enable standard video controls
// ==UserScript==
// @name Instagram - Enable standard video controls
// @namespace https://greasyfork.org/users/821661
// @match https://www.instagram.com/*
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-start
// @version 1.6
// @author hdyzen
// @description enable standard video controls
// @license GPL-3.0
// ==/UserScript==
const volDesc = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'volume');
const mutedDesc = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'muted');
const append = Node.prototype.appendChild;
const getVolume = () => GM_getValue('volume', 0);
Object.defineProperty(HTMLMediaElement.prototype, 'volume', {
get: volDesc.get,
set() { return true; }
});
Object.defineProperty(HTMLMediaElement.prototype, 'muted', {
get: mutedDesc.get,
set() { return true; }
});
Node.prototype.appendChild = function (node) {
const result = append.call(this, node)
if (node.tagName !== 'VIDEO') return result;
node.setAttribute('controls', true);
volDesc.set.call(node, getVolume());
node.addEventListener("pause", (ev) => ev.stopImmediatePropagation(), true);
node.addEventListener("play", () => volDesc.set.call(node, GM_getValue('volume', 0)), true);
node.addEventListener("volumechange", () => GM_setValue('volume', node.volume), true);
return result;
};
(document.head || document.documentElement).insertAdjacentHTML('beforeend', `
<style>
video::-webkit-media-controls {
display: block !important;
}
[data-instancekey]:has([d^="M1.5 13"]) {
display: none !important;
}
</style>`
)