Threads Auto Unmute

播放影片自動取消靜音

// ==UserScript==
// @name         Threads Auto Unmute
// @match        https://www.threads.com/*
// @grant        none
// @description  播放影片自動取消靜音
// @version 0.0.1.20250830114918
// @namespace https://greasyfork.org/users/1458180
// ==/UserScript==

(function() {
  'use strict';

  const observer = new MutationObserver(mutations => {
    for (const m of mutations) {
      m.addedNodes.forEach(node => {
        if (node.nodeType === Node.ELEMENT_NODE) {
          const vids = node.querySelectorAll('video');
          vids.forEach(v => {
            v.muted = false;
            v.volume = 1.0;
            v.play().catch(e => {/* autoplay error */});
          });
        }
      });
    }
  });

  observer.observe(document.body, { childList: true, subtree: true });

  // 頁面已載入的影片也同樣處理
  document.querySelectorAll('video').forEach(v => {
    v.muted = false;
    v.volume = 1.0;
    v.play().catch(e => {/* autoplay error */});
  });
})();