MediaWiki:MediaWikiBacklink/code.js

//MediaWikiBacklink - Count of Howard //26-12-16 - Initial revision $(function { //Cache mw variables  const mwVariables = mw.config.get([ 'skin', 'wgPageName', 'wgNamespaceNumber' ]); //Specifically meant for MW pages  if (mwVariables.wgNamespaceNumber !== 8) {    return;  }  //Works for most cases when Dev wiki conventions are followed; ex:  //MediaWiki:ExampleScript.js or MediaWiki:ExampleScript/code.js  const redacted = mwVariables.wgPageName.split(/:(.+)/)[1].split(/[\/.]+/)[0];  var html;  //Do the thing  new mw.Api.get({ action: 'query', list: 'backlinks', bltitle: mwVariables.wgPageName, blnamespace: 0, format: 'json' }).done(function(d) { if(!d.error) { var data = d.query.backlinks; for (var i in data) { if (data[i] && data[i].ns === 0 && data[i].title == redacted) { if (mwVariables.skin == 'oasis' || mwVariables.skin == 'wikia') { html = ' &lt; ' + data[i].title + ' | MediaWiki page '; $('#WikiaPageHeader .header-container .header-title h2').html(html); } else if (mwVariables.skin == 'monobook') { html = ' &lt; ' + '' + data[i].title + '  '; $(html).prependTo('#bodyContent'); }       }      }    }  }); });