Greasy Fork

Greasy Fork is available in English.

kf私信格式恢复

恢复因quote截断img导致的私信显示错误

当前为 2025-05-23 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         kf私信格式恢复
// @namespace    https://github.com/kisaragizen/kf-message-repair
// @version      1.0.1
// @description  恢复因quote截断img导致的私信显示错误
// @author       kisaragizen
// @match        https://bbs.kfpromax.com/message.php?action=read*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const pairedElements = [...document.querySelectorAll('img')]
        .filter(img => img.src.includes('[/quote]'))
        .map(img => {
            const siblings = [];
            let prevNode = img.previousSibling;
            while (prevNode) {
                siblings.push(prevNode);
                if (prevNode.textContent.trim().startsWith('[quote]')) {
                    break;
                }
                prevNode = prevNode.previousSibling;
            }
            return {
                img: img,
                siblings: siblings
            };
        });

    pairedElements.forEach(pair => {
        const { img, siblings } = pair;
        const originalURL = img.src.split('[img]')[1];
        const decodedContent = decodeURIComponent(img.src.split('[/quote]')[1].split('[img]')[0]);

        const layer00 = document.createElement('fieldset');
        const layer10 = document.createElement('legend');
        layer10.innerHTML = 'Quote:';
        layer00.appendChild(layer10);
        const newSiblings = siblings.reverse();
        newSiblings[0].textContent = newSiblings[0].textContent.replace('[quote]', '');
        for (let x of newSiblings) {
            layer00.appendChild(x);
        }
        img.insertAdjacentElement('beforebegin', layer00);

        const originalImg = document.createElement('img');
        originalImg.src = originalURL;
        img.insertAdjacentElement('afterend', originalImg);
        img.outerHTML = decodedContent;
    });
})();