MediaWiki:Common.js: Difference between revisions
Johnball589 (talk | contribs) No edit summary Tag: Reverted |
Johnball589 (talk | contribs) No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
$(function() { | $(function() { | ||
console.log("✅ April Fools script loaded"); | console.log("✅ April Fools script loaded"); | ||
var today = new Date(); | var today = new Date(); | ||
var month = today.getMonth() + 1; | var month = today.getMonth() + 1; | ||
var day = today.getDate(); | var day = today.getDate(); | ||
var prankMonth = 10; // testing month | var prankMonth = 10; // testing month | ||
var prankDay = 12; // testing day | var prankDay = 12; // testing day | ||
// Check | // Check localStorage at the very top | ||
var afDisabled = localStorage.getItem('noAF'); | var afDisabled = localStorage.getItem('noAF'); | ||
if (afDisabled) return; // If disabled, stop script immediately | |||
// Only | // Add "Turn off April Fools" to user dropdown early | ||
if (month === prankMonth && day === prankDay | 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'); | var pageName = mw.config.get('wgPageName'); | ||
if (!pageName.startsWith('AF:')) { | if (!pageName.startsWith('AF:')) { | ||
var afPage = '/wiki/AF:' + pageName; | var afPage = '/wiki/AF:' + pageName; | ||
$.get(afPage, function(data) { | $.get(afPage, function(data) { | ||
if (!data.includes('There is currently no text in this page')) { | if (!data.includes('There is currently no text in this page')) { | ||
window.location.href = afPage; | window.location.href = afPage; | ||
} | } | ||
Line 29: | Line 36: | ||
} | } | ||
// Add | // Add a "Back to regular page" bar for AF pages | ||
if (pageName.startsWith('AF:')) { | if (pageName.startsWith('AF:')) { | ||
var regularPage = pageName.replace(/^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>'); | $('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() { | $('#back-regular').on('click', function() { | ||
localStorage.setItem('noAF','1'); | localStorage.setItem('noAF','1'); | ||
window.location.href = '/wiki/' + regularPage; | window.location.href = '/wiki/' + regularPage; | ||
}); | }); | ||
} | } | ||
mw.notify("🤡 April Fools Mode Activated"); | mw.notify("🤡 April Fools Mode Activated"); | ||
} | } | ||
}); | }); |