XKCD Print Titles

Change XKCD/what-if image alt text to captions and show reference text inline (and don't hide on click)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         XKCD Print Titles
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Change XKCD/what-if image alt text to captions and show reference text inline (and don't hide on click)
// @author       You
// @match        https://*.xkcd.com/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

// Your code here...
var img = document.querySelectorAll('#comic img');
if(img.length === 0)
    img = document.querySelectorAll('.entry img');
img.forEach(function(element) {
    var title = element.title;
    if(title !== undefined) {
        var p = document.createElement('p');
        p.style.textAlign = 'center';
        p.style.lineHeight = 1.5;
        p.style.backgroundColor = '#ccc';
        p.style.padding = 5;
        p.innerHTML = `<span style="padding: 5px">${title}</span>`;
        element.parentNode.insertBefore(p, element.nextSibling);
    }
});

var ref = document.querySelectorAll('article .ref');
ref.forEach(function(element) {
    var refBody = element.querySelector(':scope .refbody');
    refBody.style.position = 'relative';
    refBody.style.display = 'inline-block';
    refBody.style.left = 0;
    refBody.style.bottom = 0;
    refBody.style.overflow = 'visible';
});

jQuery('.refnum').prop('onclick', null).off('click');
jQuery('body').prop('onclick', null).off('click');