Difference between revisions of MediaWiki:Gadget-Nightpedia.js
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
cssLoaded = nighttime ? lightsOff() : false; | cssLoaded = nighttime ? lightsOff() : false; | ||
mw.util.addPortletLink('p-personal', '#', nighttime ? ' | mw.util.addPortletLink('p-personal', '#', nighttime ? '🌞 Light Mode' : '🌒 Dark Mode', 'pt-nightpedia', '', 'np', '#pt-anonuserpage'); | ||
$('#pt-nightpedia').on('click', function(e) { | $('#pt-nightpedia').on('click', function(e) { | ||
| Line 23: | Line 23: | ||
function lightsOff() { | function lightsOff() { | ||
if(!cssLoaded) { | if(!cssLoaded) { | ||
$('head').append(mw.loader.load('https:// | $('head').append(mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:MusikAnimal/nightpedia.css&action=raw&ctype=text/css', 'text/css')); | ||
} | } | ||
$('html').addClass('nighttime'); | $('html').addClass('nighttime'); | ||
Latest revision as of 12:12, 14 June 2020
//<nowiki>
$(function() {
var nighttime = 'on' === mw.storage.get('nightpedia'),
cssLoaded = nighttime ? lightsOff() : false;
mw.util.addPortletLink('p-personal', '#', nighttime ? '🌞 Light Mode' : '🌒 Dark Mode', 'pt-nightpedia', '', 'np', '#pt-anonuserpage');
$('#pt-nightpedia').on('click', function(e) {
e.preventDefault();
nighttime = !nighttime;
if (nighttime) {
lightsOff();
} else {
lightsOn();
}
});
function lightsOn() {
$('html').removeClass('nighttime');
$('#pt-nightpedia a').text('Nightpedia');
mw.storage.set('nightpedia', 'off');
}
function lightsOff() {
if(!cssLoaded) {
$('head').append(mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:MusikAnimal/nightpedia.css&action=raw&ctype=text/css', 'text/css'));
}
$('html').addClass('nighttime');
$('#pt-nightpedia a').text('Daypedia');
mw.storage.set('nightpedia', 'on');
return true;
}
});
//</nowiki>