// ==UserScript== // @name 斗鱼弹幕循环变色发送 // @namespace https://github.com/qianjiachun // @version 0.6 // @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 { width: 20px; height: 20px; display: inline-block; vertical-align: middle; } .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 b = document.getElementsByClassName("PlayerToolbar-Wealth")[0]; b.insertBefore(a, 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 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); } } } 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); })()