ExplainXKCD

Adds explainxkcd.com link to xkcd.com

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();