Jump to content

User:LJF2019/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by LJF2019 (talk | contribs) at 23:43, 2 December 2015. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function() {
	var nighttime, cssLoaded;
	
	mw.loader.using('jquery.jStorage', function() {
		mw.util.addPortletLink("p-personal", "#", "Nightpedia", "pt-nightpedia", "", "np", "#pt-watchlist");
		var nighttime = $.jStorage.get("nightpediaTime") === "nighttime",
		cssLoaded = nighttime ? lightsOff() : false;
	});

	$("#pt-nightpedia").on("click", function(e) {
		e.preventDefault();
		nighttime = !nighttime;
		if(nighttime) {
			lightsOff();
		} else {
			lightsOn();
		}
	});

	function lightsOn() {
		$("body").removeClass("nighttime");
		$("#pt-nightpedia a").text("Nightpedia");
		$.jStorage.set("nightpediaTime", "daytime");
	}
	function lightsOff() {
		if(!cssLoaded) importStylesheet("User:MusikAnimal/nightpedia.css");
		$("body").addClass("nighttime");
		$("#pt-nightpedia a").text("Daypedia");
		$.jStorage.set("nightpediaTime", "nighttime");
		return true;
	}
}());