YouTube H.264 + FPS

Clone of h264ify with optional limit up to 30 FPS.

  1. // ==UserScript==
  2. // @name YouTube H.264 + FPS
  3. // @name:ru YouTube H.264 + FPS
  4. // @namespace https://www.youtube.com
  5. // @version 2023.11.20.2
  6. // @description Clone of h264ify with optional limit up to 30 FPS.
  7. // @description:ru Клон h264ify с опциональным ограничением до 30 FPS.
  8. // @match *://*.youtube.com/*
  9. // @match *://*.youtube-nocookie.com/*
  10. // @match *://*.youtubekids.com/*
  11. // @license MIT
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. // Constants for video settings
  17. const BLOCK_HIGH_FPS = true;
  18. const DISALLOWED_TYPES_REGEX = /webm|vp8|vp9|av01/i;
  19. const FRAME_RATE_REGEX = /framerate=(\d+)/;
  20.  
  21. (function() {
  22. const mediaSource = window.MediaSource;
  23.  
  24. if (!mediaSource) return;
  25.  
  26. const originalIsTypeSupported = mediaSource.isTypeSupported.bind(mediaSource);
  27.  
  28. mediaSource.isTypeSupported = (type) => {
  29. if (typeof type !== 'string') return false;
  30.  
  31. if (DISALLOWED_TYPES_REGEX.test(type)) return false;
  32.  
  33. const frameRateMatch = FRAME_RATE_REGEX.exec(type);
  34. if (BLOCK_HIGH_FPS && frameRateMatch && frameRateMatch[1] > 30) {
  35. return false;
  36. }
  37.  
  38. return originalIsTypeSupported(type);
  39. };
  40. })();