Add toggle danmaku keymap

This commit is contained in:
the1812 2019-08-25 23:38:01 +08:00
parent 274882cee4
commit 883f42cf52
6 changed files with 24 additions and 15 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{return(t,e)=>{(async()=>{if(!/^https:\/\/live\.bilibili\.com\/[\d]+/.test(document.URL)){return}const t=await SpinQuery.select(".chat-popups-section");console.log(t);if(!t){console.warn("[自动领奖] 未能找到弹窗容器");return}Observer.childListSubtree(t,()=>{let t;while(true){console.log("draw button = ",dq(".chat-popups-section .draw>span:nth-child(3)"));t=dq(".chat-popups-section .draw>span:nth-child(3)");if(t===null){break}t.click()}})})()}})();
(()=>{return(t,n)=>{(async()=>{if(!/^https:\/\/live\.bilibili\.com\/[\d]+/.test(document.URL)){return}const t=await SpinQuery.condition(()=>dq(".chat-popups-section"),t=>t.querySelector("chat-draw-area")===null);if(!t){console.warn("[自动领奖] 未能找到弹窗容器");return}Observer.childListSubtree(t,()=>{let n;const c=()=>{console.log("draw button = ",dq(".chat-popups-section .draw>span:nth-child(3)"));console.log(t);n=dq(".chat-popups-section .draw>span:nth-child(3)");if(n===null&&dq(".chat-popups-section chat-draw-area")===null){return}if(n!==null){n.click()}};c()})})()}})();

2
min/keymap.min.js vendored
View File

@ -1 +1 @@
(()=>{return(e,i)=>{const t={w:".bilibili-player-video-web-fullscreen",t:".bilibili-player-video-btn-widescreen",r:".bilibili-player-video-btn-repeat",m:".bilibili-player-video-btn-volume .bilibili-player-iconfont-volume"};document.body.addEventListener("keydown",e=>{if(document.activeElement&&["input","textarea"].includes(document.activeElement.nodeName.toLowerCase())){return}const i=e.key.toLowerCase();if(i in t){console.log(i);e.stopPropagation();e.preventDefault();dq(t[i]).click()}})}})();
(()=>{return(e,i)=>{const t={w:".bilibili-player-video-web-fullscreen",t:".bilibili-player-video-btn-widescreen",r:".bilibili-player-video-btn-repeat",m:".bilibili-player-video-btn-volume .bilibili-player-iconfont-volume"};document.body.addEventListener("keydown",e=>{if(document.activeElement&&["input","textarea"].includes(document.activeElement.nodeName.toLowerCase())){return}const i=e.key.toLowerCase();if(i in t){e.stopPropagation();e.preventDefault();dq(t[i]).click()}else if(i==="d"){const e=dq(".bilibili-player-video-danmaku-switch input");e.checked=!e.checked;raiseEvent(e,"change")}})}})();

View File

@ -2,21 +2,27 @@
if (!/^https:\/\/live\.bilibili\.com\/[\d]+/.test(document.URL)) {
return
}
const popupContainer = await SpinQuery.select('.chat-popups-section')
console.log(popupContainer)
const popupContainer = await SpinQuery.condition(
() => dq('.chat-popups-section'),
(it: HTMLElement) => it.querySelector('chat-draw-area') === null
)
if (!popupContainer) {
console.warn('[自动领奖] 未能找到弹窗容器')
return
}
Observer.childListSubtree(popupContainer, () => {
let draw: HTMLSpanElement | null
while (true) {
const tryDraw = () => {
console.log('draw button = ', dq('.chat-popups-section .draw>span:nth-child(3)'))
console.log(popupContainer)
draw = dq('.chat-popups-section .draw>span:nth-child(3)') as HTMLSpanElement | null
if (draw === null) {
break
if (draw === null && dq('.chat-popups-section chat-draw-area') === null) {
return
}
if (draw !== null) {
draw.click()
}
draw.click()
}
tryDraw()
})
})()

View File

@ -11,9 +11,12 @@ document.body.addEventListener('keydown', e => {
}
const key = e.key.toLowerCase()
if (key in keymap) {
console.log(key)
e.stopPropagation()
e.preventDefault();
(dq(keymap[key]) as HTMLElement).click()
} else if (key === 'd') { // 切换弹幕开关
const checkbox = dq('.bilibili-player-video-danmaku-switch input') as HTMLInputElement
checkbox.checked = !checkbox.checked
raiseEvent(checkbox, 'change')
}
})