User:Viceroy Sam/nightpedia.js

< User:Viceroy Sam
Revision as of 20:37, 13 June 2020 by Viceroy Sam (talk | contribs) (Local User:Sam.Watson/nightpedia.css)
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//<nowiki>
$(function() {
    var nighttime = 'on' === mw.storage.get('nightpedia'),
        cssLoaded = nighttime ? lightsOff() : false;

    mw.util.addPortletLink('p-personal', '#', nighttime ? 'Daypedia' : 'Nightpedia', 'pt-nightpedia', '', 'np', '#pt-watchlist');

    $('#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) importStylesheet("User:Sam.Watson/nightpedia.css");
	$("body").addClass("nighttime");
	$("#pt-nightpedia a").text("Daypedia");
	$.jStorage.set("nightpediaTime", "nighttime");
	return true;

    }
});
//</nowiki>