enable standard video controls
目前為
// ==UserScript==
// @name Enable standard video controls
// @namespace https://greasyfork.org/users/821661
// @match https://www.instagram.com/*
// @grant none
// @version 1.1
// @author hdyzen
// @description enable standard video controls
// @license GPL-3.0
// ==/UserScript==
"use strict";
const cantAddControls = () => !(window.location.pathname.startsWith("/stories/") || window.location.pathname.startsWith("/reels/"));
const videosHandler = videosEl => {
for (const video of videosEl) {
const videoNextSibling = video.nextElementSibling;
const containerButtons = videoNextSibling.children[0];
video.setAttribute("controls", "");
videoNextSibling.onclick = ev => {
containerButtons.style.display = "contents";
containerButtons.children[1].style.display = "none";
video.play();
};
}
};
const mutationsHandler = mutations => {
const videosEl = [...document.querySelectorAll("video[src")].filter(video => !video.hasAttribute("controls"));
if (videosEl.length && cantAddControls()) {
videosHandler(videosEl);
}
};
const observer = new MutationObserver(mutationsHandler);
observer.observe(document.body, { childList: true, subtree: true });