您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Stop videos looping (Youtube, Twitter, Tiktok, Instagram)
当前为
// ==UserScript== // @name Stop videos looping // @namespace http://tampermonkey.net/ // @version 0.5 // @description Stop videos looping (Youtube, Twitter, Tiktok, Instagram) // @author @dmtri // @match https://*.youtube.com/* // @match https://*.twitter.com/* // @match https://*.tiktok.com/* // @match https://*.instagram.com/* // @license MIT // @icon // @grant none // ==/UserScript== (function () { "use strict"; // Keep track of processed videos const processedVideos = new WeakSet(); const init = () => { const vids = document.querySelectorAll("video"); vids.forEach((vid) => { if (processedVideos.has(vid)) return; processedVideos.add(vid); vid.removeAttribute("loop"); const arr = []; const setupTimeout = () => { // Ensure duration is available if (isNaN(vid.duration) || vid.duration === Infinity) return; const vidLen = vid.duration; const vidCurr = vid.currentTime; if (vidLen > vidCurr) { const timeout = setTimeout(() => { vid.pause(); }, (vidLen - vidCurr - 0.1) * 1000); // Adjusted to account for potential delays arr.push(timeout); } }; vid.addEventListener('loadedmetadata', setupTimeout); vid.addEventListener('seeked', () => { clearAll(arr); setupTimeout(); }); vid.addEventListener("pause", () => { clearAll(arr); }); vid.addEventListener("play", () => { setupTimeout(); }); vid.addEventListener("ended", () => { setTimeout(() => vid.pause(), 200); }); }); }; const clearAll = (arr) => { arr.forEach((timeout) => { clearTimeout(timeout); }); arr = []; }; const observer = new MutationObserver(init); observer.observe(document.body, { childList: true, subtree: true }); init(); })();