// ==UserScript==
// @version 1.5.8
// ==/UserScript==
(function () {
window.autoSendDanmuModuleLoaded = false;
const blobURL = URL.createObjectURL(
new Blob(
[
'(',
function () {
const ids = {};
self.onmessage = (e) => {
switch (e.data.command) {
case 'interval:start':
const intervalId = setInterval(() => postMessage({ message: 'interval:tick', id: e.data.id }), e.data.interval);
ids[e.data.id] = intervalId;
break;
case 'interval:clear':
clearInterval(ids[e.data.id]);
postMessage({ message: 'interval:cleared', id: e.data.id });
delete ids[e.data.id];
break;
case 'timeout:start':
const timeoutId = setTimeout(() => postMessage({ message: 'timeout:tick', id: e.data.id }), e.data.timeout);
ids[e.data.id] = timeoutId;
break;
case 'timeout:clear':
clearTimeout(ids[e.data.id]);
postMessage({ message: 'timeout:cleared', id: e.data.id });
delete ids[e.data.id];
break;
}
};
}.toString(),
')()',
],
{ type: 'application/javascript' },
),
);
const worker = new Worker(blobURL);
URL.revokeObjectURL(blobURL);
const workerTimer = {
id: 0,
callbacks: {},
setInterval: (cb, interval, context) => {
const id = ++workerTimer.id;
workerTimer.callbacks[id] = { fn: cb, context: context };
worker.postMessage({ command: 'interval:start', interval: interval, id: id });
return id;
},
setTimeout: (cb, timeout, context) => {
const id = ++workerTimer.id;
workerTimer.callbacks[id] = { fn: cb, context: context };
worker.postMessage({ command: 'timeout:start', timeout: timeout, id: id });
return id;
},
onMessage: (e) => {
switch (e.data.message) {
case 'interval:tick':
case 'timeout:tick':
const callbackItem = workerTimer.callbacks[e.data.id];
if (callbackItem && callbackItem.fn) {
callbackItem.fn.apply(callbackItem.context);
}
break;
case 'interval:cleared':
case 'timeout:cleared':
delete workerTimer.callbacks[e.data.id];
break;
}
},
clearInterval: (id) => worker.postMessage({ command: 'interval:clear', id: id }),
clearTimeout: (id) => worker.postMessage({ command: 'timeout:clear', id: id }),
};
worker.onmessage = workerTimer.onMessage.bind(workerTimer);
let source = {
version: 3,
random: true,
data1: { available: true, values: ['弹幕①', '弹幕②'] },
data2: { available: true, values: ['弹幕③', '弹幕④'] },
data3: { available: true, values: ['弹幕⑤', '弹幕⑥'] },
data4: { available: true, values: ['弹幕⑦', '弹幕⑧'] },
data5: { available: true, values: ['弹幕⑨', '弹幕Ⅹ'] }
},
signInCheckbox, hideLoginGuideCheckbox, hideHarunaCheckbox, hideShopCheckbox, noSleepCheckbox, hideGiftControlCheckbox,
hideRoomFeedCheckbox, hideRoomInfoCheckbox, hideNoticeCheckbox, hideFooterCheckbox, lotteryCheckbox, closeLotteryCheckbox, hesitationCheckbox,
hidePrivacyCheckbox, hideRoomStatusCheckbox,
rdCheckbox, group1Checkbox, group2Checkbox, group3Checkbox, group4Checkbox, group5Checkbox,
dmInput, divSetting, dataText1, dataText2, dataText3, dataText4, dataText5, signInput, hesitateInput,
dmButtonSend, beforeSpan, afterSpan, bgcolor, spanApplyTip,
pdata = {}, config = {}, waiters = [], data = [],
sendTimer = null, signInTimer = null, miniCloseTimer, noSleepTimer, noSleepTimeouter, btnLotteryTimer, divSendBtnTimer,
count = 0, waitCount = 200, arrayIndex = 0, default_timeout = 600, bgcolor_default = 'rgba(217,157,27,1)',
lotteryChecked = 'lottery_checked', closeLotteryChecked = 'close_lottery_checked', hesitationChecked = 'hesitation_checked',
hesitationExpiry = 'hesitation_expiry',
gmNotice = obj => { alert('请更新油猴脚本'); window.location.href = parentUrl; },
getGmValue = (key, defaultValue) => { return null; },
setGmValue = (key, obj) => { console.warn('===> No implementation "setGmValue" method.'); },
delGmValue = key => { console.warn('===> No implementation "delGmValue" method.'); };
const minVersion = '2.4.2', version = '1.5.8', updateTips = '新增参与天选时刻犹豫期设置', noticeTimeout = 10e3,
icoUrl = 'https://www.bilibili.com/favicon.ico',
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',
roomId = window.location.pathname.replace(/^\/(\S+\/)*/g, ''),
setGmGetValue = callback => getGmValue = callback,
setGmSetValue = callback => setGmValue = callback,
setGmDelValue = callback => delGmValue = callback,
setGmNotice = callback => gmNotice = callback,
setParentData = obj => pdata = obj,
arrayInfo = () => console.info(data),
isOldVersion = () => {
if (!pdata.version) {
return true;
}
if (minVersion === pdata.version) {
return false;
} else {
let vals = pdata.version.split('.');
let mins = minVersion.split('.');
if (vals.length != mins.length) {
return true;
} else {
for (let i = 0; i < vals.length; i++) {
if (mins[i] > vals[i]) {
return true;
}
}
return false;
}
}
},
initCss = () => {
let linkElement = document.createElement('link');
linkElement.rel = 'stylesheet';
linkElement.href = 'https://unpkg.com/[email protected]/lib/theme-chalk/index.css';
document.head.appendChild(linkElement);
let customerStyle = document.createElement('style');
customerStyle.setAttribute('type', 'text/css');
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:60%;}.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{text-align:center;color:#0b81cc;font-size:12px;font-weight:700;cursor:help;}.disabled{color:#aaaaaa;cursor:not-allowed;}.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;}';
document.head.appendChild(customerStyle);
},
getCurrentTimestamp = () => new Date().getTime(),
send = (msg, index) => {
let dmTextArea = document.getElementById('aside-area-vm').getElementsByClassName('chat-input border-box')[0];
if (!dmTextArea) {
alert('找不到输入弹幕文本框,请尝试刷新页面');
return;
}
let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
if (!btnSend) {
alert('找不到发送按钮,请尝试刷新页面');
return;
}
dmTextArea.value = msg;
dmTextArea.dispatchEvent(new Event('input', { "bubbles": true, "cancelable": true }));
btnSend.click();
lastSent = getCurrentTimestamp();
},
isNull = str => {
if (!str || str == "") {
return true;
}
let regu = "^[ ]+$";
let re = new RegExp(regu);
return re.test(str);
},
randomSort = arr => {
for (let i = 0; i < arr.length; i++) {
const rdIndex = Math.floor(Math.random() * arr.length);
const temp = arr[i];
arr[i] = arr[rdIndex];
arr[rdIndex] = temp;
}
return arr;
},
clearWaiters = () => {
for (let i = 0; i < waiters.length; i++) {
workerTimer.clearInterval(waiters[i]);
waiters[i] = null;
}
waiters = [];
},
signIn = () => {
if (signInCheckbox.checked) {
if (!signInTimer) {
let defaultText = isNull(pdata.signText) ? pdata.signText : '打卡';
let timestamp = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()).getTime() - getCurrentTimestamp();
console.log('===> 设置凌晨打卡定时器【' + timestamp + '】');
signInput.value = isNull(config.signInText) ? defaultText : config.signInText;
signInTimer = workerTimer.setTimeout(() => {
send(isNull(signInput.value) ? defaultText : signInput.value, 0);
console.log('===> 设置下一次打卡');
workerTimer.clearTimeout(signInTimer);
signInTimer = null;
signIn();
}, timestamp);
}
} else if (signInTimer) {
console.log('===> 关闭自动打卡功能');
workerTimer.clearTimeout(signInTimer);
signInTimer = null;
}
},
runCheckbox = () => {
hideFooter();
hideGiftControl();
hideLoginGuide();
hideHaruna();
hideShop();
noSleep();
signIn();
hidePrivacy();
hideRoomStatus();
setLotteryChecked();
setHesitationChecked();
setCloseLotteryChecked();
hideRoomFeed();
hideRoomInfo();
hideNotice();
let hideTimeout = workerTimer.setTimeout(() => {
workerTimer.clearTimeout(hideTimeout);
hideRoomFeed();
hideRoomInfo();
hideNotice();
}, 1e3);
},
setCheckboxChecked = () => {
rdCheckbox.checked = source.random;
group1Checkbox.checked = source.data1.available;
group2Checkbox.checked = source.data2.available;
group3Checkbox.checked = source.data3.available;
group4Checkbox.checked = source.data4.available;
group5Checkbox.checked = source.data5.available;
signInCheckbox.checked = config.autoSignIn;
noSleepCheckbox.checked = config.noSleep;
hideLoginGuideCheckbox.checked = config.hideLoginGuide;
hideHarunaCheckbox.checked = config.hideHaruna;
hideShopCheckbox.checked = config.hideShop;
hideGiftControlCheckbox.checked = config.hideGift;
hideRoomFeedCheckbox.checked = config.hideRoomFeed;
hideRoomInfoCheckbox.checked = config.hideRoomInfo;
hideNoticeCheckbox.checked = config.hideNotice;
hideFooterCheckbox.checked = config.hideFooter;
lotteryCheckbox.checked = config.lottery;
hesitationCheckbox.checked = config.hesitation;
closeLotteryCheckbox.checked = config.closeLottery;
hidePrivacyCheckbox.checked = config.noPrivacy;
hideRoomStatusCheckbox.checked = config.hideWatermark;
runCheckbox();
},
openSetting = () => divSetting.style.display = 'block',
closeSetting = () => {
setCheckboxChecked();
divSetting.style.display = 'none';
},
initData = () => {
if (source.data1.values.length <= 0
&& source.data2.values.length <= 0
&& source.data3.values.length <= 0
&& source.data4.values.length <= 0
&& source.data5.values.length <= 0) {
return data ? data : [];
}
let result = [];
result = source.data1.available ? result.concat(source.data1.values) : result;
result = source.data2.available ? result.concat(source.data2.values) : result;
result = source.data3.available ? result.concat(source.data3.values) : result;
result = source.data4.available ? result.concat(source.data4.values) : result;
result = source.data5.available ? result.concat(source.data5.values) : result;
data = result;
rdCheckbox.checked ? data = randomSort(result) : arrayIndex = 0;
},
save = () => {
source.data1.values = isNull(dataText1.value) ? [] : dataText1.value.split('|');
source.data2.values = isNull(dataText2.value) ? [] : dataText2.value.split('|');
source.data3.values = isNull(dataText3.value) ? [] : dataText3.value.split('|');
source.data4.values = isNull(dataText4.value) ? [] : dataText4.value.split('|');
source.data5.values = isNull(dataText5.value) ? [] : dataText5.value.split('|');
source.random = rdCheckbox.checked;
source.data1.available = group1Checkbox.checked;
source.data2.available = group2Checkbox.checked;
source.data3.available = group3Checkbox.checked;
source.data4.available = group4Checkbox.checked;
source.data5.available = group5Checkbox.checked;
initData();
setGmValue(roomId, source);
if (pdata.configKey) {
config.autoSignIn = signInCheckbox.checked;
config.signInText = signInput.value;
config.noSleep = noSleepCheckbox.checked;
config.hideLoginGuide = hideLoginGuideCheckbox.checked;
config.hideHaruna = hideHarunaCheckbox.checked;
config.hideShop = hideShopCheckbox.checked;
config.hideGift = hideGiftControlCheckbox.checked;
config.hideRoomFeed = hideRoomFeedCheckbox.checked;
config.hideRoomInfo = hideRoomInfoCheckbox.checked;
config.hideNotice = hideNoticeCheckbox.checked;
config.hideFooter = hideFooterCheckbox.checked;
config.lottery = lotteryCheckbox.checked;
window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
config.hesitation = hesitationCheckbox.checked;
window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
config.hesitationExpiry = hesitateInput.value;
window.localStorage.setItem(hesitationExpiry, hesitateInput.value);
config.closeLottery = closeLotteryCheckbox.checked;
window.localStorage.setItem(closeLotteryChecked, config.closeLottery);
config.noPrivacy = hidePrivacyCheckbox.checked;
config.hideWatermark = hideRoomStatusCheckbox.checked;
setGmValue(pdata.configKey, config);
}
spanApplyTip.style.display = 'block';
let closeSettingTimer = workerTimer.setTimeout(() => {
workerTimer.clearTimeout(closeSettingTimer);
spanApplyTip.style.display = 'none';
divSetting.style.display = 'none';
}, 1.5e3);
},
danmu = () => {
if (data.length < 1) {
alert('请先设置弹幕');
return false;
}
if (rdCheckbox.checked) {
arrayIndex = Math.floor((Math.random() * data.length));
}
send(data[arrayIndex], arrayIndex);
++arrayIndex;
if (arrayIndex >= data.length) {
arrayIndex = 0;
}
return true;
},
offOrOn = () => {
let timeout = 0;
if (sendTimer) {
workerTimer.clearInterval(sendTimer);
sendTimer = null;
dmButtonSend.style.background = isNull(bgcolor) ? bgcolor_default : bgcolor;
dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
dmButtonSend.textContent = '开始';
dmInput.removeAttribute("disabled");
} else {
timeout = (isNull(dmInput.value) ? default_timeout : dmInput.value) * 1e3;
if (!danmu()) {
return;
}
sendTimer = workerTimer.setInterval(danmu, timeout);
dmButtonSend.style.background = 'rgba(255,0,0,1)';
dmButtonSend.style.setProperty('--color', 'rgba(255,0,0,0.8)');
dmButtonSend.textContent = '停止';
dmInput.setAttribute('disabled', 'disabled');
}
},
createSwitch = (id, txt, title, func, container, indent, hidden, rear) => {
let checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = id;
checkbox.checked = false;
checkbox.addEventListener('click', func);
let lblCheckbox = document.createElement('label');
lblCheckbox.setAttribute('for', id);
lblCheckbox.classList.add('switch-check-label');
let descCheckbox = document.createElement('span');
descCheckbox.textContent = txt;
descCheckbox.title = title;
descCheckbox.classList.add('danmu-random-switch-button-title');
let divCheckbox = document.createElement('div');
divCheckbox.id = id + 'Div';
divCheckbox.classList.add('switch-check');
divCheckbox.classList.add('switch-check-group');
divCheckbox.appendChild(checkbox);
divCheckbox.appendChild(lblCheckbox);
divCheckbox.appendChild(descCheckbox);
if (!isNull(indent)) {
divCheckbox.style.marginLeft = indent;
}
if (hidden) {
divCheckbox.style.setProperty('display', 'none');
}
if (rear) {
divCheckbox.appendChild(rear);
}
container.appendChild(divCheckbox);
return checkbox;
},
buildPanel = divButton => {
/* ----------------------------------------- head ----------------------------------------- */
let divSettingTitle = document.createElement('div');
divSettingTitle.textContent = '弹幕设置';
divSettingTitle.classList.add('danmu-random-setting-title');
let divSub = document.createElement('div');
divSub.textContent = version;
divSub.classList.add('danmu-random-setting-title-sub');
divSettingTitle.appendChild(divSub);
let divTip = document.createElement('div');
divTip.classList.add('danmu-random-setting-tips');
divTip.innerHTML = '任一分组内输入弹幕即可,多条用<span style="color:#dc6b07;margin:0 2px 0 4px;font-weight:700;font-style:normal;">竖线</span>分隔';
let divUpdateTip = document.createElement('div');
divUpdateTip.classList.add('danmu-random-update-tips');
divUpdateTip.innerHTML = `<span style="color:#f00">更新提示:</span>${updateTips}`;
/* ----------------------------------------- head ----------------------------------------- */
/* ----------------------------------------- textarea 1 ----------------------------------------- */
let divText1 = document.createElement('div');
divText1.textContent = '分组 1 :';
divText1.classList.add('danmu-group-title');
group1Checkbox = document.createElement('input');
group1Checkbox.type = 'checkbox';
group1Checkbox.id = 'group1Checkbox';
group1Checkbox.checked = true;
let lblGroup1Checkbox = document.createElement('label');
lblGroup1Checkbox.setAttribute('for', 'group1Checkbox');
lblGroup1Checkbox.classList.add('switch-check-label');
let divGroup1Checkbox = document.createElement('div');
divGroup1Checkbox.classList.add('switch-check');
divGroup1Checkbox.appendChild(group1Checkbox);
divGroup1Checkbox.appendChild(lblGroup1Checkbox);
dataText1 = document.createElement('textarea');
dataText1.classList.add('danmu-group-textarea');
dataText1.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
/* ----------------------------------------- textarea 1 ----------------------------------------- */
/* ----------------------------------------- textarea 2 ----------------------------------------- */
let divText2 = document.createElement('div');
divText2.textContent = '分组 2 :';
divText2.classList.add('danmu-group-title');
group2Checkbox = document.createElement('input');
group2Checkbox.type = 'checkbox';
group2Checkbox.id = 'group2Checkbox';
group2Checkbox.checked = true;
let lblGroup2Checkbox = document.createElement('label');
lblGroup2Checkbox.setAttribute('for', 'group2Checkbox');
lblGroup2Checkbox.classList.add('switch-check-label');
let divGroup2Checkbox = document.createElement('div');
divGroup2Checkbox.classList.add('switch-check');
divGroup2Checkbox.appendChild(group2Checkbox);
divGroup2Checkbox.appendChild(lblGroup2Checkbox);
dataText2 = document.createElement('textarea');
dataText2.classList.add('danmu-group-textarea');
dataText2.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
/* ----------------------------------------- textarea 2 ----------------------------------------- */
/* ----------------------------------------- textarea 3 ----------------------------------------- */
let divText3 = document.createElement('div');
divText3.textContent = '分组 3 :';
divText3.classList.add('danmu-group-title');
group3Checkbox = document.createElement('input');
group3Checkbox.type = 'checkbox';
group3Checkbox.id = 'group3Checkbox';
group3Checkbox.checked = true;
let lblGroup3Checkbox = document.createElement('label');
lblGroup3Checkbox.setAttribute('for', 'group3Checkbox');
lblGroup3Checkbox.classList.add('switch-check-label');
let divGroup3Checkbox = document.createElement('div');
divGroup3Checkbox.classList.add('switch-check');
divGroup3Checkbox.appendChild(group3Checkbox);
divGroup3Checkbox.appendChild(lblGroup3Checkbox);
dataText3 = document.createElement('textarea');
dataText3.classList.add('danmu-group-textarea');
dataText3.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
/* ----------------------------------------- textarea 3 ----------------------------------------- */
/* ----------------------------------------- textarea 4 ----------------------------------------- */
let divText4 = document.createElement('div');
divText4.textContent = '分组 4 :';
divText4.classList.add('danmu-group-title');
group4Checkbox = document.createElement('input');
group4Checkbox.type = 'checkbox';
group4Checkbox.id = 'group4Checkbox';
group4Checkbox.checked = true;
let lblGroup4Checkbox = document.createElement('label');
lblGroup4Checkbox.setAttribute('for', 'group4Checkbox');
lblGroup4Checkbox.classList.add('switch-check-label');
let divGroup4Checkbox = document.createElement('div');
divGroup4Checkbox.classList.add('switch-check');
divGroup4Checkbox.appendChild(group4Checkbox);
divGroup4Checkbox.appendChild(lblGroup4Checkbox);
dataText4 = document.createElement('textarea');
dataText4.classList.add('danmu-group-textarea');
dataText4.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
/* ----------------------------------------- textarea 4 ----------------------------------------- */
/* ----------------------------------------- textarea 5 ----------------------------------------- */
let divText5 = document.createElement('div');
divText5.textContent = '分组 5 :';
divText5.classList.add('danmu-group-title');
group5Checkbox = document.createElement('input');
group5Checkbox.type = 'checkbox';
group5Checkbox.id = 'group5Checkbox';
group5Checkbox.checked = true;
let lblGroup5Checkbox = document.createElement('label');
lblGroup5Checkbox.setAttribute('for', 'group5Checkbox');
lblGroup5Checkbox.classList.add('switch-check-label');
let divGroup5Checkbox = document.createElement('div');
divGroup5Checkbox.classList.add('switch-check');
divGroup5Checkbox.appendChild(group5Checkbox);
divGroup5Checkbox.appendChild(lblGroup5Checkbox);
dataText5 = document.createElement('textarea');
dataText5.classList.add('danmu-group-textarea');
dataText5.setAttribute('placeholder', '请输入弹幕,多条弹幕请用“|”分隔');
/* ----------------------------------------- textarea 5 ----------------------------------------- */
/* ----------------------------------------- chackbox group ----------------------------------------- */
let divCheckboxGroup = document.createElement('div');
divCheckboxGroup.style.margin = '20px 0 10px';
let divGlobalSettingTip = document.createElement('div');
divGlobalSettingTip.textContent = '以下设置保存之后,其它直播间需刷新才能适用';
divGlobalSettingTip.title = '请刷新其它直播间页面应用设置';
divGlobalSettingTip.classList.add('global-setting-tip');
divGlobalSettingTip.classList.add('switch-check-group');
divCheckboxGroup.appendChild(divGlobalSettingTip);
signInput = document.createElement('input');
signInput.style.border = '0';
signInput.style.width = '145px';
signInput.setAttribute('placeholder', '输入零点打卡发送的文字');
hesitateInput = document.createElement('input');
hesitateInput.style.border = '0';
hesitateInput.style.width = '55px';
hesitateInput.setAttribute('placeholder', '单位:秒');
hesitateInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
signInCheckbox = createSwitch('signInCheckbox', '打卡弹幕:', '每日零点发送一条打卡弹幕', signIn, divCheckboxGroup, null, false, signInput);
lotteryCheckbox = createSwitch('lotteryCheckbox', '自动参与天选时刻抽奖(需登录(不可用))', '自动点击参与按钮,请确保已经登录(不可用)了阿B账号', setLotteryChecked, divCheckboxGroup);
hesitationCheckbox = createSwitch('hesitationCheckbox', '犹豫期:', '不立刻参与天选时刻,这期间可以手动处理,免得自动参加后后悔(时间单位:秒)', setHesitationChecked, divCheckboxGroup, '20px', true, hesitateInput);
closeLotteryCheckbox = createSwitch('closeLotteryCheckbox', '关闭天选时刻', '关闭天选时刻弹窗', setCloseLotteryChecked, divCheckboxGroup);
noSleepCheckbox = createSwitch('noSleepCheckbox', '防止直播间休眠', '防止直播间页面一段时间没操作之后进入休眠', noSleep, divCheckboxGroup);
hideLoginGuideCheckbox = createSwitch('hideLoginGuideCheckbox', '隐藏播放器底部登录(不可用)提示', '隐藏未登录(不可用)时播放器底部显示的登录(不可用)提示', hideLoginGuide, divCheckboxGroup);
hideHarunaCheckbox = createSwitch('hideHarunaCheckbox', '隐藏看板娘立绘', '隐藏直播间Haruna立绘', hideHaruna, divCheckboxGroup);
hideShopCheckbox = createSwitch('hideShopCheckbox', '隐藏购物提示', '隐藏播放器左上角的商店购物提示', hideShop, divCheckboxGroup);
hideGiftControlCheckbox = createSwitch('hideGiftControlCheckbox', '隐藏礼物栏', '隐藏播放器底部的礼物栏', hideGiftControl, divCheckboxGroup);
hideRoomFeedCheckbox = createSwitch('hideRoomFeedCheckbox', '隐藏主播动态', '隐藏播放器底下主播的动态栏', hideRoomFeed, divCheckboxGroup);
hideRoomInfoCheckbox = createSwitch('hideRoomInfoCheckbox', '隐藏主播荣耀、简介', '隐藏播放器底下主播的荣耀勋章和简介', hideRoomInfo, divCheckboxGroup);
hideNoticeCheckbox = createSwitch('hideNoticeCheckbox', '隐藏主播公告', '隐藏弹幕列表底下主播的公告', hideNotice, divCheckboxGroup);
hideFooterCheckbox = createSwitch('hideFooterCheckbox', '隐藏直播间页脚', '隐藏直播间底部的网页页脚', hideFooter, divCheckboxGroup);
hidePrivacyCheckbox = createSwitch('hidePrivacyCheckbox', '隐藏隐私提示对话框', '隐藏隐私提示登录(不可用)的对话框,被打码的昵称不保证变回正常', hidePrivacy, divCheckboxGroup);
hideRoomStatusCheckbox = createSwitch('hideRoomStatusCheckbox', '隐藏直播水印', '隐藏播放器左上角的直播水印', hideRoomStatus, divCheckboxGroup);
/* ----------------------------------------- chackbox group ----------------------------------------- */
/* ----------------------------------------- div tip ----------------------------------------- */
spanApplyTip = document.createElement('span');
spanApplyTip.textContent = '设置成功';
spanApplyTip.classList.add('danmu-random-setting-success-text');
let divApplyTip = document.createElement('div');
divApplyTip.classList.add('danmu-random-setting-success-tips');
divApplyTip.appendChild(spanApplyTip);
/* ----------------------------------------- div tip ----------------------------------------- */
/* ----------------------------------------- save and close button ----------------------------------------- */
let btnSaveSetting = document.createElement('i');
btnSaveSetting.setAttribute('title', '保存');
btnSaveSetting.style.padding = '5px';
btnSaveSetting.classList.add('el-button');
btnSaveSetting.classList.add('el-icon-check');
btnSaveSetting.classList.add('is-circle');
btnSaveSetting.addEventListener('click', save);
let btnCloseSetting = document.createElement('i');
btnCloseSetting.setAttribute('title', '关闭');
btnCloseSetting.style.padding = '5px';
btnCloseSetting.classList.add('el-button');
btnCloseSetting.classList.add('el-icon-close');
btnCloseSetting.classList.add('is-circle');
btnCloseSetting.addEventListener('click', closeSetting);
let divSettingButton = document.createElement('div');
divSettingButton.classList.add('danmu-random-set-button-container');
divSettingButton.appendChild(btnSaveSetting);
divSettingButton.appendChild(btnCloseSetting);
/* ----------------------------------------- save and close button ----------------------------------------- */
/* ----------------------------------------- random chackbox ----------------------------------------- */
rdCheckbox = document.createElement('input');
rdCheckbox.type = 'checkbox';
rdCheckbox.id = 'rdCheckbox';
rdCheckbox.checked = true;
// rdCheckbox.addEventListener('click', selectRandom);
lblCheckbox = document.createElement('label');
lblCheckbox.setAttribute('for', 'rdCheckbox');
lblCheckbox.classList.add('switch-check-label');
descCheckbox = document.createElement('span');
descCheckbox.textContent = '随机从上面的弹幕中选出一条发送';
descCheckbox.title = '将合并所有分组数据,从中随机选出一条发送';
descCheckbox.classList.add('danmu-random-switch-button-title');
divCheckbox = document.createElement('div');
divCheckbox.classList.add('switch-check');
divCheckbox.appendChild(rdCheckbox);
divCheckbox.appendChild(lblCheckbox);
divCheckbox.appendChild(descCheckbox);
/* ----------------------------------------- random chackbox ----------------------------------------- */
/* ----------------------------------------- container ----------------------------------------- */
let divBottomContainer = document.createElement('div');
divBottomContainer.classList.add('danmu-random-setting-bottom');
divBottomContainer.appendChild(divApplyTip);
divBottomContainer.appendChild(divSettingButton);
let divContainer = document.createElement('div');
divContainer.style.height = 'calc(98% - 30px - 25px)';
divContainer.appendChild(divText1);
divContainer.appendChild(divGroup1Checkbox);
divContainer.appendChild(dataText1);
divContainer.appendChild(divText2);
divContainer.appendChild(divGroup2Checkbox);
divContainer.appendChild(dataText2);
divContainer.appendChild(divText3);
divContainer.appendChild(divGroup3Checkbox);
divContainer.appendChild(dataText3);
divContainer.appendChild(divText4);
divContainer.appendChild(divGroup4Checkbox);
divContainer.appendChild(dataText4);
divContainer.appendChild(divText5);
divContainer.appendChild(divGroup5Checkbox);
divContainer.appendChild(dataText5);
divContainer.appendChild(divCheckbox);
divContainer.appendChild(divCheckboxGroup);
divContainer.appendChild(divBottomContainer);
/* ----------------------------------------- container ----------------------------------------- */
divSetting = document.createElement('div');
divSetting.id = 'danmu-setting-panel';
divSetting.classList.add('danmu-random-setting-panel');
divSetting.appendChild(divSettingTitle);
divSetting.appendChild(divUpdateTip);
divSetting.appendChild(divTip);
divSetting.appendChild(divContainer);
let asideAreaVm = document.getElementById('aside-area-vm');
asideAreaVm.appendChild(divSetting);
/* ----------------------------------------- function ----------------------------------------- */
dmButtonSend = document.createElement('button');
dmButtonSend.textContent = '开始';
dmButtonSend.classList.add('danmu-btn');
dmButtonSend.style.setProperty('--color', 'rgba(217,157,27,0.8)');
//dmButtonSend.onclick = function() { alert('Hello world');}
dmButtonSend.addEventListener('click', offOrOn);
beforeSpan = document.createElement('span');
beforeSpan.textContent = '每';
beforeSpan.classList.add('danmu-text-span');
beforeSpan.style.marginLeft = '4px';
dmInput = document.createElement('input');
dmInput.value = default_timeout;
dmInput.classList.add('danmu-second-input');
dmInput.setAttribute('oninput', "this.value = this.value.replace(/[^0-9]/g, '')");
afterSpan = document.createElement('span');
afterSpan.textContent = '秒发送';
afterSpan.classList.add('danmu-text-span');
afterSpan.style.marginRight = '4px';
let iElement = document.createElement('i');
iElement.classList.add('el-icon-setting');
let btnSetting = document.createElement('button');
btnSetting.title = '设置';
btnSetting.classList.add('el-button');
btnSetting.classList.add('el-button--mini');
btnSetting.classList.add('is-circle');
btnSetting.addEventListener('click', openSetting);
btnSetting.appendChild(iElement);
let div = document.createElement('div');
div.style.position = 'absolute';
div.appendChild(dmButtonSend);
div.appendChild(beforeSpan);
div.appendChild(dmInput);
div.appendChild(afterSpan);
div.appendChild(btnSetting);
divButton.appendChild(div);
/* ----------------------------------------- function ----------------------------------------- */
},
hideOrDisplay = (dom, hidden) => {
if (hidden) {
dom.style.setProperty('display', 'none', 'important');
} else {
dom.style.removeProperty('display');
}
},
removeAttribute = (dom, attr) => {
dom.removeAttribute(attr);
if (0 < dom.children.length) {
for (let i = 0; i < dom.children.length; i++) {
removeAttribute(dom.children[i], attr);
}
}
},
setAttribute = (dom, attr, val) => {
dom.setAttribute(attr, val);
if (0 < dom.children.length) {
for (let i = 0; i < dom.children.length; i++) {
setAttribute(dom.children[i], attr, val);
}
}
},
hideLoginGuide = () => {
let dom = document.getElementById('switch-login-guide-vm');
if (dom) {
hideOrDisplay(dom, hideLoginGuideCheckbox.checked);
}
},
hideHaruna = () => {
let dom = document.getElementById('my-dear-haruna-vm');
if (dom) {
hideOrDisplay(dom, hideHarunaCheckbox.checked);
}
},
hideShop = () => {
let dom = document.getElementById('shop-popover-vm');
if (dom) {
hideOrDisplay(dom, hideShopCheckbox.checked);
}
},
hideGiftControl = () => {
let dom = document.getElementsByClassName('gift-control-section')[0];
if (dom) {
hideOrDisplay(dom, hideGiftControlCheckbox.checked);
}
dom = document.getElementById('web-player__bottom-bar__container');
if (dom) {
hideOrDisplay(dom, hideGiftControlCheckbox.checked);
}
dom = document.getElementsByTagName('video');
for (let i = 0; i < dom.length; i++) {
if (!dom[i]) {
return;
}
if (hideGiftControlCheckbox.checked) {
dom[i].style.setProperty('height', '100%');
} else if (document.body.classList.contains('player-full-win') || document.body.classList.contains('fullscreen-fix')) {
dom[i].style.setProperty('height', 'calc(100% - 114px)');
}
}
},
hideRoomFeed = () => {
let dom = document.getElementsByClassName('room-feed')[0];
if (dom) {
hideOrDisplay(dom, hideRoomFeedCheckbox.checked);
}
dom = document.getElementsByClassName('flip-view p-relative')[0];
if (dom) {
hideOrDisplay(dom, hideRoomFeedCheckbox.checked);
}
},
hideRoomInfo = () => {
let dom = document.getElementsByClassName('room-info-ctnr')[0];
if (dom) {
hideOrDisplay(dom, hideRoomInfoCheckbox.checked);
}
},
hideNotice = () => {
let dom = document.getElementsByClassName('right-container')[0];
if (dom) {
dom.style.setProperty('min-height', 'auto');
hideOrDisplay(dom, hideNoticeCheckbox.checked);
}
},
hideFooter = () => {
let dom = document.getElementById('link-footer-vm');
if (dom) {
hideOrDisplay(dom, hideFooterCheckbox.checked);
}
},
hidePrivacy = () => {
if (hidePrivacyCheckbox.checked) {
let dom = document.createElement('style');
dom.id = 'hidePrivacyDialog';
dom.setAttribute('type', 'text/css');
dom.innerHTML = '.privacy-dialog{display:none !important;}';
document.head.appendChild(dom);
} else {
let dom = document.getElementById('hidePrivacyDialog');
if (dom) {
dom.remove();
}
}
},
hideRoomStatus = () => {
let dom = document.getElementsByClassName('web-player-icon-roomStatus')[0];
if (dom) {
hideOrDisplay(dom, hideRoomStatusCheckbox.checked);
}
},
setLotteryChecked = () => {
window.localStorage.setItem(lotteryChecked, lotteryCheckbox.checked);
let dom = document.getElementById('hesitationCheckboxDiv');
if (dom) {
hideOrDisplay(dom, !lotteryCheckbox.checked)
}
},
setCloseLotteryChecked = () => {
window.localStorage.setItem(closeLotteryChecked, closeLotteryCheckbox.checked);
},
setHesitationChecked = () => {
window.localStorage.setItem(hesitationChecked, hesitationCheckbox.checked);
},
loadData = () => {
let obj = getGmValue(roomId, null);
if (obj) {
if (source.version === obj.version) {
source = obj;
}
else if (obj.version === 2) {
source.data1 = obj.data1;
source.data2 = obj.data2;
source.data3 = obj.data3;
source.data4 = obj.data4;
source.data5 = obj.data5;
setGmValue(roomId, source);
} else {
source.data1.values = obj.data1 ? obj.data1 : source.data1.values;
source.data2.values = obj.data2 ? obj.data2 : source.data2.values;
source.data3.values = obj.data3 ? obj.data3 : source.data3.values;
source.data4.values = obj.data4 ? obj.data4 : source.data4.values;
source.data5.values = obj.data5 ? obj.data5 : source.data5.values;
setGmValue(roomId, source);
}
}
if (pdata.configKey) {
config = getGmValue(pdata.configKey, {});
signInput.value = isNull(config.signInText) ? '' : config.signInText;
hesitateInput.value = isNull(config.hesitationExpiry) ? '10' : config.hesitationExpiry;
if (isNull(config.lottery)) {
config.lottery = false;
}
if (isNull(config.closeLottery)) {
config.closeLottery = false;
}
if (isNull(config.hesitation)) {
config.hesitation = false;
}
}
setCheckboxChecked();
dataText1.value = source.data1.values.join('|');
dataText2.value = source.data2.values.join('|');
dataText3.value = source.data3.values.join('|');
dataText4.value = source.data4.values.join('|');
dataText5.value = source.data5.values.join('|');
initData();
},
initSettingPanel = div => {
let settingPanel = document.getElementById('danmu-setting-panel');
if (div && !settingPanel) {
// console.log('===> 进行面板初始化');
let btnSend = document.getElementsByClassName('bl-button bl-button--primary')[0];
if (btnSend) {
buildPanel(div);
bgcolor = window.getComputedStyle(btnSend).getPropertyValue('background-color');
afterSpan.style.setProperty('background', bgcolor);
beforeSpan.style.setProperty('background', bgcolor);
dmButtonSend.style.setProperty('background', bgcolor);
dmButtonSend.style.setProperty('--color', bgcolor.replace(')', ', 0.8)'));
loadData();
// console.log('===> 面板初始化完成');
} else {
console.warn('===> 发送按钮丢失');
return false;
}
}
return true;
},
main = div => {
waiters[waiters.length] = workerTimer.setInterval(() => {
if (initSettingPanel(div)) {
clearWaiters();
} else {
--waitCount;
if (0 >= waitCount) {
clearWaiters();
console.log('===> 创建面板失败,停止初始化');
}
}
}, 1.5e3);
},
noSleep = () => {
if (noSleepCheckbox.checked) {
if (!noSleepTimer) {
console.log('===> 开启防休眠功能');
noSleepTimer = workerTimer.setInterval(() => {
noSleepTimeouter = workerTimer.setTimeout(() => {
workerTimer.clearTimeout(noSleepTimeouter);
document.body.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
}, Math.random() * 3e3);
}, 17e3);
}
} else {
console.log('===> 关闭防休眠功能');
if (noSleepTimer) {
workerTimer.clearInterval(noSleepTimer);
noSleepTimer = null;
}
if (noSleepTimeouter) {
workerTimer.clearTimeout(noSleepTimeouter);
noSleepTimeouter = null;
}
}
},
biliMiniClose = () => {
if (!miniCloseTimer) {
let miniCloseCount = 3;
miniCloseTimer = workerTimer.setInterval(() => {
let mini_close = document.getElementsByClassName('bili-mini-close')[0];
if (!mini_close) {
if (0 >= --miniCloseCount) {
workerTimer.clearInterval(miniCloseTimer);
miniCloseTimer = null;
}
return;
}
mini_close.click();
workerTimer.clearInterval(miniCloseTimer);
miniCloseTimer = null;
}, 10e3);
}
},
closeLottery = delay => {
let btnClose = document.getElementsByClassName('close-btn bg-contain')[0];
if (btnClose) {
if (isNull(delay)) {
btnClose.click();
} else {
closeLotteryTimer = workerTimer.setTimeout(() => {
workerTimer.clearTimeout(closeLotteryTimer);
btnClose.click();
}, delay * 1000);
}
}
},
lottery = btn => {
if (!btn) {
console.warn('===> 没有抽奖按钮DOM');
return;
}
if ('false' === window.localStorage.getItem(lotteryChecked)) {
if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
console.log('===> 不参与天选时刻抽奖,关闭弹窗');
closeLottery();
}
return;
}
if ('true' === window.localStorage.getItem(hesitationChecked)) {
let expiry = window.localStorage.getItem(hesitationExpiry);
expiry = isNull(expiry) ? 10e3 : expiry * 1000;
let lotteryTimer = workerTimer.setTimeout(() => {
workerTimer.clearTimeout(lotteryTimer);
console.log('===> 犹豫期过后自动参加抽奖');
btn.click();
if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
console.log('===> 参加成功,延迟关闭弹窗');
closeLottery(1);
}
}, expiry);
} else {
console.log('===> 立刻自动参加抽奖');
btn.click();
if ('true' === window.localStorage.getItem(closeLotteryChecked)) {
console.log('===> 参加成功,延迟关闭弹窗');
closeLottery(1);
}
}
},
debug = () => {debugger;},
runStart = () => {
if (isOldVersion()) {
window.location.href = parentUrl;
return;
}
let btn = document.getElementsByClassName('particitation-btn')[0];
if (btn) {
lottery(btn);
} else {
btnLotteryTimer = workerTimer.setTimeout(() => {
workerTimer.clearTimeout(btnLotteryTimer);
btn = document.getElementsByClassName('particitation-btn')[0];
if (btn) {
lottery(btn);
}
}, 2e3);
}
let div = document.getElementsByClassName('bottom-actions p-relative')[0];
if (div) {
main(div);
} else {
let count = 0;
divSendBtnTimer = workerTimer.setInterval(() => {
div = document.getElementsByClassName('bottom-actions p-relative')[0];
if (div) {
workerTimer.clearInterval(divSendBtnTimer);
main(div);
} else if (count++ >= 10) {
workerTimer.clearInterval(divSendBtnTimer);
console.log(`===> 页面【${window.location.href}】没有定位位置`);
}
}, 1e3);
}
};
initCss();
window.debug = debug;
window.runStart = runStart;
window.arrayInfo = arrayInfo;
window.setGmNotice = setGmNotice;
window.setGmGetValue = setGmGetValue;
window.setGmSetValue = setGmSetValue;
window.setGmDelValue = setGmDelValue;
window.setParentData = setParentData;
window.autoSendDanmuModuleLoaded = true;
})();