Greasy Fork

来自缓存

Greasy Fork is available in English.

Qidian P to Span

Convert <p> tags to <span> tags followed by a <br> under specific <main> tag on Qidian chapter pages

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Qidian P to Span
// @namespace    https://dvel.me/qidian-p-to-span
// @version      1.0.0
// @description  Convert <p> tags to <span> tags followed by a <br> under specific <main> tag on Qidian chapter pages
// @author       ChatGPT
// @match        https://www.qidian.com/chapter/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function replacePTagsWithSpanAndBR() {
        let xpathResult = document.evaluate('/html/body/div[1]/div/div[2]/div[2]/div/div[2]/div/main/p', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

        for (let i = 0; i < xpathResult.snapshotLength; i++) {
            let p = xpathResult.snapshotItem(i);
            let span = document.createElement('span');
            span.innerHTML = p.innerHTML;
            p.parentNode.replaceChild(span, p);

            // 添加<br>标签
            let br = document.createElement('br');
            span.parentNode.insertBefore(br, span.nextSibling);
        }
    }

    let observer = new MutationObserver((mutationsList, observer) => {
        for (let mutation of mutationsList) {
            if (mutation.type === 'childList') {
                replacePTagsWithSpanAndBR();
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

})();