b-live-random-send-test

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

当前为 2024-08-29 提交的版本,查看 最新版本

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

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