User:MetalManeMc/vector.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/**
* Toggle for dark mode testing
*
* @author [[User:Jayden]] for https://minecraft.wiki
* @author [[User:MetalManeMc]] for adaptation on Baldur's Gate 3 Wiki
* @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
*/
;(function($, mw){
var LIGHT_COOKIE = 'lightmode',
THEME_COOKIE = 'theme',
isUsingLightmode = $.cookie(THEME_COOKIE) === 'light' || ($.cookie(THEME_COOKIE) == null && $.cookie(LIGHT_COOKIE) === 'true'),
portletLink;
var self = {
init: function () {
$.cookie(THEME_COOKIE, isUsingLightmode ? 'light' : 'dark', {expires: 365, path: '/'});
portletLink = mw.util.addPortletLink(
'p-personal',
'',
'',
'pt-dm-toggle',
'Toggle light mode',
null,
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
);
$(portletLink).find('a').click(function(e) {
e.preventDefault();
isUsingLightmode = !isUsingLightmode;
$.cookie(THEME_COOKIE, isUsingLightmode ? 'dark' : 'light', {expires: 365, path: '/'});
$.cookie(LIGHT_COOKIE, isUsingLightmode, {expires: 365, path: '/'});
if (isUsingLightmode === true) {
mw.loader.using(['theme-light']).then(function() {
$('body').addClass('theme-light')
$('body').removeClass('theme-dark-grey')
});
} else {
$('body').addClass('theme-dark-grey')
$('body').removeClass('theme-light')
}
});
}
}
$(self.init);
}(jQuery, mediaWiki));