INFORMATION

Welcome to the Kingdom Hearts Database! 👑 We're always looking for more help! Be sure to check out our current projects and jump in on the action! 👑 Be sure to join our Discord server and meet our growing community!

MediaWiki:Gadget-darkMode.js

MediaWiki interface page

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
 * 
 * @author [[User:Jayden]]
 * @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js 
 *		and https://minecraft.wiki/w/MediaWiki:Gadget-darkmode.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 () {
			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) {
					mw.loader.using(['mediawiki.util', 'mediawiki.Title']).then(function() {
					  $('body').addClass('wgl-darkmode')
					  $('body').removeClass('wgl-lightmode')
					});
				} else {
					$('body').addClass('wgl-lightmode')
					$('body').removeClass('wgl-darkmode')
				}
			});
		}
	}
	
	$(self.init);

}(jQuery, mediaWiki));
Cookies help us deliver our services. By using our services, you agree to our use of cookies.