Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<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) {
            $('head').append(mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Dom_walden/vector.css&action=raw&ctype=text/css', 'text/css'));
        }
        $('html').addClass('nighttime');
        $('#pt-nightpedia a').text('Daypedia');
        mw.storage.set('nightpedia', 'on');
        return true;
    }
});
//</nowiki>