b-live-random-send-test

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

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

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

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