Jump to content

User:MusikAnimal/xtools.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 21:57, 1 August 2017. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(function () {
  if (mw.config.get('wgArticleId') === 0 || // no deleted articles, no special pages
      mw.config.get('wgCurRevisionId') !== mw.config.get('wgRevisionId') || // only current revision
      mw.config.get('wgAction') !== 'view') {
    return;
  }

  var markup = "<div id='xtools' style='font-size:84%; line-height:1.2em; margin:0 0 0.4em 0.2em; " +
    "width:auto;'><span id='xtools_result'>.</span></div>";
  $(markup).insertBefore('#contentSub');

  var loadinganimation = window.setInterval(function () {
    if ($('#xtools_result').text() === '.&nbsp;&nbsp;') {
      $('#xtools_result').text('&nbsp;.&nbsp;');
    } else if ($('#xtools_result').text() == '&nbsp;.&nbsp;') {
      $('#xtools_result').text('&nbsp;&nbsp;.');
    } else {
      $('#xtools_result').text('.&nbsp;&nbsp;');
    }
  }, 300);

  mw.loader.load(
    '//tools.wmflabs.org/xtools/api.php?pageid=' +  mw.config.get('wgPageName') +
    '&project=' + mw.config.get('wgServerName') +
    '&uselang=' + mw.config.get('wgContentLanguage')
  ).done(function (result) {
    $('#xtools_result').html(result);
    clearInterval(loadinganimation);
  });
});