Greasy Fork

Greasy Fork is available in English.

XKCD Print Titles

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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');