Gebruiker:Rots61/Gadget-LinkTeller.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(Nieuwe pagina aangemaakt met '→‎* * LinkTeller.JS * Features: [[WikiKids:LinkTeller]] * Made by [[User:Rots61]] *: // Create variables function startAP() { // Get the number of articles...')
 
Regel 1: Regel 1:
 +
/**
 +
* CountPages.JS
 +
*
 +
* Made by [[User:Rots61]]
 +
**/
 
/**
 
/**
 
  * LinkTeller.JS
 
  * LinkTeller.JS
Regel 6: Regel 11:
  
 
// Create variables
 
// Create variables
 +
var api = new mw.Api();
  
 
function startAP() {
 
function startAP() {
  
 
// Get the number of articles  
 
// Get the number of articles  
console.log("b");
+
getPageCountAP().then( function (ECarticlecount) { // The new page count we got will be passed here.
getPageCount().then( function (ECarticlecount) { // The new page count we got will be passed here.
 
 
     document.getElementById("ooui-php-9").innerHTML +=  
 
     document.getElementById("ooui-php-9").innerHTML +=  
 
         "<p>Er zijn " + ECarticlecount + " pagina's die aan deze voorwaarden voldoen.</p>";  
 
         "<p>Er zijn " + ECarticlecount + " pagina's die aan deze voorwaarden voldoen.</p>";  
Regel 17: Regel 22:
 
}
 
}
  
function getPageCount( apiContinue ) {     
+
function getPageCountAP( apiContinue ) {     
console.log("d");
 
 
     return api.get( {
 
     return api.get( {
 
         action: "query",
 
         action: "query",
Regel 30: Regel 34:
 
     } ).then( function (data) {
 
     } ).then( function (data) {
 
         if ( data.continue ) {
 
         if ( data.continue ) {
             return getPageCount( data.continue )
+
             return getPageCountAP( data.continue )
 
                 .then( function ( addedLength ) {  
 
                 .then( function ( addedLength ) {  
 
                     return addedLength + data.query.allpages.length;
 
                     return addedLength + data.query.allpages.length;
Regel 42: Regel 46:
 
if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "AllePaginas" || mw.config.get('wgTitle') === "Allepaginas")
 
if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "AllePaginas" || mw.config.get('wgTitle') === "Allepaginas")
 
) {
 
) {
var api = new mw.Api();
 
 
var queryString = window.location.search;
 
var queryString = window.location.search;
 
var urlParams = new URLSearchParams(queryString);
 
var urlParams = new URLSearchParams(queryString);
Regel 49: Regel 52:
 
var urlns = urlParams.get('namespace');
 
var urlns = urlParams.get('namespace');
 
var urlredirect = urlParams.get('hideredirects');
 
var urlredirect = urlParams.get('hideredirects');
console.log("a");
 
 
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( startAP());
 
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( startAP());
 
}
 
}
console.log("z");
+
 
 +
 
 +
function showLT() {
 +
mw.util.$content.append( '<br><button onclick="startLT()">Aantal links: </button> <span id="Gadget-LinkTeller"></span>' );
 +
}
 +
 
 +
function startLT() {
 +
// Get the number of links
 +
var temp;
 +
getPageCountLT().then( function (linkcount) { // The page count we got will be passed here.
 +
    document.getElementById("Gadget-LinkTeller").innerHTML = linkcount; } );
 +
}
 +
 
 +
function getPageCountLT( apiContinue ) {   
 +
    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;
 +
            }
 +
    } );
 +
}
 +
 
 +
if (mw.config.get('wgArticleId') > 1 ) {
 +
$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( setTimeout(showLT, 1000));
 +
}

Versie van 10 dec 2022 00:04

/**
 * CountPages.JS
 *
 * Made by [[User:Rots61]] 
**/
/**
 * LinkTeller.JS
 * Features: [[WikiKids:LinkTeller]]
 * Made by [[User:Rots61]] 
**/

// Create variables
var api = new mw.Api();

function startAP() {

// 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 queryString = window.location.search;
var urlParams = new URLSearchParams(queryString);
var urlfrom = urlParams.get('from');
var urlto = urlParams.get('to');
var urlns = urlParams.get('namespace');
var urlredirect = urlParams.get('hideredirects');
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( startAP());
}


function showLT() {
	mw.util.$content.append( '<br><button onclick="startLT()">Aantal links: </button> <span id="Gadget-LinkTeller"></span>' );
}

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

function getPageCountLT( apiContinue ) {    
    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;
            }
    } );
}

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