b-live-random-send-test

定时从设置的字幕中随机取出一条在B站直播间发送,需先登录(不可用)B站账号

当前为 2023-04-16 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/447936/1176515/b-live-random-send-test.js

  1. // ==UserScript==
  2. // @author Gamyou
  3. // @version 1.5.3
  4. // @note 23-04-16 1.5.3 B站直播间防休眠(参考@NateScarlet)
  5. // @note 23-04-16 1.5.2 修复活动直播间room_id获取失败的问题
  6. // @note 23-03-12 1.5.0 适配框架2.4.0版本
  7. // @note 23-03-08 1.4.6 隐藏弹幕输入框上层显示的登录(不可用)提示层
  8. // @note 23-02-10 1.4.5 隐藏播放器左上角的“小橙车”提示
  9. // @note 22-08-28 1.4.4 解決定時器在浏览器繁忙时时间出现偏差的问题
  10. // @note 22-08-26 1.4.3 修复正则替换方法not found的问题
  11. // @note 22-08-14 1.4.2 修复B站直播间因活动而嵌套网页而导致房间号解析出错的BUG
  12. // @note 22-08-14 1.4.1 修复B站直播间因活动而嵌套网页而导致脚本加载出错的BUG
  13. // @note 22-08-13 1.4.0 实现阿B各直播间数据分离保存和油猴脚本更新提示功能
  14. // @note 22-08-05 1.3.0 增加播放器底部登录(不可用)提示和Haruna的隐藏功能
  15. // @note 22-07-29 1.2.6 修复初始化后的常量被赋值和没能初始化成功组件时系统提示加载超时的问题
  16. // @note 22-07-24 1.2.5 增加分组启用按钮,并优化设置面板样式
  17. // @note 22-07-23 1.2.4 修复弹幕分组数据都为空时,旧数据重复合并的BUG
  18. // @note 22-07-16 1.2.3 修复设置弹幕时旧(初始)数据没有清空的BUG
  19. // @note 22-06-24 1.2.2 优化部分代码
  20. // @note 22-06-20 1.2.1 修复定时停止不能再开始的BUG
  21. // @note 22-06-19 1.2.0 添加弹幕设置功能
  22. // ==/UserScript==
  23.  
  24.  
  25. (function () {
  26. const blobURL = URL.createObjectURL(
  27. new Blob(
  28. [
  29. '(',
  30. function () {
  31. const ids = {};
  32. // 监听message 开始执行定时器或者销毁
  33. self.onmessage = (e) => {
  34. switch (e.data.command) {
  35. case 'interval:start': // 开启定时器
  36. const intervalId = setInterval(() => postMessage({ message: 'interval:tick', id: e.data.id }), e.data.interval);
  37. // postMessage({ message: 'interval:started', id: e.data.id });
  38. ids[e.data.id] = intervalId;
  39. break;
  40. case 'interval:clear': // 销毁
  41. clearInterval(ids[e.data.id]);
  42. postMessage({ message: 'interval:cleared', id: e.data.id });
  43. delete ids[e.data.id];
  44. break;
  45. case 'timeout:start':
  46. const timeoutId = setTimeout(() => postMessage({ message: 'timeout:tick', id: e.data.id }), e.data.timeout);
  47. // postMessage({ message: 'timeout:started', id: e.data.id });
  48. ids[e.data.id] = timeoutId;
  49. break;
  50. case 'timeout:clear':
  51. clearTimeout(ids[e.data.id]);
  52. postMessage({ message: 'timeout:cleared', id: e.data.id });
  53. delete ids[e.data.id];
  54. break;
  55. }
  56. };
  57. }.toString(),
  58. ')()',
  59. ],
  60. { type: 'application/javascript' },
  61. ),
  62. );
  63. const worker = new Worker(blobURL);
  64. URL.revokeObjectURL(blobURL); //用完释放URL对象
  65. const workerTimer = {
  66. id: 0,
  67. callbacks: {},
  68. setInterval: (cb, interval, context) => {
  69. const id = ++workerTimer.id;
  70. workerTimer.callbacks[id] = { fn: cb, context: context };
  71. worker.postMessage({ command: 'interval:start', interval: interval, id: id });
  72. return id;
  73. },
  74. setTimeout: (cb, timeout, context) => {
  75. const id = ++workerTimer.id;
  76. workerTimer.callbacks[id] = { fn: cb, context: context };
  77. worker.postMessage({ command: 'timeout:start', timeout: timeout, id: id });
  78. return id;
  79. },
  80.  
  81. // 监听worker 里面的定时器发送的message 然后执行回调函数
  82. onMessage: (e) => {
  83. switch (e.data.message) {
  84. case 'interval:tick':
  85. case 'timeout:tick':
  86. const callbackItem = workerTimer.callbacks[e.data.id];
  87. if (callbackItem && callbackItem.fn)
  88. callbackItem.fn.apply(callbackItem.context);
  89.  
  90. break;
  91. case 'interval:cleared':
  92. case 'timeout:cleared':
  93. delete workerTimer.callbacks[e.data.id];
  94. break;
  95. }
  96. },
  97.  
  98. // 往worker里面发送销毁指令
  99. clearInterval: (id) => worker.postMessage({ command: 'interval:clear', id: id }),
  100. clearTimeout: (id) => worker.postMessage({ command: 'timeout:clear', id: id }),
  101. };
  102. worker.onmessage = workerTimer.onMessage.bind(workerTimer);
  103.  
  104. let source = {
  105. version: 3,
  106. random: true,
  107. data1: { available: true, values: ['弹幕①', '弹幕②'] },
  108. data2: { available: true, values: ['弹幕③', '弹幕④'] },
  109. data3: { available: true, values: ['弹幕⑤', '弹幕⑥'] },
  110. data4: { available: true, values: ['弹幕⑦', '弹幕⑧'] },
  111. data5: { available: true, values: ['弹幕⑨', '弹幕Ⅹ'] }
  112. },
  113. rdCheckbox, group1Checkbox, group2Checkbox, group3Checkbox, group4Checkbox, group5Checkbox,
  114. dmButtonSend, dmInput, divSetting, dataText1, dataText2, dataText3, dataText4, dataText5, spanApplyTip,
  115. pdata = {}, waiters = [], data = [], sendTimer = null, removeElementsTimer = null, signInTimer = null,
  116. count = 0, waitCount = 200, arrayIndex = 0, removeElementsTimerCount = 0, default_timeout = 600,
  117. hbInterval = Math.floor(Math.random() * (35 - 50)) + 50, noSleepCount = 0,
  118. gmNotice = obj => { alert('请更新油猴脚本'); window.location.href = parentUrl; },
  119. getGmValue = (key, defaultValue) => { return null; },
  120. setGmValue = (key, obj) => { console.warn('===> No implementation "setGmValue" method.'); },
  121. delGmValue = key => { console.warn('===> No implementation "delGmValue" method.'); };
  122.  
  123. const minVersion = '2.4.0', updateTips = 'B站直播间防休眠', noticeTimeout = 10e3,
  124. icoUrl = 'https://www.bilibili.com/favicon.ico',
  125. parentUrl = 'https://gf.qytechs.cn/scripts/446725-b%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E5%AE%9A%E6%97%B6%E5%8F%91%E9%9A%8F%E6%9C%BA%E5%BC%B9%E5%B9%95/code/B%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E5%AE%9A%E6%97%B6%E5%8F%91%E9%9A%8F%E6%9C%BA%E5%BC%B9%E5%B9%95.user.js',
  126. // roomId = window.__NEPTUNE_IS_MY_WAIFU__
  127. // ? 0 == window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.short_id
  128. // ? window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.room_id
  129. // : window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.short_id
  130. // : window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
  131. roomId = window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
  132. setGmGetValue = callback => getGmValue = callback,
  133. setGmSetValue = callback => setGmValue = callback,
  134. setGmDelValue = callback => delGmValue = callback,
  135. setGmNotice = callback => gmNotice = callback,
  136. setParentData = obj => pdata = obj,
  137. arrayInfo = () => console.info(data),
  138. // setLoadedFlag = flag => window.autoSendDanmuModuleLoaded = flag,
  139. isOldVersion = () => {
  140. if (!pdata.version) {
  141. return true;
  142. }
  143. if (minVersion === pdata.version) {
  144. return false;
  145. } else {
  146. let vals = pdata.version.split('.');
  147. let mins = minVersion.split('.');
  148. if (vals.length != mins.length) {
  149. return true;
  150. } else {
  151. for (let i = 0; i < vals.length; i++) {
  152. if (mins[i] > vals[i]) {
  153. return true;
  154. }
  155. }
  156.  
  157. return false;
  158. }
  159. }
  160. },
  161. initCss = () => {
  162. let linkElement = document.createElement('link');
  163. linkElement.rel = 'stylesheet';
  164. linkElement.href = 'https://unpkg.com/element-ui@2.15.9/lib/theme-chalk/index.css';
  165. document.head.appendChild(linkElement);
  166.  
  167. // 图标库 https://ionic.io/ionicons
  168. // let scriptElement = document.createElement('script');
  169. // scriptElement.src = 'https://unpkg.com/ionicons@5.5.2/dist/ionicons.js';
  170. // document.head.appendChild(scriptElement);
  171.  
  172. let customerStyle = document.createElement('style');
  173. customerStyle.setAttribute('type', 'text/css');
  174. customerStyle.innerHTML = '.danmu-group-title{font-size:14px;padding-left:2px;color:rgb(18, 56, 141);display:inline;margin-right:60%;vertical-align:middle;}.danmu-group-textarea{width:98%;min-height:100px;height:16%;margin:1px 0px 4px;border:0px;resize:none;}.el-button{display:inline-block;line-height:1;white-space:nowrap;cursor:pointer;background:#FFF;border:1px solid #DCDFE6;color:#606266;-webkit-appearance:none;text-align:center;-webkit-box-sizing:border-box;box-sizing:border-box;outline:0;margin:0;-webkit-transition:.1s;transition:.1s;font-weight:500;padding:12px 20px;font-size:14px;border-radius:4px}.el-button.is-circle{border-radius:50%;padding:12px}.el-button--mini.is-circle{padding:3px;}.el-button:focus,.el-button:hover{color:#409EFF;border-color:#c6e2ff;background-color:#ecf5ff}.el-icon-close.is-circle{padding:5px;color:#ff0000;border:1px solid #ff0000;margin-left:20px;}.el-icon-check.is-circle{padding:5px;color:#0000ff;border:1px solid #0000ff;margin-left:20px;}input[type="checkbox"]{display:none;}.switch-check{display:inline-block;margin:0 5px;vertical-align:middle;}.switch-check-label{display:inline-block;vertical-align:middle;border:1px solid #bdc3c7;border-radius:60px;width:40px;height:18px;position:relative;transition:all .3s;cursor:pointer;}.switch-check-label:before{width:14px;height:14px;content:"";display:inline-block;background-color:#bdc3c7;border-radius:100%;position:absolute;top:2px;left:4px;transition:all .3s;}.switch-check :checked ~ label{background-color:#26b22b;border-color:#26b22b;}.switch-check :checked ~ label:before{left:22px;background-color:#fff;}.danmu-random-setting-panel{background-color:#d4f2e0;border-radius:2px;width:100%;height:100%;overflow-y:auto;position:absolute;left:0px;top:0px;z-index:999;display:none;}.danmu-random-setting-title{text-align:center;font-size:16px;font-weight:700;color:#1c5adc;line-height:30px;}.danmu-random-setting-tips{color:#0b81cc;text-align:center;font-style:italic;}.danmu-random-update-tips{color:#0b81cc;text-align:center;font-size:13px;font-weight:700;margin:10px 0px;}.danmu-random-setting-bottom{width:100%;line-height:35px;}.danmu-random-switch-button-title{font-size:16px;vertical-align:middle;margin-right:4px;color:#095ca2;cursor:help;}.danmu-random-setting-success-tips{text-align:center;display:inline-block;vertical-align:middle;width:34%;}.danmu-random-setting-success-text{font-size:16px;color:#128712;display:none;}.danmu-random-set-button-container{display:inline-block;vertical-align:middle;}';
  175. document.head.appendChild(customerStyle);
  176. },
  177. // initScript = () => {
  178. // let script = document.createElement('script');
  179. // script.type = 'text/javascript';
  180. // script.src = 'https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js';
  181. // document.head.appendChild(script);
  182. // },
  183. getCurrentTimestamp = () => new Date().getTime(),
  184. send = (msg, index) => {
  185. let dmTextArea = document.getElementById('aside-area-vm').getElementsByClassName('chat-input border-box')[0];
  186. if (!dmTextArea) {
  187. alert('找不到输入弹幕文本框,请尝试刷新页面');
  188. return;
  189. }
  190.  
  191. let btnSend = document.getElementsByClassName('bl-button live-skin-highlight-button-bg live-skin-button-text bl-button--primary bl-button--small')[0];
  192. if (!btnSend) {
  193. alert('找不到发送按钮,请尝试刷新页面');
  194. return;
  195. }
  196. // if (getCurrentTimestamp() - lastSent < 5e3) {
  197. // setTimeout(() => send(msg, index), 5e3);
  198. // console.log('===> 发送间隔少于5秒,进入递归处理');
  199. // } else {
  200. dmTextArea.value = msg;
  201. // 定义事件, 定义才可发送
  202. dmTextArea.dispatchEvent(new Event('input', { "bubbles": true, "cancelable": true }));
  203. btnSend.click();
  204. lastSent = getCurrentTimestamp();
  205. ++count;
  206. console.log('===> ' + new Date().toLocaleString() + ' 弹幕发送成功 ' + count + ' 次,第【' + index + '】条数据 === ' + msg);
  207. // }
  208. },
  209. isNull = str => {
  210. if (!str || str == "")
  211. return true;
  212.  
  213. let regu = "^[ ]+$";
  214. let re = new RegExp(regu);
  215. return re.test(str);
  216. },
  217. randomSort = arr => {
  218. for (let i = 0; i < arr.length; i++) {
  219. const rdIndex = Math.floor(Math.random() * arr.length);
  220. const temp = arr[i];
  221. arr[i] = arr[rdIndex];
  222. arr[rdIndex] = temp;
  223. }
  224.  
  225. return arr;
  226. },
  227. clearWaiters = () => {
  228. for (let i = 0; i < waiters.length; i++) {
  229. workerTimer.clearInterval(waiters[i]);
  230. waiters[i] = null;
  231. }
  232.  
  233. waiters = [];
  234. },
  235. signIn = () => {
  236. if (!signInTimer) {
  237. let timestamp = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()).getTime() - getCurrentTimestamp();
  238. console.log('===> 设置凌晨打卡定时器【' + timestamp + '】');
  239. signInTimer = workerTimer.setTimeout(() => {
  240. if (dmButtonSend.textContent === '停止')
  241. send(pdata.signText ? pdata.signText : '打卡', 0);
  242. console.log('===> 进入下一轮递归打卡');
  243. workerTimer.clearTimeout(signInTimer);
  244. signInTimer = null;
  245. signIn();
  246. }, timestamp);
  247. }
  248. },
  249. // selectRandom = () => source.random = rdCheckbox.checked,
  250. setCheckboxChecked = () => {
  251. rdCheckbox.checked = source.random;
  252. group1Checkbox.checked = source.data1.available;
  253. group2Checkbox.checked = source.data2.available;
  254. group3Checkbox.checked = source.data3.available;
  255. group4Checkbox.checked = source.data4.available;
  256. group5Checkbox.checked = source.data5.available;
  257. },
  258. openSetting = () => divSetting.style.display = 'block',
  259. closeSetting = () => {
  260. setCheckboxChecked();
  261. divSetting.style.display = 'none';
  262. },
  263. initData = () => {
  264. if (source.data1.values.length <= 0
  265. && source.data2.values.length <= 0
  266. && source.data3.values.length <= 0
  267. && source.data4.values.length <= 0
  268. && source.data5.values.length <= 0) {
  269. return data ? data : [];
  270. }
  271.  
  272. let result = [];
  273. result = source.data1.available ? result.concat(source.data1.values) : result;
  274. result = source.data2.available ? result.concat(source.data2.values) : result;
  275. result = source.data3.available ? result.concat(source.data3.values) : result;
  276. result = source.data4.available ? result.concat(source.data4.values) : result;
  277. result = source.data5.available ? result.concat(source.data5.values) : result;
  278. data = result;
  279. source.random ? data = randomSort(result) : arrayIndex = 0;
  280. },
  281. applySetting = () => {
  282. source.data1.values = isNull(dataText1.value) ? [] : dataText1.value.split('|');
  283. source.data2.values = isNull(dataText2.value) ? [] : dataText2.value.split('|');
  284. source.data3.values = isNull(dataText3.value) ? [] : dataText3.value.split('|');
  285. source.data4.values = isNull(dataText4.value) ? [] : dataText4.value.split('|');
  286. source.data5.values = isNull(dataText5.value) ? [] : dataText5.value.split('|');
  287. source.random = rdCheckbox.checked;
  288. source.data1.available = group1Checkbox.checked;
  289. source.data2.available = group2Checkbox.checked;
  290. source.data3.available = group3Checkbox.checked;
  291. source.data4.available = group4Checkbox.checked;
  292. source.data5.available = group5Checkbox.checked;
  293. initData();
  294. setGmValue(roomId, source);
  295. spanApplyTip.style.display = 'block';
  296. setTimeout(() => {
  297. spanApplyTip.style.display = 'none';
  298. divSetting.style.display = 'none';
  299. }, 1500);
  300. },
  301. danmu = () => {
  302. if (data.length < 1) {
  303. gmNotice({
  304. text: '请任意在一个分组里输入一条弹幕',
  305. title: '没有弹幕数据,请先设置',
  306. image: icoUrl,
  307. highlight: true,
  308. timeout: noticeTimeout
  309. });
  310. return false;
  311. }
  312. if (source.random)
  313. arrayIndex = Math.floor((Math.random() * data.length));
  314.  
  315. send(data[arrayIndex], arrayIndex);
  316. ++arrayIndex;
  317. if (arrayIndex >= data.length)
  318. arrayIndex = 0;
  319.  
  320. return true;
  321. },
  322. offOrOn = () => {
  323. let timeout = 0;
  324. if (sendTimer) {
  325. workerTimer.clearInterval(sendTimer);
  326. sendTimer = null;
  327. dmButtonSend.style.background = 'rgba(217,157,27,1)';
  328. dmButtonSend.textContent = '开始';
  329. dmInput.removeAttribute("disabled");
  330. } else {
  331. timeout = isNull(dmInput.value) ? default_timeout * 1e3 : dmInput.value * 1e3;
  332. if (!danmu())
  333. return;
  334.  
  335. sendTimer = workerTimer.setInterval(danmu, timeout);
  336. dmButtonSend.style.background = '#ff0000';
  337. dmButtonSend.textContent = '停止';
  338. dmInput.setAttribute('disabled', 'disabled');
  339. }
  340. },
  341. buildPanel = divButton => {
  342. /* ----------------------------------------- head ----------------------------------------- */
  343. let divSettingTitle = document.createElement('div');
  344. divSettingTitle.textContent = '弹幕设置';
  345. divSettingTitle.classList.add('danmu-random-setting-title');
  346.  
  347. let divTip = document.createElement('div');
  348. divTip.classList.add('danmu-random-setting-tips');
  349. divTip.innerHTML = '任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';
  350.  
  351. let divUpdateTip = document.createElement('div');
  352. divUpdateTip.classList.add('danmu-random-update-tips');
  353. divUpdateTip.innerHTML = `<span style="color:#f00">更新提示:</span>${updateTips}`;
  354. /* ----------------------------------------- head ----------------------------------------- */
  355.  
  356. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  357. let divText1 = document.createElement('div');
  358. divText1.textContent = '分组 1 :';
  359. divText1.classList.add('danmu-group-title');
  360.  
  361. group1Checkbox = document.createElement('input');
  362. group1Checkbox.type = 'checkbox';
  363. group1Checkbox.id = 'group1Checkbox';
  364. group1Checkbox.checked = true;
  365.  
  366. let lblGroup1Checkbox = document.createElement('label');
  367. lblGroup1Checkbox.setAttribute('for', 'group1Checkbox');
  368. lblGroup1Checkbox.classList.add('switch-check-label');
  369.  
  370. let divGroup1Checkbox = document.createElement('div');
  371. divGroup1Checkbox.classList.add('switch-check');
  372. divGroup1Checkbox.appendChild(group1Checkbox);
  373. divGroup1Checkbox.appendChild(lblGroup1Checkbox);
  374.  
  375. dataText1 = document.createElement('textarea');
  376. dataText1.classList.add('danmu-group-textarea');
  377. dataText1.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  378. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  379.  
  380. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  381. let divText2 = document.createElement('div');
  382. divText2.textContent = '分组 2 :';
  383. divText2.classList.add('danmu-group-title');
  384.  
  385. group2Checkbox = document.createElement('input');
  386. group2Checkbox.type = 'checkbox';
  387. group2Checkbox.id = 'group2Checkbox';
  388. group2Checkbox.checked = true;
  389.  
  390. let lblGroup2Checkbox = document.createElement('label');
  391. lblGroup2Checkbox.setAttribute('for', 'group2Checkbox');
  392. lblGroup2Checkbox.classList.add('switch-check-label');
  393.  
  394. let divGroup2Checkbox = document.createElement('div');
  395. divGroup2Checkbox.classList.add('switch-check');
  396. divGroup2Checkbox.appendChild(group2Checkbox);
  397. divGroup2Checkbox.appendChild(lblGroup2Checkbox);
  398.  
  399. dataText2 = document.createElement('textarea');
  400. dataText2.classList.add('danmu-group-textarea');
  401. dataText2.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  402. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  403.  
  404. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  405. let divText3 = document.createElement('div');
  406. divText3.textContent = '分组 3 :';
  407. divText3.classList.add('danmu-group-title');
  408.  
  409. group3Checkbox = document.createElement('input');
  410. group3Checkbox.type = 'checkbox';
  411. group3Checkbox.id = 'group3Checkbox';
  412. group3Checkbox.checked = true;
  413.  
  414. let lblGroup3Checkbox = document.createElement('label');
  415. lblGroup3Checkbox.setAttribute('for', 'group3Checkbox');
  416. lblGroup3Checkbox.classList.add('switch-check-label');
  417.  
  418. let divGroup3Checkbox = document.createElement('div');
  419. divGroup3Checkbox.classList.add('switch-check');
  420. divGroup3Checkbox.appendChild(group3Checkbox);
  421. divGroup3Checkbox.appendChild(lblGroup3Checkbox);
  422.  
  423. dataText3 = document.createElement('textarea');
  424. dataText3.classList.add('danmu-group-textarea');
  425. dataText3.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  426. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  427.  
  428. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  429. let divText4 = document.createElement('div');
  430. divText4.textContent = '分组 4 :';
  431. divText4.classList.add('danmu-group-title');
  432.  
  433. group4Checkbox = document.createElement('input');
  434. group4Checkbox.type = 'checkbox';
  435. group4Checkbox.id = 'group4Checkbox';
  436. group4Checkbox.checked = true;
  437.  
  438. let lblGroup4Checkbox = document.createElement('label');
  439. lblGroup4Checkbox.setAttribute('for', 'group4Checkbox');
  440. lblGroup4Checkbox.classList.add('switch-check-label');
  441.  
  442. let divGroup4Checkbox = document.createElement('div');
  443. divGroup4Checkbox.classList.add('switch-check');
  444. divGroup4Checkbox.appendChild(group4Checkbox);
  445. divGroup4Checkbox.appendChild(lblGroup4Checkbox);
  446.  
  447. dataText4 = document.createElement('textarea');
  448. dataText4.classList.add('danmu-group-textarea');
  449. dataText4.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  450. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  451.  
  452. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  453. let divText5 = document.createElement('div');
  454. divText5.textContent = '分组 5 :';
  455. divText5.classList.add('danmu-group-title');
  456.  
  457. group5Checkbox = document.createElement('input');
  458. group5Checkbox.type = 'checkbox';
  459. group5Checkbox.id = 'group5Checkbox';
  460. group5Checkbox.checked = true;
  461.  
  462. let lblGroup5Checkbox = document.createElement('label');
  463. lblGroup5Checkbox.setAttribute('for', 'group5Checkbox');
  464. lblGroup5Checkbox.classList.add('switch-check-label');
  465.  
  466. let divGroup5Checkbox = document.createElement('div');
  467. divGroup5Checkbox.classList.add('switch-check');
  468. divGroup5Checkbox.appendChild(group5Checkbox);
  469. divGroup5Checkbox.appendChild(lblGroup5Checkbox);
  470.  
  471. dataText5 = document.createElement('textarea');
  472. dataText5.classList.add('danmu-group-textarea');
  473. dataText5.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  474. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  475.  
  476. /* ----------------------------------------- random chackbox ----------------------------------------- */
  477. let descCheckbox = document.createElement('span');
  478. descCheckbox.textContent = '随机';
  479. descCheckbox.title = '将合并所有分组数据,从中随机选出一条发送';
  480. descCheckbox.classList.add('danmu-random-switch-button-title');
  481.  
  482. rdCheckbox = document.createElement('input');
  483. rdCheckbox.type = 'checkbox';
  484. rdCheckbox.id = 'rdmCheckbox';
  485. rdCheckbox.checked = true;
  486. // rdCheckbox.addEventListener('click', selectRandom);
  487.  
  488. let lblCheckbox = document.createElement('label');
  489. lblCheckbox.setAttribute('for', 'rdmCheckbox');
  490. lblCheckbox.classList.add('switch-check-label');
  491.  
  492. let divCheckbox = document.createElement('div');
  493. divCheckbox.classList.add('switch-check');
  494. divCheckbox.style.marginLeft = '10px';
  495. divCheckbox.appendChild(descCheckbox);
  496. divCheckbox.appendChild(rdCheckbox);
  497. divCheckbox.appendChild(lblCheckbox);
  498. /* ----------------------------------------- random chackbox ----------------------------------------- */
  499.  
  500. /* ----------------------------------------- div tip ----------------------------------------- */
  501. spanApplyTip = document.createElement('span');
  502. spanApplyTip.textContent = '设置成功';
  503. spanApplyTip.classList.add('danmu-random-setting-success-text');
  504.  
  505. let divApplyTip = document.createElement('div');
  506. divApplyTip.classList.add('danmu-random-setting-success-tips');
  507. divApplyTip.appendChild(spanApplyTip);
  508. /* ----------------------------------------- div tip ----------------------------------------- */
  509.  
  510. /* ----------------------------------------- appley and close button ----------------------------------------- */
  511. let btnApplySetting = document.createElement('i');
  512. btnApplySetting.setAttribute('title', '应用');
  513. btnApplySetting.classList.add('el-button');
  514. btnApplySetting.classList.add('el-icon-check');
  515. btnApplySetting.classList.add('is-circle');
  516. btnApplySetting.addEventListener('click', applySetting);
  517.  
  518. let btnCloseSetting = document.createElement('i');
  519. btnCloseSetting.setAttribute('title', '关闭');
  520. btnCloseSetting.classList.add('el-button');
  521. btnCloseSetting.classList.add('el-icon-close');
  522. btnCloseSetting.classList.add('is-circle');
  523. btnCloseSetting.addEventListener('click', closeSetting);
  524.  
  525. let divSettingButton = document.createElement('div');
  526. divSettingButton.classList.add('danmu-random-set-button-container');
  527. divSettingButton.appendChild(btnApplySetting);
  528. divSettingButton.appendChild(btnCloseSetting);
  529. /* ----------------------------------------- appley and close button ----------------------------------------- */
  530.  
  531. /* ----------------------------------------- container ----------------------------------------- */
  532. let divBottomContainer = document.createElement('div');
  533. divBottomContainer.classList.add('danmu-random-setting-bottom');
  534. divBottomContainer.appendChild(divCheckbox);
  535. divBottomContainer.appendChild(divApplyTip);
  536. divBottomContainer.appendChild(divSettingButton);
  537.  
  538. let divContainer = document.createElement('div');
  539. divContainer.style.height = 'calc(98% - 30px - 25px)';
  540. divContainer.appendChild(divText1);
  541. divContainer.appendChild(divGroup1Checkbox);
  542. divContainer.appendChild(dataText1);
  543. divContainer.appendChild(divText2);
  544. divContainer.appendChild(divGroup2Checkbox);
  545. divContainer.appendChild(dataText2);
  546. divContainer.appendChild(divText3);
  547. divContainer.appendChild(divGroup3Checkbox);
  548. divContainer.appendChild(dataText3);
  549. divContainer.appendChild(divText4);
  550. divContainer.appendChild(divGroup4Checkbox);
  551. divContainer.appendChild(dataText4);
  552. divContainer.appendChild(divText5);
  553. divContainer.appendChild(divGroup5Checkbox);
  554. divContainer.appendChild(dataText5);
  555. divContainer.appendChild(divBottomContainer);
  556. /* ----------------------------------------- container ----------------------------------------- */
  557.  
  558. divSetting = document.createElement('div');
  559. divSetting.id = 'danmu-setting-panel';
  560. divSetting.classList.add('danmu-random-setting-panel');
  561. divSetting.appendChild(divSettingTitle);
  562. divSetting.appendChild(divTip);
  563. divSetting.appendChild(divUpdateTip);
  564. divSetting.appendChild(divContainer);
  565.  
  566. let asideAreaVm = document.getElementById('aside-area-vm');
  567. asideAreaVm.appendChild(divSetting);
  568.  
  569. /* ----------------------------------------- function ----------------------------------------- */
  570. dmButtonSend = document.createElement('button');
  571. dmButtonSend.textContent = '开始';
  572. dmButtonSend.style.minWidth = '65px';
  573. dmButtonSend.style.height = '24px';
  574. dmButtonSend.style.fontSize = '12px';
  575. dmButtonSend.style.borderRadius = '4px';
  576. dmButtonSend.style.color = '#ffffff';
  577. dmButtonSend.style.background = 'rgba(217,157,27,1)';
  578. dmButtonSend.style.border = '0';
  579. dmButtonSend.style.cursor = 'pointer';
  580. //dmButtonSend.onclick = function() { alert('Hello world');}
  581. dmButtonSend.addEventListener('click', offOrOn);
  582.  
  583. let beforeSpan = document.createElement('span');
  584. beforeSpan.textContent = '每';
  585. beforeSpan.style.color = '#ffffff';
  586. beforeSpan.style.fontSize = '12px';
  587. beforeSpan.style.marginLeft = '4px';
  588. beforeSpan.style.backgroundColor = '#ec6c1b';
  589.  
  590. dmInput = document.createElement('input');
  591. dmInput.value = default_timeout;
  592. dmInput.style.width = '25px';
  593. dmInput.style.height = '15px';
  594. dmInput.style.margin = '0 3px';
  595. dmInput.style.border = '0';
  596. dmInput.style.borderRadius = '3px';
  597. dmInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  598.  
  599. let afterSpan = document.createElement('span');
  600. afterSpan.textContent = '秒发送';
  601. afterSpan.style.color = '#ffffff';
  602. afterSpan.style.fontSize = '12px';
  603. afterSpan.style.backgroundColor = '#ec6c1b';
  604. afterSpan.style.marginRight = '4px';
  605.  
  606. let iElement = document.createElement('i');
  607. iElement.classList.add('el-icon-setting');
  608.  
  609. let btnSetting = document.createElement('button');
  610. btnSetting.title = '设置';
  611. btnSetting.classList.add('el-button');
  612. btnSetting.classList.add('el-button--mini');
  613. btnSetting.classList.add('is-circle');
  614. btnSetting.addEventListener('click', openSetting);
  615. btnSetting.appendChild(iElement);
  616.  
  617. // let btnSetting = document.createElement('ion-icon');
  618. // btnSetting.setAttribute('name', 'settings-sharp');
  619. // btnSetting.classList.add('el-button');
  620. // btnSetting.classList.add('el-button--mini');
  621. // btnSetting.classList.add('is-circle');
  622. // btnSetting.addEventListener('click', openSetting);
  623.  
  624. let div = document.createElement('div');
  625. div.style.position = 'absolute';
  626. div.appendChild(dmButtonSend);
  627. div.appendChild(beforeSpan);
  628. div.appendChild(dmInput);
  629. div.appendChild(afterSpan);
  630. div.appendChild(btnSetting);
  631. divButton.appendChild(div);
  632. /* ----------------------------------------- function ----------------------------------------- */
  633. },
  634. removeElements = () => {
  635. let switchLoginGuideVm = document.getElementById('switch-login-guide-vm');
  636. if (switchLoginGuideVm)
  637. switchLoginGuideVm.style.setProperty('display', 'none', 'important');
  638.  
  639. let myDearHarunaVm = document.getElementById('my-dear-haruna-vm');
  640. if (myDearHarunaVm)
  641. myDearHarunaVm.style.setProperty('display', 'none', 'important');
  642.  
  643. let shopPopoverVm = document.getElementById('shop-popover-vm');
  644. if (shopPopoverVm)
  645. shopPopoverVm.style.setProperty('display', 'none', 'important');
  646.  
  647. if (removeElementsTimer) {
  648. workerTimer.clearInterval(removeElementsTimer);
  649. removeElementsTimer = null;
  650. }
  651. removeElementsTimer = workerTimer.setInterval(() => {
  652. ++removeElementsTimerCount;
  653. let ltRow = document.getElementsByClassName('lt-row')[0];
  654. if (ltRow) {
  655. ltRow.style.setProperty('display', 'none', 'important');
  656. if (removeElementsTimer) {
  657. workerTimer.clearInterval(removeElementsTimer);
  658. removeElementsTimer = null;
  659. }
  660. }
  661. if (30 <= removeElementsTimerCount && removeElementsTimer) {
  662. workerTimer.clearInterval(removeElementsTimer);
  663. removeElementsTimer = null;
  664. }
  665. }, 10e3);
  666. },
  667. loadData = () => {
  668. let obj = getGmValue(roomId, null);
  669. if (obj) {
  670. if (source.version === obj.version) {
  671. source = obj;
  672. }
  673. else if (obj.version === 2) {
  674. source.data1 = obj.data1;
  675. source.data2 = obj.data2;
  676. source.data3 = obj.data3;
  677. source.data4 = obj.data4;
  678. source.data5 = obj.data5;
  679. setGmValue(roomId, source);
  680. } else {
  681. source.data1.values = obj.data1 ? obj.data1 : source.data1.values;
  682. source.data2.values = obj.data2 ? obj.data2 : source.data2.values;
  683. source.data3.values = obj.data3 ? obj.data3 : source.data3.values;
  684. source.data4.values = obj.data4 ? obj.data4 : source.data4.values;
  685. source.data5.values = obj.data5 ? obj.data5 : source.data5.values;
  686. setGmValue(roomId, source);
  687. }
  688. }
  689.  
  690. setCheckboxChecked();
  691. dataText1.value = source.data1.values.join('|');
  692. dataText2.value = source.data2.values.join('|');
  693. dataText3.value = source.data3.values.join('|');
  694. dataText4.value = source.data4.values.join('|');
  695. dataText5.value = source.data5.values.join('|');
  696. initData();
  697. },
  698. heartBeat = async () => {
  699. const arg = `${hbInterval}|${roomId}|1|0`;
  700. // const argBase64 = CryptoJS ? CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(arg)) : window.btoa(unescape(encodeURIComponent(arg)));
  701. const argBase64 = window.btoa(unescape(encodeURIComponent(arg)));
  702. try {
  703. const result = await fetch(`//live-trace.bilibili.com/xlive/rdata-interface/v1/heartbeat/webHeartBeat?hb=${encodeURIComponent(argBase64)}&pf=web`, {
  704. mode: 'cors',
  705. credentials: 'include',
  706. }).then(res => res.json());
  707. if (0 === result.code) {
  708. hbInterval = result.data.next_interval;
  709. } else {
  710. console.error(`===> ${roomId}直播间心跳失败`);
  711. }
  712. } catch (error) {
  713. console.error(`===> ${roomId}直播间心跳网络请求失败`, error);
  714. }
  715.  
  716. let hbTimer = workerTimer.setTimeout(() => {
  717. workerTimer.clearTimeout(hbTimer);
  718. heartBeat();
  719. }, hbInterval * 1e3);
  720. },
  721. initSettingPanel = () => {
  722. let settingPanel = document.getElementById('danmu-setting-panel');
  723. if (!settingPanel) {
  724. console.log('===> 进行面板初始化');
  725. let divButton = document.getElementsByClassName('bottom-actions p-relative')[0];
  726. if (divButton) {
  727. buildPanel(divButton);
  728. loadData();
  729. console.log('===> 面板初始化完成');
  730. } else {
  731. console.warn('===> bottom-actions节点丢失');
  732. return false;
  733. }
  734. }
  735.  
  736. return true;
  737. },
  738. noSleep = () => {
  739. workerTimer.setInterval(() => {
  740. ++noSleepCount;
  741. let noSleepTimeouter = workerTimer.setTimeout(() => {
  742. workerTimer.clearTimeout(noSleepTimeouter);
  743. document.body.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
  744. console.log('===> ' + new Date().toLocaleString() + '第【' + noSleepCount + '】次触发鼠标事件防休眠');
  745. }, Math.random() * 3e3);
  746. }, 17e3);
  747. },
  748. runStart = () => {
  749. if (isOldVersion()) {
  750. // alert('发随机弹幕脚本有新版本,请及时更新');
  751. window.location.href = parentUrl;
  752. // gmNotice({
  753. // text: '当前脚本不是最新版,请更新再使用功能',
  754. // title: '油猴脚本有更新,点击进行安装',
  755. // image: icoUrl,
  756. // highlight: true,
  757. // timeout: 120e3,
  758. // onclick: () => window.open(parentUrl, '_blank')
  759. // });
  760. return;
  761. }
  762.  
  763. noSleep();
  764. waiters[waiters.length] = workerTimer.setInterval(() => {
  765. if (initSettingPanel()) {
  766. clearWaiters();
  767. removeElements();
  768. signIn();
  769. // heartBeat();
  770. console.log('===> 运行成功');
  771. } else {
  772. --waitCount;
  773. if (0 >= waitCount) {
  774. clearWaiters();
  775. console.log('===> 创建面板失败,停止初始化');
  776. }
  777. }
  778. }, 1.5e3);
  779. };
  780.  
  781. initCss();
  782. // initScript();
  783. window.runStart = runStart;
  784. window.arrayInfo = arrayInfo;
  785. window.setGmNotice = setGmNotice;
  786. window.setGmGetValue = setGmGetValue;
  787. window.setGmSetValue = setGmSetValue;
  788. window.setGmDelValue = setGmDelValue;
  789. window.setParentData = setParentData;
  790. window.autoSendDanmuModuleLoaded = true;
  791. })();

QingJ © 2025

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