Greasy Fork is available in English.

Background playback for Via Browser

11/2/2023, 4:29:15 PM

Fra 02.11.2023. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name Background playback for Via Browser
  3. // @namespace Violentmonkey Scripts
  4. // @match https://*.youtube.com/*
  5. // @match https://*.youtube.com/
  6. // @match https://*.youtube-nocookie.com/*
  7. // @grant none
  8. // @version 1.0
  9. // @author Johnny Vo
  10. // @description 11/2/2023, 4:29:15 PM
  11. // ==/UserScript==
  12. 'use strict';
  13. const lactRefreshInterval = 5 * 60 * 1000; // 5 mins
  14. const initialLactDelay = 1000;
  15.  
  16. // Page Visibility API
  17. Object.defineProperties(document, { 'hidden': { value: false }, 'visibilityState': { value: 'visible' } });
  18. window.addEventListener('visibilitychange', e => e.stopImmediatePropagation(), true);
  19.  
  20. // _lact stuff
  21. function waitForYoutubeLactInit(delay = initialLactDelay) {
  22. if (window.hasOwnProperty('_lact')) {
  23. window.setInterval(() => { window._lact = Date.now(); }, lactRefreshInterval);
  24. } else {
  25. window.setTimeout(() => waitForYoutubeLactInit(delay * 2), delay);
  26. }
  27. }
  28. waitForYoutubeLactInit();