Missav keeps playing

Let videos keeps playing after losing focus

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
})();