b-live-random-send-test

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

当前为 2023-10-21 提交的版本,查看 最新版本

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

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