Skip to content

Instantly share code, notes, and snippets.

@wrboyce
Created September 19, 2020 15:54
Show Gist options
  • Save wrboyce/2e28352faa56ed419890c8a8483f934e to your computer and use it in GitHub Desktop.
Save wrboyce/2e28352faa56ed419890c8a8483f934e to your computer and use it in GitHub Desktop.
YouTube PiP Bookmarklet
javascript:(function()%7Bdocument.body.innerHTML%20%3D%20'%3Ch1%3ELoading...%3C%2Fh1%3E'%3Bconst%20url%20%3D%20new%20URL(window.location.href)%3Bconst%20videoId%20%3D%20url.searchParams.get('v')%3Bconst%20xhr%20%3D%20new%20XMLHttpRequest()%3Bxhr.open('GET'%2C%20%60https%3A%2F%2Fwww.youtube.com%2Fget_video_info%3Fvideo_id%3D%24%7BvideoId%7D%26el%3Ddetailpage%60%2C%20false)%3Bxhr.send(null)%3Bconst%20response%20%3D%20decodeURIComponent(xhr.responseText).split(%22%26%22).filter((line)%20%3D%3E%20line.startsWith(%22player_response%22))%5B0%5D.split(%22player_response%3D%22)%5B1%5D%3Bconst%20info%20%3D%20JSON.parse(response)%3Bconst%20streams%20%3D%20info.streamingData.formats.sort((s1%2C%20s2)%20%3D%3E%20s1.height%20%3C%20s2.height)%3Bdocument.body.innerHTML%20%3D%20%60%3Cvideo%20style%3D%22width%3A%20100%25%3B%20max-width%3A%20500px%3B%22%20id%3D%22video%22%20controls%3D%22controls%22%20class%3D%22video-stream%22%20x-webkit-airplay%3D%22allow%22%20autoplay%20playsinline%20src%3D%22%24%7Bstreams%5B0%5D.url%7D%22%3E%3C%2Fvideo%3E%60%3Bconst%20vid%20%3D%20document.getElementById('video')%3Bvid.webkitSetPresentationMode('picture-in-picture')%3Bvid.play()%7D)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment