Gebruiker:Rots61/Gadget-LogTheCounter.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 32: | Regel 32: | ||
mw.notify("Hele pagina opgeslagen!", { autoHide: false }); | mw.notify("Hele pagina opgeslagen!", { autoHide: false }); | ||
} else { | } else { | ||
− | mw.notify(" | + | mw.notify("Hele pagina 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!"; | ||
}); | }); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
api.post({ | api.post({ | ||
'action': 'edit', | 'action': 'edit', | ||
Regel 67: | Regel 49: | ||
mw.notify("Info opgeslagen!", { autoHide: false }); | mw.notify("Info opgeslagen!", { autoHide: false }); | ||
} else { | } else { | ||
− | mw.notify(" | + | mw.notify("Info mislukt", { autoHide: false }); |
} | } | ||
console.log(data.edit); | console.log(data.edit); | ||
Regel 128: | Regel 110: | ||
console.log(allPages); | console.log(allPages); | ||
saveitlogthecounter(); | saveitlogthecounter(); | ||
− | |||
} | } | ||
Versie van 10 feb 2023 14:38
/* jshint sub:true maxerr:100000 */
// [[User:MakiBoy/Gadget-LogTheCounter.js]] gemaakt door [[User:Rots61]]
function saveitlogthecounter() {
if (Array.isArray(allPages)) {
allPages = JSON.stringify(allPages);
}
function addZero(number) {
return number < 10 ? "0" + number : number;
}
date = new Date();
date = addZero(date.getDate()) + "" + addZero((date.getMonth() + 1)) + "" + date.getFullYear();
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': "Gebruiker:Rots61/Statistieken/" + 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("Hele pagina mislukt", { autoHide: false });
}
console.log(data.edit);
document.getElementsByTagName("h1")[0].textContent = "Opslaan gelukt!";
});
api.post({
'action': 'edit',
'title': "Gebruiker:Rots61/Statistieken/" + date + '/info',
'text': informatieLogTheCounter,
'summary': "Pagina opgeslagen met LogTheCounter.",
'bot': true,
'token': edit_token,
}).done(
function (data) {
if (data.edit.result == "Success") {
mw.notify("Info opgeslagen!", { autoHide: false });
} else {
mw.notify("Info mislukt", { autoHide: false });
}
console.log(data.edit);
document.getElementById('bodyContent').innerHTML = "Herlaad de pagina.";
});
});
}
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":'0000-00-00T13:27:00.170Z'};
if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogTheCounter") {
document.getElementById('bodyContent').innerHTML = "Pagina gereserveerd voor het opslaan van LogCounter. Gebruik de functie goforitLogTheCounter. <br>"
+ '<input type="text" id="categorielogthecounter"><br><button onclick="goforitLogTheCounter();">Activeer deze functie</button>';
}
function goforitLogTheCounter(){
allPages = getPagesLogTheCounter();
informatieLogTheCounter["Categorie"] = document.getElementById('categorielogthecounter').value;
for (var x = 0; x < allPages.length; x++) {
console.log(x);
console.log(allPages[x]);
if (informatieLogTheCounter['Starttime'] > allPages[x]['updatedAt']) {
informatieLogTheCounter['Starttime'] = allPages[x]['updatedAt'];
}
if (informatieLogTheCounter['Endtime'] < allPages[x]['updatedAt']) {
informatieLogTheCounter['Endtime'] = allPages[x]['updatedAt'];
}
if ((allPages[x]['normalVisitors'] + allPages[x]['mainPageVisitors']) <= 2) {
delete allPages[x]['updatedAt'];
} else {
deleteit('uA','updatedAt', x);
}
if (allPages[x]['mainPageVisitors'] === 0) {
delete allPages[x]['mainPageVisitors'];
} else {
deleteit('mPV', 'mainPageVisitors', x);
}
if (allPages[x]['normalVisitors'] === 0) {
delete allPages[x]['normalVisitors'];
} else {
deleteit('nV','normalVisitors', x);
}
deleteit('t','title', x);
}
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];
}