User:Skynxnex/VitalTopicon.js

// Copy of User:Nardog/VitalTopicon.js to allow my own experiments

// Shows a topicon when viewing a vital article.

mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view' && mw.loader.using('mediawiki.api').then( => ( new mw.Api.get({		action: 'query',		titles: 'Talk:' + mw.config.get('wgTitle'),		prop: 'categories',		clcategories: 'Category:Wikipedia level-1 vital articles|Category:Wikipedia level-2 vital articles|Category:Wikipedia level-3 vital articles|Category:Wikipedia level-4 vital articles|Category:Wikipedia level-5 vital articles|Category:Wikipedia level-unknown vital articles',		formatversion: 2,		maxage: 86400,		smaxage: 86400	}) )).then(response => {	let cat = (((((response || {}).query || {}).pages || [])[0] || {}).categories || [])[0];	if (!cat) return;	let level = cat.title.match(/^Category:Wikipedia level-(.+) vital articles$/)[1];	let $icon = $(' ').attr({ id: 'mw-indicator-vital-article', class: 'mw-indicator' }).append( $('').attr({			href: `/wiki/Wikipedia:Vital_articles${['3', 'unknown'].includes(level) ? '' : '/Level/' + level}`,			title: `This is a level-${level} vital article.`		}).append(			$(' ').attr({ alt: `Vital article (level ${level})`, src: '//upload.wikimedia.org/wikipedia/commons/1/13/C%C3%ADrculos_Conc%C3%A9ntricos.svg', width: 20, height: 20 })		).append(` L${level} `) );	mw.hook('wikipage.indicators').fire($icon);	$( => { $('.mw-indicators').prepend($icon, '\n'); }); });