MediaWiki:Common.js: Difference between revisions

Johnball589 (talk | contribs)
No edit summary
Johnball589 (talk | contribs)
No edit summary
Tag: Reverted
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.


// Get current date info
var today = new Date();
var today = new Date();
var month = today.getMonth() + 1; // JS months are 0-based so add 1
var month = today.getMonth() + 1; // 1-12 months
var day = today.getDate();
var day = today.getDate();


// Define the day and month you want to trigger April Fools mode
var prankMonth = 10; // for testing
var prankMonth = 10; // October (since you're testing now)
var prankDay = 12;  // for testing
var prankDay = 12;  // today's day (or change this to whatever test day)


// Check if it's prank day
// Only redirect if it's prank day and the user hasn't disabled it
if (month === prankMonth && day === prankDay) {
if (month === prankMonth && day === prankDay && !localStorage.getItem('noAF')) {
    // Get the current page name
     var pageName = mw.config.get('wgPageName');
     var pageName = mw.config.get('wgPageName');
   
 
     // If we're not already on an AF page, redirect to it
     // If not already on an AF page, redirect
     if (!pageName.startsWith('AF:')) {
     if (!pageName.startsWith('AF:')) {
         window.location.href = '/wiki/AF:' + pageName;
         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;
        });
     }
     }
}
}