User:Aahmeti/recool-wd.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/**
* RelativeCompleteness-WD: RElative COmpleteness INdicator for WikiData
*
* Developers : Albin Ahmeti (albin.ahmeti@gmail.com), Simon Razniewski (razniewski@inf.unibz.it)
* Inspired by : COOL-WD: COmpleteness toOL for WikiData (Fariz Darari)
*/
( function( mw, $ ) {
'use strict';
console.log('recool-wd 0.0.3 loaded');
/**
* Check if we're viewing an item
*/
var entityID = mw.config.get( 'wbEntityId' );
if ( !entityID )
{
return;
}
/**
* holds the DOM input element for the label
*/
var labelsParent;
function init()
{
// Element into which to add the missing attributes
labelsParent = $('#wb-item-' + entityID + ' div.wikibase-entitytermsview-heading');
if (labelsParent.length < 1)
{
return;
}
var labelsDOM = $('<div>Most relevant missing predicates, based on the attributes that people of same occupation have:</div>');
var labelsUL = $('<ul></ul>');
$.getJSON( 'https://tadaqua.inf.unibz.it/api/getmissingattributes.php?callback=?', 'subject=' + entityID,
function ( result )
{
var complete = result.completeness;
if (complete === "1") {
$('div.mw-indicators').prepend('<img src="https://tadaqua.inf.unibz.it/progressbar/1.png" alt="Entity is highly complete" width="20" height="38">');
}
if (complete === "2") {
$('div.mw-indicators').prepend('<img src="https://tadaqua.inf.unibz.it/progressbar/2.png" alt="Entity is quite complete" width="20" height="38">');
}
if (complete === "3") {
$('div.mw-indicators').prepend('<img src="https://tadaqua.inf.unibz.it/progressbar/3.png" alt="Entity is half complete" width="20" height="38">');
}
if (complete === "4") {
$('div.mw-indicators').prepend('<img src="https://tadaqua.inf.unibz.it/progressbar/4.png" alt="Entity is quite incomplete" width="20" height="38">');
}
if (complete === "5") {
$('div.mw-indicators').prepend('<img src="https://tadaqua.inf.unibz.it/progressbar/5.png" alt="Entity is highly incomplete" width="20" height="38">');
}
for (var i=0; i< result.entities.length; i++)
{
var insertElem = '<li> ' +
'<label><a href="https://www.wikidata.org/wiki/Property:'+ result.entities[i].entity + '">' +
result.entities[i].entity + '</a>' +
' ' + result.entities[i].label + '' +
'</label></li>';
labelsUL.append(insertElem);
labelsDOM.append(labelsUL);
}
//labelsParent.append(imageDOM);
labelsParent.append(labelsDOM);
});
}
$( function () {
mw.hook( 'wikipage.content' ).add( init );
});
} ( mediaWiki, jQuery ) );