Gebruiker:Rots61/JS-TVB.js
Naar navigatie springen
Naar zoeken springen
Let op! Nadat je de veranderingen hebt opgeslagen, moet je de cache van je browser nog legen om ze daadwerkelijk te zien.
Mozilla (incl. Firefox) | ctrl-shift-r |
IE | ctrl-f5 |
Opera | f5 |
Safari | cmd-r |
Konqueror | f5 |
/* 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 = {};
// Het hoofdportaal wordt niet getoond als een onderportaal dit heeft. ["HOOFDPORTAAL"] = ["ONDERPORTAAL", "ONDERPORTAAL2"]
hoofdportalen["Nederland"] = ["Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel"];
hoofdportalen["België"] = ["Vlaanderen", "Wallonië"];
hoofdportalen["Oceanië"] = ["Australië", "Nieuw-Zeeland"];
hoofdportalen["Europa"] = ["Nederland", "België", "Frankrijk", "Denemarken", "Duitsland", "Griekenland", "Italië", "Luxemburg", "Oekraïne", "Oostenrijk", "Rusland", "Spanje", "Turkije", "Verenigd Koninkrijk", "Zweden", "Zwitserland", "Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel", "Vlaanderen", "Wallonië"];
hoofdportalen["Azië"] = ["China", "Japan", "Turkije", "Rusland", "Israël", "Filipijnen"];
hoofdportalen["Afrika"] = ["Egypte", "Israël"];
hoofdportalen["Noord-Amerika"] = ["Mexico", "Verenigde Staten", "Canada"];
hoofdportalen["WikiKidsAtlas"] = ["Nederland", "België", "Frankrijk", "Denemarken", "Duitsland", "Griekenland", "Italië", "Luxemburg", "Oekraïne", "Oostenrijk", "Rusland", "Spanje", "Turkije", "Verenigd Koninkrijk", "Zweden", "Zwitserland", "Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel", "Vlaanderen", "Wallonië", "China", "Japan", "Turkije", "Rusland", "Israël", "Filipijnen", "Egypte", "Mexico", "Verenigde Staten", "Canada"]; //Alle portalen eronder, als het goed is.
hoofdportalen["Geschiedenis"] = ["Amerikaanse Burgeroorlog", "Eerste Wereldoorlog", "Egyptische Oudheid", "Franse Tijd", "Gouden Eeuw", "Oudheid", "Prehistorie", "Renaissance", "Romeinse Oudheid", "Van 1945 tot nu", "Griekse Oudheid", "Industriële Revolutie"];
hoofdportalen["Wetenschap"] = ["Wiskunde", "Natuurkunde", "Scheikunde", "Biologie", "Coronavirus", "Menselijk lichaam", "Dierentuinen"];
hoofdportalen["Verkeer & Vervoer"] = ["Openbaar vervoer", "Ruimtevaart", "Binnen- en zeevaart"];
hoofdportalen["Biologie"] = ["Coronavirus", "Menselijk lichaam", "Dierentuinen"];
hoofdportalen["Politiek"] = ["Republiek", "Monarchie"];
function TVBstart0() {
api = new mw.Api();
// Get the number of links
var temp;
if (!catsOnPage.includes('WikiKids:Geen TVB')) {
for (var x = 0; x < catsOnPage.length; x++) {
api[x] = new mw.Api();
TVBgetPageCountPT(x, "Categorie:" + catsOnPage[x]);
}
}
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;
});
if (TVBportalen.length > 1) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan woordenschat.
TVBportalen.splice(TVBportalen.indexOf('Woordenschat'), 1);
}
for (const property in hoofdportalen) {
if (TVBportalen.includes(property)) {
for (var a = 0; a < hoofdportalen[property].length; 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);
}
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;
});
if (TVBportalen.length > 1 && TVBportalen.includes('Woordenschat')) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan woordenschat.
TVBportalen.splice(TVBportalen.indexOf('Woordenschat'), 1);
}
for (const property in hoofdportalen) {
if (TVBportalen.includes(property)) {
for (var a = 0; a < hoofdportalen[property].length; 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><div id="TVBdemo"></div>';
TVBstart0();
} else if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view') {
document.getElementById('mw-content-text').outerHTML += '<hr><div id="TVBdemo"></div>';
TVBstartCats();
}