Skip to content

Instantly share code, notes, and snippets.

/uptrends.js
Created Mar 22, 2017

Embed
What would you like to do?
trend articles on local wiki
if ($("div#uptrends").hasClass("uptrends")){
(new mw.Api()).get({
format: 'json',
action: 'query',
list: 'mostviewed',
pvimlimit: 50,
}).done(function (data) {
var popular10 = data.query.mostviewed.slice(0, 10)
var elements = popular10.map(function (item) {
var a = document.createElement('a')
a.href = mw.util.getUrl(item.title)
var li = document.createElement('li')
li.appendChild(a)
return li
})
var ul = document.createElement('ul')
elements.forEach(function (li) {
ul.appendChild(li)
})
var uptrends = document.getElementById('uptrends')
uptrends.appendChild(ul)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.