MediaWiki:Common.js

From Medalist Wiki
Revision as of 01:16, 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.
/* Any JavaScript here will be loaded for all users on every page load. */
// MediaWiki:Common.js
/* Add spoiler warning popup for first-time visitors */
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function() {
    // Check if user has seen the warning before
    if (!mw.cookie.get('spoilerWarningShown')) {
        // Create popup container
        var popup = document.createElement('div');
        popup.style.cssText = `
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
            z-index: 10000;
            max-width: 400px;
            text-align: 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.cssText = `
            padding: 8px 16px;
            background: #36c;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        `;

        // Create overlay
        var overlay = document.createElement('div');
        overlay.style.cssText = `
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.5);
            z-index: 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);
        };

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