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

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(Nieuwe pagina aangemaakt met '→‎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 krijge...')
 
Regel 4: Regel 4:
  
 
// Input met alle categorieen en portalen
 
// Input met alle categorieen en portalen
 +
/*
 
var WikiKidsAtlas = {};
 
var WikiKidsAtlas = {};
 
WikiKidsAtlas['c'] = {};
 
WikiKidsAtlas['c'] = {};
Regel 34: Regel 35:
 
     document.getElementById('mw-content-text').outerHTML += query.parse.text['*'];
 
     document.getElementById('mw-content-text').outerHTML += query.parse.text['*'];
 
});
 
});
 +
*/
 +
var api;
 +
var catsOnPage = mw.config.get('wgCategories');
 +
var TVBportalen = [];
 +
 +
function TVBstartPT() {
 +
    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) {
 +
    document.getElementById('TVBdemo').innerHTML = 'TVB: ';
 +
    for (var y = 0; y < TVBportalen.length; y++) {
 +
    document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
 +
    }
 +
    }
 +
    }, 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;
 +
            }
 +
        }
 +
    });
 +
}
 +
document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstartPT();">TVB</button></div>';

Versie van 1 mei 2023 20:55

/* 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

// Input met alle categorieen en portalen
/*
var WikiKidsAtlas = {};
WikiKidsAtlas['c'] = {};
WikiKidsAtlas.c.Denemarken = ['Denemarken', 'Deens persoon', 'Cultuur in Denemarken', 'Geografie van Denemarken', 'Weg in Denemarken', 'Regio van Denemarken', 'Plaats in Denemarken', 'Kopenhagen'];
WikiKidsAtlas.c.Duitsland = ['Duitsland', 'Cultuur in Duitsland', 'Duits automerk', 'Geografie van Duitsland', 'Weg in Duitsland', 'Duits persoon', 'Geschiedenis van Duitsland', 'Politiek van Duitsland', 'Duitse politici'];
// Einde input

var allCats = mw.config.get('wgCategories');
var Portaal; 
for (const property in WikiKidsAtlas.c) { 
	for (var x = 0; x < WikiKidsAtlas.c[property].length; x++) {
        if (allCats.includes(WikiKidsAtlas.c[property][x])) {
            Portaal = property;
        }
    }
}

// Mogelijk sjabloon, moeten standaard sjablonen worden. 
WikiKidsAtlas['sjabloon'] = '{{User:Rots61/Portaals|1=' + Portaal + '|kleur=green|afbeelding=bestand:vinkje.png|randkleur=darkgreen|tekstkleur=white}}';
var textToParse = WikiKidsAtlas['sjabloon'];
console.log(Portaal);

api.get( {
    action: 'parse',
    text: textToParse,
    titles: mw.config.get('wgTitle'),
    contentmodel: 'wikitext',
} ).done( function ( query ) {
    console.log(query.parse.text['*']);
    document.getElementById('mw-content-text').outerHTML += query.parse.text['*'];
});
*/
var api; 
var catsOnPage = mw.config.get('wgCategories');
var TVBportalen = [];

function TVBstartPT() {
    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) {
    		document.getElementById('TVBdemo').innerHTML = 'TVB: ';
    		for (var y = 0; y < TVBportalen.length; y++) { 
    			document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
    		}
    	}
    }, 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;
            }
        }
    });
}
document.getElementById('mw-content-text').outerHTML += '<hr style="clear:both;"><div id="TVBdemo"><button onclick="TVBstartPT();">TVB</button></div>';
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Rots61/JS-TVB.js&oldid=783633"