b-live-random-send-test

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

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

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

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