Jump to content

MediaWiki:Common.js

From WikiTrademarks

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// WikiTrademarks Intelligence Inline Ad - Fixed Version (KEPT INTACT)
(function() {
    // Check if ad was already shown in this session
    if (sessionStorage.getItem('trademarkAdShown')) {
        return;
    }

    // Function to show the ad
    function showTrademarkAd() {
        // Find a good insertion point in the content
        var contentArea = document.querySelector('#content') || 
                         document.querySelector('.mw-content-text') || 
                         document.querySelector('main') || 
                         document.body;
        
        var paragraphs = contentArea.querySelectorAll('p');
        
        // Insert after 2nd paragraph if it exists, otherwise after first
        var insertAfter = paragraphs.length > 1 ? paragraphs[1] : 
                         (paragraphs.length > 0 ? paragraphs[0] : contentArea.firstElementChild);
        
        if (!insertAfter) return; // Safety check
        
        var adHTML = 
            '<div class="trademark-intel-ad" style="' +
                'background: #f8f9fa;' +
                'border: 1px solid #e5e7eb;' +
                'border-radius: 8px;' +
                'padding: 24px;' +
                'margin: 32px 0;' +
                'text-align: center;' +
                'font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, sans-serif;' +
                'position: relative;' +
            '">' +
                '<button onclick="closeTrademarkAd()" style="' +
                    'position: absolute;' +
                    'top: 12px;' +
                    'right: 16px;' +
                    'background: none;' +
                    'border: none;' +
                    'font-size: 20px;' +
                    'color: #666;' +
                    'cursor: pointer;' +
                    'padding: 4px;' +
                '">&times;</button>' +
                
                '<div style="font-size: 24px; font-weight: 700; color: #111827; margin-bottom: 8px;">' +
                    'Track brand wars before they make headlines' +
                '</div>' +
                
                '<div style="font-size: 16px; color: #6b7280; margin-bottom: 20px;">' +
                    'Weekly trademark intelligence that reveals brand strategy secrets' +
                '</div>' +
                
                '<div style="display: flex; align-items: center; gap: 12px; max-width: 400px; margin: 0 auto; justify-content: center;">' +
                    '<input ' +
                        'type="email" ' +
                        'placeholder="Enter your email"' +
                        'id="trademarkAdEmail"' +
                        'style="' +
                            'flex: 1;' +
                            'padding: 12px 16px;' +
                            'border: 1px solid #d1d5db;' +
                            'border-radius: 6px;' +
                            'font-size: 14px;' +
                            'outline: none;' +
                        '"' +
                    '>' +
                    '<button onclick="submitTrademarkAd()" style="' +
                        'background: #dc2626;' +
                        'color: white;' +
                        'border: none;' +
                        'padding: 12px 20px;' +
                        'border-radius: 6px;' +
                        'font-size: 14px;' +
                        'font-weight: 600;' +
                        'cursor: pointer;' +
                        'white-space: nowrap;' +
                    '">Subscribe</button>' +
                '</div>' +
                
                '<div style="font-size: 12px; color: #9ca3af; margin-top: 12px;">' +
                    'Join brand strategists, IP lawyers, and founders tracking trademark signals • Free & paid tiers' +
                '</div>' +
            '</div>';

        // Insert the ad
        if (insertAfter.nextSibling) {
            insertAfter.parentNode.insertBefore(createElementFromHTML(adHTML), insertAfter.nextSibling);
        } else {
            insertAfter.parentNode.appendChild(createElementFromHTML(adHTML));
        }
        
        // Mark as shown
        sessionStorage.setItem('trademarkAdShown', 'true');
    }

    // Helper function to create element from HTML string
    function createElementFromHTML(htmlString) {
        var div = document.createElement('div');
        div.innerHTML = htmlString.trim();
        return div.firstChild;
    }

    // Global functions for ad interaction
    window.closeTrademarkAd = function() {
        var ad = document.querySelector('.trademark-intel-ad');
        if (ad) {
            ad.style.transition = 'opacity 0.3s ease';
            ad.style.opacity = '0';
            setTimeout(function() {
                if (ad.parentNode) {
                    ad.parentNode.removeChild(ad);
                }
            }, 300);
        }
    };

    window.submitTrademarkAd = function() {
        var emailInput = document.getElementById('trademarkAdEmail');
        var email = emailInput ? emailInput.value : '';
        if (email) {
            window.open('https://wikitrademarks.substack.com/subscribe?email=' + encodeURIComponent(email), '_blank');
            setTimeout(window.closeTrademarkAd, 500);
        }
    };

    // Wait for DOM to be ready and then show ad after delay
    function init() {
        setTimeout(function() {
            showTrademarkAd();
        }, 5000);
    }

    // Check if DOM is already loaded
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();


// Add social sharing buttons and horizontal ad below (KEPT INTACT)
$(document).ready(function() {
    // Place sharing buttons after firstHeading
    if ($('#firstHeading').length) {
        // Add sharing buttons right after the firstHeading
        $('#firstHeading').after('<div class="a2a_kit a2a_kit_size_32 a2a_default_style" style="margin: 15px 0 25px 0;">' + // Added margin for spacing
            '<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_linkedin"></a>' + // Changed from a2a_button_telegram to a2a_button_linkedin
            '<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>');
    }
    
    
    // Load AddToAny script if it's not already loaded
    if (typeof window.a2a === 'undefined') {
        var a2a_script = document.createElement('script');
        a2a_script.async = true;
        a2a_script.src = 'https://static.addtoany.com/menu/page.js';
        document.body.appendChild(a2a_script);
    } else {
        // If AddToAny is already loaded, initialize it
        window.a2a.init_all();
    }
    
    // Listen for the AddToAny script to load and initialize
    if (typeof window.a2a === 'undefined') {
        a2a_script.onload = function() {
            window.a2a.init_all();
        };
    }
});

// POPUP AD ROTATION SYSTEM - NEW FUNCTIONALITY
(function() {
    // Global rotation state management
    var ROTATION_KEY = 'popupAdRotationState';
    var SCRIPT_EXECUTION_KEY = 'popupAdSystemExecuted';

    // Function to get current rotation state
    function getRotationState() {
        var state = localStorage.getItem(ROTATION_KEY);
        return state ? JSON.parse(state) : { nextAd: 'trademark', lastShown: 0 };
    }

    // Function to save rotation state
    function saveRotationState(state) {
        localStorage.setItem(ROTATION_KEY, JSON.stringify(state));
    }

    // Function to check if we should show an ad (24-hour cooldown)
    function shouldShowAd() {
        var state = getRotationState();
        var now = new Date().getTime();
        return !state.lastShown || now - state.lastShown > 24 * 60 * 60 * 1000;
    }

    // Check if system already executed
    function hasSystemExecuted() {
        return window[SCRIPT_EXECUTION_KEY] === true;
    }

    function markSystemAsExecuted() {
        window[SCRIPT_EXECUTION_KEY] = true;
    }

    // Main popup system controller
    function initializePopupSystem() {
        if (hasSystemExecuted()) return;
        markSystemAsExecuted();

        if (!shouldShowAd()) return;

        // 50/50 random selection instead of rotation
        var showTrademark = Math.random() < 0.5;
        
        if (showTrademark) {
            createTrademarkPopup();
        } else {
            createUseKasePopup();
        }
        
        // Update last shown time
        var state = getRotationState();
        state.lastShown = new Date().getTime();
        saveRotationState(state);
    }

    // Trademark Intelligence Popup - NEW
    function createTrademarkPopup() {
        var deviceWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        var isMobile = deviceWidth < 768;
        
        var popupWidth = isMobile ? '90%' : '450px';
        var headlineSize = isMobile ? '28px' : '32px'; 
        var subheadSize = isMobile ? '16px' : '18px';
        var padding = isMobile ? '24px' : '32px';

        var popup = document.createElement('div');
        popup.id = 'trademarkPopupAd';
        popup.style.cssText = `
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #ffffff;
            padding: ${padding};
            border-radius: 16px;
            border: 4px solid #dc2626;
            box-shadow: 0 10px 40px rgba(0,0,0,0.25), 0 0 0 1000px rgba(0,0,0,0.6);
            width: ${popupWidth};
            max-width: 90%;
            z-index: 1000;
            font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            text-align: center;
            display: none;
        `;

        popup.innerHTML = `
            <div style="display:block; text-align: left; margin-bottom: 20px;">
                <p style="margin: 0;"><strong style="color: #dc2626; font-size: 18px;">WikiTrademarks Intelligence</strong></p>
            </div>
            
            <h1 style="text-align:left; color: #111; font-size: ${headlineSize}; line-height: 1.2; letter-spacing: -0.4px; font-weight: 800; margin: 0 0 16px 0;">
                Track <span style="background-color: #FEF2F2; padding: 2px 6px; border-radius: 4px; color: #dc2626;">brand wars</span> before they make headlines
            </h1>
            
            <p style="text-align:left; color: #555; font-size: ${subheadSize}; line-height: 1.5; margin-bottom: 24px; font-weight: 400;">
                Weekly trademark intelligence that reveals brand strategy secrets.
            </p>
            
            <div style="text-align: left; color: #333; margin-bottom: 28px;">
                <div style="margin-bottom: 16px; display: flex; align-items: flex-start;">
                    <span style="color: #dc2626; margin-right: 10px; font-weight: bold; flex-shrink: 0;">⚖️</span>
                    <div><strong>Legal battles</strong> brewing between major brands</div>
                </div>
                
                <div style="margin-bottom: 16px; display: flex; align-items: flex-start;">
                    <span style="color: #dc2626; margin-right: 10px; font-weight: bold; flex-shrink: 0;">🎯</span>
                    <div><strong>Brand expansion</strong> strategies 6-12 months ahead</div>
                </div>
                
                <div style="margin-bottom: 0; display: flex; align-items: flex-start;">
                    <span style="color: #dc2626; margin-right: 10px; font-weight: bold; flex-shrink: 0;">📊</span>
                    <div><strong>Market positioning</strong> insights from filing patterns</div>
                </div>
            </div>
            
            <div style="text-align: left;">
                <button id="trademarkPopupButton" style="
                    background: #dc2626;
                    color: white;
                    border: none;
                    padding: 16px 32px;
                    border-radius: 8px;
                    font-size: 16px;
                    font-weight: 600;
                    cursor: pointer;
                    transition: all 0.2s ease;
                    width: 100%;
                    margin-bottom: 12px;
                    box-shadow: 0 4px 6px rgba(220, 38, 38, 0.2);
                ">Get Weekly Trademark Intelligence</button>
                <p style="font-size: 12px; color: #777; margin: 0; text-align: center;">
                    Join 300+ brand strategists, IP lawyers, and founders • Free & paid tiers
                </p>
            </div>
            
            <button onclick="closeTrademarkPopup()" style="
                position: absolute;
                top: 18px;
                right: 18px;
                background: none;
                border: none;
                font-size: 42px;
                font-weight: 300;
                line-height: 24px;
                color: #999;
                cursor: pointer;
                padding: 0;
                margin: 0;
                height: 24px;
                display: flex;
                align-items: center;
                justify-content: center;
                transition: color 0.2s;
            ">&times;</button>
        `;

        document.body.appendChild(popup);

        // Add button interactions
        var button = document.getElementById('trademarkPopupButton');
        button.addEventListener('click', function() {
            window.open('https://wikitrademarks.substack.com/subscribe', '_blank');
            closeTrademarkPopup();
        });

        button.addEventListener('mouseover', function() {
            this.style.backgroundColor = '#b91c1c';
            this.style.boxShadow = '0 6px 8px rgba(220, 38, 38, 0.3)';
            this.style.transform = 'translateY(-2px)';
        });

        button.addEventListener('mouseout', function() {
            this.style.backgroundColor = '#dc2626';
            this.style.boxShadow = '0 4px 6px rgba(220, 38, 38, 0.2)';
            this.style.transform = 'translateY(0)';
        });

        // Global close function
        window.closeTrademarkPopup = function() {
            var popup = document.getElementById('trademarkPopupAd');
            if (popup) {
                popup.style.transition = 'opacity 0.3s ease';
                popup.style.opacity = '0';
                setTimeout(function() {
                    if (popup.parentNode) {
                        popup.parentNode.removeChild(popup);
                    }
                }, 300);
            }
        };

        // Show popup with delay
        setTimeout(function() {
            popup.style.display = 'block';
            popup.style.opacity = '0';
            popup.style.transition = 'opacity 0.5s ease';
            setTimeout(function() {
                popup.style.opacity = '1';
            }, 50);
        }, 2000);
    }

    // UseKase AI Advertisement Popup - REDESIGNED to match WikiTrademarks style
    function createUseKasePopup() {
        var deviceWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        var isMobile = deviceWidth < 768;
        
        var popupWidth = isMobile ? '90%' : '450px';
        var headlineSize = isMobile ? '28px' : '32px'; 
        var subheadSize = isMobile ? '16px' : '18px';
        var padding = isMobile ? '24px' : '32px';

        var popup = document.createElement('div');
        popup.id = 'useKaseAdPopup';
        popup.style.cssText = `
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #ffffff;
            padding: ${padding};
            border-radius: 16px;
            border: 4px solid #FF8C00;
            box-shadow: 0 10px 40px rgba(0,0,0,0.25), 0 0 0 1000px rgba(0,0,0,0.6);
            width: ${popupWidth};
            max-width: 90%;
            z-index: 1000;
            font-family: Inter, -apple-system, BlinkMacSystemFont, "Segue UI", Roboto, sans-serif;
            text-align: center;
            display: none;
        `;

        popup.innerHTML = `
            <div style="display:block; text-align: left; margin-bottom: 20px;">
                <p style="margin: 0;"><a href="https://www.usekase.ai?utm_source=wikitrademarks.org" target="_blank" style="text-decoration: none;"><img src="https://www.usekase.ai/uk-logo.png" alt="UseKase AI" style="max-width:120px; display: block;"></a></p>
            </div>
            
            <h1 style="text-align:left; color: #111; font-size: ${headlineSize}; line-height: 1.2; letter-spacing: -0.4px; font-weight: 800; margin: 0 0 16px 0;">
                Transform your business with <span style="background-color: #FFEEB5; padding: 2px 6px; border-radius: 4px; color: #FF8C00;">AI in minutes</span>, not months
            </h1>
            
            <p style="text-align:left; color: #555; font-size: ${subheadSize}; line-height: 1.5; margin-bottom: 24px; font-weight: 400;">
                Get immediate results even if you've never used AI before.
            </p>
            
            <div style="text-align: left; color: #333; margin-bottom: 28px;">
                <div style="margin-bottom: 16px; display: flex; align-items: flex-start;">
                    <span style="color: #FF8C00; margin-right: 10px; font-weight: bold; flex-shrink: 0;">🎯</span>
                    <div><strong>Custom AI strategy</strong> tailored to your specific industry needs</div>
                </div>
                
                <div style="margin-bottom: 16px; display: flex; align-items: flex-start;">
                    <span style="color: #FF8C00; margin-right: 10px; font-weight: bold; flex-shrink: 0;">📈</span>
                    <div><strong>Step-by-step implementation</strong> with measurable ROI</div>
                </div>
                
                <div style="margin-bottom: 0; display: flex; align-items: flex-start;">
                    <span style="color: #FF8C00; margin-right: 10px; font-weight: bold; flex-shrink: 0;">⚡</span>
                    <div><strong>5-minute setup</strong> that requires zero technical skills</div>
                </div>
            </div>
            
            <div style="text-align: left;">
                <button id="useKasePopupButton" style="
                    background: #FF8C00;
                    color: white;
                    border: none;
                    padding: 16px 32px;
                    border-radius: 8px;
                    font-size: 16px;
                    font-weight: 600;
                    cursor: pointer;
                    transition: all 0.2s ease;
                    width: 100%;
                    margin-bottom: 12px;
                    box-shadow: 0 4px 6px rgba(255, 140, 0, 0.2);
                ">Get Your AI Playbook</button>
                <p style="font-size: 12px; color: #777; margin: 0; text-align: center;">
                    Trusted by 1,000+ companies worldwide • One-time setup, instant results
                </p>
            </div>
            
            <button onclick="closeUseKasePopup()" style="
                position: absolute;
                top: 18px;
                right: 18px;
                background: none;
                border: none;
                font-size: 42px;
                font-weight: 300;
                line-height: 24px;
                color: #999;
                cursor: pointer;
                padding: 0;
                margin: 0;
                height: 24px;
                display: flex;
                align-items: center;
                justify-content: center;
                transition: color 0.2s;
            ">&times;</button>
        `;

        document.body.appendChild(popup);

        // Add button interactions
        var button = document.getElementById('useKasePopupButton');
        button.addEventListener('click', function() {
            window.open('https://www.usekase.ai?utm_source=wikitrademarks.org', '_blank');
            closeUseKasePopup();
        });

        button.addEventListener('mouseover', function() {
            this.style.backgroundColor = '#E67E00';
            this.style.boxShadow = '0 6px 8px rgba(255, 140, 0, 0.3)';
            this.style.transform = 'translateY(-2px)';
        });

        button.addEventListener('mouseout', function() {
            this.style.backgroundColor = '#FF8C00';
            this.style.boxShadow = '0 4px 6px rgba(255, 140, 0, 0.2)';
            this.style.transform = 'translateY(0)';
        });

        // Global close function
        window.closeUseKasePopup = function() {
            var popup = document.getElementById('useKaseAdPopup');
            if (popup) {
                popup.style.transition = 'opacity 0.3s ease';
                popup.style.opacity = '0';
                setTimeout(function() {
                    if (popup.parentNode) {
                        popup.parentNode.removeChild(popup);
                    }
                }, 300);
            }
        };

        // Show popup with delay
        setTimeout(function() {
            popup.style.display = 'block';
            popup.style.opacity = '0';
            popup.style.transition = 'opacity 0.5s ease';
            setTimeout(function() {
                popup.style.opacity = '1';
            }, 50);
        }, 2000);
    }

    // Initialize the popup system
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initializePopupSystem);
    } else {
        initializePopupSystem();
    }
})();

// WikiTrademarks Scroll Carpet Advertisement (KEPT INTACT)
(function() {
    var CARPET_KEY = 'wikiTrademarksCarpetShown';
    var carpetShown = false;

    function createScrollCarpet() {
        // Check if carpet was already shown in this session
        if (sessionStorage.getItem(CARPET_KEY) || carpetShown) {
            return;
        }

        // Get device width for responsive sizing
        var deviceWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        var isMobile = deviceWidth < 768;
        
        var carpet = document.createElement('div');
        carpet.id = 'wikitrademarks-scroll-carpet';
        carpet.style.cssText = `
            position: fixed;
            bottom: -200px;
            left: 0;
            right: 0;
            background: linear-gradient(135deg, #2e1a1a 0%, #3e1616 50%, #600f0f 100%);
            color: white;
            padding: ${isMobile ? '20px 16px' : '24px 32px'};
            box-shadow: 0 -8px 32px rgba(0,0,0,0.3);
            z-index: 999;
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            transition: bottom 0.4s ease-out;
            border-top: 3px solid #dc2626;
        `;

        var content = `
            <div style="max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: ${isMobile ? '16px' : '24px'}; ${isMobile ? 'flex-direction: column; text-align: center;' : ''}">
                
                <!-- Left side: Hook + AIDA Content -->
                <div style="flex: 1; ${isMobile ? '' : 'padding-right: 20px;'}">
                    <!-- Attention: Bold Hook -->
                    <div style="font-size: ${isMobile ? '20px' : '24px'}; font-weight: 700; margin-bottom: 8px; color: #dc2626;">
                        🚨 While everyone debates AI ethics, Apple quietly filed 23 trademarks that reveal their secret brand expansion
                    </div>
                    
                    <!-- Interest: What you get -->
                    <div style="font-size: ${isMobile ? '14px' : '16px'}; margin-bottom: 12px; opacity: 0.9; line-height: 1.4;">
                        <strong>Join 300+ brand strategists, IP lawyers, and founders</strong> who get trademark intelligence 6-12 months before mainstream coverage. Last week's analysis revealed Tesla's $50M brand pivot hiding in plain sight.
                    </div>
                    
                    <!-- Desire: Specific benefits -->
                    <div style="font-size: ${isMobile ? '13px' : '14px'}; opacity: 0.8; margin-bottom: 16px;">
                        ✓ Legal battles brewing between major brands<br>
                        ✓ Brand expansion strategies ahead of announcements<br>
                        ✓ Market positioning insights from filing patterns
                    </div>
                </div>

                <!-- Right side: Action -->
                <div style="display: flex; ${isMobile ? 'flex-direction: column; width: 100%;' : 'flex-direction: column;'}; gap: 12px; ${isMobile ? '' : 'min-width: 280px;'}">
                    <button 
                        onclick="submitCarpetClick()" 
                        style="
                            background: #dc2626;
                            color: white;
                            border: none;
                            padding: 16px 32px;
                            border-radius: 8px;
                            font-size: 16px;
                            font-weight: 600;
                            cursor: pointer;
                            white-space: nowrap;
                            transition: all 0.2s ease;
                            width: 100%;
                            box-shadow: 0 4px 6px rgba(220, 38, 38, 0.2);
                        "
                        onmouseover="this.style.backgroundColor='#b91c1c'; this.style.transform='translateY(-2px)'; this.style.boxShadow='0 6px 8px rgba(220, 38, 38, 0.3)';"
                        onmouseout="this.style.backgroundColor='#dc2626'; this.style.transform='translateY(0)'; this.style.boxShadow='0 4px 6px rgba(220, 38, 38, 0.2)';"
                    >
                        Get Weekly Trademark Intelligence
                    </button>
                    <div style="font-size: 11px; opacity: 0.7; text-align: center;">
                        Free insights • Premium deep dives available • Unsubscribe anytime
                    </div>
                </div>

                <!-- Close button -->
                <button 
                    onclick="closeCarpet()" 
                    style="
                        position: absolute;
                        top: 12px;
                        right: 16px;
                        background: none;
                        border: none;
                        color: rgba(255,255,255,0.6);
                        font-size: 24px;
                        cursor: pointer;
                        padding: 4px;
                        line-height: 1;
                        transition: color 0.2s ease;
                    "
                    onmouseover="this.style.color='rgba(255,255,255,0.9)'"
                    onmouseout="this.style.color='rgba(255,255,255,0.6)'"
                >×</button>
            </div>
        `;

        carpet.innerHTML = content;
        document.body.appendChild(carpet);

        // Show carpet with animation
        setTimeout(function() {
            carpet.style.bottom = '0px';
            carpetShown = true;
        }, 100);

        // Mark as shown to prevent duplicates
        sessionStorage.setItem(CARPET_KEY, 'true');
    }

    // Global functions for carpet interaction
    window.submitCarpetClick = function() {
        // Show success state first
        var button = event.target;
        if (button) {
            var originalText = button.textContent;
            button.textContent = 'Opening...';
            button.style.backgroundColor = '#22c55e';
            button.style.transform = 'translateY(0)';
        }
        
        // Open Substack with UTM tracking for scroll carpet
        window.open('https://wikitrademarks.substack.com/subscribe?utm_source=wikitrademarks&utm_medium=scroll_carpet&utm_campaign=trademark_intelligence&utm_content=bottom_banner', '_blank');
        
        // Close carpet after delay
        setTimeout(function() {
            window.closeCarpet();
        }, 1500);
    };

    window.closeCarpet = function() {
        var carpet = document.getElementById('wikitrademarks-scroll-carpet');
        if (carpet) {
            carpet.style.bottom = '-200px';
            setTimeout(function() {
                if (carpet.parentNode) {
                    carpet.parentNode.removeChild(carpet);
                }
            }, 400);
        }
    };

    // Scroll detection logic
    var scrollThreshold = 0.4; // Show after 40% scroll
    var hasTriggered = false;

    function handleScroll() {
        if (hasTriggered || carpetShown) return;

        var scrollPercent = (window.scrollY || document.documentElement.scrollTop) / 
                           ((document.documentElement.scrollHeight || document.body.scrollHeight) - window.innerHeight);

        if (scrollPercent >= scrollThreshold) {
            hasTriggered = true;
            createScrollCarpet();
            window.removeEventListener('scroll', handleScroll);
        }
    }

    // Add shake animation to document head
    var style = document.createElement('style');
    style.textContent = `
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-5px); }
            75% { transform: translateX(5px); }
        }
    `;
    document.head.appendChild(style);

    // Initialize scroll listener
    function init() {
        // Only add scroll listener if not already shown
        if (!sessionStorage.getItem(CARPET_KEY)) {
            window.addEventListener('scroll', handleScroll, { passive: true });
        }
    }

    // Initialize when DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    // Handle responsive updates on resize
    window.addEventListener('resize', function() {
        var carpet = document.getElementById('wikitrademarks-scroll-carpet');
        if (carpet) {
            var newDeviceWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
            var newIsMobile = newDeviceWidth < 768;
            
            // Update mobile/desktop specific styles if needed
            var content = carpet.querySelector('div');
            if (content) {
                if (newIsMobile) {
                    content.style.flexDirection = 'column';
                    content.style.textAlign = 'center';
                } else {
                    content.style.flexDirection = 'row';
                    content.style.textAlign = 'left';
                }
            }
        }
    });

})();
Cookies help us deliver our services. By using our services, you agree to our use of cookies.