Gebruiker:Rots61/JS-TVB.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 119: | Regel 119: | ||
if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view') { | if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view') { | ||
if (mw.config.get('wgUserName') === "Rots61") { | if (mw.config.get('wgUserName') === "Rots61") { | ||
− | document.querySelector('html'). | + | document.querySelector('html').innerHTML = '<div id="TVBdemo"></div>'; |
TVBstart0(); | TVBstart0(); | ||
} else { | } else { | ||
Regel 126: | Regel 126: | ||
} else if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view') { | } else if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view') { | ||
if (mw.config.get('wgUserName') === "Rots61") { | if (mw.config.get('wgUserName') === "Rots61") { | ||
− | document.querySelector('html'). | + | document.querySelector('html').innerHTML = '<div id="TVBdemo"></div>'; |
TVBstartCats(); | TVBstartCats(); | ||
} else { | } else { |
Versie van 4 mei 2023 17:56
/* 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.
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"];
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;
});
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) { //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') {
if (mw.config.get('wgUserName') === "Rots61") {
document.querySelector('html').innerHTML = '<div id="TVBdemo"></div>';
TVBstart0();
} else {
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') {
if (mw.config.get('wgUserName') === "Rots61") {
document.querySelector('html').innerHTML = '<div id="TVBdemo"></div>';
TVBstartCats();
} else {
document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstartCats();">TVB</button></div>';
}
}