b-live-random-send-test

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

目前为 2023-10-21 提交的版本。查看 最新版本

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

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