b-live-random-send-test

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

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/447936/1527683/b-live-random-send-test.js

  1. // ==UserScript==
  2. // @version 1.7.2
  3. // ==/UserScript==
  4.  
  5.  
  6.  
  7.  
  8. (function () {
  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: 6,
  90. usePublic: false,
  91. signInText: '打卡',
  92. sendMsgRandom: true,
  93. sendMsgInterval: 600,
  94. data1: { available: true, values: ['[惊喜]', '[流汗]'] },
  95. data2: { available: true, values: [] },
  96. data3: { available: true, values: [] },
  97. data4: { available: true, values: ['[爱]'] },
  98. data5: { available: true, values: [] },
  99. like: { likeRandom: false, likeInterval: false, clickLikeInterval: 6},
  100. lottery: { lottery: false, hesitationInterval: false, hesitationIntervalExpiry: 100, hesitationRandom: false, hesitationRandomExpiry: 100 }
  101. },
  102. baseInfo = {}, config = {}, waiters = [], data = [],
  103. signInCheckbox, hideLoginGuideCheckbox, hideHarunaCheckbox, hideShopCheckbox, noSleepCheckbox, hideGiftControlCheckbox,
  104. hideRoomFeedCheckbox, hideRoomInfoCheckbox, hideNoticeCheckbox, hideFooterCheckbox, lotteryCheckbox, closeLotteryCheckbox,
  105. hesitationRandomCheckbox, hesitationIntervalCheckbox, hidePrivacyCheckbox, hideRoomStatusCheckbox, setPublicCheckbox,
  106. hideBusinessCheckbox, hideRankListCheckbox, showLiveAreaCheckbox,
  107. group1Checkbox, group2Checkbox, group3Checkbox, group4Checkbox, group5Checkbox,
  108. rdCheckbox, usePublicCheckbox, autoLikeCheckbox, clickLikeRandomCheckbox, clickLikeIntervalCheckbox,
  109. dmInput, divSetting, dataText1, dataText2, dataText3, dataText4, dataText5, signInput, intervalClickLikeInput,
  110. hesitationRandomInput, hesitationIntervalInput,
  111. dmButtonSend, beforeSpan, afterSpan, spanApplyMsg, divUpdateInfo, btnStartText,
  112. sendTimer = null, signInTimer = null, miniCloseTimer, noSleepTimer, noSleepTimeouter,
  113. divSendBtnTimer, autoLikeTimer, clickLikeBtnTimer,
  114. count = 0, waitCount = 200, arrayIndex = 0, default_timeout = 600,
  115. closeLotteryChecked = 'close_lottery_checked', txtStartTask = '开始定时发送任务', lotteryPrefix = 'lottery_',
  116. gmNotice = obj => { alert(''); },
  117. getGmValue = (key, defaultValue) => { return null; },
  118. setGmValue = (key, obj) => { console.warn('===> No implementation setGmValue method.'); },
  119. delGmValue = key => { console.warn('===> No implementation delGmValue method.'); };
  120.  
  121. const version = '1.7.2', upodateInfo = '优化自动参与天选时刻功能,修复一些Bug', noticeTimeout = 10e3,
  122. icoUrl = 'https://www.bilibili.com/favicon.ico',
  123. roomId = window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
  124. setGmGetValue = callback => getGmValue = callback,
  125. setGmSetValue = callback => setGmValue = callback,
  126. setGmDelValue = callback => delGmValue = callback,
  127. setGmNotice = callback => gmNotice = callback,
  128. setBaseInfo = obj => baseInfo = obj,
  129. arrayInfo = () => console.info(data),
  130. isNull = str => {
  131. if (!str || str == '') {
  132. return true;
  133. }
  134.  
  135. let regu = "^[ ]+$";
  136. let re = new RegExp(regu);
  137. return re.test(str);
  138. },
  139. compareVersion = (ver1, ver2) => {
  140. if (isNull(ver1)) return -1;
  141. if (isNull(ver2)) return 1;
  142.  
  143. const arr1 = ver1.split('.').map(x => x * 1),
  144. arr2 = ver2.split('.').map(x => x * 1),
  145. len = Math.max(arr1.length, arr2.length);
  146. for (let i = 0; i < len; i++) {
  147. if ((arr1[i] || 0) > (arr2[i] || 0)) return 1;
  148. if ((arr1[i] || 0) < (arr2[i] || 0)) return -1;
  149. }
  150.  
  151. return 0;
  152. },
  153. initCss = () => {
  154. let linkElement = document.createElement('link');
  155. linkElement.rel = 'stylesheet';
  156. linkElement.href = 'https://unpkg.zhimg.com/element-ui/lib/theme-chalk/index.css';
  157. document.head.appendChild(linkElement);
  158.  
  159. // 图标库 https://ionic.io/ionicons
  160. // let scriptElement = document.createElement('script');
  161. // scriptElement.src = 'https://unpkg.com/ionicons@5.5.2/dist/ionicons.js';
  162. // document.head.appendChild(scriptElement);
  163.  
  164. let customerStyle = document.createElement('style');
  165. customerStyle.setAttribute('type', 'text/css');
  166. 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:#e7f1fb;border-radius:10px;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;}.module-update-info{color:#0b81cc;text-indent:2em;font-size:13px;font-weight:700;margin:8px 0;padding:2px 0;background-color:#ffffff;}.update-info-text{color:#f00;vertical-align:-webkit-baseline-middle;}.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;line-height:1;display:inline-flex;justify-content:center;align-items:center;}.danmu-btn:hover{background:var(--color)!important;}.danmu-text-span{color:#095ca2;font-size:20px;vertical-align:middle;font-weight:700}.danmu-second-input{width:70px;height:20px;margin:0px 3px;border:0px;border-radius:3px;font-size:18px}.not-display{display:none !important;}';
  167. document.head.appendChild(customerStyle);
  168. },
  169. // initScript = () => {
  170. // let script = document.createElement('script');
  171. // script.type = 'text/javascript';
  172. // script.src = 'https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js';
  173. // document.head.appendChild(script);
  174. // },
  175. getCurrentTimestamp = () => new Date().getTime(),
  176. send = (msg, index) => {
  177. let dmTextArea = document.getElementById(baseInfo.dmInputArea || 'chat-control-panel-vm').querySelector('textarea');
  178. if (!dmTextArea) {
  179. alert('找不到输入弹幕文本框,请尝试刷新页面');
  180. return;
  181. }
  182. if (!isNull(dmTextArea.value)) {
  183. console.log(`===> 有内容正在编辑,跳过该次发送任务`);
  184. return;
  185. }
  186.  
  187. let btnSend = document.getElementsByClassName(baseInfo.sendButtonArea || 'right-action')[0].querySelector('button');
  188. if (!btnSend) {
  189. alert('找不到发送按钮,请尝试刷新页面');
  190. return;
  191. }
  192. dmTextArea.value = msg;
  193. dmTextArea.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
  194. btnSend.click();
  195. // ++count;
  196. // console.log('===> ' + new Date().toLocaleString() + ' 弹幕发送成功 ' + count + ' 次,第【' + index + '】条数据 === ' + msg);
  197. },
  198. randomSort = arr => {
  199. for (let i = 0; i < arr.length; i++) {
  200. const rdIndex = Math.floor(Math.random() * arr.length);
  201. const temp = arr[i];
  202. arr[i] = arr[rdIndex];
  203. arr[rdIndex] = temp;
  204. }
  205.  
  206. return arr;
  207. },
  208. clearWaiters = () => {
  209. for (let i = 0; i < waiters.length; i++) {
  210. workerTimer.clearInterval(waiters[i]);
  211. waiters[i] = null;
  212. }
  213.  
  214. waiters = [];
  215. },
  216. signInFunc = () => {
  217. if (signInCheckbox.checked) {
  218. signInput.setAttribute('disabled', 'disabled');
  219. signInput.classList.add('disabled');
  220. if (!signInTimer) {
  221. let timestamp = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()).getTime() - getCurrentTimestamp();
  222. console.log('===> 设置凌晨打卡定时器【' + timestamp + '】');
  223. signInTimer = workerTimer.setTimeout(() => {
  224. let defaultText = isNull(source.signInText) ? '打卡' : source.signInText;
  225. send(isNull(signInput.value) ? defaultText : signInput.value, 0);
  226. console.log('===> 设置下一次打卡');
  227. workerTimer.clearTimeout(signInTimer);
  228. signInTimer = null;
  229. signInFunc();
  230. }, timestamp);
  231. }
  232. }
  233. else {
  234. signInput.removeAttribute('disabled');
  235. signInput.classList.remove('disabled');
  236. if (signInTimer) {
  237. console.log('===> 关闭自动打卡功能');
  238. workerTimer.clearTimeout(signInTimer);
  239. signInTimer = null;
  240. }
  241. }
  242. },
  243. setDmSourceInput = obj => {
  244. dataText1.value = obj.data1.values.length ? obj.data1.values.join('|') : [];
  245. dataText2.value = obj.data2.values.length ? obj.data2.values.join('|') : [];
  246. dataText3.value = obj.data3.values.length ? obj.data3.values.join('|') : [];
  247. dataText4.value = obj.data4.values.length ? obj.data4.values.join('|') : [];
  248. dataText5.value = obj.data5.values.length ? obj.data5.values.join('|') : [];
  249. },
  250. runCheckbox = () => {
  251. usePublicFunc();
  252. hideFooterFunc();
  253. hideGiftControlFunc();
  254. hideLoginGuideFunc();
  255. hideHarunaFunc();
  256. hideShopFunc();
  257. hidePrivacyFunc();
  258. hideRoomStatusFunc();
  259. hideBusinessFunc();
  260. hideRankListFunc();
  261. noSleepFunc();
  262. signInFunc();
  263. lotteryFunc();
  264. hesitationIntervalFunc();
  265. hesitationRandomFunc();
  266. closeLotteryFunc();
  267. autoLikeFunc();
  268. // autoPlay();
  269. hideRoomFeedFunc();
  270. hideRoomInfoFunc();
  271. hideNoticeFunc();
  272. showLiveAreaFunc();
  273. let hideTimeout = workerTimer.setTimeout(() => {
  274. workerTimer.clearTimeout(hideTimeout);
  275. hideRoomFeedFunc();
  276. hideRoomInfoFunc();
  277. hideNoticeFunc();
  278. showLiveAreaFunc();
  279. }, 1e3);
  280. },
  281. setOperationSetting = () => {
  282. autoLikeCheckbox.checked = true;
  283. setPublicCheckbox.checked = false;
  284. rdCheckbox.checked = source.sendMsgRandom;
  285. usePublicCheckbox.checked = source.usePublic;
  286. group1Checkbox.checked = source.data1.available;
  287. group2Checkbox.checked = source.data2.available;
  288. group3Checkbox.checked = source.data3.available;
  289. group4Checkbox.checked = source.data4.available;
  290. group5Checkbox.checked = source.data5.available;
  291. clickLikeRandomCheckbox.checked = source.like.likeRandom;
  292. clickLikeIntervalCheckbox.checked = source.like.likeInterval;
  293. intervalClickLikeInput.value = source.like.clickLikeInterval;
  294. !source.like.likeRandom && !source.like.likeInterval && (autoLikeCheckbox.checked = false);
  295. dmInput.value = source.sendMsgInterval || default_timeout;
  296. signInput.value = isNull(source.signInText) ? '' : source.signInText;
  297. lotteryCheckbox.checked = source.lottery.lottery;
  298. hesitationIntervalCheckbox.checked = source.lottery.hesitationInterval;
  299. hesitationIntervalInput.value = isNull(source.lottery.hesitationIntervalExpiry) ? 100 : source.lottery.hesitationIntervalExpiry;
  300. hesitationRandomCheckbox.checked = source.lottery.hesitationRandom;
  301. hesitationRandomInput.value = isNull(source.lottery.hesitationRandomExpiry) ? 100 : source.lottery.hesitationRandomExpiry;
  302. setLottery(source.lottery);
  303.  
  304. signInCheckbox.checked = config.autoSignIn;
  305. noSleepCheckbox.checked = config.noSleep;
  306. hideLoginGuideCheckbox.checked = config.hideLoginGuide;
  307. hideHarunaCheckbox.checked = config.hideHaruna;
  308. hideShopCheckbox.checked = config.hideShop;
  309. hideGiftControlCheckbox.checked = config.hideGift;
  310. hideRoomFeedCheckbox.checked = config.hideRoomFeed;
  311. hideRoomInfoCheckbox.checked = config.hideRoomInfo;
  312. hideNoticeCheckbox.checked = config.hideNotice;
  313. hideFooterCheckbox.checked = config.hideFooter;
  314. hidePrivacyCheckbox.checked = config.noPrivacy;
  315. hideRoomStatusCheckbox.checked = config.hideWatermark;
  316. hideBusinessCheckbox.checked = config.hideBusiness;
  317. hideRankListCheckbox.checked = config.hideRankList;
  318. showLiveAreaCheckbox.checked = config.showLiveArea;
  319. closeLotteryCheckbox.checked = config.closeLottery;
  320. window.localStorage.setItem(closeLotteryChecked, closeLotteryCheckbox.checked);
  321. runCheckbox();
  322. },
  323. openSetting = () => divSetting.style.display = 'block',
  324. closeSetting = () => {
  325. setOperationSetting();
  326. divSetting.style.display = 'none';
  327. },
  328. initData = () => {
  329. if (source.data1.values.length <= 0
  330. && source.data2.values.length <= 0
  331. && source.data3.values.length <= 0
  332. && source.data4.values.length <= 0
  333. && source.data5.values.length <= 0) {
  334. return data ? data : [];
  335. }
  336.  
  337. let result = [];
  338. result = source.data1.available ? result.concat(source.data1.values) : result;
  339. result = source.data2.available ? result.concat(source.data2.values) : result;
  340. result = source.data3.available ? result.concat(source.data3.values) : result;
  341. result = source.data4.available ? result.concat(source.data4.values) : result;
  342. result = source.data5.available ? result.concat(source.data5.values) : result;
  343. data = result;
  344. rdCheckbox.checked ? data = randomSort(result) : arrayIndex = 0;
  345. },
  346. flashMsg = (txt, back, color) => {
  347. spanApplyMsg.textContent = txt;
  348. spanApplyMsg.style.display = 'block';
  349. if (color) {
  350. spanApplyMsg.style.color = color;
  351. }
  352. else {
  353. spanApplyMsg.style.color = '#128712';
  354. }
  355.  
  356. let hideTipTimer = workerTimer.setTimeout(() => {
  357. workerTimer.clearTimeout(hideTipTimer);
  358. spanApplyMsg.style.display = 'none';
  359. spanApplyMsg.textContent = '';
  360. if (back) {
  361. divSetting.style.display = 'none';
  362. }
  363. }, 1.5e3);
  364. },
  365. save = () => {
  366. if (!baseInfo || isNull(baseInfo.default) || isNull(baseInfo.config)) {
  367. flashMsg('保存失败', false, 'red');
  368. return;
  369. }
  370. if (baseInfo.config) {
  371. config.autoSignIn = signInCheckbox.checked;
  372. config.noSleep = noSleepCheckbox.checked;
  373. config.hideLoginGuide = hideLoginGuideCheckbox.checked;
  374. config.hideHaruna = hideHarunaCheckbox.checked;
  375. config.hideShop = hideShopCheckbox.checked;
  376. config.hideGift = hideGiftControlCheckbox.checked;
  377. config.hideRoomFeed = hideRoomFeedCheckbox.checked;
  378. config.hideRoomInfo = hideRoomInfoCheckbox.checked;
  379. config.hideNotice = hideNoticeCheckbox.checked;
  380. config.hideFooter = hideFooterCheckbox.checked;
  381. config.closeLottery = closeLotteryCheckbox.checked;
  382. window.localStorage.setItem(closeLotteryChecked, config.closeLottery);
  383. config.noPrivacy = hidePrivacyCheckbox.checked;
  384. config.hideWatermark = hideRoomStatusCheckbox.checked;
  385. config.hideBusiness = hideBusinessCheckbox.checked;
  386. config.hideRankList = hideRankListCheckbox.checked;
  387. config.showLiveArea = showLiveAreaCheckbox.checked;
  388. setGmValue(baseInfo.config, config);
  389. }
  390.  
  391. let v1 = isNull(dataText1.value) ? [] : dataText1.value.split('|'),
  392. v2 = isNull(dataText2.value) ? [] : dataText2.value.split('|'),
  393. v3 = isNull(dataText3.value) ? [] : dataText3.value.split('|'),
  394. v4 = isNull(dataText4.value) ? [] : dataText4.value.split('|'),
  395. v5 = isNull(dataText5.value) ? [] : dataText5.value.split('|');
  396. source.signInText = signInput.value;
  397. source.sendMsgRandom = rdCheckbox.checked;
  398. source.sendMsgInterval = dmInput.value || default_timeout;
  399. source.data1.available = group1Checkbox.checked;
  400. source.data2.available = group2Checkbox.checked;
  401. source.data3.available = group3Checkbox.checked;
  402. source.data4.available = group4Checkbox.checked;
  403. source.data5.available = group5Checkbox.checked;
  404. source.like.likeRandom = clickLikeRandomCheckbox.checked;
  405. source.like.likeInterval = clickLikeIntervalCheckbox.checked;
  406. source.like.clickLikeInterval = intervalClickLikeInput.value || 6;
  407. source.lottery.lottery = lotteryCheckbox.checked;
  408. source.lottery.hesitationInterval = hesitationIntervalCheckbox.checked;
  409. source.lottery.hesitationIntervalExpiry = hesitationIntervalInput.value;
  410. source.lottery.hesitationRandom = hesitationRandomCheckbox.checked;
  411. source.lottery.hesitationRandomExpiry = hesitationRandomInput.value;
  412. source.usePublic = usePublicCheckbox.checked;
  413. if (!usePublicCheckbox.checked) {
  414. source.data1.values = v1;
  415. source.data2.values = v2;
  416. source.data3.values = v3;
  417. source.data4.values = v4;
  418. source.data5.values = v5;
  419. }
  420. setLottery(source.lottery);
  421. setGmValue(roomId, source);
  422. if (setPublicCheckbox.checked) {
  423. let ps = {data1:{},data2:{},data3:{},data4:{},data5:{}};
  424. ps.data1.values = v1;
  425. ps.data2.values = v2;
  426. ps.data3.values = v3;
  427. ps.data4.values = v4;
  428. ps.data5.values = v5;
  429. setGmValue(baseInfo.default, ps);
  430. }
  431. if (usePublicCheckbox.checked) {
  432. source.data1.values = v1;
  433. source.data2.values = v2;
  434. source.data3.values = v3;
  435. source.data4.values = v4;
  436. source.data5.values = v5;
  437. }
  438. initData();
  439. flashMsg('设置成功', true);
  440. },
  441. cleanCache = () => {
  442. if (baseInfo.config && config) {
  443. config.script = '';
  444. config.moduleVersion = '0.0.0';
  445. config.lastUpdate = '清除脚本缓存';
  446. setGmValue(baseInfo.config, config);
  447. flashMsg('清除成功');
  448. } else {
  449. console.warn('元数据丢失');
  450. flashMsg('操作失败', false, 'red');
  451. }
  452. },
  453. danmu = () => {
  454. if (data.length < 1) {
  455. // gmNotice({
  456. // text: '请任意在一个分组里输入一条弹幕',
  457. // title: '没有弹幕数据,请先设置',
  458. // image: icoUrl,
  459. // highlight: true,
  460. // timeout: noticeTimeout
  461. // });
  462. alert('请先设置弹幕');
  463. return false;
  464. }
  465. if (rdCheckbox.checked) {
  466. arrayIndex = Math.floor((Math.random() * data.length));
  467. }
  468.  
  469. send(data[arrayIndex], arrayIndex);
  470. ++arrayIndex;
  471. if (arrayIndex >= data.length) {
  472. arrayIndex = 0;
  473. }
  474.  
  475. return true;
  476. },
  477. offOrOn = () => {
  478. let timeout = 0;
  479. if (sendTimer) {
  480. workerTimer.clearInterval(sendTimer);
  481. sendTimer = null;
  482. dmButtonSend.title = txtStartTask;
  483. dmInput.removeAttribute('disabled');
  484. dmInput.classList.remove('disabled');
  485. if (btnStartText) {
  486. dmButtonSend.style.removeProperty('background');
  487. dmButtonSend.style.removeProperty('--color');
  488. btnStartText.textContent = '开始';
  489. }
  490. else {
  491. dmButtonSend.style.removeProperty('color');
  492. }
  493. } else {
  494. timeout = (dmInput.value || default_timeout) * 1e3;
  495. if (!danmu()) {
  496. return;
  497. }
  498.  
  499. sendTimer = workerTimer.setInterval(danmu, timeout);
  500. dmButtonSend.title = '停止定时发送任务';
  501. dmInput.setAttribute('disabled', 'disabled');
  502. dmInput.classList.add('disabled');
  503. if (btnStartText) {
  504. dmButtonSend.style.background = 'rgba(255,0,0,1)';
  505. dmButtonSend.style.setProperty('--color', 'rgba(255,0,0,0.8)');
  506. btnStartText.textContent = '停止';
  507. }
  508. else {
  509. dmButtonSend.style.color = 'rgb(255 102 153)';
  510. }
  511. }
  512. },
  513. createIntervalInput = () => {
  514. let input = document.createElement('input');
  515. input.style.border = '0';
  516. input.style.width = '55px';
  517. input.setAttribute('placeholder', '单位:秒');
  518. input.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  519. return input;
  520. },
  521. createSwitch = (id, txt, title, func, container, indent, width, hidden, rear, disabled) => {
  522. let checkbox = document.createElement('input');
  523. checkbox.type = 'checkbox';
  524. checkbox.id = id;
  525. checkbox.checked = false;
  526. if (func && !disabled) {
  527. checkbox.addEventListener('click', func);
  528. }
  529.  
  530. let lblCheckbox = document.createElement('label');
  531. lblCheckbox.setAttribute('for', id);
  532. lblCheckbox.classList.add('switch-check-label');
  533.  
  534. let descSpan = document.createElement('span');
  535. descSpan.textContent = txt;
  536. descSpan.title = title;
  537. descSpan.classList.add('danmu-random-switch-button-title');
  538. if (disabled) {
  539. checkbox.disabled = true;
  540. checkbox.classList.add('disabled');
  541. lblCheckbox.classList.add('disabled');
  542. descSpan.classList.add('disabled');
  543. }
  544.  
  545. let divCheckbox = document.createElement('div');
  546. divCheckbox.id = id + 'Div';
  547. divCheckbox.classList.add('switch-check');
  548. divCheckbox.classList.add('switch-check-group');
  549. divCheckbox.appendChild(checkbox);
  550. divCheckbox.appendChild(lblCheckbox);
  551. divCheckbox.appendChild(descSpan);
  552. if (!isNull(indent)) {
  553. divCheckbox.style.marginLeft = indent;
  554. }
  555. if (!isNull(width)) {
  556. divCheckbox.style.width = width;
  557. }
  558. if (hidden) {
  559. divCheckbox.style.setProperty('display', 'none');
  560. }
  561. if (rear) {
  562. divCheckbox.appendChild(rear);
  563. if (disabled) {
  564. rear.disabled = true;
  565. rear.classList.add('disabled');
  566. }
  567. }
  568.  
  569. container.appendChild(divCheckbox);
  570. return checkbox;
  571. },
  572. buildPanel = () => {
  573. /* ----------------------------------------- head ----------------------------------------- */
  574. let divSettingTitle = document.createElement('div');
  575. divSettingTitle.textContent = '弹幕设置';
  576. divSettingTitle.classList.add('danmu-random-setting-title');
  577.  
  578. let divSub = document.createElement('div');
  579. divSub.textContent = version;
  580. divSub.classList.add('danmu-random-setting-title-sub');
  581. divSettingTitle.appendChild(divSub);
  582.  
  583. let divTip = document.createElement('div');
  584. divTip.classList.add('danmu-random-setting-tips');
  585. divTip.innerHTML = '任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';
  586.  
  587. divUpdateInfo = document.createElement('div');
  588. divUpdateInfo.classList.add('module-update-info');
  589. divUpdateInfo.innerHTML = `<span class="update-info-text">消息提示:</span><span class="update-info-text" style="color:#0f6ba6;">${baseInfo.msg || upodateInfo}</span>`;
  590. /* ----------------------------------------- head ----------------------------------------- */
  591.  
  592. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  593. let divText1 = document.createElement('div');
  594. divText1.textContent = '分组 1 :';
  595. divText1.classList.add('danmu-group-title');
  596.  
  597. group1Checkbox = document.createElement('input');
  598. group1Checkbox.type = 'checkbox';
  599. group1Checkbox.id = 'group1Checkbox';
  600. group1Checkbox.checked = true;
  601.  
  602. let lblGroup1Checkbox = document.createElement('label');
  603. lblGroup1Checkbox.setAttribute('for', 'group1Checkbox');
  604. lblGroup1Checkbox.classList.add('switch-check-label');
  605.  
  606. let divGroup1Checkbox = document.createElement('div');
  607. divGroup1Checkbox.classList.add('switch-check');
  608. divGroup1Checkbox.appendChild(group1Checkbox);
  609. divGroup1Checkbox.appendChild(lblGroup1Checkbox);
  610.  
  611. dataText1 = document.createElement('textarea');
  612. dataText1.classList.add('danmu-group-textarea');
  613. dataText1.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  614. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  615.  
  616. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  617. let divText2 = document.createElement('div');
  618. divText2.textContent = '分组 2 :';
  619. divText2.classList.add('danmu-group-title');
  620.  
  621. group2Checkbox = document.createElement('input');
  622. group2Checkbox.type = 'checkbox';
  623. group2Checkbox.id = 'group2Checkbox';
  624. group2Checkbox.checked = true;
  625.  
  626. let lblGroup2Checkbox = document.createElement('label');
  627. lblGroup2Checkbox.setAttribute('for', 'group2Checkbox');
  628. lblGroup2Checkbox.classList.add('switch-check-label');
  629.  
  630. let divGroup2Checkbox = document.createElement('div');
  631. divGroup2Checkbox.classList.add('switch-check');
  632. divGroup2Checkbox.appendChild(group2Checkbox);
  633. divGroup2Checkbox.appendChild(lblGroup2Checkbox);
  634.  
  635. dataText2 = document.createElement('textarea');
  636. dataText2.classList.add('danmu-group-textarea');
  637. dataText2.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  638. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  639.  
  640. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  641. let divText3 = document.createElement('div');
  642. divText3.textContent = '分组 3 :';
  643. divText3.classList.add('danmu-group-title');
  644.  
  645. group3Checkbox = document.createElement('input');
  646. group3Checkbox.type = 'checkbox';
  647. group3Checkbox.id = 'group3Checkbox';
  648. group3Checkbox.checked = true;
  649.  
  650. let lblGroup3Checkbox = document.createElement('label');
  651. lblGroup3Checkbox.setAttribute('for', 'group3Checkbox');
  652. lblGroup3Checkbox.classList.add('switch-check-label');
  653.  
  654. let divGroup3Checkbox = document.createElement('div');
  655. divGroup3Checkbox.classList.add('switch-check');
  656. divGroup3Checkbox.appendChild(group3Checkbox);
  657. divGroup3Checkbox.appendChild(lblGroup3Checkbox);
  658.  
  659. dataText3 = document.createElement('textarea');
  660. dataText3.classList.add('danmu-group-textarea');
  661. dataText3.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  662. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  663.  
  664. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  665. let divText4 = document.createElement('div');
  666. divText4.textContent = '分组 4 :';
  667. divText4.classList.add('danmu-group-title');
  668.  
  669. group4Checkbox = document.createElement('input');
  670. group4Checkbox.type = 'checkbox';
  671. group4Checkbox.id = 'group4Checkbox';
  672. group4Checkbox.checked = true;
  673.  
  674. let lblGroup4Checkbox = document.createElement('label');
  675. lblGroup4Checkbox.setAttribute('for', 'group4Checkbox');
  676. lblGroup4Checkbox.classList.add('switch-check-label');
  677.  
  678. let divGroup4Checkbox = document.createElement('div');
  679. divGroup4Checkbox.classList.add('switch-check');
  680. divGroup4Checkbox.appendChild(group4Checkbox);
  681. divGroup4Checkbox.appendChild(lblGroup4Checkbox);
  682.  
  683. dataText4 = document.createElement('textarea');
  684. dataText4.classList.add('danmu-group-textarea');
  685. dataText4.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  686. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  687.  
  688. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  689. let divText5 = document.createElement('div');
  690. divText5.textContent = '分组 5 :';
  691. divText5.classList.add('danmu-group-title');
  692.  
  693. group5Checkbox = document.createElement('input');
  694. group5Checkbox.type = 'checkbox';
  695. group5Checkbox.id = 'group5Checkbox';
  696. group5Checkbox.checked = true;
  697.  
  698. let lblGroup5Checkbox = document.createElement('label');
  699. lblGroup5Checkbox.setAttribute('for', 'group5Checkbox');
  700. lblGroup5Checkbox.classList.add('switch-check-label');
  701.  
  702. let divGroup5Checkbox = document.createElement('div');
  703. divGroup5Checkbox.classList.add('switch-check');
  704. divGroup5Checkbox.appendChild(group5Checkbox);
  705. divGroup5Checkbox.appendChild(lblGroup5Checkbox);
  706.  
  707. dataText5 = document.createElement('textarea');
  708. dataText5.classList.add('danmu-group-textarea');
  709. dataText5.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  710. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  711.  
  712.  
  713. /* ----------------------------------------- send interval ----------------------------------------- */
  714. beforeSpan = document.createElement('span');
  715. beforeSpan.textContent = '设置弹幕每';
  716. beforeSpan.classList.add('danmu-text-span');
  717. beforeSpan.style.marginLeft = '4px';
  718.  
  719. dmInput = document.createElement('input');
  720. dmInput.value = default_timeout;
  721. dmInput.classList.add('danmu-second-input');
  722. dmInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  723.  
  724. afterSpan = document.createElement('span');
  725. afterSpan.textContent = '秒发送一次';
  726. afterSpan.classList.add('danmu-text-span');
  727. afterSpan.style.marginRight = '4px';
  728.  
  729. let divSendInterval = document.createElement('div');
  730. divSendInterval.appendChild(beforeSpan);
  731. divSendInterval.appendChild(dmInput);
  732. divSendInterval.appendChild(afterSpan);
  733.  
  734. let divSendNote = document.createElement('div');
  735. divSendNote.textContent = '▲ 执行任务时会占用输入框,如果输入框有内容则跳过任务,直到清空输入框为止';
  736. /* ----------------------------------------- send interval ----------------------------------------- */
  737.  
  738.  
  739. /* ----------------------------------------- different room setting ----------------------------------------- */
  740. signInput = document.createElement('input');
  741. signInput.id = 'signInputText';
  742. signInput.style.border = '0';
  743. signInput.style.width = '90px';
  744. signInput.setAttribute('placeholder', '输入打卡的文字');
  745. hesitationIntervalInput = createIntervalInput();
  746. hesitationRandomInput = createIntervalInput();
  747. intervalClickLikeInput = createIntervalInput();
  748.  
  749. let divRoomSetting = document.createElement('div');
  750. divRoomSetting.appendChild(divText1);
  751. divRoomSetting.appendChild(divGroup1Checkbox);
  752. divRoomSetting.appendChild(dataText1);
  753. divRoomSetting.appendChild(divText2);
  754. divRoomSetting.appendChild(divGroup2Checkbox);
  755. divRoomSetting.appendChild(dataText2);
  756. divRoomSetting.appendChild(divText3);
  757. divRoomSetting.appendChild(divGroup3Checkbox);
  758. divRoomSetting.appendChild(dataText3);
  759. divRoomSetting.appendChild(divText4);
  760. divRoomSetting.appendChild(divGroup4Checkbox);
  761. divRoomSetting.appendChild(dataText4);
  762. divRoomSetting.appendChild(divText5);
  763. divRoomSetting.appendChild(divGroup5Checkbox);
  764. divRoomSetting.appendChild(dataText5);
  765. divRoomSetting.appendChild(divSendInterval);
  766. divRoomSetting.appendChild(divSendNote);
  767. rdCheckbox = createSwitch('rdCheckbox', '随机从上面的弹幕中选出一条发送', '将合并所有分组数据,从中随机选出一条发送', null, divRoomSetting);
  768. usePublicCheckbox = createSwitch('usePublicCheckbox', '使用共用弹幕源', '使用设置为共用弹幕作为弹幕源', usePublicFunc, divRoomSetting);
  769. signInCheckbox = createSwitch('signInCheckbox', '打卡弹幕:', '每日零点自动发送一条打卡弹幕', signInFunc, divRoomSetting, null, null, false, signInput);
  770. autoLikeCheckbox = createSwitch('autoLikeCheckbox', '自动点赞该直播间', '分成固定间隔的定时点赞和随机某个时间点点赞功能', autoLikeFunc, divRoomSetting, null, null, null, null, null);
  771. clickLikeIntervalCheckbox = createSwitch('clickLikeIntervalCheckbox', '定时点赞:', '大于3秒的时间间隔任意设置(时间单位:秒,最小间隔3秒,免得被滥用惹恼了阿B加上人机校验)', intervalClickLikeFunc, divRoomSetting, '23px', '90%', true, intervalClickLikeInput, false);
  772. clickLikeRandomCheckbox = createSwitch('clickLikeRandomCheckbox', '随机时间点点赞', '每15秒内随机一个时间点点赞一次直播间(点赞1000次大概需要4小时)', randomClickLikeFunc, divRoomSetting, '23px', '90%', true, null, false);
  773. lotteryCheckbox = createSwitch('lotteryCheckbox', '自动参与天选时刻抽奖(需登录)', '自动点击参与按钮,请确保已经登录了阿B账号', lotteryFunc, divRoomSetting);
  774. hesitationIntervalCheckbox = createSwitch('hesitationIntervalCheckbox', '犹豫期:', '不立刻参与天选时刻,这期间可以手动处理,免得自动参加后后悔(时间单位:秒)', hesitationIntervalFunc, divRoomSetting, '23px', '90%', true, hesitationIntervalInput, false);
  775. hesitationRandomCheckbox = createSwitch('hesitationRandomCheckbox', '随机犹豫期:', '尝试应对人机校验,不一定有效,随机的范围:(0, 填的数字](时间单位:秒)', hesitationRandomFunc, divRoomSetting, '23px', '90%', true, hesitationRandomInput, false);
  776.  
  777. let operationDescription = document.createElement('div');
  778. operationDescription.textContent = '以上设置对应各个直播间独立保存,无需刷新';
  779. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  780. operationDescription.classList.add('global-setting-tip');
  781. operationDescription.classList.add('switch-check-group');
  782. divRoomSetting.appendChild(operationDescription);
  783. /* ----------------------------------------- different room setting ----------------------------------------- */
  784.  
  785. /* ----------------------------------------- global setting ----------------------------------------- */
  786. let divGlobalSetting = document.createElement('div');
  787. divGlobalSetting.style.margin = '20px 0 10px';
  788.  
  789. operationDescription = document.createElement('div');
  790. operationDescription.textContent = '以下设置,需刷新其它直播间才能适用';
  791. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  792. operationDescription.classList.add('global-setting-tip');
  793. operationDescription.classList.add('switch-check-group');
  794. divGlobalSetting.appendChild(operationDescription);
  795.  
  796. setPublicCheckbox = createSwitch('setPublicCheckbox', '设为共用弹幕源', '把这个直播间的弹幕共享给其它直播间使用,先后设置时,后面的会覆盖前面的设置', setPublicFunc, divGlobalSetting);
  797. closeLotteryCheckbox = createSwitch('closeLotteryCheckbox', '关闭天选时刻', '关闭天选时刻弹窗', closeLotteryFunc, divGlobalSetting);
  798. hideGiftControlCheckbox = createSwitch('hideGiftControlCheckbox', '隐藏礼物栏', '隐藏播放器底部的礼物栏', hideGiftControlFunc, divGlobalSetting);
  799. noSleepCheckbox = createSwitch('noSleepCheckbox', '防止直播间休眠', '防止直播间页面一段时间没操作之后进入休眠', noSleepFunc, divGlobalSetting, null, null, false);
  800. hideLoginGuideCheckbox = createSwitch('hideLoginGuideCheckbox', '隐藏播放器底部登录提示', '隐藏未登录时播放器底部显示的登录提示', hideLoginGuideFunc, divGlobalSetting);
  801. hideHarunaCheckbox = createSwitch('hideHarunaCheckbox', '隐藏看板娘立绘', '隐藏直播间Haruna立绘', hideHarunaFunc, divGlobalSetting);
  802. hideShopCheckbox = createSwitch('hideShopCheckbox', '隐藏购物提示', '隐藏播放器左上角的商店购物提示', hideShopFunc, divGlobalSetting);
  803. hideRoomFeedCheckbox = createSwitch('hideRoomFeedCheckbox', '隐藏主播动态', '隐藏播放器底下主播的动态栏', hideRoomFeedFunc, divGlobalSetting);
  804. hideRoomInfoCheckbox = createSwitch('hideRoomInfoCheckbox', '隐藏简介、荣誉,或直播间推荐列表', '隐藏播放器底下直播间推荐列表,不登录账号显示为主播的荣耀和简介', hideRoomInfoFunc, divGlobalSetting);
  805. hideNoticeCheckbox = createSwitch('hideNoticeCheckbox', '隐藏主播公告', '隐藏弹幕列表底下主播的公告', hideNoticeFunc, divGlobalSetting);
  806. hideFooterCheckbox = createSwitch('hideFooterCheckbox', '隐藏直播间页脚', '隐藏直播间底部的网页页脚', hideFooterFunc, divGlobalSetting);
  807. hidePrivacyCheckbox = createSwitch('hidePrivacyCheckbox', '隐藏隐私提示对话框', '隐藏隐私提示登录的对话框,被打码的昵称不保证变回正常', hidePrivacyFunc, divGlobalSetting);
  808. hideRoomStatusCheckbox = createSwitch('hideRoomStatusCheckbox', '隐藏直播水印', '隐藏播放器左上角的直播水印', hideRoomStatusFunc, divGlobalSetting);
  809. hideBusinessCheckbox = createSwitch('hideBusinessCheckbox', '隐藏商业性互动', '隐藏全站广播、PK、连MIC、连视频等', hideBusinessFunc, divGlobalSetting);
  810. hideRankListCheckbox = createSwitch('hideRankListCheckbox', '隐藏滚动排行榜', '隐藏顶部的人气榜、航海榜、礼物星球等', hideRankListFunc, divGlobalSetting);
  811. showLiveAreaCheckbox = createSwitch('showLiveArea', '显示直播分区', '显示直播间所属的直播分区', showLiveAreaFunc, divGlobalSetting);
  812. /* ----------------------------------------- global setting ----------------------------------------- */
  813.  
  814. /* ----------------------------------------- operation msg ----------------------------------------- */
  815. spanApplyMsg = document.createElement('span');
  816. spanApplyMsg.classList.add('danmu-random-setting-success-text');
  817.  
  818. let divApplyMsg = document.createElement('div');
  819. divApplyMsg.classList.add('danmu-random-setting-success-tips');
  820. divApplyMsg.appendChild(spanApplyMsg);
  821. /* ----------------------------------------- operation msg ----------------------------------------- */
  822. /* ----------------------------------------- clean cache ----------------------------------------- */
  823. let cleanCacheBtn = document.createElement('button');
  824. cleanCacheBtn.style.setProperty('display', 'none');
  825. cleanCacheBtn.textContent = '清除缓存';
  826. cleanCacheBtn.classList.add('clean-cache-btn');
  827. cleanCacheBtn.addEventListener('click', cleanCache);
  828. /* ----------------------------------------- clean cache ----------------------------------------- */
  829.  
  830. /* ----------------------------------------- save and close button ----------------------------------------- */
  831. let btnSave = document.createElement('i');
  832. btnSave.setAttribute('title', '保存');
  833. btnSave.style.padding = '5px';
  834. btnSave.classList.add('el-button');
  835. btnSave.classList.add('el-icon-check');
  836. btnSave.classList.add('is-circle');
  837. btnSave.addEventListener('click', save);
  838.  
  839. let btnClose = document.createElement('i');
  840. btnClose.setAttribute('title', '关闭');
  841. btnClose.style.padding = '5px';
  842. btnClose.classList.add('el-button');
  843. btnClose.classList.add('el-icon-close');
  844. btnClose.classList.add('is-circle');
  845. btnClose.addEventListener('click', closeSetting);
  846.  
  847. let divBtnSetting = document.createElement('div');
  848. divBtnSetting.classList.add('danmu-random-set-button-container');
  849. divBtnSetting.appendChild(cleanCacheBtn);
  850. divBtnSetting.appendChild(btnSave);
  851. divBtnSetting.appendChild(btnClose);
  852. /* ----------------------------------------- save and close button ----------------------------------------- */
  853.  
  854. /* ----------------------------------------- container ----------------------------------------- */
  855. let divBottomContainer = document.createElement('div');
  856. divBottomContainer.classList.add('danmu-random-setting-bottom');
  857. divBottomContainer.appendChild(divApplyMsg);
  858. divBottomContainer.appendChild(divBtnSetting);
  859.  
  860. let divOtherContainer = document.createElement('div');
  861. divOtherContainer.id = 'otherContainer';
  862.  
  863. let divContainer = document.createElement('div');
  864. divContainer.style.height = 'calc(98% - 30px - 25px)';
  865. divContainer.appendChild(divRoomSetting);
  866. divContainer.appendChild(divGlobalSetting);
  867. divContainer.appendChild(divOtherContainer);
  868. divContainer.appendChild(divBottomContainer);
  869. /* ----------------------------------------- container ----------------------------------------- */
  870.  
  871. divSetting = document.createElement('div');
  872. divSetting.id = 'danmu-setting-panel';
  873. divSetting.classList.add('danmu-random-setting-panel');
  874. divSetting.appendChild(divSettingTitle);
  875. divSetting.appendChild(divUpdateInfo);
  876. divSetting.appendChild(divTip);
  877. divSetting.appendChild(divContainer);
  878.  
  879. let asideAreaVm = document.getElementById('aside-area-vm');
  880. asideAreaVm.appendChild(divSetting);
  881.  
  882. },
  883. btnStart = btn => {
  884. btnStartText = document.createElement('span');
  885. btnStartText.textContent = '开始';
  886. btnStartText.title = txtStartTask;
  887. btnStartText.classList.add('txt');
  888.  
  889. dmButtonSend = document.createElement('button');
  890. dmButtonSend.title = txtStartTask;
  891. //dmButtonSend.onclick = function() { alert('Hello world');}
  892. dmButtonSend.addEventListener('click', offOrOn);
  893. dmButtonSend.appendChild(btnStartText);
  894. if (btn) {
  895. copyAttributes(btn, dmButtonSend);
  896. const span = btn.querySelector('span');
  897. if (span) {
  898. copyAttributes(span, btnStartText);
  899. }
  900. }
  901. else {
  902. dmButtonSend.classList.add('danmu-btn');
  903. dmButtonSend.style.setProperty('--color', 'rgba(217,157,27,0.8)');
  904. }
  905. },
  906. btnStartLogin = () => {
  907. let iElement = document.createElement('i');
  908. iElement.classList.add('el-icon-s-promotion');
  909.  
  910. dmButtonSend = document.createElement('button');
  911. dmButtonSend.title = txtStartTask;
  912. dmButtonSend.classList.add('el-button');
  913. dmButtonSend.classList.add('el-button--mini');
  914. dmButtonSend.classList.add('is-circle');
  915. dmButtonSend.style.background = 'none';
  916. dmButtonSend.style.fontSize = '20px';
  917. dmButtonSend.style.border = '0';
  918. dmButtonSend.addEventListener('click', offOrOn);
  919. dmButtonSend.appendChild(iElement);
  920.  
  921. let div = document.createElement('div');
  922. div.style.position = 'absolute';
  923. div.style.right = '5px';
  924. div.style.alignSelf = 'flex-end';
  925. div.style.marginBottom = '-2px';
  926. div.appendChild(dmButtonSend);
  927. return div;
  928. },
  929. btnSetting = () => {
  930. const divEmo = document.getElementsByClassName('emoticons-panel border-box')[0]; // 表情包
  931. let iElement = document.createElement('i');
  932. iElement.classList.add('el-icon-setting');
  933.  
  934. let btn = document.createElement('button');
  935. btn.title = '定时设置';
  936. btn.classList.add('el-button');
  937. btn.classList.add('el-button--mini');
  938. btn.classList.add('is-circle');
  939. btn.style.border = '0';
  940. btn.addEventListener('click', openSetting);
  941. btn.appendChild(iElement);
  942. if (divEmo) {
  943. btn.style.background = 'none';
  944. btn.style.fontSize = '19px';
  945. let div = document.createElement('div');
  946. copyAttributes(divEmo, div);
  947. div.style.backgroundImage = 'none';
  948. div.style.alignSelf = 'flex-end';
  949. div.style.marginBottom = '5px';
  950. div.style.position = 'absolute';
  951. div.style.right = '33px';
  952. div.appendChild(btn);
  953.  
  954. divEmo.style.alignSelf = 'flex-start';
  955. divEmo.style.marginTop = '1px';
  956. return div;
  957. }
  958. else {
  959. btn.style.fontSize = '15px';
  960. btn.style.margin = '0 5px';
  961. return btn;
  962. }
  963. },
  964. copyAttributes = (oldNode, newNode) => {
  965. Array.prototype.forEach.call(oldNode.attributes, (item, index) => newNode.setAttribute(item.name, item.value));
  966. },
  967. setDisplay = (dom, property, important) => {
  968. if (important) {
  969. dom.style.setProperty('display', property, 'important');
  970. }
  971. else {
  972. dom.style.setProperty('display', property);
  973. }
  974. },
  975. blockDisplay = (dom, shwon) => {
  976. if (shwon) {
  977. setDisplay(dom, 'block', true);
  978. }
  979. else {
  980. dom.style.removeProperty('display');
  981. }
  982. },
  983. noneDisplay = (dom, hidden) => {
  984. if (hidden) {
  985. setDisplay(dom, 'none', true);
  986. }
  987. else {
  988. dom.style.removeProperty('display');
  989. }
  990. },
  991. removeAttributeFromChildren = (dom, attr) => {
  992. dom.removeAttribute(attr);
  993. if (0 < dom.children.length) {
  994. for (let i = 0; i < dom.children.length; i++) {
  995. removeAttributeFromChildren(dom.children[i], attr);
  996. }
  997. }
  998. },
  999. setAttributeToChildren = (dom, attr, val) => {
  1000. dom.setAttribute(attr, val);
  1001. if (0 < dom.children.length) {
  1002. for (let i = 0; i < dom.children.length; i++) {
  1003. setAttributeToChildren(dom.children[i], attr, val);
  1004. }
  1005. }
  1006. },
  1007. removeClassFromChildren = (dom, classes) => {
  1008. dom.classList.remove(classes);
  1009. if (0 < dom.children.length) {
  1010. for (let i = 0; i < dom.children.length; i++) {
  1011. removeClassFromChildren(dom.children[i], classes);
  1012. }
  1013. }
  1014. },
  1015. addClassToChildren = (dom, classes) => {
  1016. dom.classList.add(classes);
  1017. if (0 < dom.children.length) {
  1018. for (let i = 0; i < dom.children.length; i++) {
  1019. addClassToChildren(dom.children[i], classes);
  1020. }
  1021. }
  1022. },
  1023. hideLoginGuideFunc = () => {
  1024. let dom = document.getElementById('switch-login-guide-vm');
  1025. if (dom) {
  1026. noneDisplay(dom, hideLoginGuideCheckbox.checked);
  1027. }
  1028. },
  1029. hideHarunaFunc = () => {
  1030. let dom = document.getElementById('my-dear-haruna-vm');
  1031. if (dom) {
  1032. noneDisplay(dom, hideHarunaCheckbox.checked);
  1033. }
  1034. },
  1035. hideShopFunc = () => {
  1036. let dom = document.getElementById('shop-popover-vm');
  1037. if (dom) {
  1038. noneDisplay(dom, hideShopCheckbox.checked);
  1039. }
  1040. },
  1041. hideGiftControlFunc = () => {
  1042. let dom = document.getElementsByClassName('gift-control-section')[0];
  1043. if (dom) {
  1044. noneDisplay(dom, hideGiftControlCheckbox.checked);
  1045. }
  1046.  
  1047. dom = document.getElementById('web-player__bottom-bar__container');
  1048. if (dom) {
  1049. noneDisplay(dom, hideGiftControlCheckbox.checked);
  1050. }
  1051.  
  1052. dom = document.getElementsByTagName('video');
  1053. for (let i = 0; i < dom.length; i++) {
  1054. if (!dom[i]) {
  1055. return;
  1056. }
  1057. if (hideGiftControlCheckbox.checked) {
  1058. dom[i].style.setProperty('height', '100%');
  1059. }
  1060. else if (document.body.classList.contains('player-full-win') || document.body.classList.contains('fullscreen-fix')) {
  1061. dom[i].style.setProperty('height', 'calc(100% - 114px)');
  1062. }
  1063. }
  1064. },
  1065. hideRoomFeedFunc = () => {
  1066. let dom = document.getElementsByClassName('room-feed')[0];
  1067. if (dom) {
  1068. noneDisplay(dom, hideRoomFeedCheckbox.checked);
  1069. }
  1070. dom = document.getElementsByClassName('flip-view p-relative')[0];
  1071. if (dom) {
  1072. noneDisplay(dom, hideRoomFeedCheckbox.checked);
  1073. }
  1074. },
  1075. hideRoomInfoFunc = () => {
  1076. let dom = document.getElementsByClassName('room-info-ctnr')[0];
  1077. if (dom) {
  1078. noneDisplay(dom, hideRoomInfoCheckbox.checked);
  1079. }
  1080. },
  1081. hideNoticeFunc = () => {
  1082. let dom = document.getElementsByClassName('right-container')[0];
  1083. if (dom) {
  1084. dom.style.setProperty('min-height', 'auto');
  1085. noneDisplay(dom, hideNoticeCheckbox.checked);
  1086. }
  1087. },
  1088. hideFooterFunc = () => {
  1089. let dom = document.getElementById('link-footer-vm');
  1090. if (dom) {
  1091. noneDisplay(dom, hideFooterCheckbox.checked);
  1092. }
  1093. },
  1094. hidePrivacyFunc = () => {
  1095. if (hidePrivacyCheckbox.checked) {
  1096. let dom = document.createElement('style');
  1097. dom.id = 'hidePrivacyDialog';
  1098. dom.setAttribute('type', 'text/css');
  1099. dom.innerHTML = '.privacy-dialog{display:none !important;}';
  1100. document.head.appendChild(dom);
  1101. }
  1102. else {
  1103. let dom = document.getElementById('hidePrivacyDialog');
  1104. if (dom) {
  1105. dom.remove();
  1106. }
  1107. }
  1108. },
  1109. hideRoomStatusFunc = () => {
  1110. let dom = document.getElementsByClassName('web-player-icon-roomStatus')[0];
  1111. if (dom) {
  1112. noneDisplay(dom, hideRoomStatusCheckbox.checked);
  1113. }
  1114. },
  1115. hideBusinessFunc = () => {
  1116. let dom = document.getElementById('businessContainerElement');
  1117. if (dom) {
  1118. noneDisplay(dom, hideBusinessCheckbox.checked);
  1119. }
  1120. },
  1121. // 适配Bilibili直播自动追帧样式
  1122. adaptBililiveSeeker = () => {
  1123. let dom = document.getElementById('playback-rate-title');
  1124. if (dom) {
  1125. noneDisplay(dom, true);
  1126. dom.parentElement.style.removeProperty('padding-bottom');
  1127. }
  1128.  
  1129. dom = document.getElementById('playback-rate-username');
  1130. if (dom) {
  1131. dom.style.removeProperty('display');
  1132. }
  1133. },
  1134. hideRankListFunc = () => {
  1135. let lower = document.getElementsByClassName('lower-row')[0];
  1136. if (!lower) {
  1137. return;
  1138. }
  1139.  
  1140. let dom = lower.getElementsByClassName('right-ctnr')[0]
  1141. if (dom) {
  1142. noneDisplay(dom, hideRankListCheckbox.checked);
  1143. let t = workerTimer.setTimeout(() => {
  1144. workerTimer.clearTimeout(t);
  1145. t = null;
  1146. adaptBililiveSeeker();
  1147. }, 100);
  1148. }
  1149. },
  1150. showLiveAreaFunc = () => {
  1151. let dom = document.getElementsByClassName('live-area')[0];
  1152. if (dom) {
  1153. blockDisplay(dom, showLiveAreaCheckbox.checked);
  1154. adaptBililiveSeeker();
  1155. }
  1156. },
  1157. getLottery = () => {
  1158. let v = window.localStorage.getItem(lotteryPrefix + roomId);
  1159. if (!v) {
  1160. return source.lottery;
  1161. }
  1162. if ('string' === typeof v) {
  1163. try {
  1164. v = JSON.parse(v);
  1165. } catch (e) {
  1166. console.error('===> Parsing error:', e);
  1167. v = source.lottery;
  1168. }
  1169. }
  1170.  
  1171. return v;
  1172. },
  1173. setLottery = obj => {
  1174. window.localStorage.setItem(lotteryPrefix + roomId, obj);
  1175. },
  1176. lotteryFunc = () => {
  1177. let obj = getLottery();
  1178. obj.lottery = lotteryCheckbox.checked;
  1179. setLottery(obj);
  1180. let domI = document.getElementById('hesitationIntervalCheckboxDiv');
  1181. if (domI) {
  1182. noneDisplay(domI, !lotteryCheckbox.checked)
  1183. }
  1184.  
  1185. let domR = document.getElementById('hesitationRandomCheckboxDiv');
  1186. if (domR) {
  1187. noneDisplay(domR, !lotteryCheckbox.checked)
  1188. }
  1189. },
  1190. closeLotteryFunc = () => {
  1191. window.localStorage.setItem(closeLotteryChecked, closeLotteryCheckbox.checked);
  1192. },
  1193. hesitationIntervalFunc = () => {
  1194. let dom = document.getElementById('hesitationRandomCheckboxDiv');
  1195. if (hesitationIntervalCheckbox.checked) {
  1196. hesitationIntervalInput.disabled = true;
  1197. if (dom) {
  1198. hesitationRandomInput.disabled = true;
  1199. hesitationRandomCheckbox.checked = false;
  1200. hesitationRandomCheckbox.disabled = true;
  1201. addClassToChildren(dom, 'disabled');
  1202. }
  1203. }
  1204. else {
  1205. hesitationIntervalInput.disabled = false;
  1206. if (dom) {
  1207. hesitationRandomInput.disabled = false;
  1208. hesitationRandomCheckbox.disabled = false;
  1209. removeClassFromChildren(dom, 'disabled');
  1210. }
  1211. }
  1212.  
  1213. let obj = getLottery();
  1214. obj.hesitationInterval = hesitationIntervalCheckbox.checked;
  1215. obj.hesitationIntervalExpiry = hesitationIntervalInput.value;
  1216. setLottery(obj);
  1217. },
  1218. hesitationRandomFunc = () => {
  1219. let dom = document.getElementById('hesitationIntervalCheckboxDiv');
  1220. if (hesitationRandomCheckbox.checked) {
  1221. hesitationRandomInput.disabled = true;
  1222. if (dom) {
  1223. hesitationIntervalInput.disabled = true;
  1224. hesitationIntervalCheckbox.checked = false;
  1225. hesitationIntervalCheckbox.disabled = true;
  1226. addClassToChildren(dom, 'disabled');
  1227. }
  1228. }
  1229. else {
  1230. hesitationRandomInput.disabled = false;
  1231. if (dom) {
  1232. hesitationIntervalInput.disabled = false;
  1233. hesitationIntervalCheckbox.disabled = false;
  1234. removeClassFromChildren(dom, 'disabled');
  1235. }
  1236. }
  1237.  
  1238. let obj = getLottery();
  1239. obj.hesitationRandom = hesitationRandomCheckbox.checked;
  1240. obj.hesitationRandomExpiry = hesitationRandomInput.value;
  1241. setLottery(obj);
  1242. },
  1243. setPublicFunc = () => {},
  1244. usePublicFunc = () => {
  1245. let obj = null;
  1246. if (usePublicCheckbox.checked) {
  1247. obj = getGmValue(baseInfo.default, null);
  1248. }
  1249. else {
  1250. obj = source;
  1251. }
  1252. if (obj) {
  1253. setDmSourceInput(obj);
  1254. }
  1255. },
  1256. clickLikeBtn = () => {
  1257. let dom = document.getElementsByClassName('like-btn')[0];
  1258. if (dom) {
  1259. dom.click();
  1260. // console.log(`===> 【${new Date().toLocaleString()}】点击一次点赞按钮`);
  1261. }
  1262. },
  1263. clearClickLikeTimer = () => {
  1264. if (autoLikeTimer) {
  1265. workerTimer.clearInterval(autoLikeTimer);
  1266. autoLikeTimer = null;
  1267. // console.log(`===> 关闭自动点赞功能`);
  1268. }
  1269. if (clickLikeBtnTimer) {
  1270. workerTimer.clearTimeout(clickLikeBtnTimer);
  1271. clickLikeBtnTimer = null;
  1272. // console.log(`===> 关闭超时点击点赞按钮功能`);
  1273. }
  1274. },
  1275. autoLikeFunc = () => {
  1276. let domI = document.getElementById('clickLikeIntervalCheckboxDiv');
  1277. if (domI) {
  1278. noneDisplay(domI, !autoLikeCheckbox.checked);
  1279. }
  1280.  
  1281. let domR = document.getElementById('clickLikeRandomCheckboxDiv');
  1282. if (domR) {
  1283. noneDisplay(domR, !autoLikeCheckbox.checked);
  1284. }
  1285. if (autoLikeCheckbox.checked) {
  1286. clickLikeRandomCheckbox.checked && randomClickLikeFunc();
  1287. clickLikeIntervalCheckbox.checked && intervalClickLikeFunc();
  1288. }
  1289. else {
  1290. clearClickLikeTimer();
  1291. if (domI) {
  1292. intervalClickLikeInput.disabled = false;
  1293. clickLikeIntervalCheckbox.disabled = false;
  1294. removeClassFromChildren(domI, 'disabled');
  1295. }
  1296. if (domR) {
  1297. clickLikeRandomCheckbox.disabled = false;
  1298. removeClassFromChildren(domR, 'disabled');
  1299. }
  1300. }
  1301. },
  1302. intervalClickLikeFunc = () => {
  1303. let dom = document.getElementById('clickLikeRandomCheckboxDiv');
  1304. if (clickLikeIntervalCheckbox.checked) {
  1305. intervalClickLikeInput.disabled = true;
  1306. if (dom) {
  1307. clickLikeRandomCheckbox.checked = false;
  1308. clickLikeRandomCheckbox.disabled = true;
  1309. addClassToChildren(dom, 'disabled');
  1310. }
  1311. if (autoLikeTimer) {
  1312. return;
  1313. }
  1314.  
  1315. // console.log(`===> 开启定时自动点赞功能【${new Date().toLocaleString()}】`);
  1316. clickLikeBtn();
  1317. let clickLikeInterval = 3e3;
  1318. !isNull(intervalClickLikeInput.value) && 3 < intervalClickLikeInput.value && (clickLikeInterval = intervalClickLikeInput.value * 1e3)
  1319. // console.log(`===> 【${new Date().toLocaleString()}】设置【${clickLikeInterval}】毫秒后点击点赞按钮`);
  1320. autoLikeTimer = workerTimer.setInterval(() => clickLikeBtn(), clickLikeInterval);
  1321. }
  1322. else {
  1323. clearClickLikeTimer();
  1324. intervalClickLikeInput.disabled = false;
  1325. if (dom) {
  1326. clickLikeRandomCheckbox.disabled = false;
  1327. removeClassFromChildren(dom, 'disabled');
  1328. }
  1329. }
  1330. },
  1331. randomClickLikeFunc = () => {
  1332. let dom = document.getElementById('clickLikeIntervalCheckboxDiv');
  1333. if (clickLikeRandomCheckbox.checked) {
  1334. if (dom) {
  1335. intervalClickLikeInput.disabled = true;
  1336. clickLikeIntervalCheckbox.disabled = true;
  1337. clickLikeIntervalCheckbox.checked = false;
  1338. addClassToChildren(dom, 'disabled');
  1339. }
  1340. if (autoLikeTimer) {
  1341. return;
  1342. }
  1343.  
  1344. clickLikeBtn();
  1345. // console.log(`===> 开启随机时间点点赞功能【${new Date().toLocaleString()}】`);
  1346. autoLikeTimer = workerTimer.setInterval(() => {
  1347. let rdTimeout = Math.floor(Math.random() * 15000);
  1348. if (1000 > rdTimeout) {
  1349. // console.log(`===> 【${new Date().toLocaleString()}】立刻点击点赞按钮`);
  1350. clickLikeBtn();
  1351. }
  1352. else {
  1353. // console.log(`===> 【${new Date().toLocaleString()}】设置【${rdTimeout}】毫秒后点击点赞按钮`);
  1354. clickLikeBtnTimer = workerTimer.setTimeout(() => {
  1355. workerTimer.clearTimeout(clickLikeBtnTimer);
  1356. clickLikeBtnTimer = null;
  1357. clickLikeBtn();
  1358. }, rdTimeout);
  1359. }
  1360. }, 15e3);
  1361. }
  1362. else {
  1363. clearClickLikeTimer();
  1364. if (dom) {
  1365. intervalClickLikeInput.disabled = false;
  1366. clickLikeIntervalCheckbox.disabled = false;
  1367. removeClassFromChildren(dom, 'disabled');
  1368. }
  1369. }
  1370. },
  1371. clickPlay = () => {
  1372. // let dom = document.getElementsByClassName('_tip-btn_6f52f')[0];
  1373. // if (dom) {
  1374. // dom.click();
  1375. // }
  1376.  
  1377. // dom = document.getElementsByClassName('_tip-text_6f52f')[0];
  1378. // if (dom) {
  1379. // dom.click();
  1380. // }
  1381. },
  1382. autoPlay = () => {
  1383. let t = workerTimer.setTimeout(() => {
  1384. workerTimer.clearTimeout(t);
  1385. clickPlay();
  1386. t = workerTimer.setTimeout(() => {
  1387. workerTimer.clearTimeout(t);
  1388. t = null;
  1389. clickPlay();
  1390. }, 2e3);
  1391. }, 3e3);
  1392. },
  1393. noSleepFunc = () => {
  1394. if (noSleepCheckbox.checked) {
  1395. if (!noSleepTimer) {
  1396. console.log('===> 开启防休眠功能');
  1397. noSleepTimer = workerTimer.setInterval(() => {
  1398. noSleepTimeouter = workerTimer.setTimeout(() => {
  1399. workerTimer.clearTimeout(noSleepTimeouter);
  1400. document.body.dispatchEvent(new MouseEvent('mousemove', { bubbles: true }));
  1401. }, Math.random() * 3e3);
  1402. }, 17e3);
  1403. }
  1404. } else {
  1405. console.log('===> 关闭防休眠功能');
  1406. if (noSleepTimer) {
  1407. workerTimer.clearInterval(noSleepTimer);
  1408. noSleepTimer = null;
  1409. }
  1410. if (noSleepTimeouter) {
  1411. workerTimer.clearTimeout(noSleepTimeouter);
  1412. noSleepTimeouter = null;
  1413. }
  1414. }
  1415. },
  1416. biliMiniClose = () => {
  1417. if (!miniCloseTimer) {
  1418. let miniCloseCount = 3;
  1419. miniCloseTimer = workerTimer.setInterval(() => {
  1420. let mini_close = document.getElementsByClassName('bili-mini-close')[0];
  1421. if (!mini_close) {
  1422. if (0 >= --miniCloseCount) {
  1423. workerTimer.clearInterval(miniCloseTimer);
  1424. miniCloseTimer = null;
  1425. }
  1426.  
  1427. return;
  1428. }
  1429.  
  1430. mini_close.click();
  1431. workerTimer.clearInterval(miniCloseTimer);
  1432. miniCloseTimer = null;
  1433. }, 10e3);
  1434. }
  1435. },
  1436. closeLottery = delay => {
  1437. let btnClose = document.getElementsByClassName('close-btn bg-contain')[0];
  1438. if (btnClose) {
  1439. if (isNull(delay)) {
  1440. btnClose.click();
  1441. } else {
  1442. let closeLotteryTimer = workerTimer.setTimeout(() => {
  1443. workerTimer.clearTimeout(closeLotteryTimer);
  1444. btnClose.click();
  1445. }, delay * 1000);
  1446. }
  1447. }
  1448. },
  1449. clickLotteryBtn = (btn, expiry) => {
  1450. // console.log(`===> 【${new Date().toLocaleString()}】随机时间【${expiry}】`);
  1451. let lotteryTimer = workerTimer.setTimeout(() => {
  1452. workerTimer.clearTimeout(lotteryTimer);
  1453. console.log(`===> ${new Date().toLocaleString()}】犹豫期过后自动参加抽奖`);
  1454. btn.click();
  1455. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1456. console.log('===> 参加成功,延迟关闭弹窗');
  1457. closeLottery(3);
  1458. }
  1459. }, expiry);
  1460. },
  1461. lottery = btn => {
  1462. if (!btn) {
  1463. console.warn('===> 没有抽奖按钮DOM');
  1464. return;
  1465. }
  1466.  
  1467. let obj = getLottery();
  1468. if (!obj.lottery) {
  1469. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1470. console.log('===> 不参与天选时刻抽奖,关闭弹窗');
  1471. closeLottery();
  1472. }
  1473.  
  1474. return;
  1475. }
  1476. if (obj.hesitationInterval) {
  1477. let expiry = isNull(obj.hesitationIntervalExpiry) || 0 >= obj.hesitationIntervalExpiry ? 100e3 : obj.hesitationIntervalExpiry * 1e3;
  1478. clickLotteryBtn(btn, expiry);
  1479. }
  1480. else if (obj.hesitationRandom) {
  1481. let expiry = isNull(obj.hesitationRandomExpiry) || 0 >= obj.hesitationRandomExpiry ? 100e3 : obj.hesitationRandomExpiry * 1e3;
  1482. expiry = Math.ceil(Math.random() * expiry);
  1483. clickLotteryBtn(btn, expiry);
  1484. }
  1485. else {
  1486. console.log('===> 立刻自动参加抽奖');
  1487. btn.click();
  1488. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1489. console.log('===> 参加成功,延迟关闭弹窗');
  1490. closeLottery(3);
  1491. }
  1492. }
  1493. },
  1494. listPlus = nodes => {
  1495. if (!nodes || 0 >= nodes.length) return;
  1496. Array.prototype.forEach.call(nodes, y => {
  1497. let aNode = y.firstChild;
  1498. if (!aNode) return;
  1499. let a_d2 = aNode.children[1];
  1500. if (!a_d2) return;
  1501. let a_d2_d2 = a_d2.children[1];
  1502. if (!a_d2_d2) return;
  1503. let a_d2_d2_d2 = a_d2_d2.children[1];
  1504. if (!a_d2_d2_d2) return;
  1505. let a_d2_d2_d2_d1 = a_d2_d2_d2.children[0];
  1506. if (!a_d2_d2_d2_d1) return;
  1507. aNode.title = a_d2_d2_d2_d1.textContent;
  1508. let a_d2_d1 = a_d2.children[0];
  1509. if (a_d2_d1) {
  1510. let a_d2_d1_last = a_d2_d1.lastChild;
  1511. if (a_d2_d1_last && a_d2_d1_last.style.display && 'none' == a_d2_d1_last.style.display) {
  1512. a_d2_d1_last.remove();
  1513. }
  1514. }
  1515. });
  1516. },
  1517. getConfig = () => {
  1518. let c = {};
  1519. if (baseInfo.config) {
  1520. c = getGmValue(baseInfo.config, {});
  1521. !isNull(c.lottery) && delete c.lottery;
  1522. !isNull(c.signInText) && delete c.signInText;
  1523. !isNull(c.hesitation) && delete c.hesitation;
  1524. !isNull(c.hesitationExpiry) && delete c.hesitationExpiry;
  1525. isNull(c.closeLottery) && (c.closeLottery = false);
  1526. }
  1527.  
  1528. return c;
  1529. },
  1530. checkVersion = () => {
  1531. config = getConfig();
  1532. if (!config || !config.moduleVersion || !divUpdateInfo) {
  1533. return;
  1534. }
  1535. if (0 < compareVersion(config.moduleVersion, version)) {
  1536. divUpdateInfo.innerHTML = `<span class="update-info-text">有新版本,刷新网页进行更新</span>`;
  1537. let dom = document.getElementById('otherContainer');
  1538. if (dom) {
  1539. dom.style.fontSize = '18px';
  1540. dom.style.textAlign = 'center';
  1541. dom.appendChild(divUpdateInfo.cloneNode(true));
  1542. }
  1543. }
  1544. },
  1545. loadData = () => {
  1546. let obj = getGmValue(roomId, null),
  1547. key = roomId;
  1548. if (obj) {
  1549. if (obj.usePublic && baseInfo.default) {
  1550. let ps = getGmValue(baseInfo.default, null);
  1551. if (ps) {
  1552. obj.data1.values = ps.data1 ? ps.data1.values : obj.data1.values;
  1553. obj.data2.values = ps.data2 ? ps.data2.values : obj.data2.values;
  1554. obj.data3.values = ps.data3 ? ps.data3.values : obj.data3.values;
  1555. obj.data4.values = ps.data4 ? ps.data4.values : obj.data4.values;
  1556. obj.data5.values = ps.data5 ? ps.data5.values : obj.data5.values;
  1557. }
  1558. }
  1559. if (source.version === obj.version) {
  1560. source = {...source, ...obj};
  1561. }
  1562. else if (obj.version === 2) {
  1563. source.data1 = obj.data1;
  1564. source.data2 = obj.data2;
  1565. source.data3 = obj.data3;
  1566. source.data4 = obj.data4;
  1567. source.data5 = obj.data5;
  1568. setGmValue(key, source);
  1569. }
  1570. else if (obj.version === 4) {
  1571. source = {...source, ...obj};
  1572. source.version = 5;
  1573. source.like && (delete source.like);
  1574. if (obj.interval) {
  1575. source.sendMsgInterval = obj.interval;
  1576. delete source.interval;
  1577. }
  1578. if (obj.random) {
  1579. source.sendMsgRandom = obj.random;
  1580. delete source.random;
  1581. }
  1582.  
  1583. setGmValue(key, source);
  1584. }
  1585. else if (obj.version === 5) {
  1586. source = {...source, ...obj};
  1587. source.version = 6;
  1588. if (obj.likeRandom) {
  1589. source.like.likeRandom = obj.likeRandom;
  1590. delete source.likeRandom;
  1591. }
  1592. if (obj.likeInterval) {
  1593. source.like.likeInterval = obj.likeInterval;
  1594. delete source.likeInterval;
  1595. }
  1596. if (obj.clickLikeInterval) {
  1597. source.like.clickLikeInterval = obj.clickLikeInterval;
  1598. delete source.clickLikeInterval;
  1599. }
  1600.  
  1601. setGmValue(key, source);
  1602. }
  1603. else {
  1604. source.data1.values = obj.data1 ? obj.data1.values : source.data1.values;
  1605. source.data2.values = obj.data2 ? obj.data2.values : source.data2.values;
  1606. source.data3.values = obj.data3 ? obj.data3.values : source.data3.values;
  1607. source.data4.values = obj.data4 ? obj.data4.values : source.data4.values;
  1608. source.data5.values = obj.data5 ? obj.data5.values : source.data5.values;
  1609. setGmValue(key, source);
  1610. }
  1611. }
  1612. config = getConfig();
  1613. setDmSourceInput(source);
  1614. setOperationSetting();
  1615. initData();
  1616. },
  1617. initSettingPanel = (div, isLogin) => {
  1618. let settingPanel = document.getElementById('danmu-setting-panel');
  1619. if (div && !settingPanel) {
  1620. // console.log('===> 进行面板初始化');
  1621. buildPanel();
  1622. if (isLogin) {
  1623. let divBtn = document.getElementsByClassName('right-actions border-box')[0]; // 登录的发送按钮
  1624. if (divBtn) {
  1625. divBtn.style.alignSelf = 'flex-start';
  1626. divBtn.style.marginTop = '0px';
  1627. div.appendChild(btnStartLogin());
  1628. div.insertBefore(btnSetting(), divBtn);
  1629. }
  1630. }
  1631. else {
  1632. let btnSend = document.getElementsByClassName('bl-button--primary bl-button--small')[0];
  1633. if (btnSend) {
  1634. btnStart(btnSend);
  1635. let funcDiv = document.createElement('div');
  1636. funcDiv.style.position = 'absolute';
  1637. funcDiv.appendChild(dmButtonSend);
  1638. funcDiv.appendChild(btnSetting());
  1639. div.appendChild(funcDiv);
  1640. // bgcolor = window.getComputedStyle(btnSend).getPropertyValue('background-color');
  1641. // dmButtonSend.style.setProperty('background', bgcolor);
  1642. // dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  1643. } else {
  1644. console.warn('===> 发送按钮丢失');
  1645. return false;
  1646. }
  1647. }
  1648. loadData();
  1649. // console.log('===> 面板初始化完成');
  1650. }
  1651.  
  1652. return true;
  1653. },
  1654. main = (div, isLogin) => {
  1655. waiters[waiters.length] = workerTimer.setInterval(() => {
  1656. if (initSettingPanel(div, isLogin)) {
  1657. clearWaiters();
  1658. } else {
  1659. --waitCount;
  1660. if (0 >= waitCount) {
  1661. clearWaiters();
  1662. console.log('===> 创建面板失败,停止初始化');
  1663. }
  1664. }
  1665. }, 1.5e3);
  1666. },
  1667. PluginBtn = (clazz, isLogin) => {
  1668. let div = document.getElementsByClassName(clazz)[0];
  1669. if (div) {
  1670. main(div, isLogin);
  1671. } else {
  1672. let count = 0;
  1673. divSendBtnTimer = workerTimer.setInterval(() => {
  1674. div = document.getElementsByClassName(clazz)[0];
  1675. if (div) {
  1676. workerTimer.clearInterval(divSendBtnTimer);
  1677. main(div, isLogin);
  1678. } else if (count++ >= 10) {
  1679. workerTimer.clearInterval(divSendBtnTimer);
  1680. // console.log(`===> 页面【${window.location.href}】没有定位位置`);
  1681. }
  1682. }, 1e3);
  1683. }
  1684. },
  1685. PluginLogout = () => PluginBtn('bottom-actions p-relative', false),
  1686. PluginLogin = () => PluginBtn('chat-input-ctnr-new p-relative default-height', true),
  1687. PluginLottery = () => {
  1688. let btn = document.getElementsByClassName('particitation-btn')[0];
  1689. if (btn) {
  1690. lottery(btn);
  1691. } else {
  1692. let btnLotteryTimer = workerTimer.setTimeout(() => {
  1693. workerTimer.clearTimeout(btnLotteryTimer);
  1694. btn = document.getElementsByClassName('particitation-btn')[0];
  1695. if (btn) {
  1696. lottery(btn);
  1697. }
  1698. }, 2e3);
  1699. }
  1700. },
  1701. PluginListPlus = () => {
  1702. let listTimer = workerTimer.setTimeout(() => {
  1703. workerTimer.clearTimeout(listTimer);
  1704. let obsConfig = {childList: true},
  1705. tags = ['all__card-list-ctnr', 'all__special-area-recommend-list-ctnr'];
  1706. tags.forEach(x => {
  1707. let dom = document.getElementsByClassName(x)[0];
  1708. if (!dom) return;
  1709. Array.prototype.forEach.call(dom.children, y => {
  1710. if (/^index_/i.test(y.className)) {
  1711. listPlus(y.children);
  1712. let obs = new MutationObserver(mrs => {
  1713. if (!mrs || 0 >= mrs.length) return;
  1714. Array.prototype.forEach.call(mrs, z => listPlus(z.addedNodes));
  1715. });
  1716. obs.observe(y, obsConfig);
  1717. }
  1718. });
  1719. });
  1720. }, 0.5e3);
  1721. },
  1722. debug = () => {debugger;},
  1723. runStart = () => {
  1724. PluginLottery();
  1725. PluginListPlus();
  1726. PluginLogout();
  1727. PluginLogin();
  1728. };
  1729.  
  1730. initCss();
  1731. // initScript();
  1732. window.debug = debug;
  1733. window.runStart = runStart;
  1734. window.arrayInfo = arrayInfo;
  1735. window.setGmNotice = setGmNotice;
  1736. window.setGmGetValue = setGmGetValue;
  1737. window.setGmSetValue = setGmSetValue;
  1738. window.setGmDelValue = setGmDelValue;
  1739. window.setBaseInfo = setBaseInfo;
  1740. window.checkVersion = checkVersion;
  1741. })();