Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

User:Willowisp/vector.js

< User:Willowisp
Revision as of 11:47, 23 January 2024 by Willowisp (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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
 * Based on the version of this gadget that was created by user MetalManeMc, see https://bg3.wiki/wiki/User:MetalManeMc/vector.js
 * which was based on https://minecraft.wiki/w/MediaWiki:Gadget-darkmode.js
 * which was itself based on https://minecraft.wiki/w/MediaWiki:Gadget-darkmode.js
 * Original author: Jayden
 * @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
 */

portletLink = mw.util.addPortletLink(
				'p-personal',
				'',
				'',
				'pt-dm-toggle',
				'Preview in light mode',
				null,
				$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
			);
			
$(portletLink).find('a').click(function(e) {
	e.preventDefault();
	if (mw.user.options.get('theme')==='dark-grey') {
		var params = {
			action: 'options',
			change: 'theme=light',
			format: 'json'
		};
		$('body').addClass('theme-light')
		$('body').removeClass('theme-dark-grey')
	}
	else {
		var params = {
			action: 'options',
			change: 'theme=dark-grey',
			format: 'json'
		};
        mw.loader.using(['ext.darkvector']).then(function() {
        	$('body').addClass('theme-dark-grey');
        	$('body').removeClass('theme-light');
        });
	}
	new mw.Api().postWithToken( 'csrf', params ).done( function ( data ) {});
});