MediaWiki:Common.js: Difference between revisions
Appearance
Cdjensen94 (talk | contribs) |
Cdjensen94 (talk | contribs) |
||
| Line 1: | Line 1: | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
const el = document.getElementById( | const el = document.getElementById('article-countdown'); | ||
console.log('countdown hook fired; element is:', el); | |||
if (!el) return; | if (!el) return; | ||
el.textContent = '✅ Countdown JS is running…'; | |||
const apiUrl = mw.util.wikiScript('api') + | |||
'?action=query&meta=siteinfo&siprop=statistics&format=json&origin=*'; | |||
const apiUrl = | |||
fetch(apiUrl) | fetch(apiUrl) | ||
.then( | .then(r => r.json()) | ||
.then( | .then(d => { | ||
const current = | const current = d.query.statistics.articles; | ||
const goal = 1000; | const goal = 1000; | ||
const left = goal - current; | const left = goal - current; | ||
| Line 21: | Line 21: | ||
}) | }) | ||
.catch(err => { | .catch(err => { | ||
el.textContent = | el.textContent = 'API request failed (see console).'; | ||
console.error(err); | console.error(err); | ||
}); | }); | ||
}); | }); | ||
// MediaWiki:Common.js | // MediaWiki:Common.js | ||