b-live-random-send-test

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

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

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

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