User:Ozuzanna/noSyntaxHighlight.js

/*
 * No Syntax Highlight
 * @description when editing a MW or User JS/CSS page, it will emulate editing a page normally, just like before it got cruelly imposed on us
 * NOTE: When editing the same page in a short space of time, you might want to Ctrl+F5 to force new page revision as sometimes it won't be like that by default
 * @author Ozuzanna
 * @TODO fix show changes

if ((mw.config.get('wgCanonicalNamespace') === "User" || mw.config.get('wgCanonicalNamespace') === "MediaWiki") && mw.config.get('wgAction') === "view" && (mw.config.get('wgTitle').indexOf('.css') !== -1 || mw.config.get('wgTitle').indexOf('.js') !== -1) && $('#ca-edit').length) $('#ca-edit').attr('href',mw.config.get('wgArticlePath').slice(0,-2) + mw.config.get('wgPageName') + '/surrogate?action=edit&nosyntaxhighlight=1');

if (mw.config.get('wgAction') == "edit" && mw.config.get('wgPageName').indexOf('/surrogate') !== -1 && $.getUrlVar('nosyntaxhighlight') == 1) { var page = mw.config.get('wgPageName').slice(0,-10), Api = new mw.Api, articlePath = mw.config.get('wgArticlePath').slice(0,-2), content; document.title = document.title.replace('/surrogate',''); $('#EditPageHeader > h1:nth-child(3) > a:nth-child(1)') .text(page) .attr('href',articlePath + page) .attr('title',page); $.ajax({     url: '/index.php',      type: 'GET',      data: {          format: 'json',          title: page,          action: 'raw',          allinone: 1,          nocache: 1      },      success: function(d) {        if (!d.error) {          content = d;          $('#wpTextbox1').val(d);        }        else {          alert('Failed to get contents of ' + page + ': ' + d.error.code);        }      },      error: function {        alert('Failed to get contents of ' + page);      }  });

$('#wpSave').click(function(e) {   e.preventDefault;

Api.post({   action: 'edit',    watchlist: 'nochange',    title: page,    summary: $('#wpSummary').val || ,    nocreate: ,    text: $('#wpTextbox1').val,    bot: true,    token: mw.user.tokens.get('editToken')    }) .done(function(d) {     if (!d.error) {        $('#wpTextbox1').val('');        setTimeout(function { location.replace(articlePath + page); }, 1000);     }      else {        alert('Failed to submit edit for ' + page + ': ' + d.error.code);      }    }) .fail(function {     alert('Failed to submit edit for ' + page);    }); }); }