Video-Background-Playback

Enable YouTube and Tiktok background playback

  1. // ==UserScript==
  2. // @name Video-Background-Playback
  3. // @namespace Video-Background-Playback-Userscript
  4. // @version 0.1.0
  5. // @description Enable YouTube and Tiktok background playback
  6. // @author lkccrr
  7. // @match *://*.tiktok.com/*
  8. // @match *://*.youtube.com/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. 'use strict';
  14. const lactRefreshInterval = 5 * 60 * 1000; // 5 mins
  15. const initialLactDelay = 1000;
  16.  
  17. // Page Visibility API
  18. Object.defineProperties(document, { 'hidden': { value: false }, 'visibilityState': { value: 'visible' } });
  19. window.addEventListener('visibilitychange', e => e.stopImmediatePropagation(), true);
  20.  
  21. // _lact stuff
  22. function waitForYoutubeLactInit(delay = initialLactDelay) {
  23. if (window.hasOwnProperty('_lact')) {
  24. window.setInterval(() => { window._lact = Date.now(); }, lactRefreshInterval);
  25. }
  26. else{
  27. window.setTimeout(() => waitForYoutubeLactInit(delay * 2), delay);
  28. }
  29.  
  30. }
  31.  
  32. waitForYoutubeLactInit();

QingJ © 2025

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