b-live-random-send-test

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

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

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

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