-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXKCD_-_Display_alt-text.user.js
40 lines (33 loc) · 1.42 KB
/
XKCD_-_Display_alt-text.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// ==UserScript==
// @name XKCD - Display alt-text
// @author Tailszefox
// @namespace localhost
// @description Shows the alt-text and adds a link to explainxkcd
// @icon https://i.imgur.com/sOoBHDy.png
// @version 1.1
// @include http://xkcd.com/
// @include http://xkcd.com/*
// @include https://xkcd.com/
// @include https://xkcd.com/*
// @include http://www.xkcd.com/
// @include http://www.xkcd.com/*
// @include https://www.xkcd.com/
// @include https://www.xkcd.com/*
// @grant none
// ==/UserScript==
var divComic = document.getElementById("comic");
var img = divComic.querySelector("img");
alt = img.title;
var p = document.createElement("p");
p.appendChild(document.createTextNode(alt));
divComic.parentNode.insertBefore(p, divComic.nextSibling.nextSibling);
var titleDiv = document.getElementById('ctitle');
nmbr = document.getElementById('middleContainer');
start = nmbr.innerHTML.indexOf("Permanent link to this comic: https://xkcd.com/")+46;
end = nmbr.innerHTML.indexOf("Image URL (for hotlinking/embedding)")-6;
var comicNumber = nmbr.innerHTML.slice(start, end);
var aExplain = document.createElement("a");
aExplain.href = "http://www.explainxkcd.com/wiki/index.php" + comicNumber;
aExplain.appendChild(document.createTextNode("(Explain)"));
titleDiv.appendChild(document.createTextNode(" "));
titleDiv.appendChild(aExplain);