Greasy Fork

Greasy Fork is available in English.

XKCD title on click

Displays mouse-over-text when you click the comic

当前为 2014-05-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           XKCD title on click
// @description    Displays mouse-over-text when you click the comic
// @namespace      http://greasyfork.icu/users/98-jonnyrobbie
// @author         JonnyRobbie
// @grant		   none
// @include        /^https?:\/\/(www\.)?xkcd\.com\/(\d+\/)?$/
// @version        2
// ==/UserScript==


function main() {
	var comicDiv = document.getElementById("comic");
	var comic = comicDiv.getElementsByTagName("img")[0];
	var titleWrap = document.createElement("div");
		titleWrap.style.height = "0px";
		titleWrap.style.color = "#fff";
		titleWrap.style.fontStyle = "italic";
		titleWrap.style.fontSize = "0.8em";
		titleWrap.style.marginLeft = "20px";
		titleWrap.style.marginRight = "20px";
	var altTitle = document.createElement("div");
		altTitle.innerHTML = comic.title;
	titleWrap.appendChild(altTitle);
	function animListener() {
		animateIn(titleWrap, altTitle, comic, animListener);
	}
	comic.addEventListener("click", animListener);
	comicDiv.parentNode.insertBefore(titleWrap, comicDiv.nextSibling);
}

function animateIn(outer, inner, comic, animListener){
	var size = 0.0;
	var rgb = 255;
	comic.removeEventListener("click", animListener);
	function animListenerOut() {
		animateOut(outer, inner, comic, animListenerOut);
	}
	var id = setInterval(function() {
		size = size + (inner.clientHeight / 10)
		outer.style.height = Math.round(size) + "px";
		if (inner.clientHeight <= outer.clientHeight) {
			clearInterval(id);
			var id2 = setInterval(function() {
				outer.style.color = "rgb(" + rgb + "," + rgb + "," + rgb + ")";
				if (rgb < 25) {
					clearInterval(id2)
					comic.addEventListener("click", animListenerOut)
				}
				rgb = rgb - 25;
			}, 20)
		}
	}, 20)
}

function animateOut(outer, inner, comic, animListener){
	var size = outer.clientHeight;
	var rgb = 0;
	comic.removeEventListener("click", animListener);
	function animListenerIn() {
		animateIn(outer, inner, comic, animListenerIn);
	}
	var id = setInterval(function() {
		outer.style.color = "rgb(" + rgb + "," + rgb + "," + rgb + ")";
		if (rgb > 230) {
			clearInterval(id);
			var id2 = setInterval(function() {
				size = size - (inner.clientHeight / 10)
				outer.style.height = Math.round(size) + "px";
				if (0 >= outer.clientHeight) {
					clearInterval(id2)
					comic.addEventListener("click", animListenerIn)
				}
			}, 20)
		}
		rgb = rgb + 25;
	}, 20)
}

main();