Greasy Fork

Greasy Fork is available in English.

b-live-random-send-test

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

当前为 2023-03-11 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/447936/1160226/b-live-random-send-test.js

!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,o,s,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,A=40,B=0,I=0,M=e=>{alert("请更新油猴脚本"),window.location.href=z},D=(e,t)=>null,T=(e,t)=>{console.warn('===> No implementation "setGmValue" method.')},_=e=>{console.warn('===> No implementation "delGmValue" method.')};const z="http://greasyfork.icu/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",S=window.__NEPTUNE_IS_MY_WAIFU__?window.__NEPTUNE_IS_MY_WAIFU__.roomInfoRes.data.room_info.room_id:window.location.pathname.replace(/^\/(\S+\/)*/g,""),F=()=>(new Date).getTime(),N=(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=F(),++L,console.log("===> "+(new Date).toLocaleString()+" 弹幕发送成功 "+L+" 次,第【"+t+"】条数据 === "+e)):alert("找不到发送按钮,请尝试刷新页面")},j=e=>{if(!e||""==e)return!0;return new RegExp("^[ ]+$").test(e)},R=()=>{for(let e=0;e<f.length;e++)a.clearInterval(f[e]),f[e]=null;f=[]},U=()=>{if(!w){let e=new Date(new Date((new Date).setDate((new Date).getDate()+1)).toDateString()).getTime()-F();console.log("===> 设置凌晨打卡定时器【"+e+"】"),w=a.setTimeout(()=>{"停止"===c.textContent&&N(k.signText?k.signText:"打卡",0),console.log("===> 进入下一轮递归签到"),a.clearTimeout(w),w=null,U()},e)}},G=()=>{l.checked=x.random,n.checked=x.data1.available,d.checked=x.data2.available,i.checked=x.data3.available,o.checked=x.data4.available,s.checked=x.data5.available},P=()=>u.style.display="block",V=()=>{G(),u.style.display="none"},W=()=>{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):B=0},H=()=>{x.data1.values=j(p.value)?[]:p.value.split("|"),x.data2.values=j(m.value)?[]:m.value.split("|"),x.data3.values=j(h.value)?[]:h.value.split("|"),x.data4.values=j(b.value)?[]:b.value.split("|"),x.data5.values=j(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=o.checked,x.data5.available=s.checked,W(),T(S,x),v.style.display="block",setTimeout(()=>{v.style.display="none",u.style.display="none"},1500)},O=()=>E.length<1?(M({text:"请任意在一个分组里输入一条弹幕",title:"没有弹幕数据,请先设置",image:"https://www.bilibili.com/favicon.ico",highlight:!0,timeout:1e4}),!1):(x.random&&(B=Math.floor(Math.random()*E.length)),N(E[B],B),++B>=E.length&&(B=0),!0),Y=()=>{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=j(r.value)?6e5:1e3*r.value,!O())return;y=a.setInterval(O,e),c.style.background="#ff0000",c.textContent="停止",r.setAttribute("disabled","disabled")}},$=()=>{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 A=document.createElement("label");A.setAttribute("for","group3Checkbox"),A.classList.add("switch-check-label");let B=document.createElement("div");B.classList.add("switch-check"),B.appendChild(i),B.appendChild(A),(h=document.createElement("textarea")).classList.add("danmu-group-textarea"),h.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let I=document.createElement("div");I.textContent="分组 4 :",I.classList.add("danmu-group-title"),(o=document.createElement("input")).type="checkbox",o.id="group4Checkbox",o.checked=!0;let M=document.createElement("label");M.setAttribute("for","group4Checkbox"),M.classList.add("switch-check-label");let D=document.createElement("div");D.classList.add("switch-check"),D.appendChild(o),D.appendChild(M),(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"),(s=document.createElement("input")).type="checkbox",s.id="group5Checkbox",s.checked=!0;let _=document.createElement("label");_.setAttribute("for","group5Checkbox"),_.classList.add("switch-check-label");let z=document.createElement("div");z.classList.add("switch-check"),z.appendChild(s),z.appendChild(_),(g=document.createElement("textarea")).classList.add("danmu-group-textarea"),g.setAttribute("placeholder","请输入弹幕,多条弹幕请用“|”分隔");let S=document.createElement("span");S.textContent="随机",S.title="将合并所有分组数据,从中随机选出一条发送",S.classList.add("danmu-random-switch-button-title"),(l=document.createElement("input")).type="checkbox",l.id="rdmCheckbox",l.checked=!0;let F=document.createElement("label");F.setAttribute("for","rdmCheckbox"),F.classList.add("switch-check-label");let N=document.createElement("div");N.classList.add("switch-check"),N.style.marginLeft="10px",N.appendChild(S),N.appendChild(l),N.appendChild(F),(v=document.createElement("span")).textContent="设置成功",v.classList.add("danmu-random-setting-success-text");let j=document.createElement("div");j.classList.add("danmu-random-setting-success-tips"),j.appendChild(v);let R=document.createElement("i");R.setAttribute("title","应用"),R.classList.add("el-button"),R.classList.add("el-icon-check"),R.classList.add("is-circle"),R.addEventListener("click",H);let U=document.createElement("i");U.setAttribute("title","关闭"),U.classList.add("el-button"),U.classList.add("el-icon-close"),U.classList.add("is-circle"),U.addEventListener("click",V);let G=document.createElement("div");G.classList.add("danmu-random-set-button-container"),G.appendChild(R),G.appendChild(U);let W=document.createElement("div");W.classList.add("danmu-random-setting-bottom"),W.appendChild(N),W.appendChild(j),W.appendChild(G);let O=document.createElement("div");O.style.height="calc(98% - 30px - 25px)",O.appendChild(k),O.appendChild(E),O.appendChild(p),O.appendChild(y),O.appendChild(w),O.appendChild(m),O.appendChild(L),O.appendChild(B),O.appendChild(h),O.appendChild(I),O.appendChild(D),O.appendChild(b),O.appendChild(T),O.appendChild(z),O.appendChild(g),O.appendChild(W),(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(O),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",Y);let $=document.createElement("span");$.textContent="每",$.style.color="#ffffff",$.style.fontSize="12px",$.style.marginLeft="4px",$.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 q=document.createElement("span");q.textContent="秒发送",q.style.color="#ffffff",q.style.fontSize="12px",q.style.backgroundColor="#ec6c1b",q.style.marginRight="4px";let J=document.createElement("i");J.classList.add("el-icon-setting");let K=document.createElement("button");K.title="设置",K.classList.add("el-button"),K.classList.add("el-button--mini"),K.classList.add("is-circle"),K.addEventListener("click",P),K.appendChild(J);let Q=document.createElement("div");Q.style.position="absolute",Q.appendChild(c),Q.appendChild($),Q.appendChild(r),Q.appendChild(q),Q.appendChild(K),e.appendChild(Q)})(e),(()=>{let e=D(S,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(S,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(S,x))),G(),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("|"),W()})(),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((()=>{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}})())return alert("发随机弹幕脚本有新版本,请及时更新"),void(window.location.href=z);f[f.length]=a.setInterval(()=>{$()?(R(),(()=>{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(()=>{++I;let e=document.getElementsByClassName("lt-row")[0];e&&(e.style.setProperty("display","none","important"),C&&(a.clearInterval(C),C=null)),30<=I&&C&&(a.clearInterval(C),C=null)},1e4)})(),U(),console.log("===> 运行成功")):0>=--A&&(R(),console.log("===> 创建弹幕设置面板失败,停止初始化"))},1500)}),window.arrayInfo=(()=>console.info(E)),window.setGmNotice=(e=>M=e),window.setGmGetValue=(e=>D=e),window.setGmSetValue=(e=>T=e),window.setGmDelValue=(e=>e),window.setParentData=(e=>k=e),window.autoSendDanmuModuleLoaded=!0}();