fuzzyworld

tools / files / userscripts / add-hover-text-COMICS / script.user.js

script.user.js

1.0 KB · history · blame

1// ==UserScript==
2// @name Add Hover Text to Webcomics
3// @namespace https://gitlab.com/PavelSafronov/tools
4// @version 0.2
5// @description Add hover text as paragraph under comics.
6// @author Pavel Safronov
7// @match https://xkcd.com/*
8// @match https://www.smbc-comics.com/*
9// @grant none
10// ==/UserScript==
11
12(function () {
13 'use strict';
14
15 const hostnameToComicDivIdDict = {
16 "www.smbc-comics.com": "cc-comicbody",
17 "xkcd.com": "comic"
18 }
19 const hostname = window.location.hostname;
20 const comicDivId = hostnameToComicDivIdDict[hostname];
21
22 if (comicDivId) {
23 const comicDiv = document.getElementById(comicDivId);
24 const image = comicDiv.getElementsByTagName("img")[0];
25 const altText = image && image.title;
26 if (altText) {
27 const p = document.createElement("p");
28 p.innerText = `Hover text: ${altText}`;
29 comicDiv.parentNode.insertBefore(p, comicDiv.nextSibling);
30 }
31 }
32})();