停用 YouTube AV1 和 VP9

停用 YouTube 的 AV1 和 VP9 影片播放

目前為 2023-08-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Disable YouTube AV1 and VP9
  3. // @description Disable AV1 and VP9 for video playback on YouTube
  4. // @name:zh-TW 停用 YouTube AV1 和 VP9
  5. // @description:zh-TW 停用 YouTube 的 AV1 和 VP9 影片播放
  6. // @name:zh-HK 停用 YouTube AV1 和 VP9
  7. // @description:zh-HK 停用 YouTube 的 AV1 和 VP9 影片播放
  8. // @name:zh-CN 停用 YouTube AV1 和 VP9
  9. // @description:zh-CN 停用 YouTube 的 AV1 和 VP9 视频播放
  10. // @name:ja YouTube AV1 と VP9 の停用
  11. // @description:ja YouTube の動画再生に AV1 と VP9 を停用する
  12. // @name:ko YouTube AV1과 VP9 비활성화
  13. // @description:ko YouTube의 동영상 재생에 AV1과 VP9를 비활성화하기
  14. // @name:vi Vô hiệu hóa YouTube AV1 và VP9
  15. // @description:vi Vô hiệu hóa AV1 và VP9 để phát video trên YouTube
  16. // @name:de YouTube AV1 und VP9 deaktivieren
  17. // @description:de Deaktiviert AV1 und VP9 für die Videowiedergabe auf YouTube
  18. // @name:fr Désactiver YouTube AV1 et VP9
  19. // @description:fr Désactivez AV1 et VP9 pour la lecture des vidéos sur YouTube
  20. // @name:it Disabilita YouTube AV1 e VP9
  21. // @description:it Disabilita AV1 e VP9 per la riproduzione dei video su YouTube
  22. // @name:es Desactivar AV1 y VP9 en YouTube
  23. // @description:es Desactivar AV1 y VP9 para la reproducción de videos en YouTube
  24. // @namespace http://tampermonkey.net/
  25. // @version 2.4.1
  26. // @author CY Fung
  27. // @match https://www.youtube.com/*
  28. // @match https://www.youtube.com/embed/*
  29. // @match https://www.youtube-nocookie.com/embed/*
  30. // @exclude https://www.youtube.com/live_chat*
  31. // @exclude https://www.youtube.com/live_chat_replay*
  32. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  33. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  34. // @grant none
  35. // @run-at document-start
  36. // @license MIT
  37. // @compatible chrome
  38. // @compatible firefox
  39. // @compatible opera
  40. // @compatible edge
  41. // @compatible safari
  42. // @unwrap
  43. // @allFrames true
  44. // @inject-into page
  45. // ==/UserScript==
  46.  
  47.  
  48. (function () {
  49. 'use strict';
  50.  
  51. console.debug("disable-youtube-av1-and-vp9", "injected");
  52.  
  53.  
  54.  
  55. const flagConfig = () => {
  56.  
  57. let firstDa = true;
  58. let cid = 0;
  59. const { setInterval, clearInterval, setTimeout } = window;
  60. const tn = () => {
  61.  
  62. const da = (window.ytcfg && window.ytcfg.data_) ? window.ytcfg.data_ : null;
  63. if (!da) return;
  64.  
  65. const isFirstDa = firstDa;
  66. firstDa = false;
  67.  
  68. for (const EXPERIMENT_FLAGS of [da.EXPERIMENT_FLAGS, da.EXPERIMENTS_FORCED_FLAGS]) {
  69.  
  70. if (EXPERIMENT_FLAGS) {
  71. // EXPERIMENT_FLAGS.html5_disable_av1_hdr = true;
  72. // EXPERIMENT_FLAGS.html5_prefer_hbr_vp9_over_av1 = true;
  73. }
  74.  
  75. }
  76.  
  77. if (isFirstDa) {
  78.  
  79.  
  80. let mo = new MutationObserver(() => {
  81.  
  82. mo.disconnect();
  83. mo.takeRecords();
  84. mo = null;
  85. setTimeout(() => {
  86. cid && clearInterval.call(window, cid);
  87. cid = 0;
  88. tn();
  89. })
  90. });
  91. mo.observe(document, { subtree: true, childList: true });
  92.  
  93.  
  94. }
  95.  
  96.  
  97. };
  98. cid = setInterval.call(window, tn);
  99.  
  100. };
  101.  
  102. const supportedFormatsConfig = () => {
  103.  
  104. function typeTest(type) {
  105.  
  106. if (typeof type === 'string' && type.startsWith('video/')) {
  107.  
  108. if (type.includes('vp9')) {
  109. if (/codecs[\x20-\x7F]+\bvp9\b/.test(type)) return false;
  110. } else if (type.includes('vp09')) {
  111. if (/codecs[\x20-\x7F]+\bvp09\b/.test(type)) return false;
  112. } else if (type.includes('av01')) {
  113. if (/codecs[\x20-\x7F]+\bav01\b/.test(type)) return false;
  114. } else if (type.includes('av1')) {
  115. if (/codecs[\x20-\x7F]+\bav1\b/.test(type)) return false;
  116. }
  117. }
  118.  
  119. }
  120.  
  121. // return a custom MIME type checker that can defer to the original function
  122. function makeModifiedTypeChecker(origChecker) {
  123. // Check if a video type is allowed
  124. return function (type) {
  125. let res = undefined;
  126. if (type === undefined) res = false;
  127. else {
  128. res = typeTest(type);
  129. }
  130. if (res === undefined) res = origChecker.apply(this, arguments);
  131.  
  132. // console.debug(20, type, res)
  133.  
  134. return res;
  135. };
  136. }
  137.  
  138. // Override video element canPlayType() function
  139. const proto = (HTMLVideoElement || 0).prototype;
  140. if (proto && typeof proto.canPlayType == 'function') {
  141. proto.canPlayType = makeModifiedTypeChecker(proto.canPlayType);
  142. }
  143.  
  144. // Override media source extension isTypeSupported() function
  145. const mse = window.MediaSource;
  146. // Check for MSE support before use
  147. if (mse && typeof mse.isTypeSupported == 'function') {
  148. mse.isTypeSupported = makeModifiedTypeChecker(mse.isTypeSupported);
  149. }
  150.  
  151. };
  152.  
  153. function disableAV1() {
  154.  
  155.  
  156.  
  157.  
  158. // This is the setting to disable AV1
  159. // localStorage['yt-player-av1-pref'] = '-1';
  160. try {
  161. Object.defineProperty(localStorage.constructor.prototype, 'yt-player-av1-pref', {
  162. get() {
  163. if (this === localStorage) return '-1';
  164. return this.getItem('yt-player-av1-pref');
  165. },
  166. set(nv) {
  167. this.setItem('yt-player-av1-pref', nv);
  168. return true;
  169. },
  170. enumerable: true,
  171. configurable: true
  172. });
  173. } catch (e) {
  174. // localStorage['yt-player-av1-pref'] = '-1';
  175. }
  176.  
  177. if (localStorage['yt-player-av1-pref'] !== '-1') {
  178.  
  179. console.warn('Disable YouTube AV1 and VP9', '"yt-player-av1-pref = -1" is not supported in your browser.');
  180. return;
  181. }
  182.  
  183. console.debug("disable-youtube-av1-and-vp9", "AV1 disabled by yt-player-av1-pref = -1");
  184.  
  185.  
  186. }
  187.  
  188.  
  189. disableAV1();
  190.  
  191. // flagConfig();
  192. supportedFormatsConfig();
  193.  
  194.  
  195.  
  196.  
  197. })();
  198.  

QingJ © 2025

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