b-live-random-send-test

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

目前為 2024-09-06 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/447936/1442522/b-live-random-send-test.js

  1. // ==UserScript==
  2. // @version 1.7.0
  3. // ==/UserScript==
  4.  
  5.  
  6.  
  7. (function () {
  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, showLiveAreaCheckbox,
  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, btnStartText,
  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.7.0', upodateInfo = '适配新版页面UI', 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:#095ca2;font-size:20px;vertical-align:middle;font-weight:700}.danmu-second-input{width:70px;height:20px;margin:0px 3px;border:0px;border-radius:3px;font-size:18px}.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. if (!isNull(dmTextArea.value)) {
  185. console.log(`===> 有内容正在编辑,跳过该次发送任务`);
  186. return;
  187. }
  188.  
  189. let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
  190. if (!btnSend) {
  191. alert('找不到发送按钮,请尝试刷新页面');
  192. return;
  193. }
  194. dmTextArea.value = msg;
  195. dmTextArea.dispatchEvent(new Event('input', { "bubbles": true, "cancelable": true }));
  196. btnSend.click();
  197. lastSent = getCurrentTimestamp();
  198. // ++count;
  199. // console.log('===> ' + new Date().toLocaleString() + ' 弹幕发送成功 ' + count + ' 次,第【' + index + '】条数据 === ' + msg);
  200. },
  201. randomSort = arr => {
  202. for (let i = 0; i < arr.length; i++) {
  203. const rdIndex = Math.floor(Math.random() * arr.length);
  204. const temp = arr[i];
  205. arr[i] = arr[rdIndex];
  206. arr[rdIndex] = temp;
  207. }
  208.  
  209. return arr;
  210. },
  211. clearWaiters = () => {
  212. for (let i = 0; i < waiters.length; i++) {
  213. workerTimer.clearInterval(waiters[i]);
  214. waiters[i] = null;
  215. }
  216.  
  217. waiters = [];
  218. },
  219. signInFunc = () => {
  220. if (signInCheckbox.checked) {
  221. if (!signInTimer) {
  222. let defaultText = isNull(pdata.signText) ? pdata.signText : '打卡';
  223. let timestamp = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()).getTime() - getCurrentTimestamp();
  224. console.log('===> 设置凌晨打卡定时器【' + timestamp + '】');
  225. signInput.value = isNull(config.signInText) ? defaultText : config.signInText;
  226. signInTimer = workerTimer.setTimeout(() => {
  227. send(isNull(signInput.value) ? defaultText : signInput.value, 0);
  228. console.log('===> 设置下一次打卡');
  229. workerTimer.clearTimeout(signInTimer);
  230. signInTimer = null;
  231. signInFunc();
  232. }, timestamp);
  233. }
  234. } else if (signInTimer) {
  235. console.log('===> 关闭自动打卡功能');
  236. workerTimer.clearTimeout(signInTimer);
  237. signInTimer = null;
  238. }
  239. },
  240. setSource = obj => {
  241. dataText1.value = obj.data1.values.length ? obj.data1.values.join('|') : [];
  242. dataText2.value = obj.data2.values.length ? obj.data2.values.join('|') : [];
  243. dataText3.value = obj.data3.values.length ? obj.data3.values.join('|') : [];
  244. dataText4.value = obj.data4.values.length ? obj.data4.values.join('|') : [];
  245. dataText5.value = obj.data5.values.length ? obj.data5.values.join('|') : [];
  246. },
  247. runCheckbox = () => {
  248. usePublicFunc();
  249. hideFooterFunc();
  250. hideGiftControlFunc();
  251. hideLoginGuideFunc();
  252. hideHarunaFunc();
  253. hideShopFunc();
  254. hidePrivacyFunc();
  255. hideRoomStatusFunc();
  256. hideBusinessFunc();
  257. hideRankListFunc();
  258. noSleepFunc();
  259. signInFunc();
  260. lotteryFunc();
  261. hesitationFunc();
  262. closeLotteryFunc();
  263. autoLikeFunc();
  264. // autoPlay();
  265. hideRoomFeedFunc();
  266. hideRoomInfoFunc();
  267. hideNoticeFunc();
  268. showLiveAreaFunc();
  269. let hideTimeout = workerTimer.setTimeout(() => {
  270. workerTimer.clearTimeout(hideTimeout);
  271. hideRoomFeedFunc();
  272. hideRoomInfoFunc();
  273. hideNoticeFunc();
  274. showLiveAreaFunc();
  275. }, 1e3);
  276. },
  277. setOperationSetting = () => {
  278. setPublicCheckbox.checked = false;
  279. rdCheckbox.checked = source.random;
  280. autoLikeCheckbox.checked = source.like;
  281. usePublicCheckbox.checked = source.usePublic;
  282. group1Checkbox.checked = source.data1.available;
  283. group2Checkbox.checked = source.data2.available;
  284. group3Checkbox.checked = source.data3.available;
  285. group4Checkbox.checked = source.data4.available;
  286. group5Checkbox.checked = source.data5.available;
  287.  
  288. signInCheckbox.checked = config.autoSignIn;
  289. noSleepCheckbox.checked = config.noSleep;
  290. hideLoginGuideCheckbox.checked = config.hideLoginGuide;
  291. hideHarunaCheckbox.checked = config.hideHaruna;
  292. hideShopCheckbox.checked = config.hideShop;
  293. hideGiftControlCheckbox.checked = config.hideGift;
  294. hideRoomFeedCheckbox.checked = config.hideRoomFeed;
  295. hideRoomInfoCheckbox.checked = config.hideRoomInfo;
  296. hideNoticeCheckbox.checked = config.hideNotice;
  297. hideFooterCheckbox.checked = config.hideFooter;
  298. lotteryCheckbox.checked = config.lottery;
  299. hesitationCheckbox.checked = config.hesitation;
  300. closeLotteryCheckbox.checked = config.closeLottery;
  301. hidePrivacyCheckbox.checked = config.noPrivacy;
  302. hideRoomStatusCheckbox.checked = config.hideWatermark;
  303. hideBusinessCheckbox.checked = config.hideBusiness;
  304. hideRankListCheckbox.checked = config.hideRankList;
  305. showLiveAreaCheckbox.checked = config.showLiveArea;
  306. runCheckbox();
  307. },
  308. openSetting = () => divSetting.style.display = 'block',
  309. closeSetting = () => {
  310. setOperationSetting();
  311. divSetting.style.display = 'none';
  312. },
  313. initData = () => {
  314. if (source.data1.values.length <= 0
  315. && source.data2.values.length <= 0
  316. && source.data3.values.length <= 0
  317. && source.data4.values.length <= 0
  318. && source.data5.values.length <= 0) {
  319. return data ? data : [];
  320. }
  321.  
  322. let result = [];
  323. result = source.data1.available ? result.concat(source.data1.values) : result;
  324. result = source.data2.available ? result.concat(source.data2.values) : result;
  325. result = source.data3.available ? result.concat(source.data3.values) : result;
  326. result = source.data4.available ? result.concat(source.data4.values) : result;
  327. result = source.data5.available ? result.concat(source.data5.values) : result;
  328. data = result;
  329. rdCheckbox.checked ? data = randomSort(result) : arrayIndex = 0;
  330. },
  331. flashMsg = (txt, back, color) => {
  332. spanApplyMsg.textContent = txt;
  333. spanApplyMsg.style.display = 'block';
  334. if (color) {
  335. spanApplyMsg.style.color = color;
  336. }
  337. else {
  338. spanApplyMsg.style.color = '#128712';
  339. }
  340.  
  341. let hideTipTimer = workerTimer.setTimeout(() => {
  342. workerTimer.clearTimeout(hideTipTimer);
  343. spanApplyMsg.style.display = 'none';
  344. spanApplyMsg.textContent = '';
  345. if (back) {
  346. divSetting.style.display = 'none';
  347. }
  348. }, 1.5e3);
  349. },
  350. save = () => {
  351. if (!pdata || isNull(pdata.defaultKey) || isNull(pdata.configKey)) {
  352. flashMsg('保存失败', false, 'red');
  353. return;
  354. }
  355. if (pdata.configKey) {
  356. config.autoSignIn = signInCheckbox.checked;
  357. config.signInText = signInput.value;
  358. config.noSleep = noSleepCheckbox.checked;
  359. config.hideLoginGuide = hideLoginGuideCheckbox.checked;
  360. config.hideHaruna = hideHarunaCheckbox.checked;
  361. config.hideShop = hideShopCheckbox.checked;
  362. config.hideGift = hideGiftControlCheckbox.checked;
  363. config.hideRoomFeed = hideRoomFeedCheckbox.checked;
  364. config.hideRoomInfo = hideRoomInfoCheckbox.checked;
  365. config.hideNotice = hideNoticeCheckbox.checked;
  366. config.hideFooter = hideFooterCheckbox.checked;
  367. config.lottery = lotteryCheckbox.checked;
  368. window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
  369. config.hesitation = hesitationCheckbox.checked;
  370. window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
  371. config.hesitationExpiry = hesitateInput.value;
  372. window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
  373. config.closeLottery = closeLotteryCheckbox.checked;
  374. window.localStorage.setItem(closeLotteryChecked, config.closeLottery);
  375. config.noPrivacy = hidePrivacyCheckbox.checked;
  376. config.hideWatermark = hideRoomStatusCheckbox.checked;
  377. config.hideBusiness = hideBusinessCheckbox.checked;
  378. config.hideRankList = hideRankListCheckbox.checked;
  379. config.showLiveArea = showLiveAreaCheckbox.checked;
  380. setGmValue(pdata.configKey, config);
  381. }
  382.  
  383. let v1 = isNull(dataText1.value) ? [] : dataText1.value.split('|'),
  384. v2 = isNull(dataText2.value) ? [] : dataText2.value.split('|'),
  385. v3 = isNull(dataText3.value) ? [] : dataText3.value.split('|'),
  386. v4 = isNull(dataText4.value) ? [] : dataText4.value.split('|'),
  387. v5 = isNull(dataText5.value) ? [] : dataText5.value.split('|');
  388. source.random = rdCheckbox.checked;
  389. source.like = autoLikeCheckbox.checked;
  390. source.usePublic = usePublicCheckbox.checked;
  391. source.data1.available = group1Checkbox.checked;
  392. source.data2.available = group2Checkbox.checked;
  393. source.data3.available = group3Checkbox.checked;
  394. source.data4.available = group4Checkbox.checked;
  395. source.data5.available = group5Checkbox.checked;
  396. if (!usePublicCheckbox.checked) {
  397. source.data1.values = v1;
  398. source.data2.values = v2;
  399. source.data3.values = v3;
  400. source.data4.values = v4;
  401. source.data5.values = v5;
  402. }
  403. setGmValue(roomId, source);
  404. if (setPublicCheckbox.checked) {
  405. let ps = {data1:{},data2:{},data3:{},data4:{},data5:{}};
  406. ps.data1.values = v1;
  407. ps.data2.values = v2;
  408. ps.data3.values = v3;
  409. ps.data4.values = v4;
  410. ps.data5.values = v5;
  411. setGmValue(pdata.defaultKey, ps);
  412. }
  413. if (usePublicCheckbox.checked) {
  414. source.data1.values = v1;
  415. source.data2.values = v2;
  416. source.data3.values = v3;
  417. source.data4.values = v4;
  418. source.data5.values = v5;
  419. }
  420. initData();
  421. flashMsg('设置成功', true);
  422. },
  423. cleanCache = () => {
  424. if (pdata.configKey && config) {
  425. config.script = '';
  426. config.lastUpdate = '清除缓存';
  427. setGmValue(pdata.configKey, config);
  428. flashMsg('清除成功');
  429. } else {
  430. console.warn('元数据丢失');
  431. flashMsg('操作失败', false, 'red');
  432. }
  433. },
  434. danmu = () => {
  435. if (data.length < 1) {
  436. // gmNotice({
  437. // text: '请任意在一个分组里输入一条弹幕',
  438. // title: '没有弹幕数据,请先设置',
  439. // image: icoUrl,
  440. // highlight: true,
  441. // timeout: noticeTimeout
  442. // });
  443. alert('请先设置弹幕');
  444. return false;
  445. }
  446. if (rdCheckbox.checked) {
  447. arrayIndex = Math.floor((Math.random() * data.length));
  448. }
  449.  
  450. send(data[arrayIndex], arrayIndex);
  451. ++arrayIndex;
  452. if (arrayIndex >= data.length) {
  453. arrayIndex = 0;
  454. }
  455.  
  456. return true;
  457. },
  458. offOrOn = () => {
  459. let timeout = 0;
  460. if (sendTimer) {
  461. workerTimer.clearInterval(sendTimer);
  462. sendTimer = null;
  463. dmButtonSend.style.background = isNull(bgcolor) ? bgcolor_default : bgcolor;
  464. dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  465. dmInput.removeAttribute("disabled");
  466. btnStartText.textContent = '开始';
  467. } else {
  468. timeout = (isNull(dmInput.value) ? default_timeout : dmInput.value) * 1e3;
  469. if (!danmu()) {
  470. return;
  471. }
  472.  
  473. sendTimer = workerTimer.setInterval(danmu, timeout);
  474. dmButtonSend.style.background = 'rgba(255,0,0,1)';
  475. dmButtonSend.style.setProperty('--color', 'rgba(255,0,0,0.8)');
  476. dmInput.setAttribute('disabled', 'disabled');
  477. btnStartText.textContent = '停止';
  478. }
  479. },
  480. createSwitch = (id, txt, title, func, container, indent, width, hidden, rear, disabled) => {
  481. let checkbox = document.createElement('input');
  482. checkbox.type = 'checkbox';
  483. checkbox.id = id;
  484. checkbox.checked = false;
  485. if (func && !disabled) {
  486. checkbox.addEventListener('click', func);
  487. }
  488.  
  489. let lblCheckbox = document.createElement('label');
  490. lblCheckbox.setAttribute('for', id);
  491. lblCheckbox.classList.add('switch-check-label');
  492.  
  493. let descSpan = document.createElement('span');
  494. descSpan.textContent = txt;
  495. descSpan.title = title;
  496. descSpan.classList.add('danmu-random-switch-button-title');
  497. if (disabled) {
  498. checkbox.disabled = true;
  499. checkbox.classList.add('disabled');
  500. lblCheckbox.classList.add('disabled');
  501. descSpan.classList.add('disabled');
  502. }
  503.  
  504. let divCheckbox = document.createElement('div');
  505. divCheckbox.id = id + 'Div';
  506. divCheckbox.classList.add('switch-check');
  507. divCheckbox.classList.add('switch-check-group');
  508. divCheckbox.appendChild(checkbox);
  509. divCheckbox.appendChild(lblCheckbox);
  510. divCheckbox.appendChild(descSpan);
  511. if (!isNull(indent)) {
  512. divCheckbox.style.marginLeft = indent;
  513. }
  514. if (!isNull(width)) {
  515. divCheckbox.style.width = width;
  516. }
  517. if (hidden) {
  518. divCheckbox.style.setProperty('display', 'none');
  519. }
  520. if (rear) {
  521. divCheckbox.appendChild(rear);
  522. }
  523.  
  524. container.appendChild(divCheckbox);
  525. return checkbox;
  526. },
  527. buildPanel = () => {
  528. /* ----------------------------------------- head ----------------------------------------- */
  529. let divSettingTitle = document.createElement('div');
  530. divSettingTitle.textContent = '弹幕设置';
  531. divSettingTitle.classList.add('danmu-random-setting-title');
  532.  
  533. let divSub = document.createElement('div');
  534. divSub.textContent = version;
  535. divSub.classList.add('danmu-random-setting-title-sub');
  536. divSettingTitle.appendChild(divSub);
  537.  
  538. let divTip = document.createElement('div');
  539. divTip.classList.add('danmu-random-setting-tips');
  540. divTip.innerHTML = '任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';
  541.  
  542. divUpdateInfo = document.createElement('div');
  543. divUpdateInfo.classList.add('module-update-info');
  544. divUpdateInfo.innerHTML = `<span class="update-info-text">更新提示:</span><span class="update-info-text" style="color:#0b81cc;">${upodateInfo}</span>`;
  545. /* ----------------------------------------- head ----------------------------------------- */
  546.  
  547. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  548. let divText1 = document.createElement('div');
  549. divText1.textContent = '分组 1 :';
  550. divText1.classList.add('danmu-group-title');
  551.  
  552. group1Checkbox = document.createElement('input');
  553. group1Checkbox.type = 'checkbox';
  554. group1Checkbox.id = 'group1Checkbox';
  555. group1Checkbox.checked = true;
  556.  
  557. let lblGroup1Checkbox = document.createElement('label');
  558. lblGroup1Checkbox.setAttribute('for', 'group1Checkbox');
  559. lblGroup1Checkbox.classList.add('switch-check-label');
  560.  
  561. let divGroup1Checkbox = document.createElement('div');
  562. divGroup1Checkbox.classList.add('switch-check');
  563. divGroup1Checkbox.appendChild(group1Checkbox);
  564. divGroup1Checkbox.appendChild(lblGroup1Checkbox);
  565.  
  566. dataText1 = document.createElement('textarea');
  567. dataText1.classList.add('danmu-group-textarea');
  568. dataText1.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  569. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  570.  
  571. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  572. let divText2 = document.createElement('div');
  573. divText2.textContent = '分组 2 :';
  574. divText2.classList.add('danmu-group-title');
  575.  
  576. group2Checkbox = document.createElement('input');
  577. group2Checkbox.type = 'checkbox';
  578. group2Checkbox.id = 'group2Checkbox';
  579. group2Checkbox.checked = true;
  580.  
  581. let lblGroup2Checkbox = document.createElement('label');
  582. lblGroup2Checkbox.setAttribute('for', 'group2Checkbox');
  583. lblGroup2Checkbox.classList.add('switch-check-label');
  584.  
  585. let divGroup2Checkbox = document.createElement('div');
  586. divGroup2Checkbox.classList.add('switch-check');
  587. divGroup2Checkbox.appendChild(group2Checkbox);
  588. divGroup2Checkbox.appendChild(lblGroup2Checkbox);
  589.  
  590. dataText2 = document.createElement('textarea');
  591. dataText2.classList.add('danmu-group-textarea');
  592. dataText2.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  593. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  594.  
  595. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  596. let divText3 = document.createElement('div');
  597. divText3.textContent = '分组 3 :';
  598. divText3.classList.add('danmu-group-title');
  599.  
  600. group3Checkbox = document.createElement('input');
  601. group3Checkbox.type = 'checkbox';
  602. group3Checkbox.id = 'group3Checkbox';
  603. group3Checkbox.checked = true;
  604.  
  605. let lblGroup3Checkbox = document.createElement('label');
  606. lblGroup3Checkbox.setAttribute('for', 'group3Checkbox');
  607. lblGroup3Checkbox.classList.add('switch-check-label');
  608.  
  609. let divGroup3Checkbox = document.createElement('div');
  610. divGroup3Checkbox.classList.add('switch-check');
  611. divGroup3Checkbox.appendChild(group3Checkbox);
  612. divGroup3Checkbox.appendChild(lblGroup3Checkbox);
  613.  
  614. dataText3 = document.createElement('textarea');
  615. dataText3.classList.add('danmu-group-textarea');
  616. dataText3.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  617. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  618.  
  619. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  620. let divText4 = document.createElement('div');
  621. divText4.textContent = '分组 4 :';
  622. divText4.classList.add('danmu-group-title');
  623.  
  624. group4Checkbox = document.createElement('input');
  625. group4Checkbox.type = 'checkbox';
  626. group4Checkbox.id = 'group4Checkbox';
  627. group4Checkbox.checked = true;
  628.  
  629. let lblGroup4Checkbox = document.createElement('label');
  630. lblGroup4Checkbox.setAttribute('for', 'group4Checkbox');
  631. lblGroup4Checkbox.classList.add('switch-check-label');
  632.  
  633. let divGroup4Checkbox = document.createElement('div');
  634. divGroup4Checkbox.classList.add('switch-check');
  635. divGroup4Checkbox.appendChild(group4Checkbox);
  636. divGroup4Checkbox.appendChild(lblGroup4Checkbox);
  637.  
  638. dataText4 = document.createElement('textarea');
  639. dataText4.classList.add('danmu-group-textarea');
  640. dataText4.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  641. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  642.  
  643. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  644. let divText5 = document.createElement('div');
  645. divText5.textContent = '分组 5 :';
  646. divText5.classList.add('danmu-group-title');
  647.  
  648. group5Checkbox = document.createElement('input');
  649. group5Checkbox.type = 'checkbox';
  650. group5Checkbox.id = 'group5Checkbox';
  651. group5Checkbox.checked = true;
  652.  
  653. let lblGroup5Checkbox = document.createElement('label');
  654. lblGroup5Checkbox.setAttribute('for', 'group5Checkbox');
  655. lblGroup5Checkbox.classList.add('switch-check-label');
  656.  
  657. let divGroup5Checkbox = document.createElement('div');
  658. divGroup5Checkbox.classList.add('switch-check');
  659. divGroup5Checkbox.appendChild(group5Checkbox);
  660. divGroup5Checkbox.appendChild(lblGroup5Checkbox);
  661.  
  662. dataText5 = document.createElement('textarea');
  663. dataText5.classList.add('danmu-group-textarea');
  664. dataText5.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  665. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  666.  
  667.  
  668. /* ----------------------------------------- send interval ----------------------------------------- */
  669. beforeSpan = document.createElement('span');
  670. beforeSpan.textContent = '设置弹幕每';
  671. beforeSpan.classList.add('danmu-text-span');
  672. beforeSpan.style.marginLeft = '4px';
  673.  
  674. dmInput = document.createElement('input');
  675. dmInput.value = default_timeout;
  676. dmInput.classList.add('danmu-second-input');
  677. dmInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  678.  
  679. afterSpan = document.createElement('span');
  680. afterSpan.textContent = '秒发送一次';
  681. afterSpan.classList.add('danmu-text-span');
  682. afterSpan.style.marginRight = '4px';
  683.  
  684. let divSendInterval = document.createElement('div');
  685. divSendInterval.appendChild(beforeSpan);
  686. divSendInterval.appendChild(dmInput);
  687. divSendInterval.appendChild(afterSpan);
  688. /* ----------------------------------------- send interval ----------------------------------------- */
  689.  
  690.  
  691. /* ----------------------------------------- different room setting ----------------------------------------- */
  692. let divRoomSetting = document.createElement('div');
  693. divRoomSetting.appendChild(divText1);
  694. divRoomSetting.appendChild(divGroup1Checkbox);
  695. divRoomSetting.appendChild(dataText1);
  696. divRoomSetting.appendChild(divText2);
  697. divRoomSetting.appendChild(divGroup2Checkbox);
  698. divRoomSetting.appendChild(dataText2);
  699. divRoomSetting.appendChild(divText3);
  700. divRoomSetting.appendChild(divGroup3Checkbox);
  701. divRoomSetting.appendChild(dataText3);
  702. divRoomSetting.appendChild(divText4);
  703. divRoomSetting.appendChild(divGroup4Checkbox);
  704. divRoomSetting.appendChild(dataText4);
  705. divRoomSetting.appendChild(divText5);
  706. divRoomSetting.appendChild(divGroup5Checkbox);
  707. divRoomSetting.appendChild(dataText5);
  708. divRoomSetting.appendChild(divSendInterval);
  709. rdCheckbox = createSwitch('rdCheckbox', '随机从上面的弹幕中选出一条发送', '将合并所有分组数据,从中随机选出一条发送', null, divRoomSetting);
  710. usePublicCheckbox = createSwitch('usePublicCheckbox', '使用共用弹幕源', '使用设置为共用弹幕作为弹幕源', usePublicFunc, divRoomSetting);
  711. autoLikeCheckbox = createSwitch('autoLikeCheckbox', '自动点赞该直播间', '每15秒内随机一个时间点点赞一次直播间(点赞1000次大概需要4小时)', autoLikeFunc, divRoomSetting, null, null, null, null);
  712.  
  713. let operationDescription = document.createElement('div');
  714. operationDescription.textContent = '以上设置对应各个直播间独立保存,无需刷新';
  715. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  716. operationDescription.classList.add('global-setting-tip');
  717. operationDescription.classList.add('switch-check-group');
  718. divRoomSetting.appendChild(operationDescription);
  719. /* ----------------------------------------- different room setting ----------------------------------------- */
  720.  
  721. /* ----------------------------------------- global setting ----------------------------------------- */
  722. let divGlobalSetting = document.createElement('div');
  723. divGlobalSetting.style.margin = '20px 0 10px';
  724.  
  725. operationDescription = document.createElement('div');
  726. operationDescription.textContent = '以下设置,需刷新其它直播间才能适用';
  727. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  728. operationDescription.classList.add('global-setting-tip');
  729. operationDescription.classList.add('switch-check-group');
  730. divGlobalSetting.appendChild(operationDescription);
  731.  
  732. signInput = document.createElement('input');
  733. signInput.id = 'signInputText';
  734. signInput.style.border = '0';
  735. signInput.style.width = '90px';
  736. signInput.setAttribute('placeholder', '输入打卡的文字');
  737.  
  738. hesitateInput = document.createElement('input');
  739. hesitateInput.style.border = '0';
  740. hesitateInput.style.width = '55px';
  741. hesitateInput.setAttribute('placeholder', '单位:秒');
  742. hesitateInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  743.  
  744. setPublicCheckbox = createSwitch('setPublicCheckbox', '设为共用弹幕源', '把这个直播间的弹幕共享给其它直播间使用,先后设置时,后面的会覆盖前面的设置', setPublicFunc, divGlobalSetting);
  745. signInCheckbox = createSwitch('signInCheckbox', '打卡弹幕(需登录):', '每日零点发送一条打卡弹幕', signInFunc, divGlobalSetting, null, null, false, signInput);
  746. lotteryCheckbox = createSwitch('lotteryCheckbox', '自动参与天选时刻抽奖(需登录)', '自动点击参与按钮,请确保已经登录了阿B账号', lotteryFunc, divGlobalSetting);
  747. hesitationCheckbox = createSwitch('hesitationCheckbox', '随机犹豫期:', '(尝试应对人机校验,不一定有效,随机的范围:(0, 填的数字])不立刻参与天选时刻,这期间可以手动处理,免得自动参加后后悔(时间单位:秒)', hesitationFunc, divGlobalSetting, '23px', '90%', true, hesitateInput);
  748. closeLotteryCheckbox = createSwitch('closeLotteryCheckbox', '关闭天选时刻', '关闭天选时刻弹窗', closeLotteryFunc, divGlobalSetting);
  749. hideGiftControlCheckbox = createSwitch('hideGiftControlCheckbox', '隐藏礼物栏', '隐藏播放器底部的礼物栏', hideGiftControlFunc, divGlobalSetting);
  750. noSleepCheckbox = createSwitch('noSleepCheckbox', '防止直播间休眠', '防止直播间页面一段时间没操作之后进入休眠', noSleepFunc, divGlobalSetting);
  751. hideLoginGuideCheckbox = createSwitch('hideLoginGuideCheckbox', '隐藏播放器底部登录提示', '隐藏未登录时播放器底部显示的登录提示', hideLoginGuideFunc, divGlobalSetting);
  752. hideHarunaCheckbox = createSwitch('hideHarunaCheckbox', '隐藏看板娘立绘', '隐藏直播间Haruna立绘', hideHarunaFunc, divGlobalSetting);
  753. hideShopCheckbox = createSwitch('hideShopCheckbox', '隐藏购物提示', '隐藏播放器左上角的商店购物提示', hideShopFunc, divGlobalSetting);
  754. hideRoomFeedCheckbox = createSwitch('hideRoomFeedCheckbox', '隐藏主播动态', '隐藏播放器底下主播的动态栏', hideRoomFeedFunc, divGlobalSetting);
  755. hideRoomInfoCheckbox = createSwitch('hideRoomInfoCheckbox', '隐藏主播荣耀、简介', '隐藏播放器底下主播的荣耀勋章和简介', hideRoomInfoFunc, divGlobalSetting);
  756. hideNoticeCheckbox = createSwitch('hideNoticeCheckbox', '隐藏主播公告', '隐藏弹幕列表底下主播的公告', hideNoticeFunc, divGlobalSetting);
  757. hideFooterCheckbox = createSwitch('hideFooterCheckbox', '隐藏直播间页脚', '隐藏直播间底部的网页页脚', hideFooterFunc, divGlobalSetting);
  758. hidePrivacyCheckbox = createSwitch('hidePrivacyCheckbox', '隐藏隐私提示对话框', '隐藏隐私提示登录的对话框,被打码的昵称不保证变回正常', hidePrivacyFunc, divGlobalSetting);
  759. hideRoomStatusCheckbox = createSwitch('hideRoomStatusCheckbox', '隐藏直播水印', '隐藏播放器左上角的直播水印', hideRoomStatusFunc, divGlobalSetting);
  760. hideBusinessCheckbox = createSwitch('hideBusinessCheckbox', '隐藏商业性互动', '隐藏全站广播、PK、连MIC、连视频等', hideBusinessFunc, divGlobalSetting);
  761. hideRankListCheckbox = createSwitch('hideRankListCheckbox', '隐藏滚动排行榜', '隐藏顶部的人气榜、航海榜、礼物星球等', hideRankListFunc, divGlobalSetting);
  762. showLiveAreaCheckbox = createSwitch('showLiveArea', '显示直播分区', '显示直播间所属的直播分区', showLiveAreaFunc, divGlobalSetting);
  763. /* ----------------------------------------- global setting ----------------------------------------- */
  764.  
  765. /* ----------------------------------------- operation msg ----------------------------------------- */
  766. spanApplyMsg = document.createElement('span');
  767. spanApplyMsg.classList.add('danmu-random-setting-success-text');
  768.  
  769. let divApplyMsg = document.createElement('div');
  770. divApplyMsg.classList.add('danmu-random-setting-success-tips');
  771. divApplyMsg.appendChild(spanApplyMsg);
  772. /* ----------------------------------------- operation msg ----------------------------------------- */
  773. /* ----------------------------------------- clean cache ----------------------------------------- */
  774. let cleanCacheBtn = document.createElement('button');
  775. cleanCacheBtn.textContent = '清除缓存';
  776. cleanCacheBtn.classList.add('clean-cache-btn');
  777. cleanCacheBtn.addEventListener('click', cleanCache);
  778. /* ----------------------------------------- clean cache ----------------------------------------- */
  779.  
  780. /* ----------------------------------------- save and close button ----------------------------------------- */
  781. let btnSave = document.createElement('i');
  782. btnSave.setAttribute('title', '保存');
  783. btnSave.style.padding = '5px';
  784. btnSave.classList.add('el-button');
  785. btnSave.classList.add('el-icon-check');
  786. btnSave.classList.add('is-circle');
  787. btnSave.addEventListener('click', save);
  788.  
  789. let btnClose = document.createElement('i');
  790. btnClose.setAttribute('title', '关闭');
  791. btnClose.style.padding = '5px';
  792. btnClose.classList.add('el-button');
  793. btnClose.classList.add('el-icon-close');
  794. btnClose.classList.add('is-circle');
  795. btnClose.addEventListener('click', closeSetting);
  796.  
  797. let divBtnSetting = document.createElement('div');
  798. divBtnSetting.classList.add('danmu-random-set-button-container');
  799. divBtnSetting.appendChild(cleanCacheBtn);
  800. divBtnSetting.appendChild(btnSave);
  801. divBtnSetting.appendChild(btnClose);
  802. /* ----------------------------------------- save and close button ----------------------------------------- */
  803.  
  804. /* ----------------------------------------- container ----------------------------------------- */
  805. let divBottomContainer = document.createElement('div');
  806. divBottomContainer.classList.add('danmu-random-setting-bottom');
  807. divBottomContainer.appendChild(divApplyMsg);
  808. divBottomContainer.appendChild(divBtnSetting);
  809.  
  810. let divOtherContainer = document.createElement('div');
  811. divOtherContainer.id = 'otherContainer';
  812.  
  813. let divContainer = document.createElement('div');
  814. divContainer.style.height = 'calc(98% - 30px - 25px)';
  815. divContainer.appendChild(divRoomSetting);
  816. divContainer.appendChild(divGlobalSetting);
  817. divContainer.appendChild(divOtherContainer);
  818. divContainer.appendChild(divBottomContainer);
  819. /* ----------------------------------------- container ----------------------------------------- */
  820.  
  821. divSetting = document.createElement('div');
  822. divSetting.id = 'danmu-setting-panel';
  823. divSetting.classList.add('danmu-random-setting-panel');
  824. divSetting.appendChild(divSettingTitle);
  825. divSetting.appendChild(divUpdateInfo);
  826. divSetting.appendChild(divTip);
  827. divSetting.appendChild(divContainer);
  828.  
  829. let asideAreaVm = document.getElementById('aside-area-vm');
  830. asideAreaVm.appendChild(divSetting);
  831.  
  832. /* ----------------------------------------- function ----------------------------------------- */
  833. /* ----------------------------------------- function ----------------------------------------- */
  834. },
  835. btnStart = btn => {
  836. const title = '开始定时发送';
  837. btnStartText = document.createElement('span');
  838. btnStartText.textContent = '开始';
  839. btnStartText.title = title;
  840. btnStartText.classList.add('txt');
  841.  
  842. dmButtonSend = document.createElement('button');
  843. dmButtonSend.title = title;
  844. //dmButtonSend.onclick = function() { alert('Hello world');}
  845. dmButtonSend.addEventListener('click', offOrOn);
  846. dmButtonSend.appendChild(btnStartText);
  847. if (btn) {
  848. copyAttributes(btn, dmButtonSend);
  849. const span = btn.querySelector('span');
  850. if (span) {
  851. copyAttributes(span, btnStartText);
  852. }
  853. }
  854. else {
  855. dmButtonSend.classList.add('danmu-btn');
  856. dmButtonSend.style.setProperty('--color', 'rgba(217,157,27,0.8)');
  857. }
  858. },
  859. btnSetting = () => {
  860. let iElement = document.createElement('i');
  861. iElement.classList.add('el-icon-setting');
  862.  
  863. let btn = document.createElement('button');
  864. btn.title = '定时设置';
  865. btn.style.margin = '0 5px';
  866. btn.classList.add('el-button');
  867. btn.classList.add('el-button--mini');
  868. btn.classList.add('is-circle');
  869. btn.addEventListener('click', openSetting);
  870. btn.appendChild(iElement);
  871. return btn;
  872. },
  873. copyAttributes = (oldNode, newNode) => {
  874. oldNode.attributes.forEach((item, index) => newNode.setAttribute(item.name, item.value));
  875. },
  876. setDisplay = (dom, property, important) => {
  877. if (important) {
  878. dom.style.setProperty('display', property, 'important');
  879. }
  880. else {
  881. dom.style.setProperty('display', property);
  882. }
  883. },
  884. blockDisplay = (dom, shwon) => {
  885. if (shwon) {
  886. setDisplay(dom, 'block', true);
  887. }
  888. else {
  889. dom.style.removeProperty('display');
  890. }
  891. },
  892. noneDisplay = (dom, hidden) => {
  893. if (hidden) {
  894. setDisplay(dom, 'none', true);
  895. }
  896. else {
  897. dom.style.removeProperty('display');
  898. }
  899. },
  900. removeAttributeFromChildren = (dom, attr) => {
  901. dom.removeAttribute(attr);
  902. if (0 < dom.children.length) {
  903. for (let i = 0; i < dom.children.length; i++) {
  904. removeAttributeFromChildren(dom.children[i], attr);
  905. }
  906. }
  907. },
  908. setAttributeToChildren = (dom, attr, val) => {
  909. dom.setAttribute(attr, val);
  910. if (0 < dom.children.length) {
  911. for (let i = 0; i < dom.children.length; i++) {
  912. setAttributeToChildren(dom.children[i], attr, val);
  913. }
  914. }
  915. },
  916. hideLoginGuideFunc = () => {
  917. let dom = document.getElementById('switch-login-guide-vm');
  918. if (dom) {
  919. noneDisplay(dom, hideLoginGuideCheckbox.checked);
  920. }
  921. },
  922. hideHarunaFunc = () => {
  923. let dom = document.getElementById('my-dear-haruna-vm');
  924. if (dom) {
  925. noneDisplay(dom, hideHarunaCheckbox.checked);
  926. }
  927. },
  928. hideShopFunc = () => {
  929. let dom = document.getElementById('shop-popover-vm');
  930. if (dom) {
  931. noneDisplay(dom, hideShopCheckbox.checked);
  932. }
  933. },
  934. hideGiftControlFunc = () => {
  935. let dom = document.getElementsByClassName('gift-control-section')[0];
  936. if (dom) {
  937. noneDisplay(dom, hideGiftControlCheckbox.checked);
  938. }
  939.  
  940. dom = document.getElementById('web-player__bottom-bar__container');
  941. if (dom) {
  942. noneDisplay(dom, hideGiftControlCheckbox.checked);
  943. }
  944.  
  945. dom = document.getElementsByTagName('video');
  946. for (let i = 0; i < dom.length; i++) {
  947. if (!dom[i]) {
  948. return;
  949. }
  950. if (hideGiftControlCheckbox.checked) {
  951. dom[i].style.setProperty('height', '100%');
  952. }
  953. else if (document.body.classList.contains('player-full-win') || document.body.classList.contains('fullscreen-fix')) {
  954. dom[i].style.setProperty('height', 'calc(100% - 114px)');
  955. }
  956. }
  957. },
  958. hideRoomFeedFunc = () => {
  959. let dom = document.getElementsByClassName('room-feed')[0];
  960. if (dom) {
  961. noneDisplay(dom, hideRoomFeedCheckbox.checked);
  962. }
  963. dom = document.getElementsByClassName('flip-view p-relative')[0];
  964. if (dom) {
  965. noneDisplay(dom, hideRoomFeedCheckbox.checked);
  966. }
  967. },
  968. hideRoomInfoFunc = () => {
  969. let dom = document.getElementsByClassName('room-info-ctnr')[0];
  970. if (dom) {
  971. noneDisplay(dom, hideRoomInfoCheckbox.checked);
  972. }
  973. },
  974. hideNoticeFunc = () => {
  975. let dom = document.getElementsByClassName('right-container')[0];
  976. if (dom) {
  977. dom.style.setProperty('min-height', 'auto');
  978. noneDisplay(dom, hideNoticeCheckbox.checked);
  979. }
  980. },
  981. hideFooterFunc = () => {
  982. let dom = document.getElementById('link-footer-vm');
  983. if (dom) {
  984. noneDisplay(dom, hideFooterCheckbox.checked);
  985. }
  986. },
  987. hidePrivacyFunc = () => {
  988. if (hidePrivacyCheckbox.checked) {
  989. let dom = document.createElement('style');
  990. dom.id = 'hidePrivacyDialog';
  991. dom.setAttribute('type', 'text/css');
  992. dom.innerHTML = '.privacy-dialog{display:none !important;}';
  993. document.head.appendChild(dom);
  994. }
  995. else {
  996. let dom = document.getElementById('hidePrivacyDialog');
  997. if (dom) {
  998. dom.remove();
  999. }
  1000. }
  1001. },
  1002. hideRoomStatusFunc = () => {
  1003. let dom = document.getElementsByClassName('web-player-icon-roomStatus')[0];
  1004. if (dom) {
  1005. noneDisplay(dom, hideRoomStatusCheckbox.checked);
  1006. }
  1007. },
  1008. hideBusinessFunc = () => {
  1009. let dom = document.getElementById('businessContainerElement');
  1010. if (dom) {
  1011. noneDisplay(dom, hideBusinessCheckbox.checked);
  1012. }
  1013. },
  1014. // 适配Bilibili直播自动追帧样式
  1015. adaptBililiveSeeker = () => {
  1016. let dom = document.getElementById('playback-rate-title');
  1017. if (dom) {
  1018. noneDisplay(dom, true);
  1019. dom.parentElement.style.removeProperty('padding-bottom');
  1020. }
  1021.  
  1022. dom = document.getElementById('playback-rate-username');
  1023. if (dom) {
  1024. dom.style.removeProperty('display');
  1025. }
  1026. },
  1027. hideRankListFunc = () => {
  1028. let lower = document.getElementsByClassName('lower-row')[0];
  1029. if (!lower) {
  1030. return;
  1031. }
  1032.  
  1033. let dom = lower.getElementsByClassName('right-ctnr')[0]
  1034. if (dom) {
  1035. noneDisplay(dom, hideRankListCheckbox.checked);
  1036. let t = workerTimer.setTimeout(() => {
  1037. workerTimer.clearTimeout(t);
  1038. t = null;
  1039. adaptBililiveSeeker();
  1040. }, 100);
  1041. }
  1042. },
  1043. showLiveAreaFunc = () => {
  1044. let dom = document.getElementsByClassName('live-area')[0];
  1045. if (dom) {
  1046. blockDisplay(dom, showLiveAreaCheckbox.checked);
  1047. adaptBililiveSeeker();
  1048. }
  1049. },
  1050. lotteryFunc = () => {
  1051. window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
  1052. let dom = document.getElementById('hesitationCheckboxDiv');
  1053. if (dom) {
  1054. noneDisplay(dom, !lotteryCheckbox.checked)
  1055. }
  1056. },
  1057. closeLotteryFunc = () => {
  1058. window.localStorage.setItem(closeLotteryChecked, closeLotteryCheckbox.checked);
  1059. },
  1060. hesitationFunc = () => {
  1061. window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
  1062. window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
  1063. },
  1064. setPublicFunc = () => {},
  1065. usePublicFunc = () => {
  1066. let key = usePublicCheckbox.checked ? pdata.defaultKey : roomId,
  1067. obj = getGmValue(key, null);
  1068. if (obj) {
  1069. setSource(obj);
  1070. }
  1071. },
  1072. clickLikeBtn = () => {
  1073. let dom = document.getElementsByClassName('like-btn')[0];
  1074. if (dom) {
  1075. dom.click();
  1076. // console.log(`===> 【${new Date().toLocaleString()}】点击一次点赞按钮`);
  1077. }
  1078. },
  1079. autoLikeFunc = () => {
  1080. if (autoLikeCheckbox.checked) {
  1081. if (autoLikeTimer) {
  1082. return;
  1083. }
  1084.  
  1085. clickLikeBtn();
  1086. // console.log(`===> 开启自动点赞功能【${new Date().toLocaleString()}】`);
  1087. autoLikeTimer = workerTimer.setInterval(() => {
  1088. let rdTimeout = Math.floor(Math.random() * 15000);
  1089. if (1000 > rdTimeout) {
  1090. // console.log(`===> 【${new Date().toLocaleString()}】立刻点击点赞按钮`);
  1091. clickLikeBtn();
  1092. }
  1093. else {
  1094. // console.log(`===> 【${new Date().toLocaleString()}】设置【${rdTimeout}】毫秒后点击点赞按钮`);
  1095. clickLikeBtnTimer = workerTimer.setTimeout(() => {
  1096. workerTimer.clearTimeout(clickLikeBtnTimer);
  1097. clickLikeBtnTimer = null;
  1098. clickLikeBtn();
  1099. }, rdTimeout);
  1100. }
  1101. }, 15e3);
  1102. }
  1103. else {
  1104. if (autoLikeTimer) {
  1105. workerTimer.clearInterval(autoLikeTimer);
  1106. autoLikeTimer = null;
  1107. // console.log(`===> 关闭自动点赞功能`);
  1108. }
  1109. if (clickLikeBtnTimer) {
  1110. workerTimer.clearTimeout(clickLikeBtnTimer);
  1111. clickLikeBtnTimer = null;
  1112. // console.log(`===> 关闭超时点击点赞按钮功能`);
  1113. }
  1114. }
  1115. },
  1116. clickPlay = () => {
  1117. // let dom = document.getElementsByClassName('_tip-btn_6f52f')[0];
  1118. // if (dom) {
  1119. // dom.click();
  1120. // }
  1121.  
  1122. // dom = document.getElementsByClassName('_tip-text_6f52f')[0];
  1123. // if (dom) {
  1124. // dom.click();
  1125. // }
  1126. },
  1127. autoPlay = () => {
  1128. let t = workerTimer.setTimeout(() => {
  1129. workerTimer.clearTimeout(t);
  1130. clickPlay();
  1131. t = workerTimer.setTimeout(() => {
  1132. workerTimer.clearTimeout(t);
  1133. t = null;
  1134. clickPlay();
  1135. }, 2e3);
  1136. }, 3e3);
  1137. },
  1138. noSleepFunc = () => {
  1139. if (noSleepCheckbox.checked) {
  1140. if (!noSleepTimer) {
  1141. console.log('===> 开启防休眠功能');
  1142. noSleepTimer = workerTimer.setInterval(() => {
  1143. noSleepTimeouter = workerTimer.setTimeout(() => {
  1144. workerTimer.clearTimeout(noSleepTimeouter);
  1145. document.body.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
  1146. }, Math.random() * 3e3);
  1147. }, 17e3);
  1148. }
  1149. } else {
  1150. console.log('===> 关闭防休眠功能');
  1151. if (noSleepTimer) {
  1152. workerTimer.clearInterval(noSleepTimer);
  1153. noSleepTimer = null;
  1154. }
  1155. if (noSleepTimeouter) {
  1156. workerTimer.clearTimeout(noSleepTimeouter);
  1157. noSleepTimeouter = null;
  1158. }
  1159. }
  1160. },
  1161. biliMiniClose = () => {
  1162. if (!miniCloseTimer) {
  1163. let miniCloseCount = 3;
  1164. miniCloseTimer = workerTimer.setInterval(() => {
  1165. let mini_close = document.getElementsByClassName('bili-mini-close')[0];
  1166. if (!mini_close) {
  1167. if (0 >= --miniCloseCount) {
  1168. workerTimer.clearInterval(miniCloseTimer);
  1169. miniCloseTimer = null;
  1170. }
  1171.  
  1172. return;
  1173. }
  1174.  
  1175. mini_close.click();
  1176. workerTimer.clearInterval(miniCloseTimer);
  1177. miniCloseTimer = null;
  1178. }, 10e3);
  1179. }
  1180. },
  1181. closeLottery = delay => {
  1182. let btnClose = document.getElementsByClassName('close-btn bg-contain')[0];
  1183. if (btnClose) {
  1184. if (isNull(delay)) {
  1185. btnClose.click();
  1186. } else {
  1187. closeLotteryTimer = workerTimer.setTimeout(() => {
  1188. workerTimer.clearTimeout(closeLotteryTimer);
  1189. btnClose.click();
  1190. }, delay * 1000);
  1191. }
  1192. }
  1193. },
  1194. lottery = btn => {
  1195. if (!btn) {
  1196. console.warn('===> 没有抽奖按钮DOM');
  1197. return;
  1198. }
  1199. if ('false' === window.localStorage.getItem(lotteryChecked)) {
  1200. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1201. console.log('===> 不参与天选时刻抽奖,关闭弹窗');
  1202. closeLottery();
  1203. }
  1204.  
  1205. return;
  1206. }
  1207. if ('true' === window.localStorage.getItem(hesitationChecked)) {
  1208. let expiry = window.localStorage.getItem(hesitationExpiry);
  1209. expiry = isNull(expiry) || 0 >= expiry ? 10e4 : expiry * 1000;
  1210. expiry = Math.ceil(Math.random() * expiry);
  1211. // console.log(`===> 【${new Date().toLocaleString()}】随机时间【${expiry}】`);
  1212. let lotteryTimer = workerTimer.setTimeout(() => {
  1213. workerTimer.clearTimeout(lotteryTimer);
  1214. console.log(`===> ${new Date().toLocaleString()}】犹豫期过后自动参加抽奖`);
  1215. btn.click();
  1216. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1217. console.log('===> 参加成功,延迟关闭弹窗');
  1218. closeLottery(1);
  1219. }
  1220. }, expiry);
  1221. } else {
  1222. console.log('===> 立刻自动参加抽奖');
  1223. btn.click();
  1224. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1225. console.log('===> 参加成功,延迟关闭弹窗');
  1226. closeLottery(1);
  1227. }
  1228. }
  1229. },
  1230. listPlus = nodes => {
  1231. if (!nodes || 0 >= nodes.length) return;
  1232. Array.prototype.forEach.call(nodes, y => {
  1233. let aNode = y.firstChild;
  1234. if (!aNode) return;
  1235. let a_d2 = aNode.children[1];
  1236. if (!a_d2) return;
  1237. let a_d2_d2 = a_d2.children[1];
  1238. if (!a_d2_d2) return;
  1239. let a_d2_d2_d2 = a_d2_d2.children[1];
  1240. if (!a_d2_d2_d2) return;
  1241. let a_d2_d2_d2_d1 = a_d2_d2_d2.children[0];
  1242. if (!a_d2_d2_d2_d1) return;
  1243. aNode.title = a_d2_d2_d2_d1.textContent;
  1244. let a_d2_d1 = a_d2.children[0];
  1245. if (a_d2_d1) {
  1246. let a_d2_d1_last = a_d2_d1.lastChild;
  1247. if (a_d2_d1_last && a_d2_d1_last.style.display && 'none' == a_d2_d1_last.style.display) {
  1248. a_d2_d1_last.remove();
  1249. }
  1250. }
  1251. });
  1252. },
  1253. getConfig = () => {
  1254. let c = {};
  1255. if (pdata.configKey) {
  1256. c = getGmValue(pdata.configKey, {});
  1257. if (isNull(c.lottery)) {
  1258. c.lottery = false;
  1259. }
  1260. if (isNull(c.closeLottery)) {
  1261. c.closeLottery = false;
  1262. }
  1263. if (isNull(c.hesitation)) {
  1264. c.hesitation = false;
  1265. }
  1266. }
  1267.  
  1268. return c;
  1269. },
  1270. checkVersion = () => {
  1271. config = getConfig();
  1272. if (!config || !config.moduleVersion || !divUpdateInfo) {
  1273. return;
  1274. }
  1275. if (0 < compareVersion(config.moduleVersion, version)) {
  1276. divUpdateInfo.innerHTML = `<span class="update-info-text">有新版本更新,请刷新网页</span>`;
  1277. let dom = document.getElementById('otherContainer');
  1278. if (dom) {
  1279. dom.appendChild(divUpdateInfo.cloneNode(true));
  1280. }
  1281. }
  1282. },
  1283. loadData = () => {
  1284. let obj = getGmValue(roomId, null),
  1285. key = roomId;
  1286. if (obj) {
  1287. if (obj.usePublic && pdata.defaultKey) {
  1288. let ps = getGmValue(pdata.defaultKey, null);
  1289. if (ps) {
  1290. obj.data1.values = ps.data1 ? ps.data1.values : obj.data1.values;
  1291. obj.data2.values = ps.data2 ? ps.data2.values : obj.data2.values;
  1292. obj.data3.values = ps.data3 ? ps.data3.values : obj.data3.values;
  1293. obj.data4.values = ps.data4 ? ps.data4.values : obj.data4.values;
  1294. obj.data5.values = ps.data5 ? ps.data5.values : obj.data5.values;
  1295. }
  1296. }
  1297. if (source.version === obj.version) {
  1298. source = obj;
  1299. }
  1300. else if (obj.version === 2) {
  1301. source.data1 = obj.data1;
  1302. source.data2 = obj.data2;
  1303. source.data3 = obj.data3;
  1304. source.data4 = obj.data4;
  1305. source.data5 = obj.data5;
  1306. setGmValue(key, source);
  1307. }
  1308. else {
  1309. source.data1.values = obj.data1 ? obj.data1.values : source.data1.values;
  1310. source.data2.values = obj.data2 ? obj.data2.values : source.data2.values;
  1311. source.data3.values = obj.data3 ? obj.data3.values : source.data3.values;
  1312. source.data4.values = obj.data4 ? obj.data4.values : source.data4.values;
  1313. source.data5.values = obj.data5 ? obj.data5.values : source.data5.values;
  1314. setGmValue(key, source);
  1315. }
  1316. }
  1317. config = getConfig();
  1318. signInput.value = isNull(config.signInText) ? '' : config.signInText;
  1319. hesitateInput.value = isNull(config.hesitationExpiry) ? '100' : config.hesitationExpiry;
  1320. setSource(source);
  1321. setOperationSetting();
  1322. initData();
  1323. },
  1324. initSettingPanel = (div, isLogin) => {
  1325. let settingPanel = document.getElementById('danmu-setting-panel');
  1326. if (div && !settingPanel) {
  1327. // console.log('===> 进行面板初始化');
  1328. let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
  1329. if (btnSend) {
  1330. buildPanel();
  1331. btnStart(btnSend);
  1332. if (isLogin) {
  1333. div.appendChild(dmButtonSend);
  1334. div.parentNode.insertBefore(btnSetting(), div);
  1335. }
  1336. else {
  1337. let funcDiv = document.createElement('div');
  1338. funcDiv.style.position = 'absolute';
  1339. funcDiv.appendChild(dmButtonSend);
  1340. funcDiv.appendChild(btnSetting());
  1341. div.appendChild(funcDiv);
  1342. // bgcolor = window.getComputedStyle(btnSend).getPropertyValue('background-color');
  1343. // dmButtonSend.style.setProperty('background', bgcolor);
  1344. // dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  1345. }
  1346. loadData();
  1347. // console.log('===> 面板初始化完成');
  1348. } else {
  1349. console.warn('===> 发送按钮丢失');
  1350. return false;
  1351. }
  1352. }
  1353.  
  1354. return true;
  1355. },
  1356. main = (div, isLogin) => {
  1357. waiters[waiters.length] = workerTimer.setInterval(() => {
  1358. if (initSettingPanel(div, isLogin)) {
  1359. clearWaiters();
  1360. } else {
  1361. --waitCount;
  1362. if (0 >= waitCount) {
  1363. clearWaiters();
  1364. console.log('===> 创建面板失败,停止初始化');
  1365. }
  1366. }
  1367. }, 1.5e3);
  1368. },
  1369. PluginBtn = (clazz, isLogin) => {
  1370. let div = document.getElementsByClassName(clazz)[0];
  1371. if (div) {
  1372. main(div, isLogin);
  1373. } else {
  1374. let count = 0;
  1375. divSendBtnTimer = workerTimer.setInterval(() => {
  1376. div = document.getElementsByClassName(clazz)[0];
  1377. if (div) {
  1378. workerTimer.clearInterval(divSendBtnTimer);
  1379. main(div, isLogin);
  1380. } else if (count++ >= 10) {
  1381. workerTimer.clearInterval(divSendBtnTimer);
  1382. // console.log(`===> 页面【${window.location.href}】没有定位位置`);
  1383. }
  1384. }, 1e3);
  1385. }
  1386. },
  1387. PluginLogout = () => PluginBtn('bottom-actions p-relative', false),
  1388. PluginLogin = () => PluginBtn('right-actions border-box', true),
  1389. PluginLottery = () => {
  1390. let btn = document.getElementsByClassName('particitation-btn')[0];
  1391. if (btn) {
  1392. lottery(btn);
  1393. } else {
  1394. btnLotteryTimer = workerTimer.setTimeout(() => {
  1395. workerTimer.clearTimeout(btnLotteryTimer);
  1396. btn = document.getElementsByClassName('particitation-btn')[0];
  1397. if (btn) {
  1398. lottery(btn);
  1399. }
  1400. }, 2e3);
  1401. }
  1402. },
  1403. PluginListPlus = () => {
  1404. let listTimer = workerTimer.setTimeout(() => {
  1405. workerTimer.clearTimeout(listTimer);
  1406. let obsConfig = {childList: true},
  1407. tags = ['all__card-list-ctnr', 'all__special-area-recommend-list-ctnr'];
  1408. tags.forEach(x => {
  1409. let dom = document.getElementsByClassName(x)[0];
  1410. if (!dom) return;
  1411. Array.prototype.forEach.call(dom.children, y => {
  1412. if (/^index_/i.test(y.className)) {
  1413. listPlus(y.children);
  1414. let obs = new MutationObserver(mrs => {
  1415. if (!mrs || 0 >= mrs.length) return;
  1416. Array.prototype.forEach.call(mrs, z => listPlus(z.addedNodes));
  1417. });
  1418. obs.observe(y, obsConfig);
  1419. }
  1420. });
  1421. });
  1422. }, 0.5e3);
  1423. },
  1424. debug = () => {debugger;},
  1425. runStart = () => {
  1426. if (0 < compareVersion(minVersion, pdata.version)) {
  1427. window.location.href = parentUrl;
  1428. return;
  1429. }
  1430.  
  1431. PluginLottery();
  1432. PluginListPlus();
  1433. PluginLogout();
  1434. PluginLogin();
  1435. };
  1436.  
  1437. initCss();
  1438. // initScript();
  1439. window.debug = debug;
  1440. window.runStart = runStart;
  1441. window.arrayInfo = arrayInfo;
  1442. window.setGmNotice = setGmNotice;
  1443. window.setGmGetValue = setGmGetValue;
  1444. window.setGmSetValue = setGmSetValue;
  1445. window.setGmDelValue = setGmDelValue;
  1446. window.setParentData = setParentData;
  1447. window.checkVersion = checkVersion;
  1448. })();