// ==UserScript== // @name 斗鱼骆歆直播间插件(自动变色刷弹幕,一键续牌) // @namespace https://github.com/qianjiachun // @version 0.7 // @description 骆歆直播间刷好听/虚张声势专用。 // @author 小淳 // @match *://*.douyu.com/0* // @match *://*.douyu.com/1* // @match *://*.douyu.com/2* // @match *://*.douyu.com/3* // @match *://*.douyu.com/4* // @match *://*.douyu.com/5* // @match *://*.douyu.com/6* // @match *://*.douyu.com/7* // @match *://*.douyu.com/8* // @match *://*.douyu.com/9* // @match *://*.douyu.com/topic/* // @grant none // @downloadURL none // ==/UserScript== let barrageColorArr = []; let barrageArr = []; let barrageColorLength = 0; let barrageLength = 0; let timer; let barrageOffset = 0; let barrageColorOffset = 0; let isChangeColor = true; let save = {}; let isMatch = false; function addInfrastructure() { let style = document.createElement("style"); style.appendChild(document.createTextNode(` .bloop { background-color: rgba(255,255,255,0.8); width: 100%; height: 200px; position: relative; bottom: 200px; display: none; } .bicon { display: inline-block; vertical-align: middle; margin-right: 8px; } .bloop__switch { position: absolute; right: 0; bottom: 0; } `)); document.head.appendChild(style); } function insertModal() { let html = ""; let a = document.createElement("div"); a.className = "bloop"; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; a.innerHTML = html; let b = document.getElementsByClassName("layout-Player-chat")[0]; b.insertBefore(a, b.childNodes[0]); } function insertIcon() { let a = document.createElement("div"); a.className = "bicon"; a.innerHTML = ''; let a1 = document.createElement("div"); a1.className = "bicon"; a1.innerHTML = ''; let b = document.getElementsByClassName("PlayerToolbar-Wealth")[0]; b.insertBefore(a, b.childNodes[0]); b.insertBefore(a1, b.childNodes[0]); } function getBarrageColorArr() { // 获取已解锁的弹幕颜色 barrageColorArr.length = 0;// 清空数组 barrageColorLength = 0; let a = document.getElementsByClassName("FansBarrageColor-item"); if (a.length == 0) { isMatch = true; let b = document.getElementsByClassName("MatchSystemFansBarrageSwitcher")[0]; if (b != undefined) { b.click(); a = document.getElementsByClassName("MatchSystemFansBarrageColor-item"); } else { isMatch = false; } } else { isMatch = false; } for (let i = 0; i < a.length; i++) { let itemClassName = a[i].className; if (itemClassName.indexOf("is-lock") == -1) { barrageColorArr.push(i); barrageColorLength++; } } barrageColorLength = barrageColorLength - 1; } function getBarrageArr() { // 获取即将发送的弹幕数组 barrageArr.length = 0; barrageLength = 0; let a = document.getElementById("bloop__textarea").value; barrageArr = a.split("\n"); barrageLength = barrageArr.length - 1; } function selectBarrageColor(index) { // 选择粉丝弹幕 let a; if (isMatch == false) { a = document.getElementsByClassName("FansBarrageColor-item")[index]; } else{ document.getElementsByClassName("MatchSystemFansBarrageSwitcher")[0].click() a = document.getElementsByClassName("MatchSystemFansBarrageColor-item")[index]; } if (a != undefined) { a.click(); } } function sendBarrage(text) { // 发送弹幕 document.getElementsByClassName("ChatSend-txt")[0].value = text; document.getElementsByClassName("ChatSend-button")[0].click(); } function getSpeed() { return document.getElementById("bloop__text_speed").value; } function saveData() { let data = { text: document.getElementById("bloop__textarea").value, speed: getSpeed(), isChangeColor: isChangeColor, } localStorage.setItem("bloop_save", JSON.stringify(data)); // 存储弹幕列表 } function sendGift(gid, count, rid) { // gid: 268是荧光棒 // count: 数量 // rid: 房间号 return fetch("https://www.douyu.com/japi/prop/donate/mainsite/v1", { method: 'POST', mode: 'no-cors', credentials: 'include', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: 'propId=' + gid + '&propCount=' + count + '&roomId=' + rid + '&bizExt=%7B%22yzxq%22%3A%7B%7D%7D' }).then(res => { return res.json(); }) } function initFunc() { // 函数初始化 // 将onclick事件绑定在这里 window.showDom = function() { let a = document.getElementsByClassName("bloop")[0]; if (a.style.display != "block") { a.style.display = "block"; } else { a.style.display = "none"; } } window.changeColor = function() { isChangeColor = document.getElementById("bloop__checkbox_changeColor").checked; } window.startSend = function() { let ischecked = document.getElementById("bloop__checkbox_startSend").checked; if (ischecked == true) { // 开始发送 barrageOffset = 0; barrageColorOffset = 0; getBarrageArr(); getBarrageColorArr(); saveData(); timer = setInterval(() => { if (isChangeColor == true) { selectBarrageColor(barrageColorOffset); barrageColorOffset++; if (barrageColorOffset > barrageColorLength) { barrageColorOffset = 0; } } sendBarrage(barrageArr[barrageOffset]); barrageOffset++; if (barrageOffset > barrageLength) { barrageOffset = 0; } }, getSpeed()); } else{ // 停止发送 clearInterval(timer); } } window.continueFans = function() { fetch('https://www.douyu.com/member/cp/getFansBadgeList',{ method: 'GET', mode: 'no-cors', cache: 'default', credentials: 'include', }).then(res => { return res.text(); }).then(async (doc) => { doc = (new DOMParser()).parseFromString(doc, 'text/html'); let a = doc.getElementsByClassName("fans-badge-list")[0].lastElementChild; let n = a.children.length; let alertText = ""; for (let i = 0; i < n; i++) { let rid = a.children[i].getAttribute("data-fans-room"); // 获取房间号 await sleep(200).then(() => { sendGift(268, 1, rid).then(data => { if (data.msg == "success") { alertText += rid + "赠送荧光棒成功\n"; console.log(rid + "赠送一根荧光棒成功"); } else{ alertText += rid + "赠送失败\n"; console.log(rid + "赠送失败"); console.log(data); } }).catch(err => { alertText += rid + "赠送失败\n"; console.log(rid + "赠送失败"); console.log(err); }) }); } alert(alertText); }) } } function initDom() { // Dom初始化 addInfrastructure(); insertModal(); insertIcon(); } function initSet() { // 设置初始化 let ret = localStorage.getItem("bloop_save"); if (ret != null) { let retJson = JSON.parse(ret); document.getElementById("bloop__textarea").value = retJson.text; document.getElementById("bloop__checkbox_changeColor").checked = retJson.isChangeColor; document.getElementById("bloop__text_speed").value = retJson.speed; } } (function() { let intID = setInterval(() => { if (typeof(document.getElementsByClassName("ChatToolBar")[0]) != "undefined") { setTimeout(() => { initFunc(); initDom(); initSet(); }, 1000) clearInterval(intID); } },1000); })() function sleep(time) { return new Promise((resolve) => setTimeout(resolve, time)); }