Greasy Fork镜像 支持简体中文。

強制 YouTube AV1

強制 YouTube 使用 AV1 進行影片播放

目前為 2023-05-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Force YouTube AV1
  3. // @description Force YouTube to use AV1 for video playback
  4. // @name:zh-TW 強制 YouTube AV1
  5. // @description:zh-TW 強制 YouTube 使用 AV1 進行影片播放
  6. // @name:zh-HK 強制 YouTube AV1
  7. // @description:zh-HK 強制 YouTube 使用 AV1 進行影片播放
  8. // @name:zh-CN 强制 YouTube AV1
  9. // @description:zh-CN 强制 YouTube 使用 AV1 进行视频播放
  10. // @name:ja YouTube AV1 強制再生
  11. // @description:ja YouTube の動画再生に AV1 を強制的に使用する
  12. // @name:ko YouTube AV1 강제 사용
  13. // @description:ko YouTube의 동영상 재생에 AV1을 강제로 사용하기
  14. // @name:vi Bắt buộc YouTube sử dụng AV1
  15. // @description:vi Bắt buộc YouTube sử dụng AV1 để phát video
  16. // @name:de YouTube AV1 erzwingen
  17. // @description:de Erzwingt die Verwendung von AV1 für die Videowiedergabe auf YouTube
  18. // @name:fr Forcer YouTube AV1
  19. // @description:fr Force YouTube à utiliser AV1 pour la lecture des vidéos
  20. // @name:it Forza YouTube AV1
  21. // @description:it Forza YouTube a utilizzare AV1 per la riproduzione dei video
  22. // @name:es Forzar AV1 en YouTube
  23. // @description:es Forzar a YouTube a usar AV1 para la reproducción de videos
  24. // @namespace http://tampermonkey.net/
  25. // @version 1.0.4
  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. // @unwrap
  41. // @allFrames
  42. // @inject-into page
  43. // ==/UserScript==
  44.  
  45. (function () {
  46. 'use strict';
  47.  
  48. console.debug("force-youtube-av1", "injected");
  49.  
  50. function enableAV1() {
  51.  
  52. console.debug("force-youtube-av1", "AV1 enabled");
  53.  
  54.  
  55. // This is the setting to force AV1
  56. // localStorage['yt-player-av1-pref'] = '8192';
  57. Object.defineProperty(localStorage, 'yt-player-av1-pref', { value: '8192', writable: true, enumerable: true, configurable: true });
  58.  
  59. function typeTest(type) {
  60.  
  61.  
  62. let disallowed_types = ['vp8', 'vp9', 'avc1'];
  63. // mp4a is a container for AAC. In most cases (<192kbps), Opus is better than AAC.
  64. // vp09 will be also disabled if av1 is enabled.
  65. for (const disallowed_type of disallowed_types) {
  66. if (type.includes(disallowed_type)) return false;
  67. }
  68.  
  69. let force_allow_types = ['av1', 'av01', 'hev1'];
  70. // av1 is currently supported by Firefox and Chrome except Edge
  71. for (const force_allow_type of force_allow_types) {
  72. if (type.includes(force_allow_type)) return true;
  73. }
  74.  
  75. }
  76.  
  77. // return a custom MIME type checker that can defer to the original function
  78. function makeModifiedTypeChecker(origChecker) {
  79. // Check if a video type is allowed
  80. return function (type) {
  81. let res = undefined;
  82. if (type === undefined) res = false;
  83. else {
  84. res = typeTest(type);
  85. }
  86. if (res === undefined) res = origChecker.apply(this, arguments);
  87.  
  88. // console.debug(20, type, res)
  89.  
  90. return res;
  91. };
  92. }
  93.  
  94. // Override video element canPlayType() function
  95. const proto = (HTMLVideoElement || 0).prototype;
  96. if (proto && typeof proto.canPlayType == 'function') {
  97. proto.canPlayType = makeModifiedTypeChecker(proto.canPlayType);
  98. }
  99.  
  100. // Override media source extension isTypeSupported() function
  101. const mse = window.MediaSource;
  102. // Check for MSE support before use
  103. if (mse && typeof mse.isTypeSupported == 'function') {
  104. mse.isTypeSupported = makeModifiedTypeChecker(mse.isTypeSupported);
  105. }
  106.  
  107. }
  108.  
  109.  
  110. let promise = null;
  111.  
  112. function callback(result) {
  113.  
  114. if (result && result.supported && result.smooth) enableAV1();
  115. else {
  116. console.warn("force-youtube-av1", 'Your browser does not support AV1. You might conside to use the latest version of Google Chrome or Mozilla FireFox.');
  117.  
  118. }
  119. }
  120.  
  121.  
  122. try {
  123. promise = navigator.mediaCapabilities.decodingInfo({
  124. type: "file",
  125. video: {
  126. contentType: "video/mp4; codecs=av01.0.05M.08.0.110.05.01.06.0",
  127. height: 1080,
  128. width: 1920,
  129. framerate: 30,
  130. bitrate: 2826848,
  131. },
  132. audio: {
  133. contentType: "audio/webm; codecs=opus",
  134. channels: "2.1",
  135. samplerate: 44100,
  136. bitrate: 255236,
  137. }
  138. }).then(callback).catch(callback);
  139.  
  140. } catch (e) {
  141. promise = null;
  142. }
  143.  
  144. if (!promise) promise = Promise.resolve(0).then(callback).catch(callback);
  145.  
  146.  
  147.  
  148.  
  149. })();

QingJ © 2025

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