User:MetalManeMc/vector.js: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
(back to when it half-worked)
Tag: Manual revert
Line 5: Line 5:


portletLink = mw.util.addPortletLink(
portletLink = mw.util.addPortletLink(
    'p-personal',
'p-personal',
    '',
'',
    '',
'',
    'pt-dm-toggle',
'pt-dm-toggle',
    'Preview in light 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.isAnon()) {
if (mw.user.options.get('theme')==='dark-grey') {
        if (mw.cookie.get('theme',null,'dark-grey')==='dark-grey') {
var params = {
            mw.cookie.set('theme','light');
action: 'options',
            mw.loader.using(['ext.gadget.theme-light']).then(function() {
change: 'theme=light',
                $('body').addClass('theme-light');
format: 'json'
                $('body').removeClass('theme-dark-grey');
};
            });
$('body').addClass('theme-light')
        }
$('body').removeClass('theme-dark-grey')
        else {
}
            mw.cookie.set('theme','dark-grey');
else {
            $('body').addClass('theme-dark-grey');
var params = {
            $('body').removeClass('theme-light');
action: 'options',
        }
change: 'theme=dark-grey',
    }
format: 'json'
    else {
};
         if (mw.user.options.get('userjs-theme','dark-grey')==='dark-grey') {
         mw.loader.using(['ext.darkvector']).then(function() {
            new mw.Api().saveOption('userjs-theme','light').then(function() {
        $('body').addClass('theme-dark-grey');
                mw.user.options.set('userjs-theme','light');
        $('body').removeClass('theme-light');
                $('body').addClass('theme-light');
        });
                $('body').removeClass('theme-dark-grey');
}
            });
new mw.Api().postWithToken( 'csrf', params ).done( function ( data ) {});
        }
        else {
            new mw.Api().saveOption('userjs-theme','dark-grey').then(function() {
                mw.user.options.set('userjs-theme','dark-grey');
                mw.loader.using(['ext.gadget.darkvector']).then(function() {
                $('body').addClass('theme-dark-grey');
                $('body').removeClass('theme-light');
                });
            });
        }
    }
});
});

Revision as of 15:55, 2 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 ) {});
});