Greasy Fork

Greasy Fork is available in English.

Bilibili 翻页评论区

恢复原来的翻页评论区,仅此而已

当前为 2022-07-01 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bilibili 翻页评论区
// @namespace    MotooriKashin
// @version      1.0.8
// @description  恢复原来的翻页评论区,仅此而已
// @author       MotooriKashin
// @icon         https://static.hdslb.com/images/favicon.ico
// @match        *://*.bilibili.com/*
// @grant        none
// @run-at       document-body
// @license      MIT
// ==/UserScript==

(function () {
    let loading = false, load = false; // 是否载入
    const arr = []; // 接口暂存
    Object.defineProperty(window, "bbComment", {
        configurable: true,
        set: v => {
            if (!load) {
                // 压栈
                arr.unshift(v);
            }
        },
        get: () => {
            if (load) {
                Promise.resolve().then(() => {
                    document.querySelectorAll("style").forEach(d => {
                        d.textContent && d.textContent.includes("热门评论") && d.remove();
                    });
                    addElement("link", { rel: "stylesheet", href: "//static.hdslb.com/phoenix/dist/css/comment.min.css" }, document.head);
                })
                Object.defineProperty(window, "bbComment", { configurable: true, value: arr[0] });
                // 出栈
                return arr[0];
            }
            return class { // 等待载入
                constructor() {
                    if (!loading) {
                        loadScript("//static.hdslb.com/phoenix/dist/js/comment.min.js").then(() => {
                            load = true;
                        })
                    }
                    loading = true;
                    setTimeout(() => new window.bbComment(...arguments), 100);
                }
                on() { }
            }
        }
    });
    Object.defineProperty(window, "initComment", {
        configurable: true,
        set: v => true,
        get: () => {
            if (load) {
                Promise.resolve().then(() => {
                    document.querySelectorAll("style").forEach(d => {
                        d.textContent && d.textContent.includes("热门评论") && d.remove();
                    });
                    addElement("link", { rel: "stylesheet", href: "//static.hdslb.com/phoenix/dist/css/comment.min.css" }, document.head);
                })
                function initComment(tar, init) {
                    new arr[0](tar, init.oid, init.pageType, init.userStatus);
                }
                Object.defineProperty(window, "initComment", { configurable: true, value: initComment });
                // 出栈
                return initComment;
            }
            return function () {
                if (!loading) {
                    loadScript("//static.hdslb.com/phoenix/dist/js/comment.min.js").then(() => {
                        load = true;
                    })
                }
                loading = true;
                setTimeout(() => window.initComment(...arguments), 100);
            }
        }
    });
    function loadScript(src, onload) {
        return new Promise((r, j) => {
            const script = document.createElement("script");
            script.type = "text/javascript";
            script.src = src;
            script.addEventListener("load", () => {
                script.remove();
                onload && onload();
                r(true);
            });
            script.addEventListener('error', () => {
                script.remove();
                j();
            });
            (document.body || document.head || document.documentElement || document).appendChild(script);
        });
    }
    function addElement(tag, attribute, parrent, innerHTML, top, replaced) {
        let element = document.createElement(tag);
        attribute && (Object.entries(attribute).forEach(d => element.setAttribute(d[0], d[1])));
        parrent = parrent || document.body;
        innerHTML && (element.innerHTML = innerHTML);
        replaced ? replaced.replaceWith(element) : top ? parrent.insertBefore(element, parrent.firstChild) : parrent.appendChild(element);
        return element;
    }
})();