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 poster = videoNextSibling.querySelector("img[src]");
video.setAttribute("controls", "");
if (poster) video.setAttribute("poster", poster.src);
videoNextSibling.style.display = "none";
}
};
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 });