复读机自动弹幕发射器

适配斗鱼直播平台的自动弹幕发射器 随机复制复读机 Github:https://github.com/zhenshiluosuo/Storyteller-AutoBarrageForDouyuTV

目前為 2020-10-25 提交的版本,檢視 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址