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); Api.get({ action: 'query',  prop: 'revisions',  rvprop: 'content',  titles: page,  cb: new Date.getTime  }) .done(function(d) {   if (!d.error) {      for (var i in d.query.pages) {        if (d.query.pages[i].revisions) {          content = d.query.pages[i].revisions[0]["*"];          $('#wpTextbox1').val(content);        }        else {          alert(page + ' does not exist or is blank!');        }      }    }    else {      alert('Failed to get contents of ' + page + ': ' + d.error.code);    }  }) .fail(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); }, 5000);     }      else {        alert('Failed to submit edit for ' + page + ': ' + d.error.code);      }    }) .fail(function {     alert('Failed to submit edit for ' + page);    }); }); }