User:Mringgaard/common.js

var url = window.location.origin + "/w/api.php?action=query&prop=pageprops&format=json&titles=$URL"; var headingElem = document.getElementById('firstHeading'); url = url.replace("$URL", encodeURIComponent(headingElem.innerHTML));

var xhr = new XMLHttpRequest; xhr.open("GET", url, false); xhr.send; var response = JSON.parse(xhr.response);

var key = Object.getOwnPropertyNames(response.query.pages)[0];

var wikidata_id; try { wikidata_id = response.query.pages[key].pageprops.wikibase_item; } catch (error) { console.log("ID not found: " + error); }

if (wikidata_id) { var id_elem = document.createElement('small'); id_elem.style.color = "gray"; id_elem.style.fontSize = "18px"; id_elem.innerHTML = " (" + wikidata_id + ")";

headingElem.appendChild(id_elem); }