Skip to content

Instantly share code, notes, and snippets.

@josephschmitt
Created September 2, 2017 18:13
Show Gist options
  • Save josephschmitt/f0a3ab7057b0632dfb4b2bc233769077 to your computer and use it in GitHub Desktop.
Save josephschmitt/f0a3ab7057b0632dfb4b2bc233769077 to your computer and use it in GitHub Desktop.
Stops the Plex web app from blocking right-click on the video to enter Picture in Picture
(function (plex) {
let timeout;
plex.addEventListener('contextmenu', (e) => {
const button = plex.querySelector('[class*="AudioVideoFullPlayer-isVideo"]');
const miniPlayer = plex.querySelector('[class*="MiniPlayerContainer-miniPlayer"]')
const wasVideoBlocked = (button && button.contains(e.target) || (miniPlayer && miniPlayer.contains(e.target)));
toggleBlock(wasVideoBlocked, button, miniPlayer);
});
function toggleBlock(disableBlock, button, miniPlayer) {
if (button) {
button.style.pointerEvents = disableBlock ? 'none' : '';
}
if (miniPlayer) {
miniPlayer.style.pointerEvents = disableBlock ? 'none' : '';
}
// Reset after a few secs
if (disableBlock) {
clearTimeout(timeout);
timeout = setTimeout(() => toggleBlock(false, button, miniPlayer), 3000)
}
}
})(document.querySelector('#plex'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment