User:Alfa80/XTools/XTools.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
var xpagehistory = {
  loadinganimation : 0,
  execute : function () {
  	if (mw.config.get('wgArticleId') === 0) return; // no deleted articles, no special pages
  	if (mw.config.get('wgCurRevisionId') != mw.config.get('wgRevisionId')) return; // only current revision
  	$("<div id='xtools' style='font-size:84%; line-height:1.2em; margin:0 0 0.4em 0.2em; width:auto;'><span id='xtoolsresult'></span><span id='xtoolsloading'>.</span></div>").insertBefore("#contentSub");
  	loadinganimation = window.setInterval( function() { if ($("#xtoolsloading").html() == ".&nbsp;&nbsp;") $("#xtoolsloading").html("&nbsp;.&nbsp;"); else if ($("#xtoolsloading").html() == "&nbsp;.&nbsp;") $("#xtoolsloading").html("&nbsp;&nbsp;."); else $("#xtoolsloading").html(".&nbsp;&nbsp;"); }, 300);
  	mw.loader.load("//tools.wmflabs.org/xtools/api.php?pageid=" +  mw.config.get('wgArticleId') + "&project=fa.wikipedia.org");
  },
  resultloaded : function( res ) {
  	$("#xtoolsresult").html(res);
  	this.stoploading();
  },
  stoploading : function() {
  	clearInterval(loadinganimation);
  	$('#xtoolsloading').remove();
  }
}
if ( (mw.config.get('wgAction') == "view") ) $( xpagehistory.execute );