User:JohannesFre/common.js

// ==UserScript== // @name          DBpedia Link for English Wikipedia Pages // @description   DBpedia Link for English Wikipedia Pages // @author        Anja Jentzsch  // @namespace     none // @include       http://*.wikipedia.org/wiki/* // ==/UserScript==

var allHTMLTags = new Array;

function getElementByClass(theClass) { var allHTMLTags=document.getElementsByTagName('li'); for (i=0; i -1) { return link; }		}	}	return ""; }

var firstHeading, dbpediaLink, pageTitle, hostName; pageTitle = location.pathname.replace(/\/wiki/, ""); if(location.host.search('en.wikipedia.org') > -1) { if (pageTitle.length > 0) { firstHeading = document.getElementById('firstHeading'); dbpediaLink = document.createElement("a"); dbpediaLink.setAttribute("style","margin-left: 20px;"); //dbpediaLink.setAttribute("href","https://global.dbpedia.org/?s=http://dbpedia.org/resource" + location.pathname.replace(/\/wiki/, "")); dbpediaLink.setAttribute("href","http://dbpedia.org/resource" + location.pathname.replace(/\/wiki/, "")); dbpediaImage = document.createElement("img"); dbpediaImage.setAttribute("style","border:none; height:1em"); dbpediaImage.setAttribute("title","DBpedia page for " + firstHeading.firstChild.nodeValue); dbpediaImage.setAttribute("src","https://pbs.twimg.com/profile_images/1353712378014298113/o1fPaIs2_400x400.jpg"); dbpediaLink.appendChild(dbpediaImage); firstHeading.appendChild(dbpediaLink); } } else { var englishLink = getElementByClass('interwiki-en'); var link = ""; if(englishLink.search('en.wikipedia.org') > -1) { link = englishLink; } else { link = getElementByClass('interwiki-en GA'); }	if(link.search('en.wikipedia.org') > -1) { if (pageTitle.length > 0) { firstHeading = document.getElementById('firstHeading'); dbpediaLink = document.createElement("a"); dbpediaLink.setAttribute("style","font-weight:bold; margin-left: 20px; margin-right: 20px;"); dbpediaLink.setAttribute("href","http://dbpedia.org/resource" + link.replace(/http:\/\/en.wikipedia.org\/wiki/, "")); dbpediaImage = document.createElement("img"); dbpediaImage.setAttribute("style","border:none; height:1em"); dbpediaImage.setAttribute("title","DBpedia page for " + firstHeading.firstChild.nodeValue); dbpediaImage.setAttribute("src","https://pbs.twimg.com/profile_images/1353712378014298113/o1fPaIs2_400x400.jpg"); dbpediaLink.appendChild(dbpediaImage); firstHeading.appendChild(dbpediaLink); }	}	}