Wikidata Links Enhancer

displays wikidata links under any wikimedia projects pages

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name Wikidata Links Enhancer
// @namespace maxlath
// @description displays wikidata links under any wikimedia projects pages
// @include *.wikipedia.org/*
// @include *.wikisource.org/*
// @include *.wikiquote.org/*
// @include *.wikimedia.org/*
// @version 1
// @grant none
// ==/UserScript==


var getLink = function () {
  return $('a').filter(function (index) {
    return /wikidata.org\/wiki\/Q/.test($(this).attr('href'))
  }).first().attr('href');
};

var extractWikidataId = function (href) {
  return href.split('wikidata.org/wiki/')[1]
};

var addLinkAfterHeader = function (href) {
  if (href) {
    var id = extractWikidataId(href);
    console.log('wikidata link found', href, id);
    $el = $(document.createElement('a')).attr('href', href).text(id);
    $('h1').next().prepend($el);
  }
};

// after DOM ready, get link and add it under the page h1
$(function () {
  addLinkAfterHeader(getLink())
});