b-live-random-send-test

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

当前为 2024-09-06 提交的版本,查看 最新版本

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址