Skip to content

Commit

Permalink
optimize auto pause video
Browse files Browse the repository at this point in the history
  • Loading branch information
HOAIAN2 committed Dec 30, 2022
1 parent 93b3143 commit 8d568cf
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,25 @@ function handleEvents() {
DISPLAY_CONTAINER.firstElementChild.classList.remove('dark')
}
}
function pauseVideo() {
if (DISPLAY_CONTAINER.classList.contains('hide')) {
DISPLAY_CONTAINER.querySelectorAll('video').forEach(video => {
video.pause()
})
}
}
const handleTheme = new MutationObserver(setTheme)
const handleVideo = new MutationObserver(pauseVideo)
handleTheme.observe(document.documentElement, {
attributes: true,
attributeFilter: ['class']
})
handleVideo.observe(DISPLAY_CONTAINER, {
attributes: true,
attributeFilter: ['class']
})
ESC_BUTTON.addEventListener('click', () => {
DISPLAY_CONTAINER.classList.add('hide')
DISPLAY_CONTAINER.querySelectorAll('video').forEach(video => {
video.pause()
})
})
window.addEventListener('keydown', (e) => {
if (!IGNORE_FOCUS_ELEMENTS.includes(document.activeElement.tagName)) {
Expand All @@ -269,4 +278,4 @@ function main() {
setDefaultShortcode()
handleEvents()
}
main()
main()

0 comments on commit 8d568cf

Please sign in to comment.