Prime Video - toggle pause on minimize or hide

Pause Amazon Prime Video movie on minimize, hide, tab switch... and play when it's back.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Prime Video - toggle pause on minimize or hide
// @version      2025-04-06
// @namespace    Jakub Marcinkowski
// @description  Pause Amazon Prime Video movie on minimize, hide, tab switch... and play when it's back.
// @author       Jakub Marcinkowski <kuba.marcinkowski on g mail>
// @copyright    2024+, Jakub Marcinkowski <kuba.marcinkowski on g mail>
// @license      Zlib
// @homepageURL  https://gist.github.com/JakubMarcinkowski
// @homepageURL  https://github.com/JakubMarcinkowski
// @match        https://*.primevideo.com/*
// @icon         data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii01MCAtNTAgMTAwIDEwMCI+PGxpbmVhckdyYWRpZW50IGlkPSJnIiB5MT0iMSIgeDI9IjEiPjxzdG9wIHN0b3AtY29sb3I9IiMwYTNkODAiLz48c3RvcCBzdG9wLWNvbG9yPSIjMDI5YmQyIiBvZmZzZXQ9IjEiLz48L2xpbmVhckdyYWRpZW50PjxjaXJjbGUgcj0iNTAiIGZpbGw9InVybCgjZykiLz48cGF0aCBkPSJNLTEzLC0yMFYyMEwyMCwwIiBmaWxsPSIjZmZmIi8+PC9zdmc+
// @noframes
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  document.addEventListener("visibilitychange", () => {
    const player = document.querySelector('video[id^="dummy"][src^="blob"]');
    if (document.visibilityState === 'hidden') {
      player.pause();
    } else {
      player.play();
    }
  });
})();