// ==UserScript== // @name bili指挥部(精准降落) // @namespace http://tampermonkey.net/ // @version 1.2 // @description 查找弹幕中的"指挥部"关键词,实现自动跳过片头 // @author kakasearch // @match *://www.bilibili.com/* // @connect comment.bilibili.com // @run-at document-end // @grant GM_xmlhttpRequest // @license MIT // @downloadURL none // ==/UserScript== function add_btn(){//添加开关,文字id bili_pass_text,开关danmu-pass-switch let otest let btn = '' let init_btn = setInterval(function(){ otest = document.querySelector("div.bilibili-player-video-danmaku-root") if(otest){clearInterval(init_btn)//成功进入页面,开始执行功能 let checked = '' if(setting.pass_op){//此p跳op checked ='checked'}//默认开启 let otest = document.querySelector("div.bilibili-player-video-danmaku-root") let node=document.querySelector("div.bilibili-player-video-danmaku-setting") let nodestr = '
关闭指挥部
' let newnode=document.createRange().createContextualFragment(nodestr); btn = document.querySelector("#danmu-pass-switch") if(btn){info('重复添加')} //只添加一次 else{otest.insertBefore(newnode,node) ///添加开关节点 } let fill = document.querySelector("#danmu-pass-fill") let text = document.querySelector("#danmu-pass-text") btn = document.querySelector("#danmu-pass-switch") if(btn .checked){ //开 fill.setAttribute('fill','#00A1D6') text.innerHTML='关闭指挥部' setting.pass_op = 1//恢复默认 }else{ //off fill.setAttribute('fill','#757575') text.innerHTML='开启指挥部' //本片所有剧集取消跳过 setting.pass_op = 0 } btn.addEventListener('click',function(){ if(btn .checked){ //开 fill.setAttribute('fill','#00A1D6') text.innerHTML='关闭指挥部' setting.pass_op = 1//恢复默认 }else{ //off fill.setAttribute('fill','#757575') text.innerHTML='开启指挥部' //本片所有剧集取消跳过 setting.pass_op = 0 } }); } } ) } var setting={ keyword:['感谢指挥部','精准降落','反手炸了指挥部','指挥部','指挥官','精准落地','感谢指路','精准'], badword:['呼叫','[吗呢怎么了??]'],//含有这些词的弹幕将被排除,例如 呼叫指挥部,指挥部呢? max_time:300,//单位秒,最大跳过时长,此时长之外的将视为不可信,0为不限制 min_time:10,//单位秒,最小跳过时长,此时长之外的将视为不可信,0为不限制 react_time:3,//弹幕发送的反应时间 cid:'',//控制切p debug : 0,//开发模式 pass_op : 1,//记录次剧集是否跳过 } function info(){ const arg = Array.from(arguments); arg.unshift(`color: white; background-color:#2274A5`); arg.unshift('%c bili指挥部:'); console["info"].apply(console, arg); } function get_danmu(cid){//获取弹幕 if(setting.debug){ info('开始获取弹幕') } GM_xmlhttpRequest({ method: 'GET', url: 'https://comment.bilibili.com/'+cid+'.xml', onload: function(xhr) { let found = 0 let key_length = setting.keyword.length let bad_length = setting.badword.length if (xhr.status == 200) { let text = xhr.responseText.replace(/<\/d>/g,'\n')//弹幕中找指挥部 for(let i=0;i (.*?"+setting.keyword[i]+".*)", "gi"); let result = pattern1.exec(text) if(result){ let danmu = result[2]//弹幕内容 for(let k=0;k=setting.min_time)||setting.max_time<=0){//指挥部可信 if(setting.debug){ info('找到指挥部,关键词',setting.keyword[i]) } let video= document.querySelector("video") video.currentTime = target-setting.react_time video.play() found = 1 info('已降落至指挥部,指示词:',setting.keyword[i]) break }else{ if(setting.debug){ info('指挥部不可信,当前跳转时长范围:',setting.min_time,'--',setting.max_time) info(result) } } } } if(found==0){ info('未找到指挥部') if(setting.debug){ info( text) } } } else { info('获取弹幕失败') } } }); } function initfun(){ //info('qie p') add_btn()//加开关 let init = setInterval(function(){ let cid = document.querySelector(" li.bilibili-player-video-btn-menu-list.bilibili-player-active.bilibili-player-blink").getAttribute('data-id') if(cid &&cid !=setting.cid){clearInterval(init) //成功进入页面,开始执行功能 if(setting.pass_op){//开关控制是否要跳op setting.cid = cid//保证只允行1次 get_danmu(cid) }else{info('off')} } },100) } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// (function() { initfun() let video= document.querySelector("#bofqi") let observer = new MutationObserver(initfun) observer.observe(video,{childList: true});//检测video变化,防止中途切p失效 // Your code here... })();