Missav keeps playing

Let videos keeps playing after losing focus

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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