Jump to content

User:Qwerfjkl/scripts/VEtoggle.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.loader.using(['user.options', 'mediawiki.api']).then(function() {
 
$( document ).ready( function () { 
   if (!mw.user.options.get('visualeditor-betatempdisable')) { // not disabled i.e. enabled
        var link = mw.util.addPortletLink( 'p-tb', '#', 'Disable VE', 'tb-disableVE', 'Enable the "temporarily disable VE" preference'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            new mw.Api().saveOption('visualeditor-betatempdisable', 1); // enable
            window.location.reload();
        } );
    }
   if (mw.user.options.get('visualeditor-betatempdisable')) { // disabled VE
        var link2 = mw.util.addPortletLink( 'p-tb', '#', 'Enable VE', 'tb-ensableVE', 'Disable the "temporarily disable VE" preference'); 
        $( link2 ).click( function ( event ) {
            event.preventDefault();
            new mw.Api().saveOption('visualeditor-betatempdisable', 0); // disable
            window.location.reload();
        } );
    }

 } );
});