MediaWiki:Common.js

From Medalist Wiki
Revision as of 01:26, 8 February 2025 by Zhiktang (talk | contribs)

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* 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 = true;
    
    // Check if user has seen the warning before (or if in debug mode)
    if (debugMode || !mw.cookie.get('spoilerWarningShown')) {
        // Create popup container
        var popup = document.createElement('div');
        popup.style.position = 'fixed';
        popup.style.top = '50%';
        popup.style.left = '50%';
        popup.style.transform = 'translate(-50%, -50%)';
        popup.style.background = 'white';
        popup.style.padding = '20px';
        popup.style.borderRadius = '5px';
        popup.style.boxShadow = '0 2px 10px rgba(0,0,0,0.3)';
        popup.style.zIndex = '10000';
        popup.style.maxWidth = '400px';
        popup.style.textAlign = 'center';

        // Create warning message
        var message = document.createElement('p');
        message.textContent = 'This wiki contains the latest manga spoilers';
        message.style.marginBottom = '20px';
        message.style.fontSize = '16px';

        // Create additional info message
        var subMessage = document.createElement('p');
        subMessage.textContent = 'You will not see this message again';
        subMessage.style.fontSize = '14px';
        subMessage.style.color = '#666';
        subMessage.style.marginBottom = '20px';

        // Create acknowledge button
        var button = document.createElement('button');
        button.textContent = 'I Understand';
        button.style.padding = '8px 16px';
        button.style.background = '#36c';
        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 closePopup() {
            // Set cookie to expire in 365 days
            mw.cookie.set('spoilerWarningShown', '1', {
                expires: 365 * 24 * 60 * 60,
                path: '/'
            });
            // Remove popup and overlay
            document.body.removeChild(popup);
            document.body.removeChild(overlay);
        }

        // Add click handlers
        button.onclick = closePopup;
        overlay.onclick = closePopup;

        // Add debug text if in debug mode
        if (debugMode) {
            var debugText = document.createElement('p');
            debugText.textContent = '(Debug Mode Active)';
            debugText.style.fontSize = '12px';
            debugText.style.color = '#666';
            popup.appendChild(debugText);
        }

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