b-live-random-send-test

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

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

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