bilibili-live-random-send

定时从设置的字幕中随机取出一条在B站直播间发送,需先登录(不可用)B站账号

目前為 2023-04-16 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/447937/1176443/bilibili-live-random-send.js

// ==UserScript==
// @author          Gamyou
// @version         1.5.2
// @note            23-04-16 1.5.2 修复活动直播间room_id获取失败的问题
// @note            23-03-12 1.5.0 适配框架2.4.0版本
// @note            23-03-08 1.4.6 隐藏弹幕输入框上层显示的登录(不可用)提示层
// @note            23-02-10 1.4.5 隐藏播放器左上角的“小橙车”提示
// @note            22-08-28 1.4.4 解決定時器在浏览器繁忙时时间出现偏差的问题
// @note            22-08-26 1.4.3 修复正则替换方法not found的问题
// @note            22-08-14 1.4.2 修复B站直播间因活动而嵌套网页而导致房间号解析出错的BUG
// @note            22-08-14 1.4.1 修复B站直播间因活动而嵌套网页而导致脚本加载出错的BUG
// @note            22-08-13 1.4.0 实现阿B各直播间数据分离保存和油猴脚本更新提示功能
// @note            22-08-05 1.3.0 增加播放器底部登录(不可用)提示和Haruna的隐藏功能
// @note            22-07-29 1.2.6 修复初始化后的常量被赋值和没能初始化成功组件时系统提示加载超时的问题
// @note            22-07-24 1.2.5 增加分组启用按钮,并优化设置面板样式
// @note            22-07-23 1.2.4 修复弹幕分组数据都为空时,旧数据重复合并的BUG
// @note            22-07-16 1.2.3 修复设置弹幕时旧(初始)数据没有清空的BUG
// @note            22-06-24 1.2.2 优化部分代码
// @note            22-06-20 1.2.1 修复定时停止不能再开始的BUG
// @note            22-06-19 1.2.0 添加弹幕设置功能
// ==/UserScript==





!function(){const e=URL.createObjectURL(new Blob(["(",function(){const e={};self.onmessage=(t=>{switch(t.data.command){case"interval:start":const a=setInterval(()=>postMessage({message:"interval:tick",id:t.data.id}),t.data.interval);e[t.data.id]=a;break;case"interval:clear":clearInterval(e[t.data.id]),postMessage({message:"interval:cleared",id:t.data.id}),delete e[t.data.id];break;case"timeout:start":const l=setTimeout(()=>postMessage({message:"timeout:tick",id:t.data.id}),t.data.timeout);e[t.data.id]=l;break;case"timeout:clear":clearTimeout(e[t.data.id]),postMessage({message:"timeout:cleared",id:t.data.id}),delete e[t.data.id]}})}.toString(),")()"],{type:"application/javascript"})),t=new Worker(e);URL.revokeObjectURL(e);const a={id:0,callbacks:{},setInterval:(e,l,n)=>{const d=++a.id;return a.callbacks[d]={fn:e,context:n},t.postMessage({command:"interval:start",interval:l,id:d}),d},setTimeout:(e,l,n)=>{const d=++a.id;return a.callbacks[d]={fn:e,context:n},t.postMessage({command:"timeout:start",timeout:l,id:d}),d},onMessage:e=>{switch(e.data.message){case"interval:tick":case"timeout:tick":const t=a.callbacks[e.data.id];t&&t.fn&&t.fn.apply(t.context);break;case"interval:cleared":case"timeout:cleared":delete a.callbacks[e.data.id]}},clearInterval:e=>t.postMessage({command:"interval:clear",id:e}),clearTimeout:e=>t.postMessage({command:"timeout:clear",id:e})};t.onmessage=a.onMessage.bind(a);let l,n,d,i,s,o,c,r,u,p,m,h,b,g,v,x={version:3,random:!0,data1:{available:!0,values:["弹幕①","弹幕②"]},data2:{available:!0,values:["弹幕③","弹幕④"]},data3:{available:!0,values:["弹幕⑤","弹幕⑥"]},data4:{available:!0,values:["弹幕⑦","弹幕⑧"]},data5:{available:!0,values:["弹幕⑨","弹幕Ⅹ"]}},k={},f=[],E=[],y=null,C=null,w=null,L=0,B=200,A=0,M=0,I=(Math.floor(-15*Math.random()),e=>{alert("请更新油猴脚本"),window.location.href=S}),D=(e,t)=>null,T=(e,t)=>{console.warn('===> No implementation "setGmValue" method.')},z=e=>{console.warn('===> No implementation "delGmValue" method.')};const S="https://gf.qytechs.cn/scripts/446725-b%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E5%AE%9A%E6%97%B6%E5%8F%91%E9%9A%8F%E6%9C%BA%E5%BC%B9%E5%B9%95/code/B%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E5%AE%9A%E6%97%B6%E5%8F%91%E9%9A%8F%E6%9C%BA%E5%BC%B9%E5%B9%95.user.js",F=window.location.pathname.replace(/^\/(\S+\/)*/g,""),j=()=>(new Date).getTime(),R=(e,t)=>{let a=document.getElementById("aside-area-vm").getElementsByClassName("chat-input border-box")[0];if(!a)return void alert("找不到输入弹幕文本框,请尝试刷新页面");let l=document.getElementsByClassName("bl-button live-skin-highlight-button-bg live-skin-button-text bl-button--primary bl-button--small")[0];l?(a.value=e,a.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0})),l.click(),lastSent=j(),++L,console.log("===> "+(new Date).toLocaleString()+" 弹幕发送成功 "+L+" 次,第【"+t+"】条数据 === "+e)):alert("找不到发送按钮,请尝试刷新页面")},G=e=>{if(!e||""==e)return!0;return new RegExp("^[ ]+$").test(e)},N=()=>{for(let e=0;e<f.length;e++)a.clearInterval(f[e]),f[e]=null;f=[]},P=()=>{if(!w){let e=new Date(new Date((new Date).setDate((new Date).getDate()+1)).toDateString()).getTime()-j();console.log("===> 设置凌晨打卡定时器【"+e+"】"),w=a.setTimeout(()=>{"停止"===c.textContent&&R(k.signText?k.signText:"打卡",0),console.log("===> 进入下一轮递归打卡"),a.clearTimeout(w),w=null,P()},e)}},V=()=>{l.checked=x.random,n.checked=x.data1.available,d.checked=x.data2.available,i.checked=x.data3.available,s.checked=x.data4.available,o.checked=x.data5.available},U=()=>u.style.display="block",H=()=>{V(),u.style.display="none"},O=()=>{if(x.data1.values.length<=0&&x.data2.values.length<=0&&x.data3.values.length<=0&&x.data4.values.length<=0&&x.data5.values.length<=0)return E||[];let e=[];e=x.data1.available?e.concat(x.data1.values):e,e=x.data2.available?e.concat(x.data2.values):e,e=x.data3.available?e.concat(x.data3.values):e,e=x.data4.available?e.concat(x.data4.values):e,e=x.data5.available?e.concat(x.data5.values):e,E=e,x.random?E=(e=>{for(let t=0;t<e.length;t++){const a=Math.floor(Math.random()*e.length),l=e[t];e[t]=e[a],e[a]=l}return e})(e):A=0},W=()=>{x.data1.values=G(p.value)?[]:p.value.split("|"),x.data2.values=G(m.value)?[]:m.value.split("|"),x.data3.values=G(h.value)?[]:h.value.split("|"),x.data4.values=G(b.value)?[]:b.value.split("|"),x.data5.values=G(g.value)?[]:g.value.split("|"),x.random=l.checked,x.data1.available=n.checked,x.data2.available=d.checked,x.data3.available=i.checked,x.data4.available=s.checked,x.data5.available=o.checked,O(),T(F,x),v.style.display="block",setTimeout(()=>{v.style.display="none",u.style.display="none"},1500)},$=()=>E.length<1?(I({text:"请任意在一个分组里输入一条弹幕",title:"没有弹幕数据,请先设置",image:"https://www.bilibili.com/favicon.ico",highlight:!0,timeout:1e4}),!1):(x.random&&(A=Math.floor(Math.random()*E.length)),R(E[A],A),++A>=E.length&&(A=0),!0),q=()=>{let e=0;if(y)a.clearInterval(y),y=null,c.style.background="rgba(217,157,27,1)",c.textContent="开始",r.removeAttribute("disabled");else{if(e=G(r.value)?6e5:1e3*r.value,!$())return;y=a.setInterval($,e),c.style.background="#ff0000",c.textContent="停止",r.setAttribute("disabled","disabled")}},J=()=>{if(!document.getElementById("danmu-setting-panel")){console.log("===> 进行面板初始化");let e=document.getElementsByClassName("bottom-actions p-relative")[0];if(!e)return console.warn("===> bottom-actions节点丢失"),!1;(e=>{let t=document.createElement("div");t.textContent="弹幕设置",t.classList.add("danmu-random-setting-title");let a=document.createElement("div");a.classList.add("danmu-random-setting-tips"),a.innerHTML='任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';let x=document.createElement("div");x.classList.add("danmu-random-update-tips"),x.innerHTML='<span style="color:#f00">更新提示:</span>修复活动直播间房间号获取问题';let k=document.createElement("div");k.textContent="分组 1 :",k.classList.add("danmu-group-title"),(n=document.createElement("input")).type="checkbox",n.id="group1Checkbox",n.checked=!0;let f=document.createElement("label");f.setAttribute("for","group1Checkbox"),f.classList.add("switch-check-label");let E=document.createElement("div");E.classList.add("switch-check"),E.appendChild(n),E.appendChild(f),(p=document.createElement("textarea")).classList.add("danmu-group-textarea"),p.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let y=document.createElement("div");y.textContent="分组 2 :",y.classList.add("danmu-group-title"),(d=document.createElement("input")).type="checkbox",d.id="group2Checkbox",d.checked=!0;let C=document.createElement("label");C.setAttribute("for","group2Checkbox"),C.classList.add("switch-check-label");let w=document.createElement("div");w.classList.add("switch-check"),w.appendChild(d),w.appendChild(C),(m=document.createElement("textarea")).classList.add("danmu-group-textarea"),m.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let L=document.createElement("div");L.textContent="分组 3 :",L.classList.add("danmu-group-title"),(i=document.createElement("input")).type="checkbox",i.id="group3Checkbox",i.checked=!0;let B=document.createElement("label");B.setAttribute("for","group3Checkbox"),B.classList.add("switch-check-label");let A=document.createElement("div");A.classList.add("switch-check"),A.appendChild(i),A.appendChild(B),(h=document.createElement("textarea")).classList.add("danmu-group-textarea"),h.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let M=document.createElement("div");M.textContent="分组 4 :",M.classList.add("danmu-group-title"),(s=document.createElement("input")).type="checkbox",s.id="group4Checkbox",s.checked=!0;let I=document.createElement("label");I.setAttribute("for","group4Checkbox"),I.classList.add("switch-check-label");let D=document.createElement("div");D.classList.add("switch-check"),D.appendChild(s),D.appendChild(I),(b=document.createElement("textarea")).classList.add("danmu-group-textarea"),b.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let T=document.createElement("div");T.textContent="分组 5 :",T.classList.add("danmu-group-title"),(o=document.createElement("input")).type="checkbox",o.id="group5Checkbox",o.checked=!0;let z=document.createElement("label");z.setAttribute("for","group5Checkbox"),z.classList.add("switch-check-label");let S=document.createElement("div");S.classList.add("switch-check"),S.appendChild(o),S.appendChild(z),(g=document.createElement("textarea")).classList.add("danmu-group-textarea"),g.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let F=document.createElement("span");F.textContent="随机",F.title="将合并所有分组数据,从中随机选出一条发送",F.classList.add("danmu-random-switch-button-title"),(l=document.createElement("input")).type="checkbox",l.id="rdmCheckbox",l.checked=!0;let j=document.createElement("label");j.setAttribute("for","rdmCheckbox"),j.classList.add("switch-check-label");let R=document.createElement("div");R.classList.add("switch-check"),R.style.marginLeft="10px",R.appendChild(F),R.appendChild(l),R.appendChild(j),(v=document.createElement("span")).textContent="设置成功",v.classList.add("danmu-random-setting-success-text");let G=document.createElement("div");G.classList.add("danmu-random-setting-success-tips"),G.appendChild(v);let N=document.createElement("i");N.setAttribute("title","应用"),N.classList.add("el-button"),N.classList.add("el-icon-check"),N.classList.add("is-circle"),N.addEventListener("click",W);let P=document.createElement("i");P.setAttribute("title","关闭"),P.classList.add("el-button"),P.classList.add("el-icon-close"),P.classList.add("is-circle"),P.addEventListener("click",H);let V=document.createElement("div");V.classList.add("danmu-random-set-button-container"),V.appendChild(N),V.appendChild(P);let O=document.createElement("div");O.classList.add("danmu-random-setting-bottom"),O.appendChild(R),O.appendChild(G),O.appendChild(V);let $=document.createElement("div");$.style.height="calc(98% - 30px - 25px)",$.appendChild(k),$.appendChild(E),$.appendChild(p),$.appendChild(y),$.appendChild(w),$.appendChild(m),$.appendChild(L),$.appendChild(A),$.appendChild(h),$.appendChild(M),$.appendChild(D),$.appendChild(b),$.appendChild(T),$.appendChild(S),$.appendChild(g),$.appendChild(O),(u=document.createElement("div")).id="danmu-setting-panel",u.classList.add("danmu-random-setting-panel"),u.appendChild(t),u.appendChild(a),u.appendChild(x),u.appendChild($),document.getElementById("aside-area-vm").appendChild(u),(c=document.createElement("button")).textContent="开始",c.style.minWidth="65px",c.style.height="24px",c.style.fontSize="12px",c.style.borderRadius="4px",c.style.color="#ffffff",c.style.background="rgba(217,157,27,1)",c.style.border="0",c.style.cursor="pointer",c.addEventListener("click",q);let J=document.createElement("span");J.textContent="每",J.style.color="#ffffff",J.style.fontSize="12px",J.style.marginLeft="4px",J.style.backgroundColor="#ec6c1b",(r=document.createElement("input")).value=600,r.style.width="25px",r.style.height="15px",r.style.margin="0 3px",r.style.border="0",r.style.borderRadius="3px",r.setAttribute("oninput","this.value = this.value.replace(/[^0-9]/g, '')");let K=document.createElement("span");K.textContent="秒发送",K.style.color="#ffffff",K.style.fontSize="12px",K.style.backgroundColor="#ec6c1b",K.style.marginRight="4px";let Q=document.createElement("i");Q.classList.add("el-icon-setting");let X=document.createElement("button");X.title="设置",X.classList.add("el-button"),X.classList.add("el-button--mini"),X.classList.add("is-circle"),X.addEventListener("click",U),X.appendChild(Q);let Y=document.createElement("div");Y.style.position="absolute",Y.appendChild(c),Y.appendChild(J),Y.appendChild(r),Y.appendChild(K),Y.appendChild(X),e.appendChild(Y)})(e),(()=>{let e=D(F,null);e&&(x.version===e.version?x=e:2===e.version?(x.data1=e.data1,x.data2=e.data2,x.data3=e.data3,x.data4=e.data4,x.data5=e.data5,T(F,x)):(x.data1.values=e.data1?e.data1:x.data1.values,x.data2.values=e.data2?e.data2:x.data2.values,x.data3.values=e.data3?e.data3:x.data3.values,x.data4.values=e.data4?e.data4:x.data4.values,x.data5.values=e.data5?e.data5:x.data5.values,T(F,x))),V(),p.value=x.data1.values.join("|"),m.value=x.data2.values.join("|"),h.value=x.data3.values.join("|"),b.value=x.data4.values.join("|"),g.value=x.data5.values.join("|"),O()})(),console.log("===> 面板初始化完成")}return!0};(()=>{let e=document.createElement("link");e.rel="stylesheet",e.href="https://unpkg.com/[email protected]/lib/theme-chalk/index.css",document.head.appendChild(e);let t=document.createElement("style");t.setAttribute("type","text/css"),t.innerHTML='.danmu-group-title{font-size:14px;padding-left:2px;color:rgb(18, 56, 141);display:inline;margin-right:60%;vertical-align:middle;}.danmu-group-textarea{width:98%;min-height:100px;height:16%;margin:1px 0px 4px;border:0px;resize:none;}.el-button{display:inline-block;line-height:1;white-space:nowrap;cursor:pointer;background:#FFF;border:1px solid #DCDFE6;color:#606266;-webkit-appearance:none;text-align:center;-webkit-box-sizing:border-box;box-sizing:border-box;outline:0;margin:0;-webkit-transition:.1s;transition:.1s;font-weight:500;padding:12px 20px;font-size:14px;border-radius:4px}.el-button.is-circle{border-radius:50%;padding:12px}.el-button--mini.is-circle{padding:3px;}.el-button:focus,.el-button:hover{color:#409EFF;border-color:#c6e2ff;background-color:#ecf5ff}.el-icon-close.is-circle{padding:5px;color:#ff0000;border:1px solid #ff0000;margin-left:20px;}.el-icon-check.is-circle{padding:5px;color:#0000ff;border:1px solid #0000ff;margin-left:20px;}input[type="checkbox"]{display:none;}.switch-check{display:inline-block;margin:0 5px;vertical-align:middle;}.switch-check-label{display:inline-block;vertical-align:middle;border:1px solid #bdc3c7;border-radius:60px;width:40px;height:18px;position:relative;transition:all .3s;cursor:pointer;}.switch-check-label:before{width:14px;height:14px;content:"";display:inline-block;background-color:#bdc3c7;border-radius:100%;position:absolute;top:2px;left:4px;transition:all .3s;}.switch-check :checked ~ label{background-color:#26b22b;border-color:#26b22b;}.switch-check :checked ~ label:before{left:22px;background-color:#fff;}.danmu-random-setting-panel{background-color:#d4f2e0;border-radius:2px;width:100%;height:100%;overflow-y:auto;position:absolute;left:0px;top:0px;z-index:999;display:none;}.danmu-random-setting-title{text-align:center;font-size:16px;font-weight:700;color:#1c5adc;line-height:30px;}.danmu-random-setting-tips{color:#0b81cc;text-align:center;font-style:italic;}.danmu-random-update-tips{color:#0b81cc;text-align:center;font-size:13px;font-weight:700;margin:10px 0px;}.danmu-random-setting-bottom{width:100%;line-height:35px;}.danmu-random-switch-button-title{font-size:16px;vertical-align:middle;margin-right:4px;color:#095ca2;cursor:help;}.danmu-random-setting-success-tips{text-align:center;display:inline-block;vertical-align:middle;width:34%;}.danmu-random-setting-success-text{font-size:16px;color:#128712;display:none;}.danmu-random-set-button-container{display:inline-block;vertical-align:middle;}',document.head.appendChild(t)})(),window.runStart=(()=>{(()=>{if(!k.version)return!0;if("2.4.0"===k.version)return!1;{let e=k.version.split("."),t="2.4.0".split(".");if(e.length!=t.length)return!0;for(let a=0;a<e.length;a++)if(t[a]>e[a])return!0;return!1}})()?window.location.href=S:f[f.length]=a.setInterval(()=>{J()?(N(),(()=>{let e=document.getElementById("switch-login-guide-vm");e&&e.style.setProperty("display","none","important");let t=document.getElementById("my-dear-haruna-vm");t&&t.style.setProperty("display","none","important");let l=document.getElementById("shop-popover-vm");l&&l.style.setProperty("display","none","important"),C&&(a.clearInterval(C),C=null),C=a.setInterval(()=>{++M;let e=document.getElementsByClassName("lt-row")[0];e&&(e.style.setProperty("display","none","important"),C&&(a.clearInterval(C),C=null)),30<=M&&C&&(a.clearInterval(C),C=null)},1e4)})(),P(),console.log("===> 运行成功")):0>=--B&&(N(),console.log("===> 创建面板失败,停止初始化"))},1500)}),window.arrayInfo=(()=>console.info(E)),window.setGmNotice=(e=>I=e),window.setGmGetValue=(e=>D=e),window.setGmSetValue=(e=>T=e),window.setGmDelValue=(e=>e),window.setParentData=(e=>k=e),window.autoSendDanmuModuleLoaded=!0}();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址