User:Skynxnex/VitalTopicon.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Skynxnex/VitalTopicon. |
// Copy of [[User:Nardog/VitalTopicon.js]] to allow my own experiments
// Shows a [[mw:Help:Page status indicators|topicon]] when viewing a [[Wikipedia:Vital articles|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 = $('<div>').attr({
id: 'mw-indicator-vital-article',
class: 'mw-indicator'
}).append(
$('<a>').attr({
href: `/wiki/Wikipedia:Vital_articles${['3', 'unknown'].includes(level) ? '' : '/Level/' level}`,
title: `This is a level-${level} vital article.`
}).append(
$('<img>').attr({
alt: `Vital article (level ${level})`,
src: '//upload.wikimedia.org/wikipedia/commons/1/13/Círculos_Concéntricos.svg',
width: 20,
height: 20
})
).append(`<strong>L${level}</strong>`)
);
mw.hook('wikipage.indicators').fire($icon);
$(() => {
$('.mw-indicators').prepend($icon, '\n');
});
});