// ==UserScript== // @name Stop videos looping // @namespace http://tampermonkey.net/ // @version 0.4 // @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 // @downloadURL none // ==/UserScript== (function () { "use strict"; // Get the video element const init = () => { const vids = document.querySelectorAll("video"); vids.forEach((vid) => { // Remove the loop attribute vid.removeAttribute("loop"); const vidLen = vid.duration let vidCurr = vid.currentTime const arr = [] if (vidLen > vidCurr) { arr.push(setTimeout(() => { vid.pause() }, vidLen * 1000 - vidCurr * 1000 - 100)) } vid.addEventListener('seeked', () => { clearAll(arr) vidCurr = vid.currentTime if (vidLen > vidCurr) { arr.push(setTimeout(() => { vid.pause() }, vidLen * 1000 - vidCurr * 1000 - 100)) } }); vid.addEventListener("ended", () => { setTimeout(vid.pause(), 200); }); // Add an event listener for the 'ended' event vid.addEventListener("pause", () => { clearAll(arr) }); // Add an event listener for the 'play' event vid.addEventListener("play", () => { vidCurr = vid.currentTime if (vidLen > vidCurr) { arr.push(setTimeout(() => { vid.pause() }, vidLen * 1000 - vidCurr * 1000 - 100)) } }); }); }; const clearAll = (arr) => { arr.forEach(a => { clearTimeout(a) }) } setInterval(init, 2000); })();