Gebruiker:MakiBoy/Gadget-LogCounter.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
 
(22 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 1: Regel 1:
 
/* jshint sub:true maxerr:100000 */
 
/* jshint sub:true maxerr:100000 */
 
// [[User:MakiBoy/Gadget-LogCounter.js]] gemaakt door [[User:MakiBoy]] en [[User:Rots61]], onderhouden door [[User:Rots61]]
 
// [[User:MakiBoy/Gadget-LogCounter.js]] gemaakt door [[User:MakiBoy]] en [[User:Rots61]], onderhouden door [[User:Rots61]]
let mw, document, console;
 
const version = '3.2';
 
let searchBarLC;
 
  
// Wordt gebruikt om de views op de juiste manier te formaten
+
var version = '3.2';
 +
var searchBarLC;
 +
 
 +
// Wordt gebruikt om de views op de juiste manier te formaten  
 
function parseNumber (number) {
 
function parseNumber (number) {
 
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
 
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
Regel 11: Regel 11:
  
 
// Wordt gebruikt om een nul toe te voegen bij de datum
 
// Wordt gebruikt om een nul toe te voegen bij de datum
function addZero (number) {
+
function addZero(number) {
return number < 10 ? '0' + number : number;
+
return number < 10 ? "0" + number : number;
 
}
 
}
  
Regel 22: Regel 22:
  
 
function showProjectLogCounter (pages, zoekbalk) {
 
function showProjectLogCounter (pages, zoekbalk) {
// Dit zorgt ervoor dat de kleur wordt weergegeven of de kleurcode.
+
// Dit zorgt ervoor dat de kleur wordt weergegeven of de kleurcode.  
const haakjesfilterkleur = /[G-Za-z]/.test(parameterLC['filterkleur']) ? '' : '#';
+
var haakjesfilterkleur = /[G-Za-z]/.test(parameterLC['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";
 
+
/*
+
searchBarLC = '<div><input type="text" id="lc-searchbar" value=' + zoekbalk +'> <button onclick="searchContainsLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPagina()"><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>'
variabele voor de bovenkant
 
zoekbalk = wordt zichtbaar in de zoekbalk, hierdoor weet de gebruiker wat hij opgezocht heeft
 
reload? ?LCx = 3 variablen die ervoor zorgen dat de juiste icoontje rechts zichtbaar is.
 
*/
 
searchBarLC = '<div><input type="text" id="lc-searchbar" value=' + zoekbalk + '> <button onclick="searchContainsLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPagina()"><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: ' + reload1LCx + ';"><a href="javascript:reload1LC();"><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: ' + reload2LCx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3LCx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/f/f6/OOjs_UI_icon_check-constructive.svg" width="50"></a></div></div></div>'
 
+ '<div style="float:right;"><div id="reload1" style="display: ' + reload1LCx + ';"><a href="javascript:reload1LC();"><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: ' + reload2LCx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3LCx + ';"><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"> <button onclick="downloadLogCounter(\';\');"><b>;</b></button> <button onclick="downloadLogCounter(\',\');"><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="downloadLogCounter(\';\');"><b>;</b></button> <button onclick="downloadLogCounter(\',\');"><b>,</b></button></button>';  
// Variabele die informatie geeft over de LogCounter.
+
let 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>';
+
// 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>';
 
// 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 (parameterLC['specialeweek']) {
 
if (parameterLC['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>';
+
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
 
// Het maken van een tabel
const table = document.createElement('table');
+
var table = document.createElement('table');
 
table.classList.add('wikitable');
 
table.classList.add('wikitable');
const tableHead = document.createElement('thead');
+
var tableHead = document.createElement('thead');
const tableHeadRow = document.createElement('tr');
+
var tableHeadRow = document.createElement('tr');
const tableBody = document.createElement('tbody');
+
var tableBody = document.createElement('tbody');
  
let tableHeadTitles;
+
var tableHeadTitles;
// Geeft de titels van de tabel weer. Als het gaat om een afgeronde week, wordt de informatie anders geüpdated.
+
// Geeft de titels van de tabel weer.
if (infoHistory) {
+
tableHeadTitles = ['Titel', 'Laatste bezoek', 'Views', infoHistory.Types, '%'];
// Haalt de een na laatste titel van de info pagina van de week.
+
/*  
tableHeadTitles = ['Titel', 'Laatste bezoek', 'Views', infoHistory.Types, '%'];
 
} else {
 
// De een na laatste wordt elke week aangepast, zodat het de juiste informatie geeft.
 
tableHeadTitles = ['Titel', 'Laatste bezoek', 'Views', 'Chrome(ium)', '%'];
 
}
 
/*
 
 
Variabelen:
 
Variabelen:
 
currentPage = de huidige pagina, deze informatie komt uit de parameters die megegeven zijn door de gebruiker
 
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
+
rowsPerPage = aantal rijen, krijgt de informatie uit de parameters die meegegeven zijn  
 
totalPages = totaal aantal pagina's, gebaseerd op het aantal rijen.
 
totalPages = totaal aantal pagina's, gebaseerd op het aantal rijen.
*/
+
*/  
let currentPage = parseInt(parameterLC['pagenr']);
+
var currentPage = parseInt(parameterLC['pagenr']);
const rowsPerPage = parseInt(parameterLC['rows']);
+
var rowsPerPage = parseInt(parameterLC['rows']);
const totalPages = Math.ceil(pages.length / rowsPerPage);
+
var totalPages = Math.ceil(pages.length / rowsPerPage);
 
+
 
// 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) {
 
currentPage = pageNumber;
 
currentPage = pageNumber;
 
tableBody.innerHTML = '';
 
tableBody.innerHTML = '';
const start = (currentPage - 1) * rowsPerPage;
+
var start = (currentPage - 1) * rowsPerPage;
const end = start + rowsPerPage;
+
var end = start + rowsPerPage;
const paginatedItems = pages.slice(start, end);
+
var paginatedItems = pages.slice(start, end);
 
paginatedItems.forEach(function (page) {
 
paginatedItems.forEach(function (page) {
let dateString;
+
var dateString;  
const row = document.createElement('tr');
+
var row = document.createElement('tr');
 
// Definieert variabelen die later nodig zijn
 
// Definieert variabelen die later nodig zijn
let totalVisitors, mainPageVisited, pageTitle, pageLink, date, tempDate;
+
var totalVisitors, mainPageVisited, pageTitle, pageLink, date, tempDate, filterShow, percentMainPage, percentStyle;
// Controleert of een gedeelte van de informatie leeg is gelaten. Dit is enkel voor voorgaande versies
+
if (infoHistory.Doublerequest) {
if (!page.nV) {
+
totalVisitors = page.nV ? page.nV :  page.mPV;
totalVisitors = page.mPV;
+
console.log(totalVisitors);
} else if (!page.mPV) {
 
totalVisitors = page.nV;
 
 
} else {
 
} else {
totalVisitors = page.nV + page.mPV;
+
// 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;
 +
}
 
}
 
}
// Vervangt de
+
mainPageVisited = page.mPV ? page.mPV : "";
mainPageVisited = page.mPV ? page.mPV : '';
 
 
pageTitle = page.t.replace(/_/g, ' ');
 
pageTitle = page.t.replace(/_/g, ' ');
 
pageLink = page.t;
 
pageLink = page.t;
 
if (parameterLC['specialeweek']) {
 
if (parameterLC['specialeweek']) {
 
if (pageLink.includes('Zoeken:')) {
 
if (pageLink.includes('Zoeken:')) {
pageLink = 'https://wikikids.nl/Speciaal:Zoeken?search=' + pageTitle.replace(/Zoeken.?:/g, '');
+
pageLink = 'https://wikikids.nl/Speciaal:Zoeken?search=' + pageTitle.replace(/Zoeken.?:/g,"");
pageTitle = pageTitle.replace(/Zoeken:/g, 'Zoek:');
+
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 = addZero(tempDate.getDate()) + ' april ' + addZero(tempDate.getHours()) + ':' + addZero(tempDate.getMinutes());
+
dateString = addZero(tempDate.getDate()) + ' april ' + addZero(tempDate.getHours()) + ":" + addZero(tempDate.getMinutes());
 
}
 
}
 
}
 
}
 
date = new Date(page.uA);
 
date = new Date(page.uA);
const filterShow = page.filterShow ? page.filterShow : '';
+
filterShow = page.filterShow ? page.filterShow : "";
const percentMainPage = Math.round((100 / totalVisitors) * mainPageVisited * 100) / 100;
+
percentMainPage = Math.round((100/totalVisitors)*mainPageVisited*100)/100;
let percentStyle = '>';
+
percentStyle = '>';
if (filterShow === 'colored') {
+
if (filterShow === 'colored') {  
percentStyle = ' style="background: ' + haakjesfilterkleur + parameterLC['filterkleur'] + '">';
+
  percentStyle = ' style="background: ' + haakjesfilterkleur + parameterLC['filterkleur'] + '">';
 
}
 
}
 
if (parameterLC['specialeweek'] && (pageLink.includes('Speciaal:Zoeken?') || pageLink.includes('Tijd'))) {
 
if (parameterLC['specialeweek'] && (pageLink.includes('Speciaal:Zoeken?') || pageLink.includes('Tijd'))) {
 
if (pageLink.includes('Speciaal:Zoeken?')) {
 
if (pageLink.includes('Speciaal:Zoeken?')) {
dateString = '-';
+
dateString = "-";
 
}
 
}
 
} else if (!isNaN(date)) {
 
} else if (!isNaN(date)) {
dateString = addZero(date.getDate()) + '-' + addZero((date.getMonth() + 1)) + '-' + date.getFullYear() + ' ' + addZero(date.getHours()) + ':' + addZero(date.getMinutes());
+
dateString = addZero(date.getDate()) + "-" + addZero((date.getMonth() + 1)) + "-" + date.getFullYear() + " " + addZero(date.getHours()) + ":" + addZero(date.getMinutes());
 
} else {
 
} else {
dateString = 'Niet beschikbaar';
+
dateString = "Niet beschikbaar";
 
}
 
}
 
row.innerHTML = `<td><a href="/${pageLink}">${pageTitle}</a></td>
 
row.innerHTML = `<td><a href="/${pageLink}">${pageTitle}</a></td>
Regel 129: Regel 123:
 
showPage(currentPage);
 
showPage(currentPage);
  
const pagination = document.createElement('div');
+
var pagination = document.createElement('div');
 
pagination.classList.add('pagination');
 
pagination.classList.add('pagination');
  
const prevButton = document.createElement('button');
+
var prevButton = document.createElement('button');
 
prevButton.textContent = 'Vorige';
 
prevButton.textContent = 'Vorige';
 
prevButton.style = 'margin-right: 10px;';
 
prevButton.style = 'margin-right: 10px;';
 
prevButton.addEventListener('click', function () {
 
prevButton.addEventListener('click', function () {
 
if (currentPage > 1) {
 
if (currentPage > 1) {
parameterLC['pagenr'] = currentPage - 1;
+
parameterLC['pagenr'] = currentPage - 1;  
 
showPage(currentPage - 1);
 
showPage(currentPage - 1);
 
changeURL();
 
changeURL();
Regel 146: Regel 140:
 
pagination.appendChild(prevButton);
 
pagination.appendChild(prevButton);
  
const pageCounter = document.createElement('span');
+
var pageCounter = document.createElement('span');
pageCounter.id = 'pageCounter';
+
pageCounter.id = "pageCounter";
 
pageCounter.innerHTML = `Pagina <input id="logcounternumberpage" type="number" size="5" value=${currentPage}> van ${totalPages}`;
 
pageCounter.innerHTML = `Pagina <input id="logcounternumberpage" type="number" size="5" value=${currentPage}> van ${totalPages}`;
 
pagination.appendChild(pageCounter);
 
pagination.appendChild(pageCounter);
  
const nextButton = document.createElement('button');
+
var nextButton = document.createElement('button');
 
nextButton.textContent = 'Volgende';
 
nextButton.textContent = 'Volgende';
 
nextButton.style = 'margin-left: 10px;';
 
nextButton.style = 'margin-left: 10px;';
 
nextButton.addEventListener('click', function () {
 
nextButton.addEventListener('click', function () {
 
if (currentPage < totalPages) {
 
if (currentPage < totalPages) {
parameterLC['pagenr'] = currentPage + 1;
+
parameterLC['pagenr'] = currentPage + 1;  
 
showPage(currentPage + 1);
 
showPage(currentPage + 1);
 
changeURL();
 
changeURL();
Regel 163: Regel 157:
 
}
 
}
 
});
 
});
 
+
const gotoButton = document.createElement('button');
+
var gotoButton = document.createElement('button');
 
gotoButton.textContent = 'Gaan';
 
gotoButton.textContent = 'Gaan';
 
gotoButton.style = 'margin-left: 10px;';
 
gotoButton.style = 'margin-left: 10px;';
Regel 170: Regel 164:
 
if (document.getElementById('logcounternumberpage').value > totalPages || document.getElementById('logcounternumberpage').value < 1) {
 
if (document.getElementById('logcounternumberpage').value > totalPages || document.getElementById('logcounternumberpage').value < 1) {
 
} else {
 
} else {
parameterLC['pagenr'] = parseInt(document.getElementById('logcounternumberpage').value);
+
parameterLC['pagenr'] = parseInt(document.getElementById('logcounternumberpage').value);  
 
showPage(parseInt(document.getElementById('logcounternumberpage').value));
 
showPage(parseInt(document.getElementById('logcounternumberpage').value));
 
changeURL();
 
changeURL();
Regel 176: Regel 170:
 
}
 
}
 
});
 
});
 
+
 
pagination.appendChild(gotoButton);
 
pagination.appendChild(gotoButton);
 
pagination.appendChild(nextButton);
 
pagination.appendChild(nextButton);
 
+
 
tableHeadTitles.forEach(function (title) {
 
tableHeadTitles.forEach(function (title) {
const tableHeadCell = document.createElement('th');
+
var tableHeadCell = document.createElement('th');
 
tableHeadCell.textContent = title;
 
tableHeadCell.textContent = title;
 
tableHeadRow.appendChild(tableHeadCell);
 
tableHeadRow.appendChild(tableHeadCell);
Regel 188: Regel 182:
 
table.appendChild(tableHead);
 
table.appendChild(tableHead);
 
table.appendChild(tableBody);
 
table.appendChild(tableBody);
 
+
const totalVisitors = pages.reduce(function (total, page) {
+
var totalVisitors;
if (!page.nV) {
+
if (infoHistory.Doublerequest) {
return total + page.mPV;
+
totalVisitors = pages.reduce(function (total, page) {
} else if (!page.mPV) {
 
 
return total + page.nV;
 
return total + page.nV;
} else {
+
}, 0);
return total + page.nV + page.mPV;
+
} else {
}
+
totalVisitors = pages.reduce(function (total, page) {
}, 0);
+
if (!page.nV) {
 
+
return total + page.mPV;
const totalElement = document.createElement('div');
+
} else if (!page.mPV) {
 +
return total + page.nV;
 +
} else {
 +
return total + page.nV + page.mPV;
 +
}
 +
}, 0);
 +
}
 +
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;';
  
const totalVisitorsElement = document.createElement('span');
+
var totalVisitorsElement = document.createElement('span');
 
totalVisitorsElement.textContent = `Totaal aantal bezoeken: ${parseNumber(totalVisitors)}`;
 
totalVisitorsElement.textContent = `Totaal aantal bezoeken: ${parseNumber(totalVisitors)}`;
 
totalElement.appendChild(totalVisitorsElement);
 
totalElement.appendChild(totalVisitorsElement);
  
const totalPagesElement = document.createElement('span');
+
var totalPagesElement = document.createElement('span');
 
totalPagesElement.textContent = `Totaal aantal pagina's: ${parseNumber(pages.length)}`;
 
totalPagesElement.textContent = `Totaal aantal pagina's: ${parseNumber(pages.length)}`;
 
totalElement.appendChild(totalPagesElement);
 
totalElement.appendChild(totalPagesElement);
 
+
if (infoHistory) {
+
var moreInfoElement = document.createElement('span');
const moreInfoElement = document.createElement('span');
+
if (!infoHistory.Live) {
const xStarttime = new Date(infoHistory.Starttime);
+
var xStarttime = new Date(infoHistory.Starttime);  
const xEndtime = new Date(infoHistory.Endtime);
+
var xEndtime = new Date(infoHistory.Endtime);  
const firstDateString = addZero(xStarttime.getDate()) + '-' + addZero((xStarttime.getMonth() + 1)) + '-' + xStarttime.getFullYear() + ' ' + addZero(xStarttime.getHours()) + ':' + addZero(xStarttime.getMinutes());
+
var firstDateString = addZero(xStarttime.getDate()) + "-" + addZero((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZero(xStarttime.getHours()) + ":" + addZero(xStarttime.getMinutes());
const lastDateString = addZero(xEndtime.getDate()) + '-' + addZero((xEndtime.getMonth() + 1)) + '-' + xEndtime.getFullYear() + ' ' + addZero(xEndtime.getHours()) + ':' + addZero(xEndtime.getMinutes());
+
var lastDateString = addZero(xEndtime.getDate()) + "-" + addZero((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZero(xEndtime.getHours()) + ":" + addZero(xEndtime.getMinutes());
 
moreInfoElement.textContent = `${firstDateString} tot ${lastDateString}`;
 
moreInfoElement.textContent = `${firstDateString} tot ${lastDateString}`;
totalElement.appendChild(moreInfoElement);
+
} else {
 +
moreInfoElement.textContent = 'Live';
 
}
 
}
document.getElementById('bodyContent').innerHTML = window.location.search.includes('&') ? terugnaarlogcounter : '';
+
totalElement.appendChild(moreInfoElement);
document.getElementById('bodyContent').innerHTML += searchBarLC + logCounterInfo;
+
 
 +
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + logCounterInfo;
 
document.getElementById('bodyContent').appendChild(table);
 
document.getElementById('bodyContent').appendChild(table);
 
document.getElementById('bodyContent').appendChild(pagination);
 
document.getElementById('bodyContent').appendChild(pagination);
Regel 226: Regel 228:
 
}
 
}
  
function downloadLogCounter (tss) {
+
function downloadLogCounter(tss) {
let a = 'Paginatitel' + tss + 'Views' + tss + 'Speciale statistiek \n';
+
var a = 'Paginatitel' + tss + 'Views' + tss + 'Speciale statistiek \n';
for (let x = 0; x < allPages.length; x++) {
+
for (var x = 0; x < allPages.length; x++){
 
if (!allPages[x].mPV) {
 
if (!allPages[x].mPV) {
 
a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].nV) + tss + '0' + tss + '\n';
 
a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].nV) + tss + '0' + tss + '\n';
 
} else if (!allPages[x].nV) {
 
} else if (!allPages[x].nV) {
a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].mPV) + tss + allPages[x].mPV + tss + '\n';
+
a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].mPV) + tss + allPages[x].mPV + tss + '\n';  
 
} else {
 
} else {
a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].mPV + allPages[x].nV) + tss + allPages[x].mPV + tss + '\n';
+
a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].mPV + allPages[x].nV) + tss + allPages[x].mPV + tss + '\n';
 
}
 
}
 
}
 
}
 
if (parameterLC['date']) {
 
if (parameterLC['date']) {
downloadfile(a, 'Statistieken WikiKids ' + parameterLC['date'] + '.csv', 'csv');
+
downloadfile(a, 'Statistieken WikiKids ' + parameterLC['date'] +'.csv', 'csv');
 
} else {
 
} else {
 
downloadfile(a, 'Statistieken WikiKids live.csv', 'csv');
 
downloadfile(a, 'Statistieken WikiKids live.csv', 'csv');
Regel 244: Regel 246:
 
}
 
}
  
function downloadfile (data, filename, type) {
+
function downloadfile(data, filename, type) {
const file = new Blob([data], { type: type });
+
var file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveOrOpenBlob(file, filename + '.' + type); } else {
+
if (window.navigator.msSaveOrOpenBlob)
const a = document.createElement('a');
+
window.navigator.msSaveOrOpenBlob(file, filename+"." + type);
const url = URL.createObjectURL(file);
+
else {  
 +
var a = document.createElement("a"),
 +
url = URL.createObjectURL(file);
 
a.href = url;
 
a.href = url;
 
a.download = filename;
 
a.download = filename;
 
document.body.appendChild(a);
 
document.body.appendChild(a);
 
a.click();
 
a.click();
setTimeout(function () {
+
setTimeout(function() {
 
document.body.removeChild(a);
 
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
+
window.URL.revokeObjectURL(url);
}, 0);
+
}, 0);  
 
}
 
}
 
}
 
}
  
function statsPerPageLogCounter () {
+
function statsPerPageLogCounter() {
document.title = 'Statistieken van een bepaalt artikel.'
+
document.title = "Statistieken van een specifiek artikel.";
 
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> ';
 
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> ';
let allHistoryPages;
+
var allHistoryPages;
const request = new XMLHttpRequest();
+
var request = new XMLHttpRequest();
 
// Geeft alle subpagina's van User:Rots/Statistieken/. /StatisiekenExtra doet dus niet mee
 
// 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.open('GET', 'https://wikikids.nl/api.php?action=query&list=allpages&apminsize=100000&apnamespace=2&apprefix=Rots61/Statistieken/&aplimit=500&format=json', false);
Regel 272: Regel 276:
 
}
 
}
 
allHistoryPages = allHistoryPages.query.allpages;
 
allHistoryPages = allHistoryPages.query.allpages;
let tableoutputLC = '<table class="wikitable" id="LogCounterPerPage"><thead><tr><th onclick="sortTable(\'LogCounterPerPage\',0, true)">Rank</th><th onclick="sortTable(\'LogCounterPerPage\',1)">Datum</th><th onclick="sortTable(\'LogCounterPerPage\',2, true)">Aantal bezoekers</th></thead><tbody>';
+
var tableoutputLC = `<table class="wikitable" id="LogCounterPerPage"><thead><tr><th onclick="sortTable('LogCounterPerPage',0, true)">Rank</th><th onclick="sortTable('LogCounterPerPage',1)">Datum</th><th onclick="sortTable('LogCounterPerPage',2, true)">Aantal bezoekers</th></thead><tbody>`;
 
requests = new Array(allHistoryPages.length);
 
requests = new Array(allHistoryPages.length);
 +
 +
searchBarLC = '<div><input type="text" id="lc-searchbar" value=' + parameterLC['page'] +'> <button onclick="searchContainsLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPagina()"><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: ' + reload1LCx + ';"><a href="javascript:reload1LC();"><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: ' + reload2LCx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3LCx + ';"><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"> <button onclick="downloadLogCounter(\';\');"><b>;</b></button> <button onclick="downloadLogCounter(\',\');"><b>,</b></button></button>';
 +
 
setTimeout(function () {
 
setTimeout(function () {
 
for (let i = 0; i < allHistoryPages.length; i++) {
 
for (let i = 0; i < allHistoryPages.length; i++) {
 
requests[i] = new XMLHttpRequest();
 
requests[i] = new XMLHttpRequest();
requests[i].open('GET', 'https://wikikids.nl/' + allHistoryPages[i]['title'] + '?action=raw');
+
requests[i].open("GET", "https://wikikids.nl/" + allHistoryPages[i]['title'] + '?action=raw');
requests[i].onload = function () {
+
requests[i].onload = function() {
const datainfo = JSON.parse(requests[i].responseText);
+
var datainfo = JSON.parse(requests[i].responseText);
let result;
+
var result;
for (let y = 0; y < datainfo.length; y++) {
+
for (var y = 0; y < datainfo.length; y++) {
 
if (datainfo[y]['t'].toLowerCase() === parameterLC['page'].replace(/ /g, '_').toLowerCase()) {
 
if (datainfo[y]['t'].toLowerCase() === parameterLC['page'].replace(/ /g, '_').toLowerCase()) {
 
result = datainfo[y];
 
result = datainfo[y];
result['Rank'] = y + 1;
+
result['Rank'] = y + 1;  
 
break;
 
break;
 
}
 
}
 
}
 
}
 
if (result) {
 
if (result) {
let totaalViews;
+
var totaalViews;
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 huidige versies worden alles gewoon doorgegeven.
+
  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 huidige versies worden alles gewoon doorgegeven.  
 
totaalViews = result.mPV;
 
totaalViews = result.mPV;
 
} else if (!result.mPV) {
 
} else if (!result.mPV) {
Regel 304: Regel 313:
 
requests[i].send();
 
requests[i].send();
 
}
 
}
document.getElementsByTagName('h1')[0].textContent = 'Speciaal:' + mw.config.get('wgTitle');
+
document.getElementsByTagName("h1")[0].textContent = "Speciaal:" + mw.config.get('wgTitle');
document.title = 'Pagina specifieke statistieken -  WikiKids';
+
document.title = "Pagina specifieke statistieken -  WikiKids";
let infotext = `<div><input type="text" id="lc-searchbar"> <button onclick="gotoGeschiedenisVanPagina()"><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>Specifieke statistieken voor <a href="/${parameterLC['page']}">${parameterLC['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>
+
infotext = `Specifieke statistieken voor <a href="/${parameterLC['page']}">${parameterLC['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. `;
 
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 () {
+
setTimeout( function () {
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + infotext + tableoutputLC + '</tbody></table>';
+
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + infotext + tableoutputLC + '</tbody></table>';  
sortTable('LogCounterPerPage', 1);
+
sortTable('LogCounterPerPage',1);
 
}, 4000);
 
}, 4000);
 
}, 500);
 
}, 500);
 +
 
}
 
}
  
function getPagesLogCounter () {
+
function getPagesLogCounter() {
const request = new XMLHttpRequest();
+
var request = new XMLHttpRequest();
 
request.open('GET', urlLogCounter, false);
 
request.open('GET', urlLogCounter, false);
 
request.send(null);
 
request.send(null);
Regel 323: Regel 333:
 
}
 
}
  
// hernoemen alle keys zodat het later makkelijker gaat
+
// hernoemen alle keys zodat het later makkelijker gaat  
 
if (!historyLogCounter) {
 
if (!historyLogCounter) {
for (let x = 0; x < pages.length; x++) {
+
for (var x = 0; x < pages.length; x++) {
renamekey('uA', 'updatedAt', x);
+
renamekey('uA','updatedAt', x);
 
renamekey('mPV', 'mainPageVisitors', x);
 
renamekey('mPV', 'mainPageVisitors', x);
renamekey('nV', 'normalVisitors', x);
+
renamekey('nV','normalVisitors', x);
renamekey('t', 'title', x);
+
renamekey('t','title', x);
 
}
 
}
 
}
 
}
 +
 
fullPages = pages;
 
fullPages = pages;
 
// Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
 
// Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
pages.sort(function (a, b) {
+
if (infoHistory.Doublerequest) {
return b.nV + b.mPV - a.nV - a.mPV;
+
pages.sort(function (a, b) {
});
+
return b.nV + b.nV - a.nV - a.nV;
 
+
});
// Filter percentmax, percentmin, aantalmax, aantalmin, only
+
} else {
 +
pages.sort(function (a, b) {
 +
  return b.nV + b.mPV - a.nV - a.mPV;
 +
});
 +
}
 +
//Filter percentmax, percentmin, aantalmax, aantalmin, only
 
if (parameterLC['checkrules']) {
 
if (parameterLC['checkrules']) {
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;
procent = (100 / (pages[y].nV + pages[y].mPV)) * pages[y].mPV; // 50
+
if (infoHistory.Doublerequest) {
if (procent <= parameterLC['percentmax']) { // 60 <= 70 true // 50 <= 50 true
+
console.log('Percent');
if (procent >= parameterLC['percentmin'] || parameterLC['percentmin'] === null) { // 60 >= 50 true //50 <= 0 true
+
procent = (100/pages[y].nV)*pages[y].mPV;
pages[y].filterShow = 'colored'; // kleuren
+
if (procent === Infinity) {
 +
procent = 100;
 +
}
 +
} else {
 +
procent = (100/(pages[y].nV + pages[y].mPV))*pages[y].mPV; // 50
 
}
 
}
}
+
if (procent <= parameterLC['percentmax']) { // 60 <= 70 true // 50 <= 50 true
if (pages[y].nV + pages[y].mPV > parameterLC['aantalmax']) { // 50 >= 100; 1 >= 1
+
if (procent >= parameterLC['percentmin'] || parameterLC['percentmin'] === null) { // 60 >= 50 true //50 <= 0 true
pages[y].filterShow = undefined;
+
pages[y].filterShow = 'colored'; // kleuren
} else if (pages[y].nV + pages[y].mPV < parameterLC['aantalmin']) { // 50 <= 0
+
}  
pages[y].filterShow = undefined;
+
}
}
+
if (pages[y].nV + pages[y].mPV > parameterLC['aantalmax']) { //50 >= 100; 1 >= 1
if (parameterLC['only']) {
+
pages[y].filterShow = undefined;
if (pages[y].filterShow !== 'colored') {
+
} else if (pages[y].nV + pages[y].mPV < parameterLC['aantalmin']) { // 50 <= 0
pages.splice(y, 1);
+
pages[y].filterShow = undefined;
y = y - 1;
+
}
 +
if (parameterLC['only']) {
 +
if (pages[y].filterShow !== 'colored') {
 +
pages.splice(y, 1);
 +
y = y-1;
 +
}
 
}
 
}
 
}
 
}
 
}
 
}
}
+
 
 
if (document.getElementById('reload2')) {
 
if (document.getElementById('reload2')) {
setTimeout(function () {
+
setTimeout( function () {
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload2').style.display = 'none';
 
document.getElementById('reload2').style.display = 'none';
Regel 370: Regel 395:
 
reload2LCx = 'none';
 
reload2LCx = 'none';
 
reload3LCx = '';
 
reload3LCx = '';
setTimeout(function () { document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1LCx = ''; reload2LCx = 'none'; reload3LCx = 'none'; }, 2500);
+
setTimeout(function () {document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1LCx = ''; reload2LCx = 'none'; reload3LCx = 'none';}, 2500);
 
}, 1000);
 
}, 1000);
 
} else {
 
} else {
Regel 381: Regel 406:
 
reload2LCx = 'none';
 
reload2LCx = 'none';
 
reload3LCx = '';
 
reload3LCx = '';
setTimeout(function () { document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1LCx = ''; reload2LCx = 'none'; reload3LCx = 'none' }, 2500);
+
setTimeout(function () {document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1LCx = ''; reload2LCx = 'none'; reload3LCx = 'none'}, 2500);
 
}
 
}
 
}, 2500);
 
}, 2500);
Regel 388: Regel 413:
 
}
 
}
  
function gotoGeschiedenisVanPagina () {
+
function gotoGeschiedenisVanPagina(){
parameterLC = {};
+
parameterLC = {};  
 
parameterLC['page'] = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
 
parameterLC['page'] = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
 
changeURL();
 
changeURL();
Regel 395: Regel 420:
 
}
 
}
  
function searchContainsLogCounterButton () {
+
function searchContainsLogCounterButton() {
 
searchQuery = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
 
searchQuery = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
parameterLC['exactzoeken'] = undefined;
+
parameterLC['exactzoeken'] = undefined;  
parameterLC['action'] = undefined;
+
parameterLC['action'] = undefined;  
parameterLC['page'] = undefined;
+
parameterLC['page'] = undefined;  
 
parameterLC['pagenr'] = 1;
 
parameterLC['pagenr'] = 1;
 
parameterLC['bevatzoeken'] = searchQuery;
 
parameterLC['bevatzoeken'] = searchQuery;
Regel 406: Regel 431:
 
}
 
}
  
function searchContainsLogCounter (searchQuery) {
+
function searchContainsLogCounter(searchQuery) {
 
if (!searchQuery) {
 
if (!searchQuery) {
 
searchQuery = parameterLC['bevatzoeken'];
 
searchQuery = parameterLC['bevatzoeken'];
 
}
 
}
 
+
const searchResult = [];
+
var searchResult = [];
for (let i = 0; i < allPages.length; i++) {
+
for (var i = 0; i < allPages.length; i++) {
 
if (allPages[i]['t'].toLowerCase().includes(searchQuery.toLowerCase())) {
 
if (allPages[i]['t'].toLowerCase().includes(searchQuery.toLowerCase())) {
 
searchResult.push(allPages[i]);
 
searchResult.push(allPages[i]);
Regel 419: Regel 444:
 
setTimeout(function () {
 
setTimeout(function () {
 
if (!searchResult.length) {
 
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.'
+
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.'  
 
+ '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 = terugnaarlogcounter + searchBarLC + printToScreen;
 
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + printToScreen;
 
} else {
 
} else {
 +
console.log(searchResult);
 
showProjectLogCounter(searchResult, searchQuery);
 
showProjectLogCounter(searchResult, searchQuery);
 
}
 
}
Regel 428: Regel 454:
 
}
 
}
  
function searchExactLogCounterButton () {
+
function searchExactLogCounterButton() {
 
searchQuery = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
 
searchQuery = document.getElementById('lc-searchbar').value.replace(/ /g, '_');
parameterLC['bevatzoeken'] = undefined;
+
parameterLC['bevatzoeken'] = undefined;  
parameterLC['action'] = undefined;
+
parameterLC['action'] = undefined;  
 
parameterLC['page'] = undefined;
 
parameterLC['page'] = undefined;
 
parameterLC['pagenr'] = 1;
 
parameterLC['pagenr'] = 1;
Regel 439: Regel 465:
 
}
 
}
  
function searchExactLogCounter (searchQuery) {
+
function searchExactLogCounter(searchQuery) {
 
if (!searchQuery) {
 
if (!searchQuery) {
 
searchQuery = parameterLC['exactzoeken'];
 
searchQuery = parameterLC['exactzoeken'];
 
}
 
}
const searchResult = [];
+
var searchResult = [];
for (let i = 0; i < allPages.length; i++) {
+
for (var i = 0; i < allPages.length; i++) {
 
if (allPages[i]['t'].toLowerCase() === searchQuery.toLowerCase()) {
 
if (allPages[i]['t'].toLowerCase() === searchQuery.toLowerCase()) {
 
searchResult.push(allPages[i]);
 
searchResult.push(allPages[i]);
Regel 451: Regel 477:
 
setTimeout(function () {
 
setTimeout(function () {
 
if (!searchResult.length) {
 
if (!searchResult.length) {
const 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. ';
+
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. ';
 
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + printToScreen;
 
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + printToScreen;
 
} else {
 
} else {
 +
console.log(searchResult);
 
showProjectLogCounter(searchResult, searchQuery);
 
showProjectLogCounter(searchResult, searchQuery);
 
}
 
}
Regel 459: Regel 486:
 
}
 
}
  
function getInfoPageLogCounter (urlInfoLogCounter) {
+
function getInfoPageLogCounter(urlInfoLogCounter) {
let infoHistory;
+
var infoHistorytemp;
const request = new XMLHttpRequest();
+
var request = new XMLHttpRequest();
 
request.open('GET', urlInfoLogCounter, false);
 
request.open('GET', urlInfoLogCounter, false);
 
request.send(null);
 
request.send(null);
 
if (request.status === 200) {
 
if (request.status === 200) {
infoHistory = JSON.parse(request.responseText);
+
infoHistorytemp = JSON.parse(request.responseText);
 
}
 
}
return infoHistory;
+
return infoHistorytemp;
 
}
 
}
  
function tabelLogCounter () {
+
function tabelLogCounter() {
let allHistoryPages;
+
var allHistoryPages;
const request = new XMLHttpRequest();
+
var request = new XMLHttpRequest();
 
// Geeft alle subpagina's van User:Rots61/Statistieken, /StatistiekenExtra doet dus mee
 
// Geeft alle subpagina's van User:Rots61/Statistieken, /StatistiekenExtra doet dus 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=100000&apnamespace=2&apprefix=Rots61/Statistieken&aplimit=500&format=json', false);
Regel 480: Regel 507:
 
}
 
}
 
allHistoryPages = allHistoryPages.query.allpages;
 
allHistoryPages = allHistoryPages.query.allpages;
let tableoutputLC = `<table class="wikitable" id="LogCounterHistory"><thead><tr><th onclick="sortTable('LogCounterHistory',0)">Link</th><th onclick="sortTable('LogCounterHistory',1)">Datum</th><th onclick="sortTable('LogCounterHistory',2, true)">Aantal bezoekers</th><th onclick="sortTable('LogCounterHistory',3, true)">Aantal pagina's</th><th onclick="sortTable('LogCounterHistory',4)">Extra informatie</th></tr></thead><tbody>
+
var tableoutputLC = `<table class="wikitable" id="LogCounterHistory"><thead><tr><th onclick="sortTable('LogCounterHistory',0)">Link</th><th onclick="sortTable('LogCounterHistory',1)">Datum</th><th onclick="sortTable('LogCounterHistory',2, true)">Aantal bezoekers</th><th onclick="sortTable('LogCounterHistory',3, true)">Aantal pagina's</th><th onclick="sortTable('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>`;
 
<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);
 
requests = new Array(allHistoryPages.length);
 
setTimeout(function () {
 
setTimeout(function () {
 
for (let i = 0; i < allHistoryPages.length; i++) {
 
for (let i = 0; i < allHistoryPages.length; i++) {
const url = 'https://wikikids.nl/' + allHistoryPages[i]['title'] + '/info?action=raw';
+
var url = "https://wikikids.nl/" + allHistoryPages[i]['title'] + '/info?action=raw';
 
requests[i] = new XMLHttpRequest();
 
requests[i] = new XMLHttpRequest();
requests[i].open('GET', url);
+
requests[i].open("GET", url);
requests[i].onload = function () {
+
requests[i].onload = function() {
const datainfo = JSON.parse(requests[i].responseText);
+
var datainfo = JSON.parse(requests[i].responseText);
 
tableoutputLC += `<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>`;
 
tableoutputLC += `<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>`;
const xStarttime = new Date(datainfo.Starttime);
+
var xStarttime = new Date(datainfo.Starttime);  
const xEndtime = new Date(datainfo.Endtime);
+
var xEndtime = new Date(datainfo.Endtime);  
const firstDateString = addZero(xStarttime.getDate()) + '-' + addZero((xStarttime.getMonth() + 1)) + '-' + xStarttime.getFullYear() + ' ' + addZero(xStarttime.getHours()) + ':' + addZero(xStarttime.getMinutes());
+
var firstDateString = addZero(xStarttime.getDate()) + "-" + addZero((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZero(xStarttime.getHours()) + ":" + addZero(xStarttime.getMinutes());
const lastDateString = addZero(xEndtime.getDate()) + '-' + addZero((xEndtime.getMonth() + 1)) + '-' + xEndtime.getFullYear() + ' ' + addZero(xEndtime.getHours()) + ':' + addZero(xEndtime.getMinutes());
+
var lastDateString = addZero(xEndtime.getDate()) + "-" + addZero((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZero(xEndtime.getHours()) + ":" + addZero(xEndtime.getMinutes());
 
tableoutputLC += `<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>`;
 
tableoutputLC += `<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();
 
requests[i].send();
 
}
 
}
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, 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>'
 
+ 'Deze lijst wordt automatisch bijgewerkt, zodat alle vorige statistieken worden getoont. <br>';
 
+ 'Deze lijst wordt automatisch bijgewerkt, zodat alle vorige statistieken worden getoont. <br>';
setTimeout(function () {
+
setTimeout( function () {  
 
tableoutputLC += '</tbody></table>';
 
tableoutputLC += '</tbody></table>';
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + infotext + tableoutputLC;
+
document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + infotext + tableoutputLC;  
sortTable('LogCounterHistory', 0);
+
sortTable('LogCounterHistory',0);
 
}, 500);
 
}, 500);
 
}, 500);
 
}, 500);
 
}
 
}
  
function changeURL () {
+
function changeURL(){
let urlPath = '/Speciaal:Statistieken WikiKids?';
+
var urlPath = '/Speciaal:Statistieken WikiKids?';
 
if (parameterLC['rows']) {
 
if (parameterLC['rows']) {
 
if (parameterLC['rows'] !== 25) {
 
if (parameterLC['rows'] !== 25) {
Regel 529: Regel 556:
 
if (parameterLC['pagenr']) {
 
if (parameterLC['pagenr']) {
 
if (parameterLC['pagenr'] < 1 || (parameterLC['pagenr'] > Math.ceil(allPages.length / parameterLC['rows']) || parameterLC['pagenr'] === 1)) {
 
if (parameterLC['pagenr'] < 1 || (parameterLC['pagenr'] > Math.ceil(allPages.length / parameterLC['rows']) || parameterLC['pagenr'] === 1)) {
parameterLC['pagenr'] = 1;
+
parameterLC['pagenr'] = 1;  
 
} else {
 
} else {
 
urlPath += 'pagenr=' + parameterLC['pagenr'] + '&';
 
urlPath += 'pagenr=' + parameterLC['pagenr'] + '&';
Regel 546: Regel 573:
 
if (parameterLC['only']) {
 
if (parameterLC['only']) {
 
urlPath += 'only=x&';
 
urlPath += 'only=x&';
}
+
}
 
if (parameterLC['aantalmax']) {
 
if (parameterLC['aantalmax']) {
 
if (parameterLC['aantalmax'] !== Infinity) {
 
if (parameterLC['aantalmax'] !== Infinity) {
Regel 571: Regel 598:
 
}
 
}
 
}
 
}
 
+
 
urlPath += 'v=1.0';
 
urlPath += 'v=1.0';
window.history.pushState('', '', urlPath);
+
window.history.pushState("","", urlPath);
// window.history.replaceState("","", urlPath);
+
//window.history.replaceState("","", urlPath);
 
}
 
}
  
function reload1LC () {
+
function reload1LC() {
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload1').style.display = 'none';
 
document.getElementById('reload2').style.display = '';
 
document.getElementById('reload2').style.display = '';
Regel 587: Regel 614:
 
}
 
}
  
function reloadPagesLogCounter () {
+
function reloadPagesLogCounter() {
 
/*
 
/*
parameterLC['action'] = undefined;
+
parameterLC['action'] = undefined;  
parameterLC['page'] = undefined;
+
parameterLC['page'] = undefined;  
 
*/
 
*/
 
changeURL();
 
changeURL();
Regel 596: Regel 623:
 
}
 
}
  
function terugLogCounter (dateparameter, specialeweekparameter) {
+
function terugLogCounter(dateparameter, specialeweekparameter) {
 
parameterLC = {};
 
parameterLC = {};
 
if (dateparameter || specialeweekparameter) {
 
if (dateparameter || specialeweekparameter) {
 
parameterLC['date'] = dateparameter;
 
parameterLC['date'] = dateparameter;
 
parameterLC['specialeweek'] = specialeweekparameter;
 
parameterLC['specialeweek'] = specialeweekparameter;
changeURL();
+
changeURL();  
 
startLC();
 
startLC();
 
} else {
 
} else {
changeURL();
+
changeURL();  
 
startLC(true);
 
startLC(true);
 
}
 
}
 
}
 
}
  
function sortTable (id, n, getal) {
+
function sortTable(id, n, getal) {
   let table; let rows; let switching; let i; let x; let y; let shouldSwitch; let dir; let switchcount = 0;
+
   var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
 
   table = document.getElementById(id);
 
   table = document.getElementById(id);
 
   switching = true;
 
   switching = true;
 
   // Set the sorting direction to ascending:
 
   // Set the sorting direction to ascending:
   dir = 'asc';
+
   dir = "asc";
 
   /* Make a loop that will continue until
 
   /* Make a loop that will continue until
 
   no switching has been done: */
 
   no switching has been done: */
Regel 628: Regel 655:
 
  /* Get the two elements you want to compare,
 
  /* Get the two elements you want to compare,
 
  one from current row and one from the next: */
 
  one from current row and one from the next: */
  x = rows[i].getElementsByTagName('TD')[n];
+
  x = rows[i].getElementsByTagName("TD")[n];
  y = rows[i + 1].getElementsByTagName('TD')[n];
+
  y = rows[i + 1].getElementsByTagName("TD")[n];
 
  /* Check if the two rows should switch place,
 
  /* Check if the two rows should switch place,
 
  based on the direction, asc or desc: */
 
  based on the direction, asc or desc: */
 
  if (getal) {
 
  if (getal) {
  if (dir === 'asc') {
+
  if (dir === "asc") {
 
if (parseInt(x.innerHTML) > parseInt(y.innerHTML)) {
 
if (parseInt(x.innerHTML) > parseInt(y.innerHTML)) {
 
  // If so, mark as a switch and break the loop:
 
  // If so, mark as a switch and break the loop:
Regel 639: Regel 666:
 
  break;
 
  break;
 
}
 
}
  } else if (dir == 'desc') {
+
  } else if (dir == "desc") {
 
if (parseInt(x.innerHTML) < parseInt(y.innerHTML)) {
 
if (parseInt(x.innerHTML) < parseInt(y.innerHTML)) {
 
  // If so, mark as a switch and break the loop:
 
  // If so, mark as a switch and break the loop:
Regel 647: Regel 674:
 
  }
 
  }
 
  } else {
 
  } else {
  if (dir == 'asc') {
+
  if (dir == "asc") {
 
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
 
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
 
  // If so, mark as a switch and break the loop:
 
  // If so, mark as a switch and break the loop:
Regel 653: Regel 680:
 
  break;
 
  break;
 
}
 
}
  } else if (dir == 'desc') {
+
  } else if (dir == "desc") {
 
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
 
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
 
  // If so, mark as a switch and break the loop:
 
  // If so, mark as a switch and break the loop:
Regel 672: Regel 699:
 
  /* If no switching has been done AND the direction is "asc",
 
  /* If no switching has been done AND the direction is "asc",
 
  set the direction to "desc" and run the while loop again. */
 
  set the direction to "desc" and run the while loop again. */
  if (switchcount === 0 && dir === 'asc') {
+
  if (switchcount === 0 && dir === "asc") {
dir = 'desc';
+
dir = "desc";
 
switching = true;
 
switching = true;
 
  }
 
  }
Regel 681: Regel 708:
  
 
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")))) {
 
var parameterLC = {};
 
var parameterLC = {};
var historyLogCounter, infoHistory, urlLogCounter, allPages, fullPages, terugnaarlogcounter;
+
var historyLogCounter, urlLogCounter, allPages, fullPages, terugnaarlogcounter;
 +
// 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 infoHistory = {"Types":"Hele pagina","Doublerequest": true, Live:true};
 
var reload1LCx = '';
 
var reload1LCx = '';
 
var reload2LCx = 'none';
 
var reload2LCx = 'none';
 
var reload3LCx = 'none';
 
var reload3LCx = 'none';
mw.loader.using('mediawiki.util', function () {
+
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.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.loader.using('mediawiki.util', function() {
mw.util.addPortletLink('p-namespaces', 'https://wikikids.nl/WikiKids:Statistieken', 'Info ', '#linkNaarWKStatistieken', 'Informatie over de statistieken');
+
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 () {
 
}); $.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>, versie: ' + version + '</li>';
+
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>, versie: ' + version + '</li>';
 
});
 
});
 
startLC(true, 'first');
 
startLC(true, 'first');
 +
 
}
 
}
  
function startLC (reloadlc, firsttime) {
+
function startLC(reloadlc, firsttime) {
parameterLC['rows'] = mw.util.getParamValue('rows') ? mw.util.getParamValue('rows') : 25;
+
parameterLC['rows'] = mw.util.getParamValue('rows') ? mw.util.getParamValue('rows') : 25;
 
parameterLC['action'] = mw.util.getParamValue('action');
 
parameterLC['action'] = mw.util.getParamValue('action');
 
parameterLC['date'] = mw.util.getParamValue('date');
 
parameterLC['date'] = mw.util.getParamValue('date');
Regel 705: Regel 739:
 
parameterLC['pagenr'] = mw.util.getParamValue('pagenr') ? mw.util.getParamValue('pagenr') : 1;
 
parameterLC['pagenr'] = mw.util.getParamValue('pagenr') ? mw.util.getParamValue('pagenr') : 1;
 
parameterLC['bevatzoeken'] = mw.util.getParamValue('bevatzoeken');
 
parameterLC['bevatzoeken'] = mw.util.getParamValue('bevatzoeken');
parameterLC['exactzoeken'] = mw.util.getParamValue('exactzoeken');
+
parameterLC['exactzoeken'] = mw.util.getParamValue('exactzoeken');  
 
parameterLC['specialeweek'] = mw.util.getParamValue('specialeweek');
 
parameterLC['specialeweek'] = mw.util.getParamValue('specialeweek');
 
parameterLC['filterkleur'] = mw.util.getParamValue('filterkleur') ? mw.util.getParamValue('filterkleur') : 'lightgreen';
 
parameterLC['filterkleur'] = mw.util.getParamValue('filterkleur') ? mw.util.getParamValue('filterkleur') : 'lightgreen';
 
+
 
parameterLC['percentmin'] = mw.util.getParamValue('percentmin') ? mw.util.getParamValue('percentmin') : -1;
 
parameterLC['percentmin'] = mw.util.getParamValue('percentmin') ? mw.util.getParamValue('percentmin') : -1;
 
parameterLC['percentmax'] = mw.util.getParamValue('percentmax') ? mw.util.getParamValue('percentmax') : 100;
 
parameterLC['percentmax'] = mw.util.getParamValue('percentmax') ? mw.util.getParamValue('percentmax') : 100;
parameterLC['only'] = mw.util.getParamValue('only');
+
parameterLC['only'] = mw.util.getParamValue('only');  
 
parameterLC['aantalmax'] = mw.util.getParamValue('aantalmax') ? mw.util.getParamValue('aantalmax') : Infinity;
 
parameterLC['aantalmax'] = mw.util.getParamValue('aantalmax') ? mw.util.getParamValue('aantalmax') : Infinity;
 
parameterLC['aantalmin'] = mw.util.getParamValue('aantalmin') ? mw.util.getParamValue('aantalmin') : 0;
 
parameterLC['aantalmin'] = mw.util.getParamValue('aantalmin') ? mw.util.getParamValue('aantalmin') : 0;
 
parameterLC['checkrules'] = mw.util.getParamValue('aantalmin') + mw.util.getParamValue('aantalmax') + mw.util.getParamValue('only') + mw.util.getParamValue('percentmax') + mw.util.getParamValue('percentmin');
 
parameterLC['checkrules'] = mw.util.getParamValue('aantalmin') + mw.util.getParamValue('aantalmax') + mw.util.getParamValue('only') + mw.util.getParamValue('percentmax') + mw.util.getParamValue('percentmin');
// 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.  
 
terugnaarlogcounter = '<div id="contentSub"><span class="subpages">&lt; <a href="javascript:terugLogCounter();" title="Speciaal:Statistieken WikiKids">Speciaal:Statistieken WikiKids</a>';
 
terugnaarlogcounter = '<div id="contentSub"><span class="subpages">&lt; <a href="javascript:terugLogCounter();" title="Speciaal:Statistieken WikiKids">Speciaal:Statistieken WikiKids</a>';
 
if (parameterLC['date']) {
 
if (parameterLC['date']) {
Regel 722: Regel 757:
 
terugnaarlogcounter += ', true';
 
terugnaarlogcounter += ', true';
 
}
 
}
terugnaarlogcounter += ');" title="Speciaal:Statistieken/' + parameterLC['date'] + '">' + parameterLC['date'] + '</a>';
+
terugnaarlogcounter += ');" title="Speciaal:Statistieken/' + parameterLC['date'] + '">' + parameterLC['date'] + '</a>';  
 
}
 
}
 
terugnaarlogcounter += '</span></div>';
 
terugnaarlogcounter += '</span></div>';
Regel 744: Regel 779:
 
if (parameterLC['action'] === 'tabel') {
 
if (parameterLC['action'] === 'tabel') {
 
tabelLogCounter();
 
tabelLogCounter();
} else if (parameterLC['page']) { // Views voor een pagina, de hele tijd;
+
} else if (parameterLC['page']) { // Views voor een pagina, de hele tijd;  
 
statsPerPageLogCounter();
 
statsPerPageLogCounter();
 
} else {
 
} else {
Regel 768: Regel 803:
  
 
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 100) {
 
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 100) {
mw.loader.using('mediawiki.util', function () {
+
mw.loader.using('mediawiki.util', function() {
mw.util.addPortletLink('p-cactions',
+
mw.util.addPortletLink('p-cactions',  
'https://wikikids.nl/Speciaal:Statistieken_WikiKids?page=' + encodeURIComponent(mw.config.get('wgPageName')),
+
'https://wikikids.nl/Speciaal:Statistieken_WikiKids?page=' + encodeURIComponent(mw.config.get('wgPageName')),  
'Statistieken* ', '#GeschiedenisStats', 'Statistieken van ' + mw.config.get('wgPageName'));
+
'Statistieken* ', '#GeschiedenisStats', "Statistieken van " + mw.config.get('wgPageName'));
 
});
 
});
 
}
 
}
  
function renamekey (new_key, old_key, x) {
+
function renamekey(new_key, old_key, x){
 
Object.defineProperty(pages[x], new_key,
 
Object.defineProperty(pages[x], new_key,
 
Object.getOwnPropertyDescriptor(pages[x], old_key));
 
Object.getOwnPropertyDescriptor(pages[x], old_key));
 
delete pages[x][old_key];
 
delete pages[x][old_key];
 
}
 
}

Huidige versie van 8 jun 2023 om 17:49

/* jshint sub:true maxerr:100000 */
// [[User:MakiBoy/Gadget-LogCounter.js]] gemaakt door [[User:MakiBoy]] en [[User:Rots61]], onderhouden door [[User:Rots61]]

var version = '3.2';
var searchBarLC;

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

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

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

function showProjectLogCounter (pages, zoekbalk) {
	// Dit zorgt ervoor dat de kleur wordt weergegeven of de kleurcode. 
	var haakjesfilterkleur = /[G-Za-z]/.test(parameterLC['filterkleur']) ? '' : '#';
	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";
	
	searchBarLC = '<div><input type="text" id="lc-searchbar" value=' + zoekbalk +'> <button onclick="searchContainsLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPagina()"><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: ' + reload1LCx + ';"><a href="javascript:reload1LC();"><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: ' + reload2LCx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3LCx + ';"><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"> <button onclick="downloadLogCounter(\';\');"><b>;</b></button> <button onclick="downloadLogCounter(\',\');"><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> </div>';
	// Controleert of het een speciale week is, als dat het geval is, dan wordt de informatie uitgebreid.
	if (parameterLC['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', 'Laatste bezoek', 'Views', infoHistory.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(parameterLC['pagenr']);
	var rowsPerPage = parseInt(parameterLC['rows']);
	var totalPages = Math.ceil(pages.length / rowsPerPage);
	
	// 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) {
			var dateString; 
			var row = document.createElement('tr');
			// Definieert variabelen die later nodig zijn
			var totalVisitors, mainPageVisited, pageTitle, pageLink, date, tempDate, filterShow, percentMainPage, percentStyle;
			if (infoHistory.Doublerequest) {
				totalVisitors = page.nV ? page.nV :  page.mPV;
				console.log(totalVisitors);
			} 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 (parameterLC['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')) {
					tempDate = new Date((parseInt(pageTitle.replace(/Tijd.?:/g,"")) + 28026240) * 60 * 1000);
					pageTitle = pageTitle.replace(/Tijd/g,"T").replace(/:.*/g, ":");
					dateString = addZero(tempDate.getDate()) + ' april ' + addZero(tempDate.getHours()) + ":" + addZero(tempDate.getMinutes());
				}
			}
			date = new Date(page.uA);
			filterShow = page.filterShow ? page.filterShow : "";
			percentMainPage = Math.round((100/totalVisitors)*mainPageVisited*100)/100;
			percentStyle = '>';
			if (filterShow === 'colored') { 
		   		percentStyle = ' style="background: ' + haakjesfilterkleur + parameterLC['filterkleur'] + '">';
			}
			if (parameterLC['specialeweek'] && (pageLink.includes('Speciaal:Zoeken?') || pageLink.includes('Tijd'))) {
				if (pageLink.includes('Speciaal:Zoeken?')) {
					dateString = "-";
				}
			} else if (!isNaN(date)) {
				dateString = addZero(date.getDate()) + "-" + addZero((date.getMonth() + 1)) + "-" + date.getFullYear() + " " + addZero(date.getHours()) + ":" + addZero(date.getMinutes());
			} else {
				dateString = "Niet beschikbaar";
			}
			row.innerHTML = `<td><a href="/${pageLink}">${pageTitle}</a></td>
				<td>${dateString}</td>
				<td>${parseNumber(totalVisitors)}</td><td>${parseNumber(mainPageVisited)}</td>
				<td ${percentStyle + percentMainPage}</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) {
			parameterLC['pagenr'] = currentPage - 1; 
			showPage(currentPage - 1);
			changeURL();
			// 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) {
			parameterLC['pagenr'] = currentPage + 1; 
			showPage(currentPage + 1);
			changeURL();
			// 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 {
			parameterLC['pagenr'] = parseInt(document.getElementById('logcounternumberpage').value); 
			showPage(parseInt(document.getElementById('logcounternumberpage').value));
			changeURL();
			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;
		tableHeadRow.appendChild(tableHeadCell);
	});
	tableHead.appendChild(tableHeadRow);
	table.appendChild(tableHead);
	table.appendChild(tableBody);
	
	var totalVisitors;
	if (infoHistory.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);
	}
	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: ${parseNumber(totalVisitors)}`;
	totalElement.appendChild(totalVisitorsElement);

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

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

function downloadLogCounter(tss) {
	var a = 'Paginatitel' + tss + 'Views' + tss + 'Speciale statistiek \n';
	for (var x = 0; x < allPages.length; x++){
		if (!allPages[x].mPV) {
			a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].nV) + tss + '0' + tss + '\n';
		} else if (!allPages[x].nV) {
			a += allPages[x].t.replace(/,/g, '.') + tss + (allPages[x].mPV) + tss + allPages[x].mPV + tss + '\n';   
		} else {
			a += allPages[x].t.replace(/,/g, '.')  + tss + (allPages[x].mPV + allPages[x].nV) + tss + allPages[x].mPV + tss + '\n';
		}
	}
	if (parameterLC['date']) {
		downloadfile(a, 'Statistieken WikiKids ' + parameterLC['date'] +'.csv', 'csv');
	} else {
		downloadfile(a, 'Statistieken WikiKids live.csv', 'csv');
	}
}

function downloadfile(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); 
	}
}

function statsPerPageLogCounter() {
	document.title = "Statistieken van een specifiek artikel.";
	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;
	var tableoutputLC = `<table class="wikitable" id="LogCounterPerPage"><thead><tr><th onclick="sortTable('LogCounterPerPage',0, true)">Rank</th><th onclick="sortTable('LogCounterPerPage',1)">Datum</th><th onclick="sortTable('LogCounterPerPage',2, true)">Aantal bezoekers</th></thead><tbody>`;
	requests = new Array(allHistoryPages.length);
	
	searchBarLC = '<div><input type="text" id="lc-searchbar" value=' + parameterLC['page'] +'> <button onclick="searchContainsLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/9/9a/OOjs_UI_indicator_search-ltr.svg" title="Bevat (zoeken)" height="25"></button> <button onclick="searchExactLogCounterButton();"><img src="https://upload.wikimedia.org/wikipedia/commons/8/86/OOjs_UI_icon_articleSearch-ltr.svg" title="Exact (zoeken)" height="25"></button> <button onclick="gotoGeschiedenisVanPagina()"><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: ' + reload1LCx + ';"><a href="javascript:reload1LC();"><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: ' + reload2LCx + ';"><img src="https://upload.wikimedia.org/wikipedia/commons/9/91/LoadingX.gif" width="50"></div><div id="reload3" style="display: ' + reload3LCx + ';"><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"> <button onclick="downloadLogCounter(\';\');"><b>;</b></button> <button onclick="downloadLogCounter(\',\');"><b>,</b></button></button>'; 

	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);
				var result;
				for (var y = 0; y < datainfo.length; y++) {
					if (datainfo[y]['t'].toLowerCase() === parameterLC['page'].replace(/ /g, '_').toLowerCase()) {
						result = datainfo[y];
						result['Rank'] = y + 1; 
						break;
					}
				}
				if (result) {
					var totaalViews;
				   	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 huidige versies worden alles gewoon doorgegeven. 
						totaalViews = result.mPV;
					} else if (!result.mPV) {
						totaalViews = result.nV;
					} else {
						totaalViews = result.nV + result.mPV;
					}
					tableoutputLC += `<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 {
					tableoutputLC += `<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="/${parameterLC['page']}">${parameterLC['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 = terugnaarlogcounter + searchBarLC + infotext + tableoutputLC + '</tbody></table>'; 
			sortTable('LogCounterPerPage',1);
		}, 4000);
	}, 500);

}

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

	// hernoemen alle keys zodat het later makkelijker gaat 
	if (!historyLogCounter) {
		for (var x = 0; x < pages.length; x++) {
			renamekey('uA','updatedAt', x);
			renamekey('mPV', 'mainPageVisitors', x);
			renamekey('nV','normalVisitors', x);
			renamekey('t','title', x);
		}
	}

	fullPages = pages;
	// Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
	if (infoHistory.Doublerequest) {
		pages.sort(function (a, b) {
			return b.nV + b.nV - a.nV - a.nV;
		});
	} else {
		pages.sort(function (a, b) {
	   		return b.nV + b.mPV - a.nV - a.mPV;
		});
	}
	//Filter percentmax, percentmin, aantalmax, aantalmin, only
	if (parameterLC['checkrules']) {
		for (var 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 (infoHistory.Doublerequest) { 
				console.log('Percent');
				procent = (100/pages[y].nV)*pages[y].mPV;
				if (procent === Infinity) {
					procent = 100;
				}
			} else {
				procent = (100/(pages[y].nV + pages[y].mPV))*pages[y].mPV; // 50
			}
			if (procent <= parameterLC['percentmax']) { // 60 <= 70 true // 50 <= 50 true
				if (procent >= parameterLC['percentmin'] || parameterLC['percentmin'] === null) { // 60 >= 50 true //50 <= 0 true
					pages[y].filterShow = 'colored'; // kleuren
				} 
			}
			if (pages[y].nV + pages[y].mPV > parameterLC['aantalmax']) { //50 >= 100; 1 >= 1
				pages[y].filterShow = undefined;
			} else if (pages[y].nV + pages[y].mPV < parameterLC['aantalmin']) { // 50 <= 0
				pages[y].filterShow = undefined;
			}
			if (parameterLC['only']) {
				if (pages[y].filterShow !== 'colored') {
					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 = '';
		reload1LCx = 'none';
		reload2LCx = 'none';
		reload3LCx = '';
		setTimeout(function () {document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1LCx = ''; reload2LCx = 'none';	reload3LCx = '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 = '';
				reload1LCx = 'none';
				reload2LCx = 'none';
				reload3LCx = '';
				setTimeout(function () {document.getElementById('reload3').style.display = 'none'; document.getElementById('reload1').style.display = ''; reload1LCx = ''; reload2LCx = 'none';	reload3LCx = 'none'}, 2500);
			}
		}, 2500);
	}
	return pages;
}

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

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

function searchContainsLogCounter(searchQuery) {
	if (!searchQuery) {
		searchQuery = parameterLC['bevatzoeken'];
	}
	
	var searchResult = [];
	for (var i = 0; i < allPages.length; i++) {
		if (allPages[i]['t'].toLowerCase().includes(searchQuery.toLowerCase())) {
			searchResult.push(allPages[i]);
		}
	}
	setTimeout(function () {
		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.' 
			+ 'Kijk voor meer <a href="https://wikikids.nl/WikiKids:Statistieken">informatie op deze pagina</a>.';
			document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + printToScreen;
		} else {
			console.log(searchResult);
			showProjectLogCounter(searchResult, searchQuery);
		}
	}, 750);
}

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

function searchExactLogCounter(searchQuery) {
	if (!searchQuery) {
		searchQuery = parameterLC['exactzoeken'];
	}
	var searchResult = [];
	for (var i = 0; i < allPages.length; i++) {
		if (allPages[i]['t'].toLowerCase() === searchQuery.toLowerCase()) {
			searchResult.push(allPages[i]);
		}
	}
	setTimeout(function () {
		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. ';
			document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + searchBarLC + printToScreen;
		} else {
			console.log(searchResult);
			showProjectLogCounter(searchResult, searchQuery);
		}
	}, 750);
}

function getInfoPageLogCounter(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 tabelLogCounter() {
	var allHistoryPages;
	var request = new XMLHttpRequest();
	// Geeft alle subpagina's van User:Rots61/Statistieken, /StatistiekenExtra doet dus 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;
	var tableoutputLC = `<table class="wikitable" id="LogCounterHistory"><thead><tr><th onclick="sortTable('LogCounterHistory',0)">Link</th><th onclick="sortTable('LogCounterHistory',1)">Datum</th><th onclick="sortTable('LogCounterHistory',2, true)">Aantal bezoekers</th><th onclick="sortTable('LogCounterHistory',3, true)">Aantal pagina's</th><th onclick="sortTable('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);
				tableoutputLC += `<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 = addZero(xStarttime.getDate()) + "-" + addZero((xStarttime.getMonth() + 1)) + "-" + xStarttime.getFullYear() + " " + addZero(xStarttime.getHours()) + ":" + addZero(xStarttime.getMinutes());
				var lastDateString = addZero(xEndtime.getDate()) + "-" + addZero((xEndtime.getMonth() + 1)) + "-" + xEndtime.getFullYear() + " " + addZero(xEndtime.getHours()) + ":" + addZero(xEndtime.getMinutes());
				tableoutputLC += `<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, 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>'
		+ 'Deze lijst wordt automatisch bijgewerkt, zodat alle vorige statistieken worden getoont. <br>';
		setTimeout( function () { 
			tableoutputLC += '</tbody></table>';
			document.getElementById('bodyContent').innerHTML = terugnaarlogcounter + infotext + tableoutputLC; 
			sortTable('LogCounterHistory',0);
		}, 500);
	}, 500);
}

function changeURL(){
	var urlPath = '/Speciaal:Statistieken WikiKids?';
	if (parameterLC['rows']) {
		if (parameterLC['rows'] !== 25) {
			urlPath += 'rows=' + parameterLC['rows'] + '&';
		}
	}
	if (parameterLC['action']) {
		urlPath += 'action=' + parameterLC['action'] + '&';
	}
	if (parameterLC['date']) {
		urlPath += 'date=' + parameterLC['date'] + '&';
	}
	if (parameterLC['page']) {
		urlPath += 'page=' + parameterLC['page'] + '&';
	}
	if (parameterLC['pagenr']) {
		if (parameterLC['pagenr'] < 1 || (parameterLC['pagenr'] > Math.ceil(allPages.length / parameterLC['rows']) || parameterLC['pagenr'] === 1)) {
			parameterLC['pagenr'] = 1; 
		} else {
			urlPath += 'pagenr=' + parameterLC['pagenr'] + '&';
		}
	}
	if (parameterLC['percentmin']) {
		if (parameterLC['percentmin'] !== -1) {
			urlPath += 'percentmin=' + parameterLC['percentmin'] + '&';
		}
	}
	if (parameterLC['percentmax']) {
		if (parameterLC['percentmax'] !== 100) {
			urlPath += 'percentmax=' + parameterLC['percentmax'] + '&';
		}
	}
	if (parameterLC['only']) {
		urlPath += 'only=x&';
	}	
	if (parameterLC['aantalmax']) {
		if (parameterLC['aantalmax'] !== Infinity) {
			urlPath += 'aantalmax=' + parameterLC['aantalmax'] + '&';
		}
	}
	if (parameterLC['aantalmin']) {
		if (parameterLC['aantalmin'] !== 0) {
			urlPath += 'aantalmin=' + parameterLC['aantalmin'] + '&';
		}
	}
	if (parameterLC['bevatzoeken']) {
		urlPath += 'bevatzoeken=' + parameterLC['bevatzoeken'] + '&';
	}
	if (parameterLC['exactzoeken']) {
		urlPath += 'exactzoeken=' + parameterLC['exactzoeken'] + '&';
	}
	if (parameterLC['specialeweek']) {
		urlPath += 'specialeweek=' + parameterLC['specialeweek'] + '&';
	}
	if (parameterLC['filterkleur']) {
		if (parameterLC['filterkleur'] !== 'lightgreen') {
			urlPath += 'filterkleur=' + parameterLC['filterkleur'] + '&';
		}
	}
	
	urlPath += 'v=1.0';
	window.history.pushState("","", urlPath);
	//window.history.replaceState("","", urlPath);
}

function reload1LC() {
	document.getElementById('reload1').style.display = 'none';
	document.getElementById('reload2').style.display = '';
	document.getElementById('reload3').style.display = 'none';
	reload1LCx = 'none';
	reload2LCx = '';
	reload3LCx = 'none';
	reloadPagesLogCounter();
}

function reloadPagesLogCounter() {
	/*
	parameterLC['action'] = undefined; 
	parameterLC['page'] = undefined; 
	*/
	changeURL();
	startLC(true);
}

function terugLogCounter(dateparameter, specialeweekparameter) {
	parameterLC = {};
	if (dateparameter || specialeweekparameter) {
		parameterLC['date'] = dateparameter;
		parameterLC['specialeweek'] = specialeweekparameter;
		changeURL(); 
		startLC();
	} else {
		changeURL(); 
		startLC(true);
	}
}

function sortTable(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;
	  }
	}
  }
}

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")))) {
	var parameterLC = {};
	var historyLogCounter, urlLogCounter, allPages, fullPages, terugnaarlogcounter;
	// 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 infoHistory = {"Types":"Hele pagina","Doublerequest": true, Live:true};
	var reload1LCx = '';
	var reload2LCx = 'none';
	var reload3LCx = 'none';
	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>, versie: ' + version + '</li>';
	});
	startLC(true, 'first');
	
}

function startLC(reloadlc, firsttime) {	
	parameterLC['rows'] = mw.util.getParamValue('rows') ?  mw.util.getParamValue('rows') : 25;
	parameterLC['action'] = mw.util.getParamValue('action');
	parameterLC['date'] = mw.util.getParamValue('date');
	parameterLC['page'] = mw.util.getParamValue('page');
	parameterLC['pagenr'] = mw.util.getParamValue('pagenr') ? mw.util.getParamValue('pagenr') : 1;
	parameterLC['bevatzoeken'] = mw.util.getParamValue('bevatzoeken');
	parameterLC['exactzoeken'] = mw.util.getParamValue('exactzoeken'); 
	parameterLC['specialeweek'] = mw.util.getParamValue('specialeweek');
	parameterLC['filterkleur'] = mw.util.getParamValue('filterkleur') ? mw.util.getParamValue('filterkleur') : 'lightgreen';
	
	parameterLC['percentmin'] = mw.util.getParamValue('percentmin') ? mw.util.getParamValue('percentmin') : -1;
	parameterLC['percentmax'] = mw.util.getParamValue('percentmax') ? mw.util.getParamValue('percentmax') : 100;
	parameterLC['only'] = mw.util.getParamValue('only'); 
	parameterLC['aantalmax'] = mw.util.getParamValue('aantalmax') ? mw.util.getParamValue('aantalmax') : Infinity;
	parameterLC['aantalmin'] = mw.util.getParamValue('aantalmin') ? mw.util.getParamValue('aantalmin') : 0;
	parameterLC['checkrules'] = mw.util.getParamValue('aantalmin') + mw.util.getParamValue('aantalmax') + mw.util.getParamValue('only') + mw.util.getParamValue('percentmax') + mw.util.getParamValue('percentmin');
	
	// zorgt ervoor dat er bovenin een link terug verwijst naar de basisinstellingen van de logcounter. 
	terugnaarlogcounter = '<div id="contentSub"><span class="subpages">&lt; <a href="javascript:terugLogCounter();" title="Speciaal:Statistieken WikiKids">Speciaal:Statistieken WikiKids</a>';
	if (parameterLC['date']) {
		terugnaarlogcounter += ' | <a href="javascript:terugLogCounter(' + parameterLC['date'];
		if (parameterLC['specialeweek']) {
			terugnaarlogcounter += ', true';
		}
		terugnaarlogcounter +=  ');" title="Speciaal:Statistieken/' + parameterLC['date'] + '">' + parameterLC['date'] + '</a>'; 
	}
	terugnaarlogcounter += '</span></div>';
	if (parameterLC['date']) {
		if (parameterLC['specialeweek']) {
			urlLogCounter = 'https://wikikids.nl/User:Rots61/StatistiekenExtra/' + parameterLC['date'] + '?action=raw';
			infoHistory = getInfoPageLogCounter('https://wikikids.nl/User:Rots61/StatistiekenExtra/' + parameterLC['date'] + '/info?action=raw');
		} else {
			urlLogCounter = 'https://wikikids.nl/User:Rots61/Statistieken/' + parameterLC['date'] + '?action=raw';
			infoHistory = getInfoPageLogCounter('https://wikikids.nl/User:Rots61/Statistieken/' + parameterLC['date'] + '/info?action=raw');
		}
		historyLogCounter = true;
	} else {
		urlLogCounter = 'https://wikikids.martvanweeghel.nl/pages';
		historyLogCounter = false;
	}
	if (firsttime) {
		allPages = getPagesLogCounter();
		changeURL();
	}
	if (parameterLC['action'] === 'tabel') {
		tabelLogCounter();
	} else if (parameterLC['page']) { // Views voor een pagina, de hele tijd; 
		statsPerPageLogCounter();
	} else {
		if (firsttime) {
		} else if (reloadlc) {
			allPages = getPagesLogCounter();
		} else {
			allPages = fullPages;
		}
		if (parameterLC['bevatzoeken']) {
			searchContainsLogCounter(parameterLC['bevatzoeken']);
		} else if (parameterLC['exactzoeken']) {
			searchExactLogCounter(parameterLC['exactzoeken']);
		} else {
			showProjectLogCounter(allPages, '');
		}
	}
}

if (!mw.storage.get('disableLoggingLC')) {
	mw.storage.set('disableLoggingLC', true, 86400);
}

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'));
	});
}

function renamekey(new_key, old_key, x){
	Object.defineProperty(pages[x], new_key,
		Object.getOwnPropertyDescriptor(pages[x], old_key));
	delete pages[x][old_key];
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:MakiBoy/Gadget-LogCounter.js&oldid=792754"