// ==UserScript==
// @name 斗鱼自动回复,可重复回复(刷屏)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 斗鱼自动回复,自定义时间,次数,回复内容!
// @author Pi7bo1
// @match https://www.douyu.com/*
// @grant none
// @supportURL woxianshouboxian@163.com
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
// Your code here...
// 定义初始变量
var dySendMsg = function (text, maxCount, stime) {
this.lastMsg = ""; // 上次喊话内容
this.count = 0; // 当前喊话次数
this.stext = text || new Date(); // 喊话内容
this.stime = stime || 30; // 间隔时间 单位/秒
this.auto = ""; //自动变量,用来定义/清除定时器
this.maxCount = maxCount || 99; //最大喊话次数
this.status = "stop"; //当前状态
};
//初始化发送模板
dySendMsg.prototype.init = function () {
var othis = this;
var jsSendMsg = document.getElementById('js-chat-speak');
//添加自定义定义样式
var _styleElement = document.createElement('style');
var _css = ".dyFunctionSend{background: #fff;width:100%;box-sizing: border-box;position:absolute;padding:5px 6px;z-index: 999;border: 1px solid #d2d2d2;bottom: 90px;left: 0;}";
_css += ".dyFunctionSend .form-control{box-sizing: border-box;background-color: #FFFFFF;resize:none;background-image: none;border: 1px solid #e5e6e7;border-radius: 1px;color: inherit;display: block;padding: 6px 12px;transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;width: 100%;}";
_css += ".dyFunctionSend .form_item{margin:5px 0;font-size:14px}";
_css += ".dyFunctionSend .form-control:focus{border-color: #1ab394;}";
_css += ".dyFunctionSend_hide {display: none;}";
_css += ".dySend_btn {margin:5px;display: inline-block;height: 33px;line-height: 33px;padding: 0 18px;background-color: #009688;color: #fff;white-space: nowrap;text-align: center;font-size: 14px;border: none;border-radius: 2px;cursor: pointer;}";
_css += ".dySend_btn:hover {opacity: 0.8}";
_css += ".dySend_btn:active {opacity: 1}";
_css += ".dySend_start_btn,.dySend_stop_btn{background-color: #1E9FFF;display:none}";
_css += ".dySend_start_btn.show_d,.dySend_stop_btn.show_d{display:inline-block}";
_css += ".ChatSendMsgBtn {display: inline-block;vertical-align: middle;width: 22px;height: 22px;margin-right: 8px;cursor: pointer;}";
_css += ".ChatSendMsgBtn .Horn4Category-btn{background:url('https://luo-1255851923.cos.ap-guangzhou.myqcloud.com/images/20181022140905.png') 50% no-repeat;background-position: 0 0px;}";
_css += ".ChatSendMsgBtn.active .Horn4Category-btn{background-position-x: -24px;}";
_styleElement.innerHTML = _css;
document.getElementsByTagName('head')[0].appendChild(_styleElement);
//添加点击的弹框模板
var dyFunctionSend = document.createElement('div');
var _html = '';
_html += '
';
_html += '';
_html += '';
_html += '
';
_html += '保存开始停止
';
_html += '
';
dyFunctionSend.classList.add('dyFunctionSend', 'dyFunctionSend_hide');
dyFunctionSend.innerHTML = _html;
dyFunctionSend.id = "dyFunctionSend";
var chatMsgBox = document.querySelectorAll('.layout-Player-aside')[0];
chatMsgBox.appendChild(dyFunctionSend);
// 斗鱼按钮栏插入按钮
var timer = setInterval(function () {
try {
document.querySelectorAll('.ShieldTool-content')[0].querySelectorAll('.ShieldTool-checkText')[0].innerText = "屏蔽特效";
var sendMsgBtn = document.createElement('div');
sendMsgBtn.onclick = othis.changeDySendPanel;
sendMsgBtn.classList.add('ChatSendMsgBtn');
sendMsgBtn.innerHTML = ``
document.querySelectorAll('.ChatToolBar')[0].appendChild(sendMsgBtn);
clearInterval(timer);
} catch (err) {
}
}, 50)
}
//开关面板
dySendMsg.prototype.changeDySendPanel = function () {
document.getElementById('dyFunctionSend').classList.toggle('dyFunctionSend_hide');
document.querySelectorAll('.ChatToolBar')[0].querySelectorAll('.ChatSendMsgBtn')[0].classList.toggle('active');
}
// 保存当前设置
dySendMsg.prototype.save = function () {
if (this.status == "start") {
document.getElementById('dyFunctionSend_error').innerText = "需要先停止喊话才能进行修改";
return;
}
document.getElementById('dyFunctionSend_error').innerText = "";
this.stext = document.getElementById('dyFunctionSend_text').value;
this.maxCount = document.getElementById('dyFunctionSend_count').value || new Date();
this.stime = document.getElementById('dyFunctionSend_time').value || 30;
}
// 开始
dySendMsg.prototype.start = function () {
this.autoSend();
this.status = "start";
document.querySelectorAll('.dySend_start_btn')[0].classList.toggle('show_d');
document.querySelectorAll('.dySend_stop_btn')[0].classList.toggle('show_d');
}
// 停止 清除定时器
dySendMsg.prototype.stop = function () {
this.count = 0;
this.status = "stop";
clearTimeout(this.auto);
document.querySelectorAll('.dySend_start_btn')[0].classList.toggle('show_d');
document.querySelectorAll('.dySend_stop_btn')[0].classList.toggle('show_d');
}
// 自动发送
dySendMsg.prototype.autoSend = function () {
// this.changeDySendPanel();
var jsSend = document.querySelectorAll('.ChatSend')[0];
// 处理内容
var currentMsg = (this.count % 2 == 0 ? "" : "") + this.stext;
// 如果相同
if (this.lastMsg == currentMsg) {
currentMsg = "" + currentMsg;
}
//输入框赋值
jsSend.querySelectorAll('textarea.ChatSend-txt')[0].value = currentMsg;
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
jsSend.querySelectorAll('.ChatSend-button')[0].dispatchEvent(e);
// 变量信息修改
this.count += 1;
this.lastMsg = currentMsg;
console.log('当前共发送' + this.count + "条弹幕");
if (this.count >= this.maxCount) {
this.stop();
return;
}
this.auto = setTimeout(this.autoSend.bind(this), this.stime * 1000 + (Math.floor(Math.random() * 50)) / 100);
}
window.$dy = new dySendMsg();
$dy.init();
})();