Gebruiker:Rots61/JS-TVB.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 6: | Regel 6: | ||
var catsOnPage = mw.config.get('wgCategories'); | var catsOnPage = mw.config.get('wgCategories'); | ||
var TVBportalen = []; | var TVBportalen = []; | ||
+ | var hoofdportalen = {}; | ||
+ | hoofdportalen["Nederland"] = ["Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel"]; | ||
+ | hoofdportalen["België"] = ["Vlaanderen", "Wallonië"]; | ||
+ | hoofdportalen["Verkeer & Vervoer"] = ["Openbaar vervoer", "Ruimtevaart", "Binnen- en zeevaart"]; | ||
+ | hoofdportalen["Biologie"] = ["Coronavirus", "Menselijk lichaam", "Dierentuinen"]; | ||
function TVBstart0() { | function TVBstart0() { | ||
Regel 69: | Regel 74: | ||
return self.indexOf(item) == pos; | return self.indexOf(item) == pos; | ||
}); | }); | ||
+ | for (const property in hoofdportalen) { | ||
+ | if (TVBportalen.includes(property)) { | ||
+ | for (var a = 0; a < hoofdportalen[property]; a++) { | ||
+ | if (TVBportalen.includes(hoofdportalen[property][a])) { | ||
+ | TVBportalen.splice(TVBportalen.indexOf(property), 1); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): '; | document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): '; | ||
for (var y = 0; y < TVBportalen.length; y++) { | for (var y = 0; y < TVBportalen.length; y++) { |
Versie van 4 mei 2023 13:38
/* 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 = [];
var hoofdportalen = {};
hoofdportalen["Nederland"] = ["Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel"];
hoofdportalen["België"] = ["Vlaanderen", "Wallonië"];
hoofdportalen["Verkeer & Vervoer"] = ["Openbaar vervoer", "Ruimtevaart", "Binnen- en zeevaart"];
hoofdportalen["Biologie"] = ["Coronavirus", "Menselijk lichaam", "Dierentuinen"];
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) {
TVBportalen = TVBportalen.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
});
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) {
TVBportalen = TVBportalen.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
});
for (const property in hoofdportalen) {
if (TVBportalen.includes(property)) {
for (var a = 0; a < hoofdportalen[property]; a++) {
if (TVBportalen.includes(hoofdportalen[property][a])) {
TVBportalen.splice(TVBportalen.indexOf(property), 1);
}
}
}
}
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 && mw.config.get('wgAction') === 'view') {
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 && mw.config.get('wgAction') === 'view') {
document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstartCats();">TVB</button></div>';
}