Jump to content

MediaWiki:Common.js: Difference between revisions

From Electron: Chat App Wiki
Johnball589 (talk | contribs)
No edit summary
Tag: Reverted
rmv accidental redirection happening every day
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */


$(function() {
    console.log("✅ April Fools script loaded");
    var today = new Date();
    var month = today.getMonth() + 1; // JS months are 0-based, so add 1
    var day = today.getDate();
    var prankMonth = 10; // testing month (October)
    var prankDay = 12;  // testing day
    // Check if user has disabled AF mode
    var afDisabled = localStorage.getItem('noAF');
    // Only proceed if it's the prank day and AF is not disabled
    if (month === prankMonth && day === prankDay && !afDisabled) {
        var pageName = mw.config.get('wgPageName');
        // Redirect to AF page if it exists and we're not already on it
        if (!pageName.startsWith('AF:')) {
            var afPage = '/wiki/AF:' + pageName;
            $.get(afPage, function(data) {
                if (!data.includes('There is currently no text in this page')) {
                    console.log("Redirecting to:", afPage);
                    window.location.href = afPage;
                }
            });
        }
        // Add yellow "Back to regular page" bar if 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'); // prevent further redirects
                window.location.href = '/wiki/' + regularPage;
            });
        }
        // Add "Turn off April Fools" in the user dropdown menu
        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'); // marks AF as disabled
                location.reload();              // reload page to stop redirect
            });
        }
        // Optional: fun notification
        mw.notify("🤡 April Fools Mode Activated");
    }
});

Latest revision as of 17:59, 12 October 2025

Cookies help us deliver our services. By using our services, you agree to our use of cookies.