骆歆直播间刷好听/虚张声势专用。
当前为
// ==UserScript==
// @name 斗鱼弹幕循环变色发送
// @namespace https://github.com/qianjiachun
// @version 0.1
// @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
// ==/UserScript==
let barrageColorArr = [];
let barrageArr = [];
let barrageColorLength = 0;
let barrageLength = 0;
let timer;
let barrageOffset = 0;
let barrageColorOffset = 0;
let isChangeColor = true;
let save = {};
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 += '<div><label>弹幕(一行一个):</label></div>';
html += '<textarea id="bloop__textarea" rows="5" cols="50"></textarea>';
html += '<div><label>速度(ms):</label><input id="bloop__text_speed" type="text" style="width:50px;text-align:center;" value="2000" /></div>';
html += '<div><label><input id="bloop__checkbox_changeColor" onclick="window.changeColor()" type="checkbox" name="checkbox_changeColor" checked>自动变色</label></div>';
html += '<div class="bloop__switch"><label><input id="bloop__checkbox_startSend" onclick="window.startSend()" type="checkbox">开始发送</label></div>';
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 = '<a href="javascript:window.showDom();"><svg t="1577862697100" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6841" width="20" height="20"><path d="M67.596337 1024C30.325205 1024 0 993.267663 0 955.490699V429.746892L138.388048 152.983133V71.161831c0-39.232771 30.53494-71.161831 68.077494-71.161831h611.068916c37.542554 0 68.077494 31.92906 68.077494 71.161831V152.983133L1024 429.746892v526.10159A68.23788 68.23788 0 0 1 955.848482 1024z" fill="#25467A" p-id="6842"></path><path d="M830.303614 166.060723L691.890892 442.812145v525.830168h264.019277a12.793831 12.793831 0 0 0 12.793831-12.793831V442.812145z" fill="#C2DBF4" p-id="6843"></path><path d="M830.303614 71.174169v94.886554H193.696386V71.174169c0-8.697831 5.72453-15.816482 12.732144-15.816482h611.068916c7.044627 0 12.806169 7.118651 12.806168 15.816482zM55.357687 442.812145v512.690891c0 7.254361 5.477783 13.139277 12.23865 13.139277h624.26988V442.812145z" fill="#F7F7F7" p-id="6844"></path><path d="M373.624289 774.921253A69.274217 69.274217 0 0 1 304.436434 705.696386a13.842506 13.842506 0 1 1 27.672674 0 41.515181 41.515181 0 0 0 83.030362 0 13.842506 13.842506 0 1 1 27.672675 0 69.274217 69.274217 0 0 1-69.187856 69.224867z" fill="#25467A" p-id="6845"></path><path d="M235.236241 595.018024m-41.515181 0a41.515181 41.515181 0 1 0 83.030362 0 41.515181 41.515181 0 1 0-83.030362 0Z" fill="#25467A" p-id="6846"></path><path d="M512 595.018024m-41.515181 0a41.515181 41.515181 0 1 0 83.030362 0 41.515181 41.515181 0 1 0-83.030362 0Z" fill="#25467A" p-id="6847"></path><path d="M179.890892 664.218217H124.607229a27.672675 27.672675 0 1 0 0 55.345349h55.345349a27.672675 27.672675 0 1 0 0-55.345349zM622.703036 664.218217h-55.357687a27.672675 27.672675 0 0 0 0 55.345349h55.357687a27.672675 27.672675 0 1 0 0-55.345349z" fill="#95C4F3" p-id="6848"></path><path d="M830.266602 166.048386L691.878554 442.812145H55.345349l138.388049-276.763759h636.533204z" fill="#FFFFFF" p-id="6849"></path><path d="M203.566265 339.277108l46.005976-98.698795h-15.989205l7.673831-16.458024h45.438458l-7.11865 90.198362 77.379855-90.198362h45.907277L395.189976 240.578313h-16.038554L333.108434 339.277108h16.038554l-7.673831 16.458025h-49.978603l7.673832-16.458025h15.841156l46.005976-98.698795-100.11759 116.464579h-3.91094l8.956916-116.464579-46.005976 98.698795h14.595084l-7.673831 16.458025h-46.968289L187.527711 339.277108zM374.389205 339.277108l46.005976-98.698795h-14.323663l7.673831-16.458024h48.695518L454.767036 240.578313H440.443373l-46.005975 98.698795h14.323662l-7.673831 16.458025h-48.695518l7.673831-16.458025zM435.002602 339.277108l46.005976-98.698795H463.884337l7.673832-16.458024h54.284337L518.168675 240.578313h-16.346988l-46.005976 98.698795h40.713253l20.862458-44.747566h18.666409l-28.548626 61.205591h-97.354024l7.673831-16.458025zM537.044819 339.277108l46.005976-98.698795h-16.606072l7.673831-16.458024h53.741494L620.186217 240.578313h-17.087229l-46.005976 98.698795h15.273639l-7.673832 16.458025h-51.927903l7.673831-16.458025z m45.438458-53.050602l63.858121-45.648193h-15.17494l7.673831-16.458024H690.891566L683.19306 240.578313h-14.126265l-62.167903 45.648193 17.272289 53.050602h14.224964l-7.673832 16.458025h-53.901879l7.673831-16.458025h14.311325z" fill="#009BEF" p-id="6850"></path></svg></a>';
let b = document.getElementsByClassName("ChatToolBar")[0];
b.appendChild(a)
}
function getBarrageColorArr() {
// 获取已解锁的弹幕颜色
barrageColorArr.length = 0;// 清空数组
barrageColorLength = 0;
let a = document.getElementsByClassName("FansBarrageColor-item");
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 = document.getElementsByClassName("FansBarrageColor-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") {
initFunc();
initDom();
initSet();
clearInterval(intID);
}
},1000);
})()