Gebruiker:Rots61/Gadget-LinkTeller.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(geen spaties meer) |
|||
Regel 10: | Regel 10: | ||
function startAP() { | function startAP() { | ||
− | api = new mw.Api(); | + | api = new mw.Api(); |
− | // Get the number of articles | + | // Get the number of articles |
− | getPageCountAP().then( function (ECarticlecount) { // The new page count we got will be passed here. | + | 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 ) { | + | function getPageCountAP(apiContinue) { |
− | return api.get( { | + | return api.get({ |
action: "query", | action: "query", | ||
list: "allpages", | list: "allpages", | ||
Regel 28: | Regel 28: | ||
apfilterredir: urlredirect ? "nonredirects" : "all", | apfilterredir: urlredirect ? "nonredirects" : "all", | ||
apcontinue: apiContinue ? apiContinue.apcontinue : undefined | apcontinue: apiContinue ? apiContinue.apcontinue : undefined | ||
− | } ).then( function (data) { | + | }).then(function (data) { |
− | if ( data.continue ) { | + | if (data.continue) { |
− | return getPageCountAP( data.continue ) | + | return getPageCountAP(data.continue) |
− | .then( function ( addedLength ) { | + | .then(function (addedLength) { |
return addedLength + data.query.allpages.length; | return addedLength + data.query.allpages.length; | ||
− | } ); | + | }); |
} else { | } else { | ||
return data.query.allpages.length; | return data.query.allpages.length; | ||
} | } | ||
− | } ); | + | }); |
} | } | ||
− | 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 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() { | 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: 20px; margin-bottom: 5px;"> | ||
+ | <ul> | ||
+ | <li> | ||
+ | <button onclick="startLT()">Aantal | ||
+ | links</button> | ||
+ | </li> | ||
+ | <li> | ||
+ | <button onclick="startPT()">Portalen</button> | ||
+ | </li> | ||
+ | </ul> | ||
+ | <ul> | ||
+ | <li> | ||
+ | <button disabled style="background: #89242B; color: white;" id="Gadget-LinkTeller-Links">-</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() { | 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() { | + | function getPageCountLT() { |
− | return api.get( { | + | return api.get({ |
action: "query", | action: "query", | ||
prop: "links", | prop: "links", | ||
− | titles: mw.config.get('wgPageName'), | + | titles: mw.config.get('wgPageName'), |
pllimit: "5000", | pllimit: "5000", | ||
− | } ).then( function (data) { | + | }).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() { | 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; | ||
+ | }); | ||
} | } | ||
− | function getPageCountPT() { | + | function getPageCountPT() { |
− | return api.get( { | + | return api.get({ |
action: "query", | action: "query", | ||
prop: "linkshere", | prop: "linkshere", | ||
− | titles: mw.config.get('wgPageName'), | + | titles: mw.config.get('wgPageName'), |
lhlimit: "5000", | lhlimit: "5000", | ||
− | } ).then( function (data) { | + | }).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('wgArticleId') > 1 ) { | + | if (mw.config.get('wgArticleId') > 1) { |
− | + | $.when(mw.loader.using('mediawiki.util'), $.ready).then(showLT); | |
} | } |
Versie van 12 jan 2023 20:20
/**
* 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 += `<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: 20px; margin-bottom: 5px;">
<ul>
<li>
<button onclick="startLT()">Aantal
links</button>
</li>
<li>
<button onclick="startPT()">Portalen</button>
</li>
</ul>
<ul>
<li>
<button disabled style="background: #89242B; color: white;" id="Gadget-LinkTeller-Links">-</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 (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;
document.getElementById("Gadget-LinkTeller-PortalenLijst").innerHTML = 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 += '<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);
}