Difference between revisions of "MediaWiki:Common.js"

From WikiPatents
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
<!-- Google tag (gtag.js) -->
+
mw.loader.load('https://static.addtoany.com/menu/page.js');
<script async src="https://www.googletagmanager.com/gtag/js?id=G-GBTLGTHG7P"></script>
+
 
<script>
+
mw.loader.load(function() {
  window.dataLayer = window.dataLayer || [];
+
    var script = document.createElement('script');
  function gtag(){dataLayer.push(arguments);}
+
    script.async = true;
  gtag('js', new Date());
+
    script.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8564930964635372";
 +
    script.setAttribute('crossorigin', 'anonymous');
 +
    document.head.appendChild(script);
 +
});
 +
 
 +
 
 +
$(document).ready(function() {
 +
    if ($('#content').length) {
 +
        $('#content').append('<div class="a2a_kit a2a_kit_size_32 a2a_default_style">' +
 +
            '<a class="a2a_dd" href="https://www.addtoany.com/share"></a>' +
 +
            '<a class="a2a_button_email"></a>' +
 +
            '<a class="a2a_button_x"></a>' +
 +
            '<a class="a2a_button_telegram"></a>' +
 +
            '<a class="a2a_button_whatsapp"></a>' +
 +
            '<a class="a2a_button_facebook"></a>' +
 +
            '<a class="a2a_button_facebook_messenger"></a>' +
 +
            '<a class="a2a_button_google_gmail"></a>' +
 +
            '</div>');
 +
    }
 +
});
  
  gtag('config', 'G-GBTLGTHG7P');
 
</script>
 
  
<script>
 
 
(function() {
 
(function() {
     // Create and append styles
+
     // Use a unique key for this script
     var style = document.createElement('style');
+
    var SCRIPT_KEY = 'patentAlertScriptExecuted';
     style.textContent = `
+
     var POPUP_KEY = 'patentAlertPopupCreated';
         .patent-popup {
+
 
            position: fixed;
+
    // Function to check if the script has already run
            top: 50%;
+
    function hasScriptRun() {
            left: 50%;
+
        return window[SCRIPT_KEY] === true;
            transform: translate(-50%, -50%) scale(0.1);
+
     }
            background-color: #f8f9fa;
+
 
            padding: 20px;
+
    // Function to mark the script as run
            border-radius: 10px;
+
    function markScriptAsRun() {
            box-shadow: 0 5px 30px rgba(0,0,0,0.3);
+
        window[SCRIPT_KEY] = true;
             width: 300px;
+
    }
             opacity: 0;
+
 
             transition: all 0.3s ease-in-out;
+
    // Function to check if popup has been created
             z-index: 1000;
+
    function hasPopupBeenCreated() {
 +
         return window[POPUP_KEY] === true;
 +
    }
 +
 
 +
    // Function to mark popup as created
 +
    function markPopupAsCreated() {
 +
        window[POPUP_KEY] = true;
 +
    }
 +
 
 +
    // Main function to create popup and banner
 +
    function createPatentAlert() {
 +
        // Check if the script has already been executed
 +
        if (hasScriptRun()) return;
 +
 
 +
        // Mark the script as run
 +
        markScriptAsRun();
 +
 
 +
        // Check if the alert has been shown in the last 24 hours
 +
        var lastShown = localStorage.getItem('patentAlertLastShown');
 +
        var now = new Date().getTime();
 +
       
 +
        if (!lastShown || now - lastShown > 24 * 60 * 60 * 1000) {
 +
            // Create and show popup
 +
             createPopup();
 +
              
 +
             // Create and show banner
 +
             createBanner();
 
         }
 
         }
         .patent-popup.show {
+
    }
            opacity: 1;
+
 
            transform: translate(-50%, -50%) scale(1);
+
    function createPopup() {
        }
+
        // Check if popup has already been created
         .patent-popup h2 {
+
         if (hasPopupBeenCreated()) return;
             margin-top: 0;
+
 
             color: #333;
+
        // Mark popup as created
         }
+
        markPopupAsCreated();
         .patent-popup p {
+
 
             color: #666;
+
        var $popup = $('<div>')
        }
+
            .attr('id', 'patentAlertPopup')
         .patent-cta-button {
+
            .css({
             display: block;
+
                position: 'fixed',
             width: 100%;
+
                top: '50%',
            padding: 10px;
+
                left: '50%',
             background-color: #007bff;
+
                transform: 'translate(-50%, -50%)',
             color: white;
+
                backgroundColor: 'rgba(255, 255, 255, 0.95)',
             border: none;
+
                padding: '30px',
             border-radius: 5px;
+
                borderRadius: '20px',
             font-size: 16px;
+
                border: '8px solid #ffbe18',
             cursor: pointer;
+
                boxShadow: '0 10px 40px rgba(0,0,0,0.2)',
             transition: background-color 0.2s;
+
                width: '400px',
         }
+
                maxWidth: '90%',
         .patent-cta-button:hover {
+
                zIndex: 1000,
            background-color: #0056b3;
+
                fontFamily: 'Arial, sans-serif',
        }
+
                textAlign: 'center',
    `;
+
                display: 'none' // Start hidden
    document.head.appendChild(style);
+
            })
 +
            .html('<h2 style="color: #333; font-size: 24px; margin-bottom: 20px;">Patent Application Monitoring</h2>' +
 +
                  '<p style="color: #555; font-size: 16px; line-height: 1.5; margin-bottom: 25px;">Want to monitor Patent Applications? Submit your custom request and get a free weekly report!</p>' +
 +
                  '<button id="patentAlertButton">Get Alerts</button>')
 +
            .appendTo('body');
 +
 
 +
         $('#patentAlertButton').css({
 +
             display: 'inline-block',
 +
            padding: '12px 24px',
 +
            backgroundColor: '#ffbe18',
 +
             color: '#333',
 +
            border: 'none',
 +
            borderRadius: '25px',
 +
            fontSize: '18px',
 +
            fontWeight: 'bold',
 +
            cursor: 'pointer',
 +
            transition: 'background-color 0.3s, transform 0.1s',
 +
            outline: 'none'
 +
        }).on('click', function() {
 +
            window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank');
 +
            $popup.fadeOut(300);
 +
            localStorage.setItem('patentAlertLastShown', new Date().getTime());
 +
         }).on('mouseover', function() {
 +
            $(this).css('backgroundColor', '#e5ab16');
 +
        }).on('mouseout', function() {
 +
            $(this).css('backgroundColor', '#ffbe18');
 +
        }).on('mousedown', function() {
 +
            $(this).css('transform', 'scale(0.95)');
 +
         }).on('mouseup', function() {
 +
             $(this).css('transform', 'scale(1)');
 +
        });
 +
 
 +
        // Add close button
 +
        $('<button>')
 +
            .text('×')
 +
            .css({
 +
                position: 'absolute',
 +
                top: '10px',
 +
                right: '10px',
 +
                background: 'none',
 +
                border: 'none',
 +
                fontSize: '24px',
 +
                color: '#666',
 +
                cursor: 'pointer'
 +
            })
 +
            .on('click', function() {
 +
                $popup.fadeOut(300);
 +
                localStorage.setItem('patentAlertLastShown', new Date().getTime());
 +
            })
 +
            .appendTo($popup);
 +
 
 +
         // Show popup with fade-in effect after a short delay
 +
        setTimeout(function() {
 +
             $popup.fadeIn(500);
 +
        }, 1000);
 +
    }
 +
 
 +
function createBanner() {
 +
        var $banner = $('<div>')
 +
             .css({
 +
                position: 'fixed',
 +
                top: '0',
 +
                left: '0',
 +
                width: '100%',
 +
                backgroundColor: '#ffbe18',
 +
                padding: '10px',
 +
                boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
 +
                zIndex: 999,
 +
                fontFamily: 'Arial, sans-serif',
 +
                textAlign: 'center',
 +
                display: 'flex',
 +
                justifyContent: 'center',
 +
                alignItems: 'center'
 +
            })
 +
            .html('<p style="color: #333; font-size: 16px; margin: 0 20px 0 0;">Want to monitor Patent Applications? Get a free weekly report!</p>' +
 +
                  '<button id="patentAlertBannerButton">Get Alerts</button>')
 +
            .prependTo('body');
 +
 
 +
        $('#patentAlertBannerButton').css({
 +
             display: 'inline-block',
 +
            padding: '8px 16px',
 +
            backgroundColor: '#333',
 +
             color: '#fff',
 +
             border: 'none',
 +
            borderRadius: '25px',
 +
             fontSize: '14px',
 +
             fontWeight: 'bold',
 +
             cursor: 'pointer',
 +
             transition: 'background-color 0.3s',
 +
            outline: 'none'
 +
        }).on('click', function() {
 +
            window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank');
 +
         }).on('mouseover', function() {
 +
            $(this).css('backgroundColor', '#555');
 +
         }).on('mouseout', function() {
 +
            $(this).css('backgroundColor', '#333');
 +
        });
 +
 
 +
        // Add close button for banner
 +
        $('<button>')
 +
            .text('×')
 +
            .css({
 +
                background: 'none',
 +
                border: 'none',
 +
                fontSize: '20px',
 +
                color: '#333',
 +
                cursor: 'pointer',
 +
                marginLeft: '20px'
 +
            })
 +
            .on('click', function() {
 +
                $banner.slideUp(300);
 +
            })
 +
            .appendTo($banner);
  
    // Create popup element
+
        // Show banner with slide-down effect
    var popup = document.createElement('div');
+
        $banner.hide().slideDown(500);
    popup.className = 'patent-popup';
 
    popup.innerHTML = `
 
        <h2>Patent Application Monitoring</h2>
 
        <p>Want to monitor Patent Applications? Submit your custom request and get a free weekly report!</p>
 
        <button class="patent-cta-button">Get Alerts</button>
 
    `;
 
    document.body.appendChild(popup);
 
  
    // Show popup after a short delay
+
        // Adjust body padding to accommodate the banner
    setTimeout(function() {
+
        $('body').css('padding-top', $banner.outerHeight());
        popup.classList.add('show');
+
     }
     }, 1000);
 
  
     // Add click event to the CTA button
+
     // Use a more reliable method to ensure the script runs only once when the DOM is ready
     popup.querySelector('.patent-cta-button').addEventListener('click', function() {
+
     if (document.readyState === 'loading') {
         window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank');
+
         document.addEventListener('DOMContentLoaded', createPatentAlert);
         popup.classList.remove('show');
+
    } else {
     });
+
         createPatentAlert();
 +
     }
 
})();
 
})();
</script>
 

Latest revision as of 06:35, 9 September 2024

mw.loader.load('https://static.addtoany.com/menu/page.js');

mw.loader.load(function() {
    var script = document.createElement('script');
    script.async = true;
    script.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8564930964635372";
    script.setAttribute('crossorigin', 'anonymous');
    document.head.appendChild(script);
});


$(document).ready(function() {
    if ($('#content').length) {
        $('#content').append('<div class="a2a_kit a2a_kit_size_32 a2a_default_style">' +
            '<a class="a2a_dd" href="https://www.addtoany.com/share"></a>' +
            '<a class="a2a_button_email"></a>' +
            '<a class="a2a_button_x"></a>' +
            '<a class="a2a_button_telegram"></a>' +
            '<a class="a2a_button_whatsapp"></a>' +
            '<a class="a2a_button_facebook"></a>' +
            '<a class="a2a_button_facebook_messenger"></a>' +
            '<a class="a2a_button_google_gmail"></a>' +
            '</div>');
    }
});


(function() {
    // Use a unique key for this script
    var SCRIPT_KEY = 'patentAlertScriptExecuted';
    var POPUP_KEY = 'patentAlertPopupCreated';

    // Function to check if the script has already run
    function hasScriptRun() {
        return window[SCRIPT_KEY] === true;
    }

    // Function to mark the script as run
    function markScriptAsRun() {
        window[SCRIPT_KEY] = true;
    }

    // Function to check if popup has been created
    function hasPopupBeenCreated() {
        return window[POPUP_KEY] === true;
    }

    // Function to mark popup as created
    function markPopupAsCreated() {
        window[POPUP_KEY] = true;
    }

    // Main function to create popup and banner
    function createPatentAlert() {
        // Check if the script has already been executed
        if (hasScriptRun()) return;

        // Mark the script as run
        markScriptAsRun();

        // Check if the alert has been shown in the last 24 hours
        var lastShown = localStorage.getItem('patentAlertLastShown');
        var now = new Date().getTime();
        
        if (!lastShown || now - lastShown > 24 * 60 * 60 * 1000) {
            // Create and show popup
            createPopup();
            
            // Create and show banner
            createBanner();
        }
    }

    function createPopup() {
        // Check if popup has already been created
        if (hasPopupBeenCreated()) return;

        // Mark popup as created
        markPopupAsCreated();

        var $popup = $('<div>')
            .attr('id', 'patentAlertPopup')
            .css({
                position: 'fixed',
                top: '50%',
                left: '50%',
                transform: 'translate(-50%, -50%)',
                backgroundColor: 'rgba(255, 255, 255, 0.95)',
                padding: '30px',
                borderRadius: '20px',
                border: '8px solid #ffbe18',
                boxShadow: '0 10px 40px rgba(0,0,0,0.2)',
                width: '400px',
                maxWidth: '90%',
                zIndex: 1000,
                fontFamily: 'Arial, sans-serif',
                textAlign: 'center',
                display: 'none' // Start hidden
            })
            .html('<h2 style="color: #333; font-size: 24px; margin-bottom: 20px;">Patent Application Monitoring</h2>' +
                  '<p style="color: #555; font-size: 16px; line-height: 1.5; margin-bottom: 25px;">Want to monitor Patent Applications? Submit your custom request and get a free weekly report!</p>' +
                  '<button id="patentAlertButton">Get Alerts</button>')
            .appendTo('body');

        $('#patentAlertButton').css({
            display: 'inline-block',
            padding: '12px 24px',
            backgroundColor: '#ffbe18',
            color: '#333',
            border: 'none',
            borderRadius: '25px',
            fontSize: '18px',
            fontWeight: 'bold',
            cursor: 'pointer',
            transition: 'background-color 0.3s, transform 0.1s',
            outline: 'none'
        }).on('click', function() {
            window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank');
            $popup.fadeOut(300);
            localStorage.setItem('patentAlertLastShown', new Date().getTime());
        }).on('mouseover', function() {
            $(this).css('backgroundColor', '#e5ab16');
        }).on('mouseout', function() {
            $(this).css('backgroundColor', '#ffbe18');
        }).on('mousedown', function() {
            $(this).css('transform', 'scale(0.95)');
        }).on('mouseup', function() {
            $(this).css('transform', 'scale(1)');
        });

        // Add close button
        $('<button>')
            .text('×')
            .css({
                position: 'absolute',
                top: '10px',
                right: '10px',
                background: 'none',
                border: 'none',
                fontSize: '24px',
                color: '#666',
                cursor: 'pointer'
            })
            .on('click', function() {
                $popup.fadeOut(300);
                localStorage.setItem('patentAlertLastShown', new Date().getTime());
            })
            .appendTo($popup);

        // Show popup with fade-in effect after a short delay
        setTimeout(function() {
            $popup.fadeIn(500);
        }, 1000);
    }

function createBanner() {
        var $banner = $('<div>')
            .css({
                position: 'fixed',
                top: '0',
                left: '0',
                width: '100%',
                backgroundColor: '#ffbe18',
                padding: '10px',
                boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
                zIndex: 999,
                fontFamily: 'Arial, sans-serif',
                textAlign: 'center',
                display: 'flex',
                justifyContent: 'center',
                alignItems: 'center'
            })
            .html('<p style="color: #333; font-size: 16px; margin: 0 20px 0 0;">Want to monitor Patent Applications? Get a free weekly report!</p>' +
                  '<button id="patentAlertBannerButton">Get Alerts</button>')
            .prependTo('body');

        $('#patentAlertBannerButton').css({
            display: 'inline-block',
            padding: '8px 16px',
            backgroundColor: '#333',
            color: '#fff',
            border: 'none',
            borderRadius: '25px',
            fontSize: '14px',
            fontWeight: 'bold',
            cursor: 'pointer',
            transition: 'background-color 0.3s',
            outline: 'none'
        }).on('click', function() {
            window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank');
        }).on('mouseover', function() {
            $(this).css('backgroundColor', '#555');
        }).on('mouseout', function() {
            $(this).css('backgroundColor', '#333');
        });

        // Add close button for banner
        $('<button>')
            .text('×')
            .css({
                background: 'none',
                border: 'none',
                fontSize: '20px',
                color: '#333',
                cursor: 'pointer',
                marginLeft: '20px'
            })
            .on('click', function() {
                $banner.slideUp(300);
            })
            .appendTo($banner);

        // Show banner with slide-down effect
        $banner.hide().slideDown(500);

        // Adjust body padding to accommodate the banner
        $('body').css('padding-top', $banner.outerHeight());
    }

    // Use a more reliable method to ensure the script runs only once when the DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', createPatentAlert);
    } else {
        createPatentAlert();
    }
})();