Jump to content

User:Rcsprinter123/pageviews.js

From Wikipedia, the free encyclopedia
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('wgAction') !== 'view') return;
  var infoPage = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'info', useLang: 'en' })
  $.ajax({
    url: infoPage,
    type: 'get',
    success: function (html) {
      var text = $(html).find('table').text()
      var monthlyViews = text.match(/Page views in the past 30 days(.+)/)
      var visitingwatchers = text.match(/Number of page watchers who visited recent edits(.+)/)
	  var floatRight = $('#coordinates').length === 0
      $('#siteSub').append(`<span style="font-size: 12px; ${floatRight ? 'float:right;':''}color: #969696;">
        ${monthlyViews ? `<a href="https://tools.wmflabs.org/pageviews/?project=en.wikipedia.org&range=latest-20&pages=${mw.config.get('wgPageName')}" style="color: black;">/ ${monthlyViews[1]} monthly views</a>`:''}${visitingwatchers && monthlyViews ? ',':''}
        ${visitingwatchers ? `<a href="${infoPage}" style="color: gray;">${visitingwatchers[1]} active watchers</a>`:''}
      </div>`)
    }
  })
})()