MediaWiki:Common.js: Difference between revisions
Appearance
Cdjensen94 (talk | contribs) |
Cdjensen94 (talk | contribs) |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
mw.hook('wikipage.content').add(function () { | |||
const el = document.getElementById('article-countdown'); | |||
.then( | console.log('countdown hook fired; element is:', el); | ||
.then( | |||
const current = | if (!el) return; | ||
const goal = | el.textContent = '✅ Countdown JS is running…'; | ||
const apiUrl = mw.util.wikiScript('api') + | |||
'?action=query&meta=siteinfo&siprop=statistics&format=json&origin=*'; | |||
fetch(apiUrl) | |||
.then(r => r.json()) | |||
.then(d => { | |||
const current = d.query.statistics.articles; | |||
const goal = 1000; | |||
const left = goal - current; | const left = goal - current; | ||
el.innerHTML = left > 0 | |||
? `🚧 Only <strong>${left}</strong> articles to go until 1000!` | |||
: `🎯 We've reached 1000 articles! Let's Go Boyz and Girlz!`; | |||
}) | |||
.catch(err => { | |||
el.textContent = 'API request failed (see console).'; | |||
console.error(err); | |||
}); | }); | ||
}); | }); | ||
// MediaWiki:Common.js | // MediaWiki:Common.js | ||
mw.hook('rcfilters.ui.initialized').add(function () { | mw.hook('rcfilters.ui.initialized').add(function () { | ||
document.documentElement.classList.add('rcfilters-ready'); | document.documentElement.classList.add('rcfilters-ready'); | ||
}); | }); | ||