User:Theleekycauldron/Million award checker.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.
try {
	let api = new mw.Api();
} catch (SyntaxError) {}
function httpGet(theUrl) { //from StackOverflow; puts a GET request to an API (we'll use it to query pageviews)
    var xmlHttp = new XMLHttpRequest(); //it does stuff
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return xmlHttp.responseText;
}
function getPage(article){
	jsonobj = JSON.parse(httpGet("https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/user/"+article.replaceAll(/ /g,"_").replaceAll(/ /g,"_").replaceAll("/","%2F").replaceAll("?","%3F")+"/daily/2021010100/2021123100"));
   sum = 0
   for (item of jsonobj.items){
     sum += item.views
   }
   return sum
}