MediaWiki:Common.js: Difference between revisions

From Medalist Wiki
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
// MediaWiki:Common.js
// MediaWiki:Common.js
/* Add spoiler warning popup for first-time visitors */
/* Add spoiler warning popup for first-time visitors */
/* Add spoiler warning popup for first-time visitors */
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function() {
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function() {
     // Check if user has seen the warning before
    // Debug mode - set to true to always show the popup
     if (!mw.cookie.get('spoilerWarningShown')) {
    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
         // Create popup container
         var popup = document.createElement('div');
         var popup = document.createElement('div');
         popup.style.cssText = `
         popup.style.position = 'fixed';
            position: fixed;
        popup.style.top = '50%';
            top: 50%;
        popup.style.left = '50%';
            left: 50%;
        popup.style.transform = 'translate(-50%, -50%)';
            transform: translate(-50%, -50%);
        popup.style.background = 'white';
            background: white;
        popup.style.padding = '20px';
            padding: 20px;
        popup.style.borderRadius = '5px';
            border-radius: 5px;
        popup.style.boxShadow = '0 2px 10px rgba(0,0,0,0.3)';
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
        popup.style.zIndex = '10000';
            z-index: 10000;
        popup.style.maxWidth = '400px';
            max-width: 400px;
        popup.style.textAlign = 'center';
            text-align: center;
        `;


         // Create warning message
         // Create warning message
Line 30: Line 32:
         var button = document.createElement('button');
         var button = document.createElement('button');
         button.textContent = 'I Understand';
         button.textContent = 'I Understand';
         button.style.cssText = `
         button.style.padding = '8px 16px';
            padding: 8px 16px;
        button.style.background = '#36c';
            background: #36c;
        button.style.color = 'white';
            color: white;
        button.style.border = 'none';
            border: none;
        button.style.borderRadius = '3px';
            border-radius: 3px;
        button.style.cursor = 'pointer';
            cursor: pointer;
        `;


         // Create overlay
         // Create overlay
         var overlay = document.createElement('div');
         var overlay = document.createElement('div');
         overlay.style.cssText = `
         overlay.style.position = 'fixed';
            position: fixed;
        overlay.style.top = '0';
            top: 0;
        overlay.style.left = '0';
            left: 0;
        overlay.style.right = '0';
            right: 0;
        overlay.style.bottom = '0';
            bottom: 0;
        overlay.style.background = 'rgba(0,0,0,0.5)';
            background: rgba(0,0,0,0.5);
        overlay.style.zIndex = '9999';
            z-index: 9999;
        `;


         // Add click handler for button
         // Add click handler for button
Line 62: Line 60:
             document.body.removeChild(overlay);
             document.body.removeChild(overlay);
         };
         };
        // 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
         // Assemble and show popup

Revision as of 01:19, 8 February 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// MediaWiki:Common.js
/* Add spoiler warning popup for first-time visitors */
/* 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 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';

        // Add click handler for button
        button.onclick = function() {
            // 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 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(button);
        document.body.appendChild(overlay);
        document.body.appendChild(popup);
    }
});