Difference between revisions of User:Viceroy Sam/nightpedia.js
Jump to navigation
Jump to search
Viceroy Sam (talk | contribs) (upd) |
m (NottNott moved page User:Sam.Watson/nightpedia.js to User:Viceroy Sam/nightpedia.js: Automatically moved page while renaming the user "Sam.Watson" to "Viceroy Sam") |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
//<nowiki> | //<nowiki> | ||
$(function() { | $(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'); | |||
lightsOn(); | $('#pt-nightpedia').on('click', function(e) { | ||
e.preventDefault(); | |||
nighttime = !nighttime; | |||
if (nighttime) { | |||
lightsOff(); | |||
} else { | |||
lightsOn(); | |||
} | |||
}); | |||
function lightsOn() { | function lightsOn() { | ||
Line 11: | Line 21: | ||
mw.storage.set('nightpedia', 'off'); | mw.storage.set('nightpedia', 'off'); | ||
} | } | ||
function lightsOff() { | |||
if(!cssLoaded) { | |||
$('head').append(mw.loader.load('https://wiki.endmyopia.org/index.php?title=User:Sam.Watson/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> | //</nowiki> |
Latest revision as of 10:28, 19 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) { $('head').append(mw.loader.load('https://wiki.endmyopia.org/index.php?title=User:Sam.Watson/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>