MediaWiki:Common.js

/** * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally * loaded for all users on every wiki page. If possible create a gadget that is * enabled by default instead of adding it here (since gadgets are fully * optimized ResourceLoader modules with possibility to add dependencies etc.) * * Since Common.js isn't a gadget, there is no place to declare its * dependencies, so we have to lazy load them with mw.loader.using on demand and * then execute the rest in the callback. In most cases these dependencies will * be loaded (or loading) already and the callback will not be delayed. In case a * dependency hasn't arrived yet it'll make sure those are loaded before this. */

/* * Discontinued Features Wiki Night/Day Mode toggle. * * Design Team: * Original author: * - Left-Eye. - User:Left-Eye - 2021-Present. * * Original authors of dark mode stuff this toggle was inspired by and based apon: * - Volker E. - [ 'https://en.wikipedia.org/wiki/User:Volker_E._(WMF)/dark-mode.css' ] * - MusikAnimal - [ 'https://www.mediawiki.org/wiki/Extension:DarkMode' ] * * Last updated: 09-20-2021 */

/* Enables the Night Mode gadget. Only works for logged in users! */

mw.messages.set({	'nightmode-turn-on-label': 'Night Mode',	'nightmode-turn-on-tooltip': 'Turn on Night Mode',	'nightmode-turning-on': 'Enabling Night Mode ...',	'daymode-turn-on-label': 'Day Mode',	'daymode-turn-on-tooltip': 'Turn on Day Mode',	'daymode-turning-on': 'Enabling Day Mode ...' }); $.when($.ready, mw.loader.using(['mediawiki.util', 'mediawiki.api'])).then(function {	var inNightMode = !! mw.user.options.get('gadget-night-mode');

var linkText = inNightMode ? mw.msg('daymode-turn-on-label') : mw.msg('nightmode-turn-on-label');

var $html = inNightMode ? mw.storage.get('client-night-mode') : mw.storage.get('clent-night-mode');

mw.util.addPortletLink('p-personal', '#', linkText, 'pt-nightmode', inNightMode ? mw.msg('daymode-turn-on-tooltip') : mw.msg('nightmode-turn-on-tooltip'), 'np', '#pt-userpage' );

$('#pt-nightmode').on('click', function(e) {

e.preventDefault; mw.notify(inNightMode ? mw.msg('daymode-turning-on') : mw.msg('nightmode-turning-on'));

new mw.Api.saveOption('gadget-night-mode', inNightMode ? '0' : '1').then(function {			location.reload;		}); }); });