Gebruiker:Rots61/Gadget-LogTheCounter.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(fix)
 
(35 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 1: Regel 1:
 
/* jshint sub:true maxerr:100000 */
 
/* jshint sub:true maxerr:100000 */
 +
// [[User:MakiBoy/Gadget-LogTheCounter.js]] gemaakt door [[User:Rots61]]
 +
 +
/*
 +
 
var api = new mw.Api();
 
var api = new mw.Api();
var data2 = [];
+
api.saveOption('userjs-ltc', 'x').then( x =>console.log(x));
var aantalallepaginasmetlinkdienietbestaan = 0;
 
  
function allepaginasmetlinkdienietbestaan(apiContinue) {
+
*/
    api.get( {
 
        action: "query",
 
        list: "querypage",
 
        qppage: "Wantedpages",
 
        qplimit: 5000,
 
        qpoffset: apiContinue ? apiContinue.qpoffset : undefined
 
    } ).then( function (data) {
 
    data2 = data2.concat(data.query.querypage.results);
 
    aantalallepaginasmetlinkdienietbestaan += 1;
 
    console.log(aantalallepaginasmetlinkdienietbestaan);
 
        if ( data.continue ) {
 
            allepaginasmetlinkdienietbestaan( data.continue );
 
        } else {
 
      console.log(data2);
 
        bewerkeenspecifiekepaginadaaronderverstaanwedepaginagebruikerdubbelepuntrotsenenzestigslashgevraagdepaginas(data2);
 
        }
 
    } );
 
}
 
  
 
+
function saveitlogthecounter() {
function bewerkeenspecifiekepaginadaaronderverstaanwedepaginagebruikerdubbelepuntrotsenenzestigslashgevraagdepaginas(textx) {
+
if (Array.isArray(allPages)) {
if (Array.isArray(textx)) {
+
         allPages = JSON.stringify(allPages);
         text = JSON.stringify(textx);
+
    }
 +
function addZero(number) {
 +
return number < 10 ? "0" + number : number;
 
     }
 
     }
 +
    date = new Date();
 +
    date = date.getFullYear() + "" + addZero((date.getMonth() + 1)) + "" + addZero(date.getDate());
 
     api.get({
 
     api.get({
 
         action: 'query',
 
         action: 'query',
Regel 40: Regel 29:
 
             api.post({
 
             api.post({
 
                 'action': 'edit',
 
                 'action': 'edit',
                 'title': "Gebruiker:Rots61/GevraagdePaginas",
+
                 'title': "Wikikids:Statistieken/Logs/" + date,
                 'text': text,
+
                 'text': allPages,
                 'summary': "Alle pagina's die bestaan, maar geen link hebben. ([[Gebruiker:Rots61/Gadget-TestGadget.js|script]]; 09-02-2023)",
+
                 'summary': "Pagina opgeslagen met LogTheCounter.",
                'tags': 'Opschonen',
 
 
                 'bot': true,
 
                 'bot': true,
 
                 'token': edit_token,
 
                 'token': edit_token,
Regel 49: Regel 37:
 
                 function (data) {
 
                 function (data) {
 
                     if (data.edit.result == "Success") {
 
                     if (data.edit.result == "Success") {
                         mw.notify("Opgeslagen!", { autoHide: false });
+
                         mw.notify("Hele pagina opgeslagen!", { autoHide: false });
 
                     } else {
 
                     } else {
                         mw.notify("Mislukt", { autoHide: false });
+
                         mw.notify("Opslaan mislukt", { autoHide: false });
 
                     }
 
                     }
 
                     console.log(data.edit);
 
                     console.log(data.edit);
 
                     document.getElementsByTagName("h1")[0].textContent = "Opslaan gelukt!";
 
                     document.getElementsByTagName("h1")[0].textContent = "Opslaan gelukt!";
                    document.getElementById('bodyContent').innerHTML = "Herlaad de pagina.";
+
                });
 +
            document.getElementById('infopaginaLogTheCounter').innerHTML = '<a href="/Wikikids:Statistieken/Logs/' + date + '/info" title="' + date + '">Pagina</a>';
 +
            document.getElementById('addinfotoinfopagelogthecounter').innerHTML = JSON.stringify(informatieLogTheCounter);
 +
        });     
 +
    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", { autoHide: false });
 +
                    }
 +
                    console.log(data.edit);
 
                 });
 
                 });
 
         });
 
         });
 +
    var settings = {
 +
  "url": "https://wikikids.martvanweeghel.nl/rots61/delete",
 +
  "method": "DELETE",
 +
  "timeout": 0,
 +
  "headers": {
 +
    "Host": "wikikids.martvanweeghel.nl",
 +
    "Content-Type": "application/json"
 +
  },
 +
  "data": JSON.stringify({
 +
    "message": tx
 +
  }),
 +
};
 +
 +
$.ajax(settings).done(function (response) {
 +
  mw.notify("Reseten statistieken gelukt", { autoHide: false });
 +
}).catch(function (error) {
 +
mw.notify('Resetten mislukt', {autoHide: false});
 +
console.log(error);
 +
});
 +
}
 +
 +
function getPagesLogTheCounter() {
 +
    var pages = [];
 +
    var request = new XMLHttpRequest();
 +
    request.open('GET', 'https://wikikids.martvanweeghel.nl/pages', false);
 +
    request.send(null);
 +
    if (request.status === 200) {
 +
        pages = JSON.parse(request.responseText);
 +
    }
 +
    // 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;
 +
}
 +
 +
var allPages;
 +
var informatieLogTheCounter = {"Starttime":'9999-99-99T13:27:00.170Z', "Endtime":new Date().toISOString()};
 +
var tx;
 +
$.when(
 +
$.ready,
 +
mw.loader.using(['mediawiki.user', 'mediawiki.api'])
 +
).then(function() {
 +
if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogTheCounter") {
 +
document.title = 'Opslaan WikiStatistieken';
 +
document.getElementById('bodyContent').innerHTML = 'Pagina gereserveerd voor het opslaan van LogCounter. <br><span id="logthecounterx5"></span><button id="logthecounterbutton" onclick="goforitLogTheCounter();">Activeer deze functie</button><br>';
 +
console.log(!mw.user.options.exists('userjs-ltc'));
 +
console.log(!mw.user.options.get('userjs-ltc'));
 +
if (!mw.user.options.exists('userjs-ltc')) {
 +
document.getElementById('logthecounterx5').innerHTML = 'Je bent nog niet gemachtigd om de statistieken op te slaan. ';
 +
document.getElementById('logthecounterbutton').disabled = true;
 +
} else {
 +
tx = mw.user.options.get('userjs-ltc').slice(3,6);
 +
}
 +
}
 +
});
 +
 +
function goforitLogTheCounter(){
 +
    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"] = 'Mobiel';
 +
    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 (informatieLogTheCounter['Starttime'] > allPages[x]['updatedAt']) {
 +
informatieLogTheCounter['Starttime'] = allPages[x]['updatedAt'];
 +
}
 +
if ((allPages[x]['normalVisitors'] + allPages[x]['mainPageVisitors']) <= 5) {
 +
delete allPages[x]['updatedAt'];
 +
} else {
 +
deleteit('uA','updatedAt', x);
 +
}
 +
if (allPages[x]['mainPageVisitors'] === 0) {
 +
delete allPages[x]['mainPageVisitors'];
 +
} else {
 +
if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
 +
informatieLogTheCounter['Totalviews'] += allPages[x]['mainPageVisitors'];
 +
}
 +
deleteit('mPV', 'mainPageVisitors', x);
 +
}
 +
if (allPages[x]['normalVisitors'] === 0) {
 +
delete allPages[x]['normalVisitors'];
 +
} else {
 +
if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
 +
informatieLogTheCounter['Totalviews'] += allPages[x]['normalVisitors'];
 +
}
 +
deleteit('nV','normalVisitors', x);
 +
}
 +
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];
 
}
 
}

Huidige versie van 1 feb 2025 om 22:39

/* jshint sub:true maxerr:100000 */
// [[User:MakiBoy/Gadget-LogTheCounter.js]] gemaakt door [[User:Rots61]]

/*

var api = new mw.Api();
api.saveOption('userjs-ltc', 'x').then( x =>console.log(x));

*/

function saveitlogthecounter() {
	if (Array.isArray(allPages)) {
        allPages = JSON.stringify(allPages);
    }
	function addZero(number) {
		return number < 10 ? "0" + number : number;
    }
    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 });
                    } else {
                        mw.notify("Opslaan mislukt", { autoHide: false });
                    }
                    console.log(data.edit);
                    document.getElementsByTagName("h1")[0].textContent = "Opslaan gelukt!";
                });
            document.getElementById('infopaginaLogTheCounter').innerHTML = '<a href="/Wikikids:Statistieken/Logs/' + date + '/info" title="' + date + '">Pagina</a>';
            document.getElementById('addinfotoinfopagelogthecounter').innerHTML = JSON.stringify(informatieLogTheCounter);
        });      
    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", { autoHide: false });
                    }
                    console.log(data.edit);
                });
        });
    var settings = {
	  "url": "https://wikikids.martvanweeghel.nl/rots61/delete",
	  "method": "DELETE",
	  "timeout": 0,
	  "headers": {
	    "Host": "wikikids.martvanweeghel.nl",
	    "Content-Type": "application/json"
	  },
	  "data": JSON.stringify({
	    "message": tx
	  }),
	};
	
	$.ajax(settings).done(function (response) {
	  mw.notify("Reseten statistieken gelukt", { autoHide: false });
	}).catch(function (error) {
		mw.notify('Resetten mislukt', {autoHide: false});
		console.log(error);
	});
}

function getPagesLogTheCounter() {
    var pages = [];
    var request = new XMLHttpRequest();
    request.open('GET', 'https://wikikids.martvanweeghel.nl/pages', false);
    request.send(null);
    if (request.status === 200) {
        pages = JSON.parse(request.responseText);
    }
    // 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;
}

var allPages;
var informatieLogTheCounter = {"Starttime":'9999-99-99T13:27:00.170Z', "Endtime":new Date().toISOString()};
var tx;
$.when(
	$.ready,
	mw.loader.using(['mediawiki.user', 'mediawiki.api'])
).then(function() {
if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogTheCounter") {
	document.title = 'Opslaan WikiStatistieken';
	document.getElementById('bodyContent').innerHTML = 'Pagina gereserveerd voor het opslaan van LogCounter. <br><span id="logthecounterx5"></span><button id="logthecounterbutton" onclick="goforitLogTheCounter();">Activeer deze functie</button><br>';
	console.log(!mw.user.options.exists('userjs-ltc'));
	console.log(!mw.user.options.get('userjs-ltc'));
	if (!mw.user.options.exists('userjs-ltc')) {
		document.getElementById('logthecounterx5').innerHTML = 'Je bent nog niet gemachtigd om de statistieken op te slaan. ';
		document.getElementById('logthecounterbutton').disabled = true; 
	} else {
		tx = mw.user.options.get('userjs-ltc').slice(3,6);
	}
}
});

function goforitLogTheCounter(){
    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"] = 'Mobiel';
    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 (informatieLogTheCounter['Starttime'] > allPages[x]['updatedAt']) {
			informatieLogTheCounter['Starttime'] = allPages[x]['updatedAt'];
		}
		if ((allPages[x]['normalVisitors'] + allPages[x]['mainPageVisitors']) <= 5) {
			delete allPages[x]['updatedAt'];
		} else {
			deleteit('uA','updatedAt', x);
		}
		if (allPages[x]['mainPageVisitors'] === 0) {
			delete allPages[x]['mainPageVisitors'];
		} else {
			if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
			informatieLogTheCounter['Totalviews'] += allPages[x]['mainPageVisitors'];
			}
			deleteit('mPV', 'mainPageVisitors', x);
		}
		if (allPages[x]['normalVisitors'] === 0) {
			delete allPages[x]['normalVisitors'];
		} else {
			if (!(allPages[x].t.includes('Zoeken:') || allPages[x].t.includes('X:'))) {
			informatieLogTheCounter['Totalviews'] += allPages[x]['normalVisitors'];
			}
			deleteit('nV','normalVisitors', x);
		}
		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];
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Rots61/Gadget-LogTheCounter.js&oldid=916801"