b-live-random-send-test

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

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

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

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