b-live-random-send-test

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

目前為 2022-08-09 提交的版本,檢視 最新版本

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @author          Gamyou
// @version         1.3.0
// @note            22-08-05 1.3.0 增加播放器底部登录提示的隐藏功能
// @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(){window.autoSendDanmuModuleLoaded=!1;let e,t,a,l,d,n,i,o,c,r,s,p,u,m,h,b={version:3,random:!0,data1:{available:!0,values:["绿豆","红豆","黄豆","蓝猫"]},data2:{available:!0,values:["红","接天莲叶无穷碧,映日荷花别样红。"]},data3:{available:!0,values:["黄","儿童急走追黄蝶,飞入菜花无处寻。"]},data4:{available:!0,values:["蓝","沧海月明珠有泪,蓝田日暖玉生烟。"]},data5:{available:!0,values:["绿","惟有绿荷红菡萏,卷舒开合任天真。"]}},g=[],v=[],x=null,y=0,k=10,f=0,C=0,E=e=>{},w=e=>{},L=e=>{};const D=()=>(new Date).getTime(),A=(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(),f=D(),++y,console.log("=================> "+(new Date).toLocaleString()+" 弹幕发送成功 "+y+" 次,第【"+t+"】条数据 === "+e)):alert("找不到发送按钮,请尝试刷新页面")},S=e=>{if(!e||""==e)return!0;return new RegExp("^[ ]+$").test(e)},z=()=>{for(let e=0;e<g.length;e++)clearInterval(g[e]),g[e]=null;g=[]},M=()=>{let e=new Date(new Date((new Date).setDate((new Date).getDate()+1)).toDateString()).getTime()-D();console.log("=================> 设置第二天凌晨签到定时器【"+e+"】"),setTimeout(()=>{A("签到",0),console.log("++++++++++++++++++++++> 完成签到发送,进入下一轮递归签到发送 <++++++++++++++++++++++"),M()},e)},I=()=>{e.checked=b.random,t.checked=b.data1.available,a.checked=b.data2.available,l.checked=b.data3.available,d.checked=b.data4.available,n.checked=b.data5.available},B=()=>c.style.display="block",F=()=>{I(),c.style.display="none"},R=()=>{if(b.data1.values.length<=0&&b.data2.values.length<=0&&b.data3.values.length<=0&&b.data4.values.length<=0&&b.data5.values.length<=0)return v||[];let e=[];e=b.data1.available?e.concat(b.data1.values):e,e=b.data2.available?e.concat(b.data2.values):e,e=b.data3.available?e.concat(b.data3.values):e,e=b.data4.available?e.concat(b.data4.values):e,e=b.data5.available?e.concat(b.data5.values):e,v=e,b.random?v=(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):C=0},T=()=>{b.data1.values=S(r.value)?[]:r.value.split("|"),b.data2.values=S(s.value)?[]:s.value.split("|"),b.data3.values=S(p.value)?[]:p.value.split("|"),b.data4.values=S(u.value)?[]:u.value.split("|"),b.data5.values=S(m.value)?[]:m.value.split("|"),b.random=e.checked,b.data1.available=t.checked,b.data2.available=a.checked,b.data3.available=l.checked,b.data4.available=d.checked,b.data5.available=n.checked,R(),E(b),h.style.display="block",setTimeout(()=>{h.style.display="none",c.style.display="none"},1500)},j=()=>{v.length<1?alert("请任意在一个分组里输入一条弹幕"):(b.random&&(C=Math.floor(Math.random()*v.length)),A(v[C],C),++C>=v.length&&(C=0))},H=()=>{let e=0;x?(console.log("=================> "+(new Date).toLocaleString()+" 停止发送弹幕"),clearInterval(x),x=null,console.log("=================> "+(new Date).toLocaleString()+" 停止成功!!"),i.style.background="rgba(217,157,27,1)",i.textContent="开始",o.removeAttribute("disabled")):(e=S(o.value)?6e5:1e3*o.value,j(),console.log("=================> "+(new Date).toLocaleString()+" 开启定时器"),x=setInterval(j,e),console.log("=================> "+(new Date).toLocaleString()+" 开启成功!!"),i.style.background="#ff0000",i.textContent="停止",o.setAttribute("disabled","disabled"))},N=()=>{let b=document.getElementsByClassName("bottom-actions p-relative")[0];if(!b)return void(0>=--k&&(window.autoSendDanmuModuleLoaded=!0,z(),L({text:"没能找到发送按钮的所属元素,请刷新重试",title:"加载错误,点击刷新页面",image:"https://www.bilibili.com/favicon.ico",highlight:!0,timeout:1e4,onclick:()=>location.reload()})));z();let g=document.createElement("div");g.textContent="弹幕设置",g.style.textAlign="center",g.style.fontSize="16px",g.style.fontWeight="700",g.style.color="#1c5adc",g.style.lineHeight="30px";let v=document.createElement("div");v.style.color="#0b81cc",v.style.textAlign="center",v.style.fontStyle="italic",v.style.height="25px",v.innerHTML='任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';let x=document.createElement("div");x.textContent="分组 1 :",x.classList.add("danmu-group-title"),(t=document.createElement("input")).type="checkbox",t.id="group1Checkbox",t.checked=!0;let y=document.createElement("label");y.setAttribute("for","group1Checkbox");let f=document.createElement("div");f.classList.add("danmu-group-check"),f.appendChild(t),f.appendChild(y),(r=document.createElement("textarea")).classList.add("danmu-group-textarea"),r.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let C=document.createElement("div");C.textContent="分组 2 :",C.classList.add("danmu-group-title"),(a=document.createElement("input")).type="checkbox",a.id="group2Checkbox",a.checked=!0;let E=document.createElement("label");E.setAttribute("for","group2Checkbox");let w=document.createElement("div");w.classList.add("danmu-group-check"),w.appendChild(a),w.appendChild(E),(s=document.createElement("textarea")).classList.add("danmu-group-textarea"),s.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let D=document.createElement("div");D.textContent="分组 3 :",D.classList.add("danmu-group-title"),(l=document.createElement("input")).type="checkbox",l.id="group3Checkbox",l.checked=!0;let A=document.createElement("label");A.setAttribute("for","group3Checkbox");let S=document.createElement("div");S.classList.add("danmu-group-check"),S.appendChild(l),S.appendChild(A),(p=document.createElement("textarea")).classList.add("danmu-group-textarea"),p.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let M=document.createElement("div");M.textContent="分组 4 :",M.classList.add("danmu-group-title"),(d=document.createElement("input")).type="checkbox",d.id="group4Checkbox",d.checked=!0;let I=document.createElement("label");I.setAttribute("for","group4Checkbox");let R=document.createElement("div");R.classList.add("danmu-group-check"),R.appendChild(d),R.appendChild(I),(u=document.createElement("textarea")).classList.add("danmu-group-textarea"),u.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let j=document.createElement("div");j.textContent="分组 5 :",j.classList.add("danmu-group-title"),(n=document.createElement("input")).type="checkbox",n.id="group5Checkbox",n.checked=!0;let N=document.createElement("label");N.setAttribute("for","group5Checkbox");let O=document.createElement("div");O.classList.add("danmu-group-check"),O.appendChild(n),O.appendChild(N),(m=document.createElement("textarea")).classList.add("danmu-group-textarea"),m.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let P=document.createElement("span");P.textContent="随机",P.title="将合并所有分组数据,从中随机选出一条发送",P.style.fontSize="16px",P.style.verticalAlign="middle",P.style.marginRight="4px",P.style.color="#095ca2",P.style.cursor="help",(e=document.createElement("input")).type="checkbox",e.id="rdmCheckbox",e.checked=!0;let W=document.createElement("label");W.setAttribute("for","rdmCheckbox");let Y=document.createElement("div");Y.classList.add("random-check"),Y.style.marginLeft="10px",Y.appendChild(P),Y.appendChild(e),Y.appendChild(W),(h=document.createElement("span")).textContent="设置成功",h.style.fontSize="16px",h.style.color="#128712",h.style.display="none";let $=document.createElement("div");$.style.textAlign="center",$.style.display="inline-block",$.style.verticalAlign="middle",$.style.width="34%",$.appendChild(h);let q=document.createElement("i");q.setAttribute("title","应用"),q.classList.add("el-button"),q.classList.add("el-icon-check"),q.classList.add("is-circle"),q.addEventListener("click",T);let G=document.createElement("i");G.setAttribute("title","关闭"),G.classList.add("el-button"),G.classList.add("el-icon-close"),G.classList.add("is-circle"),G.addEventListener("click",F);let J=document.createElement("div");J.style.display="inline-block",J.style.verticalAlign="middle",J.appendChild(q),J.appendChild(G);let K=document.createElement("div");K.style.width="100%",K.style.lineHeight="35px",K.appendChild(Y),K.appendChild($),K.appendChild(J);let Q=document.createElement("div");Q.style.height="calc(98% - 30px - 25px)",Q.appendChild(x),Q.appendChild(f),Q.appendChild(r),Q.appendChild(C),Q.appendChild(w),Q.appendChild(s),Q.appendChild(D),Q.appendChild(S),Q.appendChild(p),Q.appendChild(M),Q.appendChild(R),Q.appendChild(u),Q.appendChild(j),Q.appendChild(O),Q.appendChild(m),Q.appendChild(K),(c=document.createElement("div")).style.backgroundColor="#d4f2e0",c.style.borderRadius="2px",c.style.width="100%",c.style.height="100%",c.style.overflowY="auto",c.style.position="absolute",c.style.left="0",c.style.top="0",c.style.zIndex="999",c.style.display="none",c.appendChild(g),c.appendChild(v),c.appendChild(Q),document.getElementById("aside-area-vm").appendChild(c),(i=document.createElement("button")).textContent="开始",i.style.minWidth="65px",i.style.height="24px",i.style.fontSize="12px",i.style.borderRadius="4px",i.style.color="#ffffff",i.style.background="rgba(217,157,27,1)",i.style.border="0",i.style.cursor="pointer",i.addEventListener("click",H);let U=document.createElement("span");U.textContent="每",U.style.color="#ffffff",U.style.fontSize="12px",U.style.marginLeft="4px",U.style.backgroundColor="#ec6c1b",(o=document.createElement("input")).value=600,o.style.width="25px",o.style.height="15px",o.style.margin="0 3px",o.style.border="0",o.style.borderRadius="3px",o.setAttribute("oninput","this.value = this.value.replace(/[^0-9]/g, '')");let V=document.createElement("span");V.textContent="秒发送",V.style.color="#ffffff",V.style.fontSize="12px",V.style.backgroundColor="#ec6c1b",V.style.marginRight="4px";let X=document.createElement("i");X.classList.add("el-icon-setting");let Z=document.createElement("button");Z.title="设置",Z.classList.add("el-button"),Z.classList.add("el-button--mini"),Z.classList.add("is-circle"),Z.addEventListener("click",B),Z.appendChild(X);let _=document.createElement("div");_.style.position="absolute",_.appendChild(i),_.appendChild(U),_.appendChild(o),_.appendChild(V),_.appendChild(Z),b.appendChild(_),window.autoSendDanmuModuleLoaded=!0},O=()=>console.info(v),P=e=>{e&&(b.version===e.version?b=e:2===e.version?(b.data1=e.data1,b.data2=e.data2,b.data3=e.data3,b.data4=e.data4,b.data5=e.data5,E(b)):(b.data1.values=e.data1?e.data1:b.data1.values,b.data2.values=e.data2?e.data2:b.data2.values,b.data3.values=e.data3?e.data3:b.data3.values,b.data4.values=e.data4?e.data4:b.data4.values,b.data5.values=e.data5?e.data5:b.data5.values,E(b))),I(),r.value=b.data1.values.join("|"),s.value=b.data2.values.join("|"),p.value=b.data3.values.join("|"),u.value=b.data4.values.join("|"),m.value=b.data5.values.join("|"),R()},W=e=>E=e,Y=e=>e,$=e=>L=e;(()=>{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;}.random-check{display:inline-block;margin:0 5px;vertical-align:middle;}.random-check label{display:inline-block;vertical-align:middle;border:1px solid #bdc3c7;border-radius:60px;width:40px;height:18px;position:relative;transition:all .3s;}.random-check input{display:none;}.random-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;}.random-check :checked ~ label{background-color:#26b22b;border-color:#26b22b;}.random-check :checked ~ label:before{left:22px;background-color:#fff;}.danmu-group-check{display:inline-block;margin:0 5px;vertical-align:middle;}.danmu-group-check label{display:inline-block;vertical-align:middle;border:1px solid #bdc3c7;border-radius:60px;width:40px;height:18px;position:relative;transition:all .3s;}.danmu-group-check input{display:none;}.danmu-group-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;}.danmu-group-check :checked ~ label{background-color:#26b22b;border-color:#26b22b;}.danmu-group-check :checked ~ label:before{left:22px;background-color:#fff;}',document.head.appendChild(t)})(),window.addEventListener("load",()=>{g[g.length]=setInterval(N,1500),(()=>{let e=document.getElementById("switch-login-guide-vm");e?e.style.setProperty("display","none","important"):console.warn("====================> DOM id【switch-login-guide-vm】丢失 <====================");let t=document.getElementById("my-dear-haruna-vm");t?t.style.setProperty("display","none","important"):console.warn("====================> DOM id【my-dear-haruna-vm】丢失 <====================")})(),window.arrayInfo=O,window.setDanmuData=P,window.storeDanmuData=W,window.removeDanmuData=Y,window.setNotification=$,M()})}();