停用 YouTube AV1 和 VP9

停用 YouTube 的 AV1 和 VP9 视频播放

目前为 2023-05-19 提交的版本。查看 最新版本

  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 1.0.2
  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
  44. // @inject-into page
  45. // ==/UserScript==
  46.  
  47. (function () {
  48. 'use strict';
  49. console.debug("disable-youtube-av1-and-vp9", "injected");
  50. function disableAV1() {
  51. console.debug("disable-youtube-av1-and-vp9", "AV1 disabled");
  52. // This is the setting to disable AV1
  53. // localStorage['yt-player-av1-pref'] = '-1';
  54. Object.defineProperty(localStorage, 'yt-player-av1-pref', { value: '-1', writable: true, enumerable: true, configurable: true });
  55. function typeTest(type) {
  56. let disallowed_types = ['vp8', 'vp9', 'av1', 'av01', 'vp09'];
  57. for (const disallowed_type of disallowed_types) {
  58. if (type.includes(disallowed_type)) return false;
  59. }
  60. let force_allow_types = ['hev1'];
  61. for (const force_allow_type of force_allow_types) {
  62. if (type.includes(force_allow_type)) return true;
  63. }
  64. }
  65. // return a custom MIME type checker that can defer to the original function
  66. function makeModifiedTypeChecker(origChecker) {
  67. // Check if a video type is allowed
  68. return function (type) {
  69. let res = undefined;
  70. if (type === undefined) res = false;
  71. else {
  72. res = typeTest(type);
  73. }
  74. if (res === undefined) res = origChecker.apply(this, arguments);
  75. // console.debug(20, type, res)
  76. return res;
  77. };
  78. }
  79. // Override video element canPlayType() function
  80. const proto = (HTMLVideoElement || 0).prototype;
  81. if (proto && typeof proto.canPlayType == 'function') {
  82. proto.canPlayType = makeModifiedTypeChecker(proto.canPlayType);
  83. }
  84. // Override media source extension isTypeSupported() function
  85. const mse = window.MediaSource;
  86. // Check for MSE support before use
  87. if (mse && typeof mse.isTypeSupported == 'function') {
  88. mse.isTypeSupported = makeModifiedTypeChecker(mse.isTypeSupported);
  89. }
  90. }
  91. disableAV1();
  92. })();

QingJ © 2025

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