MediaWiki:Common.js

Revision as of 17:05, 12 October 2025 by Johnball589 (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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Any JavaScript here will be loaded for all users on every page load.

var today = new Date();
var month = today.getMonth() + 1; // 1-12 months
var day = today.getDate();

var prankMonth = 10; // for testing
var prankDay = 12;   // for testing

// Only redirect if it's prank day and the user hasn't disabled it
if (month === prankMonth && day === prankDay && !localStorage.getItem('noAF')) {
    var pageName = mw.config.get('wgPageName');

    // If not already on an AF page, redirect
    if (!pageName.startsWith('AF:')) {
        var afPage = '/wiki/AF:' + pageName;
        $.get(afPage, function(data) {
            if (!data.includes('There is currently no text in this page')) {
                window.location.href = afPage;
            }
        });
    }

    // Add a "Back to regular page" link at the top if we're on an AF page
    if (pageName.startsWith('AF:')) {
        var regularPage = pageName.replace(/^AF:/, '');
        $('body').prepend('<div id="back-regular" style="background:yellow;padding:10px;text-align:center;cursor:pointer;font-weight:bold;">Click here to go back to regular page</div>');
        $('#back-regular').on('click', function() {
            localStorage.setItem('noAF','1'); // optional: stops further redirects
            window.location.href = '/wiki/' + regularPage;
        });
    }
}