User:MetalManeMc/vector.js: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 14: Line 14:
);
);
$(portletLink).find('a').click(function(e) {
$(portletLink).find('a').click(function(e) {
e.preventDefault();
e.preventDefault();
console.error(mw.user.options.get('theme'));
console.error(mw.user.options.get('theme'));
if (mw.user.options.get('theme')==='dark-grey') {
if (mw.user.options.get('theme')==='dark-grey') {
var params = {
var params = {
action: 'options',
action: 'options',
change: 'theme=light',
change: 'theme=light',
format: 'json'
format: 'json'
};
};
$('body').addClass('theme-light')
$('body').addClass('theme-light')
$('body').removeClass('theme-dark-grey')
$('body').removeClass('theme-dark-grey')
}
}
else {
else {
var params = {
var params = {
action: 'options',
action: 'options',
change: 'theme=dark-grey',
change: 'theme=dark-grey',
format: 'json'
format: 'json'
};
};
                mw.loader.using(['ext.gadget.theme-light']).then(function() {
        mw.loader.using(['ext.gadget.theme-light']).then(function() {
                    $('body').addClass('theme-light');
        $('body').addClass('theme-light');
                    $('body').removeClass('theme-dark-grey');
        $('body').removeClass('theme-dark-grey');
                });
        });
}
}
new mw.Api().postWithToken( 'csrf', params ).done( function ( data ) {});
new mw.Api().postWithToken( 'csrf', params ).done( function ( data ) {});
});
});

Revision as of 12:06, 20 December 2023

/**
 * 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'
		};
		$('body').addClass('theme-light')
		$('body').removeClass('theme-dark-grey')
	}
	else {
		var params = {
			action: 'options',
			change: 'theme=dark-grey',
			format: 'json'
		};
        mw.loader.using(['ext.gadget.theme-light']).then(function() {
        $('body').addClass('theme-light');
        $('body').removeClass('theme-dark-grey');
        });
	}
	new mw.Api().postWithToken( 'csrf', params ).done( function ( data ) {});
});