User:EpochFail/DraftTopic.js

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

var get_and_render_categories = function{ var revId = mw.config.get('wgCurRevisionId') 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 = [] try { var catProba = data.enwiki.scores[revId].articletopic.score.probability } catch (e) { return; } 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