User:Rcsprinter123/pageviews.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Rcsprinter123/pageviews. |
(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=wiki.riteme.site&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>`)
}
})
})()