Line 14: |
Line 14: |
| } | | } |
| | | |
− | function isDataController() { | + | 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'; |
| + | |
| + | // 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)) { |
| + | generateGDPRLink(pageID); |
| + | } |
| + | }); |
| + | |
| + | function isDataController(entity) { |
| let foundThatThisIsAnInstanceOfDataController = false; | | let foundThatThisIsAnInstanceOfDataController = false; |
− | if ( typeof mw.config.values.wbEntity != "undefined" ) // if we are on the page of a loaded entity | + | |
| + | if ( typeof entity != "undefined" ) // if we are on the page of a loaded entity |
| { | | { |
− | let obj = JSON.parse ( mw.config.values.wbEntity );
| + | if ( typeof check( entity, INSTANCE_OF_PROPERTY ) != "undefined" ) // if the entity has any "instance of" claim |
− | if ( typeof check( obj, INSTANCE_OF_PROPERTY ) != "undefined" ) // if the entity has any "instance of" claim
| + | { |
| + | let claims = dive( entity, INSTANCE_OF_PROPERTY ); // get the claims which use the "instance of" property |
| + | if (claims.some(claimUsesDataControllerAsItsObject)) |
| { | | { |
− | let instance_of_claims = dive( obj, INSTANCE_OF_PROPERTY );
| + | foundThatThisIsAnInstanceOfDataController = true; |
− | if (instance_of_claims.some(dive( instance_of_claims[i] , 'mainsnak.datavalue.value')['numeric-id'] === DATA_CONTROLLER_ITEM_ID))
| |
− | {
| |
− | foundThatThisIsAnInstanceOfDataController = true;
| |
− | }
| |
| } | | } |
| + | } |
| } | | } |
| return foundThatThisIsAnInstanceOfDataController; | | return foundThatThisIsAnInstanceOfDataController; |
| } | | } |
| | | |
− | // get the ID of the current page
| + | function dive(array, read){ |
− | var pageID = document.querySelector('.wikibase-title .wikibase-title-id').innerText.replace( /[()]/g, '' );
| + | return read.split('.').reduce(indexinterpolate, array); |
| + | } |
| | | |
− | if (isDataController()) {
| + | function check(array, read){ |
− | generateGDPRLink(pageID);
| + | return read.split('.').reduce(indexcheck, array); |
| } | | } |