This userscript makes Wikipedia pages to show their corresponding Wikidata entity ID and link to it in the gray parentheses next to the entry title.
Distributed under public domain.
| // ==UserScript== | |
| // @name Wikidata Entity ID on Wikipedia | |
| // @namespace https://gist.github.com/dahlia/dc722917730c501fc74085b058046495 | |
| // @description Show Wikidata Entity ID on Wikipedia pages | |
| // @include https://*.wikipedia.org/wiki/* | |
| // @include http://*.wikipedia.org/wiki/* | |
| // @version 1 | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| var link = document.querySelector('#t-wikibase > a[href*="wikidata.org"]'); | |
| if (!link) { | |
| return; | |
| } | |
| var url = link.href, | |
| match = /\/wiki(\/Special:EntityPage)\/(Q[1-9][0-9]*)(\?|$)/.exec(url); | |
| if (!match) { | |
| return; | |
| } | |
| var entityId = match[2], | |
| heading = document.querySelector('h1#firstHeading'); | |
| wdLink = document.createElement('a'); | |
| wdLink.href = url; | |
| wdLink.style.color = '#72777d'; | |
| wdLink.style.textDecoration = 'none'; | |
| wdLink.style.fontSize = '0.6em'; | |
| wdLink.style.marginLeft = '0.4em'; | |
| wdLink.style.fontFamily = '"Linux Libertine",Georgia,Times,serif'; | |
| wdLink.style.fontWeight = 'normal'; | |
| var userselect = '', prefixes = ['', '-moz-', '-webkit-']; | |
| for (var i = 0; i < prefixes.length; ++i) { | |
| userselect += prefixes[i] + 'user-select: none;'; | |
| } | |
| wdLink.innerHTML = '<span style="' + userselect + '">(</span>' | |
| + entityId | |
| + '<span style="' + userselect + '">)</span>'; | |
| heading.appendChild(wdLink); | |
| })(); |