Skip to content

Instantly share code, notes, and snippets.

@CatzHoekk
Last active June 20, 2024 19:37
Show Gist options
  • Save CatzHoekk/6f42866895df5e7484fa005e4cbf0735 to your computer and use it in GitHub Desktop.
Save CatzHoekk/6f42866895df5e7484fa005e4cbf0735 to your computer and use it in GitHub Desktop.
Enables picture in picture on all video elements
// ==UserScript==
// @name Reactivate Picture-in-Picture
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Detects when a video element loads and allows for Picture-in-Picture (Does not actually start PIP mode)
// @author CatzHoek
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to allow Picture-in-Picture mode for all video elements
function allowPiPForAllVideos() {
const videos = document.getElementsByTagName('video');
for (let i = 0; i < videos.length; i++) {
videos[i].disablePictureInPicture = false;
}
}
// Event listener for when a video element becomes available
window.addEventListener('DOMContentLoaded', () => {
allowPiPForAllVideos();
});
// Optionally, listen for dynamic content changes if needed
var observer = new MutationObserver(() => {
allowPiPForAllVideos();
});
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment