您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
获取bilibili 评论区楼层数,使得浏览器版b站显示楼层
当前为
// ==UserScript== // @name BILIBILI show floor number // @name:zh B站显示楼层 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 获取bilibili 评论区楼层数,使得浏览器版b站显示楼层 // @author devseed // @match *://*.bilibili.com/* // @grant none // ==/UserScript== (function() { async function replycursor(oid, root, type=1) //时间顺序,游标 { return new Promise(resolve => { $.get("https://api.bilibili.com/x/v2/reply/reply/cursor", { "oid":oid, "type":type, //视频、专栏、话题…… "root":root }, function(resp){ return resolve(resp) }) }) } async function replymain(oid, next, mode, type=1) //热评 { return new Promise(resolve => { $.get("https://api.bilibili.com/x/v2/reply/main", { "oid":oid, "next":next, "mode":mode, "type":type }, function(resp){ return resolve(resp) }) }) } async function reply(oid, pn, sort, type=1) //默认,无楼层 { return new Promise(resolve => { $.get("https://api.bilibili.com/x/v2/reply", { "oid":oid, "pn":pn, "sort": sort, "type":type }, function(resp){ return resolve(resp) }) }) } var url_av = $('meta[property="og:url"]').attr('content'); var last_oid = parseInt(url_av.split('/')[4].slice(2)); var last_pn = parseInt($('div#comment span.current').html()); var last_sort = parseInt($('div.tabs-order li.on').attr('data-sort')); var last_type = 1 //暂时只支持av,不支持ss之类的番剧,专栏,话题 //var comment_div = $('div#comment').get(0); document.addEventListener("DOMNodeInserted",async (event) => { url_av = $('meta[property="og:url"]').attr('content'); var oid = parseInt(url_av.split('/')[4].slice(2)); var pn = parseInt($('div#comment span.current').html()); var sort = parseInt($('div.tabs-order li.on').attr('data-sort')); var type =1; if(oid==last_oid && pn==last_pn && sort==last_sort && type==last_type) return; //评论页面没变 last_oid = oid; last_pn = pn; last_sort = sort; //console.log(event.target, oid, pn, sort) try { var mode = 0; var resp; if(sort==0) mode=1; else if(sort==2) mode=3; if(sort==2) resp = await replymain(oid, pn, mode, type);//热门 else { console.log(pn) if(pn==1) resp = await replymain(oid, 0, mode, type); else { resp = await reply(oid, pn-1, sort, type) //取得上一页最后一项rpid //console.log('reply' , resp) let end = resp['data']['replies']['length']; let root = resp['data']['replies'][end-1]['rpid']; resp = await replycursor(oid, root, type); //取得此项floor值 //console.log('replycursor' , root, resp) let next = resp['data']['root']['floor']; resp = await replymain(oid, next, mode, type) //搜索next值 } } console.log(resp) var replies = resp['data']['replies'] for (var i in replies) //添加评论 { info = $('div.[data-id="'+ replies[i]['rpid'].toString() +'"] div.con div.info') info.prepend("<span>#"+ replies[i]['floor'].toString() + "</span>") } } catch (e){ console.error('Reply eror: ', e.message); } //console.log('DOMNodeInserted end'); }); })()