Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pintassilgo/fd16d77875281b389cc4cf40ce4ca207 to your computer and use it in GitHub Desktop.
Save pintassilgo/fd16d77875281b389cc4cf40ce4ca207 to your computer and use it in GitHub Desktop.
// ==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