// ==UserScript== // @name 修复B站评论区楼层 // @namespace MotooriKashin // @version 0.0.1 // @description 修复评论区楼层号,包括视频、动态、专栏、话题、活动…… // @author MotooriKashin // @match *://*.bilibili.com/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; let src,timer,mode,type; const url = { "reply" : "https://api.bilibili.com/x/v2/reply", "replymain" : "https://api.bilibili.com/x/v2/reply/main", "replycursor" : "https://api.bilibili.com/x/v2/reply/reply/cursor", } const xhr = { "true" : (url,callback) => { const xhr = new XMLHttpRequest(); xhr.open('GET',url,true); xhr.withCredentials = true; xhr.onload = () => callback(xhr.responseText) xhr.send(); } } const handle = { "obj2search" : (url,obj) =>{ if (obj) { let arr = [],i = 0; for (let key in obj) { if(obj[key] !== "" && obj[key] !== "undefined" && obj[key] !== null) { arr[i] = key + "=" + obj[key]; i++; } } url = url + "?" + arr.join("&"); } return url; }, "setReplyFloor" : { "start" : (src) => { try { let oid,sort,pn; src = src.split('?')[1].split('&'); for (let i=0;i { try { data = JSON.parse(data).data; let i = data.replies.length - 1; let oid = data.replies[0].oid; let root = data.replies[i].rpid; xhr.true(handle.obj2search(url.replycursor,{"oid":oid,"root":root,"type":type}),handle.setReplyFloor.cursorfloor); } catch(e) {console.error(e);} }, "cursorfloor" : (data) => { try { data = JSON.parse(data).data; let oid = data.root.oid; let next = data.root.floor; xhr.true(handle.obj2search(url.replymain,{"oid":oid,"next":next,"type":type,"mode":mode}),handle.setReplyFloor.floor); } catch(e) {console.error(e)} }, "floor" : (data) => { try { data = JSON.parse(data).data; let floor = {},top = data.top,hots = data.hots,replies = data.replies; let list_item = document.getElementsByClassName("list-item"); let main_floor = document.getElementsByClassName("main-floor"); if (hots && hots[0]) for (let i=0;i { if (msg.target.src && msg.target.src.startsWith('https://api.bilibili.com/x/v2/reply?')) src = msg.target.src; if (src) { if (msg.target.className && (msg.target.className == "main-floor" || msg.target.className == "list-item reply-wrap ")){ window.clearTimeout(timer); timer = window.setTimeout(() => {handle.setReplyFloor.start(src)},1000); } } }); })();