-
Notifications
You must be signed in to change notification settings - Fork 18
/
RandomRepeater_VM.js
185 lines (180 loc) · 9.12 KB
/
RandomRepeater_VM.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// ==UserScript==
// @icon https://www.douyu.com/favicon.ico
// @name 复读机自动弹幕发射器
// @namespace https://github.com/zhenshiluosuo/Storyteller-AutoBarrageForDouyuTV
// @namespace https://greasyfork.org/zh-CN/scripts/396928
// @author 闪光魔法师
// @description 适配斗鱼直播平台的自动弹幕发射器 随机复制复读机 Github:https://github.com/zhenshiluosuo/Storyteller-AutoBarrageForDouyuTV
// @match *://www.douyu.com/*
// @match *://www.youtube.com/*
// @version 1.0.0
// @grant none
// ==/UserScript==
(function () {
'use strict';
let tip = false;
let div1 = document.createElement('div');//默认悬浮窗
let div2 = document.createElement('div');//控制台
let css1 = 'background: #FFB5C5;color:#ffffff;overflow: hidden;z-index: 998;position: fixed;padding:5px;text-align:center;width: 85px;height: 22px;border-radius: 5px;right: 10px;top: 72%;'
let css2 = 'background: #ffffff;overflow: hidden;z-index: 999;position: fixed;padding:5px;text-align:center;width: 125px;height: 110px;box-sizing: content-box;border: 1px solid #ff921a;border-radius: 5px;right: 10px;top: 72%;display: none;';
let cycle_time;//弹幕周期,单位毫秒 建议设定至6000毫秒以上 过低有系统屏蔽风险
let _cycle_time = 800;//弹幕div定时器
let sentence = "";//复制的弹幕
let interval;//发射定时器
let danmu_interval;//等待弹幕div加载定时器
let _ready = false;//弹幕div加载标记
let div_manmu;//网页弹幕div
let div_wenzi;//网页聊天室div
let _mode = false;//套娃模式标记
let __mode = false;//复读白字标记
let ___mode = false;//重复复读标记
let website;
let ytb_iframe;//ytb直播右侧iframe
init();//初始化
//核心功能函数
function init() {
let url = window.location.host;
if(url === 'www.douyu.com') {
website = 0;
} else if(url === 'www.youtube.com') {
if (window.top !== window.self) {
throw new Error('Frame error!');
}
website = 3;
}
div1.id = 'DuLunChe2';
div1.id = 'DuLunChe3';
div1.style.cssText = css1;
div2.style.cssText = css2;
div1.innerHTML = '复读机控制台';
div2.innerHTML = '<input type="text" style="width: 100px" placeholder="间隔时间(ms)" id="DuLunCheTime1"/><div style="font-size: 10px;margin-bottom: 2px;"><button id="DuLunCheBtn1" style="display: inline-block; background: #f70; color: #FFFFFF; width:50px; height: 25px; margin: 1px;">出动</button><button id="DuLunCheYinCang1" style="display: inline-block; background: #f70; color: #FFFFFF; width:50px; height: 25px; margin: 1px;">隐藏</div></button><div style="color: black;float: left;width: 100%;font-size: 75%;"><span>套娃模式(仅斗鱼):</span><input type="checkbox" id="dlc_btn99" value="0" style=""/></div><div style="color: black;float: left;width: 100%;font-size: 75%;"><span>不复读白字(斗鱼):</span><input type="checkbox" id="dlc_btn98" value="0" style=""/></div><div style="color: black;float: left;width: 100%;font-size: 75%;"><span>不重复复读(斗鱼):</span><input type="checkbox" id="dlc_btn97" value="0" style=""/></div>';
div1.onclick = () => {
div2.style.setProperty('display','block');
if(!tip){
tip = true;
alert('欢迎使用偶尔更新的复读机自动弹幕发射装置,当前版本V1.0.0,对本插件的意见和问题可以到Github反馈哦,项目地址:https://github.com/zhenshiluosuo/Storyteller-AutoBarrageForDouyuTV/ ');
}
};
document.body.appendChild(div1);
document.body.appendChild(div2);
document.getElementById('DuLunCheYinCang1').onclick = () => {
div2.style.setProperty('display','none');
};
document.getElementById('DuLunCheBtn1').onclick = () => {
if(document.getElementById('DuLunCheBtn1').innerText === '出动') {
document.getElementById('DuLunCheBtn1').innerText = '中止';
if(!website) {
dy_run();
} else {
ytb_run();
}
}
else finish();
};
document.getElementById('dlc_btn99').onclick = () => {
if(document.getElementById('dlc_btn99').checked){
_mode = true;
}else{
_mode = false;
}
};
if(!website) {
document.getElementById('dlc_btn98').onclick = () => {
if(document.getElementById('dlc_btn98').checked){
__mode = true;
}else{
__mode = false;
}
};
document.getElementById('dlc_btn97').onclick = () => {
if(document.getElementById('dlc_btn97').checked){
___mode = true;
}else{
___mode = false;
}
};
danmu_interval = setInterval(() => {
if(document.getElementsByClassName('danmu-6e95c1')[0].childNodes.length){
div_manmu = document.getElementsByClassName('danmu-6e95c1')[0];
div_wenzi = document.getElementById('js-barrage-list');
div_manmu.addEventListener('DOMNodeInserted', function () {
let _sentence = sentence;
if(_mode){
if(__mode && 'Barrage-content' === div_wenzi.childNodes[div_wenzi.childNodes.length - 1].getElementsByClassName('Barrage-content')[0].className){
return;
}
sentence = '@' + div_wenzi.childNodes[div_wenzi.childNodes.length - 1].getElementsByClassName('Barrage-nickName')[0].innerText + div_wenzi.childNodes[div_wenzi.childNodes.length - 1].getElementsByClassName('Barrage-content')[0].innerText;
_ready = true;
}else{
let len = div_manmu.childNodes.length;
if(len){
let _temp = div_manmu.childNodes[Math.floor((Math.random() * len))];
let _color = _temp.style.color;
if(!__mode || (__mode && _color.length)){
_ready = true;
sentence = _temp.innerText;
}
}
}
if(___mode && _ready){
if(_sentence === sentence){
_ready = false;
}
}
},false);
clearInterval(danmu_interval);
}
}, _cycle_time);
let ad_i1 = setInterval(() => {
if(document.getElementsByClassName('CommonShareDraw')[0].childNodes.length){
document.getElementsByClassName('CommonShareDraw')[0].style.display = 'none'
clearInterval(ad_i1);
}
},1000);
} else {
}
//
}
//发射弹幕
function dy_run() {
let btn = document.getElementsByClassName('ChatSend-button')[0];
let txt = document.getElementsByClassName('ChatSend-txt')[0];
cycle_time = parseInt(document.getElementById('DuLunCheTime1').value);
if(cycle_time <= 2999 || !cycle_time) {
alert('请珍惜账号 加大发言间隔!');
finish();
document.getElementById('DuLunCheTime1').value = '9999';
return;
}
interval = setInterval(() => {
if(txt.value === '' && _ready && btn.innerHTML === '发送'){//输入框中有内容时等待用户发送完成后再继续
txt.value = sentence;
btn.click();
_ready = false;
}
}, cycle_time);
}
function ytb_run() {
ytb_iframe = document.getElementById('chatframe').contentWindow;
let btn = ytb_iframe.document.querySelector('#send-button button');
let txt = ytb_iframe.document.querySelector('#input.yt-live-chat-text-input-field-renderer');
cycle_time = parseInt(document.getElementById('DuLunCheTime1').value);
if(!cycle_time) {
alert('请设定一个时间间隔!');
finish();
document.getElementById('DuLunCheTime1').value = '9999';
return;
}
interval = setInterval(() => {
let list = ytb_iframe.document.getElementsByClassName('style-scope yt-live-chat-item-list-renderer');
txt.textContent = list[Math.floor(Math.random() * (list.length - 9))].children[1].children[2].innerText;
txt.dispatchEvent(new InputEvent('input'));
btn.click();
}, cycle_time);
}
//结束发射
function finish() {
document.getElementById('DuLunCheBtn1').innerText = '出动';
clearInterval(interval);
}
})();