User:Nettrom/common.js

// importScript('User:EpochFail/qualityviz/system.js'); // importScript("User:Another_Article/protostudy.js");

importScript("User:EpochFail/ArticleQuality.js")

ORES_HOST = "https://ores.wikimedia.org" MIN_PROBA = 0.15

var get_and_render_categories = function(in_namespaces){ // fetch page topics using ORES if the page is in a namespace // listed in in_namespaces (using namespace numbers) var revId = mw.config.get('wgCurRevisionId') var pageNs = mw.config.get('wgNamespaceNumber') if(!(pageNs in in_namespaces)) { // only show for selected namespaces return }	var url = ORES_HOST + "/v3/scores/enwiki/" + revId + "/articletopic" var parserOutputNode = $('.mw-parser-output') var topicsContainer = $(' ').addClass("page_topics") parserOutputNode.prepend(topicsContainer) var render_categories = function(data){ //console.log(["rendering", data]) var topics = [] var catProba = data.enwiki.scores[revId].articletopic.score.probability for (var cat in catProba) { //console.log(cat) if (catProba.hasOwnProperty(cat)) { var proba = catProba[cat] topics.push({topic: cat, proba: proba}) }		}		topics.sort(function(a, b){return b.proba - a.proba}) for (var i=0; i < Math.min(topics.length, 10); i++) { var topic = topics[i] console.log(["looping", topic]) if(topic.proba > MIN_PROBA){ topicsContainer.append(topic.topic + "(" + Math.round(topic.proba*100) + "%) ") }		}		topicsContainer.append($('').attr('href', url).text("more from ORES").css("font-size", "80%")) }	$.ajax(url, {success: render_categories.bind(this),		        error: function(jqxmlhr, status, error){console.log(status + ": " + error)}}) }

get_and_render_categories([0])