ExplainXKCD

Adds explainxkcd.com link to xkcd.com

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           ExplainXKCD
// @description    Adds explainxkcd.com link to xkcd.com
// @namespace      https://greasyfork.org/users/98-jonnyrobbie
// @author         JonnyRobbie
// @grant		   none
// @include        /^https?:\/\/(www\.)?xkcd\.com\/(\d*\/)?$/
// @version        2.1
// ==/UserScript==

function main() {
	titleDiv = document.getElementById('ctitle');
	var comicName = titleDiv.innerHTML;
	titleDiv.innerHTML = "";
	var origTitle = document.createElement("span");
		origTitle.innerHTML = comicName;
	titleDiv.appendChild(origTitle);
	var linkTitle = document.createElement("a");
		linkTitle.innerHTML = "(ExplainXKCD)";
		linkTitle.style.display = "none";
		linkTitle.href = "http://www.explainxkcd.com/wiki/index.php?title=" + getComicNumber();		
	titleDiv.appendChild(linkTitle);
	
	origTitle.onmouseover = function(){changeVisibility(this, linkTitle);}
	origTitle.onmouseclick = function(){changeVisibility(this, linkTitle);}
	linkTitle.onmouseover = function(){changeVisibility(origTitle, this);}
	origTitle.onmouseout = function(){changeVisibility(linkTitle, this);}
	linkTitle.onmouseout = function(){changeVisibility(this, origTitle);}
}

function getComicNumber(){
	nmbr = document.getElementById('middleContainer');
	start = nmbr.innerHTML.indexOf("Permanent link to this comic: http://xkcd.com/")+46;
	end = nmbr.innerHTML.indexOf("Image URL (for hotlinking/embedding)")-6;
	return nmbr.innerHTML.slice(start, end);
}

function changeVisibility(hideElem, showElem) {
	hideElem.style.display = "none";
	showElem.style.display = "inline"
}

main();