YouTube Mobile Background Playback (Firefox Android)

Enable YouTube background playback in Firefox for Android

  1. // ==UserScript==
  2. // @name YouTube Mobile Background Playback (Firefox Android)
  3. // @description Enable YouTube background playback in Firefox for Android
  4. // @namespace http://tampermonkey.net/
  5. // @match *://m.youtube.com/*
  6. // @match *://*.youtube-nocookie.com/*
  7. // @grant none
  8. // @version 1.0
  9. // @run-at document-end
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  11. // @author -
  12. // ==/UserScript==
  13.  
  14. 'use strict';
  15. const lactRefreshInterval = 5 * 60 * 1000; // 5 minutes
  16. const initialLactDelay = 1000;
  17.  
  18. // Page Visibility API
  19. Object.defineProperties(document, { 'hidden': { value: false }, 'visibilityState': { value: 'visible' } });
  20. window.addEventListener('visibilitychange', e => e.stopImmediatePropagation(), true);
  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. waitForYoutubeLactInit();