User:RCSDevs/rank.js

$(document).ready(function {	var tab = $('#ca-nstab-main');	//Ensure the current page is an actual article	if(tab.length && tab.attr('class') === 'selected')	{		var goodIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTCtCgrAAAAEH0lEQVQ4T4WUD0wUVBzH3x3cH5C/8qfTA5ERMBCygxunEh5keQqIFHkc3Z+O4/inHQ5CMWKDNA04yUG4WOrIZeomE1kOQ6uJZpYZzbUlUgxzrmCrZqxaMbhvv/cYDTLWb/tsb7/33me/95ctEksIB9FH3CemiSlijDhNGAk58b8hIezEOJMxsGQJ5FvlCHc+gtCSMHhle4PFS8C8qI+xUSKHWDRkRDeTMnjrZcg5novOLw/jo7sfY/DeoODi2EW4P3dD/1YmJKlSLvUQ+wheyILgiW6mYAh1haHtxhs4e6cXZ77pwdmRXtEWUHsut/faPgTYAsELoLlNwjIv7LxDUa7E/k8PoLm/BeoYNby8vWCwGXD01jG8PXQEuk06SKVSxGpi0X6lA41XmyArlHPhDJElTBT8AMZZhgT69zJpSQeRlpfGB/1D9Yka2N32BTlDmUGM1Z/MBEuifWXsFiGWXiwOoFEKU18RXh6shyZPs2Cy83gptjUbF+T0ZZlirPW8DaxG7CfnSYKd46fJWqTY0pOH8oEKWE5aoUpWQRmoRKpNK3JlF8qRkJsIhb8CK9asgKO3ROSNfYViLosQwg4uvM9yZ4VJxx7Dtj6jGGR63wRzvxnWCxbYBqwC3uY53sfH8LFr3103K3xCLPsTLpxm5lmhss0XEVkRdGUMsA2aUPqZFZU37dgx5BBUfmGH87oF1suF2NCRhZV50QhqXzorzBHC77hwiguV7Uos6w4V1+CptnS4hm3Y/b0TDT9WonFih6DhhwrsuuvEi7et0L2kgXeYF1TvhEB+SAGWLYQjXDimyJcj6p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EDDGnkGZKk9QMeAAeas6V6J5lITvXrHDauHEUwwmzBeslOIDhEUA/5KEdfJ85gBnUtNeuSMCTdeNKL9xLDYGvwEBTlaS04SFo9m4b6vAA8Ch/Bv4LAG8/syK/aas5NiM6OZmQbbBb8aq3EyctUuG847duDC86kazFnj3RcO39kjy9wuYr8AHgNeJ37+eWg3/wI2NuBhKPUfHZxfMnRRQ04AAAAASUVORK5CYII='; selectedIcon = '', currentURL = decodeURIComponent(tab.find('span a').eq(0).attr('href')), title = currentURL.substring(currentURL.indexOf('/wiki/') + 6), params = { //Define parameters for call to MediaWiki API (https://www.mediawiki.org/wiki/API) action: 'query', prop: 'revisions', rvlimit: '50', format: 'json', titles: title, rvprop: 'user|ids|comment' };		//Send request with JSON callback $.getJSON('https://en.wikipedia.org/w/api.php', params, function(json)		{			var pages = json.query.pages,				//Unfortunatley, there is no tag for revisions that have been reverted/undone				revs = pages[Object.keys(pages)[0]].revisions;				ids = "",				nparams = {},				flag = 0;			revs.forEach(function(rev) { ids += (rev.revid + '|'); });			ids = ids.slice(0, -1);			nparams = {				models: 'goodfaith|damaging',				revids: ids			};			$.getJSON('https://ores.wikimedia.org/v2/scores/enwiki', nparams, function(json) {				var enwiki = json.scores.enwiki, score = 0; //Get an array of revision ids to iterate over. The order doesn't matter because the rev id will be present in both arrays Object.keys(enwiki.damaging.scores).forEach(function(id)				{					score += enwiki.damaging.scores[id].probability.false;					score += enwiki.goodfaith.scores[id].probability.true;				});

/*					Not all articles will have 50 revisions, so to find the average divide by 2x the number of revisions found (because we add a number to the score 2x per revision) */				score /= (revs.length * 2); //Print score to console for debug purposes console.info("There is a " + (score * 100) + "% chance this article is a good one."); //Only show a bad article if it has a score <= 10% if(score <= 0.1) {					selectedIcon = badIcon; }				//Only show a good article if it has a score >= 80% else if(score >= 0.8) {					selectedIcon = goodIcon; }				//Only append an rating indicator if an article is very good or very bad if(selectedIcon.length !== 0) {					var icon = '  '; $('.mw-indicators').eq(0).prepend(icon); }			});		});	} });