Gebruiker:Rots61/JS-WikiStats.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(volgorde aangepast, + 2 kleine aanpassingen)
 
(134 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 13: Regel 13:
 
return number < 10 ? "0" + number : number;
 
return number < 10 ? "0" + number : number;
 
}
 
}
 +
 +
function containsAnyWS(str, substrings) {
 +
    for (let i = 0; i != substrings.length; i++) {
 +
      var substring = substrings[i];
 +
      if (str.indexOf(substring) != - 1) {
 +
        return substring;
 +
      }
 +
    }
 +
    return null;
 +
}
 +
  
 
/*
 
/*
Regel 22: Regel 33:
 
function showProjectWS (pages, zoekwoord) {
 
function showProjectWS (pages, zoekwoord) {
 
// Dit zorgt ervoor dat de kleur wordt weergegeven of de kleurcode.  
 
// Dit zorgt ervoor dat de kleur wordt weergegeven of de kleurcode.  
var haakjesfilterkleur = /[G-Za-z]/.test(parameterWS['filterkleur']) ? '' : '#';
+
//console.log(pages);
console.log(pages);
 
 
// Past de titel van de speciale pagina aan
 
// Past de titel van de speciale pagina aan
 
document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
 
document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
 
document.title = "Statistieken WikiKids";
 
document.title = "Statistieken WikiKids";
 +
 +
var request45 = new XMLHttpRequest();
 +
request45.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=100000&apnamespace=4&apprefix=Statistieken/Logs&aplimit=500&format=json', false);
 +
request45.send(null);
 +
if (request45.status === 200) {
 +
allHistoryPages = JSON.parse(request45.responseText);
 +
}
 +
//laatsteHistory = allHistoryPages.query.allpages[allHistoryPages.query.allpages.length-2]['title'].slice(-8);
 
 
searchBarWS = '<div><input type="text" id="lc-searchbar" value=' + zoekwoord +'> <button onclick="searchContainsButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPaginaWS()"><img src="https://upload.wikimedia.org/wikipedia/commons/2/27/OOjs_UI_icon_history.svg" title="Geschiedenis" height="25">*</button> <small>*Gebruikt veel internetdata </small>'
+
//infoHistoryWS = getInfoPageWS('https://wikikids.nl/Wikikids:Statistieken/Logs/' + laatsteHistory + '/info?action=raw', 2);
+ '<div style="float:right;"><div id="reload1" style="display: ' + reload1WSx + ';"><a href="javascript:reload1WS();"><img title="Refresh de gegevens" src="https://upload.wikimedia.org/wikipedia/commons/f/ff/OOjs_UI_icon_reload_flipX.svg" width="50"></a></div><div id="reload2" style="display: ' + reload2WSx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3WSx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/f/f6/OOjs_UI_icon_check-constructive.svg" width="50"></a></div></div></div>'
+
searchBarWS = '<div><input type="text" id="lc-searchbar" value=' + zoekwoord +'> <button onclick="searchContainsButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> </div>'
 
+ '<div><img src="https://upload.wikimedia.org/wikipedia/commons/8/8b/OOjs_UI_icon_download.svg" title="height="25"> <button onclick="downloadWS(\';\');"><b>;</b></button> <button onclick="downloadWS(\',\');"><b>,</b></button></button>';  
 
+ '<div><img src="https://upload.wikimedia.org/wikipedia/commons/8/8b/OOjs_UI_icon_download.svg" title="height="25"> <button onclick="downloadWS(\';\');"><b>;</b></button> <button onclick="downloadWS(\',\');"><b>,</b></button></button>';  
 
 
 
// Variabele die informatie geeft over de LogCounter.  
 
// Variabele die informatie geeft over de LogCounter.  
var logCounterInfo = '<div id="logCounterInfo">Deze pagina laat zien hoeveel paginabezoeken er zijn geweest op een specifieke pagina. De rij "Views" bevat <b>alle</b> views. De rij daarachter laat alleen maar zien hoeveel views komen vanuit iets specifieks, bijvoorbeeld vanuit een categorie of van een mobiele telefoon. <a href="/Speciaal:Statistieken_WikiKids?action=tabel">Klik hier voor statistieken van vorige weken.</a> </div>';
+
var logCounterInfo = '<div id="logCounterInfo">Deze pagina laat zien hoeveel paginabezoeken er zijn geweest op een specifieke pagina. De rij "Views" bevat <b>alle</b> views. De rij daarachter laat alleen maar zien hoeveel views komen vanuit iets specifieks, bijvoorbeeld vanuit een categorie of van een mobiele telefoon. <a href="/Speciaal:Statistieken_WikiKids?action=tabel">Klik hier voor statistieken van vorige weken.</a> De statistieken zijn voor het laatst gereset op: <span id="WikiStats-starttijd"> ' + infoHistoryWS['Endtime'] +  '</span> (in UTC).</div>';
 
// Controleert of het een speciale week is, als dat het geval is, dan wordt de informatie uitgebreid.
 
// Controleert of het een speciale week is, als dat het geval is, dan wordt de informatie uitgebreid.
 
if (parameterWS['specialeweek']) {
 
if (parameterWS['specialeweek']) {
Regel 47: Regel 65:
 
var tableHeadTitles;
 
var tableHeadTitles;
 
// Geeft de titels van de tabel weer.
 
// Geeft de titels van de tabel weer.
tableHeadTitles = ['Titel', 'Laatste bezoek', 'Views', infoHistoryWS.Types, '%'];
+
tableHeadTitles = ['Titel', 'Views', infoHistoryWS.Types, '%', '%'];
 
/*  
 
/*  
 
Variabelen:
 
Variabelen:
Regel 58: Regel 76:
 
var totalPages = Math.ceil(pages.length / rowsPerPage);
 
var totalPages = Math.ceil(pages.length / rowsPerPage);
 
 
 +
var totalVisitorsAll, totalSpecialVisitorsAll;
 +
if (infoHistoryWS.Doublerequest) {
 +
totalVisitorsAll = pages.reduce(function (total, page) {
 +
return total + page.nV;
 +
}, 0);
 +
} else {
 +
totalVisitorsAll = pages.reduce(function (total, page) {
 +
if (!page.nV) {
 +
return total + page.mPV;
 +
} else if (!page.mPV) {
 +
return total + page.nV;
 +
} else {
 +
return total + page.nV + page.mPV;
 +
}
 +
}, 0);
 +
}
 +
totalSpecialVisitorsAll = pages.reduce(function (total, page) {
 +
return total + page.mPV;
 +
}, 0);
 
// Functie die een specifieke pagina laat zien, op basis van de parameter 'pageNumber'
 
// Functie die een specifieke pagina laat zien, op basis van de parameter 'pageNumber'
 
function showPage(pageNumber) {
 
function showPage(pageNumber) {
Regel 66: Regel 103:
 
var paginatedItems = pages.slice(start, end);
 
var paginatedItems = pages.slice(start, end);
 
paginatedItems.forEach(function (page) {
 
paginatedItems.forEach(function (page) {
var dateString;
+
let row = document.createElement('tr');
var row = document.createElement('tr');
 
 
// Definieert variabelen die later nodig zijn
 
// Definieert variabelen die later nodig zijn
var totalVisitors, mainPageVisited, pageTitle, pageLink, date, tempDate, filterShow, percentMainPage, percentStyle;
+
let totalVisitors, mainPageVisited, pageTitle, pageLink, date, tempDate, filterShow, percentMainPage, percentStyle, pageStyle;
 
if (infoHistoryWS.Doublerequest) {
 
if (infoHistoryWS.Doublerequest) {
totalVisitors = page.nV ? page.nV : page.mPV;
+
totalVisitors = page.nV ? page.nV : page.mPV;
 
} else {
 
} else {
 
// Controleert of een gedeelte van de informatie leeg is gelaten. Dit is enkel voor normale versies
 
// Controleert of een gedeelte van de informatie leeg is gelaten. Dit is enkel voor normale versies
Regel 86: Regel 122:
 
pageLink = page.t;
 
pageLink = page.t;
 
if (parameterWS['specialeweek']) {
 
if (parameterWS['specialeweek']) {
if (pageLink.includes('Zoeken:')) {
 
pageLink = 'https://wikikids.nl/Speciaal:Zoeken?search=' + pageTitle.replace(/Zoeken.?:/g,"");
 
pageTitle = pageTitle.replace(/Zoeken:/g,"Zoek:");
 
}
 
 
if (pageLink.includes('Tijd')) {
 
if (pageLink.includes('Tijd')) {
 
tempDate = new Date((parseInt(pageTitle.replace(/Tijd.?:/g,"")) + 28026240) * 60 * 1000);
 
tempDate = new Date((parseInt(pageTitle.replace(/Tijd.?:/g,"")) + 28026240) * 60 * 1000);
 
pageTitle = pageTitle.replace(/Tijd/g,"T").replace(/:.*/g, ":");
 
pageTitle = pageTitle.replace(/Tijd/g,"T").replace(/:.*/g, ":");
dateString = addZeroWS(tempDate.getDate()) + ' april ' + addZeroWS(tempDate.getHours()) + ":" + addZeroWS(tempDate.getMinutes());
 
 
}
 
}
 
}
 
}
Regel 99: Regel 130:
 
filterShow = page.filterShow ? page.filterShow : "";
 
filterShow = page.filterShow ? page.filterShow : "";
 
percentMainPage = Math.round((100/totalVisitors)*mainPageVisited*100)/100;
 
percentMainPage = Math.round((100/totalVisitors)*mainPageVisited*100)/100;
percentStyle = '>';
+
percentFromTotal100 = Math.round(totalVisitors/totalVisitorsAll*100*10000)/10000;
 +
percentStyle = '';
 
if (filterShow) {  
 
if (filterShow) {  
  percentStyle = ' style="background: ' + haakjesfilterkleur + filterShow + '">';
+
  percentStyle = 'style="background: ' + filterShow + '"';
 
}
 
}
if (parameterWS['specialeweek'] && (pageLink.includes('Speciaal:Zoeken?') || pageLink.includes('Tijd'))) {
+
if (pageLink.includes('Zoeken:')) {
if (pageLink.includes('Speciaal:Zoeken?')) {
+
percentFromTotal100 = '<button onclick="deletePageR61(event, \'' + pageTitle + '\');">D</button>';
dateString = "-";
+
pageLink = 'Speciaal:Zoeken?search=' + pageTitle.replace(/Zoeken.?:/g,"");
 +
/*
 +
if (containsAnyWS(pageTitle.toLowerCase(), verwijderenWS)) {
 +
temp5 = pageTitle.replace(containsAnyWS(pageTitle.toLowerCase(), verwijderenWS) , "");
 +
pageTitle = pageTitle + '</a> - <a href="https://wikikids.nl/Speciaal:Zoeken/' + temp5.replace(/Zoeken.?:/g,"")+ '">' + temp5;
 +
pageStyle = 'style="background: #FFAAAA;"';
 +
} */
 +
let pageTitleO = pageTitle;
 +
/*
 +
new mw.Api().get( {
 +
  action: "query",
 +
  titles: [ pageTitle.replace(/Zoeken.?:/g,"") ],
 +
} ).then( function( ret ) {
 +
  $.each( ret.query.pages, function() {
 +
  //console.log(this);
 +
  if ( this.missing !== "" ) {
 +
  console.log(pageTitleO);
 +
  deletePageR61({}, pageTitleO, true);
 +
    }
 +
    });
 +
});
 +
*/
 +
pageTitle = pageTitle.charAt(7).toUpperCase() + pageTitle.slice(8).toLowerCase();
 +
if (parameterWS['specialdata'] !== 'wit') {
 +
if (waarschuwingenWS.some(function(v) { return pageTitle.toLowerCase().indexOf(v) >= 0; }) || pageTitle.startsWith('De ') || pageTitle.startsWith('Een ') || (pageTitle.split(" ").length) > 3) {
 +
pageStyle = 'style="background: orange;"';
 +
deletePageR61({}, pageTitleO, true);
 +
}
 
}
 
}
} else if (!isNaN(date)) {
+
pageTitle = 'Zoek:' + pageTitle;
dateString = addZeroWS(date.getDate()) + "-" + addZeroWS((date.getMonth() + 1)) + "-" + date.getFullYear() + " " + addZeroWS(date.getHours()) + ":" + addZeroWS(date.getMinutes());
+
totalVisitors = '-';
} else {
+
percentMainPage = '-';
dateString = "Niet beschikbaar";
+
 +
} else if (pageLink.startsWith('X:')) {
 +
pageLink = '';
 +
pageStyle = 'style="color:black;"';
 +
percentMainPage = '-';
 +
percentFromTotal100 = '-';
 
}
 
}
row.innerHTML = `<td><a href="/${pageLink}">${pageTitle}</a></td>
+
row.innerHTML = `<td ${pageStyle}><a href="/${pageLink}">${pageTitle}</a></td>
<td>${dateString}</td>
 
 
<td>${parseNumberWS(totalVisitors)}</td><td>${parseNumberWS(mainPageVisited)}</td>
 
<td>${parseNumberWS(totalVisitors)}</td><td>${parseNumberWS(mainPageVisited)}</td>
<td ${percentStyle + percentMainPage}</td>`;
+
<td ${percentStyle}> ${percentMainPage}</td>
 +
<td>${percentFromTotal100}</td>`;
 
tableBody.appendChild(row);
 
tableBody.appendChild(row);
 
});
 
});
Regel 175: Regel 239:
 
var tableHeadCell = document.createElement('th');
 
var tableHeadCell = document.createElement('th');
 
tableHeadCell.textContent = title;
 
tableHeadCell.textContent = title;
 +
//if (title === 'Laatste bezoek') {tableHeadCell.classList.add('datumstringWS')}
 
tableHeadRow.appendChild(tableHeadCell);
 
tableHeadRow.appendChild(tableHeadCell);
 
});
 
});
Regel 181: Regel 246:
 
table.appendChild(tableBody);
 
table.appendChild(tableBody);
 
 
var totalVisitors, totalSpecialVisitors;
 
if (infoHistoryWS.Doublerequest) {
 
totalVisitors = pages.reduce(function (total, page) {
 
return total + page.nV;
 
}, 0);
 
} else {
 
totalVisitors = pages.reduce(function (total, page) {
 
if (!page.nV) {
 
return total + page.mPV;
 
} else if (!page.mPV) {
 
return total + page.nV;
 
} else {
 
return total + page.nV + page.mPV;
 
}
 
}, 0);
 
}
 
totalSpecialVisitors = pages.reduce(function (total, page) {
 
return total + page.mPV;
 
}, 0);
 
 
var totalElement = document.createElement('div');
 
var totalElement = document.createElement('div');
 
totalElement.style = 'margin-top: 20px; display: flex; flex-direction: column;';
 
totalElement.style = 'margin-top: 20px; display: flex; flex-direction: column;';
  
 
var totalVisitorsElement = document.createElement('span');
 
var totalVisitorsElement = document.createElement('span');
totalVisitorsElement.textContent = `Totaal aantal bezoeken: ${parseNumberWS(totalVisitors)}`;
+
totalVisitorsElement.textContent = `Totaal aantal bezoeken: ${parseNumberWS(totalVisitorsAll)}`;
 
totalElement.appendChild(totalVisitorsElement);
 
totalElement.appendChild(totalVisitorsElement);
 
 
 
var totalSpecialVisitorsElement = document.createElement('span');
 
var totalSpecialVisitorsElement = document.createElement('span');
totalSpecialVisitorsElement.textContent = `Totaal aantal 'speciale' bezoeken: ${parseNumberWS(totalSpecialVisitors)} (${Math.round((100/totalVisitors)*totalSpecialVisitors*100)/100}%)`;
+
totalSpecialVisitorsElement.textContent = `Totaal aantal 'speciale' bezoeken: ${parseNumberWS(totalSpecialVisitorsAll)} (${Math.round((100/totalVisitorsAll)*totalSpecialVisitorsAll*100)/100}%)`;
 
totalElement.appendChild(totalSpecialVisitorsElement);
 
totalElement.appendChild(totalSpecialVisitorsElement);
  
Regel 217: Regel 263:
 
var moreInfoElement = document.createElement('span');
 
var moreInfoElement = document.createElement('span');
 
if (!infoHistoryWS.Live) {
 
if (!infoHistoryWS.Live) {
var xStarttime = new Date(infoHistoryWS.Starttime);
+
let firstDateString = '';
var xEndtime = new Date(infoHistoryWS.Endtime);  
+
if (infoHistoryWS.Starttime) {
var firstDateString = addZeroWS(xStarttime.getDate()) + "-" + addZeroWS((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZeroWS(xStarttime.getHours()) + ":" + addZeroWS(xStarttime.getMinutes());
+
let xStarttime = new Date(infoHistoryWS.Starttime);  
var lastDateString = addZeroWS(xEndtime.getDate()) + "-" + addZeroWS((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZeroWS(xEndtime.getHours()) + ":" + addZeroWS(xEndtime.getMinutes());
+
firstDateString = addZeroWS(xStarttime.getDate()) + "-" + addZeroWS((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZeroWS(xStarttime.getHours()) + ":" + addZeroWS(xStarttime.getMinutes());
 +
}
 +
const xEndtime = new Date(infoHistoryWS.Endtime);
 +
let lastDateString = addZeroWS(xEndtime.getDate()) + "-" + addZeroWS((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZeroWS(xEndtime.getHours()) + ":" + addZeroWS(xEndtime.getMinutes());
 
moreInfoElement.textContent = `${firstDateString} tot ${lastDateString}`;
 
moreInfoElement.textContent = `${firstDateString} tot ${lastDateString}`;
 
} else {
 
} else {
Regel 231: Regel 280:
 
document.getElementById('bodyContent').appendChild(pagination);
 
document.getElementById('bodyContent').appendChild(pagination);
 
document.getElementById('bodyContent').appendChild(totalElement);
 
document.getElementById('bodyContent').appendChild(totalElement);
}
 
 
function historyStatsPerPageWS() {
 
document.title = "Stats van " + parameterWS['page'];
 
document.getElementById('bodyContent').innerHTML = 'Wacht... minimaal 10 seconden. Na 20 seconden zonder resultaat kan je deze pagina opnieuw laden. Problemen? <a href="/Overleg gebruiker:Rots61">Graag hier melden.</a> ';
 
var allHistoryPages;
 
var request = new XMLHttpRequest();
 
// Geeft alle subpagina's van User:Rots/Statistieken/. /StatisiekenExtra doet dus niet mee
 
request.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=100000&apnamespace=2&apprefix=Rots61/Statistieken/&aplimit=500&format=json', false);
 
request.send(null);
 
if (request.status === 200) {
 
allHistoryPages = JSON.parse(request.responseText);
 
}
 
allHistoryPages = allHistoryPages.query.allpages;
 
historyOutputWS = `<table class="wikitable" id="LogCounterPerPage"><thead><tr><th onclick="sortTableWS('LogCounterPerPage',0, true)">Rank</th><th onclick="sortTableWS('LogCounterPerPage',1)">Datum</th><th onclick="sortTableWS('LogCounterPerPage',2, true)">Aantal bezoekers</th></thead><tbody>`;
 
requests = new Array(allHistoryPages.length);
 
 
searchBarWS = '<div><input type="text" id="lc-searchbar" value=' + parameterWS['page'] +'> <button onclick="searchContainsButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPaginaWS()"><img src="https://upload.wikimedia.org/wikipedia/commons/2/27/OOjs_UI_icon_history.svg" title="Geschiedenis" height="25">*</button> <small>*Gebruikt veel internetdata </small>'
 
+ '<div style="float:right;"><div id="reload1" style="display: ' + reload1WSx + ';"><a href="javascript:reload1WS();"><img title="Refresh de gegevens" src="https://upload.wikimedia.org/wikipedia/commons/f/ff/OOjs_UI_icon_reload_flipX.svg" width="50"></a></div><div id="reload2" style="display: ' + reload2WSx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3WSx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/f/f6/OOjs_UI_icon_check-constructive.svg" width="50"></a></div></div></div>'
 
+ '<div><img src="https://upload.wikimedia.org/wikipedia/commons/8/8b/OOjs_UI_icon_download.svg" title="height="25">';
 
 
setTimeout(function () {
 
for (let i = 0; i < allHistoryPages.length; i++) {
 
requests[i] = new XMLHttpRequest();
 
requests[i].open("GET", "https://wikikids.nl/" + allHistoryPages[i]['title'] + '?action=raw');
 
requests[i].onload = function() {
 
var datainfo = JSON.parse(requests[i].responseText);
 
/*
 
for (var d = 0; d < datainfo.length; d++) {
 
datainfo[d].d = i;
 
}
 
downloadAllWS[i] = datainfo;
 
*/
 
var result;
 
for (var y = 0; y < datainfo.length; y++) {
 
if (datainfo[y]['t'].toLowerCase() === parameterWS['page'].replace(/ /g, '_').toLowerCase()) {
 
result = datainfo[y];
 
result['Rank'] = y + 1;
 
break;
 
}
 
}
 
if (result) {
 
var totaalViews;
 
if (allHistoryPages[i]['title'].includes('20230603') || allHistoryPages[i]['title'].includes('20230610')) { //TODO: fix voor 'doublerequest' stats
 
if (result.nV) {
 
totaalViews = result.nV;
 
} else {
 
totaalViews = 1;
 
}
 
} else {
 
  if (!result.nV) { // bij een gedeelte van de opgeslagen data, wordt nV of mPV leeggelaten, dit zorgt ervoor dat het juist wordt weergegeven. Dit is alleen nodig bij een voorgaande versie. Bij live versies worden alles gewoon doorgegeven.
 
totaalViews = result.mPV;
 
} else if (!result.mPV) {
 
totaalViews = result.nV;
 
} else {
 
totaalViews = result.nV + result.mPV;
 
}
 
}
 
historyOutputWS += `<tr><td>${result['Rank']}</td><td><a href="https://wikikids.nl/Special:Statistieken_WikiKids?date=${allHistoryPages[i]['title'].slice(-8)}">${allHistoryPages[i]['title'].slice(-8)}</a></td><td>${totaalViews}</td></tr>`;
 
} else {
 
historyOutputWS += `<tr><td></td><td><a href="https://wikikids.nl/Special:Statistieken_WikiKids?date=${allHistoryPages[i]['title'].slice(-8)}">${allHistoryPages[i]['title'].slice(-8)}</a></td><td>0</td></tr>`;
 
}
 
};
 
requests[i].send();
 
}
 
document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
 
document.title = "Pagina specifieke statistieken -  WikiKids";
 
infotext = `Specifieke statistieken voor <a href="/${parameterWS['page']}">${parameterWS['page'].replace(/_/g, ' ')}</a>. <br>Indien niet alle weken zijn ingeladen, herlaad de pagina dan. Helpt dat nog steeds niet? <a href="/Overleg gebruiker:Rots61">Meld dit hier.</a> <br>
 
Voor 20230306 (week 9) telden bots ook mee in de statistieken. Hierdoor kan het zijn dat de statistieken daarvoor hoger zijn dan het daadwerkelijke aantal bezoekers. `;
 
setTimeout( function () {
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + infotext + historyOutputWS + '</tbody></table>';
 
sortTableWS('LogCounterPerPage',1);
 
}, 4000);
 
}, 500);
 
 
 
}
 
}
  
Regel 318: Regel 292:
 
// hernoemen alle keys zodat het later makkelijker gaat  
 
// hernoemen alle keys zodat het later makkelijker gaat  
 
if (!historyWS) {
 
if (!historyWS) {
for (var x = 0; x < pages.length; x++) {
+
if (parameterWS['specialdata']) {
renamekeyWS('uA','updatedAt', x);
+
for (let x = 0; x < pages.length; x++) {
renamekeyWS('mPV', 'mainPageVisitors', x);
+
if (!(pages[x].title.includes('Zoeken:') || pages[x].title.startsWith('X:'))) {
renamekeyWS('nV','normalVisitors', x);
+
pages.splice(x, 1);
renamekeyWS('t','title', x);
+
x--;
 +
} else {
 +
renamekeyWS('t','title', x);
 +
}
 +
}
 +
} else {
 +
for (let x = 0; x < pages.length; x++) {
 +
if (pages[x].title.includes('Zoeken:') || pages[x].title.startsWith('X:')) {
 +
pages.splice(x, 1);
 +
x--;
 +
} else {
 +
renamekeyWS('t','title', x);
 +
}
 +
}
 +
}
 +
} else {
 +
if (parameterWS['specialdata']) {
 +
for (let x = 0; x < pages.length; x++) {
 +
if (!(pages[x].t.includes('Zoeken:') || pages[x].t.startsWith('X:'))) {
 +
pages.splice(x, 1);
 +
x--;
 +
}
 +
}
 +
} else {
 +
for (let x = 0; x < pages.length; x++) {
 +
if (pages[x].t.includes('Zoeken:') || pages[x].t.startsWith('X:')) {
 +
pages.splice(x, 1);
 +
x--;
 +
}
 +
}
 
}
 
}
 
}
 
}
 +
// Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
 +
console.log(JSON.stringify(pages));
 +
pages.sort(function (a, b) {
 +
return (b.nV || 0) + (b.mPV || 0) - (a.nV || 0) - (a.mPV || 0);
 +
});
  
fullPagesWS = pages;
 
// Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
 
 
if (infoHistoryWS.Doublerequest) {
 
if (infoHistoryWS.Doublerequest) {
 
pages.sort(function (a, b) {
 
pages.sort(function (a, b) {
 
return b.nV + b.nV - a.nV - a.nV;
 
return b.nV + b.nV - a.nV - a.nV;
});
 
} else {
 
pages.sort(function (a, b) {
 
  return b.nV + b.mPV - a.nV - a.mPV;
 
 
});
 
});
 
}
 
}
 +
 +
fullPagesWS = pages;
 +
 
//Filter percentmax, percentmin, aantalmax, aantalmin, only
 
//Filter percentmax, percentmin, aantalmax, aantalmin, only
if (parameterWS['aantalmin'] + parameterWS['aantalmax'] + parameterWS['only'] + parameterWS['percentmax'] + parameterWS['percentmin']) {
+
for (let y=0; y < pages.length; y++) {
for (var y=0; y < pages.length; y++) {
 
 
pages[y].mPV = pages[y].mPV ? pages[y].mPV : 0;
 
pages[y].mPV = pages[y].mPV ? pages[y].mPV : 0;
 
pages[y].nV = pages[y].nV ? pages[y].nV : 0;
 
pages[y].nV = pages[y].nV ? pages[y].nV : 0;
if (infoHistoryWS.Doublerequest) {  
+
if (infoHistoryWS.Doublerequest) {
 +
aantalviewspagina = pages[y].nV;
 
procent = (100/pages[y].nV)*pages[y].mPV;
 
procent = (100/pages[y].nV)*pages[y].mPV;
 
if (procent === Infinity) {
 
if (procent === Infinity) {
procent = 200;
+
procent = 100;
 
}
 
}
 
} else {
 
} else {
procent = (100/(pages[y].nV + pages[y].mPV))*pages[y].mPV; // 50
+
aantalviewspagina = pages[y].nV + pages[y].mPV;
 +
procent = (100/(aantalviewspagina))*pages[y].mPV; // 50
 
}
 
}
if (procent <= parameterWS['percentmax']) { // 60 <= 70 true // 50 <= 50 true
+
if (procent < parameterWS['only'][0] || procent > parameterWS['only'][1]) { // dat wat buiten deze categorie ([x, y]) wordt verwijderd.
if (procent >= parameterWS['percentmin'] || parameterWS['percentmin'] === null) { // 60 >= 50 true
+
pages.splice(y, 1);
//pages[y].filterShow = parameterWS['filterkleur1']; // kleuren
+
y = y-1;
} else {
+
} else if (aantalviewspagina < parameterWS['only'][2] || aantalviewspagina > parameterWS['only'][3]) { // bovenstaande
pages[y].filterShow = parameterWS['filterkleur1']; // kleuren
+
pages.splice(y, 1);
 +
y = y-1;
 +
} else if (parameterWS['kleur1'] || parameterWS['kleur2'] || parameterWS['kleur3'] || parameterWS['kleur4']) {
 +
if (parameterWS['kleur1']) {
 +
if (procent >= parameterWS['kleur1'][0]) {
 +
if (procent <= parameterWS['kleur1'][1]) {
 +
haakjenodig = /[G-Za-z]/.test(parameterWS['kleur1'][2]) ? '' : '#';
 +
pages[y].filterShow = haakjenodig + parameterWS['kleur1'][2];
 +
}
 +
}
 +
}
 +
if (parameterWS['kleur2']) {
 +
if (procent >= parameterWS['kleur2'][0]) {
 +
if (procent <= parameterWS['kleur2'][1]) {
 +
haakjenodig = /[G-Za-z]/.test(parameterWS['kleur2'][2]) ? '' : '#';
 +
pages[y].filterShow = haakjenodig + parameterWS['kleur2'][2];  
 +
}
 +
}
 +
}
 +
if (parameterWS['kleur3']) {
 +
if (procent >= parameterWS['kleur3'][0]) {
 +
if (procent <= parameterWS['kleur3'][1]) {
 +
haakjenodig = /[G-Za-z]/.test(parameterWS['kleur3'][2]) ? '' : '#';
 +
pages[y].filterShow = haakjenodig + parameterWS['kleur3'][2];  
 +
}
 +
}
 
}
 
}
} else {
+
if (parameterWS['kleur4']) {
pages[y].filterShow = parameterWS['filterkleur2'];
+
if (procent >= parameterWS['kleur4'][0]) {
}
+
if (procent <= parameterWS['kleur4'][1]) {
if (pages[y].nV + pages[y].mPV > parameterWS['aantalmax']) { //50 >= 100; 1 >= 1
+
haakjenodig = /[G-Za-z]/.test(parameterWS['kleur4'][2]) ? '' : '#';
pages[y].filterShow = undefined;
+
pages[y].filterShow = haakjenodig + parameterWS['kleur4'][2];
} else if (pages[y].nV + pages[y].mPV < parameterWS['aantalmin']) { // 50 <= 0
+
}
pages[y].filterShow = undefined;
+
}
}
 
if (parameterWS['only']) {
 
if (pages[y].filterShow) {
 
pages.splice(y, 1);
 
y = y-1;
 
 
}
 
}
 
}
 
}
 
}
 
}
}
 
 
if (document.getElementById('reload2')) {
 
setTimeout( function () {
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload2').style.display = 'none';
 
document.getElementById('reload3').style.display = '';
 
reload1WSx = 'none';
 
reload2WSx = 'none';
 
reload3WSx = '';
 
setTimeout(function () {document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1WSx = ''; reload2WSx = 'none'; reload3WSx = 'none';}, 2500);
 
}, 1000);
 
} else {
 
setTimeout(function () {
 
if (document.getElementById('reload2')) {
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload2').style.display = 'none';
 
document.getElementById('reload3').style.display = '';
 
reload1WSx = 'none';
 
reload2WSx = 'none';
 
reload3WSx = '';
 
setTimeout(function () {document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1WSx = ''; reload2WSx = 'none'; reload3WSx = 'none'}, 2500);
 
}
 
}, 2500);
 
}
 
 
return pages;
 
return pages;
 
}
 
}
Regel 405: Regel 406:
 
startLC();
 
startLC();
 
}
 
}
 +
 +
function deletePageR61(event, title, hide) {
 +
let objectrefhp = {
 +
title: title
 +
};
 +
fetch("https://wikikids.wikirots61.workers.dev/pages/deletepage",
 +
        {
 +
            headers: {
 +
                'Accept': 'application/json',
 +
                'Content-Type': 'text/plain'
 +
            },
 +
            method: "POST",
 +
            body: JSON.stringify(objectrefhp)
 +
        })
 +
        .then(function (res) {})
 +
        .catch(function (res) {});
 +
    if (!hide) event.target.parentElement.parentElement.style.display = 'none';
 +
}
 +
  
 
function searchContainsButtonWS() {
 
function searchContainsButtonWS() {
Regel 421: Regel 441:
 
searchQuery = parameterWS['bevatzoeken'];
 
searchQuery = parameterWS['bevatzoeken'];
 
}
 
}
 
 
var searchResult = [];
 
var searchResult = [];
for (var i = 0; i < allPagesWS.length; i++) {
+
for (let i = 0; i < allPagesWS.length; i++) {
if (allPagesWS[i]['t'].toLowerCase().includes(searchQuery.toLowerCase())) {
+
if (parameterWS['regex']) {
searchResult.push(allPagesWS[i]);
+
regex = new RegExp(searchQuery, "i");
 +
if (regex.test(allPagesWS[i]['t'].toLowerCase())) {
 +
searchResult.push(allPagesWS[i]);
 +
}
 +
} else {
 +
if (allPagesWS[i]['t'].toLowerCase().includes(searchQuery.toLowerCase())) {
 +
searchResult.push(allPagesWS[i]);
 +
}
 
}
 
}
 
}
 
}
 
setTimeout(function () {
 
setTimeout(function () {
 
if (!searchResult.length) {
 
if (!searchResult.length) {
var printToScreen = '<br>Er is geen pagina die <a href="https://wikikids.nl/Speciaal:Zoeken/' + searchQuery + '">' + searchQuery + '</a> bevat, en die in deze periode views heeft ontvangen.'  
+
const printToScreen = '<br>Er is geen pagina die <a href="https://wikikids.nl/Speciaal:Zoeken/' + searchQuery + '">' + searchQuery + '</a> bevat, en die in deze periode views heeft ontvangen.'  
 
+ 'Kijk voor meer <a href="https://wikikids.nl/WikiKids:Statistieken">informatie op deze pagina</a>.';
 
+ 'Kijk voor meer <a href="https://wikikids.nl/WikiKids:Statistieken">informatie op deze pagina</a>.';
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + printToScreen;
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + printToScreen;
 
} else {
 
} else {
console.log(searchResult);
 
 
showProjectWS(searchResult, searchQuery);
 
showProjectWS(searchResult, searchQuery);
 
}
 
}
Regel 455: Regel 480:
 
searchQuery = parameterWS['exactzoeken'];
 
searchQuery = parameterWS['exactzoeken'];
 
}
 
}
var searchResult = [];
+
let searchResult = [];
for (var i = 0; i < allPagesWS.length; i++) {
+
for (let i = 0; i < allPagesWS.length; i++) {
 
if (allPagesWS[i]['t'].toLowerCase() === searchQuery.toLowerCase()) {
 
if (allPagesWS[i]['t'].toLowerCase() === searchQuery.toLowerCase()) {
 
searchResult.push(allPagesWS[i]);
 
searchResult.push(allPagesWS[i]);
Regel 463: Regel 488:
 
setTimeout(function () {
 
setTimeout(function () {
 
if (!searchResult.length) {
 
if (!searchResult.length) {
var printToScreen = '<br>De pagina <a href="https://wikikids.nl/' + searchQuery + '">' + searchQuery + '</a> heeft geen views ontvangen, voldoet niet aan het ingestelde filter of bestaat niet. ';
+
let printToScreen = '<br>De pagina <a href="https://wikikids.nl/' + searchQuery + '">' + searchQuery + '</a> heeft geen views ontvangen, voldoet niet aan het ingestelde filter of bestaat niet. ';
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + printToScreen;
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + printToScreen;
 
} else {
 
} else {
Regel 496: Regel 521:
 
}
 
}
  
function changeURLWS(){
+
function changeURLWS() {
 
var urlPath = '/Speciaal:Statistieken WikiKids?';
 
var urlPath = '/Speciaal:Statistieken WikiKids?';
 
if (parameterWS['rows']) {
 
if (parameterWS['rows']) {
Regel 517: Regel 542:
 
} else {
 
} else {
 
urlPath += 'pagenr=' + parameterWS['pagenr'] + '&';
 
urlPath += 'pagenr=' + parameterWS['pagenr'] + '&';
}
 
}
 
if (parameterWS['percentmin']) {
 
if (parameterWS['percentmin'] !== -1) {
 
urlPath += 'percentmin=' + parameterWS['percentmin'] + '&';
 
}
 
}
 
if (parameterWS['percentmax']) {
 
if (parameterWS['percentmax'] !== 100) {
 
urlPath += 'percentmax=' + parameterWS['percentmax'] + '&';
 
}
 
}
 
if (parameterWS['only']) {
 
urlPath += 'only=x&';
 
}
 
if (parameterWS['aantalmax']) {
 
if (parameterWS['aantalmax'] !== Infinity) {
 
urlPath += 'aantalmax=' + parameterWS['aantalmax'] + '&';
 
}
 
}
 
if (parameterWS['aantalmin']) {
 
if (parameterWS['aantalmin'] !== 0) {
 
urlPath += 'aantalmin=' + parameterWS['aantalmin'] + '&';
 
 
}
 
}
 
}
 
}
 
if (parameterWS['bevatzoeken']) {
 
if (parameterWS['bevatzoeken']) {
 
urlPath += 'bevatzoeken=' + parameterWS['bevatzoeken'] + '&';
 
urlPath += 'bevatzoeken=' + parameterWS['bevatzoeken'] + '&';
 +
}
 +
if (parameterWS['regex']) {
 +
urlPath += 'regex=' + parameterWS['regex'] + '&';
 
}
 
}
 
if (parameterWS['exactzoeken']) {
 
if (parameterWS['exactzoeken']) {
 
urlPath += 'exactzoeken=' + parameterWS['exactzoeken'] + '&';
 
urlPath += 'exactzoeken=' + parameterWS['exactzoeken'] + '&';
 +
}
 +
if (parameterWS['seconddata']) {
 +
urlPath += 'seconddata=' + parameterWS['seconddata'] + '&';
 
}
 
}
 
if (parameterWS['specialeweek']) {
 
if (parameterWS['specialeweek']) {
 
urlPath += 'specialeweek=' + parameterWS['specialeweek'] + '&';
 
urlPath += 'specialeweek=' + parameterWS['specialeweek'] + '&';
 
}
 
}
if (parameterWS['filterkleur1']) {
+
if (JSON.stringify(parameterWS['only']) !== JSON.stringify([0, 100, 0, Infinity])) {
if (parameterWS['filterkleur1'] !== 'aqua') {
+
urlPath += 'only=' + JSON.stringify(parameterWS['only']) + '&';
urlPath += 'filterkleur1=' + parameterWS['filterkleur1'] + '&';
+
}
}
+
if (parameterWS['kleur1']) {
 +
urlPath += 'kleur1=' + JSON.stringify(parameterWS['kleur1']) + '&';
 +
}
 +
if (parameterWS['kleur2']) {
 +
urlPath += 'kleur2=' + JSON.stringify(parameterWS['kleur2']) + '&';
 +
}
 +
if (parameterWS['kleur3']) {
 +
urlPath += 'kleur3=' + JSON.stringify(parameterWS['kleur3']) + '&';
 +
}
 +
if (parameterWS['kleur4']) {
 +
urlPath += 'kleur4=' + JSON.stringify(parameterWS['kleur4']) + '&';
 
}
 
}
if (parameterWS['filterkleur2']) {
+
if (parameterWS['specialdata']) {
if (parameterWS['filterkleur2'] !== 'orange') {
+
urlPath += 'specialdata=' + parameterWS['specialdata'] + '&';
urlPath += 'filterkleur2=' + parameterWS['filterkleur2'] + '&';
 
}
 
 
}
 
}
+
urlPath += 'v=2.0';
urlPath += 'v=1.0';
 
 
window.history.pushState("","", urlPath);
 
window.history.pushState("","", urlPath);
 
//window.history.replaceState("","", urlPath);
 
//window.history.replaceState("","", urlPath);
}
 
 
function reload1WS() {
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload2').style.display = '';
 
document.getElementById('reload3').style.display = 'none';
 
reload1WSx = 'none';
 
reload2WSx = '';
 
reload3WSx = 'none';
 
 
changeURLWS();
 
startLC(true);
 
 
}
 
}
  
Regel 583: Regel 586:
 
var allHistoryPages;
 
var allHistoryPages;
 
var request = new XMLHttpRequest();
 
var request = new XMLHttpRequest();
// Geeft alle subpagina's van User:Rots61/Statistieken, /StatistiekenExtra doet dus mee
+
// Geeft alle subpagina's van WikiKids:Statistieken/Logs, /StatistiekenExtra staan in naamruimte Rots, en doen dus niet mee
request.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=100000&apnamespace=2&apprefix=Rots61/Statistieken&aplimit=500&format=json', false);
+
request.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=1000&apnamespace=4&apprefix=Statistieken/Logs&aplimit=500&format=json', false);
 
request.send(null);
 
request.send(null);
 
if (request.status === 200) {
 
if (request.status === 200) {
Regel 603: Regel 606:
 
var xStarttime = new Date(datainfo.Starttime);  
 
var xStarttime = new Date(datainfo.Starttime);  
 
var xEndtime = new Date(datainfo.Endtime);  
 
var xEndtime = new Date(datainfo.Endtime);  
var firstDateString = addZeroWS(xStarttime.getDate()) + "-" + addZeroWS((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZeroWS(xStarttime.getHours()) + ":" + addZeroWS(xStarttime.getMinutes());
+
var firstDateString = 'voorgaande week';
 +
if (xStarttime.getDate()) {
 +
firstDateString = addZeroWS(xStarttime.getDate()) + "-" + addZeroWS((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZeroWS(xStarttime.getHours()) + ":" + addZeroWS(xStarttime.getMinutes());
 +
}
 
var lastDateString = addZeroWS(xEndtime.getDate()) + "-" + addZeroWS((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZeroWS(xEndtime.getHours()) + ":" + addZeroWS(xEndtime.getMinutes());
 
var lastDateString = addZeroWS(xEndtime.getDate()) + "-" + addZeroWS((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZeroWS(xEndtime.getHours()) + ":" + addZeroWS(xEndtime.getMinutes());
 
tableOutputWS += `<td>van ${firstDateString} tot ${lastDateString}</td><td>${datainfo.Totalviews}</td><td>${datainfo.Totalpages}</td><td><a href="/WikiKids:Statistieken#${datainfo.Types.replace(/ /g, '_')}">${datainfo.Types}</a></td></tr>`;
 
tableOutputWS += `<td>van ${firstDateString} tot ${lastDateString}</td><td>${datainfo.Totalviews}</td><td>${datainfo.Totalpages}</td><td><a href="/WikiKids:Statistieken#${datainfo.Types.replace(/ /g, '_')}">${datainfo.Types}</a></td></tr>`;
Regel 611: Regel 617:
 
document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
 
document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
 
document.title = "Voorgaande statistieken -  WikiKids";
 
document.title = "Voorgaande statistieken -  WikiKids";
infotext = 'Elke zaterdag worden, rond 6 uur, de statistieken opnieuw ingesteld. Een week loopt dus van zaterdag tot zaterdag. Het real-time registreren van de bezoekers wordt mogelijk gemaakt door MakiBoy. Voor vragen kun je terecht bij MakiBoy of Rots61. <br>'
+
infotext = 'Elke zaterdag worden, de statistieken opnieuw opgeslagen. Een week loopt dus van zaterdag tot zaterdag. Het real-time registreren van de bezoekers wordt mogelijk gemaakt door Rots61. Voor vragen kun je terecht bij Rots61. <br>'
+ 'Deze lijst wordt automatisch bijgewerkt, zodat alle vorige statistieken worden getoont. <br>';
+
+ 'Deze lijst wordt automatisch bijgewerkt, zodat alle vorige statistieken worden getoont. (Als niet alles is getoond, herlaad de pagina dan.)<br>';
 
setTimeout( function () {  
 
setTimeout( function () {  
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + infotext + tableOutputWS + '</tbody></table>';  
 
document.getElementById('bodyContent').innerHTML = terugnaarWS + infotext + tableOutputWS + '</tbody></table>';  
Regel 622: Regel 628:
 
// Download functies
 
// Download functies
 
function downloadWS(tss) {
 
function downloadWS(tss) {
var downloadResult = 'Paginatitel' + tss + 'Views' + tss + 'Speciale statistiek \n';
+
let downloadResult = 'Paginatitel' + tss + 'Views' + tss + 'Speciale statistiek \n';
for (var x = 0; x < allPagesWS.length; x++){
+
for (let x = 0; x < allPagesWS.length; x++){
 
if (!allPagesWS[x].mPV) {
 
if (!allPagesWS[x].mPV) {
 
downloadResult += allPagesWS[x].t.replace(/,/g, '.') + tss + (allPagesWS[x].nV) + tss + '0' + tss + '\n';
 
downloadResult += allPagesWS[x].t.replace(/,/g, '.') + tss + (allPagesWS[x].nV) + tss + '0' + tss + '\n';
Regel 657: Regel 663:
 
}
 
}
  
// Functies van het internet
+
// Functies van het internet, of die iets veel makkelijker maken, zonder dat er onderhoud voor nodig is.
 
function sortTableWS(id, n, getal) {
 
function sortTableWS(id, n, getal) {
 
   var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
 
   var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
Regel 729: Regel 735:
 
}
 
}
  
function isJsonWS(item) {
+
function checkJsonWS(item, returnvalue) {
  let value = typeof item !== "string" ? JSON.stringify(item) : item;     
+
let value = typeof item !== "string" ? JSON.stringify(item) : item;     
  try {
+
try {
    value = JSON.parse(value);
+
value = JSON.parse(value);
  } catch (e) {
+
} catch (e) {
    return false;
+
return returnvalue;
  }
+
}
   
+
if (typeof value === "object" && value !== null) {
  return typeof value === "object" && value !== null;
+
return JSON.parse(item);
 +
} else {
 +
return returnvalue;
 +
}
 +
}
 +
 
 +
function clearSecondStatsWS() {
 +
var settings = {
 +
  "url": "https://wikikids.wikirots61.workers.dev/pages/delete",
 +
  "method": "POST",
 +
  "timeout": 0,
 +
  "headers": {
 +
    "Host": "wikikids.wikirots61.workers.dev/",
 +
    "Content-Type": "application/json"
 +
  },
 +
  "data": JSON.stringify({
 +
    "message": 'gek'
 +
  }),
 +
};
 +
$.ajax(settings).done(function (response) {
 +
mw.notify("Reseten statistieken gelukt", { autoHide: false });
 +
window.onbeforeunload = null;
 +
}).catch(function (error) {
 +
if (error.responseText || JSON.parse(error.responseText).succes) {
 +
mw.notify("Reseten statistieken2 gelukt", { autoHide: false });
 +
window.onbeforeunload = null;
 +
} else {
 +
mw.notify('Resetten mislukt, stuur Rots61 aub direct een berichtje.', {autoHide: false});
 +
}
 +
});
 
}
 
}
 +
  
 
function renamekeyWS(new_key, old_key, x){
 
function renamekeyWS(new_key, old_key, x){
Regel 749: Regel 785:
  
 
function startLC(reloadlc, firsttime) {
 
function startLC(reloadlc, firsttime) {
parameterWS['version'] = mw.util.getParamValue('v') ? mw.util.getParamValue('v') :  
+
parameterWS['version'] = mw.util.getParamValue('v') ? mw.util.getParamValue('v') : false;
 +
 
 +
// worden ondersteund door versie 1 & 2
 
parameterWS['rows'] = mw.util.getParamValue('rows') ?  mw.util.getParamValue('rows') : 25;
 
parameterWS['rows'] = mw.util.getParamValue('rows') ?  mw.util.getParamValue('rows') : 25;
 
parameterWS['action'] = mw.util.getParamValue('action');
 
parameterWS['action'] = mw.util.getParamValue('action');
Regel 756: Regel 794:
 
parameterWS['pagenr'] = mw.util.getParamValue('pagenr') ? mw.util.getParamValue('pagenr') : 1;
 
parameterWS['pagenr'] = mw.util.getParamValue('pagenr') ? mw.util.getParamValue('pagenr') : 1;
 
parameterWS['bevatzoeken'] = mw.util.getParamValue('bevatzoeken');
 
parameterWS['bevatzoeken'] = mw.util.getParamValue('bevatzoeken');
 +
parameterWS['regex'] = mw.util.getParamValue('regex');
 
parameterWS['exactzoeken'] = mw.util.getParamValue('exactzoeken');  
 
parameterWS['exactzoeken'] = mw.util.getParamValue('exactzoeken');  
 
parameterWS['specialeweek'] = mw.util.getParamValue('specialeweek');
 
parameterWS['specialeweek'] = mw.util.getParamValue('specialeweek');
parameterWS['filterkleur1'] = mw.util.getParamValue('filterkleur1') ? mw.util.getParamValue('filterkleur1') : 'aqua';
+
parameterWS['seconddata'] = mw.util.getParamValue('seconddata');
parameterWS['filterkleur2'] = mw.util.getParamValue('filterkleur2') ? mw.util.getParamValue('filterkleur2') : 'orange';
 
 
 
parameterWS['percentmin'] = mw.util.getParamValue('percentmin') ? mw.util.getParamValue('percentmin') : -1;
+
parameterWS['specialdata'] = mw.util.getParamValue('specialdata');
parameterWS['percentmax'] = mw.util.getParamValue('percentmax') ? mw.util.getParamValue('percentmax') : 100;
+
var allowedUsersSpecialData = ["Rots61", "Hanssain", "Mike1023", "Hippogryph", "PaulD", "Wouter15", "S.Perquin", "Gerarddummer", "Groempdebeer", "DeHelpendePenny", "FreekKraak"];
parameterWS['only'] = mw.util.getParamValue('only');
+
if (!allowedUsersSpecialData.includes(mw.config.get('wgUserName')) && parameterWS['specialdata']) {
parameterWS['aantalmax'] = mw.util.getParamValue('aantalmax') ? mw.util.getParamValue('aantalmax') : Infinity;
+
parameterWS['specialdata'] = false;
parameterWS['aantalmin'] = mw.util.getParamValue('aantalmin') ? mw.util.getParamValue('aantalmin') : 0;
+
mw.notify( 'Helaas, je hebt geen toegang tot deze specifieke gegevens. Je kunt wel de normale statistieken bekijken. Controleer of je ingelogd bent. ', { autoHideSeconds : 30 } );
parameterWS['checkrules'] = mw.util.getParamValue('aantalmin') + mw.util.getParamValue('aantalmax') + mw.util.getParamValue('only') + mw.util.getParamValue('percentmax') + mw.util.getParamValue('percentmin'); // dit is geen parameter
+
}
 
 
 +
if (parameterWS['version'] === '1.0' || parameterWS['version'] === '1.1') {
 +
parameterWS['percentmin'] = mw.util.getParamValue('percentmin') ? mw.util.getParamValue('percentmin') : -1;
 +
parameterWS['percentmax'] = mw.util.getParamValue('percentmax') ? mw.util.getParamValue('percentmax') : 100;
 +
parameterWS['only'] = mw.util.getParamValue('only');
 +
parameterWS['aantalmax'] = mw.util.getParamValue('aantalmax') ? mw.util.getParamValue('aantalmax') : Infinity;
 +
parameterWS['aantalmin'] = mw.util.getParamValue('aantalmin') ? mw.util.getParamValue('aantalmin') : 0;
 +
if (parameterWS['only']) {
 +
parameterWS['only'] = [parameterWS['percentmin'] ? parameterWS['percentmin'] : 0 , parameterWS['percentmax'] ?  parameterWS['percentmax'] : 100, parameterWS['aantalmin'] ? parameterWS['aantalmin'] : 0, parameterWS['aantalmax'] ? parameterWS['aantalmax'] : Infinity];
 +
} else if (parameterWS['version'] === '1.1') {
 +
parameterWS['only'] = [0, 100, 0, Infinity];
 +
parameterWS['kleur1'] = [0, parameterWS['percentmin'], 'aqua'];
 +
parameterWS['kleur2'] = [parameterWS['percentmax'], 100, 'orange'];
 +
} else {
 +
parameterWS['only'] = [0, 100, 0, Infinity];
 +
parameterWS['kleur1'] = [parameterWS['percentmin'], parameterWS['percentmax'], 'lightgreen'];
 +
}
 +
} else {
 +
parameterWS['only'] = checkJsonWS(mw.util.getParamValue('only'), [0, 100, 0, Infinity]);
 +
parameterWS['kleur1'] = checkJsonWS(mw.util.getParamValue('kleur1'), false);
 +
parameterWS['kleur2'] = checkJsonWS(mw.util.getParamValue('kleur2'), false);
 +
parameterWS['kleur3'] = checkJsonWS(mw.util.getParamValue('kleur3'), false);
 +
parameterWS['kleur4'] = checkJsonWS(mw.util.getParamValue('kleur4'), false);
 +
if (!parameterWS['only'][1]) {
 +
parameterWS['only'][1] = 100;
 +
}
 +
if (!parameterWS['only'][2]) {
 +
parameterWS['only'][2] = 0;
 +
}
 +
if (!parameterWS['only'][3]) {
 +
parameterWS['only'][3] = Infinity;
 +
}
 +
if (!parameterWS['kleur1'][2] && parameterWS['kleur1']) {
 +
parameterWS['kleur1'][2] = 'lightblue';
 +
}
 +
if (!parameterWS['kleur2'][2] && parameterWS['kleur2']) {
 +
parameterWS['kleur2'][2] = 'lightgreen';
 +
}
 +
if (!parameterWS['kleur3'][2] && parameterWS['kleur3']) {
 +
parameterWS['kleur3'][2] = 'pink';
 +
}
 +
if (!parameterWS['kleur4'][2] && parameterWS['kleur4']) {
 +
parameterWS['kleur4'][2] = 'orange';
 +
}
 +
}
 +
 
// zorgt ervoor dat er bovenin een link terug verwijst naar de basisinstellingen van de logcounter.  
 
// zorgt ervoor dat er bovenin een link terug verwijst naar de basisinstellingen van de logcounter.  
 
terugnaarWS = '<div id="contentSub"><span class="subpages">&lt; <a href="javascript:terugWS();" title="Speciaal:Statistieken WikiKids">Speciaal:Statistieken WikiKids</a>';
 
terugnaarWS = '<div id="contentSub"><span class="subpages">&lt; <a href="javascript:terugWS();" title="Speciaal:Statistieken WikiKids">Speciaal:Statistieken WikiKids</a>';
Regel 783: Regel 866:
 
infoHistoryWS = getInfoPageWS('https://wikikids.nl/User:Rots61/StatistiekenExtra/' + parameterWS['date'] + '/info?action=raw');
 
infoHistoryWS = getInfoPageWS('https://wikikids.nl/User:Rots61/StatistiekenExtra/' + parameterWS['date'] + '/info?action=raw');
 
} else {
 
} else {
urlWS = 'https://wikikids.nl/User:Rots61/Statistieken/' + parameterWS['date'] + '?action=raw';
+
urlWS = 'https://wikikids.nl/Wikikids:Statistieken/Logs/' + parameterWS['date'] + '?action=raw';
infoHistoryWS = getInfoPageWS('https://wikikids.nl/User:Rots61/Statistieken/' + parameterWS['date'] + '/info?action=raw');
+
infoHistoryWS = getInfoPageWS('https://wikikids.nl/Wikikids:Statistieken/Logs/' + parameterWS['date'] + '/info?action=raw');
 
}
 
}
 
historyWS = true;
 
historyWS = true;
 +
} else if (parameterWS['seconddata']) {
 +
if (parameterWS['seconddata'].startsWith('http')) {
 +
urlWS = parameterWS['seconddata'];
 +
} else {
 +
urlWS = 'https://wikikids.wikirots61.workers.dev/pages';
 +
}
 +
historyWS = false;
 
} else {
 
} else {
urlWS = 'https://wikikids.martvanweeghel.nl/pages';
+
urlWS = 'https://wikikids.dekenos.nl/pages';
 
historyWS = false;
 
historyWS = false;
 
}
 
}
if (firsttime) {
+
 
allPagesWS = getPagesWS();
 
changeURLWS();
 
}
 
 
if (parameterWS['action'] === 'tabel') {
 
if (parameterWS['action'] === 'tabel') {
 
tabelWS();
 
tabelWS();
 
} else if (parameterWS['page']) { // Views voor een pagina, de hele tijd;  
 
} else if (parameterWS['page']) { // Views voor een pagina, de hele tijd;  
historyStatsPerPageWS();
+
mw.notify('Deze functie is niet meer beschikbaar. Omdat hij niet goed werkt. ');
 
} else {
 
} else {
 
if (firsttime) {
 
if (firsttime) {
 +
allPagesWS = getPagesWS();
 +
changeURLWS();
 
} else if (reloadlc) {
 
} else if (reloadlc) {
 
allPagesWS = getPagesWS();
 
allPagesWS = getPagesWS();
Regel 806: Regel 895:
 
allPagesWS = fullPagesWS;
 
allPagesWS = fullPagesWS;
 
}
 
}
if (parameterWS['bevatzoeken']) {
+
if (parameterWS['bevatzoeken'] || parameterWS['regex']) {
 
searchContainsWS(parameterWS['bevatzoeken']);
 
searchContainsWS(parameterWS['bevatzoeken']);
 
} else if (parameterWS['exactzoeken']) {
 
} else if (parameterWS['exactzoeken']) {
Regel 818: Regel 907:
 
var pages = [];
 
var pages = [];
 
if (mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "LogCounter" || (mw.config.get('wgTitle') === "Statistieken Wikikids" || (mw.config.get('wgTitle') === "Statistieken WikiKids" || mw.config.get('wgTitle') === "WikiStats")))) {
 
if (mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "LogCounter" || (mw.config.get('wgTitle') === "Statistieken Wikikids" || (mw.config.get('wgTitle') === "Statistieken WikiKids" || mw.config.get('wgTitle') === "WikiStats")))) {
 +
document.getElementById('bodyContent').innerHTML = 'WikiStats is aan het opstarten. Dit kan enkele seconden duren. ';
 
var parameterWS = {};
 
var parameterWS = {};
 
var historyWS, urlWS, allPagesWS, fullPagesWS, terugnaarWS, historyOutputWS, searchBarWS;
 
var historyWS, urlWS, allPagesWS, fullPagesWS, terugnaarWS, historyOutputWS, searchBarWS;
 
//var downloadAllWS = [];  
 
//var downloadAllWS = [];  
 
// deze variabele regelt wat er bovenin de tabel te zien is als speciale statistiek. Ook regelt hij dingen zoals de dubbele requests. Zodat het goed geregeld kan worden.  
 
// deze variabele regelt wat er bovenin de tabel te zien is als speciale statistiek. Ook regelt hij dingen zoals de dubbele requests. Zodat het goed geregeld kan worden.  
var infoHistoryWS = {"Types":"België/Nederland", Live:true};
+
var infoHistoryWS = {"Types":"Mobiel", Live:true};
var reload1WSx = '';
+
var waarschuwingenWS = ['hebben', 'wat eten', 'wat ', 'wat eet', 'info', 'beziens', 'wat probeer', 'feiten', 'aantal', 'hoezo', 'wat deed', 'wat deden', 'wat als', 'warom', 'wat kan', 'mag je', 'top 1', 'plaatje', 'afbeelding', 'foto', 'hoeveel', 'wat doe', 'waneer', 'leefomgeving', 'ontstaan', 'informatie', 'verhalen', 'wat heb', 'graag', 'wat zijn', 'van een', 'kan er', '?', 'spreekbeurt', 'cultuur', 'leeftijd', 'waarvan', 'heeft', 'wat beteken', 'geschiedenis', 'bekend', 'wie ', 'leuk', 'zoek', 'is een', 'ooit', 'waar ', 'woont', 'in de ', 'belangrijk', 'beroemd', 'welk', 'wanneer', 'waarom', 'hoe ', 'belangerijk', ' de ', ' het ', 'wat is ', 'hoofstad', 'weetje'];
var reload2WSx = 'none';
+
var verwijderenWS = [];
var reload3WSx = 'none';
 
 
mw.loader.using('mediawiki.util', function() {
 
mw.loader.using('mediawiki.util', function() {
 
mw.util.addPortletLink('p-namespaces',  
 
mw.util.addPortletLink('p-namespaces',  
Regel 842: Regel 931:
  
 
if ((!mw.storage.get('disableLoggingWS')) || mw.config.get('wgNamespaceNumber') !== 0) {
 
if ((!mw.storage.get('disableLoggingWS')) || mw.config.get('wgNamespaceNumber') !== 0) {
mw.storage.set('disableLoggingWS', true, 86400);
+
mw.storage.set('disableLoggingWS', true, 604800);
}
 
 
 
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 100) {
 
mw.loader.using('mediawiki.util', function() {
 
mw.util.addPortletLink('p-cactions',
 
'https://wikikids.nl/Speciaal:Statistieken_WikiKids?page=' + encodeURIComponent(mw.config.get('wgPageName')),
 
'Statistieken* ', '#GeschiedenisStats', "Statistieken van " + mw.config.get('wgPageName'));
 
});
 
 
}
 
}

Huidige versie van 12 sep 2025 om 17:15

/* jshint sub:true maxerr:100000 */
// [[User:Rots61/JS-WikiStats.js]];
// eerste versie gemaakt door [[User:MakiBoy]] ( https://wikikids.nl/index.php?title=Gebruiker:MakiBoy/Gadget-LogCounter.js&oldid=759863 )
// onderhouden door [[User:Rots61]]

// Wordt gebruikt om de views op de juiste manier te formaten 
function parseNumberWS(number) {
	return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
}

// Wordt gebruikt om een nul toe te voegen bij de datum
function addZeroWS(number) {
	return number < 10 ? "0" + number : number;
}

function containsAnyWS(str, substrings) {
    for (let i = 0; i != substrings.length; i++) {
       var substring = substrings[i];
       if (str.indexOf(substring) != - 1) {
         return substring;
       }
    }
    return null; 
}


/*
	laat de speciale pagina uiteindelijk zien
	pages = array met alle pagina's die getoont moeten worden
	zoekwoord = de waarde die zichtbaar moet zijn in de zoekbalk
*/

function showProjectWS (pages, zoekwoord) {
	// Dit zorgt ervoor dat de kleur wordt weergegeven of de kleurcode. 
	//console.log(pages);
	// Past de titel van de speciale pagina aan
	document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
	document.title = "Statistieken WikiKids";

	var request45 = new XMLHttpRequest();
	request45.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=100000&apnamespace=4&apprefix=Statistieken/Logs&aplimit=500&format=json', false);
	request45.send(null);
	if (request45.status === 200) {
		allHistoryPages = JSON.parse(request45.responseText);
	}
	//laatsteHistory = allHistoryPages.query.allpages[allHistoryPages.query.allpages.length-2]['title'].slice(-8);
	
	//infoHistoryWS = getInfoPageWS('https://wikikids.nl/Wikikids:Statistieken/Logs/' + laatsteHistory + '/info?action=raw', 2);
	searchBarWS = '<div><input type="text" id="lc-searchbar" value=' + zoekwoord +'> <button onclick="searchContainsButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactButtonWS();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> </div>'
	+ '<div><img src="https://upload.wikimedia.org/wikipedia/commons/8/8b/OOjs_UI_icon_download.svg" title="height="25"> <button onclick="downloadWS(\';\');"><b>;</b></button> <button onclick="downloadWS(\',\');"><b>,</b></button></button>'; 
	
	// Variabele die informatie geeft over de LogCounter. 
	var logCounterInfo = '<div id="logCounterInfo">Deze pagina laat zien hoeveel paginabezoeken er zijn geweest op een specifieke pagina. De rij "Views" bevat <b>alle</b> views. De rij daarachter laat alleen maar zien hoeveel views komen vanuit iets specifieks, bijvoorbeeld vanuit een categorie of van een mobiele telefoon. <a href="/Speciaal:Statistieken_WikiKids?action=tabel">Klik hier voor statistieken van vorige weken.</a> De statistieken zijn voor het laatst gereset op: <span id="WikiStats-starttijd"> ' + infoHistoryWS['Endtime'] +  '</span> (in UTC).</div>';
	// Controleert of het een speciale week is, als dat het geval is, dan wordt de informatie uitgebreid.
	if (parameterWS['specialeweek']) {
		logCounterInfo += '<span style="color:red;">Let op! De week die je nu bekijkt, is een speciale week. In deze week is gekeken naar de bezoeker op een andere manier dan de standaard manier (per pagina). De gegevens die hier staan zijn dus niet eenvoudig te begrijpen. </span><br>'; 
	}
	// Het maken van een tabel
	var table = document.createElement('table');
	table.classList.add('wikitable');
	var tableHead = document.createElement('thead');
	var tableHeadRow = document.createElement('tr');
	var tableBody = document.createElement('tbody');

	var tableHeadTitles;
	// Geeft de titels van de tabel weer.
	tableHeadTitles = ['Titel', 'Views', infoHistoryWS.Types, '%', '%'];
	/* 
		Variabelen:
		currentPage = de huidige pagina, deze informatie komt uit de parameters die megegeven zijn door de gebruiker
		rowsPerPage = aantal rijen, krijgt de informatie uit de parameters die meegegeven zijn 
		totalPages = totaal aantal pagina's, gebaseerd op het aantal rijen.
	*/ 
	var currentPage = parseInt(parameterWS['pagenr']);
	var rowsPerPage = parseInt(parameterWS['rows']);
	var totalPages = Math.ceil(pages.length / rowsPerPage);
	
	var totalVisitorsAll, totalSpecialVisitorsAll;
	if (infoHistoryWS.Doublerequest) {
		totalVisitorsAll = pages.reduce(function (total, page) {
			return total + page.nV;
		}, 0);
	} else {		
		totalVisitorsAll = pages.reduce(function (total, page) {
			if (!page.nV) { 
				return total + page.mPV;
			} else if (!page.mPV) {
				return total + page.nV;
			} else {
				return total + page.nV + page.mPV;
			}
		}, 0);
	}
	totalSpecialVisitorsAll = pages.reduce(function (total, page) {
		return total + page.mPV;
	}, 0);
	// Functie die een specifieke pagina laat zien, op basis van de parameter 'pageNumber'
	function showPage(pageNumber) {
		currentPage = pageNumber;
		tableBody.innerHTML = '';
		var start = (currentPage - 1) * rowsPerPage;
		var end = start + rowsPerPage;
		var paginatedItems = pages.slice(start, end);
		paginatedItems.forEach(function (page) {
			let row = document.createElement('tr');
			// Definieert variabelen die later nodig zijn
			let totalVisitors, mainPageVisited, pageTitle, pageLink, date, tempDate, filterShow, percentMainPage, percentStyle, pageStyle;
			if (infoHistoryWS.Doublerequest) {
				totalVisitors = page.nV ? page.nV : page.mPV;
			} else {
			// Controleert of een gedeelte van de informatie leeg is gelaten. Dit is enkel voor normale versies
				if (!page.nV) { 
					totalVisitors = page.mPV;
				} else if (!page.mPV) {
					totalVisitors = page.nV;
				} else {
					totalVisitors = page.nV + page.mPV;
				}
			}
			mainPageVisited = page.mPV ? page.mPV : "";
			pageTitle = page.t.replace(/_/g, ' ');
			pageLink = page.t;
			if (parameterWS['specialeweek']) {
				if (pageLink.includes('Tijd')) {
					tempDate = new Date((parseInt(pageTitle.replace(/Tijd.?:/g,"")) + 28026240) * 60 * 1000);
					pageTitle = pageTitle.replace(/Tijd/g,"T").replace(/:.*/g, ":");
				}
			}
			date = new Date(page.uA);
			filterShow = page.filterShow ? page.filterShow : "";
			percentMainPage = Math.round((100/totalVisitors)*mainPageVisited*100)/100;
			percentFromTotal100 = Math.round(totalVisitors/totalVisitorsAll*100*10000)/10000;
			percentStyle = '';
			if (filterShow) { 
		   		percentStyle = 'style="background: ' + filterShow + '"';
			}
			if (pageLink.includes('Zoeken:')) {
				percentFromTotal100 = '<button onclick="deletePageR61(event, \'' + pageTitle + '\');">D</button>';
				pageLink = 'Speciaal:Zoeken?search=' + pageTitle.replace(/Zoeken.?:/g,"");
				/*
				if (containsAnyWS(pageTitle.toLowerCase(), verwijderenWS)) {
					temp5 = pageTitle.replace(containsAnyWS(pageTitle.toLowerCase(), verwijderenWS) , "");
					pageTitle = pageTitle + '</a> - <a href="https://wikikids.nl/Speciaal:Zoeken/' + temp5.replace(/Zoeken.?:/g,"")+ '">' + temp5;
					pageStyle = 'style="background: #FFAAAA;"';
				} */
				let pageTitleO = pageTitle;
				/*
				new mw.Api().get( {
				   action: "query",
				   titles: [ pageTitle.replace(/Zoeken.?:/g,"") ],
				} ).then( function( ret ) {
				   $.each( ret.query.pages, function() {
				   		//console.log(this);
				   		if ( this.missing !== "" ) {
				   			console.log(pageTitleO);
				   			deletePageR61({}, pageTitleO, true);
				    	}
				    });
				});
				*/
				pageTitle = pageTitle.charAt(7).toUpperCase() + pageTitle.slice(8).toLowerCase();
				if (parameterWS['specialdata'] !== 'wit') {
					if (waarschuwingenWS.some(function(v) { return pageTitle.toLowerCase().indexOf(v) >= 0; }) || pageTitle.startsWith('De ') || pageTitle.startsWith('Een ') || (pageTitle.split(" ").length) > 3) {
						pageStyle = 'style="background: orange;"';
						deletePageR61({}, pageTitleO, true);
					}
				}
				pageTitle = 'Zoek:' + pageTitle;
				totalVisitors = '-';
				percentMainPage = '-';
				
			} else if (pageLink.startsWith('X:')) {
				pageLink = '';
				pageStyle = 'style="color:black;"';
				percentMainPage = '-';
				percentFromTotal100 = '-';
			}
			row.innerHTML = `<td ${pageStyle}><a href="/${pageLink}">${pageTitle}</a></td>
				<td>${parseNumberWS(totalVisitors)}</td><td>${parseNumberWS(mainPageVisited)}</td>
				<td ${percentStyle}> ${percentMainPage}</td>
				<td>${percentFromTotal100}</td>`;
			tableBody.appendChild(row);
		});
	}
	showPage(currentPage);

	var pagination = document.createElement('div');
	pagination.classList.add('pagination');

	var prevButton = document.createElement('button');
	prevButton.textContent = 'Vorige';
	prevButton.style = 'margin-right: 10px;';
	prevButton.addEventListener('click', function () {
		if (currentPage > 1) {
			parameterWS['pagenr'] = currentPage - 1; 
			showPage(currentPage - 1);
			changeURLWS();
			// Manier waarop je kunt zien op welke pagina je bent
			document.getElementById('pageCounter').innerHTML = `Pagina <input id="logcounternumberpage" type="number" size="5" value=${currentPage}> van ${totalPages}`;
		}
	});
	pagination.appendChild(prevButton);

	var pageCounter = document.createElement('span');
	pageCounter.id = "pageCounter";
	pageCounter.innerHTML = `Pagina <input id="logcounternumberpage" type="number" size="5" value=${currentPage}> van ${totalPages}`;
	pagination.appendChild(pageCounter);

	var nextButton = document.createElement('button');
	nextButton.textContent = 'Volgende';
	nextButton.style = 'margin-left: 10px;';
	nextButton.addEventListener('click', function () {
		if (currentPage < totalPages) {
			parameterWS['pagenr'] = currentPage + 1; 
			showPage(currentPage + 1);
			changeURLWS();
			// Manier waarop je kunt zien op welke pagina je bent
			document.getElementById('pageCounter').innerHTML = `Pagina <input id="logcounternumberpage" type="number" size="5" value=${currentPage}> van ${totalPages}`;
		}
	});
	
	var gotoButton = document.createElement('button');
	gotoButton.textContent = 'Gaan';
	gotoButton.style = 'margin-left: 10px;';
	gotoButton.addEventListener('click', function () {
		if (document.getElementById('logcounternumberpage').value > totalPages || document.getElementById('logcounternumberpage').value < 1) {
		} else {
			parameterWS['pagenr'] = parseInt(document.getElementById('logcounternumberpage').value); 
			showPage(parseInt(document.getElementById('logcounternumberpage').value));
			changeURLWS();
			document.getElementById('pageCounter').innerHTML = `Pagina <input id="logcounternumberpage" type="number" size="5" value=${currentPage}> van ${totalPages}`;
		}
	});
	
	pagination.appendChild(gotoButton);
	pagination.appendChild(nextButton);
	
	tableHeadTitles.forEach(function (title) {
		var tableHeadCell = document.createElement('th');
		tableHeadCell.textContent = title;
		//if (title === 'Laatste bezoek') {tableHeadCell.classList.add('datumstringWS')}
		tableHeadRow.appendChild(tableHeadCell);
	});
	tableHead.appendChild(tableHeadRow);
	table.appendChild(tableHead);
	table.appendChild(tableBody);
	
	var totalElement = document.createElement('div');
	totalElement.style = 'margin-top: 20px; display: flex; flex-direction: column;';

	var totalVisitorsElement = document.createElement('span');
	totalVisitorsElement.textContent = `Totaal aantal bezoeken: ${parseNumberWS(totalVisitorsAll)}`;
	totalElement.appendChild(totalVisitorsElement);
	
	var totalSpecialVisitorsElement = document.createElement('span');
	totalSpecialVisitorsElement.textContent = `Totaal aantal 'speciale' bezoeken: ${parseNumberWS(totalSpecialVisitorsAll)} (${Math.round((100/totalVisitorsAll)*totalSpecialVisitorsAll*100)/100}%)`;
	totalElement.appendChild(totalSpecialVisitorsElement);

	var totalPagesElement = document.createElement('span');
	totalPagesElement.textContent = `Totaal aantal pagina's: ${parseNumberWS(pages.length)}`;
	totalElement.appendChild(totalPagesElement);
	
	var moreInfoElement = document.createElement('span');	
	if (!infoHistoryWS.Live) {
		let firstDateString = '';
		if (infoHistoryWS.Starttime) {
			let xStarttime = new Date(infoHistoryWS.Starttime); 
			firstDateString = addZeroWS(xStarttime.getDate()) + "-" + addZeroWS((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZeroWS(xStarttime.getHours()) + ":" + addZeroWS(xStarttime.getMinutes());
		}
		const xEndtime = new Date(infoHistoryWS.Endtime); 
		let lastDateString = addZeroWS(xEndtime.getDate()) + "-" + addZeroWS((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZeroWS(xEndtime.getHours()) + ":" + addZeroWS(xEndtime.getMinutes());
		moreInfoElement.textContent = `${firstDateString} tot ${lastDateString}`;
	} else {
		moreInfoElement.textContent = 'Live';
	}
	totalElement.appendChild(moreInfoElement);

	document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + logCounterInfo;
	document.getElementById('bodyContent').appendChild(table);
	document.getElementById('bodyContent').appendChild(pagination);
	document.getElementById('bodyContent').appendChild(totalElement);
}

function getPagesWS() {
	var request = new XMLHttpRequest();
	request.open('GET', urlWS, false);
	request.send(null);
	if (request.status === 200) {
		pages = JSON.parse(request.responseText);
	}

	// hernoemen alle keys zodat het later makkelijker gaat 
	if (!historyWS) {
		if (parameterWS['specialdata']) {
			for (let x = 0; x < pages.length; x++) {
				if (!(pages[x].title.includes('Zoeken:') || pages[x].title.startsWith('X:'))) {
					pages.splice(x, 1);
					x--;
				} else { 
					renamekeyWS('t','title', x);
				}
			}
		} else {
			for (let x = 0; x < pages.length; x++) {
				if (pages[x].title.includes('Zoeken:') || pages[x].title.startsWith('X:')) {
					pages.splice(x, 1);
					x--;
				} else { 
					renamekeyWS('t','title', x);
				}
			}			
		}
	} else {
		if (parameterWS['specialdata']) {
			for (let x = 0; x < pages.length; x++) {
				if (!(pages[x].t.includes('Zoeken:') || pages[x].t.startsWith('X:'))) {
					pages.splice(x, 1);
					x--;
				}
			}
		} else {
			for (let x = 0; x < pages.length; x++) {
				if (pages[x].t.includes('Zoeken:') || pages[x].t.startsWith('X:')) {
					pages.splice(x, 1);
					x--;
				}
			}			
		}
	}
	// Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
	console.log(JSON.stringify(pages));
	pages.sort(function (a, b) {
		return (b.nV || 0) + (b.mPV || 0) - (a.nV || 0) - (a.mPV || 0);
	});

	if (infoHistoryWS.Doublerequest) {
		pages.sort(function (a, b) {
			return b.nV + b.nV - a.nV - a.nV;
		});
	}

	fullPagesWS = pages;

	//Filter percentmax, percentmin, aantalmax, aantalmin, only
	for (let y=0; y < pages.length; y++) {
			pages[y].mPV = pages[y].mPV ? pages[y].mPV : 0;
			pages[y].nV = pages[y].nV ? pages[y].nV : 0;
			if (infoHistoryWS.Doublerequest) {
				aantalviewspagina = pages[y].nV; 
				procent = (100/pages[y].nV)*pages[y].mPV;
				if (procent === Infinity) {
					procent = 100;
				}
			} else {
				aantalviewspagina = pages[y].nV + pages[y].mPV;
				procent = (100/(aantalviewspagina))*pages[y].mPV; // 50
			}
			if (procent < parameterWS['only'][0] || procent > parameterWS['only'][1]) { // dat wat buiten deze categorie ([x, y]) wordt verwijderd.
				pages.splice(y, 1);
				y = y-1;
			} else if (aantalviewspagina < parameterWS['only'][2] || aantalviewspagina > parameterWS['only'][3]) { // bovenstaande 
				pages.splice(y, 1);
				y = y-1;
			} else if (parameterWS['kleur1'] || parameterWS['kleur2'] || parameterWS['kleur3'] || parameterWS['kleur4']) {
				if (parameterWS['kleur1']) {
					if (procent >= parameterWS['kleur1'][0]) {
						if (procent <= parameterWS['kleur1'][1]) {
							haakjenodig = /[G-Za-z]/.test(parameterWS['kleur1'][2]) ? '' : '#';
							pages[y].filterShow = haakjenodig + parameterWS['kleur1'][2]; 
						}
					}
				}
				if (parameterWS['kleur2']) {
					if (procent >= parameterWS['kleur2'][0]) {
						if (procent <= parameterWS['kleur2'][1]) {
							haakjenodig = /[G-Za-z]/.test(parameterWS['kleur2'][2]) ? '' : '#';
							pages[y].filterShow = haakjenodig + parameterWS['kleur2'][2]; 
						}
					}
				}
				if (parameterWS['kleur3']) {
					if (procent >= parameterWS['kleur3'][0]) {
						if (procent <= parameterWS['kleur3'][1]) {
							haakjenodig = /[G-Za-z]/.test(parameterWS['kleur3'][2]) ? '' : '#';
							pages[y].filterShow = haakjenodig + parameterWS['kleur3'][2]; 
						}
					}
				}
				if (parameterWS['kleur4']) {
					if (procent >= parameterWS['kleur4'][0]) {
						if (procent <= parameterWS['kleur4'][1]) {
							haakjenodig = /[G-Za-z]/.test(parameterWS['kleur4'][2]) ? '' : '#';
							pages[y].filterShow = haakjenodig + parameterWS['kleur4'][2]; 
						}
					}
				}
			}
		}
	return pages;
}

function gotoGeschiedenisVanPaginaWS(){
	parameterWS = {}; 
	parameterWS['page'] = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
	changeURLWS();
	startLC();
}

function deletePageR61(event, title, hide) {
	let objectrefhp = {
		title: title
	};
	fetch("https://wikikids.wikirots61.workers.dev/pages/deletepage",
        {
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'text/plain'
            },
            method: "POST",
            body: JSON.stringify(objectrefhp)
        })
        .then(function (res) {})
        .catch(function (res) {});	
    if (!hide) event.target.parentElement.parentElement.style.display = 'none';
}


function searchContainsButtonWS() {
	searchQuery = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
	parameterWS['exactzoeken'] = undefined; 
	parameterWS['action'] = undefined; 
	parameterWS['page'] = undefined; 
	parameterWS['pagenr'] = 1;
	parameterWS['bevatzoeken'] = searchQuery;
	changeURLWS();
	startLC();
}

function searchContainsWS(searchQuery) {
	if (!searchQuery) {
		searchQuery = parameterWS['bevatzoeken'];
	}
	var searchResult = [];
	for (let i = 0; i < allPagesWS.length; i++) {
		if (parameterWS['regex']) {
			regex = new RegExp(searchQuery, "i");
			if (regex.test(allPagesWS[i]['t'].toLowerCase())) {
				searchResult.push(allPagesWS[i]);
			}
		} else {
			if (allPagesWS[i]['t'].toLowerCase().includes(searchQuery.toLowerCase())) {
				searchResult.push(allPagesWS[i]);
			}
		}
	}
	setTimeout(function () {
		if (!searchResult.length) {
			const printToScreen = '<br>Er is geen pagina die <a href="https://wikikids.nl/Speciaal:Zoeken/' + searchQuery + '">' + searchQuery + '</a> bevat, en die in deze periode views heeft ontvangen.' 
			+ 'Kijk voor meer <a href="https://wikikids.nl/WikiKids:Statistieken">informatie op deze pagina</a>.';
			document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + printToScreen;
		} else {
			showProjectWS(searchResult, searchQuery);
		}
	}, 750);
}

function searchExactButtonWS() {
	searchQuery = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
	parameterWS['bevatzoeken'] = undefined; 
	parameterWS['action'] = undefined; 
	parameterWS['page'] = undefined;
	parameterWS['pagenr'] = 1;
	parameterWS['exactzoeken'] = searchQuery;
	changeURLWS();
	startLC();
}

function searchExactWS(searchQuery) {
	if (!searchQuery) {
		searchQuery = parameterWS['exactzoeken'];
	}
	let searchResult = [];
	for (let i = 0; i < allPagesWS.length; i++) {
		if (allPagesWS[i]['t'].toLowerCase() === searchQuery.toLowerCase()) {
			searchResult.push(allPagesWS[i]);
		}
	}
	setTimeout(function () {
		if (!searchResult.length) {
			let printToScreen = '<br>De pagina <a href="https://wikikids.nl/' + searchQuery + '">' + searchQuery + '</a> heeft geen views ontvangen, voldoet niet aan het ingestelde filter of bestaat niet. ';
			document.getElementById('bodyContent').innerHTML = terugnaarWS + searchBarWS + printToScreen;
		} else {
			console.log(searchResult);
			showProjectWS(searchResult, searchQuery);
		}
	}, 750);
}

function getInfoPageWS(urlInfoLogCounter) {
	var infoHistorytemp;
	var request = new XMLHttpRequest();
	request.open('GET', urlInfoLogCounter, false);
	request.send(null);
	if (request.status === 200) {
		infoHistorytemp = JSON.parse(request.responseText);
	}
	return infoHistorytemp;
}

function terugWS(dateparameter, specialeweekparameter) {
	parameterWS = {};
	if (dateparameter || specialeweekparameter) {
		parameterWS['date'] = dateparameter;
		parameterWS['specialeweek'] = specialeweekparameter;
		changeURLWS(); 
		startLC();
	} else {
		changeURLWS(); 
		startLC(true);
	}
}

function changeURLWS() {
	var urlPath = '/Speciaal:Statistieken WikiKids?';
	if (parameterWS['rows']) {
		if (parameterWS['rows'] !== 25) {
			urlPath += 'rows=' + parameterWS['rows'] + '&';
		}
	}
	if (parameterWS['action']) {
		urlPath += 'action=' + parameterWS['action'] + '&';
	}
	if (parameterWS['date']) {
		urlPath += 'date=' + parameterWS['date'] + '&';
	}
	if (parameterWS['page']) {
		urlPath += 'page=' + parameterWS['page'] + '&';
	}
	if (parameterWS['pagenr']) {
		if (parameterWS['pagenr'] < 1 || (parameterWS['pagenr'] > Math.ceil(allPagesWS.length / parameterWS['rows']) || parameterWS['pagenr'] === 1)) {
			parameterWS['pagenr'] = 1; 
		} else {
			urlPath += 'pagenr=' + parameterWS['pagenr'] + '&';
		}
	}
	if (parameterWS['bevatzoeken']) {
		urlPath += 'bevatzoeken=' + parameterWS['bevatzoeken'] + '&';
	}
	if (parameterWS['regex']) {
		urlPath += 'regex=' + parameterWS['regex'] + '&';
	}
	if (parameterWS['exactzoeken']) {
		urlPath += 'exactzoeken=' + parameterWS['exactzoeken'] + '&';
	}
	if (parameterWS['seconddata']) {
		urlPath += 'seconddata=' + parameterWS['seconddata'] + '&';
	}
	if (parameterWS['specialeweek']) {
		urlPath += 'specialeweek=' + parameterWS['specialeweek'] + '&';
	}
	if (JSON.stringify(parameterWS['only']) !== JSON.stringify([0, 100, 0, Infinity])) {
		urlPath += 'only=' + JSON.stringify(parameterWS['only']) + '&';
	}
	if (parameterWS['kleur1']) {
		urlPath += 'kleur1=' + JSON.stringify(parameterWS['kleur1']) + '&';
	}
	if (parameterWS['kleur2']) {
		urlPath += 'kleur2=' + JSON.stringify(parameterWS['kleur2']) + '&';
	}
	if (parameterWS['kleur3']) {
		urlPath += 'kleur3=' + JSON.stringify(parameterWS['kleur3']) + '&';
	}
	if (parameterWS['kleur4']) {
		urlPath += 'kleur4=' + JSON.stringify(parameterWS['kleur4']) + '&';
	}
	if (parameterWS['specialdata']) {
		urlPath += 'specialdata=' + parameterWS['specialdata'] + '&';
	}
	urlPath += 'v=2.0';
	window.history.pushState("","", urlPath);
	//window.history.replaceState("","", urlPath);
}

// Tabel 
function tabelWS() {
	var allHistoryPages;
	var request = new XMLHttpRequest();
	// Geeft alle subpagina's van WikiKids:Statistieken/Logs, /StatistiekenExtra staan in naamruimte Rots, en doen dus niet mee
	request.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=1000&apnamespace=4&apprefix=Statistieken/Logs&aplimit=500&format=json', false);
	request.send(null);
	if (request.status === 200) {
		allHistoryPages = JSON.parse(request.responseText);
	}
	allHistoryPages = allHistoryPages.query.allpages;
	var tableOutputWS = `<table class="wikitable" id="LogCounterHistory"><thead><tr><th onclick="sortTableWS('LogCounterHistory',0)">Link</th><th onclick="sortTableWS('LogCounterHistory',1)">Datum</th><th onclick="sortTableWS('LogCounterHistory',2, true)">Aantal bezoekers</th><th onclick="sortTableWS('LogCounterHistory',3, true)">Aantal pagina's</th><th onclick="sortTableWS('LogCounterHistory',4)">Extra informatie</th></tr></thead><tbody>
	<tr><td><a href="https://wikikids.nl/Special:Statistieken_WikiKids">Live</a></td><td>Sinds zaterdag</td><td>0</td><td>0</td></tr>`;
	requests = new Array(allHistoryPages.length);
		setTimeout(function () {
		for (let i = 0; i < allHistoryPages.length; i++) {
			var url = "https://wikikids.nl/" + allHistoryPages[i]['title'] + '/info?action=raw';
			requests[i] = new XMLHttpRequest();
			requests[i].open("GET", url);
			requests[i].onload = function() {
				var datainfo = JSON.parse(requests[i].responseText);
				tableOutputWS += `<tr><td><a href="https://wikikids.nl/Special:Statistieken_WikiKids?date=${allHistoryPages[i]['title'].slice(-8)}${allHistoryPages[i]['specialeweek'] ? '&specialeweek=true' : ''}">${datainfo['Jaar-Week']}</a></td>`;
				var xStarttime = new Date(datainfo.Starttime); 
				var xEndtime = new Date(datainfo.Endtime); 
				var firstDateString = 'voorgaande week';
				if (xStarttime.getDate()) {
					firstDateString = addZeroWS(xStarttime.getDate()) + "-" + addZeroWS((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZeroWS(xStarttime.getHours()) + ":" + addZeroWS(xStarttime.getMinutes());
				}
				var lastDateString = addZeroWS(xEndtime.getDate()) + "-" + addZeroWS((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZeroWS(xEndtime.getHours()) + ":" + addZeroWS(xEndtime.getMinutes());
				tableOutputWS += `<td>van ${firstDateString} tot ${lastDateString}</td><td>${datainfo.Totalviews}</td><td>${datainfo.Totalpages}</td><td><a href="/WikiKids:Statistieken#${datainfo.Types.replace(/ /g, '_')}">${datainfo.Types}</a></td></tr>`;
			};
			requests[i].send();
		}
		document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
		document.title = "Voorgaande statistieken -  WikiKids";
		infotext = 'Elke zaterdag worden, de statistieken opnieuw opgeslagen. Een week loopt dus van zaterdag tot zaterdag. Het real-time registreren van de bezoekers wordt mogelijk gemaakt door Rots61. Voor vragen kun je terecht bij Rots61. <br>'
		+ 'Deze lijst wordt automatisch bijgewerkt, zodat alle vorige statistieken worden getoont. (Als niet alles is getoond, herlaad de pagina dan.)<br>';
		setTimeout( function () { 
			document.getElementById('bodyContent').innerHTML = terugnaarWS + infotext + tableOutputWS + '</tbody></table>'; 
			sortTableWS('LogCounterHistory',0);
		}, 500);
	}, 500);
}

// Download functies
function downloadWS(tss) {
	let downloadResult = 'Paginatitel' + tss + 'Views' + tss + 'Speciale statistiek \n';
	for (let x = 0; x < allPagesWS.length; x++){
		if (!allPagesWS[x].mPV) {
			downloadResult += allPagesWS[x].t.replace(/,/g, '.') + tss + (allPagesWS[x].nV) + tss + '0' + tss + '\n';
		} else if (!allPagesWS[x].nV) {
			downloadResult += allPagesWS[x].t.replace(/,/g, '.') + tss + (allPagesWS[x].mPV) + tss + allPagesWS[x].mPV + tss + '\n';   
		} else {
			downloadResult += allPagesWS[x].t.replace(/,/g, '.')  + tss + (allPagesWS[x].mPV + allPagesWS[x].nV) + tss + allPagesWS[x].mPV + tss + '\n';
		}
	}
	if (parameterWS['date']) {
		downloadfileWS(downloadResult, 'Statistieken WikiKids ' + parameterWS['date'] +'.csv', 'csv');
	} else {
		downloadfileWS(downloadResult, 'Statistieken WikiKids live.csv', 'csv');
	}
}

function downloadfileWS(data, filename, type) {
	var file = new Blob([data], {type: type});
	if (window.navigator.msSaveOrOpenBlob)
		window.navigator.msSaveOrOpenBlob(file, filename+"." + type);
	else { 
		var a = document.createElement("a"),
		url = URL.createObjectURL(file);
		a.href = url;
		a.download = filename;
		document.body.appendChild(a);
		a.click();
		setTimeout(function() {
			document.body.removeChild(a);
			window.URL.revokeObjectURL(url);  
		}, 0); 
	}
}

// Functies van het internet, of die iets veel makkelijker maken, zonder dat er onderhoud voor nodig is. 
function sortTableWS(id, n, getal) {
  var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
  table = document.getElementById(id);
  switching = true;
  // Set the sorting direction to ascending:
  dir = "asc";
  /* Make a loop that will continue until
  no switching has been done: */
  while (switching) {
	// Start by saying: no switching is done:
	switching = false;
	rows = table.rows;
	/* Loop through all table rows (except the
	first, which contains table headers): */
	for (i = 1; i < (rows.length - 1); i++) {
	  // Start by saying there should be no switching:
	  shouldSwitch = false;
	  /* Get the two elements you want to compare,
	  one from current row and one from the next: */
	  x = rows[i].getElementsByTagName("TD")[n];
	  y = rows[i + 1].getElementsByTagName("TD")[n];
	  /* Check if the two rows should switch place,
	  based on the direction, asc or desc: */
	  if (getal) {
		  if (dir === "asc") {
			if (parseInt(x.innerHTML) > parseInt(y.innerHTML)) {
			  // If so, mark as a switch and break the loop:
			  shouldSwitch = true;
			  break;
			}
		  } else if (dir == "desc") {
			if (parseInt(x.innerHTML) < parseInt(y.innerHTML)) {
			  // If so, mark as a switch and break the loop:
			  shouldSwitch = true;
			  break;
			}
		  }
	  } else {
		  if (dir == "asc") {
			if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
			  // If so, mark as a switch and break the loop:
			  shouldSwitch = true;
			  break;
			}
		  } else if (dir == "desc") {
			if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
			  // If so, mark as a switch and break the loop:
			  shouldSwitch = true;
			  break;
			}
		  }
	  }
	}
	if (shouldSwitch) {
	  /* If a switch has been marked, make the switch
	  and mark that a switch has been done: */
	  rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
	  switching = true;
	  // Each time a switch is done, increase this count by 1:
	  switchcount++;
	} else {
	  /* If no switching has been done AND the direction is "asc",
	  set the direction to "desc" and run the while loop again. */
	  if (switchcount === 0 && dir === "asc") {
		dir = "desc";
		switching = true;
	  }
	}
  }
}

function checkJsonWS(item, returnvalue) {
	let value = typeof item !== "string" ? JSON.stringify(item) : item;    
	try {
		value = JSON.parse(value);
	} catch (e) {
		return returnvalue;
	}
	if (typeof value === "object" && value !== null) {
		return JSON.parse(item);
	} else {
		return returnvalue; 	
	}
}

function clearSecondStatsWS() {
	var settings = {
	  "url": "https://wikikids.wikirots61.workers.dev/pages/delete",
	  "method": "POST",
	  "timeout": 0,
	  "headers": {
	    "Host": "wikikids.wikirots61.workers.dev/",
	    "Content-Type": "application/json"
	  },
	  "data": JSON.stringify({
	    "message": 'gek'
	  }),
	};
	$.ajax(settings).done(function (response) {
		mw.notify("Reseten statistieken gelukt", { autoHide: false });
		window.onbeforeunload = null;
	}).catch(function (error) {
		if (error.responseText || JSON.parse(error.responseText).succes) {
			mw.notify("Reseten statistieken2 gelukt", { autoHide: false });
			window.onbeforeunload = null;
		} else {
			mw.notify('Resetten mislukt, stuur Rots61 aub direct een berichtje.', {autoHide: false});
		}
	});
}


function renamekeyWS(new_key, old_key, x){
	Object.defineProperty(pages[x], new_key,
		Object.getOwnPropertyDescriptor(pages[x], old_key));
	delete pages[x][old_key];
}

// Einde functies van het internet

function startLC(reloadlc, firsttime) {	
	parameterWS['version'] = mw.util.getParamValue('v') ? mw.util.getParamValue('v') : false; 

	// worden ondersteund door versie 1 & 2 
	parameterWS['rows'] = mw.util.getParamValue('rows') ?  mw.util.getParamValue('rows') : 25;
	parameterWS['action'] = mw.util.getParamValue('action');
	parameterWS['date'] = mw.util.getParamValue('date');
	parameterWS['page'] = mw.util.getParamValue('page');
	parameterWS['pagenr'] = mw.util.getParamValue('pagenr') ? mw.util.getParamValue('pagenr') : 1;
	parameterWS['bevatzoeken'] = mw.util.getParamValue('bevatzoeken');
	parameterWS['regex'] = mw.util.getParamValue('regex');
	parameterWS['exactzoeken'] = mw.util.getParamValue('exactzoeken'); 
	parameterWS['specialeweek'] = mw.util.getParamValue('specialeweek');
	parameterWS['seconddata'] = mw.util.getParamValue('seconddata');
	
	parameterWS['specialdata'] = mw.util.getParamValue('specialdata');
	var allowedUsersSpecialData = ["Rots61", "Hanssain", "Mike1023", "Hippogryph", "PaulD", "Wouter15", "S.Perquin", "Gerarddummer", "Groempdebeer", "DeHelpendePenny", "FreekKraak"];
	if (!allowedUsersSpecialData.includes(mw.config.get('wgUserName')) && parameterWS['specialdata']) {
		parameterWS['specialdata'] = false;
		mw.notify( 'Helaas, je hebt geen toegang tot deze specifieke gegevens. Je kunt wel de normale statistieken bekijken. Controleer of je ingelogd bent. ', { autoHideSeconds : 30 } );
	}
	
	if (parameterWS['version'] === '1.0' || parameterWS['version'] === '1.1') {
		parameterWS['percentmin'] = mw.util.getParamValue('percentmin') ? mw.util.getParamValue('percentmin') : -1;
		parameterWS['percentmax'] = mw.util.getParamValue('percentmax') ? mw.util.getParamValue('percentmax') : 100;
		parameterWS['only'] = mw.util.getParamValue('only'); 
		parameterWS['aantalmax'] = mw.util.getParamValue('aantalmax') ? mw.util.getParamValue('aantalmax') : Infinity;
		parameterWS['aantalmin'] = mw.util.getParamValue('aantalmin') ? mw.util.getParamValue('aantalmin') : 0;
		if (parameterWS['only']) {
			parameterWS['only'] = [parameterWS['percentmin'] ? parameterWS['percentmin'] : 0 , parameterWS['percentmax'] ?  parameterWS['percentmax'] : 100, parameterWS['aantalmin'] ? parameterWS['aantalmin'] : 0, parameterWS['aantalmax'] ? parameterWS['aantalmax'] : Infinity];
		} else if (parameterWS['version'] === '1.1') {
			parameterWS['only'] = [0, 100, 0, Infinity];
			parameterWS['kleur1'] = [0, parameterWS['percentmin'], 'aqua'];
			parameterWS['kleur2'] = [parameterWS['percentmax'], 100, 'orange'];
		} else {
			parameterWS['only'] = [0, 100, 0, Infinity];
			parameterWS['kleur1'] = [parameterWS['percentmin'], parameterWS['percentmax'], 'lightgreen']; 
		}
	} else {
		parameterWS['only'] = checkJsonWS(mw.util.getParamValue('only'), [0, 100, 0, Infinity]);
		parameterWS['kleur1'] = checkJsonWS(mw.util.getParamValue('kleur1'), false);
		parameterWS['kleur2'] = checkJsonWS(mw.util.getParamValue('kleur2'), false);
		parameterWS['kleur3'] = checkJsonWS(mw.util.getParamValue('kleur3'), false);
		parameterWS['kleur4'] = checkJsonWS(mw.util.getParamValue('kleur4'), false);
		if (!parameterWS['only'][1]) {
			parameterWS['only'][1] = 100;
		}
		if (!parameterWS['only'][2]) {
			parameterWS['only'][2] = 0;
		}
		if (!parameterWS['only'][3]) {
			parameterWS['only'][3] = Infinity;
		}
		if (!parameterWS['kleur1'][2] && parameterWS['kleur1']) {
			parameterWS['kleur1'][2] = 'lightblue';
		}
		if (!parameterWS['kleur2'][2] && parameterWS['kleur2']) {
			parameterWS['kleur2'][2] = 'lightgreen';
		}
		if (!parameterWS['kleur3'][2] && parameterWS['kleur3']) {
			parameterWS['kleur3'][2] = 'pink';
		}
		if (!parameterWS['kleur4'][2] && parameterWS['kleur4']) {
			parameterWS['kleur4'][2] = 'orange';
		}
	}

	// zorgt ervoor dat er bovenin een link terug verwijst naar de basisinstellingen van de logcounter. 
	terugnaarWS = '<div id="contentSub"><span class="subpages">&lt; <a href="javascript:terugWS();" title="Speciaal:Statistieken WikiKids">Speciaal:Statistieken WikiKids</a>';
	if (parameterWS['date']) {
		terugnaarWS += ' | <a href="javascript:terugWS(' + parameterWS['date'];
		if (parameterWS['specialeweek']) {
			terugnaarWS += ', true';
		}
		terugnaarWS +=  ');" title="Speciaal:Statistieken/' + parameterWS['date'] + '">' + parameterWS['date'] + '</a>'; 
	}
	terugnaarWS += '</span></div>';
	if (parameterWS['date']) {
		if (parameterWS['specialeweek']) {
			urlWS = 'https://wikikids.nl/User:Rots61/StatistiekenExtra/' + parameterWS['date'] + '?action=raw';
			infoHistoryWS = getInfoPageWS('https://wikikids.nl/User:Rots61/StatistiekenExtra/' + parameterWS['date'] + '/info?action=raw');
		} else {
			urlWS = 'https://wikikids.nl/Wikikids:Statistieken/Logs/' + parameterWS['date'] + '?action=raw';
			infoHistoryWS = getInfoPageWS('https://wikikids.nl/Wikikids:Statistieken/Logs/' + parameterWS['date'] + '/info?action=raw');
		}
		historyWS = true;
	} else if (parameterWS['seconddata']) {
		if (parameterWS['seconddata'].startsWith('http')) { 
			urlWS = parameterWS['seconddata'];
		} else {
			urlWS = 'https://wikikids.wikirots61.workers.dev/pages';	
		}
		historyWS = false;
	} else {
		urlWS = 'https://wikikids.dekenos.nl/pages';
		historyWS = false;
	}

	if (parameterWS['action'] === 'tabel') {
		tabelWS();
	} else if (parameterWS['page']) { // Views voor een pagina, de hele tijd; 
		mw.notify('Deze functie is niet meer beschikbaar. Omdat hij niet goed werkt. ');
	} else {
		if (firsttime) {
			allPagesWS = getPagesWS();
			changeURLWS();
		} else if (reloadlc) {
			allPagesWS = getPagesWS();
		} else {
			allPagesWS = fullPagesWS;
		}
		if (parameterWS['bevatzoeken'] || parameterWS['regex']) {
			searchContainsWS(parameterWS['bevatzoeken']);
		} else if (parameterWS['exactzoeken']) {
			searchExactWS(parameterWS['exactzoeken']);
		} else {
			showProjectWS(allPagesWS, '');
		}
	}
}

var pages = [];
if (mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "LogCounter" || (mw.config.get('wgTitle') === "Statistieken Wikikids" || (mw.config.get('wgTitle') === "Statistieken WikiKids" || mw.config.get('wgTitle') === "WikiStats")))) {
	document.getElementById('bodyContent').innerHTML = 'WikiStats is aan het opstarten. Dit kan enkele seconden duren. ';
	var parameterWS = {};
	var historyWS, urlWS, allPagesWS, fullPagesWS, terugnaarWS, historyOutputWS, searchBarWS;
	//var downloadAllWS = []; 
	// deze variabele regelt wat er bovenin de tabel te zien is als speciale statistiek. Ook regelt hij dingen zoals de dubbele requests. Zodat het goed geregeld kan worden. 
	var infoHistoryWS = {"Types":"Mobiel", Live:true};
	var waarschuwingenWS = ['hebben', 'wat eten', 'wat ', 'wat eet', 'info', 'beziens', 'wat probeer', 'feiten', 'aantal', 'hoezo', 'wat deed', 'wat deden', 'wat als', 'warom', 'wat kan', 'mag je', 'top 1', 'plaatje', 'afbeelding', 'foto', 'hoeveel', 'wat doe', 'waneer', 'leefomgeving', 'ontstaan', 'informatie', 'verhalen', 'wat heb', 'graag', 'wat zijn', 'van een', 'kan er', '?', 'spreekbeurt', 'cultuur', 'leeftijd', 'waarvan', 'heeft', 'wat beteken', 'geschiedenis', 'bekend', 'wie ', 'leuk', 'zoek', 'is een', 'ooit', 'waar ', 'woont', 'in de ', 'belangrijk', 'beroemd', 'welk', 'wanneer', 'waarom', 'hoe ', 'belangerijk', ' de ', ' het ', 'wat is ', 'hoofstad', 'weetje'];
	var verwijderenWS = [];
	mw.loader.using('mediawiki.util', function() {
		mw.util.addPortletLink('p-namespaces', 
			'https://wikikids.nl/index.php?title=Overleg_gebruiker:Rots61&action=edit&section=new', 
			'Vragen? ', '#linkNaarOverlegPaginaR61', "Vragen over de statistieken");
	});
	mw.loader.using('mediawiki.util', function() {
		mw.util.addPortletLink('p-namespaces', 
			'https://wikikids.nl/WikiKids:Statistieken', 
			'Info ', '#linkNaarWKStatistieken', "Informatie over de statistieken");
	});	$.when($.ready, mw.loader.using(['mediawiki.util'])).done(function () {
		document.getElementById("footer-places").innerHTML += '<li id="footer-places-gadget-LogCounter">Script gemaakt door <a href="/User:MakiBoy" title="Gebruiker:MakiBoy">MakiBoy</a> en <a href="/User:Rots61" title="Gebruiker:Rots61">Rots61</a></li>';
	});
	startLC(true, 'first');
}

if ((!mw.storage.get('disableLoggingWS')) || mw.config.get('wgNamespaceNumber') !== 0) {
	mw.storage.set('disableLoggingWS', true, 604800);
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Rots61/JS-WikiStats.js&oldid=972564"