b-live-random-send-test

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

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

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

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