Gebruiker:Rots61/JS-TVB.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
Regel 32: Regel 32:
 
    }
 
    }
 
     }
 
     }
    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) {
 
function TVBgetPageCountPT(apinr, pageName) {
     return api[apinr].get({
+
     api[apinr].get({
 
         action: "query",
 
         action: "query",
 
         prop: "linkshere",
 
         prop: "linkshere",
Regel 70: Regel 45:
 
         temp = temp[property].linkshere;
 
         temp = temp[property].linkshere;
 
         }
 
         }
         if (typeof temp === 'undefined') {
+
         if (typeof temp !== 'undefined') {
            return 0;
 
        } else {
 
 
             var tempgetal = 0;
 
             var tempgetal = 0;
 
             while (temp[tempgetal]) {
 
             while (temp[tempgetal]) {
Regel 80: Regel 53:
 
                 tempgetal += 1;
 
                 tempgetal += 1;
 
             }
 
             }
             if (TVBportalen.length) {
+
            console.log(apinr);
                return TVBportalen;
+
             if ((apinr + 1) == catsOnPage.length) {
             } else {
+
            loadBoxes();
                return 0;
+
             } else if (apinr === 1 && mw.config.get('wgNamespaceNumber') === 14) {
 +
            loadBoxes();
 +
            }
 +
        } else {
 +
        if (apinr + 1 === catsOnPage.length) {
 +
            loadBoxes();
 +
            } else if (apinr === 1 && mw.config.get('wgNamespaceNumber') === 14) {
 +
            loadBoxes();
 
             }
 
             }
 
         }
 
         }
 +
       
 
     });
 
     });
 +
}
 +
 +
function loadBoxes() {
 +
var wikitekskt = "{{TVB|";
 +
    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);
 +
}
 +
}
 +
}
 +
}
 +
for (var y = 0; y < TVBportalen.length; y++) {
 +
wikitekst += TVBportalen[y] + '|';
 +
}
 +
}
 +
bodyContentWidthX = document.getElementById('bodyContent').offsetWidth;
 +
wikitekst += 'w=' + bodyContentWidthX + '}}';
 +
console.log(wikitekst);
 +
api.get( {
 +
    action: 'parse',
 +
    text: textToParse,
 +
    titles: mw.config.get('wgTitle'),
 +
    contentmodel: 'wikitext',
 +
} ).done( function ( query ) {
 +
    console.log(query.parse.text['*']);
 +
    document.getElementById('TVBdemo').outerHTML += query.parse.text['*'];
 +
});
 
}
 
}
  
Regel 92: Regel 109:
 
api[1] = new mw.Api();
 
api[1] = new mw.Api();
 
TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle'));
 
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);
 
 
}
 
}
  

Versie van 8 mei 2023 21:36

/* 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]);
	    }
    }
}

function TVBgetPageCountPT(apinr, pageName) {
    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') {
            var tempgetal = 0;
            while (temp[tempgetal]) {
                if (temp[tempgetal]["title"].startsWith("Gebruiker:Rots61/Portalen")) {
                    TVBportalen.push(temp[tempgetal]["title"].split("/Portalen/").pop());
                }
                tempgetal += 1;
            }
            console.log(apinr);
            if ((apinr + 1) == catsOnPage.length) {
            	loadBoxes();
            } else if (apinr === 1 && mw.config.get('wgNamespaceNumber') === 14) {
            	loadBoxes();
            }
        } else {
        	if (apinr + 1 === catsOnPage.length) {
            	loadBoxes();
            } else if (apinr === 1 && mw.config.get('wgNamespaceNumber') === 14) {
            	loadBoxes();
            }
        }
        
    });
}

function loadBoxes() {
	var wikitekskt = "{{TVB|";
    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);
					}
				}
			}
		}
		for (var y = 0; y < TVBportalen.length; y++) { 
			wikitekst += TVBportalen[y] + '|';
		}
	}
	bodyContentWidthX = document.getElementById('bodyContent').offsetWidth;
	wikitekst += 'w=' + bodyContentWidthX + '}}';
	console.log(wikitekst);
	api.get( {
	    action: 'parse',
	    text: textToParse,
	    titles: mw.config.get('wgTitle'),
	    contentmodel: 'wikitext',
	} ).done( function ( query ) {
	    console.log(query.parse.text['*']);
	    document.getElementById('TVBdemo').outerHTML += query.parse.text['*'];
	});
}

function TVBstartCats() {
	api[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 += '<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();
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Rots61/JS-TVB.js&oldid=785433"