Difference between revisions of "User:Alexbfree/Code:GDPRMailAccess.js"
Jump to navigation
Jump to search
Line 27: | Line 27: | ||
console.log(pageID); | console.log(pageID); | ||
− | if (isDataController()) { | + | if (isDataController(entity)) { |
console.log('is dc'); | console.log('is dc'); | ||
generateGDPRLink(pageID); | generateGDPRLink(pageID); | ||
Line 33: | Line 33: | ||
}); | }); | ||
− | function isDataController() { | + | function isDataController(entity) { |
let foundThatThisIsAnInstanceOfDataController = false; | let foundThatThisIsAnInstanceOfDataController = false; | ||
console.log('here1'); | console.log('here1'); | ||
Line 40: | Line 40: | ||
{ | { | ||
console.log( "entity is defined" ); | console.log( "entity is defined" ); | ||
− | |||
console.log('here2'); | console.log('here2'); | ||
− | console.dir( | + | console.dir(entity); |
− | + | if ( typeof check( entity, INSTANCE_OF_PROPERTY ) != "undefined" ) // if the entity has any "instance of" claim | |
− | if ( typeof check( | ||
{ | { | ||
console.log('here3'); | console.log('here3'); | ||
− | let claims = dive( | + | let claims = dive( entity, INSTANCE_OF_PROPERTY ); // get the claims which use the "instance of" property |
if (claims.some(claimUsesDataControllerAsItsObject)) | if (claims.some(claimUsesDataControllerAsItsObject)) | ||
{ | { |
Revision as of 14:45, 24 February 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 claimUsesDataControllerAsItsObject(claim) {
return dive( claim , 'mainsnak.datavalue.value')['numeric-id'] === DATA_CONTROLLER_ITEM_ID;
}
mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
'use strict';
console.log( entity );
// get the ID of the current page
var pageID = document.querySelector('.wikibase-title .wikibase-title-id').innerText.replace( /[()]/g, '' );
console.log(pageID);
if (isDataController(entity)) {
console.log('is dc');
generateGDPRLink(pageID);
}
});
function isDataController(entity) {
let foundThatThisIsAnInstanceOfDataController = false;
console.log('here1');
if ( typeof entity != "undefined" ) // if we are on the page of a loaded entity
{
console.log( "entity is defined" );
console.log('here2');
console.dir(entity);
if ( typeof check( entity, INSTANCE_OF_PROPERTY ) != "undefined" ) // if the entity has any "instance of" claim
{
console.log('here3');
let claims = dive( entity, INSTANCE_OF_PROPERTY ); // get the claims which use the "instance of" property
if (claims.some(claimUsesDataControllerAsItsObject))
{
console.log('here4');
foundThatThisIsAnInstanceOfDataController = true;
}
}
}
return foundThatThisIsAnInstanceOfDataController;
}