Missav keeps playing

Let videos keeps playing after losing focus

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Missav keeps playing
// @namespace    http://tampermonkey.net/
// @version      2025-01-31
// @description  Let videos keeps playing after losing focus
// @author       zqi
// @match        https://missav.ai/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=missav.ai
// @grant        none
// @license MIT

// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('DOMContentLoaded', () => {
        console.log('[Debug] DOM loaded');
        initPlayerObserver();
    });

    function initPlayerObserver() {
        const observer = new MutationObserver(() => {
            if (window.player?.pause) {
                console.log('[Debug] Player detected');
                overridePause();
                observer.disconnect();
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
        if (window.player) overridePause();
    }

    function overridePause() {
        try {
            const originalPause = window.player.pause.bind(window.player);
            Object.defineProperty(window.player, 'pause', {
                value: function() {
                    console.log('[Debug] Pause called. Focus:', document.hasFocus());
                    if (document.hasFocus()) originalPause();
                },
                writable: false,
                configurable: false
            });
            console.log('[Debug] Pause overridden');
        } catch (e) {
            console.error('[Debug] Override error:', e);
        }
    }

    setInterval(() => {
        if (!window.player?.pause?.toString().includes('Focus:')) {
            console.log('[Debug] Pause was reset! Re-overriding...');
            overridePause();
        }
    }, 2000);
})();