Jump to content

User:Nihiltres/Gadget-metadata.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.
var api = new mw.Api();
api.get({
	action: "query",
	prop: "pageassessments",
	titles: mw.config.get("wgPageName")
}).done(function (data) {
	var assessments = data.query.pages[mw.config.get("wgArticleId")].pageassessments;
	$.each(assessments, function (k, v) {
		//TODO: Rework to avoid hardcoded quality scale
		var classes = [
				"fa", "fl", "a", "ga", "bplus", "b", "c", "start", "stub",
				"al", "bl", "cl", "list", "sl", "dab", "sia", "cur", "future"
			], normed;
		if (assessments.hasOwnProperty(k)) {
			normed = typeof v["class"] == "string" &&
				v["class"].trim().toLowerCase();
			if (classes.indexOf(normed) !== -1) {
				ap.foundAssessment = normed;
				return false;
			}
		}
	});
});