Last active
February 17, 2023 22:00
-
-
Save PJnes/e6bd4497e33b1c67dd94d1a1d2e4f51b to your computer and use it in GitHub Desktop.
Disney+ Enable PiP Userscript
This file contains 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 Disney+ PiP | |
// @namespace pauljones.io | |
// @version 0.2 | |
// @description Enable PiP on Disney+ videos. | |
// @author Paul Jones | |
// @match https://www.disneyplus.com/* | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
(function() { | |
// This is the root element, and the only thing we know will be available. | |
const targetNode = document.getElementById('webAppRoot'); | |
// Mutation Observers are a cool way to watch elements for changes. | |
const observer = new MutationObserver((mutationsList, observer) => { | |
mutationsList.forEach((item) => { | |
// Disney+ injects the video element dynamically. They no longer use the `autoplay` attribute, so ... | |
// When there is a change to the `src` attribute on a `<video>` tag | |
if (item.type === 'attributes' && item.attributeName === 'src' && item.target.tagName === 'VIDEO') { | |
// ... set the 'disablePictureInPicture' attribute to false. | |
item.target.disablePictureInPicture = false; | |
} | |
}); | |
}); | |
// Tell our observer to monitor changes in attributes, and within child elements. | |
observer.observe(targetNode, { attributes: true, subtree: true }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment