Gebruiker:Rots61/JS-TVB.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 7: | Regel 7: | ||
var TVBportalen = []; | var TVBportalen = []; | ||
− | function | + | function TVBstart0() { |
api = new mw.Api(); | api = new mw.Api(); | ||
// Get the number of links | // Get the number of links | ||
Regel 58: | Regel 58: | ||
} | } | ||
− | + | function TVBstartCats() { | |
− | |||
− | |||
api[1] = new mw.Api(); | api[1] = new mw.Api(); | ||
TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle')); | TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle')); | ||
Regel 73: | Regel 71: | ||
} | } | ||
}, 500); | }, 500); | ||
+ | } | ||
+ | |||
+ | if (mw.config.get('wgNamespaceNumber') === 0) { | ||
+ | document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstart0();">TVB</button></div>'; | ||
+ | } else if (mw.config.get('wgNamespaceNumber') === 14) { | ||
+ | document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstartCats();">TVB</button></div>'; | ||
} | } |
Versie van 1 mei 2023 22:14
/* jshint sub:true maxerr:100000 */
// Script dat ervoor zorgt dat alle pagina's met een categorie die bij een portaal hoort, automatisch een of meerdere TVB krijgen.
// Geschreven door Rots61
var api;
var catsOnPage = mw.config.get('wgCategories');
var TVBportalen = [];
function TVBstart0() {
api = new mw.Api();
// Get the number of links
var temp;
for (var x = 0; x < catsOnPage.length; x++) {
api[x] = new mw.Api();
console.log('Begin');
TVBgetPageCountPT(x, "Categorie:" + catsOnPage[x]).then(console.log('Einde'));
}
setTimeout( function () { // The page count we got will be passed here.
if (TVBportalen.length !== 0) {
document.getElementById('TVBdemo').innerHTML = 'TVB: ';
for (var y = 0; y < TVBportalen.length; y++) {
document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
}
} else {
document.getElementById('TVBdemo').innerHTML = 'Geen';
}
}, 500);
}
function TVBgetPageCountPT(apinr, pageName) {
return api[apinr].get({
action: "query",
prop: "linkshere",
titles: pageName,
lhlimit: "100",
}).then(function (data) {
temp = data.query.pages;
for (const property in temp) {
temp = temp[property].linkshere;
}
if (typeof temp === 'undefined') {
return 0;
} else {
var tempgetal = 0;
while (temp[tempgetal]) {
if (temp[tempgetal]["title"].startsWith("Gebruiker:Rots61/Portalen")) {
TVBportalen.push(temp[tempgetal]["title"].split("/Portalen/").pop());
}
tempgetal += 1;
}
if (TVBportalen.length) {
return TVBportalen;
} else {
return 0;
}
}
});
}
function TVBstartCats() {
api[1] = new mw.Api();
TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle'));
setTimeout( function () { // The page count we got will be passed here.
if (TVBportalen.length !== 0) {
document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): ';
for (var y = 0; y < TVBportalen.length; y++) {
document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
}
} else {
document.getElementById('TVBdemo').innerHTML = 'Geen boxen in deze categorie.' ;
}
}, 500);
}
if (mw.config.get('wgNamespaceNumber') === 0) {
document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstart0();">TVB</button></div>';
} else if (mw.config.get('wgNamespaceNumber') === 14) {
document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstartCats();">TVB</button></div>';
}