Gebruiker:Rots61/Gadget-LogTheCounter.js: verschil tussen versies
		
		
		
		
		
		Naar navigatie springen
		Naar zoeken springen
		
				
		
		
	
| (92 tussenliggende versies door dezelfde gebruiker niet weergegeven) | |||
| Regel 1: | Regel 1: | ||
| /* jshint sub:true maxerr:100000 */ | /* jshint sub:true maxerr:100000 */ | ||
| − | // Gadget gemaakt door [[User:Rots61]] | + | // [[User:Rots61/Gadget-LogTheCounter.js]] gemaakt door [[User:Rots61]] | 
| − | / | + | |
| + | /* | ||
| − | |||
| − | |||
| var api = new mw.Api(); | var api = new mw.Api(); | ||
| − | + | api.saveOption('userjs-ltc', 'x').then( x =>console.log(x)); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | function  | + | */ | 
| − | + | function addZero(number) { | |
| − | + | 	return number < 10 ? "0" + number : number; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| } | } | ||
| − | function  | + | function saveitlogthecounter() { | 
| − | + | 	if (Array.isArray(allPages)) { | |
| − | + |         allPages = JSON.stringify(allPages); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|      } |      } | ||
| − | + |      date = new Date(); | |
| − | + |      date = date.getFullYear() + "" + addZero((date.getMonth() + 1)) + "" + addZero(date.getDate()); | |
| − | + |      api.get({ | |
| − | + |          action: 'query', | |
| − | + |         prop: 'info', | |
| − | + |         intoken: 'edit', | |
| − | + |         titles: 'kaslv', //Pagina moet niet bestaan.   | |
| − | + |      }).done( | |
| − | + |          function (data) { | |
| − | + |             edit_token = data.query.pages['-1'].edittoken; | |
| − | + |         }).done(function (data) { | |
| − | + |             api.post({ | |
| − | + |                 'action': 'edit', | |
| − | + |                 'title': "Wikikids:Statistieken/Logs/" + date, | |
| − | + |                 'text': allPages, | |
| − | + |                 'summary': "Pagina opgeslagen met LogTheCounter.", | |
| − | + |                  'bot': true, | |
| − | + |                  'token': edit_token, | |
| − | + |              }).done( | |
| − | + |                  function (data) { | |
| − | + |                      if (data.edit.result == "Success") { | |
| − | + |                          mw.notify("Hele pagina opgeslagen!", { autoHide: false }); | |
| − | + |                          deleteDataOnServer(); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | } | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | function  | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − |              }  | ||
| − | |||
| − |                      if ( | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|                      } else { |                      } else { | ||
| − | + |                          mw.notify("Opslaan mislukt, stuur Rots61 aub direct een berichtje.", { autoHide: false }); | |
| − |                          mw.notify(" | ||
|                      } |                      } | ||
| − | + |                     console.log(data.edit); | |
| + |                     document.getElementsByTagName("h1")[0].textContent = "Opslaan gelukt!"; | ||
|                  }); |                  }); | ||
| − | + |          });       | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|      api.get({ |      api.get({ | ||
|          action: 'query', |          action: 'query', | ||
| Regel 453: | Regel 57: | ||
|              api.post({ |              api.post({ | ||
|                  'action': 'edit', |                  'action': 'edit', | ||
| − |                  'title': " | + |                  'title': "Wikikids:Statistieken/Logs/" + date + "/info", | 
| − |                  'text':  | + |                  'text': JSON.stringify(informatieLogTheCounter), | 
| − |                  'summary': "Pagina | + |                  'summary': "Pagina opgeslagen met LogTheCounter.", | 
| − | |||
|                  'bot': true, |                  'bot': true, | ||
|                  'token': edit_token, |                  'token': edit_token, | ||
| Regel 462: | Regel 65: | ||
|                  function (data) { |                  function (data) { | ||
|                      if (data.edit.result == "Success") { |                      if (data.edit.result == "Success") { | ||
| − |                          mw.notify(" | + |                          mw.notify("Pagina opgeslagen!", { autoHide: false }); | 
|                      } else { |                      } else { | ||
| − |                          mw.notify(" | + |                          mw.notify("Opslaan mislukt 2, stuur Rots61 aub direct een berichtje.", { autoHide: false }); | 
|                      } |                      } | ||
|                      console.log(data.edit); |                      console.log(data.edit); | ||
| − | |||
|                  }); |                  }); | ||
|          }); |          }); | ||
| } | } | ||
| − | function  | + | function deleteDataOnServer() { | 
| − | + |      var settings2 = { | |
| − | + | 	  "url": "https://wikikids.dekenos.nl/pages/delete", | |
| − | + | 	  "method": "POST", | |
| − | + | 	  "timeout": 0, | |
| − | + | 	  "headers": { | |
| − | + | 	    "Host": "wikikids.dekenos.nl", | |
| − | + | 	    "Content-Type": "application/json" | |
| − | + | 	  }, | |
| − | + | 	  "data": JSON.stringify({ | |
| − | + | 	    "message": 'oke' | |
| − | + | 	  }), | |
| − | + | 	}; | |
| − | + | 	$.ajax(settings2).done(function (response) { | |
| − | + | 		mw.notify("Reseten statistieken2 gelukt", { autoHide: false }); | |
| − | + | 		window.onbeforeunload = null; | |
| − | + | 		window.location.href = '/'; | |
| − | + | 	}).catch(function (error) { | |
| − | + | 		if (error.responseText || JSON.parse(error.responseText).succes) { | |
| − | + | 			mw.notify("Reseten statistieken2 gelukt", { autoHide: false }); | |
| − | + | 			window.onbeforeunload = null; | |
| − | + | 			window.location.href = '/'; | |
| − | + | 		} else { | |
| − | + | 			mw.notify('Resetten mislukt, stuur Rots61 aub direct een berichtje.', {autoHide: false}); | |
| − | + | 		} | |
| − | + | 	}); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| } | } | ||
| − | + | function getPagesLogTheCounter() { | |
| − | function  | + |     var pages = []; | 
| − |      if ( | + |     var request = new XMLHttpRequest(); | 
| − | + |     request.open('GET', 'https://wikikids.dekenos.nl/pages', false); | |
| − | + |     request.send(null); | |
| + |      if (request.status === 200) { | ||
| + |          pages = JSON.parse(request.responseText); | ||
|      } |      } | ||
| − | + |      console.log(pages); | |
| − | + |      // Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors) | |
| − | + |      pages.sort(function (a, b) { | |
| − | + |    		return b.normalVisitors + b.mainPageVisitors - a.normalVisitors - a.mainPageVisitors; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | function  | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|      }); |      }); | ||
| + |     return pages; | ||
| } | } | ||
| − | + | if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogTheCounter") { | |
| − | + | 	document.title = 'Opslaan WikiStatistieken'; | |
| − | + | 	document.getElementById('bodyContent').innerHTML = `Op deze pagina kun je de Statistieken van WikiKids reseten, dit doen we elke zaterdag (\'s middags: tussen 13u en 19u).  | |
| − | + | 			Als je op deze onderstaande knop drukt, moet je ongeveer 5 seconden wachten. Door op de knop te drukken doe je 2 bewerkingen. <br> | |
| − | + | 			<span style="color: red;">Zodra de acties zijn uitgevoerd, wordt je doorgestuurd naar de hoofdpagina,   | |
| − | + | 			als dat niet gebeurt, <a href="https://wikikids.nl/index.php?title=Overleg_gebruiker:Rots61&action=edit§ion=new">klik hier</a> (KLIK). </span> | |
| − | + | 			Want dan zijn de statistieken niet opgeslagen. <br> | |
| − | + | 			<span id="logthecounterx5"></span><button id="logthecounterbutton" onclick="goforitLogTheCounter();" disabled>Activeer deze functie</button><br><br><br> | |
| − | + | 			Wil je geen meldingen meer ontvangen op zaterdag? Dan kun je je <a href="https://wikikids.nl/Speciaal:Voorkeuren#mw-prefsection-gadgets">hier (KLIK)</a> uitschrijven. Maak het vakje voor <b>WikiStats Opslaan</b> wit, en klik op opslaan. `; | |
| − | + | 	document.getElementById('firstHeading').innerHTML = 'Special:LogTheCounter (WikiStats opslaan)'; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | 	if (!mw.user.options.exists('userjs-ltc')) { | |
| − | + | 		document.getElementById('logthecounterx5').innerHTML = 'De statistieken zijn al opgeslagen of het is niet tussen tussen 13:00 en 19:00 op zaterdag.<br>'; | |
| − | + | 	} else { | |
| − | + | 		tx = mw.user.options.get('userjs-ltc').slice(3,6); | |
| − | + | 		document.getElementById('logthecounterbutton').disabled = false;   | |
| − | + | 	} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| } | } | ||
| − | + | checkDate();  | |
| − | function  | + | function checkDate() { | 
| − | + | 	let now = new Date(); | |
| − | + | 	if (now.getUTCDay() !== 6) return; | |
| − | + | 	if (now.getUTCHours() < 11) return; | |
| − | + | 	if (now.getUTCHours() > 18) return; | |
| − | + | 	let date = now.getFullYear() + "" + addZero((now.getMonth() + 1)) + "" + addZero(now.getDate()); | |
| − | + | 	new mw.Api().get( { | |
| − | + | 	   action: "query", | |
| − | + | 	   titles: [ "WikiKids:Statistieken/Logs/" + date], | |
| − | + | 	} ).then( function( ret ) { | |
| − | + | 	   $.each( ret.query.pages, function() { | |
| − | + | 	   		console.log(this); | |
| − | + | 	   		if ( this.missing !== "" ) { | |
| − | + | ||
| + | 	    	} else { | ||
| + | 	    		ltc_showMessage(); | ||
| + | 	    	} | ||
| + | 	    } ); | ||
| + | 	}, function( error ) { | ||
| + | 	    ltc_showMessage(); | ||
| + | 	} ); | ||
| } | } | ||
| − | + | var allPages; | |
| − | + | var informatieLogTheCounter = {"Endtime":new Date().toISOString()}; | |
| − | + | var tx; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | function  | + | function goforitLogTheCounter(){ | 
| − | + | 	window.onbeforeunload = function() { | |
| − | + | 		return true; | |
| − | + | 	}; | |
| − | + |     allPages = getPagesLogTheCounter(); | |
| − | + |     let now = new Date(); | |
| − | + | 	let onejan = new Date(now.getFullYear(), 0, 1); | |
| − | + | 	let week = Math.ceil((((now.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | 	informatieLogTheCounter["Types"] = 'Intern'; | |
| − | + |      informatieLogTheCounter["Jaar-Week"] = now.getFullYear() + '' + week; | |
| − | + |      informatieLogTheCounter["Totalpages"] = 0; | |
| − | + |      informatieLogTheCounter['Totalviews'] = 0; | |
| − | + | 	for (var x = 0; x < allPages.length; x++) { | |
| − | + | 		deleteit('t','title', x); | |
| − | + | 		if (allPages[x]['mPV'] === 0) { | |
| − | + | 			delete allPages[x]['mPV']; | |
| − | + | 		} else { | |
| − | + | 			if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) { | |
| − | + | 				informatieLogTheCounter['Totalviews'] += allPages[x]['mPV']; | |
| − | + | 			} | |
| − | + | 		} | |
| − | + | 		if (allPages[x]['nV'] === 0) { | |
| − | + | 			delete allPages[x]['nV']; | |
| − | + | 		} else { | |
| − | + | 			if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) { | |
| − | + | 			informatieLogTheCounter['Totalviews'] += allPages[x]['nV']; | |
| − | + | 			} | |
| − | + | 		} | |
| − | + | 		if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) { | |
| − | + | 			informatieLogTheCounter["Totalpages"] += 1; | |
| − | + | 		} | |
| − | + | 	} | |
| − | + | 	console.log(allPages);  | |
| − | + | 	saveitlogthecounter(); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| } | } | ||
| − | + | function deleteit(new_key, old_key, x){ | |
| − | + | 	Object.defineProperty(allPages[x], new_key, | |
| − | + |         Object.getOwnPropertyDescriptor(allPages[x], old_key)); | |
| − | + |      delete allPages[x][old_key]; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| } | } | ||
| − | + | function ltc_showMessage() { | |
| − | + | 	try { | |
| − | + | 	document.getElementById('logthecounterbutton').disabled = false;  | |
| − | + | 	document.getElementById('logthecounterx5').innerHTML = ''; | |
| − | + | 	} catch (err) { | |
| − | + | 	} | |
| − | + | 	document.getElementById('siteNotice').innerHTML = '<a style="background:yellow" href="https://wikikids.nl/Speciaal:LogTheCounter">Klik hier om de statistieken op te slaan. (KLIK)</a>'; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| } | } | ||
Huidige versie van 17 mei 2025 om 11:52
/* jshint sub:true maxerr:100000 */
// [[User:Rots61/Gadget-LogTheCounter.js]] gemaakt door [[User:Rots61]]
/*
var api = new mw.Api();
api.saveOption('userjs-ltc', 'x').then( x =>console.log(x));
*/
function addZero(number) {
	return number < 10 ? "0" + number : number;
}
function saveitlogthecounter() {
	if (Array.isArray(allPages)) {
        allPages = JSON.stringify(allPages);
    }
    date = new Date();
    date = date.getFullYear() + "" + addZero((date.getMonth() + 1)) + "" + addZero(date.getDate());
    api.get({
        action: 'query',
        prop: 'info',
        intoken: 'edit',
        titles: 'kaslv', //Pagina moet niet bestaan. 
    }).done(
        function (data) {
            edit_token = data.query.pages['-1'].edittoken;
        }).done(function (data) {
            api.post({
                'action': 'edit',
                'title': "Wikikids:Statistieken/Logs/" + date,
                'text': allPages,
                'summary': "Pagina opgeslagen met LogTheCounter.",
                'bot': true,
                'token': edit_token,
            }).done(
                function (data) {
                    if (data.edit.result == "Success") {
                        mw.notify("Hele pagina opgeslagen!", { autoHide: false });
                        deleteDataOnServer();
                    } else {
                        mw.notify("Opslaan mislukt, stuur Rots61 aub direct een berichtje.", { autoHide: false });
                    }
                    console.log(data.edit);
                    document.getElementsByTagName("h1")[0].textContent = "Opslaan gelukt!";
                });
        });      
    api.get({
        action: 'query',
        prop: 'info',
        intoken: 'edit',
        titles: 'kaslv', //Pagina moet niet bestaan. 
    }).done(
        function (data) {
            edit_token = data.query.pages['-1'].edittoken;
        }).done(function (data) {
            api.post({
                'action': 'edit',
                'title': "Wikikids:Statistieken/Logs/" + date + "/info",
                'text': JSON.stringify(informatieLogTheCounter),
                'summary': "Pagina opgeslagen met LogTheCounter.",
                'bot': true,
                'token': edit_token,
            }).done(
                function (data) {
                    if (data.edit.result == "Success") {
                        mw.notify("Pagina opgeslagen!", { autoHide: false });
                    } else {
                        mw.notify("Opslaan mislukt 2, stuur Rots61 aub direct een berichtje.", { autoHide: false });
                    }
                    console.log(data.edit);
                });
        });
}
function deleteDataOnServer() {
    var settings2 = {
	  "url": "https://wikikids.dekenos.nl/pages/delete",
	  "method": "POST",
	  "timeout": 0,
	  "headers": {
	    "Host": "wikikids.dekenos.nl",
	    "Content-Type": "application/json"
	  },
	  "data": JSON.stringify({
	    "message": 'oke'
	  }),
	};
	$.ajax(settings2).done(function (response) {
		mw.notify("Reseten statistieken2 gelukt", { autoHide: false });
		window.onbeforeunload = null;
		window.location.href = '/';
	}).catch(function (error) {
		if (error.responseText || JSON.parse(error.responseText).succes) {
			mw.notify("Reseten statistieken2 gelukt", { autoHide: false });
			window.onbeforeunload = null;
			window.location.href = '/';
		} else {
			mw.notify('Resetten mislukt, stuur Rots61 aub direct een berichtje.', {autoHide: false});
		}
	});
}
function getPagesLogTheCounter() {
    var pages = [];
    var request = new XMLHttpRequest();
    request.open('GET', 'https://wikikids.dekenos.nl/pages', false);
    request.send(null);
    if (request.status === 200) {
        pages = JSON.parse(request.responseText);
    }
    console.log(pages);
    // Sorteer de pagina's op het aantal bezoekers (hoog naar laag) (page.normalVisitors + page.mainPageVisitors)
    pages.sort(function (a, b) {
   		return b.normalVisitors + b.mainPageVisitors - a.normalVisitors - a.mainPageVisitors;
    });
    return pages;
}
if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogTheCounter") {
	document.title = 'Opslaan WikiStatistieken';
	document.getElementById('bodyContent').innerHTML = `Op deze pagina kun je de Statistieken van WikiKids reseten, dit doen we elke zaterdag (\'s middags: tussen 13u en 19u). 
			Als je op deze onderstaande knop drukt, moet je ongeveer 5 seconden wachten. Door op de knop te drukken doe je 2 bewerkingen. <br>
			<span style="color: red;">Zodra de acties zijn uitgevoerd, wordt je doorgestuurd naar de hoofdpagina, 
			als dat niet gebeurt, <a href="https://wikikids.nl/index.php?title=Overleg_gebruiker:Rots61&action=edit§ion=new">klik hier</a> (KLIK). </span>
			Want dan zijn de statistieken niet opgeslagen. <br>
			<span id="logthecounterx5"></span><button id="logthecounterbutton" onclick="goforitLogTheCounter();" disabled>Activeer deze functie</button><br><br><br>
			Wil je geen meldingen meer ontvangen op zaterdag? Dan kun je je <a href="https://wikikids.nl/Speciaal:Voorkeuren#mw-prefsection-gadgets">hier (KLIK)</a> uitschrijven. Maak het vakje voor <b>WikiStats Opslaan</b> wit, en klik op opslaan. `;
	document.getElementById('firstHeading').innerHTML = 'Special:LogTheCounter (WikiStats opslaan)';
	if (!mw.user.options.exists('userjs-ltc')) {
		document.getElementById('logthecounterx5').innerHTML = 'De statistieken zijn al opgeslagen of het is niet tussen tussen 13:00 en 19:00 op zaterdag.<br>';
	} else {
		tx = mw.user.options.get('userjs-ltc').slice(3,6);
		document.getElementById('logthecounterbutton').disabled = false; 
	}
}
checkDate(); 
function checkDate() {
	let now = new Date();
	if (now.getUTCDay() !== 6) return;
	if (now.getUTCHours() < 11) return;
	if (now.getUTCHours() > 18) return;
	let date = now.getFullYear() + "" + addZero((now.getMonth() + 1)) + "" + addZero(now.getDate());
	new mw.Api().get( {
	   action: "query",
	   titles: [ "WikiKids:Statistieken/Logs/" + date],
	} ).then( function( ret ) {
	   $.each( ret.query.pages, function() {
	   		console.log(this);
	   		if ( this.missing !== "" ) {
	   			
	    	} else {
	    		ltc_showMessage();
	    	}
	    } );
	}, function( error ) {
	    ltc_showMessage();
	} );
}
var allPages;
var informatieLogTheCounter = {"Endtime":new Date().toISOString()};
var tx;
function goforitLogTheCounter(){
	window.onbeforeunload = function() {
		return true;
	};
    allPages = getPagesLogTheCounter();
    let now = new Date();
	let onejan = new Date(now.getFullYear(), 0, 1);
	let week = Math.ceil((((now.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7);
	informatieLogTheCounter["Types"] = 'Intern';
    informatieLogTheCounter["Jaar-Week"] = now.getFullYear() + '' + week;
    informatieLogTheCounter["Totalpages"] = 0;
    informatieLogTheCounter['Totalviews'] = 0;
	for (var x = 0; x < allPages.length; x++) {
		deleteit('t','title', x);
		if (allPages[x]['mPV'] === 0) {
			delete allPages[x]['mPV'];
		} else {
			if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
				informatieLogTheCounter['Totalviews'] += allPages[x]['mPV'];
			}
		}
		if (allPages[x]['nV'] === 0) {
			delete allPages[x]['nV'];
		} else {
			if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
			informatieLogTheCounter['Totalviews'] += allPages[x]['nV'];
			}
		}
		if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
			informatieLogTheCounter["Totalpages"] += 1;
		}
	}
	console.log(allPages); 
	saveitlogthecounter();
}
function deleteit(new_key, old_key, x){
	Object.defineProperty(allPages[x], new_key,
        Object.getOwnPropertyDescriptor(allPages[x], old_key));
    delete allPages[x][old_key];
}
function ltc_showMessage() {
	try {
	document.getElementById('logthecounterbutton').disabled = false; 
	document.getElementById('logthecounterx5').innerHTML = '';
	} catch (err) {
	}
	document.getElementById('siteNotice').innerHTML = '<a style="background:yellow" href="https://wikikids.nl/Speciaal:LogTheCounter">Klik hier om de statistieken op te slaan. (KLIK)</a>';
}