b-live-random-send-test

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

当前为 2023-12-03 提交的版本,查看 最新版本

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

  1. // ==UserScript==
  2. // @version 1.5.9
  3. // ==/UserScript==
  4.  
  5.  
  6. (function () {
  7. window.autoSendDanmuModuleLoaded = false;
  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, hesitationCheckbox,
  100. hidePrivacyCheckbox, hideRoomStatusCheckbox, usePublicCheckbox, setPublicCheckbox,
  101. rdCheckbox, group1Checkbox, group2Checkbox, group3Checkbox, group4Checkbox, group5Checkbox,
  102. dmInput, divSetting, dataText1, dataText2, dataText3, dataText4, dataText5, signInput, hesitateInput,
  103. dmButtonSend, beforeSpan, afterSpan, bgcolor, spanApplyMsg,
  104. pdata = {}, config = {}, waiters = [], data = [],
  105. sendTimer = null, signInTimer = null, miniCloseTimer, noSleepTimer, noSleepTimeouter, btnLotteryTimer, divSendBtnTimer,
  106. count = 0, waitCount = 200, arrayIndex = 0, default_timeout = 600, bgcolor_default = 'rgba(217,157,27,1)',
  107. lotteryChecked = 'lottery_checked', closeLotteryChecked = 'close_lottery_checked', hesitationChecked = 'hesitation_checked',
  108. hesitationExpiry = 'hesitation_expiry',
  109. gmNotice = obj => { alert('请更新油猴脚本'); window.location.href = parentUrl; },
  110. getGmValue = (key, defaultValue) => { return null; },
  111. setGmValue = (key, obj) => { console.warn('===> No implementation "setGmValue" method.'); },
  112. delGmValue = key => { console.warn('===> No implementation "delGmValue" method.'); };
  113.  
  114. const minVersion = '2.4.2', version = '1.5.9', upodateInfo = '新增弹幕源共享设置', noticeTimeout = 10e3,
  115. icoUrl = 'https://www.bilibili.com/favicon.ico',
  116. parentUrl = 'https://gf.qytechs.cn/scripts/446725-b%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E5%AE%9A%E6%97%B6%E5%8F%91%E9%9A%8F%E6%9C%BA%E5%BC%B9%E5%B9%95/code/B%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E5%AE%9A%E6%97%B6%E5%8F%91%E9%9A%8F%E6%9C%BA%E5%BC%B9%E5%B9%95.user.js',
  117. roomId = window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
  118. setGmGetValue = callback => getGmValue = callback,
  119. setGmSetValue = callback => setGmValue = callback,
  120. setGmDelValue = callback => delGmValue = callback,
  121. setGmNotice = callback => gmNotice = callback,
  122. setParentData = obj => pdata = obj,
  123. arrayInfo = () => console.info(data),
  124. isOldVersion = () => {
  125. if (!pdata.version) {
  126. return true;
  127. }
  128. if (minVersion === pdata.version) {
  129. return false;
  130. } else {
  131. let vals = pdata.version.split('.');
  132. let mins = minVersion.split('.');
  133. if (vals.length != mins.length) {
  134. return true;
  135. } else {
  136. for (let i = 0; i < vals.length; i++) {
  137. if (mins[i] > vals[i]) {
  138. return true;
  139. }
  140. }
  141.  
  142. return false;
  143. }
  144. }
  145. },
  146. initCss = () => {
  147. let linkElement = document.createElement('link');
  148. linkElement.rel = 'stylesheet';
  149. linkElement.href = 'https://unpkg.com/element-ui@2.15.9/lib/theme-chalk/index.css';
  150. document.head.appendChild(linkElement);
  151.  
  152. let customerStyle = document.createElement('style');
  153. customerStyle.setAttribute('type', 'text/css');
  154. 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;}.danmu-random-update-tips{color:#0b81cc;text-align:center;font-size:13px;font-weight:700;margin:10px 0px;}.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;}.danmu-btn:hover{background:var(--color)!important;}.danmu-text-span{color:rgb(255, 255, 255);font-size:12px;background:rgb(236,108,27);}.danmu-second-input{width:25px;height:15px;margin:0px 3px;border:0px;border-radius:3px;}.not-display{display:none !important;}';
  155. document.head.appendChild(customerStyle);
  156. },
  157. getCurrentTimestamp = () => new Date().getTime(),
  158. send = (msg, index) => {
  159. let dmTextArea = document.getElementById('aside-area-vm').getElementsByClassName('chat-input border-box')[0];
  160. if (!dmTextArea) {
  161. alert('找不到输入弹幕文本框,请尝试刷新页面');
  162. return;
  163. }
  164.  
  165. let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
  166. if (!btnSend) {
  167. alert('找不到发送按钮,请尝试刷新页面');
  168. return;
  169. }
  170. dmTextArea.value = msg;
  171. dmTextArea.dispatchEvent(new Event('input', { "bubbles": true, "cancelable": true }));
  172. btnSend.click();
  173. lastSent = getCurrentTimestamp();
  174. // ++count;
  175. // console.log('===> ' + new Date().toLocaleString() + ' 弹幕发送成功 ' + count + ' 次,第【' + index + '】条数据 === ' + msg);
  176. },
  177. isNull = str => {
  178. if (!str || str == "") {
  179. return true;
  180. }
  181.  
  182. let regu = "^[ ]+$";
  183. let re = new RegExp(regu);
  184. return re.test(str);
  185. },
  186. randomSort = arr => {
  187. for (let i = 0; i < arr.length; i++) {
  188. const rdIndex = Math.floor(Math.random() * arr.length);
  189. const temp = arr[i];
  190. arr[i] = arr[rdIndex];
  191. arr[rdIndex] = temp;
  192. }
  193.  
  194. return arr;
  195. },
  196. clearWaiters = () => {
  197. for (let i = 0; i < waiters.length; i++) {
  198. workerTimer.clearInterval(waiters[i]);
  199. waiters[i] = null;
  200. }
  201.  
  202. waiters = [];
  203. },
  204. signIn = () => {
  205. if (signInCheckbox.checked) {
  206. if (!signInTimer) {
  207. let defaultText = isNull(pdata.signText) ? pdata.signText : '打卡';
  208. let timestamp = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()).getTime() - getCurrentTimestamp();
  209. console.log('===> 设置凌晨打卡定时器【' + timestamp + '】');
  210. signInput.value = isNull(config.signInText) ? defaultText : config.signInText;
  211. signInTimer = workerTimer.setTimeout(() => {
  212. send(isNull(signInput.value) ? defaultText : signInput.value, 0);
  213. console.log('===> 设置下一次打卡');
  214. workerTimer.clearTimeout(signInTimer);
  215. signInTimer = null;
  216. signIn();
  217. }, timestamp);
  218. }
  219. } else if (signInTimer) {
  220. console.log('===> 关闭自动打卡功能');
  221. workerTimer.clearTimeout(signInTimer);
  222. signInTimer = null;
  223. }
  224. },
  225. setSource = obj => {
  226. dataText1.value = obj.data1.values.join('|');
  227. dataText2.value = obj.data2.values.join('|');
  228. dataText3.value = obj.data3.values.join('|');
  229. dataText4.value = obj.data4.values.join('|');
  230. dataText5.value = obj.data5.values.join('|');
  231. },
  232. runCheckbox = () => {
  233. hideFooter();
  234. hideGiftControl();
  235. hideLoginGuide();
  236. hideHaruna();
  237. hideShop();
  238. noSleep();
  239. signIn();
  240. hidePrivacy();
  241. hideRoomStatus();
  242. setLotteryChecked();
  243. setHesitationChecked();
  244. setCloseLotteryChecked();
  245. hideRoomFeed();
  246. hideRoomInfo();
  247. hideNotice();
  248. let hideTimeout = workerTimer.setTimeout(() => {
  249. workerTimer.clearTimeout(hideTimeout);
  250. hideRoomFeed();
  251. hideRoomInfo();
  252. hideNotice();
  253. }, 1e3);
  254. },
  255. setOperationSetting = () => {
  256. rdCheckbox.checked = source.random;
  257. usePublicCheckbox.checked = source.usePublic;
  258. group1Checkbox.checked = source.data1.available;
  259. group2Checkbox.checked = source.data2.available;
  260. group3Checkbox.checked = source.data3.available;
  261. group4Checkbox.checked = source.data4.available;
  262. group5Checkbox.checked = source.data5.available;
  263.  
  264. signInCheckbox.checked = config.autoSignIn;
  265. noSleepCheckbox.checked = config.noSleep;
  266. hideLoginGuideCheckbox.checked = config.hideLoginGuide;
  267. hideHarunaCheckbox.checked = config.hideHaruna;
  268. hideShopCheckbox.checked = config.hideShop;
  269. hideGiftControlCheckbox.checked = config.hideGift;
  270. hideRoomFeedCheckbox.checked = config.hideRoomFeed;
  271. hideRoomInfoCheckbox.checked = config.hideRoomInfo;
  272. hideNoticeCheckbox.checked = config.hideNotice;
  273. hideFooterCheckbox.checked = config.hideFooter;
  274. lotteryCheckbox.checked = config.lottery;
  275. hesitationCheckbox.checked = config.hesitation;
  276. closeLotteryCheckbox.checked = config.closeLottery;
  277. hidePrivacyCheckbox.checked = config.noPrivacy;
  278. hideRoomStatusCheckbox.checked = config.hideWatermark;
  279. runCheckbox();
  280. },
  281. openSetting = () => divSetting.style.display = 'block',
  282. closeSetting = () => {
  283. setOperationSetting();
  284. divSetting.style.display = 'none';
  285. },
  286. initData = () => {
  287. if (source.data1.values.length <= 0
  288. && source.data2.values.length <= 0
  289. && source.data3.values.length <= 0
  290. && source.data4.values.length <= 0
  291. && source.data5.values.length <= 0) {
  292. return data ? data : [];
  293. }
  294.  
  295. let result = [];
  296. result = source.data1.available ? result.concat(source.data1.values) : result;
  297. result = source.data2.available ? result.concat(source.data2.values) : result;
  298. result = source.data3.available ? result.concat(source.data3.values) : result;
  299. result = source.data4.available ? result.concat(source.data4.values) : result;
  300. result = source.data5.available ? result.concat(source.data5.values) : result;
  301. data = result;
  302. rdCheckbox.checked ? data = randomSort(result) : arrayIndex = 0;
  303. },
  304. flashMsg = (txt, back, color) => {
  305. spanApplyMsg.textContent = txt;
  306. spanApplyMsg.style.display = 'block';
  307. if (color) {
  308. spanApplyMsg.style.color = color;
  309. }
  310. else {
  311. spanApplyMsg.style.color = '#128712';
  312. }
  313.  
  314. let hideTipTimer = workerTimer.setTimeout(() => {
  315. workerTimer.clearTimeout(hideTipTimer);
  316. spanApplyMsg.style.display = 'none';
  317. spanApplyMsg.textContent = '';
  318. if (back) {
  319. divSetting.style.display = 'none';
  320. }
  321. }, 1.5e3);
  322. },
  323. save = () => {
  324. if (!pdata || isNull(pdata.defaultKey) || isNull(pdata.configKey)) {
  325. flashMsg('保存失败', false, 'red');
  326. return;
  327. }
  328. if (pdata.configKey) {
  329. config.autoSignIn = signInCheckbox.checked;
  330. config.signInText = signInput.value;
  331. config.noSleep = noSleepCheckbox.checked;
  332. config.hideLoginGuide = hideLoginGuideCheckbox.checked;
  333. config.hideHaruna = hideHarunaCheckbox.checked;
  334. config.hideShop = hideShopCheckbox.checked;
  335. config.hideGift = hideGiftControlCheckbox.checked;
  336. config.hideRoomFeed = hideRoomFeedCheckbox.checked;
  337. config.hideRoomInfo = hideRoomInfoCheckbox.checked;
  338. config.hideNotice = hideNoticeCheckbox.checked;
  339. config.hideFooter = hideFooterCheckbox.checked;
  340. config.lottery = lotteryCheckbox.checked;
  341. window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
  342. config.hesitation = hesitationCheckbox.checked;
  343. window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
  344. config.hesitationExpiry = hesitateInput.value;
  345. window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
  346. config.closeLottery = closeLotteryCheckbox.checked;
  347. window.localStorage.setItem(closeLotteryChecked, config.closeLottery);
  348. config.noPrivacy = hidePrivacyCheckbox.checked;
  349. config.hideWatermark = hideRoomStatusCheckbox.checked;
  350. setGmValue(pdata.configKey, config);
  351. }
  352. if (setPublicCheckbox.checked) {
  353. let ps = {data1:{values:[]},data2:{values:[]},data3:{values:[]},data4:{values:[]},data5:{values:[]}};
  354. ps.data1.values = isNull(dataText1.value) ? [] : dataText1.value.split('|');
  355. ps.data2.values = isNull(dataText2.value) ? [] : dataText2.value.split('|');
  356. ps.data3.values = isNull(dataText3.value) ? [] : dataText3.value.split('|');
  357. ps.data4.values = isNull(dataText4.value) ? [] : dataText4.value.split('|');
  358. ps.data5.values = isNull(dataText5.value) ? [] : dataText5.value.split('|');
  359. setGmValue(pdata.defaultKey, ps);
  360. }
  361. else if (!usePublicCheckbox.checked) {
  362. source.data1.values = isNull(dataText1.value) ? [] : dataText1.value.split('|');
  363. source.data2.values = isNull(dataText2.value) ? [] : dataText2.value.split('|');
  364. source.data3.values = isNull(dataText3.value) ? [] : dataText3.value.split('|');
  365. source.data4.values = isNull(dataText4.value) ? [] : dataText4.value.split('|');
  366. source.data5.values = isNull(dataText5.value) ? [] : dataText5.value.split('|');
  367. }
  368. source.random = rdCheckbox.checked;
  369. source.usePublic = usePublicCheckbox.checked;
  370. source.data1.available = group1Checkbox.checked;
  371. source.data2.available = group2Checkbox.checked;
  372. source.data3.available = group3Checkbox.checked;
  373. source.data4.available = group4Checkbox.checked;
  374. source.data5.available = group5Checkbox.checked;
  375. setGmValue(roomId, source);
  376. initData();
  377. flashMsg('设置成功', true);
  378. },
  379. cleanCache = () => {
  380. if (pdata.configKey && config) {
  381. config.script = '';
  382. config.lastUpdate = '清除缓存';
  383. setGmValue(pdata.configKey, config);
  384. flashMsg('清除成功');
  385. } else {
  386. console.warn('元数据丢失');
  387. flashMsg('操作失败', false, 'red');
  388. }
  389. },
  390. danmu = () => {
  391. if (data.length < 1) {
  392. // gmNotice({
  393. // text: '请任意在一个分组里输入一条弹幕',
  394. // title: '没有弹幕数据,请先设置',
  395. // image: icoUrl,
  396. // highlight: true,
  397. // timeout: noticeTimeout
  398. // });
  399. alert('请先设置弹幕');
  400. return false;
  401. }
  402. if (rdCheckbox.checked) {
  403. arrayIndex = Math.floor((Math.random() * data.length));
  404. }
  405.  
  406. send(data[arrayIndex], arrayIndex);
  407. ++arrayIndex;
  408. if (arrayIndex >= data.length) {
  409. arrayIndex = 0;
  410. }
  411.  
  412. return true;
  413. },
  414. offOrOn = () => {
  415. let timeout = 0;
  416. if (sendTimer) {
  417. workerTimer.clearInterval(sendTimer);
  418. sendTimer = null;
  419. dmButtonSend.style.background = isNull(bgcolor) ? bgcolor_default : bgcolor;
  420. dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  421. dmButtonSend.textContent = '开始';
  422. dmInput.removeAttribute("disabled");
  423. } else {
  424. timeout = (isNull(dmInput.value) ? default_timeout : dmInput.value) * 1e3;
  425. if (!danmu()) {
  426. return;
  427. }
  428.  
  429. sendTimer = workerTimer.setInterval(danmu, timeout);
  430. dmButtonSend.style.background = 'rgba(255,0,0,1)';
  431. dmButtonSend.style.setProperty('--color', 'rgba(255,0,0,0.8)');
  432. dmButtonSend.textContent = '停止';
  433. dmInput.setAttribute('disabled', 'disabled');
  434. }
  435. },
  436. createSwitch = (id, txt, title, func, container, indent, width, hidden, rear, disabled) => {
  437. let checkbox = document.createElement('input');
  438. checkbox.type = 'checkbox';
  439. checkbox.id = id;
  440. checkbox.checked = false;
  441. if (func && !disabled) {
  442. checkbox.addEventListener('click', func);
  443. }
  444.  
  445. let lblCheckbox = document.createElement('label');
  446. lblCheckbox.setAttribute('for', id);
  447. lblCheckbox.classList.add('switch-check-label');
  448.  
  449. let descSpan = document.createElement('span');
  450. descSpan.textContent = txt;
  451. descSpan.title = title;
  452. descSpan.classList.add('danmu-random-switch-button-title');
  453. if (disabled) {
  454. checkbox.disabled = true;
  455. checkbox.classList.add('disabled');
  456. lblCheckbox.classList.add('disabled');
  457. descSpan.classList.add('disabled');
  458. }
  459.  
  460. let divCheckbox = document.createElement('div');
  461. divCheckbox.id = id + 'Div';
  462. divCheckbox.classList.add('switch-check');
  463. divCheckbox.classList.add('switch-check-group');
  464. divCheckbox.appendChild(checkbox);
  465. divCheckbox.appendChild(lblCheckbox);
  466. divCheckbox.appendChild(descSpan);
  467. if (!isNull(indent)) {
  468. divCheckbox.style.marginLeft = indent;
  469. }
  470. if (!isNull(width)) {
  471. divCheckbox.style.width = width;
  472. }
  473. if (hidden) {
  474. divCheckbox.style.setProperty('display', 'none');
  475. }
  476. if (rear) {
  477. divCheckbox.appendChild(rear);
  478. }
  479.  
  480. container.appendChild(divCheckbox);
  481. return checkbox;
  482. },
  483. buildPanel = divButton => {
  484. /* ----------------------------------------- head ----------------------------------------- */
  485. let divSettingTitle = document.createElement('div');
  486. divSettingTitle.textContent = '弹幕设置';
  487. divSettingTitle.classList.add('danmu-random-setting-title');
  488.  
  489. let divSub = document.createElement('div');
  490. divSub.textContent = version;
  491. divSub.classList.add('danmu-random-setting-title-sub');
  492. divSettingTitle.appendChild(divSub);
  493.  
  494. let divTip = document.createElement('div');
  495. divTip.classList.add('danmu-random-setting-tips');
  496. divTip.innerHTML = '任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';
  497.  
  498. let divUpdateTip = document.createElement('div');
  499. divUpdateTip.classList.add('danmu-random-update-tips');
  500. divUpdateTip.innerHTML = `<span style="color:#f00">更新提示:</span>${upodateInfo}`;
  501. /* ----------------------------------------- head ----------------------------------------- */
  502.  
  503. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  504. let divText1 = document.createElement('div');
  505. divText1.textContent = '分组 1 :';
  506. divText1.classList.add('danmu-group-title');
  507.  
  508. group1Checkbox = document.createElement('input');
  509. group1Checkbox.type = 'checkbox';
  510. group1Checkbox.id = 'group1Checkbox';
  511. group1Checkbox.checked = true;
  512.  
  513. let lblGroup1Checkbox = document.createElement('label');
  514. lblGroup1Checkbox.setAttribute('for', 'group1Checkbox');
  515. lblGroup1Checkbox.classList.add('switch-check-label');
  516.  
  517. let divGroup1Checkbox = document.createElement('div');
  518. divGroup1Checkbox.classList.add('switch-check');
  519. divGroup1Checkbox.appendChild(group1Checkbox);
  520. divGroup1Checkbox.appendChild(lblGroup1Checkbox);
  521.  
  522. dataText1 = document.createElement('textarea');
  523. dataText1.classList.add('danmu-group-textarea');
  524. dataText1.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  525. /* ----------------------------------------- textarea 1 ----------------------------------------- */
  526.  
  527. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  528. let divText2 = document.createElement('div');
  529. divText2.textContent = '分组 2 :';
  530. divText2.classList.add('danmu-group-title');
  531.  
  532. group2Checkbox = document.createElement('input');
  533. group2Checkbox.type = 'checkbox';
  534. group2Checkbox.id = 'group2Checkbox';
  535. group2Checkbox.checked = true;
  536.  
  537. let lblGroup2Checkbox = document.createElement('label');
  538. lblGroup2Checkbox.setAttribute('for', 'group2Checkbox');
  539. lblGroup2Checkbox.classList.add('switch-check-label');
  540.  
  541. let divGroup2Checkbox = document.createElement('div');
  542. divGroup2Checkbox.classList.add('switch-check');
  543. divGroup2Checkbox.appendChild(group2Checkbox);
  544. divGroup2Checkbox.appendChild(lblGroup2Checkbox);
  545.  
  546. dataText2 = document.createElement('textarea');
  547. dataText2.classList.add('danmu-group-textarea');
  548. dataText2.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  549. /* ----------------------------------------- textarea 2 ----------------------------------------- */
  550.  
  551. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  552. let divText3 = document.createElement('div');
  553. divText3.textContent = '分组 3 :';
  554. divText3.classList.add('danmu-group-title');
  555.  
  556. group3Checkbox = document.createElement('input');
  557. group3Checkbox.type = 'checkbox';
  558. group3Checkbox.id = 'group3Checkbox';
  559. group3Checkbox.checked = true;
  560.  
  561. let lblGroup3Checkbox = document.createElement('label');
  562. lblGroup3Checkbox.setAttribute('for', 'group3Checkbox');
  563. lblGroup3Checkbox.classList.add('switch-check-label');
  564.  
  565. let divGroup3Checkbox = document.createElement('div');
  566. divGroup3Checkbox.classList.add('switch-check');
  567. divGroup3Checkbox.appendChild(group3Checkbox);
  568. divGroup3Checkbox.appendChild(lblGroup3Checkbox);
  569.  
  570. dataText3 = document.createElement('textarea');
  571. dataText3.classList.add('danmu-group-textarea');
  572. dataText3.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  573. /* ----------------------------------------- textarea 3 ----------------------------------------- */
  574.  
  575. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  576. let divText4 = document.createElement('div');
  577. divText4.textContent = '分组 4 :';
  578. divText4.classList.add('danmu-group-title');
  579.  
  580. group4Checkbox = document.createElement('input');
  581. group4Checkbox.type = 'checkbox';
  582. group4Checkbox.id = 'group4Checkbox';
  583. group4Checkbox.checked = true;
  584.  
  585. let lblGroup4Checkbox = document.createElement('label');
  586. lblGroup4Checkbox.setAttribute('for', 'group4Checkbox');
  587. lblGroup4Checkbox.classList.add('switch-check-label');
  588.  
  589. let divGroup4Checkbox = document.createElement('div');
  590. divGroup4Checkbox.classList.add('switch-check');
  591. divGroup4Checkbox.appendChild(group4Checkbox);
  592. divGroup4Checkbox.appendChild(lblGroup4Checkbox);
  593.  
  594. dataText4 = document.createElement('textarea');
  595. dataText4.classList.add('danmu-group-textarea');
  596. dataText4.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  597. /* ----------------------------------------- textarea 4 ----------------------------------------- */
  598.  
  599. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  600. let divText5 = document.createElement('div');
  601. divText5.textContent = '分组 5 :';
  602. divText5.classList.add('danmu-group-title');
  603.  
  604. group5Checkbox = document.createElement('input');
  605. group5Checkbox.type = 'checkbox';
  606. group5Checkbox.id = 'group5Checkbox';
  607. group5Checkbox.checked = true;
  608.  
  609. let lblGroup5Checkbox = document.createElement('label');
  610. lblGroup5Checkbox.setAttribute('for', 'group5Checkbox');
  611. lblGroup5Checkbox.classList.add('switch-check-label');
  612.  
  613. let divGroup5Checkbox = document.createElement('div');
  614. divGroup5Checkbox.classList.add('switch-check');
  615. divGroup5Checkbox.appendChild(group5Checkbox);
  616. divGroup5Checkbox.appendChild(lblGroup5Checkbox);
  617.  
  618. dataText5 = document.createElement('textarea');
  619. dataText5.classList.add('danmu-group-textarea');
  620. dataText5.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
  621. /* ----------------------------------------- textarea 5 ----------------------------------------- */
  622.  
  623. /* ----------------------------------------- different room setting ----------------------------------------- */
  624. let divRoomSetting = document.createElement('div');
  625. divRoomSetting.appendChild(divText1);
  626. divRoomSetting.appendChild(divGroup1Checkbox);
  627. divRoomSetting.appendChild(dataText1);
  628. divRoomSetting.appendChild(divText2);
  629. divRoomSetting.appendChild(divGroup2Checkbox);
  630. divRoomSetting.appendChild(dataText2);
  631. divRoomSetting.appendChild(divText3);
  632. divRoomSetting.appendChild(divGroup3Checkbox);
  633. divRoomSetting.appendChild(dataText3);
  634. divRoomSetting.appendChild(divText4);
  635. divRoomSetting.appendChild(divGroup4Checkbox);
  636. divRoomSetting.appendChild(dataText4);
  637. divRoomSetting.appendChild(divText5);
  638. divRoomSetting.appendChild(divGroup5Checkbox);
  639. divRoomSetting.appendChild(dataText5);
  640. rdCheckbox = createSwitch('rdCheckbox', '随机从上面的弹幕中选出一条发送', '将合并所有分组数据,从中随机选出一条发送', null, divRoomSetting);
  641. usePublicCheckbox = createSwitch('usePublicCheckbox', '使用共用弹幕源', '使用设置为共用弹幕作为弹幕源', usePublicDanmu, divRoomSetting);
  642. createSwitch('autoLikeCheckbox', '自动点赞该直播间(需登录(不可用))', '开发中……', null, divRoomSetting, null, null, null, null, true);
  643.  
  644. let operationDescription = document.createElement('div');
  645. operationDescription.textContent = '以上设置对应各个直播间独立保存,无需刷新';
  646. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  647. operationDescription.classList.add('global-setting-tip');
  648. operationDescription.classList.add('switch-check-group');
  649. divRoomSetting.appendChild(operationDescription);
  650. /* ----------------------------------------- different room setting ----------------------------------------- */
  651.  
  652. /* ----------------------------------------- global setting ----------------------------------------- */
  653. let divGlobalSetting = document.createElement('div');
  654. divGlobalSetting.style.margin = '20px 0 10px';
  655.  
  656. operationDescription = document.createElement('div');
  657. operationDescription.textContent = '以下设置,需刷新其它直播间才能适用';
  658. operationDescription.title = '请点击设置面板底下的“✓”进行保存';
  659. operationDescription.classList.add('global-setting-tip');
  660. operationDescription.classList.add('switch-check-group');
  661. divGlobalSetting.appendChild(operationDescription);
  662.  
  663. signInput = document.createElement('input');
  664. signInput.style.border = '0';
  665. signInput.style.width = '90px';
  666. signInput.setAttribute('placeholder', '输入打卡的文字');
  667.  
  668. hesitateInput = document.createElement('input');
  669. hesitateInput.style.border = '0';
  670. hesitateInput.style.width = '55px';
  671. hesitateInput.setAttribute('placeholder', '单位:秒');
  672. hesitateInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  673.  
  674. setPublicCheckbox = createSwitch('setPublicCheckbox', '设为共用弹幕源', '把这个直播间的弹幕共享给其它直播间使用,先后设置时,后面的会覆盖前面的设置', setPublicDanmu, divGlobalSetting);
  675. signInCheckbox = createSwitch('signInCheckbox', '打卡弹幕(需登录(不可用)):', '每日零点发送一条打卡弹幕', signIn, divGlobalSetting, null, null, false, signInput);
  676. lotteryCheckbox = createSwitch('lotteryCheckbox', '自动参与天选时刻抽奖(需登录(不可用))', '自动点击参与按钮,请确保已经登录(不可用)了阿B账号', setLotteryChecked, divGlobalSetting);
  677. hesitationCheckbox = createSwitch('hesitationCheckbox', '犹豫期:', '不立刻参与天选时刻,这期间可以手动处理,免得自动参加后后悔(时间单位:秒)', setHesitationChecked, divGlobalSetting, '23px', '90%', true, hesitateInput);
  678. closeLotteryCheckbox = createSwitch('closeLotteryCheckbox', '关闭天选时刻', '关闭天选时刻弹窗', setCloseLotteryChecked, divGlobalSetting);
  679. noSleepCheckbox = createSwitch('noSleepCheckbox', '防止直播间休眠', '防止直播间页面一段时间没操作之后进入休眠', noSleep, divGlobalSetting);
  680. hideLoginGuideCheckbox = createSwitch('hideLoginGuideCheckbox', '隐藏播放器底部登录(不可用)提示', '隐藏未登录(不可用)时播放器底部显示的登录(不可用)提示', hideLoginGuide, divGlobalSetting);
  681. hideHarunaCheckbox = createSwitch('hideHarunaCheckbox', '隐藏看板娘立绘', '隐藏直播间Haruna立绘', hideHaruna, divGlobalSetting);
  682. hideShopCheckbox = createSwitch('hideShopCheckbox', '隐藏购物提示', '隐藏播放器左上角的商店购物提示', hideShop, divGlobalSetting);
  683. hideGiftControlCheckbox = createSwitch('hideGiftControlCheckbox', '隐藏礼物栏', '隐藏播放器底部的礼物栏', hideGiftControl, divGlobalSetting);
  684. hideRoomFeedCheckbox = createSwitch('hideRoomFeedCheckbox', '隐藏主播动态', '隐藏播放器底下主播的动态栏', hideRoomFeed, divGlobalSetting);
  685. hideRoomInfoCheckbox = createSwitch('hideRoomInfoCheckbox', '隐藏主播荣耀、简介', '隐藏播放器底下主播的荣耀勋章和简介', hideRoomInfo, divGlobalSetting);
  686. hideNoticeCheckbox = createSwitch('hideNoticeCheckbox', '隐藏主播公告', '隐藏弹幕列表底下主播的公告', hideNotice, divGlobalSetting);
  687. hideFooterCheckbox = createSwitch('hideFooterCheckbox', '隐藏直播间页脚', '隐藏直播间底部的网页页脚', hideFooter, divGlobalSetting);
  688. hidePrivacyCheckbox = createSwitch('hidePrivacyCheckbox', '隐藏隐私提示对话框', '隐藏隐私提示登录(不可用)的对话框,被打码的昵称不保证变回正常', hidePrivacy, divGlobalSetting);
  689. hideRoomStatusCheckbox = createSwitch('hideRoomStatusCheckbox', '隐藏直播水印', '隐藏播放器左上角的直播水印', hideRoomStatus, divGlobalSetting);
  690. /* ----------------------------------------- global setting ----------------------------------------- */
  691.  
  692. /* ----------------------------------------- operation msg ----------------------------------------- */
  693. spanApplyMsg = document.createElement('span');
  694. spanApplyMsg.classList.add('danmu-random-setting-success-text');
  695.  
  696. let divApplyMsg = document.createElement('div');
  697. divApplyMsg.classList.add('danmu-random-setting-success-tips');
  698. divApplyMsg.appendChild(spanApplyMsg);
  699. /* ----------------------------------------- operation msg ----------------------------------------- */
  700. /* ----------------------------------------- clean cache ----------------------------------------- */
  701. let cleanCacheBtn = document.createElement('button');
  702. cleanCacheBtn.textContent = '清除缓存';
  703. cleanCacheBtn.classList.add('clean-cache-btn');
  704. cleanCacheBtn.addEventListener('click', cleanCache);
  705. /* ----------------------------------------- clean cache ----------------------------------------- */
  706.  
  707. /* ----------------------------------------- save and close button ----------------------------------------- */
  708. let btnSave = document.createElement('i');
  709. btnSave.setAttribute('title', '保存');
  710. btnSave.style.padding = '5px';
  711. btnSave.classList.add('el-button');
  712. btnSave.classList.add('el-icon-check');
  713. btnSave.classList.add('is-circle');
  714. btnSave.addEventListener('click', save);
  715.  
  716. let btnClose = document.createElement('i');
  717. btnClose.setAttribute('title', '关闭');
  718. btnClose.style.padding = '5px';
  719. btnClose.classList.add('el-button');
  720. btnClose.classList.add('el-icon-close');
  721. btnClose.classList.add('is-circle');
  722. btnClose.addEventListener('click', closeSetting);
  723.  
  724. let divBtnSetting = document.createElement('div');
  725. divBtnSetting.classList.add('danmu-random-set-button-container');
  726. divBtnSetting.appendChild(cleanCacheBtn);
  727. divBtnSetting.appendChild(btnSave);
  728. divBtnSetting.appendChild(btnClose);
  729. /* ----------------------------------------- save and close button ----------------------------------------- */
  730.  
  731. /* ----------------------------------------- container ----------------------------------------- */
  732. let divBottomContainer = document.createElement('div');
  733. divBottomContainer.classList.add('danmu-random-setting-bottom');
  734. divBottomContainer.appendChild(divApplyMsg);
  735. divBottomContainer.appendChild(divBtnSetting);
  736.  
  737. let divContainer = document.createElement('div');
  738. divContainer.style.height = 'calc(98% - 30px - 25px)';
  739. divContainer.appendChild(divRoomSetting);
  740. divContainer.appendChild(divGlobalSetting);
  741. divContainer.appendChild(divBottomContainer);
  742. /* ----------------------------------------- container ----------------------------------------- */
  743.  
  744. divSetting = document.createElement('div');
  745. divSetting.id = 'danmu-setting-panel';
  746. divSetting.classList.add('danmu-random-setting-panel');
  747. divSetting.appendChild(divSettingTitle);
  748. divSetting.appendChild(divUpdateTip);
  749. divSetting.appendChild(divTip);
  750. divSetting.appendChild(divContainer);
  751.  
  752. let asideAreaVm = document.getElementById('aside-area-vm');
  753. asideAreaVm.appendChild(divSetting);
  754.  
  755. /* ----------------------------------------- function ----------------------------------------- */
  756. dmButtonSend = document.createElement('button');
  757. dmButtonSend.textContent = '开始';
  758. dmButtonSend.classList.add('danmu-btn');
  759. dmButtonSend.style.setProperty('--color', 'rgba(217,157,27,0.8)');
  760. //dmButtonSend.onclick = function() { alert('Hello world');}
  761. dmButtonSend.addEventListener('click', offOrOn);
  762.  
  763. beforeSpan = document.createElement('span');
  764. beforeSpan.textContent = '每';
  765. beforeSpan.classList.add('danmu-text-span');
  766. beforeSpan.style.marginLeft = '4px';
  767.  
  768. dmInput = document.createElement('input');
  769. dmInput.value = default_timeout;
  770. dmInput.classList.add('danmu-second-input');
  771. dmInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
  772.  
  773. afterSpan = document.createElement('span');
  774. afterSpan.textContent = '秒发送';
  775. afterSpan.classList.add('danmu-text-span');
  776. afterSpan.style.marginRight = '4px';
  777.  
  778. let iElement = document.createElement('i');
  779. iElement.classList.add('el-icon-setting');
  780.  
  781. let btnSetting = document.createElement('button');
  782. btnSetting.title = '设置';
  783. btnSetting.classList.add('el-button');
  784. btnSetting.classList.add('el-button--mini');
  785. btnSetting.classList.add('is-circle');
  786. btnSetting.addEventListener('click', openSetting);
  787. btnSetting.appendChild(iElement);
  788.  
  789. // let btnSetting = document.createElement('ion-icon');
  790. // btnSetting.setAttribute('name', 'settings-sharp');
  791. // btnSetting.classList.add('el-button');
  792. // btnSetting.classList.add('el-button--mini');
  793. // btnSetting.classList.add('is-circle');
  794. // btnSetting.addEventListener('click', openSetting);
  795.  
  796. let div = document.createElement('div');
  797. div.style.position = 'absolute';
  798. div.appendChild(dmButtonSend);
  799. div.appendChild(beforeSpan);
  800. div.appendChild(dmInput);
  801. div.appendChild(afterSpan);
  802. div.appendChild(btnSetting);
  803. divButton.appendChild(div);
  804. /* ----------------------------------------- function ----------------------------------------- */
  805. },
  806. hideOrDisplay = (dom, hidden) => {
  807. if (hidden) {
  808. dom.style.setProperty('display', 'none', 'important');
  809. } else {
  810. dom.style.removeProperty('display');
  811. }
  812. },
  813. removeAttribute = (dom, attr) => {
  814. dom.removeAttribute(attr);
  815. if (0 < dom.children.length) {
  816. for (let i = 0; i < dom.children.length; i++) {
  817. removeAttribute(dom.children[i], attr);
  818. }
  819. }
  820. },
  821. setAttribute = (dom, attr, val) => {
  822. dom.setAttribute(attr, val);
  823. if (0 < dom.children.length) {
  824. for (let i = 0; i < dom.children.length; i++) {
  825. setAttribute(dom.children[i], attr, val);
  826. }
  827. }
  828. },
  829. hideLoginGuide = () => {
  830. let dom = document.getElementById('switch-login-guide-vm');
  831. if (dom) {
  832. hideOrDisplay(dom, hideLoginGuideCheckbox.checked);
  833. }
  834. },
  835. hideHaruna = () => {
  836. let dom = document.getElementById('my-dear-haruna-vm');
  837. if (dom) {
  838. hideOrDisplay(dom, hideHarunaCheckbox.checked);
  839. }
  840. },
  841. hideShop = () => {
  842. let dom = document.getElementById('shop-popover-vm');
  843. if (dom) {
  844. hideOrDisplay(dom, hideShopCheckbox.checked);
  845. }
  846. },
  847. hideGiftControl = () => {
  848. let dom = document.getElementsByClassName('gift-control-section')[0];
  849. if (dom) {
  850. hideOrDisplay(dom, hideGiftControlCheckbox.checked);
  851. }
  852.  
  853. dom = document.getElementById('web-player__bottom-bar__container');
  854. if (dom) {
  855. hideOrDisplay(dom, hideGiftControlCheckbox.checked);
  856. }
  857.  
  858. dom = document.getElementsByTagName('video');
  859. for (let i = 0; i < dom.length; i++) {
  860. if (!dom[i]) {
  861. return;
  862. }
  863. if (hideGiftControlCheckbox.checked) {
  864. dom[i].style.setProperty('height', '100%');
  865. } else if (document.body.classList.contains('player-full-win') || document.body.classList.contains('fullscreen-fix')) {
  866. dom[i].style.setProperty('height', 'calc(100% - 114px)');
  867. }
  868. }
  869. },
  870. hideRoomFeed = () => {
  871. let dom = document.getElementsByClassName('room-feed')[0];
  872. if (dom) {
  873. hideOrDisplay(dom, hideRoomFeedCheckbox.checked);
  874. }
  875. dom = document.getElementsByClassName('flip-view p-relative')[0];
  876. if (dom) {
  877. hideOrDisplay(dom, hideRoomFeedCheckbox.checked);
  878. }
  879. },
  880. hideRoomInfo = () => {
  881. let dom = document.getElementsByClassName('room-info-ctnr')[0];
  882. if (dom) {
  883. hideOrDisplay(dom, hideRoomInfoCheckbox.checked);
  884. }
  885. },
  886. hideNotice = () => {
  887. let dom = document.getElementsByClassName('right-container')[0];
  888. if (dom) {
  889. dom.style.setProperty('min-height', 'auto');
  890. hideOrDisplay(dom, hideNoticeCheckbox.checked);
  891. }
  892. },
  893. hideFooter = () => {
  894. let dom = document.getElementById('link-footer-vm');
  895. if (dom) {
  896. hideOrDisplay(dom, hideFooterCheckbox.checked);
  897. }
  898. },
  899. hidePrivacy = () => {
  900. if (hidePrivacyCheckbox.checked) {
  901. let dom = document.createElement('style');
  902. dom.id = 'hidePrivacyDialog';
  903. dom.setAttribute('type', 'text/css');
  904. dom.innerHTML = '.privacy-dialog{display:none !important;}';
  905. document.head.appendChild(dom);
  906. } else {
  907. let dom = document.getElementById('hidePrivacyDialog');
  908. if (dom) {
  909. dom.remove();
  910. }
  911. }
  912. },
  913. hideRoomStatus = () => {
  914. let dom = document.getElementsByClassName('web-player-icon-roomStatus')[0];
  915. if (dom) {
  916. hideOrDisplay(dom, hideRoomStatusCheckbox.checked);
  917. }
  918. },
  919. setLotteryChecked = () => {
  920. window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
  921. let dom = document.getElementById('hesitationCheckboxDiv');
  922. if (dom) {
  923. hideOrDisplay(dom, !lotteryCheckbox.checked)
  924. }
  925. },
  926. setCloseLotteryChecked = () => {
  927. window.localStorage.setItem(closeLotteryChecked, closeLotteryCheckbox.checked);
  928. },
  929. setHesitationChecked = () => {
  930. window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
  931. window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
  932. },
  933. setPublicDanmu = () => {},
  934. usePublicDanmu = () => {
  935. let key = usePublicCheckbox.checked ? pdata.defaultKey : roomId,
  936. obj = getGmValue(key, null);
  937. if (obj) {
  938. setSource(obj);
  939. }
  940. },
  941. loadData = () => {
  942. let obj = getGmValue(roomId, null),
  943. key = roomId;
  944. if (obj) {
  945. if (obj.usePublic && pdata.defaultKey) {
  946. let ps = getGmValue(pdata.defaultKey, null);
  947. if (ps) {
  948. obj.data1.values = ps.data1 ? ps.data1.values : obj.data1.values;
  949. obj.data2.values = ps.data2 ? ps.data2.values : obj.data2.values;
  950. obj.data3.values = ps.data3 ? ps.data3.values : obj.data3.values;
  951. obj.data4.values = ps.data4 ? ps.data4.values : obj.data4.values;
  952. obj.data5.values = ps.data5 ? ps.data5.values : obj.data5.values;
  953. }
  954. }
  955. if (source.version === obj.version) {
  956. source = obj;
  957. }
  958. else if (obj.version === 2) {
  959. source.data1 = obj.data1;
  960. source.data2 = obj.data2;
  961. source.data3 = obj.data3;
  962. source.data4 = obj.data4;
  963. source.data5 = obj.data5;
  964. setGmValue(key, source);
  965. }
  966. else {
  967. source.data1.values = obj.data1 ? obj.data1 : source.data1.values;
  968. source.data2.values = obj.data2 ? obj.data2 : source.data2.values;
  969. source.data3.values = obj.data3 ? obj.data3 : source.data3.values;
  970. source.data4.values = obj.data4 ? obj.data4 : source.data4.values;
  971. source.data5.values = obj.data5 ? obj.data5 : source.data5.values;
  972. setGmValue(key, source);
  973. }
  974. }
  975. if (pdata.configKey) {
  976. config = getGmValue(pdata.configKey, {});
  977. signInput.value = isNull(config.signInText) ? '' : config.signInText;
  978. hesitateInput.value = isNull(config.hesitationExpiry) ? '10' : config.hesitationExpiry;
  979. if (isNull(config.lottery)) {
  980. config.lottery = false;
  981. }
  982. if (isNull(config.closeLottery)) {
  983. config.closeLottery = false;
  984. }
  985. if (isNull(config.hesitation)) {
  986. config.hesitation = false;
  987. }
  988. }
  989. setSource(source);
  990. setOperationSetting();
  991. initData();
  992. },
  993. initSettingPanel = div => {
  994. let settingPanel = document.getElementById('danmu-setting-panel');
  995. if (div && !settingPanel) {
  996. // console.log('===> 进行面板初始化');
  997. let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
  998. if (btnSend) {
  999. buildPanel(div);
  1000. bgcolor = window.getComputedStyle(btnSend).getPropertyValue('background-color');
  1001. afterSpan.style.setProperty('background', bgcolor);
  1002. beforeSpan.style.setProperty('background', bgcolor);
  1003. dmButtonSend.style.setProperty('background', bgcolor);
  1004. dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
  1005. loadData();
  1006. // console.log('===> 面板初始化完成');
  1007. } else {
  1008. console.warn('===> 发送按钮丢失');
  1009. return false;
  1010. }
  1011. }
  1012.  
  1013. return true;
  1014. },
  1015. main = div => {
  1016. waiters[waiters.length] = workerTimer.setInterval(() => {
  1017. if (initSettingPanel(div)) {
  1018. clearWaiters();
  1019. } else {
  1020. --waitCount;
  1021. if (0 >= waitCount) {
  1022. clearWaiters();
  1023. console.log('===> 创建面板失败,停止初始化');
  1024. }
  1025. }
  1026. }, 1.5e3);
  1027. },
  1028. noSleep = () => {
  1029. if (noSleepCheckbox.checked) {
  1030. if (!noSleepTimer) {
  1031. console.log('===> 开启防休眠功能');
  1032. noSleepTimer = workerTimer.setInterval(() => {
  1033. noSleepTimeouter = workerTimer.setTimeout(() => {
  1034. workerTimer.clearTimeout(noSleepTimeouter);
  1035. document.body.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
  1036. }, Math.random() * 3e3);
  1037. }, 17e3);
  1038. }
  1039. } else {
  1040. console.log('===> 关闭防休眠功能');
  1041. if (noSleepTimer) {
  1042. workerTimer.clearInterval(noSleepTimer);
  1043. noSleepTimer = null;
  1044. }
  1045. if (noSleepTimeouter) {
  1046. workerTimer.clearTimeout(noSleepTimeouter);
  1047. noSleepTimeouter = null;
  1048. }
  1049. }
  1050. },
  1051. biliMiniClose = () => {
  1052. if (!miniCloseTimer) {
  1053. let miniCloseCount = 3;
  1054. miniCloseTimer = workerTimer.setInterval(() => {
  1055. let mini_close = document.getElementsByClassName('bili-mini-close')[0];
  1056. if (!mini_close) {
  1057. if (0 >= --miniCloseCount) {
  1058. workerTimer.clearInterval(miniCloseTimer);
  1059. miniCloseTimer = null;
  1060. }
  1061.  
  1062. return;
  1063. }
  1064.  
  1065. mini_close.click();
  1066. workerTimer.clearInterval(miniCloseTimer);
  1067. miniCloseTimer = null;
  1068. }, 10e3);
  1069. }
  1070. },
  1071. closeLottery = delay => {
  1072. let btnClose = document.getElementsByClassName('close-btn bg-contain')[0];
  1073. if (btnClose) {
  1074. if (isNull(delay)) {
  1075. btnClose.click();
  1076. } else {
  1077. closeLotteryTimer = workerTimer.setTimeout(() => {
  1078. workerTimer.clearTimeout(closeLotteryTimer);
  1079. btnClose.click();
  1080. }, delay * 1000);
  1081. }
  1082. }
  1083. },
  1084. lottery = btn => {
  1085. if (!btn) {
  1086. console.warn('===> 没有抽奖按钮DOM');
  1087. return;
  1088. }
  1089. if ('false' === window.localStorage.getItem(lotteryChecked)) {
  1090. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1091. console.log('===> 不参与天选时刻抽奖,关闭弹窗');
  1092. closeLottery();
  1093. }
  1094.  
  1095. return;
  1096. }
  1097. if ('true' === window.localStorage.getItem(hesitationChecked)) {
  1098. let expiry = window.localStorage.getItem(hesitationExpiry);
  1099. expiry = isNull(expiry) ? 10e3 : expiry * 1000;
  1100. let lotteryTimer = workerTimer.setTimeout(() => {
  1101. workerTimer.clearTimeout(lotteryTimer);
  1102. console.log('===> 犹豫期过后自动参加抽奖');
  1103. btn.click();
  1104. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1105. console.log('===> 参加成功,延迟关闭弹窗');
  1106. closeLottery(1);
  1107. }
  1108. }, expiry);
  1109. } else {
  1110. console.log('===> 立刻自动参加抽奖');
  1111. btn.click();
  1112. if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
  1113. console.log('===> 参加成功,延迟关闭弹窗');
  1114. closeLottery(1);
  1115. }
  1116. }
  1117. },
  1118. debug = () => {debugger;},
  1119. runStart = () => {
  1120. if (isOldVersion()) {
  1121. window.location.href = parentUrl;
  1122. return;
  1123. }
  1124.  
  1125. let btn = document.getElementsByClassName('particitation-btn')[0];
  1126. if (btn) {
  1127. lottery(btn);
  1128. } else {
  1129. btnLotteryTimer = workerTimer.setTimeout(() => {
  1130. workerTimer.clearTimeout(btnLotteryTimer);
  1131. btn = document.getElementsByClassName('particitation-btn')[0];
  1132. if (btn) {
  1133. lottery(btn);
  1134. }
  1135. }, 2e3);
  1136. }
  1137.  
  1138. let div = document.getElementsByClassName('bottom-actions p-relative')[0];
  1139. if (div) {
  1140. main(div);
  1141. } else {
  1142. let count = 0;
  1143. divSendBtnTimer = workerTimer.setInterval(() => {
  1144. div = document.getElementsByClassName('bottom-actions p-relative')[0];
  1145. if (div) {
  1146. workerTimer.clearInterval(divSendBtnTimer);
  1147. main(div);
  1148. } else if (count++ >= 10) {
  1149. workerTimer.clearInterval(divSendBtnTimer);
  1150. console.log(`===> 页面【${window.location.href}】没有定位位置`);
  1151. }
  1152. }, 1e3);
  1153. }
  1154. };
  1155.  
  1156. initCss();
  1157. window.debug = debug;
  1158. window.runStart = runStart;
  1159. window.arrayInfo = arrayInfo;
  1160. window.setGmNotice = setGmNotice;
  1161. window.setGmGetValue = setGmGetValue;
  1162. window.setGmSetValue = setGmSetValue;
  1163. window.setGmDelValue = setGmDelValue;
  1164. window.setParentData = setParentData;
  1165. window.autoSendDanmuModuleLoaded = true;
  1166. })();

QingJ © 2025

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