Created
May 21, 2020 12:33
-
-
Save ilyasKerbal/1def083082e5530d949b134adfa72e35 to your computer and use it in GitHub Desktop.
Request picture in picture on first found video that is playing #bookmarklet
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
javascript: void ((function() { | |
/** @type {NodeListOf<HTMLIFrameElement>} */ | |
const iFrames = window.document.querySelectorAll('iframe'); | |
/** @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) | |
]; | |
/** @type {HTMLVideoElement[]} */ | |
const allVideos = allDocuments.flatMap(d => Array.from(d.querySelectorAll('video'))); | |
/** @type {HTMLVideoElement} */ | |
const playingVideo = allVideos.find(v => !v.paused); | |
if (playingVideo) { | |
playingVideo.requestPictureInPicture(); | |
} | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment