b-live-random-send-test

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

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

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