b-live-random-send-test

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

目前為 2023-12-13 提交的版本,檢視 最新版本

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