您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Pause videos playing in background tabs when a video starts
A userscript that pauses background YouTube videos when a video starts playing in the active tab.
This prevents multiple videos from playing simultaneously across tabs.
anhkhoakz
1.1.0
anhkhoakz
*://www.youtube.com/*
document-start
The script leverages:
pause
message is broadcast to other tabs.video.currentTime > 0
!video.paused
!video.ended
video.readyState >= HAVE_ENOUGH_DATA
popstate
, pushstate
, replacestate
eventshistory.pushState
/ history.replaceState
setInterval
fallbackfindElement(selector: string): Promise<Element>
Waits for a DOM element (YouTube video player) to appear before attaching listeners.
isVideoPlaying(video: HTMLVideoElement): boolean
Checks if a video is actively playing.
isTabInFocus(): boolean
Returns true
if the current tab is active.
shouldPauseVideo(message: string, video: VideoWithIsPlaying): boolean
Determines if a background video should be paused when a pause
message is received.
playing
, loadeddata
, canplay
→ Broadcast pause
message when in focus.visibilitychange
→ Sends pause
when tab regains focus.pushState
, replaceState
)setInterval
check every secondpopstate
, pushstate
, replacestate
BroadcastChannel("video-channel")
pause
messages and stop their video.1.1.0
playing
event.1.0.0