Created
March 22, 2017 13:24
-
-
Save anonymous/b449a1b9c8c9b2981f9a63d6995e1cda to your computer and use it in GitHub Desktop.
trend articles on local wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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