// ==UserScript==
// @name 斗鱼自动回复,可重复回复(刷屏)
// @namespace http://tampermonkey.net/
// @version 1.2.1
// @description 斗鱼自动回复,自定义时间,次数,回复内容!
// @author Pi7bo1
// @match https://www.douyu.com/*
// @match https://www.douyu.com/*/*
// @grant none
// @supportURL [email protected]
// ==/UserScript==
(function () {
'use strict';
// Your code here...
// 定义初始变量
var dySendMsg = function (text, maxCount, stime) {
var cookieObj = this.getCookieData();
this.lastMsg = ""; // 上次喊话内容
this.count = 0; // 当前喊话次数
this.stext = unescape(cookieObj['dyFunctionSend_text']) || ["黄初三年", "余朝京师", "还济洛川", "古人有言", "斯水之神", "名曰宓妃", "感宋玉对楚王神女之事", "遂作斯赋", "其辞曰:\n\n余从京域", "言归东藩", "背伊阙", "越轘辕", "经通谷", "陵景山", "日既西倾", "车殆马烦", "尔乃税驾乎蘅皋", "秣驷乎芝田", "容与乎阳林", "流眄乎洛川", "于是精移神骇", "忽焉思散", "俯则未察", "仰以殊观", "睹一丽人", "于岩之畔", "乃援御者而告之曰:“尔有觌于彼者乎?彼何人斯?若此之艳也!”御者对曰:“臣闻河洛之神", "名曰宓妃", "然则君王所见", "无乃是乎?其状若何?臣愿闻之", "”\n\n余告之曰:“其形也", "翩若惊鸿", "婉若游龙", "荣曜秋菊", "华茂春松", "髣髴兮若轻云之蔽月", "飘飖兮若流风之回雪", "远而望之", "皎若太阳升朝霞;迫而察之", "灼若芙蕖出渌波", "秾纤得衷", "修短合度", "肩若削成", "腰如约素", "延颈秀项", "皓质呈露", "芳泽无加", "铅华弗御", "云髻峨峨", "修眉联娟", "丹唇外朗", "皓齿内鲜", "明眸善睐", "靥辅承权", "瑰姿艳逸", "仪静体闲", "柔情绰态", "媚于语言", "奇服旷世", "骨像应图", "披罗衣之璀粲兮", "珥瑶碧之华琚", "戴金翠之首饰", "缀明珠以耀躯", "践远游之文履", "曳雾绡之轻裾", "微幽兰之芳蔼兮", "步踟蹰于山隅", "\n\n于是忽焉纵体", "以遨以嬉", "左倚采旄", "右荫桂旗", "壤皓腕于神浒兮", "采湍濑之玄芝", "余情悦其淑美兮", "心振荡而不怡", "无良媒以接欢兮", "托微波而通辞", "愿诚素之先达兮", "解玉佩以要之", "嗟佳人之信修", "羌习礼而明诗", "抗琼珶以和予兮", "指潜渊而为期", "执眷眷之款实兮", "惧斯灵之我欺", "感交甫之弃言兮", "怅犹豫而狐疑", "收和颜而静志兮", "申礼防以自持", "\n\n于是洛灵感焉", "徙倚彷徨", "神光离合", "乍阴乍阳", "竦轻躯以鹤立", "若将飞而未翔", "践椒涂之郁烈", "步蘅薄而流芳", "超长吟以永慕兮", "声哀厉而弥长", "\n\n尔乃众灵杂沓", "命俦啸侣", "或戏清流", "或翔神渚", "或采明珠", "或拾翠羽", "从南湘之二妃", "携汉滨之游女", "叹匏瓜之无匹兮", "咏牵牛之独处", "扬轻袿之猗靡兮", "翳修袖以延伫", "体迅飞凫", "飘忽若神", "凌波微步", "罗袜生尘", "动无常则", "若危若安", "进止难期", "若往若还", "转眄流精", "光润玉颜", "含辞未吐", "气若幽兰", "华容婀娜", "令我忘餐", "\n\n于是屏翳收风", "川后静波", "冯夷鸣鼓", "女娲清歌", "腾文鱼以警乘", "鸣玉鸾以偕逝", "六龙俨其齐首", "载云车之容裔", "鲸鲵踊而夹毂", "水禽翔而为卫", "\n\n于是越北沚", "过南冈", "纡素领", "回清阳", "动朱唇以徐言", "陈交接之大纲", "恨人神之道殊兮", "怨盛年之莫当", "抗罗袂以掩涕兮", "泪流襟之浪浪", "悼良会之永绝兮", "哀一逝而异乡", "无微情以效爱兮", "献江南之明珰", "虽潜处于太阴", "长寄心于君王", "忽不悟其所舍", "怅神宵而蔽光", "\n\n于是背下陵高", "足往神留", "遗情想像", "顾望怀愁", "冀灵体之复形", "御轻舟而上溯", "浮长川而忘返", "思绵绵而增慕", "夜耿耿而不寐", "沾繁霜而至曙", "命仆夫而就驾", "吾将归乎东路", "揽騑辔以抗策", "怅盘桓而不能去"] // 喊话内容
this.stime = cookieObj['dyFunctionSend_time'] || 30; // 间隔时间 单位/秒
this.auto = ""; //自动变量,用来定义/清除定时器
this.maxCount = cookieObj['dyFunctionSend_count'] || 10; //最大喊话次数
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;}";
_css += ".dySend_count {position:absolute;bottom: 8px;left: 15px;}";
_styleElement.innerHTML = _css;
document.getElementsByTagName('head')[0].appendChild(_styleElement);
var cookieObj = this.getCookieData();
//添加点击的弹框模板
var dyFunctionSend = document.createElement('div');
var _html = '';
_html += '<div class="form_item"><div class="col-100-w"><label>文本内容:</label></div>';
_html += '<div class="col-100-w"><textarea maxlength="56" class="form-control" name="" id="dyFunctionSend_text" rows="2">' + unescape(cookieObj.dyFunctionSend_text) + '</textarea></div></div>';
_html += '<div class="form_item"><div class="col-100-w"><label>喊话次数:</label></div>';
_html += '<div class="col-100-w"><input class="form-control" placeholder="默认喊话喊话次数为 10" value="' + cookieObj.dyFunctionSend_count + '" onkeyup="value=value.replace(/[^\d]/g,"")" type="text" name="" id="dyFunctionSend_count"></div></div>';
_html += '<div class="form_item"><div class="col-100-w"><label>喊话时间间隔:</label></div>';
_html += '<div class="col-100-w"><input class="form-control" placeholder="默认喊话时间间隔为 30" value="' + cookieObj.dyFunctionSend_time + '" onkeyup="value=value.replace(/[^\d]/g,"")" type="text" name="" id="dyFunctionSend_time"></div></div>';
_html += '<div class="col-100-w"><span style="color:#FF5722" id="dyFunctionSend_error">设置需要保存才能生效</span></div>';
_html += '<div class="col-100-w" style="text-align: center;"><span onclick="javascript:$dy.save()" class="dySend_save_btn dySend_btn">保存</span><span onclick="javascript:$dy.start()" class="dySend_start_btn show_d dySend_btn">开始</span><span onclick="javascript:$dy.stop()" class="dySend_stop_btn dySend_btn">停止</span></div>';
_html += '<div style="top:-4px" onclick="javascript:$dy.changeDySendPanel()" class="PrivateLetter-close"><i></i></div>';
_html += '<div class="dySend_count"><p style="color:#009688" id="dySend_Num">已发送:0</p><p style="color:#01AAED" id="dySend_remainder">剩余次数:0</p></div>';
dyFunctionSend.classList.add('dyFunctionSend', 'dyFunctionSend_hide');
dyFunctionSend.innerHTML = _html;
dyFunctionSend.id = "dyFunctionSend";
var chatMsgBox = document.querySelectorAll('.layout-Player-aside')[0] || document.querySelectorAll('#js-live-room-normal-right .chat')[0];
chatMsgBox.appendChild(dyFunctionSend);
// 斗鱼按钮栏插入按钮
var timer = setInterval(function () {
try {
var sub_ele_text = document.querySelectorAll('.ShieldTool-content .ShieldTool-checkText')[0] || document.getElementById('js-chat-speak').querySelectorAll('.speak-up #shie-switch span')[0];
sub_ele_text.innerText = "屏蔽特效";
var sendMsgBtn = document.createElement('div');
sendMsgBtn.onclick = othis.changeDySendPanel;
sendMsgBtn.classList.add('ChatSendMsgBtn');
if (document.getElementById('js-chat-speak')) {
sendMsgBtn.style.marginLeft = "5px";
sendMsgBtn.innerHTML = `<div title="喊话设置" style="height:100%;margin-top:5px;" class="Horn4Category-btn Horn4Category-btn--popTrigger"></div>`
} else {
sendMsgBtn.innerHTML = `<div title="喊话设置" style="height:100%" class="Horn4Category-btn Horn4Category-btn--popTrigger"></div>`
}
var btnBox = document.querySelectorAll('.ChatToolBar')[0] || document.getElementById('js-chat-speak').querySelectorAll('.speak-up')[0];
btnBox.appendChild(sendMsgBtn);
clearInterval(timer);
} catch (err) {
}
}, 50)
}
//获取Cookie信息
dySendMsg.prototype.getCookieData = function (name) {
var a = document.cookie.split(";");
var o = {};
for (var i = 0; i < a.length; i++) { //遍历cookie信息数组
a[i] && (a[i] = a[i].replace(/(^\s*)|(\s*$)/g, ''));
//清除头部空格符
var b = a[i].split("=");
var c = b[1];
c && (c = c.replace(/(^\s*)|(\s*$)/g, ''));
c = unescape(c);
//如果c中不包含逗号(不是子cookie),直接把c作为cookie变量的值存入对象
if (!/\,/gi.test(c)) {
o[b[0]] = b[1];
} else {
var d = c.split(",");
for (var j = 0; j < d.length; j++) {
var e = d[j].split(":");
e[0] && (e[0] = e[0].replace(/(^\s*)|(\s*$)/g, ''));
o[e[0]] = e[1];
}
}
}
if (name) {
return o[name];
}
return o;
}
//开关面板
dySendMsg.prototype.changeDySendPanel = function () {
document.getElementById('dyFunctionSend').classList.toggle('dyFunctionSend_hide');
document.querySelectorAll('.ChatSendMsgBtn')[0].classList.toggle('active');
}
// 保存当前设置
dySendMsg.prototype.save = function () {
if (this.status == "start") {
document.getElementById('dyFunctionSend_error').innerText = "需要先停止喊话才能进行修改";
return;
}
this.stext = document.getElementById('dyFunctionSend_text').value || ["黄初三年", "余朝京师", "还济洛川", "古人有言", "斯水之神", "名曰宓妃", "感宋玉对楚王神女之事", "遂作斯赋", "其辞曰:\n\n余从京域", "言归东藩", "背伊阙", "越轘辕", "经通谷", "陵景山", "日既西倾", "车殆马烦", "尔乃税驾乎蘅皋", "秣驷乎芝田", "容与乎阳林", "流眄乎洛川", "于是精移神骇", "忽焉思散", "俯则未察", "仰以殊观", "睹一丽人", "于岩之畔", "乃援御者而告之曰:“尔有觌于彼者乎?彼何人斯?若此之艳也!”御者对曰:“臣闻河洛之神", "名曰宓妃", "然则君王所见", "无乃是乎?其状若何?臣愿闻之", "”\n\n余告之曰:“其形也", "翩若惊鸿", "婉若游龙", "荣曜秋菊", "华茂春松", "髣髴兮若轻云之蔽月", "飘飖兮若流风之回雪", "远而望之", "皎若太阳升朝霞;迫而察之", "灼若芙蕖出渌波", "秾纤得衷", "修短合度", "肩若削成", "腰如约素", "延颈秀项", "皓质呈露", "芳泽无加", "铅华弗御", "云髻峨峨", "修眉联娟", "丹唇外朗", "皓齿内鲜", "明眸善睐", "靥辅承权", "瑰姿艳逸", "仪静体闲", "柔情绰态", "媚于语言", "奇服旷世", "骨像应图", "披罗衣之璀粲兮", "珥瑶碧之华琚", "戴金翠之首饰", "缀明珠以耀躯", "践远游之文履", "曳雾绡之轻裾", "微幽兰之芳蔼兮", "步踟蹰于山隅", "\n\n于是忽焉纵体", "以遨以嬉", "左倚采旄", "右荫桂旗", "壤皓腕于神浒兮", "采湍濑之玄芝", "余情悦其淑美兮", "心振荡而不怡", "无良媒以接欢兮", "托微波而通辞", "愿诚素之先达兮", "解玉佩以要之", "嗟佳人之信修", "羌习礼而明诗", "抗琼珶以和予兮", "指潜渊而为期", "执眷眷之款实兮", "惧斯灵之我欺", "感交甫之弃言兮", "怅犹豫而狐疑", "收和颜而静志兮", "申礼防以自持", "\n\n于是洛灵感焉", "徙倚彷徨", "神光离合", "乍阴乍阳", "竦轻躯以鹤立", "若将飞而未翔", "践椒涂之郁烈", "步蘅薄而流芳", "超长吟以永慕兮", "声哀厉而弥长", "\n\n尔乃众灵杂沓", "命俦啸侣", "或戏清流", "或翔神渚", "或采明珠", "或拾翠羽", "从南湘之二妃", "携汉滨之游女", "叹匏瓜之无匹兮", "咏牵牛之独处", "扬轻袿之猗靡兮", "翳修袖以延伫", "体迅飞凫", "飘忽若神", "凌波微步", "罗袜生尘", "动无常则", "若危若安", "进止难期", "若往若还", "转眄流精", "光润玉颜", "含辞未吐", "气若幽兰", "华容婀娜", "令我忘餐", "\n\n于是屏翳收风", "川后静波", "冯夷鸣鼓", "女娲清歌", "腾文鱼以警乘", "鸣玉鸾以偕逝", "六龙俨其齐首", "载云车之容裔", "鲸鲵踊而夹毂", "水禽翔而为卫", "\n\n于是越北沚", "过南冈", "纡素领", "回清阳", "动朱唇以徐言", "陈交接之大纲", "恨人神之道殊兮", "怨盛年之莫当", "抗罗袂以掩涕兮", "泪流襟之浪浪", "悼良会之永绝兮", "哀一逝而异乡", "无微情以效爱兮", "献江南之明珰", "虽潜处于太阴", "长寄心于君王", "忽不悟其所舍", "怅神宵而蔽光", "\n\n于是背下陵高", "足往神留", "遗情想像", "顾望怀愁", "冀灵体之复形", "御轻舟而上溯", "浮长川而忘返", "思绵绵而增慕", "夜耿耿而不寐", "沾繁霜而至曙", "命仆夫而就驾", "吾将归乎东路", "揽騑辔以抗策", "怅盘桓而不能去"];
this.maxCount = document.getElementById('dyFunctionSend_count').value || 10;
this.stime = document.getElementById('dyFunctionSend_time').value || 30;
document.getElementById('dySend_Num').innerText = "已发送:" + this.count;
document.getElementById('dySend_remainder').innerText = "剩余次数:" + this.maxCount;
document.getElementById('dyFunctionSend_error').innerText = "保存成功";
// 保存当前设置
document.cookie = "dyFunctionSend_text=" + escape(this.stext);
document.cookie = "dyFunctionSend_count=" + this.maxCount;
document.cookie = "dyFunctionSend_time=" + this.stime;
setTimeout(function () {
document.getElementById('dyFunctionSend_error').innerText = "设置需要保存才能生效";
}, 2000)
}
// 开始
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');
}
// 等待发言cd
dySendMsg.prototype.wait = function (timer) {
var othis = this;
return new Promise(function (resolve) {
setTimeout(function () {
resolve("true");
}, (Number(othis.stime) + Math.random()) * 1000);
});
}
// 自动发送
dySendMsg.prototype.autoSend = function () {
// this.changeDySendPanel();
var jsSend = document.querySelectorAll('.ChatSend')[0] || document.getElementById('js-send-msg');
var currentMsg = "";
// 文本数组循环
if (typeof this.stext == "object") {
currentMsg = this.stext[(this.count % this.stext.length)];
} else {
// 处理内容
currentMsg = (this.count % 2 == 0 ? "" : "") + this.stext;
}
// 如果相同
if (this.lastMsg === currentMsg) {
currentMsg = "" + currentMsg;
}
//输入框赋值
jsSend.querySelectorAll('textarea')[0].value = currentMsg;
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
var sendBtn = jsSend.querySelectorAll('.ChatSend-button')[0] || jsSend.querySelectorAll('.b-btn')[0];
var _enentBtnText = sendBtn.innerText;
if (_enentBtnText != "发送") {
document.getElementById('dyFunctionSend_error').innerText = "等待发言CD" + _enentBtnText + "秒";
(async function () {
var state = this.wait(_enentBtnText);
}.bind(this)())
} else {
document.getElementById('dyFunctionSend_error').innerText = "弹幕发送中...";
sendBtn.dispatchEvent(e);
// 变量信息修改
this.count += 1;
this.lastMsg = currentMsg;
document.getElementById('dySend_Num').innerText = "已发送:" + this.count;
document.getElementById('dySend_remainder').innerText = "剩余次数:" + (this.maxCount - this.count);
console.log('当前共发送' + this.count + "条弹幕");
if (this.count >= this.maxCount) {
document.getElementById('dyFunctionSend_error').innerText = "弹幕发送完成";
this.stop();
return;
}
}
this.auto = setTimeout(this.autoSend.bind(this), (Number(this.stime) + Math.random()) * 1000);
}
window.$dy = new dySendMsg();
$dy.init();
})();