// ==UserScript== // @name 哔哩哔哩(B站)评论区显示楼层 // @description (2022/11难以使用)bilibili哔哩哔哩网页端视频、动态等页面显示评论区楼层与楼中楼楼层,理论兼容Bilibill Evolved // @author lchzh3473 , Modify by Tinhone // @namespace Original by lchzh3473 , Modify by Tinhone // @license GPL-3.0 // @version 1.9.0 // @icon https://app.bilibili.com/favicon.ico // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @compatible firefox V84+ // @compatible edge V88+ // @compatible chrome V88+ // @match *://www.bilibili.com/video/* // @match *://www.bilibili.com/read/cv* // @match *://t.bilibili.com/* // @match *://space.bilibili.com/* // @exclude *://workshop.bilibili.com/illust/* // @exclude *://workshop.bilibili.com/live2d/* // @exclude *://t.bilibili.com/ // @exclude *://www.bilibili.com/bangumi/play/* // @run-at document-end // @downloadURL none // ==/UserScript== (function() { //代码看起来长,实际上只是一个功能对于几个页面的分别适配,看if (page==0)这一段就可以大概理解整个脚本了(~ ̄▽ ̄)~ 'use strict'; const newVideoPageV1="body.harmony-font.header-v2.win.always-show-duration div#app.app-v1 div.video-container-v1 div.left-container div.left-container-under-player div#comment.comment-m-v1 div.comment div.bili-comment.browser-pc div.reply-header div.reply-navigation ul.nav-bar li.nav-title li.nav-title-text" //新版视频页版本一特征 //版本特性为不可使用楼中楼楼层、旧页面 const newVideoPageV2="body.harmony-font.header-v2.win:not(.always-show-duration) div#app.app-v1" //新版视频页版本二特征 //版本特性为可使用楼中楼楼层、新页面 const newVideoPageV3="body.harmony-font.header-v2.win.always-show-duration div#app.app-v1 div.video-container-v1 div.left-container div.left-container-under-player div#comment.comment-m-v1 div.comment div.bili-comment.browser-pc div.reply-header div.reply-navigation ul.nav-bar li.nav-title span.nav-title-text" //新版视频页版本三特征 //版本特性为不可使用楼中楼楼层、新页面 const workshopLive2dPage="div.live2d div.container div.left div.comment-area div.bb-comment div.comment-header div.tabs-order ul.clearfix" //创意工坊live2d页面特征 const workshopIllustPage="div.illust div.container div.left div.comment-area div.bb-comment div.comment-header div.tabs-order ul.clearfix" //创意工坊插画页面特征 const userSpacePage="div.s-space div div#page-dynamic.wrapper.clearfix div.col-1 div.bili-dyn-list div.bili-dyn-list__items" //用户个人空间页面特征 const albumDynamicDetailedPage="div#app div.content div.card div.bili-dyn-item .bili-album" //含图片动态详细页面特征 const textDynamicDetailedPage="div#app div.content div.card div.bili-dyn-item" //纯文字动态详细页面特征 //新版视频页版本一总楼层数,VP=VideoPage const newVPReplyV1Counts1="div#comment.comment-m-v1 div.comment div.bb-comment div.comment-header.clearfix div.tabs-order ul.clearfix:not(.e)" const newVPReplyV1Counts2="div#comment.comment-m-v1 div.comment div.bb-comment div.comment-header.clearfix div.tabs-order ul.clearfix.e" //新版视频页版本二总楼层数 const newVPReplyV2Counts1="div#comment.comment-m-v1 div.comment div.bili-comment.browser-pc div.reply-header div.reply-navigation ul.nav-bar li.nav-title:not(.e)" const newVPReplyV2Counts2="div#comment.comment-m-v1 div.comment div.bili-comment.browser-pc div.reply-header div.reply-navigation ul.nav-bar li.nav-title.e" //新版视频页版本三总楼层数 const newVPReplyV3Counts1="div#comment.comment-m-v1 div.comment div.bili-comment.browser-pc div.reply-header div.reply-navigation ul.nav-bar li.nav-title:not(.e)" const newVPReplyV3Counts2="div#comment.comment-m-v1 div.comment div.bili-comment.browser-pc div.reply-header div.reply-navigation ul.nav-bar li.nav-title.e" //创意工坊live2d页面总楼层数,WLP=workshopLive2dPage const WLPReplyCounts1="div.live2d div.container div.left div.comment-area div.bb-comment div.comment-header div.tabs-order ul.clearfix:not(.e)" const WLPReplyCounts2="div.live2d div.container div.left div.comment-area div.bb-comment div.comment-header div.tabs-order ul.clearfix.e" //创意工坊插画页面总楼层数,WIP=workshopIllustPage const WIPReplyCounts1="div.illust div.container div.left div.comment-area div.bb-comment div.comment-header div.tabs-order ul.clearfix:not(.e)" const WIPReplyCounts2="div.illust div.container div.left div.comment-area div.bb-comment div.comment-header div.tabs-order ul.clearfix.e" //用户个人空间页面总楼层数,USP=userSpacePage const USPReplyCounts1="div.dynamic-card-comment div.bb-comment div.comment-header.clearfix div.tabs-order:not(.e)" const USPReplyCounts2="div.dynamic-card-comment div.bb-comment div.comment-header.clearfix div.tabs-order.e" //含图片动态详细页面总楼层数,ADDP=albumDynamicDetailedPage const ADDPReplyCounts1="div.dynamic-card-comment div.bb-comment div.comment-header.clearfix:not(.e)" const ADDPReplyCounts2="div.dynamic-card-comment div.bb-comment div.comment-header.clearfix.e" //纯文字动态详细页面总楼层数,TDDP=textDynamicDetailedPage const TDDPReplyCounts1="div.dynamic-card-comment div.bb-comment div.comment-header.clearfix:not(.e)" const TDDPReplyCounts2="div.dynamic-card-comment div.bb-comment div.comment-header.clearfix.e" //旧版视频页,OVP=oldVideoPage const OVP=new Map([ ["pageFeature","html body.header-v2.win.round-corner div#app div.v-wrap div.l-con div#comment.comment-m"], //页面特征 ["replyCount1","div.common > div.b-head:not(.e)"], //回复总数所在的尚未添加楼层总数的div,用来定位楼层总数 ["replyCount2","div.common > div.b-head.e"], //回复总数所在的已添加楼层总数的div,用来定位楼层总数 ["separateReply1","div.list-item.reply-wrap:not(.a)"], //独立楼层回复 ["separateReply2","div.list-item.reply-wrap.c"], //独立楼层回复 ["floorInFloor1","div.list-item.reply-wrap.c > div.con > div.reply-box > div.reply-item.reply-wrap"], //楼中楼回复 ["floorInFloor2","div.list-item.reply-wrap.c > div.con > div.reply-box > div.reply-item.reply-wrap:not(.d)"], //楼中楼回复 ]) let OVPRCCState=false //OVPRCCState=oldVideoPageReplyCountsChangeState let OVPFloorCount=document.createElement("span") let OVPCommentArea="div#comment > div.common" let OVPObserver="" let newVPObserverOpening=false //新版视频页观察器是否打开 let WLPObserverOpening=false //创意工坊live2d页面观察器是否打开 let WIPObserverOpening=false //创意工坊插画页面观察器是否打开 let USPObserverOpening=false //用户个人空间页面观察器是否打开 let ADDPObserverOpening=false //含图片动态详细页面观察器是否打开 let TDDPObserverOpening=false //纯文字动态详细页面观察器是否打开 //页面特征+按钮选择器 GM_addStyle(` /*旧版视频页[回复]按钮*/ html body.header-v2.win.round-corner div#app div.v-wrap div.l-con div#comment.comment-m .reply.btn-hover{ height:16px !important; padding-top:2px !important; padding-bottom:2px !important } `) if (typeof(GM_getValue("fifButton"))=="undefined"){ GM_setValue("fifButton","ON") } const fifButton=GM_getValue("fifButton")?true:false let loopTime=30 function createXhr(url){ const xhr=new XMLHttpRequest() xhr.open("get", url, true) //method, url, async[可选,默认为true,表示要异步执行操作], user[可选,默认为null,用于认证用途], password[可选,默认为null,用于认证用途] xhr.responseType="json" xhr.withCredentials=true //指定跨域的请求是否应该使用证书 return xhr } function checkPage(){ let a=-1 //0=旧版视频页,1=新版视频页V1,2=新版视频页V2,3=新版视频页V3,4=创意工坊live2d页面,5=创意工坊插画页面,6=用户个人空间,7=含图片动态详细页面,8=纯文字动态详细页面 if (document.querySelector(OVP.get("pageFeature"))){ a=0 } if (document.querySelector(newVideoPageV1)){ a=1 } if (document.querySelector(newVideoPageV2)){ a=2 } if (document.querySelector(newVideoPageV3)){ a=3 } if (document.querySelector(workshopLive2dPage)){ a=4 } if (document.querySelector(workshopIllustPage)){ a=5 } if (document.querySelector(userSpacePage)){ a=6 } if (document.querySelector(albumDynamicDetailedPage)){ a=7 } if (document.querySelector(textDynamicDetailedPage) && document.querySelector(albumDynamicDetailedPage)==null){ a=8 } return a } let page=-1 let CPSafe=3 let CPLoop=setInterval(()=>{ //拿到可靠的 page 数值 //console.time() if (checkPage()+1){ CPSafe-=1 if (!CPSafe){ clearInterval(CPLoop) CPSafe=undefined CPLoop=undefined page=checkPage() OVPCommentArea=document.querySelector(OVPCommentArea) //顺便加一个 //console.log(OVPCommentArea) } } else{ CPSafe=3 } //console.timeEnd() }, 500) let StartOVPObserver=setInterval(()=>{ //启动观察器侦测 按热度排序 li,出现变动就改变 replyCounts 的 class,做到和评论总数同步的刷新 //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer if (typeof(CPSafe)=="undefined" && page==0 && document.querySelector(OVP.get("replyCount2")) && document.querySelector(".tabs-order .clearfix .hot-sort")){ clearInterval(StartOVPObserver) //console.log("2333") const OVPObserverTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const OVPObserverConfig={attributes:true, childList:true, subtree:true, classList:true} const OVPObserverCallback=()=>{ const OVPRCCClass=document.querySelector(OVP.get("replyCount2")) //OVPRCClass=oldVideoPageReplyCountsChangeClass OVPRCCClass.classList.remove("e") OVPRCCClass.classList.add("f") //console.log("23333") } OVPObserver=new MutationObserver(OVPObserverCallback) //创建一个观察器并传入回调参数 OVPObserver.observe(OVPObserverTarget,OVPObserverConfig) //以这两个配置开始观察 } }, 500) setInterval(()=>{ //console.time() if (!(loopTime%60)){ page=checkPage() } if (page==0){ //.e: 回复总数所在的div是否已添加楼层总数 //.f: 按热度排序/按时间排序出现切换动作 //===在视频页面显示总楼层数=== if (OVPCommentArea.querySelector(OVP.get("replyCount1"))){ //不能优化掉,会导致 owowo1change is null 以及其他问题,原因是 replyCount 可能会重置导致部分元素一同消失 const owo1=OVPCommentArea.querySelector(OVP.get("replyCount1")) owo1.classList.add("e") OVPRCCState=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") //到此为止 const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=1&oid=${unsafeWindow.aid?unsafeWindow.aid:unsafeWindow.player.getUserParams().input.aid}&mode=2`) //获取最新评论 xhr1.send() xhr1.onload=()=>{ const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${xhr1.response.data.replies[0].rpid}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ if (OVPRCCState){ //如果总楼层数已显示,则改为替换数字,否则创建新的 OVPFloorCount.innerHTML=`${xhr2.response.data.floor}` OVPRCCState=false } else{ const OVPFloorCountSuffix=document.createElement("span") OVPFloorCount.innerHTML=`${xhr2.response.data.floor}` OVPFloorCountSuffix.innerHTML="楼" OVPFloorCount.setAttribute("style",`margin-left:17px; margin-right:3px; font-size:80%; opacity:0.8`) OVPFloorCountSuffix.setAttribute("style",`font-size:90%; opacity:0.8`) owo1.appendChild(OVPFloorCount) owo1.appendChild(OVPFloorCountSuffix) } } } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (OVPCommentArea.querySelector(OVP.get("separateReply1"))){ for (let i2 of OVPCommentArea.querySelectorAll(OVP.get("separateReply1"))){ i2.classList.add("a"); //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为 fulse 的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ const i2_1=i2.querySelector(".operation.more-operation .opera-list ul") const li=document.createElement("li") li.setAttribute("class","fif") //fif=floor-in-floor li.innerHTML="楼中楼楼层" li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) i2_1.appendChild(li) } else{ i2.classList.add("c") } //显示独立非楼中楼评论楼层 const qwq = i2.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i2.attributes["data-id"].value}`) xhr.send(); const qwqwq = document.createElement("span"); qwqwq.setAttribute("style","height:16px; margin-right:14px"); xhr.onload = () => { qwqwq.innerHTML = `#${xhr.response.data.floor}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (OVPCommentArea.querySelector(OVP.get("floorInFloor1"))){ for (let i4 of OVPCommentArea.querySelectorAll(OVP.get("separateReply2"))){ for (let i4_1 of i4.querySelectorAll(OVP.get("floorInFloor2"))){ const i4_1_1=i4_1.querySelector(".info") i4_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_1.attributes["data-id"].value}`) xhr.send() const span=document.createElement("span") span.setAttribute("style","height:16px; margin-right:14px") xhr.onload=()=>{ span.innerHTML=`#${xhr.response.data.floor}` i4_1_1.insertBefore(span, i4_1_1.childNodes[3]) } } } } //===end=== } //# //= 旧版视频页 //# //= 新版视频页V1 //# else if (page==1){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1=".list-item.reply-wrap:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2=".list-item.reply-wrap.c" const floorInFloor1=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap" //楼中楼 const floorInFloor2=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap:not(.d)" const replyOperation=".operation.more-operation .opera-list ul:not(.b)" //评论旁边的三个点 //e代表视频总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的li,特殊标识,方便操作 //===在视频页面显示总楼层数=== if (document.querySelector(newVPReplyV1Counts1)){ const owo1=document.querySelector(newVPReplyV1Counts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=1&oid=${unsafeWindow.aid?unsafeWindow.aid:unsafeWindow.player.getUserParams().input.aid}&mode=2`) //获取最新评论 xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.replies[0].rpid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo1}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.floor if (contains==true){ //如果总楼层数已显示,则改为替换数字,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo2}` } else{ const style1=unsafeWindow.getComputedStyle(document.querySelector(".tabs-order .clearfix .default-sort:not(owo)")) //读取最终样式,包括内联样式、嵌入样式和外部样式 const style2=unsafeWindow.getComputedStyle(document.querySelector(".tabs-order .clearfix .total-reply:not(owo)")) const owowo1=document.createElement("li") const owowo2=document.createElement("li") owowo1.innerHTML="楼层" owowo2.innerHTML=`${owowowo2}` owowo2.setAttribute("style",`height:${style2.height}; margin-right:${style2.marginRight}; line-height:${style2.lineHeight}; font-size:${style2.fontSize}; color:${style2.color}`) owowo1.classList.add("default-sort") //为设置网站自带css owowo2.classList.add("default-sort") //设置成这个class是因为设置成其他的都会出问题,并非为了设置网站自带css owowo1.classList.add("owo") owowo2.classList.add("owo") owowo2.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[2]) //向列表中指定位置插入一个项目 owo1.insertBefore(owowo2,owo1.childNodes[3]) document.querySelector("li.total-reply:not(.owo)").setAttribute("style","margin-right:20px") } } } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ if (i2.querySelector(replyOperation)){ const i2_1=i2.querySelector(replyOperation) const li=document.createElement("li"); li.setAttribute("class","fif") //fif=floor-in-floor li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) li.innerHTML="楼中楼楼层" i2_1.appendChild(li) i2_1.classList.add("b") } } } if (!fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ i2.classList.add("c") } } //显示楼层 const spanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.con div.info span.like span")).lineHeight //在没有文本的时候height会为0,所以用line-height for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.attributes["data-id"].value}`) xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style",`height:${spanHeight}; margin-right:16px;`); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (document.querySelector(floorInFloor1)){ const FIFSpanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.reply-box div.reply-item.reply-wrap div.info span.like span")).lineHeight for (let i4 of document.querySelectorAll(separateReply2)){ const i4_2=i4.querySelectorAll(floorInFloor2) for (let i4_2_1 of i4_2){ const i4_2_1_1=i4_2_1.querySelector(".info") i4_2_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_2_1.attributes["data-id"].value}`) xhr.send() xhr.onload=()=>{ const data=xhr.response.data.floor const span=document.createElement("span") span.setAttribute("style",`height:${FIFSpanHeight}; margin-right:16px;`) span.innerHTML=`#${data}` i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[3]) } } } } //===end=== //===侦测 最热 li,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (newVPObserverOpening==false && document.querySelector(".tabs-order .clearfix .hot-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(newVPReplyV1Counts2)){ const RCChangeClass=document.querySelector(newVPReplyV1Counts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 newVPObserverOpening=true } //===end=== } //# //= 新版视频页V1 //# //= 新版视频页V2 //# else if (page==2){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1="div.reply-list div.reply-item:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2="div.reply-list div.reply-item.c" const separateReply3="div.reply-list div.reply-item" const floorInFloor1="div.sub-reply-container div.sub-reply-list div.sub-reply-item" //楼中楼 const floorInFloor2="div.sub-reply-container div.sub-reply-list div.sub-reply-item:not(.d)" const replyOperation="div.reply-operation-warp div.reply-operation ul.operation-list:not(.b)" //评论旁边的三个点 //e代表视频总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的span,特殊标识,方便操作 //===在视频页面显示总楼层数=== if (document.querySelector(newVPReplyV2Counts1)){ const owo1=document.querySelector(newVPReplyV2Counts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=1&oid=${unsafeWindow.aid?unsafeWindow.aid:unsafeWindow.player.getUserParams().input.aid}&mode=2`) //获取最新评论 xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.replies[0].rpid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo1}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.floor if (contains==true){ //如果总楼层数已显示,则改为替换数字,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo2}` } else{ const style1=unsafeWindow.getComputedStyle(document.querySelector("div.reply-navigation ul.nav-bar li.nav-title.e span.nav-title-text:not(owo)")) //读取最终样式,包括内联样式、嵌入样式和外部样式 const style2=unsafeWindow.getComputedStyle(document.querySelector("div.reply-navigation ul.nav-bar li.nav-title.e span.total-reply:not(owo)")) const owowo1=document.createElement("span") const owowo2=document.createElement("span") owowo1.innerHTML="楼层" owowo2.innerHTML=`${owowowo2}` owowo1.setAttribute("style",`height:${style1.height}; margin-left:${style1.marginLeft}; margin-right:${style1.marginRight}; line-height:${style1.lineHeight}; font-family:${style1.fontFamily}; font-size:100%; font-weight:${style1.fontWeight}; color:${style1.color}`) owowo2.setAttribute("style",`height:${style2.height}; margin-left:${style2.marginLeft}; margin-right:${style2.marginRight}; line-height:${style2.lineHeight}; font-family:${style2.fontFamily}; font-size:${style2.fontSize}; font-weight:${style2.fontWeight}; color:${style2.color}`) owowo1.classList.add("owo") owowo2.classList.add("owo") owowo2.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[2]) //向列表中指定位置插入一个项目 owo1.insertBefore(owowo2,owo1.childNodes[3]) document.querySelector("div.reply-navigation ul.nav-bar li.nav-title.e span.total-reply:not(.owo)").setAttribute("style","margin-right:22px") } } } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { // //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 // for (let i2 of document.querySelectorAll(separateReply1)){ // if (i2.querySelector(replyOperation)){ // const i2_1=i2.querySelector(replyOperation) // const li=document.createElement("li") // li.setAttribute("class","operation-option") // const span=document.createElement("span") // span.setAttribute("class","option-title") // li.addEventListener("click",(()=>{ //点击事件 // i2.classList.add("c") // })) // span.innerHTML="楼中楼楼层" // li.appendChild(span) // i2_1.appendChild(li) // i2_1.classList.add("b") // } // } //显示楼层 const spanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.root-reply div.reply-info")).lineHeight //在没有文本的时候height会为0,所以用line-height for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".reply-info") const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.querySelector(".root-reply-avatar").attributes["data-root-reply-id"].value}`) xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style",`height:${spanHeight};margin-right:18px`); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[4]) //加在div info里的第四位 } } } //===end=== // //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== // if (document.querySelector(floorInFloor1)){ // const FIFSpanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.sub-reply-list div.sub-reply-item div.sub-reply-info span.sub-reply-like")).lineHeight // for (let i4 of document.querySelectorAll(separateReply2)){ // const i4_2=i4.querySelectorAll(floorInFloor2) // for (let i4_2_1 of i4_2){ // const i4_2_1_1=i4_2_1.querySelector(".sub-reply-info") // i4_2_1.classList.add("d") // const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_2_1.querySelector(".sub-reply-avatar").attributes["data-root-reply-id"].value}`) // xhr.send() // xhr.onload=()=>{ // const data=xhr.response.data.floor // const span=document.createElement("span") // span.setAttribute("style",`height:${FIFSpanHeight};margin-right:14px`) // span.innerHTML=`#${data}` // i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[4]) // } // } // } // } // //===end=== //===侦测 最热 div,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (newVPObserverOpening==false && document.querySelector("div.reply-navigation ul.nav-bar li.nav-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector("div.reply-navigation ul.nav-bar li.nav-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(newVPReplyV2Counts2)){ const RCChangeClass=document.querySelector(newVPReplyV2Counts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 newVPObserverOpening=true } //===end=== } //# //= 新版视频页V2 //# //= 新版视频页V3 //# else if (page==3){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1="div.reply-list div.reply-item:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2="div.reply-list div.reply-item.c" const separateReply3="div.reply-list div.reply-item" const floorInFloor1="div.reply-warp div.reply-list div.reply-item div.content-warp div.sub-reply-list div.sub-reply-item" //楼中楼 const floorInFloor2="div.reply-warp div.reply-list div.reply-item div.content-warp div.sub-reply-list div.sub-reply-item:not(.d)" const replyOperation="div.reply-operation-warp div.reply-operation ul.operation-list:not(.b)" //评论旁边的三个点 //e代表视频总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的span,特殊标识,方便操作 //===在视频页面显示总楼层数=== if (document.querySelector(newVPReplyV3Counts1)){ const owo1=document.querySelector(newVPReplyV3Counts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=1&oid=${unsafeWindow.aid?unsafeWindow.aid:unsafeWindow.player.getUserParams().input.aid}&mode=2`) //获取最新评论 xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.replies[0].rpid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo1}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.floor if (contains==true){ //如果总楼层数已显示,则改为替换数字,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo2}` } else{ const style1=unsafeWindow.getComputedStyle(document.querySelector("div.reply-navigation ul.nav-bar li.nav-title.e span.nav-title-text:not(owo)")) //读取最终样式,包括内联样式、嵌入样式和外部样式 const style2=unsafeWindow.getComputedStyle(document.querySelector("div.reply-navigation ul.nav-bar li.nav-title.e span.total-reply:not(owo)")) const owowo1=document.createElement("span") const owowo2=document.createElement("span") owowo1.innerHTML="楼层" owowo2.innerHTML=`${owowowo2}` owowo1.setAttribute("style",`height:${style1.height}; margin-left:${style1.marginLeft}; margin-right:${style1.marginRight}; line-height:${style1.lineHeight}; font-family:${style1.fontFamily}; font-size:100%; font-weight:${style1.fontWeight}; color:${style1.color}`) owowo2.setAttribute("style",`height:${style2.height}; margin-left:${style2.marginLeft}; margin-right:${style2.marginRight}; line-height:${style2.lineHeight}; font-family:${style2.fontFamily}; font-size:${style2.fontSize}; font-weight:${style2.fontWeight}; color:${style2.color}`) owowo1.classList.add("owo") owowo2.classList.add("owo") owowo2.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[2]) //向列表中指定位置插入一个项目 owo1.insertBefore(owowo2,owo1.childNodes[3]) document.querySelector("div.reply-navigation ul.nav-bar li.nav-title.e span.total-reply:not(.owo)").setAttribute("style","margin-right:22px") } } } } //===end=== //===显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply3)) { //显示楼层 const spanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.content-warp div.root-reply div.reply-info span.reply-like")).lineHeight //在没有文本的时候height会为0,所以用line-height for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".reply-info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.querySelector(".root-reply-avatar").attributes["data-root-reply-id"].value}`) xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style",`height:${spanHeight}; margin-right:22px`); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[4]) //加在div info里的第四位 } } } //===end=== //===侦测 最热 div,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (newVPObserverOpening==false && document.querySelector("div.reply-navigation ul.nav-bar li.nav-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector("div.reply-navigation ul.nav-bar li.nav-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(newVPReplyV3Counts2)){ const RCChangeClass=document.querySelector(newVPReplyV3Counts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 newVPObserverOpening=true } //===end=== } //# //= 新版视频页V3 //# //= 创意工坊live2d页面 //# else if (page==4){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1=".list-item.reply-wrap:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2=".list-item.reply-wrap.c" const floorInFloor1=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap" //楼中楼 const floorInFloor2=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap:not(.d)" const replyOperation=".operation.more-operation .opera-list ul:not(.b)" //评论旁边的三个点 //e代表视频总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的li,特殊标识,方便操作 //===在页面显示总楼层数=== if (document.querySelector(WLPReplyCounts1)){ const owo1=document.querySelector(WLPReplyCounts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=42&oid=${unsafeWindow.location.pathname.split("/")[2]}&mode=2`) //获取最新评论 //获取url的文件名,以/为界分割,用最后一个,即oid xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.replies[0].rpid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo1}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.floor if (contains==true){ //如果总楼层数已显示,则改为替换数字,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo2}` } else{ const style1=unsafeWindow.getComputedStyle(document.querySelector(".tabs-order .clearfix .default-sort:not(owo)")) //读取最终样式,包括内联样式、嵌入样式和外部样式 const style2=unsafeWindow.getComputedStyle(document.querySelector(".tabs-order .clearfix .total-reply:not(owo)")) const owowo1=document.createElement("li") const owowo2=document.createElement("li") owowo1.innerHTML="楼层" owowo2.innerHTML=`${owowowo2}` owowo2.setAttribute("style",`height:${style2.height}; margin-right:${style2.marginRight}; line-height:${style2.lineHeight}; font-size:${style2.fontSize}; color:${style2.color}`) owowo1.classList.add("default-sort") //为设置网站自带css owowo2.classList.add("default-sort") //设置成这个class是因为设置成其他的都会出问题,并非为了设置网站自带css owowo1.classList.add("owo") owowo2.classList.add("owo") owowo2.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[2]) //向列表中指定位置插入一个项目 owo1.insertBefore(owowo2,owo1.childNodes[3]) document.querySelector("li.total-reply:not(.owo)").setAttribute("style","margin-right:20px") } } } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ if (i2.querySelector(replyOperation)){ const i2_1=i2.querySelector(replyOperation) const li=document.createElement("li"); li.setAttribute("class","fif") //fif=floor-in-floor li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) li.innerHTML="楼中楼楼层" i2_1.appendChild(li) i2_1.classList.add("b") } } } if (!fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ i2.classList.add("c") } } //显示楼层 const spanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.con div.info span.like span")).lineHeight //在没有文本的时候height会为0,所以用line-height for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.attributes["data-id"].value}`); xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style",`height:${spanHeight}; margin-right:14px`); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (document.querySelector(floorInFloor1)){ const FIFSpanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.reply-box div.reply-item.reply-wrap div.info span.like span")).lineHeight for (let i4 of document.querySelectorAll(separateReply2)){ const i4_2=i4.querySelectorAll(floorInFloor2) for (let i4_2_1 of i4_2){ const i4_2_1_1=i4_2_1.querySelector(".info") i4_2_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_2_1.attributes["data-id"].value}`) xhr.send() xhr.onload=()=>{ const data=xhr.response.data.floor const span=document.createElement("span") span.setAttribute("style",`height:${FIFSpanHeight};margin-right:14px`) span.innerHTML=`#${data}` i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[3]) } } } } //===end=== //===侦测 最热 li,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (WLPObserverOpening==false && document.querySelector(".tabs-order .clearfix .hot-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(WLPReplyCounts2)){ const RCChangeClass=document.querySelector(WLPReplyCounts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 WLPObserverOpening=true } //===end=== } //# //= 创意工坊live2d页面 //# //= 创意工坊插画页面 //# else if (page==5){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1=".list-item.reply-wrap:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2=".list-item.reply-wrap.c" const floorInFloor1=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap" //楼中楼 const floorInFloor2=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap:not(.d)" const replyOperation=".operation.more-operation .opera-list ul:not(.b)" //评论旁边的三个点 //e代表视频总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的li,特殊标识,方便操作 //===在页面显示总楼层数=== if (document.querySelector(WIPReplyCounts1)){ const owo1=document.querySelector(WIPReplyCounts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=42&oid=${unsafeWindow.location.pathname.split("/")[2]}&mode=2`) //获取最新评论 //获取url的文件名,以/为界分割,用最后一个,即oid xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.replies[0].rpid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo1}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.floor if (contains==true){ //如果总楼层数已显示,则改为替换数字,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo2}` } else{ const style1=unsafeWindow.getComputedStyle(document.querySelector(".tabs-order .clearfix .default-sort:not(owo)")) //读取最终样式,包括内联样式、嵌入样式和外部样式 const style2=unsafeWindow.getComputedStyle(document.querySelector(".tabs-order .clearfix .total-reply:not(owo)")) const owowo1=document.createElement("li") const owowo2=document.createElement("li") owowo1.innerHTML="楼层" owowo2.innerHTML=`${owowowo2}` owowo2.setAttribute("style",`height:${style2.height}; margin-right:${style2.marginRight}; line-height:${style2.lineHeight}; font-size:${style2.fontSize}; color:${style2.color}`) owowo1.classList.add("default-sort") //为设置网站自带css owowo2.classList.add("default-sort") //设置成这个class是因为设置成其他的都会出问题,并非为了设置网站自带css owowo1.classList.add("owo") owowo2.classList.add("owo") owowo2.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[2]) //向列表中指定位置插入一个项目 owo1.insertBefore(owowo2,owo1.childNodes[3]) document.querySelector("li.total-reply:not(.owo)").setAttribute("style","margin-right:20px") } } } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ if (i2.querySelector(replyOperation)){ const i2_1=i2.querySelector(replyOperation) const li=document.createElement("li"); li.setAttribute("class","fif") //fif=floor-in-floor li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) li.innerHTML="楼中楼楼层" i2_1.appendChild(li) i2_1.classList.add("b") } } } if (!fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ i2.classList.add("c") } } //显示楼层 const spanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.con div.info span.like span")).lineHeight //在没有文本的时候height会为0,所以用line-height for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.attributes["data-id"].value}`); xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style",`height:${spanHeight}; margin-right:14px`); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (document.querySelector(floorInFloor1)){ const FIFSpanHeight=unsafeWindow.getComputedStyle(document.querySelector("div.reply-box div.reply-item.reply-wrap div.info span.like span")).lineHeight for (let i4 of document.querySelectorAll(separateReply2)){ const i4_2=i4.querySelectorAll(floorInFloor2) for (let i4_2_1 of i4_2){ const i4_2_1_1=i4_2_1.querySelector(".info") i4_2_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_2_1.attributes["data-id"].value}`) xhr.send() xhr.onload=()=>{ const data=xhr.response.data.floor const span=document.createElement("span") span.setAttribute("style",`height:${FIFSpanHeight};margin-right:14px`) span.innerHTML=`#${data}` i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[3]) } } } } //===end=== //===侦测 最热 li,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (WIPObserverOpening==false && document.querySelector(".tabs-order .clearfix .hot-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(WIPReplyCounts2)){ const RCChangeClass=document.querySelector(WIPReplyCounts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 WIPObserverOpening=true } //===end=== } //# //= 创意工坊插画页面 //# //= 用户个人空间 //# else if (page==6){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1=".list-item.reply-wrap:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2=".list-item.reply-wrap.c" const floorInFloor1=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap" //楼中楼 const floorInFloor2=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap:not(.d)" const replyOperation=".operation.more-operation .opera-list ul:not(.b)" //评论旁边的三个点 //e代表动态总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表{████},特殊标识,方便操作 //===在动态页面显示总楼层数=== // if (document.querySelector(USPReplyCounts1)){ // const owo1=document.querySelector(USPReplyCounts1) // owo1.classList.add("e") // const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 // owo1.classList.remove("f") // const xhr1=new XMLHttpRequest() //获取最新评论 // xhr1.open("get",`//api.bilibili.com/x/v2/reply/main?type=1&oid=${unsafeWindow.aid}&mode=2`) // xhr1.responseType="json" // xhr1.withCredentials=true // xhr1.send() // xhr1.onload=()=>{ // const owowowo1=xhr1.response.data.replies[0].rpid // const xhr2=new XMLHttpRequest() //获取最新评论的楼层 // xhr2.open("get",`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo1}`) // xhr2.responseType="json" // xhr2.withCredentials=true // xhr2.send() // xhr2.onload=()=>{ // const owowowo2=xhr2.response.data.floor // if (contains==true){ //如果总楼层数已显示,则改为替换数字,否则创建新的 // const owowo1change=owo1.querySelector(".g") // owowo1change.innerHTML=`${owowowo2}` // } // else{ // const owowo1=document.createElement("span") // const owowo2=document.createElement("span") // owowo1.innerHTML=`${owowowo2}` // owowo2.innerHTML="楼" // owowo1.setAttribute("style","margin-left:17px; margin-right:3px; font-size:80%; color:#a1a1a1") // owowo2.setAttribute("style","font-size:90%; color:#a1a1a1") // owowo1.classList.add("g") // owo1.appendChild(owowo1) // owo1.appendChild(owowo2) // } // } // } // } //===end=== //===设置 回复 按钮样式=== if(document.querySelector(replyBtn)){ for(let i1 of document.querySelectorAll(replyBtn)){ i1.setAttribute("style","height:16px !important; padding-top:2px !important; padding-bottom:2px !important") i1.classList.add("b") } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ if (i2.querySelector(replyOperation)){ const i2_1=i2.querySelector(replyOperation) const li=document.createElement("li"); li.setAttribute("class","fif") //fif=floor-in-floor li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) li.innerHTML="楼中楼楼层" i2_1.appendChild(li) i2_1.classList.add("b") } } } if (!fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ i2.classList.add("c") } } //显示楼层 for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.attributes["data-id"].value}`); //xhr.open("get", `//api.bilibili.com/x/v2/reply/detail?type=12&oid=1&root=${i.attributes["data-id"].value}`); //另一个api接口,可用 xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style","height:16px; margin-right:14px"); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (document.querySelector(floorInFloor1)){ for (let i4 of document.querySelectorAll(separateReply2)){ const i4_2=i4.querySelectorAll(floorInFloor2) for (let i4_2_1 of i4_2){ const i4_2_1_1=i4_2_1.querySelector(".info") i4_2_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_2_1.attributes["data-id"].value}`) xhr.send() xhr.onload=()=>{ const data=xhr.response.data.floor const span=document.createElement("span") span.setAttribute("style","height:16px; margin-right:14px") span.innerHTML=`#${data}` i4_2_1_1.appendChild(span) i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[3]) } } } } //===end=== //===侦测 按热度排序 li,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (USPObserverOpening==false && document.querySelector(".tabs-order .clearfix .hot-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(USPReplyCounts2)){ const RCChangeClass=document.querySelector(USPReplyCounts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 USPObserverOpening=true } //===end=== } //# //= 用户个人空间 //# //= 含图片动态详细页面 //# else if (page==7){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1=".list-item.reply-wrap:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2=".list-item.reply-wrap.c" const floorInFloor1=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap" //楼中楼 const floorInFloor2=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap:not(.d)" const replyOperation=".operation.more-operation .opera-list ul:not(.b)" //评论旁边的三个点 //e代表动态总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的span,特殊标识,方便操作 //===在动态页面显示总楼层数=== if (document.querySelector(ADDPReplyCounts1)){ const owo1=document.querySelector(ADDPReplyCounts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id=${unsafeWindow.location.href.split("/")[3]}`) //获取动态oid xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.card.desc.rid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/main?type=11&oid=${owowowo1}&mode=2`) //获取最新评论 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.replies[0].rpid const xhr3=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${owowowo2}`) //获取最新评论的楼层 xhr3.send() xhr3.onload=()=>{ const owowowo3=xhr3.response.data.floor if (contains==true){ //如果总楼层数已显示,则更新,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo3}楼` } else{ const owowo1=document.createElement("span") owowo1.innerHTML=`${owowowo3}楼` owowo1.setAttribute("style","margin:0 !important; line-height:normal; font-size:14px; font-weight:700; padding-top:8px; padding-bottom:8px; float:right; opacity:0.7;") owowo1.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[1]) } } } } } //===end=== //===设置 回复 按钮样式=== if(document.querySelector(replyBtn)){ for(let i1 of document.querySelectorAll(replyBtn)){ i1.setAttribute("style","height:16px !important; padding-top:2px !importan; adding-bottom:2px !important") i1.classList.add("b") } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ if (i2.querySelector(replyOperation)){ const i2_1=i2.querySelector(replyOperation) const li=document.createElement("li"); li.setAttribute("class","fif") //fif=floor-in-floor li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) li.innerHTML="楼中楼楼层" i2_1.appendChild(li) i2_1.classList.add("b") } } } if (!fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ i2.classList.add("c") } } //显示楼层 for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i3.attributes["data-id"].value}`); //xhr.open("get", `//api.bilibili.com/x/v2/reply/detail?type=12&oid=1&root=${i.attributes["data-id"].value}`); //另一个api接口,可用 xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style","height:16px; margin-right:14px"); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (document.querySelector(floorInFloor1)){ for (let i4 of document.querySelectorAll(separateReply2)){ const i4_2=i4.querySelectorAll(floorInFloor2) for (let i4_2_1 of i4_2){ const i4_2_1_1=i4_2_1.querySelector(".info") i4_2_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=12&oid=1&rpid=${i4_2_1.attributes["data-id"].value}`) xhr.send() xhr.onload=()=>{ const data=xhr.response.data.floor const span=document.createElement("span") span.setAttribute("style","height:16px; margin-right:14px") span.innerHTML=`#${data}` i4_2_1_1.appendChild(span) i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[3]) } } } } //===end=== //===侦测 按热度排序 li,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (ADDPObserverOpening==false && document.querySelector(".tabs-order .clearfix .hot-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(ADDPReplyCounts2)){ const RCChangeClass=document.querySelector(ADDPReplyCounts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 ADDPObserverOpening=true } //===end=== } //# //= 含图片动态详细页面 //# //= 纯文字动态详细页面 //# else if (page==8){ const replyBtn=".reply.btn-hover:not(.b)" //排除已被 b class包含的元素 const separateReply1=".list-item.reply-wrap:not(.a)" //寻找相应属性的div 有独立楼层非楼中楼的回复 const separateReply2=".list-item.reply-wrap.c" const floorInFloor1=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap" //楼中楼 const floorInFloor2=".list-item.reply-wrap.c .con .reply-box .reply-item.reply-wrap:not(.d)" const replyOperation=".operation.more-operation .opera-list ul:not(.b)" //评论旁边的三个点 //e代表动态总楼层数已准备完成 //f代表出现切换 按xx排序 的操作,但还没刷新楼层数 //g代表总楼层数的span,特殊标识,方便操作 //===在动态页面显示总楼层数=== if (document.querySelector(TDDPReplyCounts1)){ const owo1=document.querySelector(TDDPReplyCounts1) owo1.classList.add("e") const contains=owo1.classList.contains("f") //返回布尔值,判断指定的类名是否存在 owo1.classList.remove("f") const xhr1=createXhr(`//api.bilibili.com/x/v2/reply/main?type=17&oid=${unsafeWindow.location.href.split("/")[3]}&mode=2`) //获取最新评论 xhr1.send() xhr1.onload=()=>{ const owowowo1=xhr1.response.data.replies[0].rpid const xhr2=createXhr(`//api.bilibili.com/x/v2/reply/info?type=17&oid=1&rpid=${owowowo1}`) //获取最新评论的楼层 xhr2.send() xhr2.onload=()=>{ const owowowo2=xhr2.response.data.floor if (contains==true){ //如果总楼层数已显示,则更新,否则创建新的 const owowo1change=owo1.querySelector(".g") owowo1change.innerHTML=`${owowowo2}楼` } else{ const owowo1=document.createElement("span") owowo1.innerHTML=`${owowowo2}楼` owowo1.setAttribute("style","margin:0 !important; line-height:normal; font-size:14px; font-weight:700; padding-top:8px; padding-bottom:8px; float:right; opacity:0.7;") owowo1.classList.add("g") owo1.insertBefore(owowo1,owo1.childNodes[1]) } } } } //===end=== //===设置 回复 按钮样式=== if(document.querySelector(replyBtn)){ for(let i1 of document.querySelectorAll(replyBtn)){ i1.setAttribute("style","height:16px !important; padding-top:2px !importan; adding-bottom:2px !important") i1.classList.add("b") } } //===end=== //===显示 显示楼中楼 按钮 && 显示独立非楼中楼评论楼层=== if (document.querySelector(separateReply1)) { //显示 显示楼中楼 按钮,以及对应功能;当 fifButton 为OFF的时候则切换不显示按钮,变成直接显示楼层 if (fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ if (i2.querySelector(replyOperation)){ const i2_1=i2.querySelector(replyOperation) const li=document.createElement("li"); li.setAttribute("class","fif") //fif=floor-in-floor li.addEventListener("click",(()=>{ //点击事件 i2.classList.add("c") })) li.innerHTML="楼中楼楼层" i2_1.appendChild(li) i2_1.classList.add("b") } } } if (!fifButton){ for (let i2 of document.querySelectorAll(separateReply1)){ i2.classList.add("c") } } //显示楼层 for (let i3 of document.querySelectorAll(separateReply1)) { i3.classList.add("a"); const qwq = i3.querySelector(".info"); const xhr = createXhr(`//api.bilibili.com/x/v2/reply/info?type=17&oid=1&rpid=${i3.attributes["data-id"].value}`); xhr.send(); xhr.onload = () => { const data = xhr.response.data.floor const qwqwq = document.createElement("span"); qwqwq.setAttribute("style","height:16px; margin-right:14px"); qwqwq.innerHTML = `#${data}`; qwq.insertBefore(qwqwq,qwq.childNodes[3]) //加在div info里的第三位 } } } //===end=== //===赋予 楼中楼楼层 按钮功能,即显示楼中楼楼层=== if (document.querySelector(floorInFloor1)){ for (let i4 of document.querySelectorAll(separateReply2)){ const i4_2=i4.querySelectorAll(floorInFloor2) for (let i4_2_1 of i4_2){ const i4_2_1_1=i4_2_1.querySelector(".info") i4_2_1.classList.add("d") const xhr=createXhr(`//api.bilibili.com/x/v2/reply/info?type=17&oid=1&rpid=${i4_2_1.attributes["data-id"].value}`) xhr.send() xhr.onload=()=>{ const data=xhr.response.data.floor const span=document.createElement("span") span.setAttribute("style","height:16px; margin-right:14px") span.innerHTML=`#${data}` i4_2_1_1.appendChild(span) i4_2_1_1.insertBefore(span,i4_2_1_1.childNodes[3]) } } } } //===end=== //===侦测 按热度排序 li,出现变动就改变replyCounts的class,做到和评论总数同步的刷新=== if (TDDPObserverOpening==false && document.querySelector(".tabs-order .clearfix .hot-sort")){ //observer仅需开启一次,过多的开启会拖累性能,脚本的每次循环不会重置observer const observerTarget=document.querySelector(".tabs-order .clearfix .hot-sort") const observerConfig={attributes: true,childList: true,subtree: true,classList:true} const observerCallback=()=>{ if (document.querySelector(TDDPReplyCounts2)){ const RCChangeClass=document.querySelector(TDDPReplyCounts2) //RCChangeClass=replyCountsChangeClass RCChangeClass.classList.remove("e") RCChangeClass.classList.add("f") } } const observer=new MutationObserver(observerCallback) //创建一个观察器并传入回调参数 observer.observe(observerTarget,observerConfig) //以这两个配置开始观察 TDDPObserverOpening=true } //===end=== } loopTime+=1 //console.timeEnd() }, 1000); })();