MediaWiki:Gadget-darkmode.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Created page with ";(function($, mw){ var DARK_COOKIE = 'darkmode', THEME_COOKIE = 'theme', isUsingDarkmode = $.cookie(THEME_COOKIE) === 'dark' || ($.cookie(THEME_COOKIE) == null && $.cookie(DARK_COOKIE) === 'true'), portletLink; var self = { init: function () { $.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'}); portletLink = mw.util.addPortletLink( 'p-personal', '', '', 'pt-dm-toggle', 'Toggle dark mode', null,...") |
mNo edit summary |
||
Line 14: | Line 14: | ||
'', |
'', |
||
'pt-dm-toggle', |
'pt-dm-toggle', |
||
' |
'Switch themes', |
||
null, |
null, |
||
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0] |
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0] |
Latest revision as of 11:46, 23 June 2024
;(function($, mw){
var DARK_COOKIE = 'darkmode',
THEME_COOKIE = 'theme',
isUsingDarkmode = $.cookie(THEME_COOKIE) === 'dark' || ($.cookie(THEME_COOKIE) == null && $.cookie(DARK_COOKIE) === 'true'),
portletLink;
var self = {
init: function () {
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
portletLink = mw.util.addPortletLink(
'p-personal',
'',
'',
'pt-dm-toggle',
'Switch themes',
null,
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
);
$(portletLink).find('a').click(function(e) {
e.preventDefault();
isUsingDarkmode = !isUsingDarkmode;
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
$.cookie(DARK_COOKIE, isUsingDarkmode, {expires: 365, path: '/'});
if (isUsingDarkmode === true) {
mw.loader.using(['wgl.theme.dark']).then(function() {
$('body').addClass('wgl-theme-dark')
$('body').removeClass('wgl-theme-light')
});
} else {
$('body').addClass('wgl-theme-light')
$('body').removeClass('wgl-theme-dark')
}
});
}
}
$(self.init);
}(jQuery, mediaWiki));