Diferencia entre revisiones de «MediaWiki:Gadget-show-quality-on-cats.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (oops)
m (oops)
Línea 1: Línea 1:
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {

const icons = {
'Stubs': [0x25D4],
'Partially complete articles': [0x25D2],
'Articles nearing completion': [0x25D5],
'Complete articles': [0x26AB, 0xFE0E],
}


// only on categories
// only on categories
Línea 17: Línea 24:
gcmtype: "page",
gcmtype: "page",
}).then(function (response) {
}).then(function (response) {
const all = {};
response.query.pageids.forEach(function (id) {
const page = response.query.pages[id];
all[page.title] = page.categories.map(function(o){ return o.title});
})
console.log(all)


const all = {};
})
response.query.pageids.forEach(function (id) {
const page = response.query.pages[id];
all[page.title] = page.categories.map(function(o){ return o.title.replace('Category:','') });
})

document.querySelectorAll('#mw-pages a').forEach(el) {
Object.keys(icons).forEach(function (cat) {
const title = el.getAttribute('title')
const data = all[title]
if (!data.categories.includes(cat)) { continue }
console.log(title, 'is a', cat)
})
})

})


})
})

Revisión del 06:59 13 ago 2019

mw.hook('wikipage.content').add(function () {

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",
  generator: "categorymembers",
    gcmtitle: mw.config.get('wgPageName'),
    gcmlimit: "max",
    gcmtype: "page",
}).then(function (response) {

const all = {};
response.query.pageids.forEach(function (id) {
  const page = response.query.pages[id];
  all[page.title] = page.categories.map(function(o){ return o.title.replace('Category:','') });
})

document.querySelectorAll('#mw-pages a').forEach(el) {
Object.keys(icons).forEach(function (cat) {
  const title = el.getAttribute('title')
  const data = all[title]
  if (!data.categories.includes(cat)) { continue }
  console.log(title, 'is a', cat)
})
})

})


})