Difference between revisions of User:Viceroy Sam/nightpedia.js

From Reduced Lens Wiki, the free vision improvement encyclopedia
Jump to navigation Jump to search
(Has to be registered user otherwise. "For security reasons JavaScript, CSS and JSON user subpages cannot be loaded for unregistered users.")
(Local User:Sam.Watson/nightpedia.css)
Line 22: Line 22:
     }
     }
     function lightsOff() {
     function lightsOff() {
        if(!cssLoaded) {
if(!cssLoaded) importStylesheet("User:Sam.Watson/nightpedia.css");
            $('head').append(mw.loader.load('https://wiki.endmyopia.org/index.php?title=User:Sam.Watson/nightpedia.css&action=raw&ctype=text/css', 'text/css'));
$("body").addClass("nighttime");
        }
$("#pt-nightpedia a").text("Daypedia");
        $('html').addClass('nighttime');
$.jStorage.set("nightpediaTime", "nighttime");
        $('#pt-nightpedia a').text('Daypedia');
return true;
        mw.storage.set('nightpedia', 'on');
 
        return true;
     }
     }
});
});
//</nowiki>
//</nowiki>

Revision as of 20:37, 13 June 2020

//<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>