User:MetalManeMc/vector.js: Difference between revisions
Jump to navigation
Jump to search
MetalManeMc (talk | contribs) mNo edit summary |
MetalManeMc (talk | contribs) No edit summary |
||
Line 34: | Line 34: | ||
if (isUsingDarkmode === true) { | if (isUsingDarkmode === true) { | ||
$('body').addClass('theme-dark-grey') | |||
$('body').removeClass('theme-light') | |||
} else { | } else { | ||
$('body').addClass('theme-light') | $('body').addClass('theme-light') |
Revision as of 17:32, 19 December 2023
/**
* Toggle for dark mode testing
*
* @author [https://minecraft.wiki/w/User:Jayden] for https://minecraft.wiki
* adapted by [[User:MetalManeMc]] for use on the Baldur's Gate 3 Wiki
* @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
*/
;(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,
$('#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) {
$('body').addClass('theme-dark-grey')
$('body').removeClass('theme-light')
} else {
$('body').addClass('theme-light')
$('body').removeClass('theme-dark-grey')
}
});
}
}
$(self.init);
}(jQuery, mediaWiki));