Stop videos looping

Stop videos looping (Youtube, Twitter, Tiktok, Instagram)

スクリプトをインストール?
作者が勧める他のスクリプト

YouTube Channel Hover Popupも気に入るかもしれません。

スクリプトをインストール
このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==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();
})();