MediaWiki:Gadget-themetoggler.js

mw.loader.getScript( 'https://dev.fandom.com/index.php?title=MediaWiki:WDSIcons/code.js&action=raw&ctype=text/javascript' );

$(function {   if (mw.config.get('skin') !== 'fandomdesktop' || window.ThemeTogglerLoaded) return;	window.ThemeTogglerLoaded = true;	mw.hook('dev.wds').add(function(wds) { $('.page-side-tools').append(' '); $('.skin-theme-toggle').append( wds.icon('eye-small') ); $('.page-side-tools').append(' '); $('.skin-theme-toggle-temporal').append( wds.icon('clock-small') ); function toggleWithoutReload { var theme = $('body').hasClass('theme-fandomdesktop-light') ? 'light' : 'dark'; var newTheme = theme === 'light' ? 'dark' : 'light'; // Implementation by User:Pcj from ThemeSwitcher $.get(mw.util.wikiScript('wikia')+'?controller=ThemeApi&method=themeVariables&variant='+newTheme+'&cb='+(new Date.getTime)).done(function(data) {	 		var $s = $('#pcjThemeSwitch')[0] || $(' ').attr('id','pcjThemeSwitch').appendTo('body');	       	$($s).text(data);	        	$('body').removeClass('theme-fandomdesktop-light theme-fandomdesktop-dark').addClass('theme-fandomdesktop-'+newTheme);			}); }	   var api = new mw.Api; $('.skin-theme-toggle').click( function {			var theme = $('body').hasClass('theme-fandomdesktop-light') ? 'light' : 'dark';			var newTheme = theme === 'light' ? 'dark' : 'light';			toggleWithoutReload;	       api.postWithToken( 'csrf', { action: 'options', optionname: 'theme', optionvalue: newTheme } );	    } ) $('.skin-theme-toggle-temporal').click( function {			toggleWithoutReload;		} ) }); });