Diferencia entre revisiones de «MediaWiki:Gadget-show-quality-on-cats.js»
Ir a la navegación
Ir a la búsqueda
m (try) |
m (tweak) |
||
Línea 1: | Línea 1: | ||
mw.hook('wikipage.content').add(function () { |
mw.hook('wikipage.content').add(function hook_handler() { |
||
const icons = { |
const icons = { |
||
Línea 24: | Línea 24: | ||
gcmlimit: "max", |
gcmlimit: "max", |
||
gcmtype: "page", |
gcmtype: "page", |
||
}).then(function (response) { |
}).then(function query_response(response) { |
||
console.debug(response) |
console.debug(response) |
||
if (response.continue) { |
|||
console.warn('gadget:', 'show-quality-on-cats', 'missing results', response) |
|||
} |
|||
const all = {} |
const all = {} |
||
response.query.pageids.forEach(function (id) { |
response.query.pageids.forEach(function each_pageid(id) { |
||
const page = response.query.pages[id] |
const page = response.query.pages[id] |
||
if (!page.categories) return |
if (!page.categories) return |
||
Línea 35: | Línea 38: | ||
}) |
}) |
||
document.querySelectorAll('#mw-pages a').forEach(function (el) { |
document.querySelectorAll('#mw-pages a').forEach(function each_link(el) { |
||
const title = el.getAttribute('title') |
const title = el.getAttribute('title') |
||
const cat = all[title] |
const cat = all[title] |
Revisión del 20:09 13 ago 2019
mw.hook('wikipage.content').add(function hook_handler() { const icons = { 'Stubs': [0x25D4], 'Partially complete articles': [0x25D2], 'Articles nearing completion': [0x25D5], 'Complete articles': [0x26AB, 0xFE0E], } // only on categories if (mw.config.get('wgCanonicalNamespace') != 'Category') return console.warn('gadget:', 'show-quality-markers') ;(new mw.Api).get({ action: "query", format: "json", prop: "categories", indexpageids: true, cllimit: "max", clcategories: Object.keys(icons).map(function(cat) { return 'Category:'+ cat }), generator: "categorymembers", gcmtitle: mw.config.get('wgPageName'), gcmlimit: "max", gcmtype: "page", }).then(function query_response(response) { console.debug(response) if (response.continue) { console.warn('gadget:', 'show-quality-on-cats', 'missing results', response) } const all = {} response.query.pageids.forEach(function each_pageid(id) { const page = response.query.pages[id] if (!page.categories) return all[page.title] = page.categories[0].title.replace('Category:','') }) document.querySelectorAll('#mw-pages a').forEach(function each_link(el) { const title = el.getAttribute('title') const cat = all[title] if (!cat) return const icon = String.fromCodePoint.apply(null, icons[cat]) el.parentElement.append(icon) }) }) // end of API query }) // end of MW hook