User:MetalManeMc/vector.js: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:
  * Toggle for dark mode testing
  * Toggle for dark mode testing
  *  
  *  
  * @author [https://minecraft.wiki/w/User:Jayden] for https://minecraft.wiki
  * @author [[User:MetalManeMc]] for use on the Baldur's Gate 3 Wiki
* adapted by [[User:MetalManeMc]] for use on the Baldur's Gate 3 Wiki
* @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
  */
  */
;(function($, mw){
var DARK_COOKIE = 'darkmode',
THEME_COOKIE = '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]
Line 28: Line 17:
$(portletLink).find('a').click(function(e) {
$(portletLink).find('a').click(function(e) {
e.preventDefault();
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();
}
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
});
isUsingDarkmode = !isUsingDarkmode;
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
$.cookie(DARK_COOKIE, isUsingDarkmode, {expires: 365, path: '/'});
if (isUsingDarkmode === true) {
$('body').addClass('theme-dark-grey')
$('body').removeClass('theme-light')
} else {
$('body').addClass('theme-light')
$('body').removeClass('theme-dark-grey')
}
});
});
}
}
$(self.init);
}(jQuery, mediaWiki));

Revision as of 18:21, 19 December 2023

/**
 * Toggle for dark mode testing
 * 
 * @author [[User:MetalManeMc]] for use on the Baldur's Gate 3 Wiki
 */

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();
					}
				api.postWithToken( 'csrf', params ).done( function ( data ) {
					console.log( data );
				});
				
			});