Jump to content

MediaWiki:Common.js

From Electron: Chat App Wiki
Revision as of 17:15, 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.
$(function() {
    console.log("✅ April Fools script loaded");

    var today = new Date();
    var month = today.getMonth() + 1;
    var day = today.getDate();

    var prankMonth = 10; // testing month
    var prankDay = 12;   // testing day

    // Check localStorage at the very top
    var afDisabled = localStorage.getItem('noAF');
    if (afDisabled) return; // If disabled, stop script immediately

    // Add "Turn off April Fools" to user dropdown early
    if ($('#p-personal ul').length) {
        $('#p-personal ul').append('<li><a href="#" id="disable-af">Turn off April Fools</a></li>');
        $('#disable-af').on('click', function(e) {
            e.preventDefault();
            localStorage.setItem('noAF','1'); // disable AF mode
            location.reload();
        });
    }

    // Only redirect if it's the prank day
    if (month === prankMonth && day === prankDay) {
        var pageName = mw.config.get('wgPageName');

        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" bar for AF pages
        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');
                window.location.href = '/wiki/' + regularPage;
            });
        }

        mw.notify("🤡 April Fools Mode Activated");
    }
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.