User:Bargioni/StatementsSitelinksCountsSBN.js: Difference between revisions
Content deleted Content added
No edit summary |
mNo edit summary |
||
Line 78: | Line 78: | ||
if (v.st.value < 5) |
if (v.st.value < 5) |
||
colour = " style='color: " + (v.st.value === "0" ? "#d33" : "chocolate") + "'"; |
colour = " style='color: " + (v.st.value === "0" ? "#d33" : "chocolate") + "'"; |
||
$("a[title='" + v.page.value.replace(/(['"])/g, "\\\$1") + "']") |
var au = $("a[title='" + v.page.value.replace(/(['"])/g, "\\\$1") + "']") |
||
.after(" <small>(<a href='https://www.wikidata.org/wiki/" + qid + "'" + colour + ">" |
.after(" <small>(<a href='https://www.wikidata.org/wiki/" + qid + "'" + colour + ">" |
||
+ v.si.value + " sit.; " + v.st.value + " sta.; " + v.idn.value + " IDs; " |
+ v.si.value + " sit.; " + v.st.value + " sta.; " + v.idn.value + " IDs; " |
||
+ v.viaf0.value + "; " + v.sbn0.value + "</a>)</small>"); |
+ v.viaf0.value + "; " + v.sbn0.value + "</a>)</small>"); |
||
console.log(au); // test |
|||
}); |
}); |
||
$('.con_viaf').css({'color':'green','font-weight':'bold'}); |
$('.con_viaf').css({'color':'green','font-weight':'bold'}); |
Revision as of 14:31, 25 June 2023
/* This script runs on category pages and shows the number of statements and
sitelinks that each page in the category has in its Wikidata items.
Links for pages with fewer than 5 statements are highlighted to make it
easier to see which pages' items are most likely to need improvement.
To use it, add the following line to your global.js on Meta-Wiki if you want
it to work on all wikis, or to your common.js on a specific wiki if you only
want to use it on that wiki:
mw.loader.load("//meta.wikimedia.org/w/index.php?title=User:Epìdosis/StatementsSitelinksCountsSBN.js&action=raw&ctype=text/javascript");
License: CC0
Initially forked from [[User:Nikki/StatementCounts.js]]; see also [[User:Epìdosis/StatementsSitelinksCountsSBN.js]]
*/
$(document).ready(function () {
(function () {
if (mw.config.get("wgCanonicalNamespace") !== "Category")
return;
var lang = mw.config.get("wgContentLanguage");
var domain = mw.config.get("wgServerName");
var pages = [];
$(".ns-14 #mw-pages li a, .ns-14 #mw-subcategories li a").each(function (i, v) {
var page = '"' + v.title.replace(/"/g, '\\\"') + '"@' + lang;
pages.push(page);
});
if (!pages.length)
return;
function buttons(action) {
if(action == 'create') {
$('#mw-pages h2').append(' <button id="toggle_completi">Nascondi/mostra completi</button>');
// $('#mw-pages h2').append(' <button id="toggle_senza_SBN">Nascondi/mostra se senza SBN</button>');
// $('#mw-pages h2').append(' <button id="toggle_senza_VIAF">Nascondi/mostra se senza VIAF</button>');
}
if (action == 'activate') {
$('#toggle_completi').click(function(){
// $('.con_viaf').add('.con_sbn').parent().parent().toggle();
var ss = $('small a span.con_sbn');
var with_both = ss.filter(function(i,e){if($(e).parent().find('span.con_viaf').length) return true});
$(with_both).parent().parent().toggle();
});
$('#toggle_senza_SBN').click(function(){
$('.con_viaf').add('.con_sbn').add('.senza_viaf').add('.senza_sbn').css('display','inline');
$('.senza_sbn').parent().parent().toggle();
});
$('#toggle_senza_VIAF').click(function(){
$('.con_viaf').add('.con_sbn').add('.senza_viaf').add('.senza_sbn').css('display','inline');
$('.senza_viaf').parent().parent().toggle();
});
}
}
buttons('create');
var query = "\
select ?page ?sitelink ?item\
?si ?idn ?st (IF(BOUND(?viaf),\"<span class='con_viaf'>+VIAF</span>\",\"<span class='senza_viaf'>-VIAF</span>\") AS ?viaf0) (IF(BOUND(?sbn),\"<span class='con_sbn'>+SBN</span>\",\"<span class='senza_sbn'>-SBN</span>\") AS ?sbn0) {\
values ?page { " + pages.join(" ") + " }\
?sitelink schema:name ?page;\
schema:isPartOf <https://" + domain + "/>;\
schema:about ?item.\
?item wikibase:sitelinks ?si;\
wikibase:identifiers ?idn;\
wikibase:statements ?st.\
OPTIONAL {?item wdt:P214 ?viaf}.\
OPTIONAL {?item wdt:P396 ?sbn}.\
}";
$.post("https://query.wikidata.org/sparql?format=json", { query: query }, function (data) {
$.each(data.results.bindings, function (i, v) {
var qid = v.item.value.replace(/.*\//, "");
var colour = "";
if (v.si.value === "1") v.si.value.replace(/1/, "🌼");
if (v.st.value < 5)
colour = " style='color: " + (v.st.value === "0" ? "#d33" : "chocolate") + "'";
var au = $("a[title='" + v.page.value.replace(/(['"])/g, "\\\$1") + "']")
.after(" <small>(<a href='https://www.wikidata.org/wiki/" + qid + "'" + colour + ">"
+ v.si.value + " sit.; " + v.st.value + " sta.; " + v.idn.value + " IDs; "
+ v.viaf0.value + "; " + v.sbn0.value + "</a>)</small>");
console.log(au); // test
});
$('.con_viaf').css({'color':'green','font-weight':'bold'});
$('.senza_viaf').css({'color':'red','font-weight':'bold'});
$('.con_sbn').css({'color':'green','font-weight':'bold'});
$('.senza_sbn').css({'color':'red','font-weight':'bold'});
$('.mw-category-group li a').attr('target','_new'); // Wikipedia links open in new page
$('small>a').attr('target','_new'); // Wikidata links open in new page
buttons('activate');
});
})();
});