Last active
November 22, 2024 13:10
-
-
Save danielrotaermel/eaa640ec08e869c4b072ee0d44a39edd to your computer and use it in GitHub Desktop.
UserScript: Toggle picture-in-picture (ctrl+p) and fullscreen (ctrl+f) in Safari. Tested with -> https://apps.apple.com/us/app/userscripts/id1463298887
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
// ==UserScript== | |
// @name Toggle pip and fullscreen on any video | |
// @description Toggle picture-in-picture (ctrl+p) and fullscreen (ctrl+f) in Safari | |
// @license MIT | |
// @author Daniel Rotärmel | |
// @namespace https://gist.github.com/danielrotaermel | |
// @match *://*.* | |
// @match *://*/* | |
// ==/UserScript== | |
document.onkeyup = function(e) { | |
if (e.ctrlKey && e.key == "p") togglePip() | |
if (e.ctrlKey && e.key == "f") toggleFullscreen() | |
}; | |
function togglePip() { | |
const element = document.querySelector('video') | |
if (!element) return | |
const isNotPip = element.webkitPresentationMode === 'inline' || element.webkitPresentationMode === 'fullscreen' | |
element.webkitSetPresentationMode(isNotPip ? 'picture-in-picture' : 'inline') | |
} | |
function toggleFullscreen() { | |
const element = document.querySelector('video') | |
if (!element) return | |
const isNotFullScreen = element.webkitPresentationMode === 'inline' || element.webkitPresentationMode === 'picture-in-picture' | |
element.webkitSetPresentationMode(isNotFullScreen ? 'fullscreen' : 'inline') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the great suggestions @ILikePlayingGames & @yurkimus. I’ve added the fullscreen toggle by default. The touchscreen buttons are a nice addition too, though I’m not using them personally. For anyone interested, this snippet should work with the userscript. Just append it to the script to add the buttons: