User:MetalManeMc/vector.js: Difference between revisions

From Baldur's Gate 3 Wiki
Jump to navigation Jump to search
No edit summary
(Undo revision 147274 by MetalManeMc (talk))
Tag: Undo
 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
/**
/**
  * Toggle for dark mode testing
  * Toggle for dark mode testing
  *  
  * Inspired from https://minecraft.wiki/w/MediaWiki:Gadget-darkmode.js
* @author [[User:Jayden]] for https://minecraft.wiki
* @author [[User:MetalManeMc]] for adaptation on Baldur's Gate 3 Wiki
* @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
  */
  */
;(function($, mw){
var DARK_COOKIE = 'darkmode',
THEME_COOKIE = 'test_theme',
isUsingDarkmode = $.cookie(THEME_COOKIE) === 'dark' || ($.cookie(THEME_COOKIE) == null && $.cookie(DARK_COOKIE) === 'true'),
portletLink;


var self = {
portletLink = mw.util.addPortletLink(
init: function () {
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
 
portletLink = mw.util.addPortletLink(
'p-personal',
'p-personal',
'',
'',
'',
'',
'pt-dm-toggle',
'pt-dm-toggle',
'Toggle dark mode',
'Preview in light mode',
null,
null,
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
);
);
$(portletLink).find('a').click(function(e) {
$(portletLink).find('a').click(function(e) {
e.preventDefault();
e.preventDefault();
if (mw.user.options.get('theme')==='dark-grey') {
isUsingDarkmode = !isUsingDarkmode;
var params = {
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
action: 'options',
$.cookie(DARK_COOKIE, isUsingDarkmode, {expires: 365, path: '/'});
change: 'theme=light',
format: 'json'
if (isUsingDarkmode === true) {
};
mw.loader.using(['wgl.theme.dark']).then(function() {
$('body').addClass('theme-light')
  $('body').addClass('wgl-theme-dark')
$('body').removeClass('theme-dark-grey')
  $('body').removeClass('wgl-theme-light')
});
} else {
$('body').addClass('wgl-theme-light')
$('body').removeClass('wgl-theme-dark')
}
});
}
}
}
else {
$(self.init);
var params = {
 
action: 'options',
}(jQuery, mediaWiki));
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 ) {});
});

Latest revision as of 17:16, 27 January 2024

/**
 * 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();
	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 ) {});
});