User:MetalManeMc/vector.js

From bg3.wiki
Revision as of 10:13, 20 December 2023 by MetalManeMc (talk | contribs)
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
 * Inspired from https://minecraft.wiki/w/MediaWiki:Gadget-darkmode.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();
				console.error(mw.user.options.get('theme'));
				if (mw.user.options.get('theme')==='dark-grey') {
					var params = {
						action: 'options',
						change: 'theme=light',
						format: 'json'
					},
					api = new mw.Api();
					$('body').addClass('theme-light')
					$('body').removeClass('theme-dark-grey')
				}
				else {
					var params = {
						action: 'options',
						change: 'theme=dark-grey',
						format: 'json'
					},
					api = new mw.Api();
                	mw.loader.using(['ext.gadget.theme-light']).then(function() {
                    	$('body').addClass('theme-light');
                    	$('body').removeClass('theme-dark-grey');
                	});
				}
				api.postWithToken( 'csrf', params ).done( function ( data ) {});
				
			});