Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 阻止全屏时使用Enter跳过赞助片段时播放器默认聚焦到弹幕输入框的行为 #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,21 @@ function hotkeyListener(e: KeyboardEvent): void {
if (keybindEquals(key, skipKey)) {
if (activeSkipKeybindElement) {
activeSkipKeybindElement.toggleSkip.call(activeSkipKeybindElement);

/*
* b站视频播放器全屏或网页全屏时,快捷键`Enter`会聚焦到弹幕输入框
* 这里阻止了使用`Enter`跳过赞助片段时播放器的默认行为
*/
if (key.key === 'Enter') {
const currentTime: number | null = document.querySelector<HTMLVideoElement>(".bpx-player-video-wrap video")?.currentTime ?? null;
if (currentTime) {
const inSponsorRange = sponsorTimes.some(({segment: [start, end]}) => start <= currentTime && end >= currentTime);
if (inSponsorRange) {
utils.biliBiliPlayerDanmakuInputBlur();
}
}

}
}

return;
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,8 @@ export default class Utils {

Config.forceLocalUpdate("downvotedSegments");
}

biliBiliPlayerDanmakuInputBlur() {
setTimeout(() => document.querySelector<HTMLInputElement>("input.bpx-player-dm-input")?.blur(), 0);
}
}