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. |
This user script seems to have a documentation page at User:Enterprisey/parent-cats. |
$( function () {
mw.loader.using( [ "mediawiki.api", 'mediawiki.util' ], function () {
var api = new mw.Api();
var catsOnPage = mw.config.get('wgCategories');
for(var cat of catsOnPage) {
// check if any categories on this page are parents of this category
api.get({formatversion:2, prop:'categories', titles:'Category:' cat})
.then(function(data){
var parents=data.query.pages[0].categories.map(c => c.title);
var actualCat = data.query.pages[0].title.substring('Category:'.length);
for(var catOnPage of catsOnPage) {
if(parents.indexOf('Category:' catOnPage) >= 0){
// tag parent with child
$('a[href$="Category:' catOnPage '"]')
.css({'background-color':'pink'})
.text(catOnPage ' (parent of ' actualCat ')')
// tag child with parent
$('a[href$="Category:' actualCat '"]')
.css({'background-color':'pink'})
.text(actualCat ' (child of ' catOnPage ')')
}
}
});
}
});
});