User:2NumForIce/Tools/ToggleNewWikitextEd.js

/* * Tool for toggling between the old and new ("2017") editors, if you need both. * Doesn't work while editing though, for now (still need to figure out action=submit.)

// Get whether new editor is enabled mw.loader.using(['user.options', 'mediawiki.api']); const isNewEditorEnabled = mw.user.options.get('visualeditor-newwikitext');

if (!isNewEditorEnabled) { var portletText = "new"; } else { var portletText = "old"; }

// Make function function toggleNewEditor { mw.notify('Switching the editor (page will reload automatically)', {type: 'info', tag: 'toggle-new-wikitext-ed', autoHide: false}); new mw.Api.saveOption('visualeditor-newwikitext', +!isNewEditorEnabled); setTimeout( => {		let newUrl = window.location.href;   		if (newUrl.indexOf('?') > -1){			newUrl += '&';		} else {			newUrl += '?';		}		newUrl += 'toggled_wt_ed=' + isNewEditorEnabled;		window.location.href = newUrl;	}, 1000); }

// Notification after reloading const searchParams = new URLSearchParams(window.location.search); if (searchParams.has('toggled_wt_ed')) { if (isNewEditorEnabled != searchParams.get('toggled_wt_ed')) { mw.notify('Switched from ' + portletText + ' editor.', {type: 'success', tag: 'toggle-new-wikitext-ed'}); } else { mw.notify('Could not switch from ' + portletText + ' editor.', {type: 'error', tag: 'toggle-new-wikitext-ed'}); } }

// Portlet mw.util.addPortletLink('p-tb', 'javascript:toggleNewEditor;',					  "Use " + portletText + " editor", 't-toggle-new-wikitext-editor',					   'Toggle between new and old wikitext editors', null, '#t-whatlinkshere' );