b-live-random-send-test

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

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

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

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