Created
January 1, 2020 07:27
-
-
Save pintassilgo/fd16d77875281b389cc4cf40ce4ca207 to your computer and use it in GitHub Desktop.
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 Always show controls in HTML5 videos | |
// @include * | |
// ==/UserScript== | |
let observer = new MutationObserver(mutations => { | |
mutations.forEach(mutation => { | |
mutation.addedNodes.forEach(node => { | |
if (node instanceof HTMLElement && node.nodeName === 'DIV' && !document.body.contains(node)) { // Imagus places its element oustide the <body> | |
let videoElements = node.getElementsByTagName('video'); | |
if (videoElements.length) { | |
let videoElement = videoElements[0]; | |
videoElement.controls = true; | |
observerControls.observe(videoElement, { attributes: true }); | |
observer.disconnect(); | |
} | |
} | |
}); | |
}); | |
}); | |
let observerControls = new MutationObserver(mutations => { | |
mutations.forEach(mutation => { | |
if (mutation.attributeName == 'controls' && !mutation.target.hasAttribute('controls')) { | |
mutation.target.controls = true; | |
} | |
}); | |
}); | |
observer.observe(document, { childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment