b-live-random-send-test

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

当前为 2023-12-13 提交的版本,查看 最新版本

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

  1. (function () {
  2. window.autoSendDanmuModuleLoaded = false;
  3. const blobURL = URL.createObjectURL(
  4. new Blob(
  5. [
  6. '(',
  7. function () {
  8. const ids = {};
  9. // 监听message 开始执行定时器或者销毁
  10. self.onmessage = (e) => {
  11. switch (e.data.command) {
  12. case 'interval:start': // 开启定时器
  13. const intervalId = setInterval(() => postMessage({ message: 'interval:tick', id: e.data.id }), e.data.interval);
  14. // postMessage({ message: 'interval:started', id: e.data.id });
  15. ids[e.data.id] = intervalId;
  16. break;
  17. case 'interval:clear': // 销毁
  18. clearInterval(ids[e.data.id]);
  19. postMessage({ message: 'interval:cleared', id: e.data.id });
  20. delete ids[e.data.id];
  21. break;
  22. case 'timeout:start':
  23. const timeoutId = setTimeout(() => postMessage({ message: 'timeout:tick', id: e.data.id }), e.data.timeout);
  24. // postMessage({ message: 'timeout:started', id: e.data.id });
  25. ids[e.data.id] = timeoutId;
  26. break;
  27. case 'timeout:clear':
  28. clearTimeout(ids[e.data.id]);
  29. postMessage({ message: 'timeout:cleared', id: e.data.id });
  30. delete ids[e.data.id];
  31. break;
  32. }
  33. };
  34. }.toString(),
  35. ')()',
  36. ],
  37. { type: 'application/javascript' },
  38. ),
  39. );
  40. const worker = new Worker(blobURL);
  41. URL.revokeObjectURL(blobURL); //用完释放URL对象
  42. const workerTimer = {
  43. id: 0,
  44. callbacks: {},
  45. setInterval: (cb, interval, context) => {
  46. const id = ++workerTimer.id;
  47. workerTimer.callbacks[id] = { fn: cb, context: context };
  48. worker.postMessage({ command: 'interval:start', interval: interval, id: id });
  49. return id;
  50. },
  51. setTimeout: (cb, timeout, context) => {
  52. const id = ++workerTimer.id;
  53. workerTimer.callbacks[id] = { fn: cb, context: context };
  54. worker.postMessage({ command: 'timeout:start', timeout: timeout, id: id });
  55. return id;
  56. },
  57.  
  58. // 监听worker 里面的定时器发送的message 然后执行回调函数
  59. onMessage: (e) => {
  60. switch (e.data.message) {
  61. case 'interval:tick':
  62. case 'timeout:tick':
  63. const callbackItem = workerTimer.callbacks[e.data.id];
  64. if (callbackItem && callbackItem.fn) {
  65. callbackItem.fn.apply(callbackItem.context);
  66. }
  67.  
  68. break;
  69. case 'interval:cleared':
  70. case 'timeout:cleared':
  71. delete workerTimer.callbacks[e.data.id];
  72. break;
  73. }
  74. },
  75.  
  76. // 往worker里面发送销毁指令
  77. clearInterval: (id) => worker.postMessage({ command: 'interval:clear', id: id }),
  78. clearTimeout: (id) => worker.postMessage({ command: 'timeout:clear', id: id }),
  79. };
  80. worker.onmessage = workerTimer.onMessage.bind(workerTimer);
  81.  
  82. let source = {
  83. version: 4,
  84. like: false,
  85. random: true,
  86. usePublic: false,
  87. data1: { available: true, values: ['弹幕①', '弹幕②'] },
  88. data2: { available: true, values: [] },
  89. data3: { available: true, values: [] },
  90. data4: { available: true, values: ['弹幕⑦'] },
  91. data5: { available: true, values: [] }
  92. },
  93. signInCheckbox, hideLoginGuideCheckbox, hideHarunaCheckbox, hideShopCheckbox, noSleepCheckbox, hideGiftControlCheckbox,
  94. hideRoomFeedCheckbox, hideRoomInfoCheckbox, hideNoticeCheckbox, hideFooterCheckbox, lotteryCheckbox, closeLotteryCheckbox, hesitationCheckbox,
  95. hidePrivacyCheckbox, hideRoomStatusCheckbox, setPublicCheckbox,
  96. group1Checkbox, group2Checkbox, group3Checkbox, group4Checkbox, group5Checkbox,
  97. rdCheckbox, usePublicCheckbox, autoLikeCheckbox,
  98. dmInput, divSetting, dataText1, dataText2, dataText3, dataText4, dataText5, signInput, hesitateInput,
  99. dmButtonSend, beforeSpan, afterSpan, bgcolor, spanApplyMsg,
  100. pdata = {}, config = {}, waiters = [], data = [],
  101. sendTimer = null, signInTimer = null, miniCloseTimer, noSleepTimer, noSleepTimeouter, btnLotteryTimer,
  102. divSendBtnTimer, autoLikeTimer, clickLikeBtnTimer,
  103. count = 0, waitCount = 200, arrayIndex = 0, default_timeout = 600, bgcolor_default = 'rgba(217,157,27,1)',
  104. lotteryChecked = 'lottery_checked', closeLotteryChecked = 'close_lottery_checked', hesitationChecked = 'hesitation_checked',
  105. hesitationExpiry = 'hesitation_expiry',
  106. gmNotice = obj => { alert('请更新油猴脚本'); window.location.href = parentUrl; },
  107. getGmValue = (key, defaultValue) => { return null; },
  108. setGmValue = (key, obj) => { console.warn('===> No implementation "setGmValue" method.'); },
  109. delGmValue = key => { console.warn('===> No implementation "delGmValue" method.'); };
  110.  
  111. const minVersion = '2.4.2', version = '1.5.10', upodateInfo = '新增自动点赞设置', noticeTimeout = 10e3,
  112. icoUrl = 'https://www.bilibili.com/favicon.ico',
  113. 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',
  114. // roomId = window.__NEPTUNE_IS_MY_WAIFU__
  115. // ? 0 == window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.short_id
  116. // ? window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.room_id
  117. // : window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.short_id
  118. // : window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
  119. roomId = window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
  120. setGmGetValue = callback => getGmValue = callback,
  121. setGmSetValue = callback => setGmValue = callback,
  122. setGmDelValue = callback => delGmValue = callback,
  123. setGmNotice = callback => gmNotice = callback,
  124. setParentData = obj => pdata = obj,
  125. arrayInfo = () => console.info(data),
  126. isOldVersion = () => {
  127. if (!pdata.version) {
  128. return true;
  129. }
  130. if (minVersion === pdata.version) {
  131. return false;
  132. } else {
  133. let vals = pdata.version.split('.');
  134. let mins = minVersion.split('.');
  135. if (vals.length != mins.length) {
  136. return true;
  137. } else {
  138. for (let i = 0; i < vals.length; i++) {
  139. if (mins[i] > vals[i]) {
  140. return true;
  141. }
  142. }
  143.  
  144. return false;
  145. }
  146. }
  147. },
  148. initCss = () => {
  149. let linkElement = document.createElement('link');
  150. linkElement.rel = 'stylesheet';
  151. linkElement.href = 'https://unpkg.com/element-ui@2.15.9/lib/theme-chalk/index.css';
  152. document.head.appendChild(linkElement);
  153.  
  154. // 图标库 https://ionic.io/ionicons
  155. // let scriptElement = document.createElement('script');
  156. // scriptElement.src = 'https://unpkg.com/ionicons@5.5.2/dist/ionicons.js';
  157. // document.head.appendChild(scriptElement);
  158.  
  159. let customerStyle = document.createElement('style');
  160. customerStyle.setAttribute('type', 'text/css');
  161. 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;}.switch-check-group{margin-top:5px;width:95%;}.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-panel::-webkit-scrollbar{width:4px;height:4px;}.danmu-random-setting-panel::-webkit-scrollbar-thumb{border-radius:5px;-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,0.2);background:rgba(0,0,0,0.2);}.danmu-random-setting-panel::-webkit-scrollbar-track{-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,0.2);border-radius:0;background:rgba(0,0,0,0.1);}.danmu-random-setting-title{text-align:center;font-size:16px;font-weight:700;color:#1c5adc;line-height:30px;}.danmu-random-setting-title-sub{display:inline-block;color:#ee8b8b;height:24px;vertical-align:sub;-webkit-transform:scale(0.7);}.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:14px;vertical-align:middle;margin-left:5px;color:#095ca2;cursor:help;}.danmu-random-setting-success-tips{text-align:center;display:inline-block;vertical-align:middle;width:40%;}.danmu-random-setting-success-text{font-size:16px;color:#128712;display:none;}.danmu-random-set-button-container{display:inline-block;vertical-align:middle;}.global-setting-tip{padding-left:10px;color:red;font-size:14px;font-weight:700;cursor:help;}.disabled{color:#ababab;cursor:not-allowed;}.clean-cache-btn{min-width:70px;font-size:14px;border-radius:4px;color:#fff;background:#d99d1b;border:0px;cursor:pointer;vertical-align:middle;line-height:30px;}.clean-cache-btn:hover{background:rgba(217,157,27,0.8);color:#000}.danmu-btn{min-width:65px;height:24px;font-size:12px;border-radius:4px;color:rgb(255,255,255);background:rgb(217,157,27);border:0px;cursor:pointer;}.danmu-btn:hover{background:var(--color)!important;}.danmu-text-span{color:rgb(255, 255, 255);font-size:12px;background:rgb(236,108,27);}.danmu-second-input{width:25px;height:15px;margin:0px 3px;border:0px;border-radius:3px;}.not-display{display:none !important;}';
  162. document.head.appendChild(customerStyle);
  163. },
  164. // initScript = () => {
  165. // let script = document.createElement('script');
  166. // script.type = 'text/javascript';
  167. // script.src = 'https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js';
  168. // document.head.appendChild(script);
  169. // },
  170. getCurrentTimestamp = () => new Date().getTime(),
  171. send = (msg, index) => {
  172. let dmTextArea = document.getElementById('aside-area-vm').getElementsByClassName('chat-input border-box')[0];
  173. if (!dmTextArea) {
  174. alert('找不到输入弹幕文本框,请尝试刷新页面');
  175. return;
  176. }
  177.  
  178. let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
  179. if (!btnSend) {
  180. alert('找不到发送按钮,请尝试刷新页面');
  181. return;
  182. }
  183. dmTextArea.value = msg;
  184. dmTextArea.dispatchEvent(new Event('input', { "bubbles": true, "cancelable": true }));
  185. btnSend.click();
  186. lastSent = getCurrentTimestamp();
  187. // ++count;
  188. // console.log('===> ' + new Date().toLocaleString() + ' 弹幕发送成功 ' + count + ' 次,第【' + index + '】条数据 === ' + msg);
  189. },
  190. isNull = str => {
  191. if (!str || str == "") {
  192. return true;
  193. }
  194.  
  195. let regu = "^[ ]+$";
  196. let re = new RegExp(regu);
  197. return re.test(str);
  198. },
  199. randomSort = arr => {
  200. for (let i = 0; i < arr.length; i++) {
  201. const rdIndex = Math.floor(Math.random() * arr.length);
  202. const temp = arr[i];
  203. arr[i] = arr[rdIndex];
  204. arr[rdIndex] = temp;
  205. }
  206.  
  207. return arr;
  208. },
  209. clearWaiters = () => {
  210. for (let i = 0; i < waiters.length; i++) {
  211. workerTimer.clearInterval(waiters[i]);
  212. waiters[i] = null;
  213. }
  214.  
  215. waiters = [];
  216. },
  217. signInFunc = () => {
  218. if (signInCheckbox.checked) {
  219. if (!signInTimer) {
  220. let defaultText = isNull(pdata.signText) ? pdata.signText : '打卡';
  221. let timestamp = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()).getTime() - getCurrentTimestamp();
  222. console.log('===> 设置凌晨打卡定时器【' + timestamp + '】');
  223. signInput.value = isNull(config.signInText) ? defaultText : config.signInText;
  224. signInTimer = workerTimer.setTimeout(() => {
  225. send(isNull(signInput.value) ? defaultText : signInput.value, 0);
  226. console.log('===> 设置下一次打卡');
  227. workerTimer.clearTimeout(signInTimer);
  228. signInTimer = null;
  229. signInFunc();
  230. }, timestamp);
  231. }
  232. } else if (signInTimer) {
  233. console.log('===> 关闭自动打卡功能');
  234. workerTimer.clearTimeout(signInTimer);
  235. signInTimer = null;
  236. }
  237. },
  238. setSource = obj => {
  239. dataText1.value = obj.data1.values.length ? obj.data1.values.join('|') : [];
  240. dataText2.value = obj.data2.values.length ? obj.data2.values.join('|') : [];
  241. dataText3.value = obj.data3.values.length ? obj.data3.values.join('|') : [];
  242. dataText4.value = obj.data4.values.length ? obj.data4.values.join('|') : [];
  243. dataText5.value = obj.data5.values.length ? obj.data5.values.join('|') : [];
  244. },
  245. runCheckbox = () => {
  246. usePublicFunc();
  247. hideFooterFunc();
  248. hideGiftControlFunc();
  249. hideLoginGuideFunc();
  250. hideHarunaFunc();
  251. hideShopFunc();
  252. noSleepFunc();
  253. signInFunc();
  254. hidePrivacyFunc();
  255. hideRoomStatusFunc();
  256. lotteryFunc();
  257. hesitationFunc();
  258. closeLotteryFunc();
  259. autoLikeFunc();
  260. hideRoomFeedFunc();
  261. hideRoomInfoFunc();
  262. hideNoticeFunc();
  263. let hideTimeout = workerTimer.setTimeout(() => {
  264. workerTimer.clearTimeout(hideTimeout);
  265. hideRoomFeedFunc();
  266. hideRoomInfoFunc();
  267. hideNoticeFunc();
  268. }, 1e3);
  269. },
  270. setOperationSetting = () => {
  271. setPublicCheckbox.checked = false;
  272. rdCheckbox.checked = source.random;
  273. autoLikeCheckbox.checked = source.like;
  274. usePublicCheckbox.checked = source.usePublic;
  275. group1Checkbox.checked = source.data1.available;
  276. group2Checkbox.checked = source.data2.available;
  277. group3Checkbox.checked = source.data3.available;
  278. group4Checkbox.checked = source.data4.available;
  279. group5Checkbox.checked = source.data5.available;
  280.  
  281. signInCheckbox.checked = config.autoSignIn;
  282. noSleepCheckbox.checked = config.noSleep;
  283. hideLoginGuideCheckbox.checked = config.hideLoginGuide;
  284. hideHarunaCheckbox.checked = config.hideHaruna;
  285. hideShopCheckbox.checked = config.hideShop;
  286. hideGiftControlCheckbox.checked = config.hideGift;
  287. hideRoomFeedCheckbox.checked = config.hideRoomFeed;
  288. hideRoomInfoCheckbox.checked = config.hideRoomInfo;
  289. hideNoticeCheckbox.checked = config.hideNotice;
  290. hideFooterCheckbox.checked = config.hideFooter;
  291. lotteryCheckbox.checked = config.lottery;
  292. hesitationCheckbox.checked = config.hesitation;
  293. closeLotteryCheckbox.checked = config.closeLottery;
  294. hidePrivacyCheckbox.checked = config.noPrivacy;
  295. hideRoomStatusCheckbox.checked = config.hideWatermark;
  296. runCheckbox();
  297. },
  298. openSetting = () => divSetting.style.display = 'block',
  299. closeSetting = () => {
  300. setOperationSetting();
  301. divSetting.style.display = 'none';
  302. },
  303. initData = () => {
  304. if (source.data1.values.length <= 0
  305. && source.data2.values.length <= 0
  306. && source.data3.values.length <= 0
  307. && source.data4.values.length <= 0
  308. && source.data5.values.length <= 0) {
  309. return data ? data : [];
  310. }
  311.  
  312. let result = [];
  313. result = source.data1.available ? result.concat(source.data1.values) : result;
  314. result = source.data2.available ? result.concat(source.data2.values) : result;
  315. result = source.data3.available ? result.concat(source.data3.values) : result;
  316. result = source.data4.available ? result.concat(source.data4.values) : result;
  317. result = source.data5.available ? result.concat(source.data5.values) : result;
  318. data = result;
  319. rdCheckbox.checked ? data = randomSort(result) : arrayIndex = 0;
  320. },
  321. flashMsg = (txt, back, color) => {
  322. spanApplyMsg.textContent = txt;
  323. spanApplyMsg.style.display = 'block';
  324. if (color) {
  325. spanApplyMsg.style.color = color;
  326. }
  327. else {
  328. spanApplyMsg.style.color = '#128712';
  329. }
  330.  
  331. let hideTipTimer = workerTimer.setTimeout(() => {
  332. workerTimer.clearTimeout(hideTipTimer);
  333. spanApplyMsg.style.display = 'none';
  334. spanApplyMsg.textContent = '';
  335. if (back) {
  336. divSetting.style.display = 'none';
  337. }
  338. }, 1.5e3);
  339. },
  340. save = () => {
  341. if (!pdata || isNull(pdata.defaultKey) || isNull(pdata.configKey)) {
  342. flashMsg('保存失败', false, 'red');
  343. return;
  344. }
  345. if (pdata.configKey) {
  346. config.autoSignIn = signInCheckbox.checked;
  347. config.signInText = signInput.value;
  348. config.noSleep = noSleepCheckbox.checked;
  349. config.hideLoginGuide = hideLoginGuideCheckbox.checked;
  350. config.hideHaruna = hideHarunaCheckbox.checked;
  351. config.hideShop = hideShopCheckbox.checked;
  352. config.hideGift = hideGiftControlCheckbox.checked;
  353. config.hideRoomFeed = hideRoomFeedCheckbox.checked;
  354. config.hideRoomInfo = hideRoomInfoCheckbox.checked;
  355. config.hideNotice = hideNoticeCheckbox.checked;
  356. config.hideFooter = hideFooterCheckbox.checked;
  357. config.lottery = lotteryCheckbox.checked;
  358. window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
  359. config.hesitation = hesitationCheckbox.checked;
  360. window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
  361. config.hesitationExpiry = hesitateInput.value;
  362. window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
  363. config.closeLottery = closeLotteryCheckbox.checked;
  364. window.localStorage.setItem(closeLotteryChecked, config.closeLottery);
  365. config.noPrivacy = hidePrivacyCheckbox.checked;
  366. config.hideWatermark = hideRoomStatusCheckbox.checked;
  367. setGmValue(pdata.configKey, config);
  368. }
  369.  
  370. let v1 = isNull(dataText1.value) ? [] : dataText1.value.split('|'),
  371. v2 = isNull(dataText2.value) ? [] : dataText2.value.split('|'),
  372. v3 = isNull(dataText3.value) ? [] : dataText3.value.split('|'),
  373. v4 = isNull(dataText4.value) ? [] : dataText4.value.split('|'),
  374. v5 = isNull(dataText5.value) ? [] : dataText5.value.split('|');
  375. source.random = rdCheckbox.checked;
  376. source.like = autoLikeCheckbox.checked;
  377. source.usePublic = usePublicCheckbox.checked;
  378. source.data1.available = group1Checkbox.checked;
  379. source.data2.available = group2Checkbox.checked;
  380. source.data3.available = group3Checkbox.checked;
  381. source.data4.available = group4Checkbox.checked;
  382. source.data5.available = group5Checkbox.checked;
  383. if (!usePublicCheckbox.checked) {
  384. source.data1.values = v1;
  385. source.data2.values = v2;
  386. source.data3.values = v3;
  387. source.data4.values = v4;
  388. source.data5.values = v5;
  389. }
  390. setGmValue(roomId, source);
  391. if (setPublicCheckbox.checked) {
  392. let ps = {data1:{},data2:{},data3:{},data4:{},data5:{}};
  393. ps.data1.values = v1;
  394. ps.data2.values = v2;
  395. ps.data3.values = v3;
  396. ps.data4.values = v4;
  397. ps.data5.values = v5;
  398. setGmValue(pdata.defaultKey, ps);
  399. }
  400. if (usePublicCheckbox.checked) {
  401. source.data1.values = v1;
  402. source.data2.values = v2;
  403. source.data3.values = v3;
  404. source.data4.values = v4;
  405. source.data5.values = v5;
  406. }
  407. initData();
  408. flashMsg('设置成功', true);
  409. },
  410. cleanCache = () => {
  411. if (pdata.configKey && config) {
  412. config.script = '';
  413. config.lastUpdate = '清除缓存';
  414. setGmValue(pdata.configKey, config);
  415. flashMsg('清除成功');
  416. } else {
  417. console.warn('元数据丢失');
  418. flashMsg('操作失败', false, 'red');
  419. }
  420. },
  421. danmu = () => {
  422. if (data.length < 1) {
  423. alert('请先设置弹幕');
  424. return false;
  425. }
  426. if (rdCheckbox.checked) {
  427. arrayIndex = Math.floor((Math.random() * data.length));
  428. }
  429.  
  430. send(data[arrayIndex], arrayIndex);
  431. ++arrayIndex;
  432. if (arrayIndex >= data.length) {
  433. arrayIndex = 0;
  434. }
  435.  
  436. return true;
  437. },
  438. offOrOn = () => {
  439. let timeout = 0;
  440. if (sendTimer) {
  441. workerTimer.clearInterval(sendTimer);
  442. sendTimer = null;
  443. dmButtonSend.style.background = isNull(bgcolor) ? bgcolor_default : bgcolor;
  444. dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  445. dmButtonSend.textContent = '开始';
  446. dmInput.removeAttribute("disabled");
  447. } else {
  448. timeout = (isNull(dmInput.value) ? default_timeout : dmInput.value) * 1e3;
  449. if (!danmu()) {
  450. return;
  451. }
  452.  
  453. sendTimer = workerTimer.setInterval(danmu, timeout);
  454. dmButtonSend.style.background = 'rgba(255,0,0,1)';
  455. dmButtonSend.style.setProperty('--color', 'rgba(255,0,0,0.8)');
  456. dmButtonSend.textContent = '停止';
  457. dmInput.setAttribute('disabled', 'disabled');
  458. }
  459. },
  460. createSwitch = (id, txt, title, func, container, indent, width, hidden, rear, disabled) => {
  461. let checkbox = document.createElement('input');
  462. checkbox.type = 'checkbox';
  463. checkbox.id = id;
  464. checkbox.checked = false;
  465. if (func && !disabled) {
  466. checkbox.addEventListener('click', func);
  467. }
  468.  
  469. let lblCheckbox = document.createElement('label');
  470. lblCheckbox.setAttribute('for', id);
  471. lblCheckbox.classList.add('switch-check-label');
  472.  
  473. let descSpan = document.createElement('span');
  474. descSpan.textContent = txt;
  475. descSpan.title = title;
  476. descSpan.classList.add('danmu-random-switch-button-title');
  477. if (disabled) {
  478. checkbox.disabled = true;
  479. checkbox.classList.add('disabled');
  480. lblCheckbox.classList.add('disabled');
  481. descSpan.classList.add('disabled');
  482. }
  483.  
  484. let divCheckbox = document.createElement('div');
  485. divCheckbox.id = id + 'Div';
  486. divCheckbox.classList.add('switch-check');
  487. divCheckbox.classList.add('switch-check-group');
  488. divCheckbox.appendChild(checkbox);
  489. divCheckbox.appendChild(lblCheckbox);
  490. divCheckbox.appendChild(descSpan);
  491. if (!isNull(indent)) {
  492. divCheckbox.style.marginLeft = indent;
  493. }
  494. if (!isNull(width)) {
  495. divCheckbox.style.width = width;
  496. }
  497. if (hidden) {
  498. divCheckbox.style.setProperty('display', 'none');
  499. }
  500. if (rear) {
  501. divCheckbox.appendChild(rear);
  502. }
  503.  
  504. container.appendChild(divCheckbox);
  505. return checkbox;
  506. },
  507. buildPanel = divButton => {
  508. /* ----------------------------------------- head ----------------------------------------- */
  509. let divSettingTitle = document.createElement('div');
  510. divSettingTitle.textContent = '弹幕设置';
  511. divSettingTitle.classList.add('danmu-random-setting-title');
  512.  
  513. let divSub = document.createElement('div');
  514. divSub.textContent = version;
  515. divSub.classList.add('danmu-random-setting-title-sub');
  516. divSettingTitle.appendChild(divSub);
  517.  
  518. let divTip = document.createElement('div');
  519. divTip.classList.add('danmu-random-setting-tips');
  520. divTip.innerHTML = '任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';
  521.  
  522. let divUpdateTip = document.createElement('div');
  523. divUpdateTip.classList.add('danmu-random-update-tips');
  524. divUpdateTip.innerHTML = `<span style="color:#f00">更新提示:</span>${upodateInfo}`;
  525. /* ----------------------------------------- head ----------------------------------------- */
  526.  
  527. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  528. let divText1 = document.createElement('div');
  529. divText1.textContent = '分组 1 :';
  530. divText1.classList.add('danmu-group-title');
  531.  
  532. group1Checkbox = document.createElement('input');
  533. group1Checkbox.type = 'checkbox';
  534. group1Checkbox.id = 'group1Checkbox';
  535. group1Checkbox.checked = true;
  536.  
  537. let lblGroup1Checkbox = document.createElement('label');
  538. lblGroup1Checkbox.setAttribute('for', 'group1Checkbox');
  539. lblGroup1Checkbox.classList.add('switch-check-label');
  540.  
  541. let divGroup1Checkbox = document.createElement('div');
  542. divGroup1Checkbox.classList.add('switch-check');
  543. divGroup1Checkbox.appendChild(group1Checkbox);
  544. divGroup1Checkbox.appendChild(lblGroup1Checkbox);
  545.  
  546. dataText1 = document.createElement('textarea');
  547. dataText1.classList.add('danmu-group-textarea');
  548. dataText1.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  549. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  550.  
  551. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  552. let divText2 = document.createElement('div');
  553. divText2.textContent = '分组 2 :';
  554. divText2.classList.add('danmu-group-title');
  555.  
  556. group2Checkbox = document.createElement('input');
  557. group2Checkbox.type = 'checkbox';
  558. group2Checkbox.id = 'group2Checkbox';
  559. group2Checkbox.checked = true;
  560.  
  561. let lblGroup2Checkbox = document.createElement('label');
  562. lblGroup2Checkbox.setAttribute('for', 'group2Checkbox');
  563. lblGroup2Checkbox.classList.add('switch-check-label');
  564.  
  565. let divGroup2Checkbox = document.createElement('div');
  566. divGroup2Checkbox.classList.add('switch-check');
  567. divGroup2Checkbox.appendChild(group2Checkbox);
  568. divGroup2Checkbox.appendChild(lblGroup2Checkbox);
  569.  
  570. dataText2 = document.createElement('textarea');
  571. dataText2.classList.add('danmu-group-textarea');
  572. dataText2.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  573. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  574.  
  575. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  576. let divText3 = document.createElement('div');
  577. divText3.textContent = '分组 3 :';
  578. divText3.classList.add('danmu-group-title');
  579.  
  580. group3Checkbox = document.createElement('input');
  581. group3Checkbox.type = 'checkbox';
  582. group3Checkbox.id = 'group3Checkbox';
  583. group3Checkbox.checked = true;
  584.  
  585. let lblGroup3Checkbox = document.createElement('label');
  586. lblGroup3Checkbox.setAttribute('for', 'group3Checkbox');
  587. lblGroup3Checkbox.classList.add('switch-check-label');
  588.  
  589. let divGroup3Checkbox = document.createElement('div');
  590. divGroup3Checkbox.classList.add('switch-check');
  591. divGroup3Checkbox.appendChild(group3Checkbox);
  592. divGroup3Checkbox.appendChild(lblGroup3Checkbox);
  593.  
  594. dataText3 = document.createElement('textarea');
  595. dataText3.classList.add('danmu-group-textarea');
  596. dataText3.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  597. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  598.  
  599. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  600. let divText4 = document.createElement('div');
  601. divText4.textContent = '分组 4 :';
  602. divText4.classList.add('danmu-group-title');
  603.  
  604. group4Checkbox = document.createElement('input');
  605. group4Checkbox.type = 'checkbox';
  606. group4Checkbox.id = 'group4Checkbox';
  607. group4Checkbox.checked = true;
  608.  
  609. let lblGroup4Checkbox = document.createElement('label');
  610. lblGroup4Checkbox.setAttribute('for', 'group4Checkbox');
  611. lblGroup4Checkbox.classList.add('switch-check-label');
  612.  
  613. let divGroup4Checkbox = document.createElement('div');
  614. divGroup4Checkbox.classList.add('switch-check');
  615. divGroup4Checkbox.appendChild(group4Checkbox);
  616. divGroup4Checkbox.appendChild(lblGroup4Checkbox);
  617.  
  618. dataText4 = document.createElement('textarea');
  619. dataText4.classList.add('danmu-group-textarea');
  620. dataText4.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  621. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  622.  
  623. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  624. let divText5 = document.createElement('div');
  625. divText5.textContent = '分组 5 :';
  626. divText5.classList.add('danmu-group-title');
  627.  
  628. group5Checkbox = document.createElement('input');
  629. group5Checkbox.type = 'checkbox';
  630. group5Checkbox.id = 'group5Checkbox';
  631. group5Checkbox.checked = true;
  632.  
  633. let lblGroup5Checkbox = document.createElement('label');
  634. lblGroup5Checkbox.setAttribute('for', 'group5Checkbox');
  635. lblGroup5Checkbox.classList.add('switch-check-label');
  636.  
  637. let divGroup5Checkbox = document.createElement('div');
  638. divGroup5Checkbox.classList.add('switch-check');
  639. divGroup5Checkbox.appendChild(group5Checkbox);
  640. divGroup5Checkbox.appendChild(lblGroup5Checkbox);
  641.  
  642. dataText5 = document.createElement('textarea');
  643. dataText5.classList.add('danmu-group-textarea');
  644. dataText5.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  645. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  646.  
  647. /* ----------------------------------------- different room setting ----------------------------------------- */
  648. let divRoomSetting = document.createElement('div');
  649. divRoomSetting.appendChild(divText1);
  650. divRoomSetting.appendChild(divGroup1Checkbox);
  651. divRoomSetting.appendChild(dataText1);
  652. divRoomSetting.appendChild(divText2);
  653. divRoomSetting.appendChild(divGroup2Checkbox);
  654. divRoomSetting.appendChild(dataText2);
  655. divRoomSetting.appendChild(divText3);
  656. divRoomSetting.appendChild(divGroup3Checkbox);
  657. divRoomSetting.appendChild(dataText3);
  658. divRoomSetting.appendChild(divText4);
  659. divRoomSetting.appendChild(divGroup4Checkbox);
  660. divRoomSetting.appendChild(dataText4);
  661. divRoomSetting.appendChild(divText5);
  662. divRoomSetting.appendChild(divGroup5Checkbox);
  663. divRoomSetting.appendChild(dataText5);
  664. rdCheckbox = createSwitch('rdCheckbox', '随机从上面的弹幕中选出一条发送', '将合并所有分组数据,从中随机选出一条发送', null, divRoomSetting);
  665. usePublicCheckbox = createSwitch('usePublicCheckbox', '使用共用弹幕源', '使用设置为共用弹幕作为弹幕源', usePublicFunc, divRoomSetting);
  666. autoLikeCheckbox = createSwitch('autoLikeCheckbox', '自动点赞该直播间', '每15秒内随机一个时间点点赞一次直播间(点赞1000次大概需要4小时)', autoLikeFunc, divRoomSetting, null, null, null, null);
  667.  
  668. let operationDescription = document.createElement('div');
  669. operationDescription.textContent = '以上设置对应各个直播间独立保存,无需刷新';
  670. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  671. operationDescription.classList.add('global-setting-tip');
  672. operationDescription.classList.add('switch-check-group');
  673. divRoomSetting.appendChild(operationDescription);
  674. /* ----------------------------------------- different room setting ----------------------------------------- */
  675.  
  676. /* ----------------------------------------- global setting ----------------------------------------- */
  677. let divGlobalSetting = document.createElement('div');
  678. divGlobalSetting.style.margin = '20px 0 10px';
  679.  
  680. operationDescription = document.createElement('div');
  681. operationDescription.textContent = '以下设置,需刷新其它直播间才能适用';
  682. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  683. operationDescription.classList.add('global-setting-tip');
  684. operationDescription.classList.add('switch-check-group');
  685. divGlobalSetting.appendChild(operationDescription);
  686.  
  687. signInput = document.createElement('input');
  688. signInput.style.border = '0';
  689. signInput.style.width = '90px';
  690. signInput.setAttribute('placeholder', '输入打卡的文字');
  691.  
  692. hesitateInput = document.createElement('input');
  693. hesitateInput.style.border = '0';
  694. hesitateInput.style.width = '55px';
  695. hesitateInput.setAttribute('placeholder', '单位:秒');
  696. hesitateInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  697.  
  698. setPublicCheckbox = createSwitch('setPublicCheckbox', '设为共用弹幕源', '把这个直播间的弹幕共享给其它直播间使用,先后设置时,后面的会覆盖前面的设置', setPublicFunc, divGlobalSetting);
  699. signInCheckbox = createSwitch('signInCheckbox', '打卡弹幕(需登录(不可用)):', '每日零点发送一条打卡弹幕', signInFunc, divGlobalSetting, null, null, false, signInput);
  700. lotteryCheckbox = createSwitch('lotteryCheckbox', '自动参与天选时刻抽奖(需登录(不可用))', '自动点击参与按钮,请确保已经登录(不可用)了阿B账号', lotteryFunc, divGlobalSetting);
  701. hesitationCheckbox = createSwitch('hesitationCheckbox', '犹豫期:', '不立刻参与天选时刻,这期间可以手动处理,免得自动参加后后悔(时间单位:秒)', hesitationFunc, divGlobalSetting, '23px', '90%', true, hesitateInput);
  702. closeLotteryCheckbox = createSwitch('closeLotteryCheckbox', '关闭天选时刻', '关闭天选时刻弹窗', closeLotteryFunc, divGlobalSetting);
  703. hideGiftControlCheckbox = createSwitch('hideGiftControlCheckbox', '隐藏礼物栏', '隐藏播放器底部的礼物栏', hideGiftControlFunc, divGlobalSetting);
  704. noSleepCheckbox = createSwitch('noSleepCheckbox', '防止直播间休眠', '防止直播间页面一段时间没操作之后进入休眠', noSleepFunc, divGlobalSetting);
  705. hideLoginGuideCheckbox = createSwitch('hideLoginGuideCheckbox', '隐藏播放器底部登录(不可用)提示', '隐藏未登录(不可用)时播放器底部显示的登录(不可用)提示', hideLoginGuideFunc, divGlobalSetting);
  706. hideHarunaCheckbox = createSwitch('hideHarunaCheckbox', '隐藏看板娘立绘', '隐藏直播间Haruna立绘', hideHarunaFunc, divGlobalSetting);
  707. hideShopCheckbox = createSwitch('hideShopCheckbox', '隐藏购物提示', '隐藏播放器左上角的商店购物提示', hideShopFunc, divGlobalSetting);
  708. hideRoomFeedCheckbox = createSwitch('hideRoomFeedCheckbox', '隐藏主播动态', '隐藏播放器底下主播的动态栏', hideRoomFeedFunc, divGlobalSetting);
  709. hideRoomInfoCheckbox = createSwitch('hideRoomInfoCheckbox', '隐藏主播荣耀、简介', '隐藏播放器底下主播的荣耀勋章和简介', hideRoomInfoFunc, divGlobalSetting);
  710. hideNoticeCheckbox = createSwitch('hideNoticeCheckbox', '隐藏主播公告', '隐藏弹幕列表底下主播的公告', hideNoticeFunc, divGlobalSetting);
  711. hideFooterCheckbox = createSwitch('hideFooterCheckbox', '隐藏直播间页脚', '隐藏直播间底部的网页页脚', hideFooterFunc, divGlobalSetting);
  712. hidePrivacyCheckbox = createSwitch('hidePrivacyCheckbox', '隐藏隐私提示对话框', '隐藏隐私提示登录(不可用)的对话框,被打码的昵称不保证变回正常', hidePrivacyFunc, divGlobalSetting);
  713. hideRoomStatusCheckbox = createSwitch('hideRoomStatusCheckbox', '隐藏直播水印', '隐藏播放器左上角的直播水印', hideRoomStatusFunc, divGlobalSetting);
  714. /* ----------------------------------------- global setting ----------------------------------------- */
  715.  
  716. /* ----------------------------------------- operation msg ----------------------------------------- */
  717. spanApplyMsg = document.createElement('span');
  718. spanApplyMsg.classList.add('danmu-random-setting-success-text');
  719.  
  720. let divApplyMsg = document.createElement('div');
  721. divApplyMsg.classList.add('danmu-random-setting-success-tips');
  722. divApplyMsg.appendChild(spanApplyMsg);
  723. /* ----------------------------------------- operation msg ----------------------------------------- */
  724. /* ----------------------------------------- clean cache ----------------------------------------- */
  725. let cleanCacheBtn = document.createElement('button');
  726. cleanCacheBtn.textContent = '清除缓存';
  727. cleanCacheBtn.classList.add('clean-cache-btn');
  728. cleanCacheBtn.addEventListener('click', cleanCache);
  729. /* ----------------------------------------- clean cache ----------------------------------------- */
  730.  
  731. /* ----------------------------------------- save and close button ----------------------------------------- */
  732. let btnSave = document.createElement('i');
  733. btnSave.setAttribute('title', '保存');
  734. btnSave.style.padding = '5px';
  735. btnSave.classList.add('el-button');
  736. btnSave.classList.add('el-icon-check');
  737. btnSave.classList.add('is-circle');
  738. btnSave.addEventListener('click', save);
  739.  
  740. let btnClose = document.createElement('i');
  741. btnClose.setAttribute('title', '关闭');
  742. btnClose.style.padding = '5px';
  743. btnClose.classList.add('el-button');
  744. btnClose.classList.add('el-icon-close');
  745. btnClose.classList.add('is-circle');
  746. btnClose.addEventListener('click', closeSetting);
  747.  
  748. let divBtnSetting = document.createElement('div');
  749. divBtnSetting.classList.add('danmu-random-set-button-container');
  750. divBtnSetting.appendChild(cleanCacheBtn);
  751. divBtnSetting.appendChild(btnSave);
  752. divBtnSetting.appendChild(btnClose);
  753. /* ----------------------------------------- save and close button ----------------------------------------- */
  754.  
  755. /* ----------------------------------------- container ----------------------------------------- */
  756. let divBottomContainer = document.createElement('div');
  757. divBottomContainer.classList.add('danmu-random-setting-bottom');
  758. divBottomContainer.appendChild(divApplyMsg);
  759. divBottomContainer.appendChild(divBtnSetting);
  760.  
  761. let divContainer = document.createElement('div');
  762. divContainer.style.height = 'calc(98% - 30px - 25px)';
  763. divContainer.appendChild(divRoomSetting);
  764. divContainer.appendChild(divGlobalSetting);
  765. divContainer.appendChild(divBottomContainer);
  766. /* ----------------------------------------- container ----------------------------------------- */
  767.  
  768. divSetting = document.createElement('div');
  769. divSetting.id = 'danmu-setting-panel';
  770. divSetting.classList.add('danmu-random-setting-panel');
  771. divSetting.appendChild(divSettingTitle);
  772. divSetting.appendChild(divUpdateTip);
  773. divSetting.appendChild(divTip);
  774. divSetting.appendChild(divContainer);
  775.  
  776. let asideAreaVm = document.getElementById('aside-area-vm');
  777. asideAreaVm.appendChild(divSetting);
  778.  
  779. /* ----------------------------------------- function ----------------------------------------- */
  780. dmButtonSend = document.createElement('button');
  781. dmButtonSend.textContent = '开始';
  782. dmButtonSend.classList.add('danmu-btn');
  783. dmButtonSend.style.setProperty('--color', 'rgba(217,157,27,0.8)');
  784. //dmButtonSend.onclick = function() { alert('Hello world');}
  785. dmButtonSend.addEventListener('click', offOrOn);
  786.  
  787. beforeSpan = document.createElement('span');
  788. beforeSpan.textContent = '每';
  789. beforeSpan.classList.add('danmu-text-span');
  790. beforeSpan.style.marginLeft = '4px';
  791.  
  792. dmInput = document.createElement('input');
  793. dmInput.value = default_timeout;
  794. dmInput.classList.add('danmu-second-input');
  795. dmInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  796.  
  797. afterSpan = document.createElement('span');
  798. afterSpan.textContent = '秒发送';
  799. afterSpan.classList.add('danmu-text-span');
  800. afterSpan.style.marginRight = '4px';
  801.  
  802. let iElement = document.createElement('i');
  803. iElement.classList.add('el-icon-setting');
  804.  
  805. let btnSetting = document.createElement('button');
  806. btnSetting.title = '设置';
  807. btnSetting.classList.add('el-button');
  808. btnSetting.classList.add('el-button--mini');
  809. btnSetting.classList.add('is-circle');
  810. btnSetting.addEventListener('click', openSetting);
  811. btnSetting.appendChild(iElement);
  812.  
  813. // let btnSetting = document.createElement('ion-icon');
  814. // btnSetting.setAttribute('name', 'settings-sharp');
  815. // btnSetting.classList.add('el-button');
  816. // btnSetting.classList.add('el-button--mini');
  817. // btnSetting.classList.add('is-circle');
  818. // btnSetting.addEventListener('click', openSetting);
  819.  
  820. let div = document.createElement('div');
  821. div.style.position = 'absolute';
  822. div.appendChild(dmButtonSend);
  823. div.appendChild(beforeSpan);
  824. div.appendChild(dmInput);
  825. div.appendChild(afterSpan);
  826. div.appendChild(btnSetting);
  827. divButton.appendChild(div);
  828. /* ----------------------------------------- function ----------------------------------------- */
  829. },
  830. hideOrDisplay = (dom, hidden) => {
  831. if (hidden) {
  832. dom.style.setProperty('display', 'none', 'important');
  833. } else {
  834. dom.style.removeProperty('display');
  835. }
  836. },
  837. removeAttribute = (dom, attr) => {
  838. dom.removeAttribute(attr);
  839. if (0 < dom.children.length) {
  840. for (let i = 0; i < dom.children.length; i++) {
  841. removeAttribute(dom.children[i], attr);
  842. }
  843. }
  844. },
  845. setAttribute = (dom, attr, val) => {
  846. dom.setAttribute(attr, val);
  847. if (0 < dom.children.length) {
  848. for (let i = 0; i < dom.children.length; i++) {
  849. setAttribute(dom.children[i], attr, val);
  850. }
  851. }
  852. },
  853. hideLoginGuideFunc = () => {
  854. let dom = document.getElementById('switch-login-guide-vm');
  855. if (dom) {
  856. hideOrDisplay(dom, hideLoginGuideCheckbox.checked);
  857. }
  858. },
  859. hideHarunaFunc = () => {
  860. let dom = document.getElementById('my-dear-haruna-vm');
  861. if (dom) {
  862. hideOrDisplay(dom, hideHarunaCheckbox.checked);
  863. }
  864. },
  865. hideShopFunc = () => {
  866. let dom = document.getElementById('shop-popover-vm');
  867. if (dom) {
  868. hideOrDisplay(dom, hideShopCheckbox.checked);
  869. }
  870. },
  871. hideGiftControlFunc = () => {
  872. let dom = document.getElementsByClassName('gift-control-section')[0];
  873. if (dom) {
  874. hideOrDisplay(dom, hideGiftControlCheckbox.checked);
  875. }
  876.  
  877. dom = document.getElementById('web-player__bottom-bar__container');
  878. if (dom) {
  879. hideOrDisplay(dom, hideGiftControlCheckbox.checked);
  880. }
  881.  
  882. dom = document.getElementsByTagName('video');
  883. for (let i = 0; i < dom.length; i++) {
  884. if (!dom[i]) {
  885. return;
  886. }
  887. if (hideGiftControlCheckbox.checked) {
  888. dom[i].style.setProperty('height', '100%');
  889. } else if (document.body.classList.contains('player-full-win') || document.body.classList.contains('fullscreen-fix')) {
  890. dom[i].style.setProperty('height', 'calc(100% - 114px)');
  891. }
  892. }
  893. },
  894. hideRoomFeedFunc = () => {
  895. let dom = document.getElementsByClassName('room-feed')[0];
  896. if (dom) {
  897. hideOrDisplay(dom, hideRoomFeedCheckbox.checked);
  898. }
  899. dom = document.getElementsByClassName('flip-view p-relative')[0];
  900. if (dom) {
  901. hideOrDisplay(dom, hideRoomFeedCheckbox.checked);
  902. }
  903. },
  904. hideRoomInfoFunc = () => {
  905. let dom = document.getElementsByClassName('room-info-ctnr')[0];
  906. if (dom) {
  907. hideOrDisplay(dom, hideRoomInfoCheckbox.checked);
  908. }
  909. },
  910. hideNoticeFunc = () => {
  911. let dom = document.getElementsByClassName('right-container')[0];
  912. if (dom) {
  913. dom.style.setProperty('min-height', 'auto');
  914. hideOrDisplay(dom, hideNoticeCheckbox.checked);
  915. }
  916. },
  917. hideFooterFunc = () => {
  918. let dom = document.getElementById('link-footer-vm');
  919. if (dom) {
  920. hideOrDisplay(dom, hideFooterCheckbox.checked);
  921. }
  922. },
  923. hidePrivacyFunc = () => {
  924. if (hidePrivacyCheckbox.checked) {
  925. let dom = document.createElement('style');
  926. dom.id = 'hidePrivacyDialog';
  927. dom.setAttribute('type', 'text/css');
  928. dom.innerHTML = '.privacy-dialog{display:none !important;}';
  929. document.head.appendChild(dom);
  930. } else {
  931. let dom = document.getElementById('hidePrivacyDialog');
  932. if (dom) {
  933. dom.remove();
  934. }
  935. }
  936. },
  937. hideRoomStatusFunc = () => {
  938. let dom = document.getElementsByClassName('web-player-icon-roomStatus')[0];
  939. if (dom) {
  940. hideOrDisplay(dom, hideRoomStatusCheckbox.checked);
  941. }
  942. },
  943. lotteryFunc = () => {
  944. window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
  945. let dom = document.getElementById('hesitationCheckboxDiv');
  946. if (dom) {
  947. hideOrDisplay(dom, !lotteryCheckbox.checked)
  948. }
  949. },
  950. closeLotteryFunc = () => {
  951. window.localStorage.setItem(closeLotteryChecked, closeLotteryCheckbox.checked);
  952. },
  953. hesitationFunc = () => {
  954. window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
  955. window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
  956. },
  957. setPublicFunc = () => {},
  958. usePublicFunc = () => {
  959. let key = usePublicCheckbox.checked ? pdata.defaultKey : roomId,
  960. obj = getGmValue(key, null);
  961. if (obj) {
  962. setSource(obj);
  963. }
  964. },
  965. clickLikeBtn = () => {
  966. let dom = document.getElementsByClassName('like-btn')[0];
  967. if (dom) {
  968. dom.click();
  969. console.log(`===> ${new Date().toLocaleString()}】点击一次点赞按钮`);
  970. }
  971. },
  972. autoLikeFunc = () => {
  973. if (autoLikeCheckbox.checked) {
  974. if (autoLikeTimer) {
  975. return;
  976. }
  977.  
  978. clickLikeBtn();
  979. console.log(`===> 开启自动点赞功能【${new Date().toLocaleString()}】`);
  980. autoLikeTimer = workerTimer.setInterval(() => {
  981. let rdTimeout = Math.floor(Math.random() * 15);
  982. if (0 >= rdTimeout) {
  983. console.log(`===> ${new Date().toLocaleString()}】立刻点击点赞按钮`);
  984. clickLikeBtn();
  985. }
  986. else {
  987. console.log(`===> ${new Date().toLocaleString()}】设置【${rdTimeout}】秒后点击点赞按钮`);
  988. clickLikeBtnTimer = workerTimer.setTimeout(() => {
  989. workerTimer.clearTimeout(clickLikeBtnTimer);
  990. clickLikeBtnTimer = null;
  991. clickLikeBtn();
  992. }, rdTimeout * 1000);
  993. }
  994. }, 15e3);
  995. }
  996. else {
  997. if (autoLikeTimer) {
  998. workerTimer.clearInterval(autoLikeTimer);
  999. autoLikeTimer = null;
  1000. console.log(`===> 关闭自动点赞功能`);
  1001. }
  1002. if (clickLikeBtnTimer) {
  1003. workerTimer.clearTimeout(clickLikeBtnTimer);
  1004. clickLikeBtnTimer = null;
  1005. console.log(`===> 关闭超时点击点赞按钮功能`);
  1006. }
  1007. }
  1008. },
  1009. loadData = () => {
  1010. let obj = getGmValue(roomId, null),
  1011. key = roomId;
  1012. if (obj) {
  1013. if (obj.usePublic && pdata.defaultKey) {
  1014. let ps = getGmValue(pdata.defaultKey, null);
  1015. if (ps) {
  1016. obj.data1.values = ps.data1 ? ps.data1.values : obj.data1.values;
  1017. obj.data2.values = ps.data2 ? ps.data2.values : obj.data2.values;
  1018. obj.data3.values = ps.data3 ? ps.data3.values : obj.data3.values;
  1019. obj.data4.values = ps.data4 ? ps.data4.values : obj.data4.values;
  1020. obj.data5.values = ps.data5 ? ps.data5.values : obj.data5.values;
  1021. }
  1022. }
  1023. if (source.version === obj.version) {
  1024. source = obj;
  1025. }
  1026. else if (obj.version === 2) {
  1027. source.data1 = obj.data1;
  1028. source.data2 = obj.data2;
  1029. source.data3 = obj.data3;
  1030. source.data4 = obj.data4;
  1031. source.data5 = obj.data5;
  1032. setGmValue(key, source);
  1033. }
  1034. else {
  1035. source.data1.values = obj.data1 ? obj.data1.values : source.data1.values;
  1036. source.data2.values = obj.data2 ? obj.data2.values : source.data2.values;
  1037. source.data3.values = obj.data3 ? obj.data3.values : source.data3.values;
  1038. source.data4.values = obj.data4 ? obj.data4.values : source.data4.values;
  1039. source.data5.values = obj.data5 ? obj.data5.values : source.data5.values;
  1040. setGmValue(key, source);
  1041. }
  1042. }
  1043. if (pdata.configKey) {
  1044. config = getGmValue(pdata.configKey, {});
  1045. signInput.value = isNull(config.signInText) ? '' : config.signInText;
  1046. hesitateInput.value = isNull(config.hesitationExpiry) ? '10' : config.hesitationExpiry;
  1047. if (isNull(config.lottery)) {
  1048. config.lottery = false;
  1049. }
  1050. if (isNull(config.closeLottery)) {
  1051. config.closeLottery = false;
  1052. }
  1053. if (isNull(config.hesitation)) {
  1054. config.hesitation = false;
  1055. }
  1056. }
  1057. setSource(source);
  1058. setOperationSetting();
  1059. initData();
  1060. },
  1061. initSettingPanel = div => {
  1062. let settingPanel = document.getElementById('danmu-setting-panel');
  1063. if (div && !settingPanel) {
  1064. // console.log('===> 进行面板初始化');
  1065. let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
  1066. if (btnSend) {
  1067. buildPanel(div);
  1068. bgcolor = window.getComputedStyle(btnSend).getPropertyValue('background-color');
  1069. afterSpan.style.setProperty('background', bgcolor);
  1070. beforeSpan.style.setProperty('background', bgcolor);
  1071. dmButtonSend.style.setProperty('background', bgcolor);
  1072. dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  1073. loadData();
  1074. // console.log('===> 面板初始化完成');
  1075. } else {
  1076. console.warn('===> 发送按钮丢失');
  1077. return false;
  1078. }
  1079. }
  1080.  
  1081. return true;
  1082. },
  1083. main = div => {
  1084. waiters[waiters.length] = workerTimer.setInterval(() => {
  1085. if (initSettingPanel(div)) {
  1086. clearWaiters();
  1087. } else {
  1088. --waitCount;
  1089. if (0 >= waitCount) {
  1090. clearWaiters();
  1091. console.log('===> 创建面板失败,停止初始化');
  1092. }
  1093. }
  1094. }, 1.5e3);
  1095. },
  1096. noSleepFunc = () => {
  1097. if (noSleepCheckbox.checked) {
  1098. if (!noSleepTimer) {
  1099. console.log('===> 开启防休眠功能');
  1100. noSleepTimer = workerTimer.setInterval(() => {
  1101. noSleepTimeouter = workerTimer.setTimeout(() => {
  1102. workerTimer.clearTimeout(noSleepTimeouter);
  1103. document.body.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
  1104. }, Math.random() * 3e3);
  1105. }, 17e3);
  1106. }
  1107. } else {
  1108. console.log('===> 关闭防休眠功能');
  1109. if (noSleepTimer) {
  1110. workerTimer.clearInterval(noSleepTimer);
  1111. noSleepTimer = null;
  1112. }
  1113. if (noSleepTimeouter) {
  1114. workerTimer.clearTimeout(noSleepTimeouter);
  1115. noSleepTimeouter = null;
  1116. }
  1117. }
  1118. },
  1119. biliMiniClose = () => {
  1120. if (!miniCloseTimer) {
  1121. let miniCloseCount = 3;
  1122. miniCloseTimer = workerTimer.setInterval(() => {
  1123. let mini_close = document.getElementsByClassName('bili-mini-close')[0];
  1124. if (!mini_close) {
  1125. if (0 >= --miniCloseCount) {
  1126. workerTimer.clearInterval(miniCloseTimer);
  1127. miniCloseTimer = null;
  1128. }
  1129.  
  1130. return;
  1131. }
  1132.  
  1133. mini_close.click();
  1134. workerTimer.clearInterval(miniCloseTimer);
  1135. miniCloseTimer = null;
  1136. }, 10e3);
  1137. }
  1138. },
  1139. closeLottery = delay => {
  1140. let btnClose = document.getElementsByClassName('close-btn bg-contain')[0];
  1141. if (btnClose) {
  1142. if (isNull(delay)) {
  1143. btnClose.click();
  1144. } else {
  1145. closeLotteryTimer = workerTimer.setTimeout(() => {
  1146. workerTimer.clearTimeout(closeLotteryTimer);
  1147. btnClose.click();
  1148. }, delay * 1000);
  1149. }
  1150. }
  1151. },
  1152. lottery = btn => {
  1153. if (!btn) {
  1154. console.warn('===> 没有抽奖按钮DOM');
  1155. return;
  1156. }
  1157. if ('false' === window.localStorage.getItem(lotteryChecked)) {
  1158. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1159. console.log('===> 不参与天选时刻抽奖,关闭弹窗');
  1160. closeLottery();
  1161. }
  1162.  
  1163. return;
  1164. }
  1165. if ('true' === window.localStorage.getItem(hesitationChecked)) {
  1166. let expiry = window.localStorage.getItem(hesitationExpiry);
  1167. expiry = isNull(expiry) ? 10e3 : expiry * 1000;
  1168. let lotteryTimer = workerTimer.setTimeout(() => {
  1169. workerTimer.clearTimeout(lotteryTimer);
  1170. console.log('===> 犹豫期过后自动参加抽奖');
  1171. btn.click();
  1172. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1173. console.log('===> 参加成功,延迟关闭弹窗');
  1174. closeLottery(1);
  1175. }
  1176. }, expiry);
  1177. } else {
  1178. console.log('===> 立刻自动参加抽奖');
  1179. btn.click();
  1180. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1181. console.log('===> 参加成功,延迟关闭弹窗');
  1182. closeLottery(1);
  1183. }
  1184. }
  1185. },
  1186. debug = () => {debugger;},
  1187. runStart = () => {
  1188. if (isOldVersion()) {
  1189. window.location.href = parentUrl;
  1190. return;
  1191. }
  1192.  
  1193. let btn = document.getElementsByClassName('particitation-btn')[0];
  1194. if (btn) {
  1195. lottery(btn);
  1196. } else {
  1197. btnLotteryTimer = workerTimer.setTimeout(() => {
  1198. workerTimer.clearTimeout(btnLotteryTimer);
  1199. btn = document.getElementsByClassName('particitation-btn')[0];
  1200. if (btn) {
  1201. lottery(btn);
  1202. }
  1203. }, 2e3);
  1204. }
  1205.  
  1206. let div = document.getElementsByClassName('bottom-actions p-relative')[0];
  1207. if (div) {
  1208. main(div);
  1209. } else {
  1210. let count = 0;
  1211. divSendBtnTimer = workerTimer.setInterval(() => {
  1212. div = document.getElementsByClassName('bottom-actions p-relative')[0];
  1213. if (div) {
  1214. workerTimer.clearInterval(divSendBtnTimer);
  1215. main(div);
  1216. } else if (count++ >= 10) {
  1217. workerTimer.clearInterval(divSendBtnTimer);
  1218. console.log(`===> 页面【${window.location.href}】没有定位位置`);
  1219. }
  1220. }, 1e3);
  1221. }
  1222. };
  1223.  
  1224. initCss();
  1225. window.debug = debug;
  1226. window.runStart = runStart;
  1227. window.arrayInfo = arrayInfo;
  1228. window.setGmNotice = setGmNotice;
  1229. window.setGmGetValue = setGmGetValue;
  1230. window.setGmSetValue = setGmSetValue;
  1231. window.setGmDelValue = setGmDelValue;
  1232. window.setParentData = setParentData;
  1233. window.autoSendDanmuModuleLoaded = true;
  1234. })();

QingJ © 2025

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