MediaWiki:Common.js: Difference between revisions

From Medalist Wiki
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function() {
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function() {
     // Debug mode - set to true to always show the popup
     // Debug mode - set to true to always show the popup
     var debugMode = true;
     var debugMode = false;
      
      
     // Check if user has seen the warning before (or if in debug mode)
     // Check if user has seen the warning before (or if in debug mode)
     if (debugMode || !mw.cookie.get('spoilerWarningShown')) {
     if (debugMode || !mw.cookie.get('spoilerWarningShown')) {
        // Create styles for light/dark mode
        var style = document.createElement('style');
        style.textContent = '@media (prefers-color-scheme: dark) { ' +
            '.spoiler-warning { background: #202020 !important; color: #ffffff !important; }' +
            '.spoiler-warning .subtext { color: #bbbbbb !important; }' +
        '} ' +
        '@media (prefers-color-scheme: light) { ' +
            '.spoiler-warning { background: #ffffff !important; color: #000000 !important; }' +
            '.spoiler-warning .subtext { color: #666666 !important; }' +
        '}';
        document.head.appendChild(style);
        // Create overlay
        var overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.top = '0';
        overlay.style.left = '0';
        overlay.style.right = '0';
        overlay.style.bottom = '0';
        overlay.style.background = 'rgba(0, 0, 0, 0.5)';
        overlay.style.zIndex = '9999';
        overlay.style.cursor = 'pointer';
         // Create popup container
         // Create popup container
         var popup = document.createElement('div');
         var popup = document.createElement('div');
        popup.className = 'spoiler-warning';
         popup.style.position = 'fixed';
         popup.style.position = 'fixed';
         popup.style.top = '50%';
         popup.style.top = '50%';
         popup.style.left = '50%';
         popup.style.left = '50%';
         popup.style.transform = 'translate(-50%, -50%)';
         popup.style.transform = 'translate(-50%, -50%)';
        popup.style.background = 'white';
         popup.style.padding = '20px';
         popup.style.padding = '20px';
         popup.style.borderRadius = '5px';
         popup.style.textAlign = 'center';
        popup.style.boxShadow = '0 2px 10px rgba(0,0,0,0.3)';
         popup.style.zIndex = '10000';
         popup.style.zIndex = '10000';
         popup.style.maxWidth = '400px';
         popup.style.maxWidth = '400px';
         popup.style.textAlign = 'center';
         popup.style.borderRadius = '8px';
        popup.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';


         // Create warning message
         // Create the main text with "spoilers" in normal weight
         var message = document.createElement('p');
         var message = document.createElement('div');
         message.textContent = 'This wiki contains the latest manga spoilers';
         message.style.marginBottom = '5px';
         message.style.marginBottom = '20px';
         message.style.fontSize = '14px';
         message.style.fontSize = '16px';
       
        var textBefore = document.createTextNode('This wiki contains ');
         var spoilersSpan = document.createElement('span');
        spoilersSpan.textContent = 'spoilers';
        var textAfter = document.createTextNode(' for the manga until the latest chapter.');
       
        message.appendChild(textBefore);
        message.appendChild(spoilersSpan);
        message.appendChild(textAfter);


         // Create additional info message
         // Create subtext
         var subMessage = document.createElement('p');
         //var subMessage = document.createElement('div');
         subMessage.textContent = 'You will not see this message again';
         //subMessage.textContent = 'By continuing, you agree to accept the risk of spoilers.';
         subMessage.style.fontSize = '14px';
         //subMessage.style.fontSize = '12px';
         subMessage.style.color = '#666';
         //subMessage.className = 'subtext';
         subMessage.style.marginBottom = '20px';
         //subMessage.style.marginBottom = '5px';


         // Create acknowledge button
         // Create "click anywhere" text
         var button = document.createElement('button');
         var clickText = document.createElement('div');
         button.textContent = 'I Understand';
         clickText.textContent = 'Click anywhere to continue.';
        button.style.padding = '8px 16px';
         clickText.style.fontSize = '14px';
        button.style.background = '#36c';
         clickText.className = 'spoiler';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '3px';
        button.style.cursor = 'pointer';
 
        // Create overlay
        var overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.top = '0';
        overlay.style.left = '0';
        overlay.style.right = '0';
        overlay.style.bottom = '0';
         overlay.style.background = 'rgba(0,0,0,0.5)';
         overlay.style.zIndex = '9999';


         // Function to close popup and set cookie
         // Function to close popup and set cookie
Line 60: Line 77:
                 path: '/'
                 path: '/'
             });
             });
             // Remove popup and overlay
             // Remove popup, overlay, and style
             document.body.removeChild(popup);
             document.body.removeChild(popup);
             document.body.removeChild(overlay);
             document.body.removeChild(overlay);
            document.head.removeChild(style);
         }
         }


         // Add click handlers
         // Add click handlers
        button.onclick = closePopup;
         overlay.onclick = closePopup;
         overlay.onclick = closePopup;
        popup.onclick = function(e) {
            e.stopPropagation(); // Prevent clicks on popup from triggering overlay click
            closePopup();
        };


         // Add debug text if in debug mode
         // Add debug text if in debug mode
         if (debugMode) {
         if (debugMode) {
             var debugText = document.createElement('p');
             var debugText = document.createElement('div');
             debugText.textContent = '(Debug Mode Active)';
             debugText.textContent = '(Debug Mode Active)';
             debugText.style.fontSize = '12px';
             debugText.style.fontSize = '10px';
             debugText.style.color = '#666';
             debugText.className = 'subtext';
             popup.appendChild(debugText);
             popup.appendChild(debugText);
         }
         }
Line 80: Line 101:
         // Assemble and show popup
         // Assemble and show popup
         popup.appendChild(message);
         popup.appendChild(message);
        popup.appendChild(subMessage);
      // popup.appendChild(subMessage);
         popup.appendChild(button);
         popup.appendChild(clickText);
         document.body.appendChild(overlay);
         document.body.appendChild(overlay);
         document.body.appendChild(popup);
         document.body.appendChild(popup);
     }
     }
});
});

Latest revision as of 02:29, 8 February 2025

/* Add spoiler warning popup for first-time visitors */
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function() {
    // Debug mode - set to true to always show the popup
    var debugMode = false;
    
    // Check if user has seen the warning before (or if in debug mode)
    if (debugMode || !mw.cookie.get('spoilerWarningShown')) {
        // Create styles for light/dark mode
        var style = document.createElement('style');
        style.textContent = '@media (prefers-color-scheme: dark) { ' +
            '.spoiler-warning { background: #202020 !important; color: #ffffff !important; }' +
            '.spoiler-warning .subtext { color: #bbbbbb !important; }' +
        '} ' +
        '@media (prefers-color-scheme: light) { ' +
            '.spoiler-warning { background: #ffffff !important; color: #000000 !important; }' +
            '.spoiler-warning .subtext { color: #666666 !important; }' +
        '}';
        document.head.appendChild(style);

        // Create overlay
        var overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.top = '0';
        overlay.style.left = '0';
        overlay.style.right = '0';
        overlay.style.bottom = '0';
        overlay.style.background = 'rgba(0, 0, 0, 0.5)';
        overlay.style.zIndex = '9999';
        overlay.style.cursor = 'pointer';

        // Create popup container
        var popup = document.createElement('div');
        popup.className = 'spoiler-warning';
        popup.style.position = 'fixed';
        popup.style.top = '50%';
        popup.style.left = '50%';
        popup.style.transform = 'translate(-50%, -50%)';
        popup.style.padding = '20px';
        popup.style.textAlign = 'center';
        popup.style.zIndex = '10000';
        popup.style.maxWidth = '400px';
        popup.style.borderRadius = '8px';
        popup.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';

        // Create the main text with "spoilers" in normal weight
        var message = document.createElement('div');
        message.style.marginBottom = '5px';
        message.style.fontSize = '14px';
        
        var textBefore = document.createTextNode('This wiki contains ');
        var spoilersSpan = document.createElement('span');
        spoilersSpan.textContent = 'spoilers';
        var textAfter = document.createTextNode(' for the manga until the latest chapter.');
        
        message.appendChild(textBefore);
        message.appendChild(spoilersSpan);
        message.appendChild(textAfter);

        // Create subtext
        //var subMessage = document.createElement('div');
        //subMessage.textContent = 'By continuing, you agree to accept the risk of spoilers.';
        //subMessage.style.fontSize = '12px';
        //subMessage.className = 'subtext';
        //subMessage.style.marginBottom = '5px';

        // Create "click anywhere" text
        var clickText = document.createElement('div');
        clickText.textContent = 'Click anywhere to continue.';
        clickText.style.fontSize = '14px';
        clickText.className = 'spoiler';

        // Function to close popup and set cookie
        function closePopup() {
            // Set cookie to expire in 365 days
            mw.cookie.set('spoilerWarningShown', '1', {
                expires: 365 * 24 * 60 * 60,
                path: '/'
            });
            // Remove popup, overlay, and style
            document.body.removeChild(popup);
            document.body.removeChild(overlay);
            document.head.removeChild(style);
        }

        // Add click handlers
        overlay.onclick = closePopup;
        popup.onclick = function(e) {
            e.stopPropagation(); // Prevent clicks on popup from triggering overlay click
            closePopup();
        };

        // Add debug text if in debug mode
        if (debugMode) {
            var debugText = document.createElement('div');
            debugText.textContent = '(Debug Mode Active)';
            debugText.style.fontSize = '10px';
            debugText.className = 'subtext';
            popup.appendChild(debugText);
        }

        // Assemble and show popup
        popup.appendChild(message);
       // popup.appendChild(subMessage);
        popup.appendChild(clickText);
        document.body.appendChild(overlay);
        document.body.appendChild(popup);
    }
});