Gebruiker:Rots61/Gadget-LinkTeller.js

Uit Wikikids
< Gebruiker:Rots61
Versie door Rots61 (overleg | bijdragen) op 7 jan 2023 om 16:10 (geen spaties meer)
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
/**
 * LinkTeller.JS
 * Features: [[WikiKids:LinkTeller]]
 * Made by [[User:Rots61]] 
**/

var api;
var portaal = 0;
var portaal2 = "";

function startAP() {
api = new mw.Api();
// Get the number of articles 
getPageCountAP().then( function (ECarticlecount) { // The new page count we got will be passed here.
    document.getElementById("ooui-php-9").innerHTML += 
        "<p>Er zijn " + ECarticlecount + " pagina's die aan deze voorwaarden voldoen.</p>"; 
} );
}

function getPageCountAP( apiContinue ) {    
    return api.get( {
        action: "query",
        list: "allpages",
        apfrom: urlfrom ? urlfrom : undefined,
        aplimit: "5000",
        apto: urlto ? urlto : undefined,
        apnamespace: urlns ? urlns : undefined,
        apfilterredir: urlredirect ? "nonredirects" : "all",
        apcontinue: apiContinue ? apiContinue.apcontinue : undefined
    } ).then( function (data) {
        if ( data.continue ) {
            return getPageCountAP( data.continue )
                .then( function ( addedLength ) { 
                    return addedLength + data.query.allpages.length;
                } );
        } else {
            return data.query.allpages.length;
        }
    } );
}

if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "AllePaginas" || mw.config.get('wgTitle') === "Allepaginas")
) {
	var urlfrom = mw.util.getParamValue( 'from' );
	var urlto = mw.util.getParamValue( 'to' );
	var urlns = mw.util.getParamValue( 'namespace' );
	var urlredirect = mw.util.getParamValue( 'hideredirects' );
	$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( startAP());
}


function showLT() {
	document.getElementById("mw-panel").innerHTML +='&nbsp;&nbsp;&nbsp;Gadget:LinkTeller<br>&nbsp;&nbsp;&nbsp;<button onclick="startLT()">Aantal links:</button> <span id="Gadget-LinkTeller-Links"></span>'
	+ '<br>&nbsp;&nbsp;&nbsp;<button onclick="startPT()">Portalen:</button> <span id="Gadget-LinkTeller-Portalen" style="font-size: x-small;"></span>';

}

function startLT() {
	 api = new mw.Api();
	 // Get the number of links
	 var temp;
	 getPageCountLT().then( function (linkcount) { // The page count we got will be passed here.
		document.getElementById("Gadget-LinkTeller-Links").innerHTML = linkcount; } );
}

function getPageCountLT() {    
    return api.get( {
        action: "query",
        prop: "links",
        titles: mw.config.get('wgPageName'), 
        pllimit: "5000",
    } ).then( function (data) {
            temp = data.query.pages;
            temp = temp[mw.config.get('wgArticleId')];
            if (typeof temp.links !== 'undefined') {
            	return temp.links.length;
            } else { 
            	return 0;
            }
    } );
}


function startPT() {
	 api = new mw.Api();
	 // Get the number of links
	 var temp;
	 getPageCountPT().then( function (linkcount) { // The page count we got will be passed here.
		document.getElementById("Gadget-LinkTeller-Portalen").innerHTML = linkcount + portaal2 ; } );
}

function getPageCountPT() {    
    return api.get( {
        action: "query",
        prop: "linkshere",
        titles: mw.config.get('wgPageName'), 
        lhlimit: "5000",
    } ).then( function (data) {
            temp = data.query.pages;
            temp = temp[mw.config.get('wgArticleId')];
            temp = temp.linkshere;
            if (typeof temp === 'undefined') {
            	return 0;
            } else {
            	var tempgetal = 0;
            	while (typeof temp[tempgetal] !== 'undefined'){
            		if ( temp[tempgetal]["title"].startsWith("Portaal:") ) {
            			portaal += 1;
            			portaal2 += '<br><a href="https://wikikids.nl/' + temp[tempgetal]["title"] + '">' + temp[tempgetal]["title"] + '</a>'; 
            		}
            		tempgetal += 1;
            	}
            	return portaal;
            }
    } );
}


if (mw.config.get('wgArticleId') > 1 ) { 
	$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( showLT);
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Rots61/Gadget-LinkTeller.js&oldid=758676"