MediaWiki:Common.js: Difference between revisions
Appearance
Johnball589 (talk | contribs) No edit summary Tag: Reverted |
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. */ | ||
$(function() { | |||
console.log("✅ April Fools script loaded"); | |||
var | var today = new Date(); | ||
var | 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 | |||
var | |||
// | // 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) { | |||
window.location.href = | 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"); | |||
} | } | ||
} | }); |
Revision as of 17:10, 12 October 2025
/* 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");
}
});