b-live-random-send-test

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

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

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

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