Re-acquire video element when current one empties

This commit is contained in:
Max Goodhart
2026-01-24 18:24:22 -08:00
parent e6467bdd54
commit 74de18aa28

View File

@@ -186,7 +186,7 @@ const igHacks = {
}, },
} }
async function findVideo(kind: 'video' | 'audio') { async function findMedia(kind: 'video' | 'audio') {
if (igHacks.isMatch()) { if (igHacks.isMatch()) {
await igHacks.onLoad() await igHacks.onLoad()
} }
@@ -227,10 +227,7 @@ async function findVideo(kind: 'video' | 'audio') {
video.muted = false video.muted = false
const info = { return video
title: document.title,
}
return { info, video }
} }
async function main() { async function main() {
@@ -243,13 +240,31 @@ async function main() {
]) ])
let rotationController: RotationController | undefined let rotationController: RotationController | undefined
async function acquireMedia() {
const media = await findMedia(content.kind)
console.log('media acquired', media)
if (content.kind === 'video' && media instanceof HTMLVideoElement) {
rotationController = new RotationController(media)
}
media.addEventListener(
'emptied',
() => {
console.warn('media emptied, re-acquiring', media)
media.remove()
acquireMedia()
},
{ once: true },
)
}
if (content.kind === 'video' || content.kind === 'audio') { if (content.kind === 'video' || content.kind === 'audio') {
webFrame.insertCSS(VIDEO_OVERRIDE_STYLE, { cssOrigin: 'user' }) webFrame.insertCSS(VIDEO_OVERRIDE_STYLE, { cssOrigin: 'user' })
const { info, video } = await findVideo(content.kind) acquireMedia()
if (content.kind === 'video' && video instanceof HTMLVideoElement) { ipcRenderer.send('view-info', {
rotationController = new RotationController(video) info: {
} title: document.title,
ipcRenderer.send('view-info', { info }) },
})
} else if (content.kind === 'web') { } else if (content.kind === 'web') {
webFrame.insertCSS(NO_SCROLL_STYLE, { cssOrigin: 'user' }) webFrame.insertCSS(NO_SCROLL_STYLE, { cssOrigin: 'user' })
} }