MediaWiki:Common.js
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. */
$(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");
}
});