Video Background Play Fix

Prevents YouTube and Vimeo from pausing videos when minimizing or switching tabs. Cross-browser port of https://addons.mozilla.org/en-US/firefox/addon/video-background-play-fix/

目前為 2019-05-21 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Video Background Play Fix
// @namespace    https://gf.qytechs.cn/en/users/50-couchy
// @version      1.1
// @description  Prevents YouTube and Vimeo from pausing videos when minimizing or switching tabs. Cross-browser port of https://addons.mozilla.org/en-US/firefox/addon/video-background-play-fix/
// @author       Couchy
// @match        *://*.youtube.com/*
// @match        *://*.vimeo.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const IS_YOUTUBE = window.location.hostname.endsWith('youtube.com') || window.location.hostname.endsWith('youtube-nocookie.com');
    const IS_VIMEO = window.location.hostname.endsWith('vimeo.com');

    // Page Visibility API
    Object.defineProperties(document, { 'hidden': {value: false}, 'visibilityState': {value: 'visible'} });
    window.addEventListener('visibilitychange', evt => evt.stopImmediatePropagation(), true);

    // Fullscreen API
    if (IS_VIMEO) {
        window.addEventListener('fullscreenchange', evt => evt.stopImmediatePropagation(), true);
    }

    // User activity tracking
    if (IS_YOUTUBE) {
        const REFRESH_INTERVAL = 60 * 1000;
        const TIMEOUT_FUNC = function(){window._lact = Date.now();};
        if (window.hasOwnProperty('_lact')) {
            window.setInterval(TIMEOUT_FUNC, REFRESH_INTERVAL);
        }
        else {
            // Set a "listener" for _lact property to be written the first time
            Object.defineProperty(window, '_lact', {
                configurable: true,
                set: function(val){
                    Object.defineProperty(window, '_lact', {writable: true});
                    window._lact = val;
                    window.setInterval(TIMEOUT_FUNC, REFRESH_INTERVAL);
                }
            });
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址