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: You might have to refresh to get it to show sometimes
 * @author Ozuzanna
 * @TODO fix show changes


 * (function($, mw) {

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').replace('$1', 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);    }); }); }

}) (this.jQuery, this.mediaWiki);