User:Zombiebaron/Invert.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes.
- Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
- Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
- Opera, Konqueror and Safari users can just click the Reload button.
- Chrome: press Ctrl+F5 or Shift+F5
// Creates a link and an html class to invert the screen
// Documentation at [[w:User:BrandonXLF/Invert]]
mw.loader.load('//en.uncyclopedia.co/w/index.php?title=User:Zombiebaron/Invert.css&action=raw&ctype=text/css', 'text/css'); // Import stylesheet
$(function() {
function update(){ // Function to update filter
if(mw.storage.get('InvertPage') == 'true'){
$(document.body).addClass('inverted-colors'); // Add CSS
}else{
$(document.body).removeClass('inverted-colors'); // Remove CSS
}
}
function set(e){ // Function to set web storage and update filter
e.preventDefault(); // Pervent default action
if(mw.storage.get('InvertPage') == 'true'){
mw.storage.set('InvertPage','false');
}else{
mw.storage.set('InvertPage','true');
}
update(); // Update fiter
}
var node = mw.util.addPortletLink( // Add link
'p-personal',
"https://en.wikipedia.org/wiki/User:BrandonXLF/Invert/select", // Backup link to URL
'🌛',
'night mode',
'enter night mode',
'n',
'#pt-mytalk'
);
update();
$(node).on('click',function(e){ // Make the dark mode link work
set(e);
});
$('#ToggleWikiInvert').click(function(e){ // Allow for id to toggle dark mode
set(e);
});
$('.ToggleWikiInvert').click(function(e){ // Allow to CSS class to toggle dark mode
set(e);
});
});