Missav keeps playing

Let videos keeps playing after losing focus

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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