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

Uit Wikikids
Naar navigatie springen Naar zoeken springen
 
(5 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 50: Regel 50:
 
</h3>
 
</h3>
 
<div class="body vector-menu-content" style="border-bottom: 1px solid #89242B">
 
<div class="body vector-menu-content" style="border-bottom: 1px solid #89242B">
<div style="display: flex; flex-direction: row; gap: 10px; margin-bottom: 5px;">
+
<div style="display: flex; flex-direction: row; gap: 5px; margin-bottom: 5px;">
 
<ul>
 
<ul>
 
<li>
 
<li>
<button onclick="startLT()">Aantal
+
<button id="linkbuttonLT" onclick="startLT()">Links</button>
links</button>
 
 
</li>
 
</li>
 
<li>
 
<li>
<button onclick="startPT()">Portalen</button>
+
<button disabled style="background: #89242B; color: white;" id="Gadget-LinkTeller-Links">-</button>
 
</li>
 
</li>
 
</ul>
 
</ul>
 
<ul>
 
<ul>
 
<li>
 
<li>
<button disabled style="background: #89242B; color: white;" id="Gadget-LinkTeller-Links">-</button>
+
<button id="portalenbuttonLT" onclick="startPT()">Portalen</button>
 
</li>
 
</li>
 
<li>
 
<li>
Regel 81: Regel 80:
 
// Get the number of links
 
// Get the number of links
 
var temp;
 
var temp;
getPageCountLT().then(function (linkcount) { // The page count we got will be passed here.
+
getPageCountLT().then(function () { // The page count we got will be passed here.
document.getElementById("Gadget-LinkTeller-Links").innerHTML = linkcount;
 
 
for (var x = 0; x < alltLT.length; x++) {
 
for (var x = 0; x < alltLT.length; x++) {
 
for (const y in alltLT[x]) {
 
for (const y in alltLT[x]) {
Regel 92: Regel 90:
 
}
 
}
 
}
 
}
document.getElementById("Gadget-LinkTeller-Links").innerHTML = linkcount + '(' + bestaatwelLT + ',' + bestaatnietLT + ')';
+
document.getElementById("Gadget-LinkTeller-Links").innerHTML = (bestaatwelLT + bestaatnietLT) + ' <br>(' + bestaatwelLT + ', ' + bestaatnietLT + ')';
  +
bestaatnietLT = 0;
  +
bestaatwelLT = 0;
 
});
 
});
 
}
 
}
Regel 101: Regel 101:
 
action: "query",
 
action: "query",
 
prop: "revisions",
 
prop: "revisions",
titles: XYZ,
+
titles: mw.config.get('wgPageName'),
gplcontinue: contin ? contin.gplcontinue : undefined
+
gplcontinue: contin ? contin.gplcontinue : undefined
 
}).then(function (data) {
 
}).then(function (data) {
 
if (data.continue) {
 
if (data.continue) {
 
return getPageCountLT(data.continue).then(function () {
 
return getPageCountLT(data.continue).then(function () {
allt.push(data.query.pages);
+
alltLT.push(data.query.pages);
 
});
 
});
 
} else {
 
} else {
allt.push(data.query.pages);
+
alltLT.push(data.query.pages);
 
}
 
}
 
});
 
});

Huidige versie van 6 jul 2023 om 14:06

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

var api;
var portaal = 0;
var portaal2 = "";
var bestaatnietLT = 0;
var bestaatwelLT = 0;
var alltLT = [];
function startAP() {
    api = new mw.Api();
    // Get the number of articles 
    document.getElementById("ooui-php-9").innerHTML += "<p id='lt-count'>Laden van aantallen...</p>";
    getPageCountAP().then(function (ECarticlecount) { // The new page count we got will be passed here.
        document.getElementById("lt-count").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;
        }
    });
}

function showLT() {
    document.getElementById("mw-panel").innerHTML += `<nav style="background-color: #89242B" class="vector-menu vector-menu-portal portal" aria-labelledby="p-lt-label"
    role="navigation">
    <h3 id="p-lt-label">
        <span>LinkTeller</span>
    </h3>
    <div class="body vector-menu-content" style="border-bottom: 1px solid #89242B">
        <div style="display: flex; flex-direction: row; gap: 5px; margin-bottom: 5px;">
            <ul>
                <li>
                    <button id="linkbuttonLT" onclick="startLT()">Links</button>
                </li>
                <li>
                    <button disabled style="background: #89242B; color: white;" id="Gadget-LinkTeller-Links">-</button>
                </li>
            </ul>
            <ul>
                <li>
                    <button id="portalenbuttonLT" onclick="startPT()">Portalen</button>
                </li>
                <li>
                    <button disabled style="background: #89242B; color: white;"
                        id="Gadget-LinkTeller-Portalen">-</button>
                </li>
            </ul>
        </div>
        <div id="Gadget-LinkTeller-PortalenLijst"
            style='display: flex; flex-direction: column; font-size: 8pt; margin-bottom: 5px;'>
        </div>
    </div>
</nav>`;
}

function startLT() {
    api = new mw.Api();
    // Get the number of links
    var temp;
    getPageCountLT().then(function () { // The page count we got will be passed here.
		for (var x = 0; x < alltLT.length; x++) {
		    for (const y in alltLT[x]) {
		        if (alltLT[x][y].pageid === undefined) {
		            bestaatnietLT +=1;
		        } else {
		            bestaatwelLT +=1;
		        }
		    }
		}
		document.getElementById("Gadget-LinkTeller-Links").innerHTML = (bestaatwelLT + bestaatnietLT) + ' <br>(' + bestaatwelLT + ', ' + bestaatnietLT + ')';
		bestaatnietLT = 0;
		bestaatwelLT = 0;
    });
}

function getPageCountLT(contin) {
    return api.get({
        generator: "links",
        action: "query",
        prop: "revisions",
        titles: mw.config.get('wgPageName'),
        gplcontinue: contin ? contin.gplcontinue : undefined
    }).then(function (data) {
		if (data.continue) {
            return getPageCountLT(data.continue).then(function () {
                	alltLT.push(data.query.pages);
                });
        } else {
            alltLT.push(data.query.pages);
        }
    });
}

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;
        document.getElementById("Gadget-LinkTeller-PortalenLijst").innerHTML = portaal2;
        portaal2 = "";
        portaal = 0;
    });
}

function getPageCountPT() {
    return api.get({
        action: "query",
        prop: "linkshere",
        titles: mw.config.get('wgPageName'),
        lhlimit: "5000",
        lhnamespace: '100',
    }).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 += '<a href="https://wikikids.nl/' + temp[tempgetal]["title"] + '">' + temp[tempgetal]["title"] + '</a>';
                }
                tempgetal += 1;
            }
            return portaal;
        }
    });
}

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());
} else 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=799817"