YouTube: Force html5_exponential_memory_for_sticky

To prevent YouTube to change the video quality automatically during YouTube Live Streaming.

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

  1. // ==UserScript==
  2. // @name YouTube: Force html5_exponential_memory_for_sticky
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.3.0
  6. // @license MIT
  7. // @author CY Fung
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/yt-engine.png
  9. // @description To prevent YouTube to change the video quality automatically during YouTube Live Streaming.
  10. // @run-at document-start
  11. // @grant none
  12. // @unwrap
  13. // @allFrames true
  14. // @inject-into page
  15. // @require https://gf.qytechs.cn/scripts/475632-ytconfighacks/code/ytConfigHacks.js?version=1252599
  16. // ==/UserScript==
  17.  
  18. // html5_exponential_memory_for_sticky
  19. /* "YouTube to change the video quality automatically during YouTube Live Streaming" refers to the following code:
  20.  
  21. k_=function(a){if(a.Tf){var b=a.Zi;var c=a.Tf;a=a.Dv();if(b.va.qt().isInline())var d=gO;else b.N("html5_exponential_memory_for_sticky")?d=.5>Jwa(b.Z.Wf,"sticky-lifetime")?"auto":TH[xL()]:d=TH[xL()],d=g.RH("auto",d,!1,"s");if(SH(d)){d=n_a(b,c);var e=d.compose,f;a:if((f=c.j)&&f.videoInfos.length){for(var h=g.u(f.videoInfos),l=h.next();!l.done;l=h.next()){l=l.value;var m=void 0;if(null==(m=l.u)?0:m.smooth){f=l.video.j;break a}}f=f.videoInfos[0].video.j}else f=0;Tma()&&!g.MM(b.Z)&&hI(c.j.videoInfos[0])&&
  22. (f=Math.min(f,g.QH.large));d=e.call(d,new PH(0,f,!1,"o"));e=d.compose;f=4320;!b.Z.u||g.FM(b.Z)||b.Z.N("hls_for_vod")||b.Z.N("mweb_remove_360p_cap")||(f=g.QH.medium);(h=g.AL(b.Z.experiments,"html5_default_quality_cap"))&&c.j.j&&!c.videoData.aj&&!c.videoData.me&&(f=Math.min(f,h));h=g.AL(b.Z.experiments,"html5_random_playback_cap");l=/[a-h]$/;h&&l.test(c.videoData.clientPlaybackNonce)&&(f=Math.min(f,h));if(l=h=g.AL(b.Z.experiments,"html5_hfr_quality_cap"))a:{l=c.j;if(l.j)for(l=g.u(l.videoInfos),m=l.next();!m.done;m=
  23. l.next())if(32<m.value.video.fps){l=!0;break a}l=!1}l&&(f=Math.min(f,h));(h=g.AL(b.Z.experiments,"html5_live_quality_cap"))&&c.videoData.isLivePlayback&&(f=Math.min(f,h));f=A_a(b,c,f);d=e.call(d,new PH(0,4320===f?0:f,!1,"d")).compose(z_a(b)).compose(B_a(b,c.videoData,c)).compose(y_a(b,c)).compose(q_a(b,c));SH(a)&&(d=d.compose(r_a(b,c)))}else b.N("html5_perf_cap_override_sticky")&&(d=d.compose(y_a(b,c))),b.N("html5_ustreamer_cap_override_sticky")&&(d=d.compose(r_a(b,c)));d=d.compose(q_a(b,c));b=c.videoData.Yx.compose(d).compose(c.videoData.lT).compose(a)}else b=
  24. gO;return b};
  25.  
  26. */
  27.  
  28. (() => {
  29.  
  30. const win = this instanceof Window ? this : window;
  31.  
  32. // Create a unique key for the script and check if it is already running
  33. const hkey_script = 'ezinmgkfbpgh';
  34. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  35. win[hkey_script] = true;
  36.  
  37. /** @type {globalThis.PromiseConstructor} */
  38. const Promise = ((async () => { })()).constructor;
  39.  
  40. let isMainWindow = false;
  41. try {
  42. isMainWindow = window.document === window.top.document
  43. } catch (e) { }
  44.  
  45. window.ytConfigHacks.add((config_) => {
  46.  
  47. let obj = null;
  48. try {
  49. obj = config_.WEB_PLAYER_CONTEXT_CONFIGS.WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH;
  50. } catch (e) { }
  51.  
  52. if (obj) {
  53.  
  54. const sflags = obj.serializedExperimentFlags
  55. if (typeof sflags === 'string') {
  56. if (sflags.includes('&h5_expr_b9Nkc=true')) return;
  57. obj.serializedExperimentFlags = sflags.replace(/(^|&)html5_exponential_memory_for_sticky=\w+/, '') + '&html5_exponential_memory_for_sticky=true&h5_expr_b9Nkc=true';
  58. }
  59.  
  60. }
  61.  
  62. });
  63.  
  64. })();

QingJ © 2025

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