// ==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 // @downloadURL none // ==/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; } })();