Video-Background-Playback

Enable YouTube and Tiktok background playback

// ==UserScript==
// @name         Video-Background-Playback
// @namespace    Video-Background-Playback-Userscript
// @version      0.1.0
// @description  Enable YouTube and Tiktok background playback
// @author       lkccrr
// @match        *://*.tiktok.com/*
// @match        *://*.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

'use strict';
const lactRefreshInterval = 5 * 60 * 1000; // 5 mins
const initialLactDelay = 1000;

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

// _lact stuff
function waitForYoutubeLactInit(delay = initialLactDelay) {
  if (window.hasOwnProperty('_lact')) {
  window.setInterval(() => { window._lact = Date.now(); }, lactRefreshInterval);
  }
  else{
    window.setTimeout(() => waitForYoutubeLactInit(delay * 2), delay);
  }

}

waitForYoutubeLactInit();

QingJ © 2025

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