🏠 Home 

Wikidata Links Enhancer

displays wikidata links under any wikimedia projects pages


Install this script?
  1. // ==UserScript==
  2. // @name Wikidata Links Enhancer
  3. // @namespace maxlath
  4. // @description displays wikidata links under any wikimedia projects pages
  5. // @include *.wikipedia.org/*
  6. // @include *.wikisource.org/*
  7. // @include *.wikiquote.org/*
  8. // @include *.wikimedia.org/*
  9. // @version 1
  10. // @grant none
  11. // ==/UserScript==
  12. var getLink = function () {
  13. return $('a').filter(function (index) {
  14. return /wikidata.org\/wiki\/Q/.test($(this).attr('href'))
  15. }).first().attr('href');
  16. };
  17. var extractWikidataId = function (href) {
  18. return href.split('wikidata.org/wiki/')[1]
  19. };
  20. var addLinkAfterHeader = function (href) {
  21. if (href) {
  22. var id = extractWikidataId(href);
  23. console.log('wikidata link found', href, id);
  24. $el = $(document.createElement('a')).attr('href', href).text(id);
  25. $('h1').next().prepend($el);
  26. }
  27. };
  28. // after DOM ready, get link and add it under the page h1
  29. $(function () {
  30. addLinkAfterHeader(getLink())
  31. });