Last active
August 25, 2025 03:27
-
-
Save wragge/40f66af72c400b2563f95bda60e713dd to your computer and use it in GitHub Desktop.
Add links from Wikidata to entries in the Australian Dictionary of Biography
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Add Wikidata links to ADB | |
// @namespace wraggelabs.com/add-wikidata-links-to-adb | |
// @match https://adb.anu.edu.au/biography/* | |
// @version 1.2 | |
// @author Tim Sherratt | |
// @description 25/08/2025, 10:39:27 | |
// @grant GM.xmlHttpRequest | |
// @connect query.wikidata.org | |
// ==/UserScript== | |
function addWikidataLinks(query) { | |
// Query the Wikidata SPARQL service | |
const endpointUrl = 'https://query.wikidata.org/sparql'; | |
const fullUrl = endpointUrl + '?query=' + encodeURIComponent(query); | |
const headers = { 'Accept': 'application/sparql-results+json' }; | |
GM.xmlHttpRequest({ | |
method: 'GET', | |
url: fullUrl, | |
headers: headers, | |
onload: function(response) { | |
const data = JSON.parse(response.responseText); | |
const bindings = data.results.bindings; | |
if (bindings.length > 0) { | |
// Add a new heading to the life summary | |
let lifeSummary = document.querySelector("div.lifeSummary"); | |
let heading = document.createElement("h5"); | |
heading.textContent = "Related links from WikiData"; | |
lifeSummary.appendChild(heading); | |
// Create a list to contain the links | |
let linkList = document.createElement("ul"); | |
for (let link of bindings) { | |
// Add the links to the list (ignoring the ADB link) | |
if (link.propertyLabel.value != "Australian Dictionary of Biography ID") { | |
let linkItem = document.createElement("li"); | |
linkItem.innerHTML = '<a href="' + link.url.value + '">' + link.propertyLabel.value.replace(" ID", "") + '</a>'; | |
linkList.appendChild(linkItem); | |
} | |
} | |
// Add the list of links to the life summary | |
lifeSummary.appendChild(linkList); | |
} | |
} | |
}); | |
} | |
// Get the ADB id from the url | |
const adb_id = window.location.href.match(/\/biography\/([a-zA-Z0-9\-]+)\/?/)[1]; | |
// This query gets all the Australian external identifiers that are linked to the person who has this ADB id. | |
const query = `SELECT DISTINCT ?property ?propertyLabel ?value ?url where { | |
?item p:P1907 ?statement. | |
?statement (ps:P1907) "${adb_id}". | |
?item ?wdt ?value. | |
?property wikibase:directClaim ?wdt; | |
wikibase:propertyType wikibase:ExternalId; | |
wdt:P17 wd:Q408. | |
OPTIONAL { ?property wdt:P1630 ?formatter } | |
BIND(uri(REPLACE(?formatter,"\\\\\$1",?value)) as ?url) | |
SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO LANGUAGE],en" .} | |
}`; | |
addWikidataLinks(query); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This userscript enriches entries in the Australian Dictionary of Biography by adding links to other biographical resources obtained from WikiData.
A section from the record for Margaret Baskerville showing the results of the userscript.
It makes use of WikiData's SPARQL Query Service to request details of any Australian external identifiers attached to a person's record. Not everyone in the ADB is currently represented in WikiData, so some entries might have no added links.
Installation