Created
December 28, 2024 15:24
-
-
Save thangman22/85ae30b09892939e1ccf3ab42e9c7127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipButton.addEventListener("click", async () => { | |
const chatScreen = document.querySelector("#chat-screen"); | |
// Open a Picture-in-Picture window. | |
const pipWindow = await documentPictureInPicture.requestWindow(); | |
// Copy style sheets over from the initial document | |
// so that the player looks the same. | |
[...document.styleSheets].forEach((styleSheet) => { | |
try { | |
const cssRules = [...styleSheet.cssRules].map((rule) => rule.cssText).join(''); | |
const style = document.createElement('style'); | |
style.textContent = cssRules; | |
pipWindow.document.head.appendChild(style); | |
} catch (e) { | |
const link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.type = styleSheet.type; | |
link.media = styleSheet.media; | |
link.href = styleSheet.href; | |
pipWindow.document.head.appendChild(link); | |
} | |
}); | |
// Move the player to the Picture-in-Picture window. | |
pipWindow.document.body.append(chatScreen); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment