Difference between revisions of "User:Alexbfree/Code:GDPRMailAccess.js"
Jump to navigation
Jump to search
Line 15: | Line 15: | ||
function isDataController() { | function isDataController() { | ||
− | let | + | let foundThatThisIsAnInstanceOfDataController = false; |
if ( typeof mw.config.values.wbEntity != "undefined" ) // if we are on the page of a loaded entity | if ( typeof mw.config.values.wbEntity != "undefined" ) // if we are on the page of a loaded entity | ||
{ | { | ||
Line 29: | Line 29: | ||
console.log('found data controller'); | console.log('found data controller'); | ||
// it's a data controller | // it's a data controller | ||
− | + | foundThatThisIsAnInstanceOfDataController = true; break; | |
} | } | ||
} | } | ||
} | } | ||
} | } | ||
− | return | + | return foundThatThisIsAnInstanceOfDataController; |
} | } | ||
Revision as of 16:19, 27 January 2020
const DATA_CONTROLLER_ITEM_ID = 96; // because Q96 is data controller"
const INSTANCE_OF_PROPERTY = 'claims.P3'; // because P3 is the property "instance of"
function generateGDPRLink(dataControllerItemID) {
// make an API call to expand the letter template, using this item.
let api = new mw.Api();
api.get( {
action: 'expandtemplates',
text: '{{User:Alexbfree/Template:DataControllerMenu|qID='+dataControllerItemID+'}}'
} ).done( function ( data ) {
var expanded = $(data.expandtemplates["*"])
mw.notify( expanded , { autoHide: false } ); // pop up the notification with the link
} );
}
function isDataController() {
let foundThatThisIsAnInstanceOfDataController = false;
if ( typeof mw.config.values.wbEntity != "undefined" ) // if we are on the page of a loaded entity
{
let obj = JSON.parse ( mw.config.values.wbEntity );
if ( typeof check( obj, INSTANCE_OF_PROPERTY ) != "undefined" ) // if the entity has any "instance of" claim
{
let instance_of_claims = dive( obj, INSTANCE_OF_PROPERTY );
for( var i = 0; i < instance_of_claims.length; i++ ) // retrieve each 'instance of' claim to check it
{
let the_thing_it_is_an_instance_of = dive( instance_of_claims[i] , 'mainsnak.datavalue.value');
if (the_thing_it_is_an_instance_of['numeric-id'] === DATA_CONTROLLER_ITEM_ID )
{
console.log('found data controller');
// it's a data controller
foundThatThisIsAnInstanceOfDataController = true; break;
}
}
}
}
return foundThatThisIsAnInstanceOfDataController;
}
// get the ID of the current page
var pageID = document.querySelector('.wikibase-title .wikibase-title-id').innerText.replace( /[()]/g, '' );
if (isDataController()) {
generateGDPRLink(pageID);
}