b-live-random-send-test

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

当前为 2024-02-01 提交的版本,查看 最新版本

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

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