Gebruiker:Rots61/JS-TVB.js

Uit Wikikids
⧼vector-jumptonavigation⧽ ⧼vector-jumptosearch⧽

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 */
// Dit script heeft invloed op heel WikiKids, alle gebruikers.  
// 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 apiTVB = {}; 
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-Brabant", "Limburg (Nederland)", "Utrecht (provincie)", "Overijssel"];
hoofdportalen["België"] = ["Vlaanderen", "Wallonië"];
hoofdportalen["Oceanië"] = ["Australië", "Nieuw-Zeeland"];
hoofdportalen["Europa"] = ["Romeinse Oudheid" ,"Griekse Oudheid", "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", "Middeleeuwen", "Oudheid", "Prehistorie", "Renaissance", "Romeinse Oudheid", "Van 1945 tot nu", "Griekse Oudheid", "Industriële Revolutie", "Tweede Wereldoorlog"];
hoofdportalen["Wetenschap"] = ["Wiskunde", "Natuurkunde", "Scheikunde", "Biologie", "Coronavirus", "Menselijk lichaam", "Dierentuinen", "Dieren"];
hoofdportalen["Verkeer & Vervoer"] = ["Openbaar vervoer", "Ruimtevaart", "Binnen- en zeevaart", "Luchtvaart"];
hoofdportalen["Biologie"] = ["Coronavirus", "Menselijk lichaam", "Dierentuinen", "Dieren"];
hoofdportalen["Politiek"] = ["Republiek", "Monarchie"];
hoofdportalen["Media"] = ["Televisie"];
hoofdportalen["Godsdienst"] = ['Islam', 'Christendom'];
hoofdportalen["Oudheid"] = ["Griekse Oudheid", "Romeinse Oudheid", "Egyptische Oudheid"];
hoofdportalen["Griekenland"] = ["Griekse Oudheid"];
hoofdportalen["Kunst & Cultuur"] = ["Muziek", "Architectuur", "Literatuur", "Theater", "Film", "Harry Potter"];
//hoofdportalen["Economie"] = ["Beroepen"]; Lijkt me niet nodig, op dit moment
 
//einde definitie hoofdportalen en subportalen

function TVBstart0() {
    apiTVB['randomstingasd4'] = new mw.Api();
    // Get the number of links
    var temp;
    if (catsOnPage.includes('WikiKids:Geen TVB') || catsOnPage.includes('Wikikids:Doorverwijspagina') || mw.config.get('wgArticleId') === 1) {
    } else {
    	if (catsOnPage.includes('Woordenschat') && catsOnPage.length === 1) {
    		TVBportalen.push('Woordenschat');
			loadBoxes();
    	} else if (catsOnPage.includes('Woordenschat') && catsOnPage.length === 2 ) {
			if (catsOnPage.includes('Basiswoordenlijstgroep8') || (catsOnPage.includes('Basiswoordenlijstgroep7') || (catsOnPage.includes('Basiswoordenlijstgroep6') || ( catsOnPage.includes('Basiswoordenlijstgroep5') || (catsOnPage.includes('Basiswoordenlijstgroep4') || (catsOnPage.includes('Basiswoordenlijstgroep3') || (catsOnPage.includes('Basiswoordenlijstgroep2') ||  catsOnPage.includes('Basiswoordenlijstgroep1')))))))) {
				TVBportalen.push('Woordenschat');
				loadBoxes();
			} else {
			    for (var x = 0; x < catsOnPage.length; x++) {
			    	apiTVB[x] = new mw.Api();
			    	TVBgetPageCountPT(x, "Categorie:" + catsOnPage[x]);
			    }
			}
    	} else {
		    for (var e = 0; e < catsOnPage.length; e++) {
		    	apiTVB[e] = new mw.Api();
		    	TVBgetPageCountPT(e, "Categorie:" + catsOnPage[e]);
		    }
    	}
    }
}

function TVBgetPageCountPT(apinr, pageName) {
    apiTVB[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') {
            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 ((apinr + 1) == catsOnPage.length) {
            	loadBoxes(pageName);
            } else if (apinr === 1 && mw.config.get('wgNamespaceNumber') === 14) {
            	loadBoxes(pageName);
            } else if (mw.config.get('wgPageName').startsWith("Gebruiker:Rots61/Portalen/")) {
            	loadBoxes(pageName);
            }
        } else {
        	if (apinr + 1 === catsOnPage.length) {
            	loadBoxes(pageName);
            } else if (apinr === 1 && mw.config.get('wgNamespaceNumber') === 14) {
            	loadBoxes(pageName);
            } else if (mw.config.get('wgPageName').startsWith("Gebruiker:Rots61/Portalen/")) {
            	loadBoxes(pageName);
            }
        }
        
    });
}

function loadBoxes(pageName) {
	setTimeout(function() {
	var wikitekstTVB = "{{TVB|";
    if (TVBportalen.length !== 0) {
		TVBportalen = TVBportalen.filter(function(item, pos, self) {
		    return self.indexOf(item) == pos;
		});
		console.log(TVBportalen);
		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);
		}
		if (TVBportalen.length > 1 && TVBportalen.includes('Maatschappij')) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan maatschappij.
			TVBportalen.splice(TVBportalen.indexOf('Maatschappij'), 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])) {
						if (TVBportalen.includes(property)) {
							TVBportalen.splice(TVBportalen.indexOf(property), 1);
						}
					}
				}
			}
		}
		if (TVBportalen.length > 1 && TVBportalen.includes('Beroepen')) { //Zorgt ervoor dat alle pagina's in de cat beroepen, alleen zichtbaar is als het de enige categorie is. 
			TVBportalen.splice(TVBportalen.indexOf('Beroepen'), 1);
		}
		for (var y = 0; y < TVBportalen.length; y++) { 
			wikitekstTVB += TVBportalen[y] + '|';
		}
	}
	bodyContentWidthX = document.getElementById('bodyContent').offsetWidth;
	wikitekstTVB += 'w=' + bodyContentWidthX + '}}';
	console.log(wikitekstTVB);
	if (mw.config.get('wgPageName').startsWith("Gebruiker:Rots61/Portalen/")) {
		document.getElementById(pageName).outerHTML = wikitekstTVB; 
		TVBportalen = [];
	} else {
		api.get( {
		    action: 'parse',
		    text: wikitekstTVB,
		    titles: mw.config.get('wgTitle'),
		    contentmodel: 'wikitext',
		} ).done( function ( query ) {
		    document.getElementById('TerugVerwijsBox').outerHTML += query.parse.text['*'];
		});
	}
	}, 250);
}

function TVBactionOverzichtPagina() {
	var alllinks = document.getElementById('mw-content-text').getElementsByTagName('a').length;
	for (var x = 0; x < alllinks; x++) {
		var linkje = document.getElementById('mw-content-text').getElementsByTagName('a')[x].title;
		document.getElementById('mw-content-text').getElementsByTagName('a')[x].outerHTML += ' <span class="TVBbutton" id="'+ linkje + '"><button onclick=\'TVBstartOverzichtPagina(\"' + linkje +'\")\'>Bekijk resultaat</button></span>';
	}
}

function TVBstartOverzichtPagina(cat) {
	apiTVB[cat] = new mw.Api();
	TVBgetPageCountPT(cat, cat);
}

function TVBstartCats() {
	apiTVB[1] = new mw.Api();
	TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle'));
}

if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view') {
	document.getElementById('mw-content-text').outerHTML += '<div id="TerugVerwijsBox"></div>';
	TVBstart0();
} else if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view') {
	document.getElementById('mw-content-text').outerHTML += '<div id="TerugVerwijsBox"></div>';
	TVBstartCats();
} else if (mw.config.get('wgPageName').startsWith("Gebruiker:Rots61/Portalen/") && mw.config.get('wgAction') === 'view') {
	//TVBactionOverzichtPagina();
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Rots61/JS-TVB.js&oldid=846053"