MediaWiki:Gadget-dark-mode-toggle.js: Difference between revisions
Content deleted Content added
Line 18:
$.when($.ready, mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Uri', 'mediawiki.storage', 'es6-polyfills'])).then(function () {
var isOn =
if (isOn) {
Line 34:
var tooltip = mw.msg('darkmode-turn-' + onOrOff + '-tooltip');
var nextnode = mw.config.get('skin') !== 'minerva' && '#pt-watchlist';
mw.util.addPortletLink('p-personal', '#', label, 'pt-darkmode', tooltip, '', nextnode);
mw.util.addPortletLink('p-personal-sticky-header', '#', label, 'pt-darkmode-sticky-header', tooltip, '', nextnode + '-sticky-header');
function toggleMode(offline) {
isOn = !isOn;
var newState = Number(isOn);
if (!offline) {
// Broadcast state change to other tabs
broadcastChannel.postMessage(isOn);
}
$(document.documentElement).toggleClass('client-dark-mode', isOn);
// In case the user navigates to another page too quickly
Line 53 ⟶ 60:
$('#pt-darkmode a, #pt-darkmode-sticky-header a').attr('title', mw.msg('darkmode-turn-' + onOrOff + '-tooltip'));
// Update the mobile theme-color
$('meta[name="theme-color"]').attr('content',
// Modify the <link> element on the page to include/exclude dark-mode styles
Line 61 ⟶ 68:
if ($gadgetsLink.length) {
var uri = new mw.Uri($gadgetsLink.prop('href'));
if (
uri.query.modules += ',dark-mode';
} else {
Line 92 ⟶ 99:
var storageState = mw.storage.session.get('dark-mode-toggled');
if (storageState && Number(storageState) !== Number(isOn)) {
toggleMode(true);
}
// Listen to dark mode state change made on other tabs
broadcastChannel.onmessage = function (msg) {
if (msg.data !== isOn) {
toggleMode(true);
}
};
if (window.wpDarkModeAutoToggle) {
Line 99 ⟶ 116:
var systemSchemeNow = matchMedia('(prefers-color-scheme: dark)').matches;
var systemSchemeLast = mw.storage.get('dark-mode-system-scheme') === '1';
▲ var wpSchemeNow = !!mw.user.options.get('gadget-dark-mode');
if (systemSchemeNow !== systemSchemeLast) {
if (systemSchemeNow !==
toggleMode();
}
|