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 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Video Background Play Fix
  3. // @namespace https://gf.qytechs.cn/en/users/50-couchy
  4. // @version 1.1
  5. // @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/
  6. // @author Couchy
  7. // @match *://*.youtube.com/*
  8. // @match *://*.vimeo.com/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const IS_YOUTUBE = window.location.hostname.endsWith('youtube.com') || window.location.hostname.endsWith('youtube-nocookie.com');
  17. const IS_VIMEO = window.location.hostname.endsWith('vimeo.com');
  18.  
  19. // Page Visibility API
  20. Object.defineProperties(document, { 'hidden': {value: false}, 'visibilityState': {value: 'visible'} });
  21. window.addEventListener('visibilitychange', evt => evt.stopImmediatePropagation(), true);
  22.  
  23. // Fullscreen API
  24. if (IS_VIMEO) {
  25. window.addEventListener('fullscreenchange', evt => evt.stopImmediatePropagation(), true);
  26. }
  27.  
  28. // User activity tracking
  29. if (IS_YOUTUBE) {
  30. const REFRESH_INTERVAL = 60 * 1000;
  31. const TIMEOUT_FUNC = function(){window._lact = Date.now();};
  32. if (window.hasOwnProperty('_lact')) {
  33. window.setInterval(TIMEOUT_FUNC, REFRESH_INTERVAL);
  34. }
  35. else {
  36. // Set a "listener" for _lact property to be written the first time
  37. Object.defineProperty(window, '_lact', {
  38. configurable: true,
  39. set: function(val){
  40. Object.defineProperty(window, '_lact', {writable: true});
  41. window._lact = val;
  42. window.setInterval(TIMEOUT_FUNC, REFRESH_INTERVAL);
  43. }
  44. });
  45. }
  46. }
  47. })();

QingJ © 2025

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