Gebruiker:MakiBoy/Gadget-TestGadget.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 8: | Regel 8: | ||
document.title = "LogCounter - WikiKids"; | document.title = "LogCounter - WikiKids"; | ||
− | + | table = `<table class="wikitable sortable"> | |
− | + | <thead> | |
− | + | <tr> | |
− | + | <th>Paginatitel</th> | |
− | + | <th>Laatst bezocht</th> | |
− | + | <th>Normaal bezocht</th> | |
− | + | <th>Via hoofdpagina bezocht</th> | |
− | + | <th>Totaal aantal</th> | |
− | + | </tr> | |
− | + | </thead> | |
− | + | <tbody> | |
− | + | ${pages.map((function (page) { | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
var totalVisitors = page.normalVisitors + page.mainPageVisitors; | var totalVisitors = page.normalVisitors + page.mainPageVisitors; | ||
var pageTitle = page.title.replace(/_/g, ' '); | var pageTitle = page.title.replace(/_/g, ' '); | ||
− | return ` | + | return `<tr> |
− | + | <td><a href="/${page.title}">${pageTitle}</a></td> | |
− | + | <td>${page.date}</td> | |
− | + | <td>${page.normalVisitors}</td> | |
− | + | <td>${page.mainPageVisitors}</td> | |
− | + | <td>${totalVisitors}</td> | |
− | + | </tr>`; | |
− | |||
})).join('')} | })).join('')} | ||
− | `; | + | </tbody> |
+ | </table>`; | ||
document.getElementById('bodyContent').innerHTML = table; | document.getElementById('bodyContent').innerHTML = table; | ||
Regel 58: | Regel 37: | ||
function getPages() { | function getPages() { | ||
− | + | var pages = []; | |
− | + | var request = new XMLHttpRequest(); | |
− | + | request.open('GET', 'https://wikikids.martvanweeghel.nl/pages', false); | |
− | + | request.send(null); | |
− | + | if (request.status === 200) { | |
− | + | pages = JSON.parse(request.responseText); | |
− | + | } | |
− | + | return pages; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Versie van 13 jan 2023 14:26
/* jshint sub:true maxerr:100000 */
// Gadget gemaakt door [[User:MakiBoy]]
// Documentatie op [[WikiKids:LogCounter]]
var version = '1.2';
function showProject(pages) {
document.getElementsByTagName("h1")[0].textContent = "Speciaal:LogCounter";
document.title = "LogCounter - WikiKids";
table = `<table class="wikitable sortable">
<thead>
<tr>
<th>Paginatitel</th>
<th>Laatst bezocht</th>
<th>Normaal bezocht</th>
<th>Via hoofdpagina bezocht</th>
<th>Totaal aantal</th>
</tr>
</thead>
<tbody>
${pages.map((function (page) {
var totalVisitors = page.normalVisitors + page.mainPageVisitors;
var pageTitle = page.title.replace(/_/g, ' ');
return `<tr>
<td><a href="/${page.title}">${pageTitle}</a></td>
<td>${page.date}</td>
<td>${page.normalVisitors}</td>
<td>${page.mainPageVisitors}</td>
<td>${totalVisitors}</td>
</tr>`;
})).join('')}
</tbody>
</table>`;
document.getElementById('bodyContent').innerHTML = table;
}
function getPages() {
var pages = [];
var request = new XMLHttpRequest();
request.open('GET', 'https://wikikids.martvanweeghel.nl/pages', false);
request.send(null);
if (request.status === 200) {
pages = JSON.parse(request.responseText);
}
return pages;
}
if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogCounter") {
document.getElementById("footer-places").innerHTML += '<li id="footer-places-gadget-LogCounter">Script gemaakt door <a href="/User:MakiBoy" title="Gebruiker:MakiBoy">MakiBoy</a>, versie: ' + version + '</li>';
var allPages = getPages();
showProject(allPages);
}