Last active
April 25, 2024 13:46
-
-
Save iamandrewluca/71b57cb2d905ab06429c481251db9833 to your computer and use it in GitHub Desktop.
Request picture in picture on first found video that is playing #bookmarklet
This file contains 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
javascript: void ((function() { | |
/* More bookmarklets at https://gist.github.com/iamandrewluca/61feacf07bc4f2f50e70f986c2e9b2d2 */ | |
/** @type {NodeListOf<HTMLIFrameElement>} */ | |
const iFrames = window.document.querySelectorAll('iframe'); | |
console.log(`Found ${iFrames.length} iframes`); | |
/** @type {Document[]} */ | |
const allDocuments = [ | |
window.document, | |
...Array.from(iFrames) | |
.map(i => i.contentDocument) | |
/** | |
* some iFrames have `null` contentDocument | |
* one reason for this is because of not Same-Origin policy | |
*/ | |
.filter(Boolean) | |
]; | |
console.log(`Found ${allDocuments.length} documents`); | |
/** @type {HTMLVideoElement[]} */ | |
const allVideos = allDocuments.flatMap(d => Array.from(d.querySelectorAll('video'))); | |
console.log(`Found ${allVideos.length} videos`); | |
/** @type {HTMLVideoElement} */ | |
const playingVideo = allVideos.find(v => !v.paused); | |
if (playingVideo) { | |
console.log(`Found playing video`); | |
playingVideo.requestPictureInPicture(); | |
} | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment