Prime Video iOS Safari Audio Fix

Fixes audio playback issues on Prime Video for iOS Safari by spoofing UA and triggering AudioContext

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Prime Video iOS Safari Audio Fix
// @name:ja      Prime Video 音声再生修正スクリプト(iOS Safari用)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Fixes audio playback issues on Prime Video for iOS Safari by spoofing UA and triggering AudioContext
// @description:ja iOS SafariでPrime Videoの音声が再生されない問題を回避するため、ユーザーエージェントの偽装とAudioContextの起動を行います。
// @match        https://www.primevideo.com/*
// @match        https://www.amazon.co.jp/*
// @run-at       document-start
// ==/UserScript==

(() => {
  'use strict';

  // UA偽装(Mac Safari風)
  const ua = {
    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
    platform: "MacIntel",
    vendor: "Apple Computer, Inc.",
    maxTouchPoints: 1
  };
  Object.entries(ua).forEach(([k,v]) =>
    Object.defineProperty(navigator, k, { get: () => v, configurable: true })
  );

  // タッチイベント模倣(iOS用)
  window.addEventListener("load", () => {
    document.body.dispatchEvent(new TouchEvent('touchend', { bubbles: true }));
  });

  // AudioContextトリガー
  function triggerAudio() {
    try {
      const ctx = new AudioContext();
      const osc = ctx.createOscillator();
      const gain = ctx.createGain();
      gain.gain.value = 0;
      osc.connect(gain).connect(ctx.destination);
      osc.start(); osc.stop(ctx.currentTime + 0.05);
    } catch {}
  }
  window.addEventListener("DOMContentLoaded", triggerAudio);

  new MutationObserver((muts, obs) => {
    if (document.querySelector('video')) {
      triggerAudio();
      obs.disconnect();
    }
  }).observe(document.documentElement, { childList: true, subtree: true });
})();