YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前為 2024-04-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.14.5
  6. // @license MIT
  7. // @author CY Fung
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/yt-engine.png
  9. // @description To enhance YouTube performance by modifying YouTube JS Engine
  10. // @grant none
  11. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@7221a4efffd49d852de0074ec503d4febb99f28b/library/nextBrowserTick.min.js
  12. // @run-at document-start
  13. // @unwrap
  14. // @inject-into page
  15. // @allFrames true
  16. // ==/UserScript==
  17.  
  18. (() => {
  19.  
  20. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  21. const FIX_schedulerInstanceInstance = 2 | 4;
  22. const FIX_yt_player = true; // DONT CHANGE
  23. const FIX_Animation_n_timeline = true;
  24. const NO_PRELOAD_GENERATE_204 = false;
  25. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  26. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  27. const CHANGE_appendChild = true; // discussions#236759
  28.  
  29. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  30. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  31. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  32.  
  33. const FIX_Iframe_NULL_SRC = true;
  34.  
  35. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  36.  
  37. const FIX_ytdExpander_childrenChanged = true;
  38. const FIX_paper_ripple_animate = true;
  39. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  40. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  41.  
  42. const FIX_doIdomRender = true;
  43.  
  44. const FIX_Shady = true;
  45.  
  46. // [[ 2024.04.24 ]]
  47. const MODIFY_ShadyDOM_OBJ = true;
  48. // << if MODIFY_ShadyDOM_OBJ >>
  49. const WEAKREF_ShadyDOM = true;
  50. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  51. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  52. // << end >>
  53.  
  54. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  55.  
  56. const FIX_ytAction_ = true; // ytd-app
  57. const FIX_onVideoDataChange = false;
  58. // const FIX_onClick = true;
  59. const FIX_onStateChange = true;
  60. const FIX_onLoopRangeChange = true;
  61. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  62. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  63.  
  64. const ENABLE_discreteTasking = true;
  65. // << if ENABLE_discreteTasking >>
  66. const FIX_stampDomArray_stableList = true;
  67. const ENABLE_weakenStampReferences = true; // disabled in old browsers
  68. // << end >>
  69.  
  70. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  71. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  72.  
  73. const UNLOAD_DETACHED_POLYMER = false; // unstable
  74.  
  75. const WEAK_REF_BINDING = true; // false if your browser is slow
  76. // << if WEAK_REF_BINDING >>
  77. const WEAK_REF_PROXY_DOLLAR = true; // false if your browser is slow
  78. // << end >>
  79.  
  80. const TO_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  81. const DEBUG_removePrune = false; // true for DEBUG
  82.  
  83. const FIX_XHR_REQUESTING = true;
  84. const FIX_VIDEO_BLOCKING = true; // usually it is a ads block issue
  85.  
  86. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  87.  
  88. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  89.  
  90. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  91. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  92.  
  93. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  94.  
  95. // ----------------------------- Shortkey Keyboard Control -----------------------------
  96. // dependency: FIX_yt_player
  97.  
  98. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  99. // [0] no fix - not recommended
  100. // [1] basic fix - just fix the global focus detection variable
  101. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  102. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  103.  
  104. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  105. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  106.  
  107.  
  108. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  109.  
  110. // ----------------------------- Shortkey Keyboard Control -----------------------------
  111.  
  112. /*
  113. window.addEventListener('edm',()=>{
  114. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  115. });
  116.  
  117. window.addEventListener('edn',()=>{
  118. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  119. });
  120. window.addEventListener('edr',()=>{
  121. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  122. });
  123. */
  124.  
  125. // only for macOS with Chrome/Firefox 100+
  126. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  127.  
  128. const win = this instanceof Window ? this : window;
  129.  
  130. // Create a unique key for the script and check if it is already running
  131. const hkey_script = 'jswylcojvzts';
  132. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  133. win[hkey_script] = true;
  134.  
  135.  
  136.  
  137. let BY_PASS_KEYBOARD_CONTROL = false;
  138.  
  139.  
  140. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  141. /** @type {(f: ()=>{})=>{}} */
  142. const nextBrowserTick = (self || 0).nextBrowserTick || 0;
  143. const nextBrowserTick_ = nextBrowserTick || (f => f());
  144.  
  145. let p59 = 0;
  146.  
  147. const Promise = (async () => { })().constructor;
  148.  
  149. const PromiseExternal = ((resolve_, reject_) => {
  150. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  151. return class PromiseExternal extends Promise {
  152. constructor(cb = h) {
  153. super(cb);
  154. if (cb === h) {
  155. /** @type {(value: any) => void} */
  156. this.resolve = resolve_;
  157. /** @type {(reason?: any) => void} */
  158. this.reject = reject_;
  159. }
  160. }
  161. };
  162. })();
  163.  
  164. /**
  165. @param {number} x
  166. @param {number} d */
  167. const toFixed2 = (x, d) => {
  168. let t = x.toFixed(d);
  169. let y = `${+t}`;
  170. return y.length > t.length ? t : y;
  171. }
  172.  
  173.  
  174. let pf31 = new PromiseExternal();
  175.  
  176. // native RAF
  177. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  178.  
  179. // 1st wrapped RAF
  180. const baseRAF = (callback) => {
  181. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  182. pf31.then(() => {
  183. callback(hRes);
  184. });
  185. });
  186. };
  187.  
  188. // 2nd wrapped RAF
  189. window.requestAnimationFrame = baseRAF;
  190.  
  191. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  192. const indr = o => insp(o).$ || o.$ || 0;
  193.  
  194. const prototypeInherit = (d, b) => {
  195. const m = Object.getOwnPropertyDescriptors(b);
  196. for (const p in m) {
  197. if (!Object.getOwnPropertyDescriptor(d, p)) {
  198. Object.defineProperty(d, p, m[p]);
  199. }
  200. }
  201. };
  202.  
  203. /** @type {(o: Object | null) => WeakRef | null} */
  204. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  205.  
  206. /** @type {(wr: Object | null) => Object | null} */
  207. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  208.  
  209. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  210. if (DENY_requestStorageAccess) {
  211. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  212. Document.prototype.requestStorageAccessFor = undefined;
  213. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  214. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  215. Document.prototype.requestStorageAccessFor = function () {
  216. return new Promise((resolve, reject) => {
  217. reject();
  218. });
  219. };
  220. }
  221. }
  222.  
  223. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  224. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  225. const f = performance.now23 = Performance.prototype.now;
  226.  
  227. let k = 0; // 0 <= k < 9998m
  228. let u = 0;
  229. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  230.  
  231. // By definition, performance.now() is mono increasing.
  232. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  233. performance.now = performance.now16 = function () {
  234. /**
  235. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  236. *
  237. * If consecutive session history entries had history.state.entryTime set to same value,
  238. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  239. * and modifying its return value slightly to make sure two close consecutive calls don't
  240. * get the same result helped with resolving the issue.
  241. */
  242. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  243. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  244.  
  245. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  246. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  247. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  248. else { // more than 9998 consecutive calls
  249. /**
  250. *
  251. * max no. of consecutive calls
  252. *
  253. * Sample Size: 4800
  254. * Sample Avg = 1565.375
  255. * Sample Median = 1469.5
  256. * Sample Max = 5660 << 7500 << 9999
  257. *
  258. *
  259. * */
  260. k = 0;
  261. s += 1 / 7;
  262. }
  263. return v + k; // 0 < v - M < v - M + k < v
  264. }
  265.  
  266. let loggerMsg = '';
  267. if (`${performance.now()}` === `${performance.now()}`) {
  268. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  269. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  270. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  271. }
  272. loggerMsg && console.warn(loggerMsg);
  273. })();
  274.  
  275. // WEAKREF_ShadyDOM
  276.  
  277. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  278.  
  279. const setupPlainShadyDOM = (b) => {
  280. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  281. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  282. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  283. b.patchOnDemand = true;
  284. b.preferPerformance = true;
  285. b.noPatch = true;
  286. }
  287.  
  288. const isPlainObject = (b, m) => {
  289. if (!b || typeof b !== 'object') return false;
  290. const e = Object.getOwnPropertyDescriptors(b);
  291. if (e.length <= m) return false;
  292. let pr = 0;
  293. for (const k in e) {
  294. const d = e[k];
  295. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  296. if (!('value' in d) || typeof d.value === 'function') return false;
  297. pr++;
  298. }
  299. return pr > m;
  300. }
  301.  
  302. let b;
  303.  
  304. let lz = 0;
  305.  
  306. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  307. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  308.  
  309. // Brave - ShadyDOM exists before userscripting
  310. b = sdp.value;
  311.  
  312. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  313. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  314. lz = 1;
  315. }
  316.  
  317. }
  318.  
  319.  
  320. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  321. } else if (!sdp) {
  322. } else {
  323. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  324. return;
  325. }
  326.  
  327. const shadyDOMNodeWRM = new WeakMap();
  328.  
  329. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  330.  
  331. function weakWrapper(_ShadyDOM) {
  332. const ShadyDOM = _ShadyDOM;
  333. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  334. let nullElement = { node: null };
  335. Object.setPrototypeOf(nullElement, Element.prototype);
  336. let p = new ShadyDOM.Wrapper(nullElement);
  337. let d = Object.getOwnPropertyDescriptor(p, 'node');
  338. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  339. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', {
  340. get() {
  341. let w = shadyDOMNodeWRM.get(this);
  342. if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
  343. return w;
  344. },
  345. set(nv) {
  346. shadyDOMNodeWRM.set(this, mWeakRef(nv));
  347. return true;
  348. },
  349. enumerable: true,
  350. configurable: true
  351. });
  352. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  353. }
  354. }
  355. }
  356.  
  357. let previousWrapStore = null;
  358.  
  359. const standardWrap = function (a) {
  360. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  361. if (previousWrapStore) {
  362. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  363. if (s) {
  364. previousWrapStore.delete(a);
  365. shadyDOMNodeWRM.set(a, mWeakRef(s));
  366. }
  367. }
  368. let u = kRef(shadyDOMNodeWRM.get(a));
  369. if (!u) {
  370. u = new ShadyDOM.Wrapper(a);
  371. shadyDOMNodeWRM.set(a, mWeakRef(u));
  372. }
  373. return u;
  374. }
  375.  
  376.  
  377. function setupWrapFunc(_ShadyDOM) {
  378. const ShadyDOM = _ShadyDOM;
  379.  
  380.  
  381. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  382. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  383. return;
  384. }
  385. let mm = new Set();
  386. const pget = wmPD.value;
  387. WeakMap.prototype.get = function (a) {
  388. mm.add(this);
  389. return a;
  390. }
  391. try {
  392. let nullElement = { node: null };
  393. Object.setPrototypeOf(nullElement, Element.prototype);
  394. ShadyDOM.wrapIfNeeded(nullElement)
  395. ShadyDOM.wrap(nullElement)
  396. } catch (e) { }
  397. WeakMap.prototype.get = pget;
  398. if (mm.size !== 1) {
  399. mm.clear();
  400. return;
  401. }
  402. const p = mm.values().next().value;
  403. if (!(p instanceof WeakMap)) return;
  404. // p.clear();
  405. // p.get = function (a) { return a }
  406. // p.set = function (a, b) { return this }
  407. // console.log(188, window.n2n = mm, window.n2p = p)
  408.  
  409. // console.log(34929,p.size)
  410. previousWrapStore = p;
  411.  
  412. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  413. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  414. }
  415. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  416. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  417. }
  418.  
  419. }
  420.  
  421. function setupLZ3(nv) {
  422.  
  423. const ShadyDOM = nv;
  424.  
  425. const ShadyDOMSettings = ShadyDOM.settings;
  426. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  427. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  428. return false;
  429. }
  430.  
  431. weakWrapper(ShadyDOM);
  432.  
  433. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  434.  
  435. setupPlainShadyDOM(ShadyDOMSettings);
  436. setupPlainShadyDOM(ShadyDOM);
  437.  
  438. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  439.  
  440. setupWrapFunc(ShadyDOM);
  441. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  442. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  443.  
  444. // To be confirmed
  445. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  446. ShadyDOM.composedPath = function (e) {
  447. const t = (e || 0).target || null;
  448. if (!(t instanceof HTMLElement)) {
  449. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  450. }
  451. return t instanceof HTMLElement ? [t] : [];
  452. };
  453. }
  454.  
  455. }
  456.  
  457. }
  458.  
  459.  
  460. function setupLZ6(nv) {
  461.  
  462. const ShadyDOM = nv;
  463.  
  464. const ShadyDOMSettings = ShadyDOM.settings;
  465.  
  466. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  467. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  468. return false;
  469. }
  470.  
  471. weakWrapper(ShadyDOM);
  472.  
  473. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  474.  
  475. setupPlainShadyDOM(ShadyDOMSettings);
  476. setupPlainShadyDOM(ShadyDOM);
  477.  
  478. setupWrapFunc(ShadyDOM);
  479.  
  480. }
  481.  
  482. }
  483.  
  484. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  485.  
  486. const nv = b;
  487.  
  488. if (setupLZ6(nv) === false) return;
  489.  
  490. lz = 6;
  491.  
  492. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  493.  
  494. return;
  495. }
  496.  
  497. delete window.ShadyDOM;
  498.  
  499. Object.defineProperty(window, 'ShadyDOM', {
  500. get() {
  501. return b;
  502. },
  503. set(nv) {
  504. let ret = 0;
  505. try {
  506. do {
  507. if (!nv || !nv.settings) {
  508. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  509. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  510. lz = 1;
  511. break;
  512. } else {
  513. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  514. break;
  515. }
  516. }
  517.  
  518. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  519. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  520. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  521. break;
  522. }
  523.  
  524. if (setupLZ3(nv) === false) break;
  525.  
  526. lz = 3;
  527.  
  528. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  529.  
  530. ret = 1;
  531.  
  532. } while (0);
  533. } catch (e) {
  534. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  535. }
  536.  
  537. if (!ret) b = nv;
  538. else {
  539. delete this.ShadyDOM;
  540. this.ShadyDOM = nv;
  541. }
  542. return true;
  543. },
  544. enumerable: false,
  545. configurable: true
  546. });
  547.  
  548. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  549.  
  550. if (ENABLE_ASYNC_DISPATCHEVENT && nextBrowserTick) {
  551. const filter = new Set([
  552. 'yt-action',
  553. // 'iframe-src-replaced',
  554. 'shown-items-changed',
  555. 'can-show-more-changed', 'collapsed-changed',
  556.  
  557. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  558. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  559. 'yt-navigate-finish',
  560.  
  561. // 'data-changed','yt-watch-comments-ready'
  562. ])
  563. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  564. EventTarget.prototype.dispatchEvent = function (event) {
  565. const type = (event || 0).type;
  566. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  567. if (!filter.has(type) && !type.endsWith('-changed')) {
  568. if (this instanceof Node || this instanceof Window) {
  569. nextBrowserTick(() => this.dispatchEvent938(event));
  570. return true;
  571. }
  572. }
  573. }
  574. return this.dispatchEvent938(event);
  575. }
  576. }
  577.  
  578. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  579. const removePrune_propNeedles = () => {
  580. // const xhr = new XMLHttpRequest;
  581. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  582. if (!pdOri || pdOri.configurable !== true) return;
  583. let propNeedles = null;
  584. const pdNew = {
  585. configurable: true,
  586. enumerable: true,
  587. get: function () {
  588. propNeedles = this;
  589. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  590. throw new Error();
  591. }
  592. }
  593. Object.defineProperty(Map.prototype, 'size', pdNew);
  594. try {
  595. XMLHttpRequest.prototype.open.call(0);
  596. // xhr.open.call(null)
  597. } catch (e) { }
  598. Object.defineProperty(Map.prototype, 'size', pdOri);
  599. if (!propNeedles) return;
  600. const entries = [...propNeedles.entries()];
  601. propNeedles.clear();
  602. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  603. }
  604.  
  605. if (TO_REMOVE_PRUNE_propNeedles) {
  606. removePrune_propNeedles();
  607. }
  608.  
  609. if (FIX_XHR_REQUESTING) {
  610.  
  611. const URL = window.URL || new Function('return URL')();
  612. const createObjectURL = URL.createObjectURL.bind(URL);
  613.  
  614. XMLHttpRequest = (() => {
  615. const XMLHttpRequest_ = XMLHttpRequest;
  616. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  617. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  618. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  619. constructor(...args) {
  620. super(...args);
  621. }
  622. open(method, url, ...args) {
  623. let skip = false;
  624. if (!url || typeof url !== 'string') skip = true;
  625. else if (typeof url === 'string') {
  626. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  627. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  628. skip = true;
  629. } else if (turl.includes('.youtube.com/pagead/')) {
  630. skip = true;
  631. } else if (turl.includes('.youtube.com/ptracking')) {
  632. skip = true;
  633. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  634. skip = true;
  635. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  636. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  637. skip = true;
  638. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  639. skip = true;
  640. } else {
  641. // skip = true; // for user activity logging e.g. watched videos
  642. }
  643. } else if (turl.includes('play.google.com/log')) {
  644. skip = true;
  645. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  646. skip = true;
  647. }
  648. }
  649. if (!skip) {
  650. this.__xmMc8__ = 1;
  651. return super.open(method, url, ...args);
  652. } else {
  653. this.__xmMc8__ = 2;
  654. return super.open('GET', url0);
  655. }
  656. }
  657. send(...args) {
  658. if (this.__xmMc8__ === 1) {
  659. return super.send(...args);
  660. } else if (this.__xmMc8__ === 2) {
  661. return super.send();
  662. } else {
  663. console.log('[yt-js-engine-tamer]', 'xhr warning');
  664. return super.send(...args);
  665. }
  666. }
  667. }
  668. c.prototype.__xmMc8__ = 0;
  669. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  670. return c;
  671. })();
  672. }
  673.  
  674. // Alternative HACK -> Tabview Youtube
  675. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  676.  
  677. // ---- << this.overscrollConfig HACK >> -----
  678.  
  679. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  680.  
  681. /*
  682.  
  683. ;function gZb(a, b) {
  684. b = void 0 === b ? !0 : b;
  685. a.addEventListener("wheel", hZb);
  686. a.overscrollConfig = {
  687. cooldown: b
  688. }
  689. }
  690. function iZb(a) {
  691. a.overscrollConfig = void 0;
  692. a.removeEventListener("wheel", hZb)
  693. }
  694. function hZb(a) {
  695. var b = a.deltaY
  696. , c = a.target
  697. , d = null;
  698. if (window.Polymer && window.Polymer.Element) {
  699. if (c = a.path || a.composedPath && a.composedPath()) {
  700. c = g(c);
  701. for (var e = c.next(); !e.done && (e = e.value,
  702. !jZb(e, b)); e = c.next())
  703. if (e.overscrollConfig) {
  704. d = e;
  705. break
  706. }
  707. }
  708. } else
  709. for (; c && !jZb(c, b); ) {
  710. if (c.overscrollConfig) {
  711. d = c;
  712. break
  713. }
  714. c = c.parentElement
  715. }
  716. d && (b = d.overscrollConfig,
  717. b.cooldown ? (d = a.deltaY,
  718. c = b.lastDeltaY || 0,
  719. b.lastDeltaY = d,
  720. e = b.lastStopped || 0,
  721. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  722. c = !1) : (d = e + 600,
  723. c = !0) : (d = Date.now() + 600,
  724. c = !0),
  725. d > Date.now() && (a.preventDefault(),
  726. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  727. }
  728. */
  729.  
  730. let wheelHandler = function (a) {
  731. if (window.Polymer && window.Polymer.Element) {
  732. let c;
  733. if (c = a.path || a.composedPath && a.composedPath()) {
  734. for (const e of c) {
  735. const cnt = insp(e);
  736. if (e.overscrollConfig) e.overscrollConfig = void 0;
  737. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  738. }
  739. }
  740. } else {
  741. let e = a.target;
  742. for (; e instanceof Element; e = e.parentElement) {
  743. const cnt = insp(e);
  744. if (e.overscrollConfig) e.overscrollConfig = void 0;
  745. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  746. }
  747. }
  748. };
  749.  
  750. let checkWheelListenerObjs = null;
  751.  
  752. let getObjsFn = () => {
  753. let euyVal = 0;
  754. const eukElm = {};
  755. Object.setPrototypeOf(eukElm, HTMLElement.prototype);
  756. const euzObj = new Proxy(eukElm, {
  757. get(target, prop) {
  758. throw `ErrorF31.get(${prop})`
  759. },
  760. set(target, prop, value) {
  761. throw `ErrorF33.set(${prop}, ${value})`
  762. }
  763. });
  764. const euxElm = new Proxy(eukElm, {
  765. get(target, prop) {
  766. if (prop === 'scrollTop') {
  767. euyVal = euyVal | 8;
  768. return 0;
  769. }
  770. if (prop === 'overscrollConfig') {
  771. euyVal = euyVal | 16;
  772. return void 0;
  773. }
  774. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  775. return 640;
  776. }
  777. if (prop === 'scrollLeft') {
  778. euyVal = euyVal | 8;
  779. return 0;
  780. }
  781. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  782. return 800;
  783. }
  784. throw `ErrorF45.get(${prop})`
  785. },
  786. set(target, prop, value) {
  787. throw `ErrorF47.set(${prop}, ${value})`
  788. }
  789. });
  790. const eukEvt = {};
  791. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  792. const euyEvt = new Proxy(eukEvt, {
  793. get(target, prop) {
  794. if (prop === 'deltaY' || prop === 'deltaX') {
  795. euyVal = euyVal | 1;
  796. return -999;
  797. }
  798. if (prop === 'target') {
  799. euyVal = euyVal | 2;
  800. return euxElm
  801. }
  802. if (prop === 'path' || prop === 'composedPath') {
  803. euyVal = euyVal | 2;
  804. return [euxElm]
  805. }
  806. throw `ErrorF51.get(${prop})`
  807. },
  808. set(target, prop, value) {
  809. throw `ErrorF53.set(${prop}, ${value})`
  810. }
  811. });
  812. const setVal = (v) => {
  813. euyVal = v;
  814. }
  815. const getVal = () => {
  816. return euyVal;
  817. }
  818. return { euzObj, euyEvt, setVal, getVal };
  819. }
  820.  
  821. let checkWheelListener = (callback) => {
  822.  
  823. let callbackIdentifier = '';
  824.  
  825. let res = null;
  826. try {
  827. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  828. setVal(0);
  829. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  830. throw `RESULT${getVal()}`;
  831. } catch (e) {
  832. res = e;
  833. }
  834.  
  835. res = `${res}` || `${null}`;
  836. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  837.  
  838. callbackIdentifier = res;
  839. if (callbackIdentifier === 'RESULT27') 0;
  840. else if (callbackIdentifier === 'RESULT0') {
  841. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  842. } else if (callbackIdentifier.startsWith('RESULT')) {
  843. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  844. }
  845. return callbackIdentifier;
  846.  
  847. };
  848.  
  849. let callbackFound = false;
  850. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  851. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  852. // M-youtube-js-engine-tamer.52178
  853. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  854. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  855. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  856. // RESULTXX / ErrorFXX / Other...
  857. if (callbackIdentifier === 'RESULT27') {
  858. this.overscrollConfigDisable = true;
  859. if (!callbackFound) {
  860. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  861. getObjsFn = checkWheelListener = null;
  862. checkWheelListenerObjs = null;
  863. wheelHandler = null;
  864. }
  865. return void 0;
  866. } else if (!callbackFound && !this.overscrollConfigDisable) {
  867. this.overscrollConfigDisable = true;
  868. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  869. }
  870. }
  871. return this.addEventListener52178(type, callback, option);
  872. };
  873.  
  874. // ---- << this.overscrollConfig HACK >> -----
  875.  
  876. }
  877.  
  878. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  879.  
  880. let p_a_objWR = null;
  881. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  882. let ytPageReady = 0;
  883.  
  884. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  885. let isGlobalSpaceControl = true;
  886. let mediaPlayerElementWR = null;
  887. let focusedElementAtSelection = null;
  888.  
  889. // let want_control_video = false;
  890.  
  891. let spaceBarControl_keyG = '';
  892.  
  893. let lastUserAction = 0;
  894.  
  895. const wmKeyControlPhase = new WeakMap();
  896.  
  897. let currentSelectionText = null;
  898.  
  899. const getCurrentSelectionText = () => {
  900. if (currentSelectionText !== null) return currentSelectionText
  901. return (currentSelectionText = getSelection() + "")
  902. }
  903.  
  904. const pageMediaWatcher = () => {
  905.  
  906. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  907. // want_control_video = false;
  908. // }, { capture: true, passive: true });
  909.  
  910. document.addEventListener('yt-navigate', () => {
  911. ytPageReady = 0;
  912. });
  913. document.addEventListener('yt-navigate-start', () => {
  914. ytPageReady = 0;
  915. });
  916. document.addEventListener('yt-navigate-cache', () => {
  917. ytPageReady = 0;
  918. });
  919.  
  920. document.addEventListener('yt-navigate-finish', () => {
  921. ytPageReady = 1;
  922. });
  923.  
  924. document.addEventListener('durationchange', () => {
  925. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  926. if (elm.duration > 0.01) {
  927. if (elm.closest('[hidden]')) continue;
  928. mediaPlayerElementWR = mWeakRef(elm);
  929. return;
  930. }
  931. }
  932. }, { capture: true, passive: true });
  933.  
  934. document.addEventListener('selectionchange', (evt) => {
  935. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  936. currentSelectionText = null;
  937. if (!(evt.target instanceof Node)) return;
  938. focusedElementAtSelection = evt.target;
  939. }, { capture: true, passive: true })
  940.  
  941. document.addEventListener('pointerdown', (evt) => {
  942. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  943. }, { capture: true, passive: true });
  944.  
  945.  
  946. document.addEventListener('pointerup', (evt) => {
  947. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  948. }, { capture: true, passive: true });
  949.  
  950.  
  951. document.addEventListener('keydown', (evt) => {
  952. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  953. }, { capture: true, passive: true });
  954.  
  955. document.addEventListener('keyup', (evt) => {
  956. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  957. }, { capture: true, passive: true });
  958.  
  959. };
  960.  
  961.  
  962. const checkKeyB = (p_a_obj) => {
  963.  
  964. const boolList = new Set();
  965. const p_a_obj_api = p_a_obj.api;
  966.  
  967. const nilFunc0 = function () {
  968. return void 0
  969. };
  970. const mt = new Proxy({}, {
  971. get(target, prop) {
  972. if (prop === 'get') return nilFunc0;
  973. return mt;
  974. }
  975. });
  976. const nilFunc = function () {
  977. return mt
  978. };
  979. const mw = new Proxy({}, {
  980. get(target, prop) {
  981. if (prop in p_a_obj_api) {
  982. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  983. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  984. if (q && q.value) {
  985. if (!q.writable) return q.value;
  986. if (typeof q.value === 'string') return '';
  987. if (typeof q.value === 'number') return 0;
  988. if (typeof q.value === 'boolean') return false;
  989. if (q.value && typeof q.value === 'object') return {};
  990. }
  991. }
  992. return undefined;
  993. },
  994. set(target, prop) {
  995. throw 'mwSet';
  996. }
  997. });
  998.  
  999. const mq = new Proxy({}, {
  1000. get(target, prop) {
  1001. if (prop === 'api') return mw;
  1002. if (prop in p_a_obj) {
  1003. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  1004. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  1005. if (q && q.value) {
  1006. if (!q.writable) return q.value;
  1007. if (typeof q.value === 'string') return '';
  1008. if (typeof q.value === 'number') return 0;
  1009. if (typeof q.value === 'boolean') return false;
  1010. if (q.value && typeof q.value === 'object') return {};
  1011. }
  1012. }
  1013. return undefined;
  1014. },
  1015. set(target, prop, val) {
  1016. if (typeof val === 'boolean') boolList.add(prop)
  1017. throw `mqSet(${prop},${val})`;
  1018. }
  1019. });
  1020.  
  1021. let res = ''
  1022. try {
  1023. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  1024. } catch (e) {
  1025. res = `ERROR::${e}`;
  1026. }
  1027.  
  1028. if (boolList.size === 1) {
  1029. const value = boolList.values().next().value;
  1030. if (res === `ERROR::mqSet(${value},${true})`) {
  1031. p_a_obj.__uZWaD__ = value;
  1032. }
  1033. }
  1034.  
  1035. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  1036.  
  1037. }
  1038.  
  1039.  
  1040. let pm_p_a = null;
  1041.  
  1042. const p_a_init = function () {
  1043. const r = this.init91();
  1044. const keyBw = this.__cPzfo__ || '__NIL__';
  1045. const p_a_obj = this[keyBw];
  1046. if (!p_a_obj) return;
  1047. try {
  1048. checkKeyB(p_a_obj);
  1049. } catch (e) { }
  1050. p_a_objWR = mWeakRef(p_a_obj);
  1051. if (FIX_SHORTCUTKEYS > 0) {
  1052. if (p_a_obj && !p_a_obj.hVhtg) {
  1053. p_a_obj.hVhtg = 1;
  1054.  
  1055. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  1056. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  1057. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  1058. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  1059. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  1060. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  1061.  
  1062. }
  1063. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  1064. // const api = p_a_obj.api
  1065. // api.hVhtg = 1;
  1066. // api.playVideo91 = api.playVideo;
  1067. // api.playVideo = p_a_jt.playVideo;
  1068. // api.pauseVideo91 = api.pauseVideo;
  1069. // api.pauseVideo = p_a_jt.pauseVideo;
  1070. // }
  1071. }
  1072. if (pm_p_a) {
  1073. pm_p_a.resolve();
  1074. pm_p_a = null;
  1075. }
  1076. return r;
  1077. };
  1078.  
  1079. const p_a_xt = {
  1080.  
  1081. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  1082.  
  1083. if (FIX_SHORTCUTKEYS === 2) {
  1084.  
  1085. if (activeElement) {
  1086.  
  1087. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  1088.  
  1089. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  1090. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  1091. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  1092.  
  1093. }
  1094.  
  1095. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  1096. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  1097. // console.log(582, isDelayedSpaceBar)
  1098. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  1099.  
  1100. if (activeElement && (h === 'Space' || h === 'Enter')) {
  1101. const controlPhase = wmKeyControlPhase.get(activeElement);
  1102. if (controlPhase === 4 || controlPhase === 5) return false;
  1103. }
  1104. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  1105. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  1106. // if (!isSpaceKeyImmediate) return false;
  1107. // }
  1108. }
  1109.  
  1110. },
  1111.  
  1112. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  1113.  
  1114. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  1115.  
  1116. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  1117. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  1118. // console.log(583, isDelayedSpaceBar)
  1119. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  1120.  
  1121. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1122.  
  1123. let mediaWorking = false;
  1124. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  1125. mediaWorking = true;
  1126. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  1127. mediaWorking = true;
  1128. }
  1129. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  1130. mediaWorking && Promise.resolve().then(() => {
  1131. if (activeElement === document.activeElement) {
  1132. return activeElement.blur()
  1133. } else {
  1134. return false
  1135. }
  1136. }).then((r) => {
  1137. r !== false && mediaPlayerElement.focus();
  1138. });
  1139. }
  1140. },
  1141.  
  1142.  
  1143. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  1144.  
  1145. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  1146. if (!getGlobalSpacebarControlFlag()) return false;
  1147.  
  1148. const activeElement = document.activeElement;
  1149.  
  1150. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  1151. if (allow === false) return false;
  1152.  
  1153. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  1154. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  1155.  
  1156. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  1157.  
  1158. return ret;
  1159. },
  1160. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  1161.  
  1162.  
  1163. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  1164.  
  1165. if (!getGlobalSpacebarControlFlag()) return false;
  1166.  
  1167. const activeElement = document.activeElement;
  1168. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  1169. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  1170. // }
  1171. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  1172. if (allow === false) return false;
  1173.  
  1174. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  1175. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  1176.  
  1177. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  1178.  
  1179. return ret;
  1180. }
  1181.  
  1182. };
  1183.  
  1184. // const p_a_jt = { // API
  1185.  
  1186. // playVideo(a) { // without spinner effect
  1187.  
  1188. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  1189.  
  1190. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1191. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  1192. // want_control_video = true;
  1193. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  1194. // }
  1195.  
  1196. // }
  1197. // return this.playVideo91(a);
  1198.  
  1199. // },
  1200.  
  1201. // pauseVideo(a) { // without spinner effect
  1202.  
  1203. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  1204.  
  1205. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1206. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  1207. // want_control_video = true;
  1208. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  1209. // }
  1210.  
  1211. // }
  1212. // return this.pauseVideo91(a);
  1213.  
  1214. // }
  1215. // };
  1216.  
  1217. let flagSpeedMaster = null;
  1218. const getSpeedMasterControlFlag = () => {
  1219.  
  1220. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  1221. isSpeedMastSpacebarControlEnabled = false;
  1222. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  1223. isSpeedMastSpacebarControlEnabled = true;
  1224. }
  1225. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  1226. isSpeedMastSpacebarControlEnabled = true;
  1227. }
  1228.  
  1229. if (flagSpeedMaster === null) {
  1230. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  1231. if (!p) {
  1232. flagSpeedMaster = false;
  1233. } else {
  1234.  
  1235. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  1236.  
  1237. }
  1238.  
  1239. }
  1240. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  1241.  
  1242. return isSpeedMastSpacebarControlEnabled;
  1243. }
  1244.  
  1245.  
  1246. const getGlobalSpacebarControlFlag = () => {
  1247.  
  1248. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  1249. isGlobalSpaceControl = false;
  1250. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  1251. isGlobalSpaceControl = true;
  1252. }
  1253. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  1254. isGlobalSpaceControl = true;
  1255. }
  1256.  
  1257. return isGlobalSpaceControl;
  1258. }
  1259.  
  1260. const keyboardController = async (_yt_player) => {
  1261.  
  1262. const keyQT = getQT(_yt_player);
  1263. const keySV = getSV(_yt_player);
  1264. const keyDX = getDX(_yt_player);
  1265. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  1266.  
  1267. if (!keyDX) return;
  1268. if (keyDX === keyQT || keyDX === keySV) return;
  1269.  
  1270. if (typeof keyDX !== 'string') return;
  1271.  
  1272. let lastAccessKey = '';
  1273. let lastAccessKeyConfirmed = '';
  1274. const mb = new Proxy({}, {
  1275. get(target, prop) {
  1276. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  1277. throw 'mbGet'
  1278. },
  1279. set(target, prop, val) {
  1280. throw 'mbSet'
  1281. }
  1282. });
  1283. const ma = new Proxy({}, {
  1284. get(target, prop) {
  1285. lastAccessKey = prop;
  1286. return mb
  1287. },
  1288. set(target, prop, val) {
  1289. throw 'maSet'
  1290. }
  1291. });
  1292.  
  1293. let keyBw = '';
  1294. try {
  1295. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  1296. } catch (e) {
  1297. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  1298. keyBw = lastAccessKeyConfirmed;
  1299. }
  1300. }
  1301.  
  1302. if (!keyBw) return;
  1303.  
  1304. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  1305.  
  1306. pm_p_a = new PromiseExternal();
  1307.  
  1308. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  1309.  
  1310. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  1311.  
  1312. _yt_player[keyDX].prototype.init = p_a_init;
  1313.  
  1314. await pm_p_a.then();
  1315. const p_a_obj = kRef(p_a_objWR);
  1316.  
  1317. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  1318.  
  1319.  
  1320. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  1321.  
  1322. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  1323.  
  1324. if (!isSpeedMastSpacebarControlEnabled) {
  1325.  
  1326. if (config && config.EXPERIMENT_FLAGS) {
  1327. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  1328. }
  1329. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  1330. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  1331. }
  1332.  
  1333. } else {
  1334.  
  1335. if (config && config.EXPERIMENT_FLAGS) {
  1336. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  1337. }
  1338. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  1339. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  1340. }
  1341.  
  1342. }
  1343.  
  1344. }
  1345.  
  1346. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  1347.  
  1348.  
  1349.  
  1350.  
  1351. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  1352.  
  1353. // console.log(p_a_obj.handleGlobalKeyUp)
  1354. console.log('[yt-js-engine-tamer] p_a', p_a_obj)
  1355.  
  1356. // console.log(p_a_obj.api)
  1357.  
  1358.  
  1359. // QT -> DX(SV) -> p_a
  1360.  
  1361.  
  1362. /*
  1363. *
  1364. *
  1365. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  1366. b = void 0 === b ? !1 : b;
  1367. c = void 0 === c ? !1 : c;
  1368. d = void 0 === d ? !1 : d;
  1369. e = void 0 === e ? !1 : e;
  1370. var l = g.PT(this);
  1371. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  1372. }
  1373.  
  1374. */
  1375.  
  1376. /*
  1377. *
  1378. *
  1379. *
  1380. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  1381. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  1382. }
  1383.  
  1384. */
  1385.  
  1386.  
  1387. // if(!keyDX) return;
  1388.  
  1389. // console.log(4999, keyDX)
  1390.  
  1391. };
  1392.  
  1393.  
  1394. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  1395.  
  1396. const p_a_obj = kRef(p_a_objWR);
  1397. // const api = p_a_obj.api;
  1398.  
  1399.  
  1400. // console.log(540);
  1401.  
  1402. let boolList = null;
  1403. let ret;
  1404. isSpaceKeyImmediate = true;
  1405. try {
  1406.  
  1407. ret = 0;
  1408. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  1409. let p_a_objT;
  1410. if (!spaceBarControl_keyG) { // just in case
  1411. boolList = new Set();
  1412. p_a_objT = new Proxy(p_a_obj, {
  1413. get(target, prop, handler) {
  1414. const val = target[prop];
  1415. if (typeof val !== 'boolean') return val;
  1416. boolList.add(prop);
  1417. // console.log(555, prop, val);
  1418. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  1419. spaceBarControl_keyG = prop;
  1420. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  1421. val = false;
  1422. }
  1423. return val;
  1424. }
  1425. });
  1426.  
  1427.  
  1428. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  1429. p_a_obj[spaceBarControl_keyG] = false;
  1430. p_a_objT = p_a_obj;
  1431. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  1432. } else {
  1433.  
  1434. p_a_objT = p_a_obj;
  1435. }
  1436.  
  1437. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  1438.  
  1439.  
  1440. } catch (e) {
  1441. console.log(e)
  1442. }
  1443. isSpaceKeyImmediate = false;
  1444.  
  1445. if (boolList && boolList.size === 1) {
  1446. const value = boolList.values().next().value;
  1447. spaceBarControl_keyG = value;
  1448. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  1449.  
  1450. }
  1451.  
  1452. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  1453.  
  1454. return ret;
  1455. }
  1456.  
  1457. const shortcutKeysFixer = () => {
  1458.  
  1459. let pausePromiseControlJ = 0;
  1460.  
  1461.  
  1462. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  1463.  
  1464. let controlPhase = 0;
  1465. const aElm = document.activeElement;
  1466.  
  1467. if (aElm) {
  1468.  
  1469. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  1470.  
  1471. if (typeof controlPhaseCache === 'number') {
  1472.  
  1473. controlPhase = controlPhaseCache;
  1474. } else {
  1475.  
  1476. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  1477. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  1478. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  1479. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  1480. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  1481. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  1482. else {
  1483. if (aElm instanceof HTMLElement && aElm.closest('[role]')) controlPhase = 5;
  1484. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  1485. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  1486. else if (!(aElm instanceof HTMLElement) && (aElm instanceof Element)) controlPhase = 2; // svg
  1487. }
  1488.  
  1489. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement) && aElm.contains(mediaPlayerElement)) {
  1490. controlPhase = 0;
  1491. }
  1492.  
  1493. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  1494. if (aElm.closest('[contenteditable], input, textarea')) {
  1495. controlPhase = 5;
  1496. } else if (aElm.closest('button')) {
  1497. controlPhase = 4;
  1498. }
  1499. }
  1500.  
  1501. if (aElm.closest('#movie_player')) controlPhase = 6;
  1502.  
  1503. wmKeyControlPhase.set(aElm, controlPhase);
  1504.  
  1505. }
  1506. }
  1507.  
  1508. return controlPhase;
  1509.  
  1510. }
  1511.  
  1512. const isStateControllable = (api) => {
  1513. let appState = null;
  1514. let playerState = null;
  1515. let adState = null;
  1516. try {
  1517. appState = api.getAppState();
  1518. playerState = api.getPlayerState();
  1519. adState = api.getAdState();
  1520. } catch (e) { }
  1521. // ignore playerState -1
  1522. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  1523. };
  1524.  
  1525.  
  1526. const keyEventListener = (evt) => {
  1527. if (BY_PASS_KEYBOARD_CONTROL) return;
  1528.  
  1529. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  1530. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  1531. if (!ytPageReady) return;
  1532.  
  1533. if (evt.defaultPrevented === true) return;
  1534.  
  1535. const p_a_obj = kRef(p_a_objWR);
  1536.  
  1537. if (!p_a_obj) return;
  1538.  
  1539.  
  1540. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1541. if (!mediaPlayerElement) return;
  1542.  
  1543. // let focusBodyIfSuccess = false;
  1544.  
  1545. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  1546.  
  1547. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  1548. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  1549. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  1550.  
  1551.  
  1552. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  1553.  
  1554. // console.log(`${evt.type}::controlPhase`,controlPhase)
  1555.  
  1556. // if (controlPhase == 4) {
  1557. // focusBodyIfSuccess = true;
  1558. // }
  1559.  
  1560. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  1561. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  1562.  
  1563. if (FIX_SHORTCUTKEYS < 2) return;
  1564. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  1565.  
  1566. let rr;
  1567. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  1568.  
  1569.  
  1570.  
  1571. let useImprovedPauseResume = false;
  1572.  
  1573. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  1574.  
  1575. const api = p_a_obj.api;
  1576. const stateControllable = isStateControllable(api);
  1577. // console.log(2122, appState, playerState, adState)
  1578.  
  1579. if (stateControllable && location.pathname === '/watch' && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  1580.  
  1581. useImprovedPauseResume = true;
  1582.  
  1583. }
  1584.  
  1585.  
  1586. }
  1587.  
  1588.  
  1589. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  1590. if (evt.type === 'keydown') {
  1591.  
  1592. if (useImprovedPauseResume) {
  1593.  
  1594. const isPaused = mediaPlayerElement.paused;
  1595.  
  1596. const cj = ++pausePromiseControlJ;
  1597. Promise.resolve().then(() => {
  1598.  
  1599. if (cj !== pausePromiseControlJ) return;
  1600.  
  1601. if (mediaPlayerElement.paused !== isPaused) return;
  1602.  
  1603. const ret = ytResumeFn();
  1604. if (!ret) { // fallback
  1605. isPaused ? api.playVideo() : api.pauseVideo();
  1606. }
  1607.  
  1608. /*
  1609. let a = void 0;
  1610. console.log('Rb', api.Rb())
  1611. a = !window._yt_player.nL(api.Rb());
  1612. p_a_obj.Wd.kG(a)
  1613. a ? api.playVideo() : api.pauseVideo();
  1614.  
  1615. */
  1616.  
  1617.  
  1618. });
  1619. rr = true;
  1620. } else {
  1621.  
  1622. isSpaceKeyImmediate = true;
  1623. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  1624. isSpaceKeyImmediate = false;
  1625. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  1626.  
  1627. }
  1628.  
  1629.  
  1630. } else if (evt.type === 'keyup') {
  1631.  
  1632. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  1633.  
  1634. rr = true;
  1635. } else {
  1636.  
  1637. isSpaceKeyImmediate = true;
  1638. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  1639. isSpaceKeyImmediate = false;
  1640. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  1641.  
  1642. }
  1643.  
  1644.  
  1645. /*
  1646.  
  1647. if (d)
  1648. switch (c) {
  1649. case 32:
  1650. case 13:
  1651. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  1652. b = !0,
  1653. e = !1;
  1654. else if (e) {
  1655. var m = d.getAttribute("role");
  1656. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  1657. d.click(),
  1658. f = !0)
  1659. }
  1660. break;
  1661. case 37:
  1662. case 39:
  1663. case 36:
  1664. case 35:
  1665. b = "slider" === d.getAttribute("role");
  1666. break;
  1667. case 38:
  1668. case 40:
  1669. m = d.getAttribute("role"),
  1670. d = 38 === c ? d.previousSibling : d.nextSibling,
  1671. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  1672. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  1673. f = b = !0))
  1674. }
  1675. if (e && !f)
  1676. switch (c) {
  1677. case 38:
  1678. f = Math.min(this.api.getVolume() + 5, 100);
  1679. XV(this.Wd, f, !1);
  1680. this.api.setVolume(f);
  1681. h = f = !0;
  1682. break;
  1683. case 40:
  1684. f = Math.max(this.api.getVolume() - 5, 0);
  1685. XV(this.Wd, f, !0);
  1686. this.api.setVolume(f);
  1687. h = f = !0;
  1688. break;
  1689. case 36:
  1690. this.api.Yh() && (this.api.startSeekCsiAction(),
  1691. this.api.seekTo(0, void 0, void 0, void 0, 79),
  1692. h = f = !0);
  1693. break;
  1694. case 35:
  1695. this.api.Yh() && (this.api.startSeekCsiAction(),
  1696. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  1697. h = f = !0)
  1698. }
  1699. */
  1700.  
  1701. }
  1702.  
  1703.  
  1704. if (rr) {
  1705.  
  1706. // focusBodyIfSuccess && Promise.resolve().then(() => {
  1707. // activeElement === document.activeElement && activeElement.blur();
  1708. // });
  1709.  
  1710. evt.preventDefault();
  1711. evt.stopImmediatePropagation();
  1712. evt.stopPropagation();
  1713.  
  1714. }
  1715.  
  1716. };
  1717.  
  1718. document.addEventListener('keydown', keyEventListener, { capture: true });
  1719.  
  1720.  
  1721. document.addEventListener('keyup', keyEventListener, { capture: true });
  1722.  
  1723. }
  1724.  
  1725. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  1726.  
  1727. })();
  1728.  
  1729.  
  1730. pageMediaWatcher();
  1731. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  1732.  
  1733.  
  1734. const check_for_set_key_order = (() => {
  1735.  
  1736. let mySet = new Set();
  1737.  
  1738. mySet.add("value1");
  1739. mySet.add("value2");
  1740. mySet.add("value3");
  1741.  
  1742. // Function to convert Set values to an array
  1743. function getSetValues(set) {
  1744. return Array.from(set.values());
  1745. }
  1746.  
  1747. // Function to test if the Set maintains insertion order
  1748. function testSetOrder(set, expectedOrder) {
  1749. let values = getSetValues(set);
  1750. return expectedOrder.join(',') === values.join(',');
  1751. }
  1752.  
  1753. // Test 1: Initial order
  1754. if (mySet.values().next().value !== "value1") return false;
  1755. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  1756.  
  1757. // Test 2: After deleting an element
  1758. mySet.delete("value2");
  1759. if (mySet.values().next().value !== "value1") return false;
  1760. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  1761.  
  1762. // Test 3: After re-adding a deleted element
  1763. mySet.add("value2");
  1764. if (mySet.values().next().value !== "value1") return false;
  1765. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  1766.  
  1767. // Test 4: After adding a new element
  1768. mySet.add("value4");
  1769. if (mySet.values().next().value !== "value1") return false;
  1770. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  1771.  
  1772. // Test 5: Delete+Add
  1773. mySet.delete("value1");
  1774. mySet.delete("value3");
  1775. mySet.add("value3");
  1776. mySet.add("value1");
  1777. if (mySet.values().next().value !== "value2") return false;
  1778. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  1779.  
  1780. return true;
  1781. })();
  1782.  
  1783.  
  1784. // const qm47 = Symbol();
  1785. const qm57 = Symbol();
  1786. const qm53 = Symbol();
  1787. const qn53 = Symbol();
  1788.  
  1789.  
  1790. const ump3 = new WeakMap();
  1791.  
  1792. const stp = document.createElement('noscript');
  1793. stp.id = 'weakref-placeholder'
  1794.  
  1795.  
  1796. const setupD = typeof WeakRef !== 'undefined' ? (elm, s, usePlaceholder) => {
  1797.  
  1798. const z = `${s}72`;
  1799.  
  1800. if (s in elm) {
  1801.  
  1802. const p = elm[s];
  1803.  
  1804. delete elm[s];
  1805.  
  1806. Object.defineProperty(elm, s, {
  1807. get() {
  1808. const elm = this;
  1809. const wr = elm[z];
  1810. if (!wr) return null;
  1811. const m = kRef(wr);
  1812. if (!m && usePlaceholder) {
  1813. if (typeof usePlaceholder === 'function') usePlaceholder(elm);
  1814. return stp;
  1815. }
  1816. return m;
  1817. },
  1818. set(nv) {
  1819. const elm = this;
  1820. elm[z] = nv ? mWeakRef(nv) : null;
  1821. return true;
  1822. },
  1823. configurable: true,
  1824. enumerable: true
  1825.  
  1826. });
  1827.  
  1828. elm[s] = p;
  1829. elm = null;
  1830.  
  1831.  
  1832. }
  1833. } : null;
  1834.  
  1835. const mxMap = new WeakMap();
  1836.  
  1837. const myMap = new WeakSet();
  1838.  
  1839. const setup$ = typeof WeakRef !== 'undefined' ? function (dh) {
  1840.  
  1841. const $ = dh.$;
  1842.  
  1843. if (WEAK_REF_PROXY_DOLLAR && $ && typeof $ === 'object' && !dh.$ky37) {
  1844.  
  1845. dh.$ky37 = 1;
  1846.  
  1847. if (!myMap.has($)) {
  1848.  
  1849. for (const [k, v] of Object.entries($)) {
  1850. if (v instanceof Node) {
  1851. $[k] = mWeakRef(v);
  1852. }
  1853. }
  1854.  
  1855. dh.$ = mxMap.get($) || new Proxy($, {
  1856. get(obj, prop) {
  1857. const val = obj[prop];
  1858. if (typeof (val || 0).deref === 'function') {
  1859. return val.deref();
  1860. }
  1861. return val;
  1862. },
  1863. set(obj, prop, val) {
  1864. if (val instanceof Node) {
  1865. obj[prop] = mWeakRef(val);
  1866. } else {
  1867. obj[prop] = val;
  1868. }
  1869. return true;
  1870. }
  1871. });
  1872.  
  1873. mxMap.set($, dh.$);
  1874. myMap.add(dh.$);
  1875.  
  1876. }
  1877.  
  1878. }
  1879.  
  1880. } : null;
  1881.  
  1882.  
  1883. const configureVisibilityObserverT_ = function () {
  1884. const hostElement = this.hostElement;
  1885. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  1886. this.unobserve_();
  1887. } else {
  1888. return this.configureVisibilityObserver27_();
  1889. }
  1890. };
  1891. const getParentRendererT = function () {
  1892. const hostElement = this.hostElement;
  1893. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  1894. return null;
  1895. } else {
  1896. return this.getParentRenderer27();
  1897. }
  1898. }
  1899.  
  1900. const attachedT = function () {
  1901. const hostElement = this.hostElement;
  1902. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  1903. if (this.isAttached === true) this.isAttached = false;
  1904. return void 0;
  1905. } else {
  1906. return this.attached27();
  1907. }
  1908. }
  1909.  
  1910. const hostElementCleanUp = (dh) => {
  1911. if (typeof dh.dispose === 'function') {
  1912. try {
  1913. if (dh.visibilityMonitor || dh.visibilityObserver) {
  1914. dh.dispose();
  1915. dh.visibilityMonitor = null;
  1916. dh.visibilityObserver = null;
  1917. }
  1918. } catch (e) { }
  1919. }
  1920. if (typeof dh.detached === 'function') {
  1921. try {
  1922. if (dh.visibilityObserverForChild_ || dh.localVisibilityObserver_) {
  1923. dh.detached();
  1924. dh.visibilityObserverForChild_ = null;
  1925. dh.localVisibilityObserver_ = null;
  1926. }
  1927. } catch (e) { }
  1928. }
  1929. };
  1930. const setupDataHost = setupD && setup$ ? function (dh, opt) {
  1931.  
  1932. if (dh && typeof dh === 'object') {
  1933.  
  1934. if (typeof dh.configureVisibilityObserver_ === 'function' && !dh.configureVisibilityObserver27_) {
  1935. dh.configureVisibilityObserver27_ = dh.configureVisibilityObserver_;
  1936. dh.configureVisibilityObserver_ = configureVisibilityObserverT_;
  1937. }
  1938.  
  1939. if (typeof dh.getParentRenderer === 'function' && !dh.getParentRenderer27) {
  1940. dh.getParentRenderer27 = dh.getParentRenderer;
  1941. dh.getParentRenderer = getParentRendererT;
  1942. }
  1943.  
  1944. if (typeof dh.attached === 'function' && !dh.attached27) {
  1945. dh.attached27 = dh.attached;
  1946. dh.attached = attachedT;
  1947. }
  1948.  
  1949. setupD(dh, 'hostElement', hostElementCleanUp);
  1950. setupD(dh, 'parentComponent');
  1951. setupD(dh, 'localVisibilityObserver_');
  1952. setupD(dh, 'cachedProviderNode_');
  1953.  
  1954.  
  1955. setupD(dh, '__template');
  1956. setupD(dh, '__templatizeOwner');
  1957. setupD(dh, '__templateInfo');
  1958.  
  1959. // setupD(dh, 'root', 1);
  1960.  
  1961. const elements_ = dh.elements_;
  1962. if (elements_ && typeof elements_ === 'object' && Object.keys(elements_).length > 0) setupD(dh, 'elements_');
  1963.  
  1964. setup$(dh);
  1965. }
  1966.  
  1967.  
  1968.  
  1969.  
  1970. } : null;
  1971.  
  1972.  
  1973. let delay300 = null;
  1974.  
  1975. if (UNLOAD_DETACHED_POLYMER || WEAK_REF_BINDING) {
  1976. delay300 = new PromiseExternal();
  1977. setInterval(() => {
  1978. delay300.resolve();
  1979. delay300 = new PromiseExternal();
  1980. }, 300);
  1981. }
  1982.  
  1983. const aDelay = async function () {
  1984. await delay300.then();
  1985. await delay300.then();
  1986. }
  1987.  
  1988. const convertionFuncMap = new WeakMap();
  1989. let val_kevlar_should_maintain_stable_list = null;
  1990.  
  1991. const createStampDomArrayFn_ = (fn) => {
  1992. if (val_kevlar_should_maintain_stable_list === null) {
  1993. const config_ = ((window.yt || 0).config_ || 0);
  1994. val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true
  1995. }
  1996. const gn = function (a, b, c, d, e, h) {
  1997. const isNonEmptyArray = (a || 0).length >= 1
  1998. if (!isNonEmptyArray) {
  1999. return fn.call(this, undefined, b, undefined, d);
  2000. } else if (h === undefined && typeof b === 'string' && c && typeof c === 'object' && this.is && val_kevlar_should_maintain_stable_list) {
  2001. if (c.clientSideToggleMenuItemRenderer) {
  2002. h = false;
  2003. } else {
  2004. h = true;
  2005. }
  2006. }
  2007. return fn.call(this, a, b, c, d, e, h)
  2008. }
  2009. gn.originalFn = fn;
  2010. convertionFuncMap.set(fn, gn);
  2011. return gn;
  2012. }
  2013.  
  2014. const fixStampDomArrayStableList = (h) => {
  2015. if (!h.stampDomArray_) return;
  2016. const proto = h.__proto__;
  2017. const f = proto.stampDomArray_;
  2018. if (!proto.stampDomArrayF001_ && typeof f === 'function' && f.length === 6) {
  2019. proto.stampDomArrayF001_ = 1;
  2020. proto.stampDomArray_ = convertionFuncMap.get(f) || createStampDomArrayFn_(f);
  2021. }
  2022. }
  2023.  
  2024. const weakenStampReferences = (() => {
  2025.  
  2026. const DEBUG_STAMP = false;
  2027.  
  2028. const s1 = Symbol();
  2029. const handler1 = {
  2030. get(target, prop, receiver) {
  2031. if (prop === 'object') {
  2032. return kRef(target[s1]); // avoid memory leakage
  2033. }
  2034. if (prop === '__proxy312__') return 1;
  2035. return target[prop];
  2036. }
  2037. };
  2038. const handler2 = {
  2039. get(target, prop, receiver) {
  2040. if (prop === 'indexSplices') {
  2041. return kRef(target[s1]); // avoid memory leakage
  2042. }
  2043. if (prop === '__proxy312__') return 1;
  2044. return target[prop];
  2045. }
  2046. }
  2047. return (h) => {
  2048.  
  2049. if (h.rendererStamperApplyChangeRecord_ || h.stampDomArraySplices_) {
  2050. const proto = h.__proto__;
  2051. if (!proto.yzxer && (proto.rendererStamperApplyChangeRecord_ || proto.stampDomArraySplices_)) {
  2052. proto.yzxer = 1;
  2053.  
  2054. const list = [
  2055. // "rendererStamperObserver_", // 3 ==> rendererStamperApplyChangeRecord_
  2056. "rendererStamperApplyChangeRecord_", // 3
  2057. "forwardRendererStamperChanges_", // 3
  2058. "stampDomArraySplices_", // 3
  2059. "stampDomArray_", // 6
  2060. "deferRenderStamperBinding_", // 3
  2061. ];
  2062. for (const key of list) {
  2063. const pey = `${key}$wq0iw_`;
  2064. const vKey = proto[key];
  2065. if (typeof vKey !== 'function') continue;
  2066. if (proto[pey] || vKey.length === 0) continue;
  2067.  
  2068. if (key === 'stampDomArraySplices_' && vKey.length === 3) {
  2069. proto[pey] = vKey;
  2070. proto[key] = function (a, b, c) {
  2071.  
  2072. if (typeof a === 'string' && typeof b === 'string' && typeof c === 'object' && c && c.indexSplices && c.indexSplices.length >= 1 && !c.indexSplices.rzgjr) {
  2073.  
  2074. c.indexSplices = c.indexSplices.map(e => {
  2075. if (e.__proxy312__) return e;
  2076. e[s1] = mWeakRef(e.object);
  2077. e.object = null;
  2078. return new Proxy(e, handler1);
  2079. });
  2080. c.indexSplices.rzgjr = 1;
  2081.  
  2082. c[s1] = mWeakRef(c.indexSplices);
  2083. c.indexSplices = null;
  2084. c = new Proxy(c, handler2)
  2085. arguments[2] = c;
  2086.  
  2087. }
  2088. // console.log(key, arguments.length, [...arguments]);
  2089. return proto[pey].call(this, a, b, c);
  2090. }
  2091.  
  2092. } else if (key === 'rendererStamperApplyChangeRecord_' && vKey.length === 3) {
  2093.  
  2094. // Nil
  2095.  
  2096. } else if (DEBUG_STAMP) {
  2097.  
  2098. console.log(proto.isRenderer_, 'ms_' + key, vKey.length, h.is)
  2099. proto[pey] = vKey;
  2100. proto[key] = function () {
  2101. if (key === 'rendererStamperApplyChangeRecord_' && typeof arguments[3] === 'object') {
  2102. console.log(key, arguments.length, { value: arguments[3].value, base: arguments[3].base, })
  2103. }
  2104. console.log(key, arguments.length, [...arguments]);
  2105. return proto[pey].apply(this, arguments);
  2106. }
  2107.  
  2108. }
  2109.  
  2110. }
  2111.  
  2112.  
  2113. // const m = (Object.mkss = Object.mkss || new Set());
  2114. // Object.keys(h.__proto__).filter(e => e.toLowerCase().includes('stamp') && typeof h[e] === 'function').forEach(e => m.add(e))
  2115. // console.log([...m])
  2116. }
  2117. }
  2118.  
  2119. }
  2120. })();
  2121.  
  2122. const setupDiscreteTasks = (h, rb) => {
  2123.  
  2124. if (rb) {
  2125. if (h.ky36) return;
  2126. }
  2127.  
  2128.  
  2129. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  2130. const f = h.onYtRendererstamperFinished;
  2131. const g = ump3.get(f) || function () {
  2132. if (this.updateChildVisibilityProperties && !this.markDirty) {
  2133. return f.apply(this, arguments);
  2134. }
  2135. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2136. }
  2137. ump3.set(f, g);
  2138. g.km34 = 1;
  2139. h.onYtRendererstamperFinished = g;
  2140.  
  2141. }
  2142.  
  2143. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  2144. const f = h.onYtUpdateDescriptionAction;
  2145. const g = ump3.get(f) || function (a) {
  2146. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2147. }
  2148. ump3.set(f, g);
  2149. g.km34 = 1;
  2150. h.onYtUpdateDescriptionAction = g;
  2151.  
  2152. }
  2153.  
  2154. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  2155. const f = h.handleUpdateDescriptionAction;
  2156. const g = ump3.get(f) || function (a) {
  2157. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2158. }
  2159. ump3.set(f, g);
  2160. g.km34 = 1;
  2161. h.handleUpdateDescriptionAction = g;
  2162.  
  2163. }
  2164.  
  2165. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  2166. const f = h.handleUpdateLiveChatPollAction;
  2167. const g = ump3.get(f) || function (a) {
  2168. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2169. }
  2170. ump3.set(f, g);
  2171. g.km34 = 1;
  2172. h.handleUpdateLiveChatPollAction = g;
  2173.  
  2174. }
  2175.  
  2176. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  2177. const f = h.onTextChanged;
  2178. const g = ump3.get(f) || function () {
  2179. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2180. }
  2181. ump3.set(f, g);
  2182. g.km34 = 1;
  2183. h.onTextChanged = g;
  2184.  
  2185. }
  2186.  
  2187. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  2188. const f = h.onVideoDataChange;
  2189. const g = ump3.get(f) || function (a) {
  2190. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2191. }
  2192. ump3.set(f, g);
  2193. g.km34 = 1;
  2194. h.onVideoDataChange = g;
  2195.  
  2196. }
  2197.  
  2198. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  2199. const f = h.onVideoDataChange_;
  2200. const g = ump3.get(f) || function () {
  2201. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2202. }
  2203. ump3.set(f, g);
  2204. g.km34 = 1;
  2205. h.onVideoDataChange_ = g;
  2206.  
  2207. }
  2208.  
  2209. if (typeof h.addTooltips === 'function' && !(h.addTooltips.km34)) {
  2210.  
  2211. const f = h.addTooltips;
  2212. const g = ump3.get(f) || function () {
  2213. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2214. }
  2215. ump3.set(f, g);
  2216. g.km34 = 1;
  2217. h.addTooltips = g;
  2218.  
  2219. }
  2220.  
  2221. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  2222.  
  2223. const f = h.addTooltips_;
  2224. const g = ump3.get(f) || function () {
  2225. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2226. }
  2227. ump3.set(f, g);
  2228. g.km34 = 1;
  2229. h.addTooltips_ = g;
  2230.  
  2231. }
  2232.  
  2233. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  2234.  
  2235. const f = h.updateRenderedElements;
  2236. const g = ump3.get(f) || function () {
  2237. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2238. }
  2239. ump3.set(f, g);
  2240. g.km34 = 1;
  2241. h.updateRenderedElements = g;
  2242.  
  2243. }
  2244.  
  2245. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  2246. const f = h.loadPage_;
  2247. const g = ump3.get(f) || function (a) {
  2248. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2249. }
  2250. ump3.set(f, g);
  2251. g.km34 = 1;
  2252. h.loadPage_ = g;
  2253.  
  2254. }
  2255. // updatePageData_ : possible conflict with Omit ShadyDOM
  2256. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  2257. const f = h.updatePageData_;
  2258. const g = ump3.get(f) || function (a) {
  2259. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2260. }
  2261. ump3.set(f, g);
  2262. g.km34 = 1;
  2263. h.updatePageData_ = g;
  2264.  
  2265. }
  2266.  
  2267.  
  2268. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  2269.  
  2270. const f = h.onFocus_;
  2271. const g = ump3.get(f) || function () {
  2272. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2273. }
  2274. ump3.set(f, g);
  2275. g.km34 = 1;
  2276. h.onFocus_ = g;
  2277.  
  2278. }
  2279.  
  2280. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  2281.  
  2282. const f = h.onBlur_;
  2283. const g = ump3.get(f) || function () {
  2284. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2285. }
  2286. ump3.set(f, g);
  2287. g.km34 = 1;
  2288. h.onBlur_ = g;
  2289.  
  2290. }
  2291.  
  2292.  
  2293. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  2294.  
  2295. const f = h.buttonClassChanged_;
  2296. const g = ump3.get(f) || function (a, b) {
  2297. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2298. }
  2299. ump3.set(f, g);
  2300. g.km34 = 1;
  2301. h.buttonClassChanged_ = g;
  2302.  
  2303. }
  2304.  
  2305. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  2306.  
  2307. const f = h.buttonIconChanged_;
  2308. const g = ump3.get(f) || function (a) {
  2309. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2310. }
  2311. ump3.set(f, g);
  2312. g.km34 = 1;
  2313. h.buttonIconChanged_ = g;
  2314.  
  2315. }
  2316.  
  2317. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  2318.  
  2319. const f = h.dataChangedInBehavior_;
  2320. const g = ump3.get(f) || function () {
  2321. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2322. }
  2323. ump3.set(f, g);
  2324. g.km34 = 1;
  2325. h.dataChangedInBehavior_ = g;
  2326.  
  2327. }
  2328.  
  2329. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  2330.  
  2331. const f = h.continuationsChanged_;
  2332. const g = ump3.get(f) || function () {
  2333. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2334. }
  2335. ump3.set(f, g);
  2336. g.km34 = 1;
  2337. h.continuationsChanged_ = g;
  2338.  
  2339. }
  2340.  
  2341.  
  2342. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  2343.  
  2344. const f = h.forceChatPoll_;
  2345. const g = ump3.get(f) || function (a) {
  2346. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2347. }
  2348. ump3.set(f, g);
  2349. g.km34 = 1;
  2350. h.forceChatPoll_ = g;
  2351.  
  2352. }
  2353.  
  2354. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  2355.  
  2356. const f = h.onEndpointClick_;
  2357. const g = ump3.get(f) || function (a) {
  2358. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2359. }
  2360. ump3.set(f, g);
  2361. g.km34 = 1;
  2362. h.onEndpointClick_ = g;
  2363.  
  2364. }
  2365.  
  2366. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  2367.  
  2368. const f = h.onEndpointTap_;
  2369. const g = ump3.get(f) || function (a) {
  2370. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2371. }
  2372. ump3.set(f, g);
  2373. g.km34 = 1;
  2374. h.onEndpointTap_ = g;
  2375.  
  2376. }
  2377.  
  2378. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  2379.  
  2380. const f = h.handleClick_;
  2381. const g = ump3.get(f) || function (a, b) {
  2382. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2383. }
  2384. ump3.set(f, g);
  2385. g.km34 = 1;
  2386. h.handleClick_ = g;
  2387.  
  2388. }
  2389.  
  2390. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  2391.  
  2392. const f = h.onReadyStateChange_;
  2393. const g = ump3.get(f) || function () {
  2394. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2395. }
  2396. ump3.set(f, g);
  2397. g.km34 = 1;
  2398. h.onReadyStateChange_ = g;
  2399.  
  2400. }
  2401.  
  2402. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  2403.  
  2404. const f = h.onReadyStateChangeEntryPoint_;
  2405. const g = ump3.get(f) || function () {
  2406. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2407. }
  2408. ump3.set(f, g);
  2409. g.km34 = 1;
  2410. h.onReadyStateChangeEntryPoint_ = g;
  2411.  
  2412. }
  2413.  
  2414. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  2415.  
  2416. const f = h.readyStateChangeHandler_;
  2417. const g = ump3.get(f) || function (a) {
  2418. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2419. }
  2420. ump3.set(f, g);
  2421. g.km34 = 1;
  2422. h.readyStateChangeHandler_ = g;
  2423.  
  2424. }
  2425.  
  2426. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  2427.  
  2428. const f = h.xmlHttpHandler_;
  2429. const g = ump3.get(f) || function (a) {
  2430. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2431. }
  2432. ump3.set(f, g);
  2433. g.km34 = 1;
  2434. h.xmlHttpHandler_ = g;
  2435.  
  2436. }
  2437.  
  2438. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  2439.  
  2440. const f = h.executeCallbacks_; // overloaded
  2441. const g = ump3.get(f) || function (a) {
  2442. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2443. }
  2444. ump3.set(f, g);
  2445. g.km34 = 1;
  2446. h.executeCallbacks_ = g;
  2447.  
  2448. }
  2449.  
  2450. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  2451.  
  2452. const f = h.handleInvalidationData_;
  2453. const g = ump3.get(f) || function (a, b) {
  2454. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2455. }
  2456. ump3.set(f, g);
  2457. g.km34 = 1;
  2458. h.handleInvalidationData_ = g;
  2459.  
  2460. }
  2461.  
  2462. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  2463.  
  2464. const f = h.onInput_;
  2465. const g = ump3.get(f) || function () {
  2466. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2467. }
  2468. ump3.set(f, g);
  2469. g.km34 = 1;
  2470. h.onInput_ = g;
  2471.  
  2472. }
  2473. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  2474.  
  2475. const f = h.trigger_;
  2476. const g = ump3.get(f) || function (a) {
  2477. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2478. }
  2479. ump3.set(f, g);
  2480. g.km34 = 1;
  2481. h.trigger_ = g;
  2482.  
  2483. }
  2484.  
  2485. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  2486.  
  2487. const f = h.requestData_;
  2488. const g = ump3.get(f) || function (a) {
  2489. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2490. }
  2491. ump3.set(f, g);
  2492. g.km34 = 1;
  2493. h.requestData_ = g;
  2494.  
  2495. }
  2496.  
  2497. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  2498.  
  2499. const f = h.onLoadReloadContinuation_;
  2500. const g = ump3.get(f) || function (a, b) {
  2501. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2502. }
  2503. ump3.set(f, g);
  2504. g.km34 = 1;
  2505. h.onLoadReloadContinuation_ = g;
  2506.  
  2507. }
  2508.  
  2509. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  2510.  
  2511. const f = h.onLoadIncrementalContinuation_;
  2512. const g = ump3.get(f) || function (a, b) {
  2513. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2514. }
  2515. ump3.set(f, g);
  2516. g.km34 = 1;
  2517. h.onLoadIncrementalContinuation_ = g;
  2518.  
  2519. }
  2520.  
  2521. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  2522.  
  2523. const f = h.onLoadSeekContinuation_;
  2524. const g = ump3.get(f) || function (a, b) {
  2525. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2526. }
  2527. ump3.set(f, g);
  2528. g.km34 = 1;
  2529. h.onLoadSeekContinuation_ = g;
  2530.  
  2531. }
  2532. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  2533.  
  2534. const f = h.onLoadReplayContinuation_;
  2535. const g = ump3.get(f) || function (a, b) {
  2536. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2537. }
  2538. ump3.set(f, g);
  2539. g.km34 = 1;
  2540. h.onLoadReplayContinuation_ = g;
  2541.  
  2542. }
  2543. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  2544.  
  2545. const f = h.onNavigate_;
  2546. const g = ump3.get(f) || function (a) {
  2547. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2548. }
  2549. ump3.set(f, g);
  2550. g.km34 = 1;
  2551. h.onNavigate_ = g;
  2552.  
  2553. }
  2554.  
  2555. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  2556.  
  2557. const f = h.ytRendererBehaviorDataObserver_;
  2558. const g = ump3.get(f) || function () {
  2559. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2560. }
  2561. ump3.set(f, g);
  2562. g.km34 = 1;
  2563. h.ytRendererBehaviorDataObserver_ = g;
  2564.  
  2565. }
  2566.  
  2567. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  2568.  
  2569. const f = h.ytRendererBehaviorTargetIdObserver_;
  2570. const g = ump3.get(f) || function () {
  2571. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2572. }
  2573. ump3.set(f, g);
  2574. g.km34 = 1;
  2575. h.ytRendererBehaviorTargetIdObserver_ = g;
  2576.  
  2577. }
  2578.  
  2579. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  2580.  
  2581. const f = h.unregisterRenderer_;
  2582. const g = ump3.get(f) || function (a) {
  2583. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2584. }
  2585. ump3.set(f, g);
  2586. g.km34 = 1;
  2587. h.unregisterRenderer_ = g;
  2588.  
  2589. }
  2590.  
  2591. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  2592.  
  2593. const f = h.textChanged_;
  2594. const g = ump3.get(f) || function (a) {
  2595. if (void 0 !== this.isAttached) {
  2596. const hostElement = this.hostElement;
  2597. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  2598. return;
  2599. }
  2600. }
  2601. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2602. }
  2603. ump3.set(f, g);
  2604. g.km34 = 1;
  2605. h.textChanged_ = g;
  2606.  
  2607. }
  2608.  
  2609.  
  2610.  
  2611. /**
  2612. *
  2613. * Neglect following
  2614. *
  2615. * h.onYtAction_
  2616. * h.startLoadingWatch [ buggy for yt-player-updated ]
  2617. * h.deferRenderStamperBinding_
  2618. *
  2619. * h.stampDomArray_
  2620. * h.stampDomArraySplices_
  2621. *
  2622. */
  2623.  
  2624.  
  2625. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  2626. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  2627. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  2628. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  2629. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  2630. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  2631.  
  2632. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  2633.  
  2634. const f = h.searchChanged_;
  2635. const g = ump3.get(f) || function () {
  2636. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2637. }
  2638. ump3.set(f, g);
  2639. g.km34 = 1;
  2640. h.searchChanged_ = g;
  2641.  
  2642. }
  2643.  
  2644. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  2645.  
  2646. const f = h.skinToneChanged_;
  2647. const g = ump3.get(f) || function (a) {
  2648. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2649. }
  2650. ump3.set(f, g);
  2651. g.km34 = 1;
  2652. h.skinToneChanged_ = g;
  2653.  
  2654. }
  2655.  
  2656. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  2657.  
  2658. const f = h.onEmojiHover_;
  2659. const g = ump3.get(f) || function (a) {
  2660. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2661. }
  2662. ump3.set(f, g);
  2663. g.km34 = 1;
  2664. h.onEmojiHover_ = g;
  2665.  
  2666. }
  2667.  
  2668. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  2669.  
  2670. const f = h.onSelectCategory_;
  2671. const g = ump3.get(f) || function (a) {
  2672. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2673. }
  2674. ump3.set(f, g);
  2675. g.km34 = 1;
  2676. h.onSelectCategory_ = g;
  2677.  
  2678. }
  2679.  
  2680. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  2681.  
  2682. const f = h.onShowEmojiVariantSelector;
  2683. const g = ump3.get(f) || function (a) {
  2684. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2685. }
  2686. ump3.set(f, g);
  2687. g.km34 = 1;
  2688. h.onShowEmojiVariantSelector = g;
  2689.  
  2690. }
  2691.  
  2692. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  2693.  
  2694. const f = h.updateCategoriesAndPlaceholder_;
  2695. const g = ump3.get(f) || function () {
  2696. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2697. }
  2698. ump3.set(f, g);
  2699. g.km34 = 1;
  2700. h.updateCategoriesAndPlaceholder_ = g;
  2701.  
  2702. }
  2703.  
  2704. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  2705.  
  2706. const f = h.watchPageActiveChanged_;
  2707. const g = ump3.get(f) || function () {
  2708. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2709. }
  2710. ump3.set(f, g);
  2711. g.km34 = 1;
  2712. h.watchPageActiveChanged_ = g;
  2713.  
  2714. }
  2715.  
  2716. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  2717.  
  2718. const f = h.activate_;
  2719. const g = ump3.get(f) || function () {
  2720. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2721. }
  2722. ump3.set(f, g);
  2723. g.km34 = 1;
  2724. h.activate_ = g;
  2725.  
  2726. }
  2727. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  2728.  
  2729. const f = h.onYtPlaylistDataUpdated_;
  2730. const g = ump3.get(f) || function () {
  2731. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2732. }
  2733. ump3.set(f, g);
  2734. g.km34 = 1;
  2735. h.onYtPlaylistDataUpdated_ = g;
  2736.  
  2737. }
  2738.  
  2739. FIX_stampDomArray_stableList && fixStampDomArrayStableList(h);
  2740. const ENABLE_weakenStampReferencesQ = ENABLE_weakenStampReferences && typeof DocumentTimeline !== 'undefined' && typeof WeakRef !== 'undefined';
  2741. ENABLE_weakenStampReferencesQ && weakenStampReferences(h);
  2742.  
  2743.  
  2744. /**
  2745. *
  2746. * Neglect following
  2747. *
  2748. * h.rendererStamperObserver_
  2749. * h.rendererStamperApplyChangeRecord_
  2750. * h.flushRenderStamperComponentBindings_
  2751. * h.forwardRendererStamperChanges_
  2752. *
  2753. */
  2754.  
  2755. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  2756.  
  2757. const f = h.tryRenderChunk_;
  2758. const g = ump3.get(f) || function () {
  2759. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2760. }
  2761. ump3.set(f, g);
  2762. g.km34 = 1;
  2763. h.tryRenderChunk_ = g;
  2764.  
  2765. }
  2766.  
  2767.  
  2768. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  2769.  
  2770. const f = h.renderChunk_;
  2771. const g = ump3.get(f) || function () {
  2772. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2773. }
  2774. ump3.set(f, g);
  2775. g.km34 = 1;
  2776. h.renderChunk_ = g;
  2777.  
  2778. }
  2779.  
  2780. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  2781.  
  2782. const f = h.deepLazyListObserver_;
  2783. const g = ump3.get(f) || function () {
  2784. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2785. }
  2786. ump3.set(f, g);
  2787. g.km34 = 1;
  2788. h.deepLazyListObserver_ = g;
  2789.  
  2790. }
  2791.  
  2792. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  2793.  
  2794. const f = h.onItemsUpdated_;
  2795. const g = ump3.get(f) || function () {
  2796. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2797. }
  2798. ump3.set(f, g);
  2799. g.km34 = 1;
  2800. h.onItemsUpdated_ = g;
  2801.  
  2802. }
  2803.  
  2804. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  2805.  
  2806. const f = h.requestRenderChunk_;
  2807. const g = ump3.get(f) || function () {
  2808. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2809. }
  2810. ump3.set(f, g);
  2811. g.km34 = 1;
  2812. h.requestRenderChunk_ = g;
  2813.  
  2814. }
  2815.  
  2816. /**
  2817. *
  2818. * Neglect following
  2819. *
  2820. * h.dataChanged_ [ buggy for page swtiching ]
  2821. *
  2822. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  2823. *
  2824. * h.cancelPendingTasks_
  2825. * h.fillRange_
  2826. * h.addTextNodes_
  2827. * h.updateText_
  2828. * h.stampTypeChanged_
  2829. *
  2830. */
  2831.  
  2832.  
  2833. }
  2834.  
  2835. const keyStConnectedCallback = Symbol(); // avoid copying the value
  2836.  
  2837. // const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  2838. const cmf = new WeakMap();
  2839. const dmf = new WeakMap();
  2840.  
  2841. const gvGenerator = (nv) => {
  2842. return function () {
  2843. const cnt = insp(this);
  2844. const hostElement = cnt.hostElement || 0;
  2845. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  2846. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  2847. if (p && (!dollar && !this.is)) {
  2848. const nodeName = hostElement.nodeName;
  2849. if (typeof nodeName !== 'string') {
  2850. // just in case
  2851. } else if (nodeName.startsWith("DOM-")) {
  2852. // dom-if, dom-repeat, etc
  2853. } else {
  2854. // yt element - new model, yt-xxxx, anixxxxxx
  2855. p = false;
  2856. }
  2857. }
  2858. if (p) {
  2859. if (typeof cnt.markDirty === 'function') {
  2860. // the yt element might call markDirty (occasionally)
  2861. p = false;
  2862. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  2863. // see https://github.com/cyfung1031/userscript-supports/issues/20
  2864. p = false;
  2865. }
  2866. }
  2867. if (p) {
  2868.  
  2869. // << dom-repeat & dom-if >>
  2870.  
  2871. // sequence on the same instance
  2872. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  2873. } else {
  2874. nv.apply(this, arguments);
  2875. }
  2876. };
  2877. }
  2878.  
  2879. const setupWeakRef = (h) => {
  2880.  
  2881.  
  2882. if (WEAK_REF_BINDING && !h.kz62 && setup$ && setupD && setupDataHost && (h.is || h.__dataHost)) {
  2883.  
  2884. let skip = false;
  2885. // if (h.is && typeof h.is === 'string' && h.is.length > 15 && h.is.length < 30) {
  2886. // if (h.is.includes('yt-') && !h.$ && h.is.length !== 20 && h.is.length !== 21 && h.is.length !== 22) {
  2887. // skip = true;
  2888. // // return;
  2889. // }
  2890. // }
  2891.  
  2892. h.kz62 = 1;
  2893.  
  2894. //
  2895.  
  2896. setup$(h);
  2897. const hostElement = h.hostElement;
  2898.  
  2899. if (hostElement !== h) {
  2900.  
  2901. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  2902. setupD(h, s);
  2903. }
  2904.  
  2905. const dh = h.__dataHost;
  2906. setupDataHost(dh, skip);
  2907. }
  2908.  
  2909. if (hostElement) {
  2910.  
  2911. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  2912. setupD(hostElement, s);
  2913. }
  2914.  
  2915. const dh = hostElement.__dataHost;
  2916. setupDataHost(dh, skip);
  2917.  
  2918. aDelay().then(() => {
  2919. setupD(hostElement, '__CE_shadowRoot');
  2920. });
  2921.  
  2922. }
  2923.  
  2924. }
  2925.  
  2926. }
  2927.  
  2928.  
  2929. let nativeHTMLElement = window.HTMLElement;
  2930.  
  2931. try {
  2932.  
  2933. const q = document.createElement('template');
  2934. q.innerHTML = '<ytz-null361></ytz-null361>';
  2935. nativeHTMLElement = q.content.firstChild.constructor
  2936.  
  2937. } catch (e) { }
  2938.  
  2939. if (!nativeHTMLElement.prototype.connectedCallback) {
  2940. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  2941. nativeHTMLElement.prototype.connectedCallback = function () {
  2942. let r;
  2943. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  2944.  
  2945. if (WEAK_REF_BINDING && (this instanceof Node) && (this.is || this.__dataHost)) {
  2946. setupWeakRef(this)
  2947. // setupWeakRef(this.__dataHost)
  2948. }
  2949. return r;
  2950. }
  2951. }
  2952.  
  2953. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  2954. get() {
  2955. const f = this[keyStConnectedCallback];
  2956. if (this.is) {
  2957. setupDiscreteTasks(this, true);
  2958. if (f) this.ky36 = 1;
  2959. }
  2960. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  2961. setupWeakRef(this)
  2962. }
  2963. return f;
  2964. },
  2965. set(nv) {
  2966. let gv;
  2967. if (typeof nv === 'function') {
  2968.  
  2969. gv = cmf.get(nv) || gvGenerator(nv);
  2970. if (gv !== nv) {
  2971. cmf.set(nv, gv);
  2972. cmf.set(gv, gv);
  2973. dmf.set(gv, nv);
  2974. }
  2975.  
  2976. } else {
  2977. gv = nv;
  2978. }
  2979. this[keyStConnectedCallback] = gv; // proto or object
  2980. if (this.is) {
  2981. setupDiscreteTasks(this);
  2982. }
  2983. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  2984. setupWeakRef(this)
  2985. }
  2986. return true;
  2987. },
  2988. enumerable: false,
  2989. configurable: true
  2990.  
  2991. });
  2992.  
  2993. const pLoad = new Promise(resolve => {
  2994. if (document.readyState !== 'loading') {
  2995. resolve();
  2996. } else {
  2997. window.addEventListener("DOMContentLoaded", resolve, false);
  2998. }
  2999. });
  3000. pLoad.then(() => {
  3001.  
  3002. let nonce = document.querySelector('style[nonce]');
  3003. nonce = nonce ? nonce.getAttribute('nonce') : null;
  3004. const st = document.createElement('style');
  3005. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  3006. st.textContent = "none-element-k47{order:0}";
  3007. st.addEventListener('load', () => {
  3008. pf31.resolve();
  3009. p59 = 1;
  3010. }, false);
  3011. (document.body || document.head || document.documentElement).appendChild(st);
  3012.  
  3013. });
  3014.  
  3015. const prepareLogs = [];
  3016.  
  3017. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  3018.  
  3019. let winError00 = window.onerror;
  3020.  
  3021. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  3022.  
  3023. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  3024.  
  3025. ; FIX_Iframe_NULL_SRC && (() => {
  3026.  
  3027. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  3028. const lcOpt = { sensitivity: 'base' };
  3029. document.createElement24 = document.createElement;
  3030. document.createElement = function (t) {
  3031. if (typeof t === 'string' && t.length === 6) {
  3032. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  3033. const p = this.createElement24(t);
  3034. try {
  3035. const stack = new Error().stack;
  3036. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  3037. if (!isSearchbox) {
  3038. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  3039. }
  3040. } catch (e) { }
  3041. return p;
  3042. }
  3043. }
  3044. return this.createElement24.apply(this, arguments);
  3045. };
  3046.  
  3047. })();
  3048.  
  3049. ; fix_error_many_stack_state === 1 && (() => {
  3050.  
  3051.  
  3052. let p1 = winError00;
  3053.  
  3054. let stackNeedleDetails = null;
  3055.  
  3056. Object.defineProperty(Object.prototype, 'matchAll', {
  3057. get() {
  3058. stackNeedleDetails = this;
  3059. return true;
  3060. },
  3061. enumerable: true,
  3062. configurable: true
  3063. });
  3064.  
  3065. try {
  3066. JSON.parse("{}");
  3067. } catch (e) {
  3068. console.warn(e)
  3069. fix_error_many_stack_state = 0;
  3070. }
  3071.  
  3072. delete Object.prototype['matchAll'];
  3073.  
  3074. let p2 = window.onerror;
  3075.  
  3076. window.onerror = p1;
  3077.  
  3078. if (fix_error_many_stack_state === 0) return;
  3079.  
  3080. if (stackNeedleDetails) {
  3081. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  3082. stackNeedleDetails.matchAll = true;
  3083. }
  3084.  
  3085. if (p1 === p2) return (fix_error_many_stack_state = 0);
  3086.  
  3087. // p1!==p2
  3088. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  3089.  
  3090. })();
  3091.  
  3092. ; fix_error_many_stack_state === 2 && (() => {
  3093.  
  3094.  
  3095. let p1 = winError00;
  3096.  
  3097. let objectPrune = null;
  3098. let stackNeedleDetails = null;
  3099.  
  3100. Object.defineProperty(Function.prototype, 'findOwner', {
  3101. get() {
  3102. objectPrune = this;
  3103. return this._findOwner;
  3104. },
  3105. set(nv) {
  3106. this._findOwner = nv;
  3107. return true;
  3108. },
  3109. enumerable: true,
  3110. configurable: true
  3111. });
  3112.  
  3113. Object.defineProperty(Object.prototype, 'matchAll', {
  3114. get() {
  3115. stackNeedleDetails = this;
  3116. return true;
  3117. },
  3118. enumerable: true,
  3119. configurable: true
  3120. });
  3121.  
  3122. try {
  3123. JSON.parse("{}");
  3124. } catch (e) {
  3125. console.warn(e)
  3126. fix_error_many_stack_state = 0;
  3127. }
  3128.  
  3129. delete Function.prototype['findOwner'];
  3130. delete Object.prototype['matchAll'];
  3131.  
  3132. let p2 = window.onerror;
  3133.  
  3134. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  3135.  
  3136. if (fix_error_many_stack_state == 0) return;
  3137.  
  3138. // the following will only execute when Brave's scriptlets.js is executed.
  3139.  
  3140. prepareLogs.push("fix_error_many_stack_state NB")
  3141.  
  3142. if (stackNeedleDetails) {
  3143. stackNeedleDetails.pattern = null;
  3144. stackNeedleDetails.re = null;
  3145. stackNeedleDetails.expect = null;
  3146. stackNeedleDetails.matchAll = true;
  3147. }
  3148.  
  3149. if (objectPrune) {
  3150. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  3151. delete objectPrune._findOwner;
  3152. }
  3153.  
  3154. fix_error_many_stack_state = 3;
  3155. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  3156. JSON.parse.objectPrune = objectPrune;
  3157.  
  3158. })();
  3159.  
  3160. ; fix_error_many_stack_state === 3 && (() => {
  3161.  
  3162.  
  3163. let p1 = winError00;
  3164.  
  3165. try {
  3166. JSON.parse("{}");
  3167. } catch (e) {
  3168. console.warn(e)
  3169. fix_error_many_stack_state = 0;
  3170. }
  3171.  
  3172. let p2 = window.onerror;
  3173.  
  3174. if (p1 === p2) return;
  3175.  
  3176. window.onerror = p1;
  3177.  
  3178. if (fix_error_many_stack_state === 0) return;
  3179.  
  3180. fix_error_many_stack_state = 4; // p1 != p2
  3181.  
  3182.  
  3183. })();
  3184.  
  3185. fix_error_many_stack_state === 4 && (() => {
  3186.  
  3187. // the following will only execute when Brave's scriptlets.js is executed.
  3188.  
  3189. prepareLogs.push("fix_error_many_stack_state AB")
  3190.  
  3191. JSON.parseProxy = JSON.parse;
  3192.  
  3193. JSON.parse = ((parse) => {
  3194.  
  3195. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  3196. return function (text, reviver) {
  3197. const onerror = window.onerror;
  3198. window.onerror = null;
  3199. let r;
  3200. try {
  3201. r = parse(...arguments);
  3202. } catch (e) {
  3203. r = e;
  3204. }
  3205. window.onerror = onerror;
  3206. if (r instanceof Error) {
  3207. throw r;
  3208. }
  3209. return r;
  3210. }
  3211.  
  3212. })(JSON.parse);
  3213.  
  3214.  
  3215. })();
  3216.  
  3217.  
  3218. // << if FIX_yt_player >>
  3219.  
  3220. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  3221. const PERF_471489_ = true;
  3222. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  3223. // This script uses a much gentle way to tamer the JS engine instead.
  3224.  
  3225. // << end >>
  3226.  
  3227. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  3228.  
  3229.  
  3230.  
  3231. const nilFn = () => { };
  3232.  
  3233. let isMainWindow = false;
  3234. try {
  3235. isMainWindow = window.document === window.top.document
  3236. } catch (e) { }
  3237.  
  3238. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  3239. let headLinkCollection = null;
  3240.  
  3241. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3242.  
  3243. const promiseForCustomYtElementsReady = isCustomElementsProvided ? null : new Promise((callback) => {
  3244. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3245. if (typeof customElements === 'undefined') {
  3246. if (!('__CE_registry' in document)) {
  3247. // https://github.com/webcomponents/polyfills/
  3248. Object.defineProperty(document, '__CE_registry', {
  3249. get() {
  3250. // return undefined
  3251. },
  3252. set(nv) {
  3253. if (typeof nv == 'object') {
  3254. delete this.__CE_registry;
  3255. this.__CE_registry = nv;
  3256. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3257. }
  3258. return true;
  3259. },
  3260. enumerable: false,
  3261. configurable: true
  3262. })
  3263. }
  3264. let eventHandler = (evt) => {
  3265. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3266. const f = callback;
  3267. callback = null;
  3268. eventHandler = null;
  3269. f();
  3270. };
  3271. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3272. } else {
  3273. callback();
  3274. }
  3275. });
  3276.  
  3277. const whenCEDefined = isCustomElementsProvided
  3278. ? (nodeName) => customElements.whenDefined(nodeName)
  3279. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3280.  
  3281. // const assertor = (f) => f() || console.assert(false, f + "");
  3282.  
  3283. const fnIntegrity = (f, d) => {
  3284. if (!f || typeof f !== 'function') {
  3285. console.warn('f is not a function', f);
  3286. return;
  3287. }
  3288. let p = f + "", s = 0, j = -1, w = 0;
  3289. for (let i = 0, l = p.length; i < l; i++) {
  3290. const t = p[i];
  3291. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  3292. if (j < i - 1) w++;
  3293. j = i;
  3294. } else {
  3295. s++;
  3296. }
  3297. }
  3298. let itz = `${f.length}.${s}.${w}`;
  3299. if (!d) {
  3300. return itz;
  3301. } else {
  3302. return itz === d;
  3303. }
  3304. };
  3305.  
  3306. const getZqOu = (_yt_player) => {
  3307.  
  3308. const w = 'ZqOu';
  3309.  
  3310. let arr = [];
  3311.  
  3312. for (const [k, v] of Object.entries(_yt_player)) {
  3313.  
  3314. const p = typeof v === 'function' ? v.prototype : 0;
  3315. if (p
  3316. && typeof p.start === 'function' && p.start.length === 0 // Ou
  3317. && typeof p.isActive === 'function' && p.isActive.length === 0
  3318. && typeof p.stop === 'function' && p.stop.length === 0
  3319. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  3320. && !p.send && !p.abort
  3321. && !p.sample && !p.initialize && !p.fail && !p.getName
  3322. // && !p.dispose && !p.isDisposed
  3323.  
  3324. ) {
  3325. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3326.  
  3327.  
  3328. }
  3329.  
  3330. }
  3331.  
  3332. if (arr.length === 0) {
  3333.  
  3334. console.warn(`Key does not exist. [${w}]`);
  3335. } else {
  3336.  
  3337. console.log(`[${w}]`, arr);
  3338. return arr[0];
  3339. }
  3340.  
  3341. }
  3342.  
  3343. const getZqQu = (_yt_player) => {
  3344.  
  3345. const w = 'ZqQu';
  3346.  
  3347. let arr = [];
  3348.  
  3349.  
  3350. for (const [k, v] of Object.entries(_yt_player)) {
  3351.  
  3352. const p = typeof v === 'function' ? v.prototype : 0;
  3353. if (p
  3354. && typeof p.start === 'function' && p.start.length === 1 // Qu
  3355. && typeof p.isActive === 'function' && p.isActive.length === 0
  3356. && typeof p.stop === 'function' && p.stop.length === 0
  3357. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  3358. && !p.send && !p.abort
  3359. && !p.sample && !p.initialize && !p.fail && !p.getName
  3360. // && !p.dispose && !p.isDisposed
  3361.  
  3362. ) {
  3363. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3364.  
  3365.  
  3366. }
  3367.  
  3368. }
  3369.  
  3370. if (arr.length === 0) {
  3371.  
  3372. console.warn(`Key does not exist. [${w}]`);
  3373. } else {
  3374.  
  3375. console.log(`[${w}]`, arr);
  3376. return arr[0];
  3377. }
  3378.  
  3379. }
  3380.  
  3381.  
  3382. const getVG = (_yt_player) => {
  3383. const w = 'VG';
  3384.  
  3385. let arr = [];
  3386.  
  3387. for (const [k, v] of Object.entries(_yt_player)) {
  3388.  
  3389. const p = typeof v === 'function' ? v.prototype : 0;
  3390. if (p
  3391. && typeof p.show === 'function' && p.show.length === 1
  3392. && typeof p.hide === 'function' && p.hide.length === 0
  3393. && typeof p.stop === 'function' && p.stop.length === 0) {
  3394.  
  3395. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3396.  
  3397. }
  3398.  
  3399. }
  3400.  
  3401.  
  3402. if (arr.length === 0) {
  3403.  
  3404. console.warn(`Key does not exist. [${w}]`);
  3405. } else {
  3406.  
  3407. console.log(`[${w}]`, arr);
  3408. return arr[0];
  3409. }
  3410.  
  3411.  
  3412.  
  3413. }
  3414.  
  3415.  
  3416. const getzo = (_yt_player) => {
  3417. const w = 'zo';
  3418.  
  3419. let arr = [];
  3420.  
  3421. for (const [k, v] of Object.entries(_yt_player)) {
  3422.  
  3423. if (
  3424. typeof v === 'function' && v.length === 3 && k.length < 3
  3425. && (v + "").includes("a.style[b]=c")
  3426. ) {
  3427.  
  3428. arr.push(k);
  3429.  
  3430. }
  3431.  
  3432. }
  3433.  
  3434.  
  3435. if (arr.length === 0) {
  3436.  
  3437. console.warn(`Key does not exist. [${w}]`);
  3438. } else {
  3439.  
  3440. console.log(`[${w}]`, arr);
  3441. return arr[0];
  3442. }
  3443.  
  3444. }
  3445.  
  3446. const addProtoToArr = (parent, key, arr) => {
  3447.  
  3448.  
  3449. let isChildProto = false;
  3450. for (const sr of arr) {
  3451. if (parent[key].prototype instanceof parent[sr]) {
  3452. isChildProto = true;
  3453. break;
  3454. }
  3455. }
  3456.  
  3457. if (isChildProto) return;
  3458.  
  3459. arr = arr.filter(sr => {
  3460. if (parent[sr].prototype instanceof parent[key]) {
  3461. return false;
  3462. }
  3463. return true;
  3464. });
  3465.  
  3466. arr.push(key);
  3467.  
  3468. return arr;
  3469.  
  3470.  
  3471. }
  3472.  
  3473. const getuG = (_yt_player) => {
  3474.  
  3475. const w = 'uG';
  3476.  
  3477. let arr = [];
  3478.  
  3479. for (const [k, v] of Object.entries(_yt_player)) {
  3480.  
  3481.  
  3482. const p = typeof v === 'function' ? v.prototype : 0;
  3483.  
  3484. if (p
  3485. && typeof p.createElement === 'function' && p.createElement.length === 2
  3486. && typeof p.detach === 'function' && p.detach.length === 0
  3487. && typeof p.update === 'function' && p.update.length === 1
  3488. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  3489. ) {
  3490.  
  3491. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3492.  
  3493. }
  3494.  
  3495. }
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501. if (arr.length === 0) {
  3502.  
  3503. console.warn(`Key does not exist. [${w}]`);
  3504. } else {
  3505.  
  3506. console.log(`[${w}]`, arr);
  3507. return arr[0];
  3508. }
  3509.  
  3510. }
  3511.  
  3512.  
  3513. const getQT = (_yt_player) => {
  3514. const w = 'QT';
  3515.  
  3516. let arr = [];
  3517. let brr = new Map();
  3518.  
  3519. for (const [k, v] of Object.entries(_yt_player)) {
  3520.  
  3521. const p = typeof v === 'function' ? v.prototype : 0;
  3522. if (p) {
  3523. let q = 0;
  3524. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  3525. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  3526. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  3527.  
  3528. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  3529.  
  3530. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  3531.  
  3532. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  3533. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  3534. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  3535. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  3536.  
  3537.  
  3538. // differentiate QT and DX
  3539.  
  3540. q += 280;
  3541. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  3542. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  3543. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  3544. if (typeof p.seekBy === 'function') q += 4;
  3545. if (typeof p.seekTo === 'function') q += 4;
  3546. if (typeof p.getStoryboardFormat === 'function') q += 4;
  3547. if (typeof p.getDuration === 'function') q += 4;
  3548. if (typeof p.loadModule === 'function') q += 4;
  3549. if (typeof p.unloadModule === 'function') q += 4;
  3550. if (typeof p.getOption === 'function') q += 4;
  3551. if (typeof p.getOptions === 'function') q += 4;
  3552. if (typeof p.setOption === 'function') q += 4;
  3553. if (typeof p.addCueRange === 'function') q += 4;
  3554. if (typeof p.getDebugText === 'function') q += 4;
  3555. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  3556. if (typeof p.setSizeStyle === 'function') q += 4;
  3557. if (typeof p.showControls === 'function') q += 4;
  3558. if (typeof p.hideControls === 'function') q += 4;
  3559. if (typeof p.getVideoContentRect === 'function') q += 4;
  3560. if (typeof p.toggleFullscreen === 'function') q += 4;
  3561. if (typeof p.isFullscreen === 'function') q += 4;
  3562. if (typeof p.cancelPlayback === 'function') q += 4;
  3563. if (typeof p.getProgressState === 'function') q += 4;
  3564. if (typeof p.isInline === 'function') q += 4;
  3565. if (typeof p.setInline === 'function') q += 4;
  3566. if (typeof p.toggleSubtitles === 'function') q += 4;
  3567. if (typeof p.getPlayerSize === 'function') q += 4;
  3568. if (typeof p.wakeUpControls === 'function') q += 4;
  3569. if (typeof p.setCenterCrop === 'function') q += 4;
  3570. if (typeof p.getLoopVideo === 'function') q += 4;
  3571. if (typeof p.setLoopVideo === 'function') q += 4;
  3572.  
  3573.  
  3574. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  3575.  
  3576. if (q > 0) brr.set(k, q);
  3577.  
  3578. }
  3579.  
  3580. }
  3581.  
  3582. if (arr.length === 0) {
  3583.  
  3584. console.warn(`Key does not exist. [${w}]`);
  3585. } else {
  3586.  
  3587. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  3588.  
  3589. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  3590.  
  3591. if (arr.length > 2) console.log(`[${w}]`, arr);
  3592. return arr[0][0];
  3593. }
  3594.  
  3595.  
  3596.  
  3597. }
  3598.  
  3599.  
  3600.  
  3601. const getSV = (_yt_player) => {
  3602. const w = 'SV';
  3603.  
  3604. let arr = [];
  3605. let brr = new Map();
  3606.  
  3607. for (const [k, v] of Object.entries(_yt_player)) {
  3608.  
  3609. const p = typeof v === 'function' ? v.prototype : 0;
  3610. if (p) {
  3611. let q = 0;
  3612. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  3613. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  3614. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  3615.  
  3616. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  3617.  
  3618. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  3619.  
  3620. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  3621. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  3622. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  3623. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  3624.  
  3625.  
  3626. // differentiate QT and DX
  3627.  
  3628.  
  3629. q += 280;
  3630.  
  3631. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  3632. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  3633. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  3634. if (typeof p.seekBy === 'function') q -= 4;
  3635. if (typeof p.seekTo === 'function') q -= 4;
  3636. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  3637. if (typeof p.getDuration === 'function') q -= 4;
  3638. if (typeof p.loadModule === 'function') q -= 4;
  3639. if (typeof p.unloadModule === 'function') q -= 4;
  3640. if (typeof p.getOption === 'function') q -= 4;
  3641. if (typeof p.getOptions === 'function') q -= 4;
  3642. if (typeof p.setOption === 'function') q -= 4;
  3643. if (typeof p.addCueRange === 'function') q -= 4;
  3644. if (typeof p.getDebugText === 'function') q -= 4;
  3645. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  3646. if (typeof p.setSizeStyle === 'function') q -= 4;
  3647. if (typeof p.showControls === 'function') q -= 4;
  3648. if (typeof p.hideControls === 'function') q -= 4;
  3649. if (typeof p.getVideoContentRect === 'function') q -= 4;
  3650. if (typeof p.toggleFullscreen === 'function') q -= 4;
  3651. if (typeof p.isFullscreen === 'function') q -= 4;
  3652. if (typeof p.cancelPlayback === 'function') q -= 4;
  3653. if (typeof p.getProgressState === 'function') q -= 4;
  3654. if (typeof p.isInline === 'function') q -= 4;
  3655. if (typeof p.setInline === 'function') q -= 4;
  3656. if (typeof p.toggleSubtitles === 'function') q -= 4;
  3657. if (typeof p.getPlayerSize === 'function') q -= 4;
  3658. if (typeof p.wakeUpControls === 'function') q -= 4;
  3659. if (typeof p.setCenterCrop === 'function') q -= 4;
  3660. if (typeof p.getLoopVideo === 'function') q -= 4;
  3661. if (typeof p.setLoopVideo === 'function') q -= 4;
  3662.  
  3663.  
  3664. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  3665.  
  3666. if (q > 0) brr.set(k, q);
  3667.  
  3668. }
  3669.  
  3670. }
  3671.  
  3672. if (arr.length === 0) {
  3673.  
  3674. console.warn(`Key does not exist. [${w}]`);
  3675. } else {
  3676.  
  3677. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  3678.  
  3679. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  3680.  
  3681. if (arr.length > 2) console.log(`[${w}]`, arr);
  3682. return arr[0][0];
  3683. }
  3684.  
  3685.  
  3686.  
  3687. }
  3688.  
  3689.  
  3690.  
  3691.  
  3692. const getDX = (_yt_player) => {
  3693. const w = 'DX';
  3694.  
  3695. let arr = [];
  3696. let brr = new Map();
  3697.  
  3698. for (const [k, v] of Object.entries(_yt_player)) {
  3699.  
  3700. const p = typeof v === 'function' ? v.prototype : 0;
  3701. if (p) {
  3702. let q = 0;
  3703. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  3704. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  3705. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  3706.  
  3707. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  3708.  
  3709.  
  3710. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  3711.  
  3712. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  3713.  
  3714. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  3715. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  3716. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  3717. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  3718.  
  3719.  
  3720. // differentiate QT and DX
  3721.  
  3722.  
  3723. q += 280;
  3724.  
  3725. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  3726. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  3727. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  3728. if (typeof p.seekBy === 'function') q -= 4;
  3729. if (typeof p.seekTo === 'function') q -= 4;
  3730. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  3731. if (typeof p.getDuration === 'function') q -= 4;
  3732. if (typeof p.loadModule === 'function') q -= 4;
  3733. if (typeof p.unloadModule === 'function') q -= 4;
  3734. if (typeof p.getOption === 'function') q -= 4;
  3735. if (typeof p.getOptions === 'function') q -= 4;
  3736. if (typeof p.setOption === 'function') q -= 4;
  3737. if (typeof p.addCueRange === 'function') q -= 4;
  3738. if (typeof p.getDebugText === 'function') q -= 4;
  3739. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  3740. if (typeof p.setSizeStyle === 'function') q -= 4;
  3741. if (typeof p.showControls === 'function') q -= 4;
  3742. if (typeof p.hideControls === 'function') q -= 4;
  3743. if (typeof p.getVideoContentRect === 'function') q -= 4;
  3744. if (typeof p.toggleFullscreen === 'function') q -= 4;
  3745. if (typeof p.isFullscreen === 'function') q -= 4;
  3746. if (typeof p.cancelPlayback === 'function') q -= 4;
  3747. if (typeof p.getProgressState === 'function') q -= 4;
  3748. if (typeof p.isInline === 'function') q -= 4;
  3749. if (typeof p.setInline === 'function') q -= 4;
  3750. if (typeof p.toggleSubtitles === 'function') q -= 4;
  3751. if (typeof p.getPlayerSize === 'function') q -= 4;
  3752. if (typeof p.wakeUpControls === 'function') q -= 4;
  3753. if (typeof p.setCenterCrop === 'function') q -= 4;
  3754. if (typeof p.getLoopVideo === 'function') q -= 4;
  3755. if (typeof p.setLoopVideo === 'function') q -= 4;
  3756.  
  3757.  
  3758. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  3759.  
  3760. if (q > 0) brr.set(k, q);
  3761.  
  3762. }
  3763.  
  3764. }
  3765.  
  3766. if (arr.length === 0) {
  3767.  
  3768. console.warn(`Key does not exist. [${w}]`);
  3769. } else {
  3770.  
  3771. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  3772.  
  3773. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  3774.  
  3775. if (arr.length > 2) console.log(`[${w}]`, arr);
  3776. return arr[0][0];
  3777. }
  3778.  
  3779.  
  3780.  
  3781. }
  3782.  
  3783.  
  3784.  
  3785. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  3786.  
  3787. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  3788. let pageSetupState = 0;
  3789.  
  3790. isPrepareCachedV && (() => {
  3791.  
  3792. pageSetupVideoId = '';
  3793. const clearCachedV = () => {
  3794. pageSetupVideoId = '';
  3795. pageSetupState = 0;
  3796. }
  3797. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  3798. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  3799. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  3800. document.addEventListener('yt-navigate-finish', () => {
  3801. pageSetupState = 1;
  3802. try {
  3803. const url = new URL(location.href);
  3804. if (!url || url.pathname !== '/watch') {
  3805. pageSetupVideoId = '';
  3806. } else {
  3807. pageSetupVideoId = url.searchParams.get('v') || '';
  3808. }
  3809. } catch (e) {
  3810. pageSetupVideoId = '';
  3811. }
  3812. }, false);
  3813.  
  3814. })();
  3815.  
  3816. let videoPlayingY = null;
  3817.  
  3818. isPrepareCachedV && (() => {
  3819.  
  3820. let getNext = true;
  3821. let videoPlayingX = {
  3822. get videoId() {
  3823. if (getNext) {
  3824. getNext = false;
  3825.  
  3826. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  3827. const arr = [];
  3828. for (const element of elements) {
  3829. if (!element.closest('[hidden]')) arr.push(element);
  3830. }
  3831. if (arr.length !== 1) this.__videoId__ = '';
  3832. else {
  3833. this.__videoId__ = arr[0].getAttribute('video-id');
  3834. }
  3835.  
  3836. }
  3837. return this.__videoId__ || '';
  3838. }
  3839. }
  3840.  
  3841. videoPlayingY = videoPlayingX;
  3842. const handler = (evt) => {
  3843. const target = (evt || 0).target;
  3844. if (target instanceof HTMLVideoElement) {
  3845. getNext = true;
  3846. }
  3847. }
  3848. document.addEventListener('loadedmetadata', handler, true);
  3849. document.addEventListener('durationchange', handler, true);
  3850.  
  3851. })();
  3852.  
  3853.  
  3854.  
  3855. const cleanContext = async (win) => {
  3856. const waitFn = requestAnimationFrame; // shall have been binded to window
  3857. try {
  3858. let mx = 16; // MAX TRIAL
  3859. const frameId = 'vanillajs-iframe-v1';
  3860. /** @type {HTMLIFrameElement | null} */
  3861. let frame = document.getElementById(frameId);
  3862. let removeIframeFn = null;
  3863. if (!frame) {
  3864. frame = document.createElement('iframe');
  3865. frame.id = frameId;
  3866. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  3867. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  3868. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  3869. n.appendChild(frame);
  3870. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  3871. const root = document.documentElement;
  3872. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  3873. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  3874.  
  3875. removeIframeFn = (setTimeout) => {
  3876. const removeIframeOnDocumentReady = (e) => {
  3877. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  3878. e = n;
  3879. n = win = removeIframeFn = 0;
  3880. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  3881. }
  3882. if (!setTimeout || document.readyState !== 'loading') {
  3883. removeIframeOnDocumentReady();
  3884. } else {
  3885. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  3886. }
  3887. }
  3888. }
  3889. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  3890. const fc = frame.contentWindow;
  3891. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  3892. try {
  3893. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  3894. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  3895. for (let k in res) res[k] = res[k].bind(win); // necessary
  3896. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  3897. res.animate = fc.HTMLElement.prototype.animate;
  3898. res.perfNow = fc.performance.now;
  3899. return res;
  3900. } catch (e) {
  3901. if (removeIframeFn) removeIframeFn();
  3902. return null;
  3903. }
  3904. } catch (e) {
  3905. console.warn(e);
  3906. return null;
  3907. }
  3908. };
  3909.  
  3910. const promiseForYtActionCalled = new Promise(resolve => {
  3911. if (typeof AbortSignal !== 'undefined') {
  3912. let hn = () => {
  3913. if (!hn) return;
  3914. hn = null;
  3915. resolve(document.querySelector('ytd-app'));
  3916. };
  3917. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  3918. } else {
  3919. let hn = () => {
  3920. if (!hn) return;
  3921. document.removeEventListener('yt-action', hn, true);
  3922. hn = null;
  3923. resolve(document.querySelector('ytd-app'));
  3924. };
  3925. document.addEventListener('yt-action', hn, true);
  3926. }
  3927. });
  3928.  
  3929.  
  3930.  
  3931. cleanContext(window).then(__CONTEXT__ => {
  3932. if (!__CONTEXT__) return null;
  3933.  
  3934. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  3935.  
  3936.  
  3937. performance.now17 = perfNow.bind(performance);
  3938.  
  3939.  
  3940.  
  3941. __requestAnimationFrame__ = requestAnimationFrame;
  3942.  
  3943. let rafPromise = null;
  3944.  
  3945. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  3946. requestAnimationFrame(hRes => {
  3947. rafPromise = null;
  3948. resolve(hRes);
  3949. });
  3950. }));
  3951.  
  3952.  
  3953. const wmComputedStyle = new WeakMap();
  3954.  
  3955. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  3956. window.__native__getComputedStyle__ = getComputedStyle;
  3957. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  3958. window.__original__getComputedStyle__ = window.getComputedStyle;
  3959. window.getComputedStyle = function (elem) {
  3960. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  3961. return window.__native__getComputedStyle__(...arguments);
  3962. }
  3963. let cs = wmComputedStyle.get(elem);
  3964. if (!cs) {
  3965. cs = window.__native__getComputedStyle__(elem);
  3966. wmComputedStyle.set(elem, cs);
  3967. }
  3968. return cs;
  3969. };
  3970. } else {
  3971. window.__original__getComputedStyle__ = null;
  3972. }
  3973. window.__jst__getComputedStyle__ = window.getComputedStyle;
  3974. }
  3975.  
  3976. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  3977. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  3978. window.getComputedStyle = window.__jst__getComputedStyle__;
  3979. }
  3980. });
  3981.  
  3982. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  3983. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  3984.  
  3985. const promiseForTamerTimeout = new Promise(resolve => {
  3986. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  3987. setTimeout(resolve, 480);
  3988. }, { capture: true, passive: true, once: true });
  3989. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  3990. setTimeout(resolve, 1200);
  3991. });
  3992. setTimeout(resolve, 3000);
  3993. });
  3994.  
  3995. const promiseForPageInitied = new Promise(resolve => {
  3996. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  3997. setTimeout(resolve, 450);
  3998. }, { capture: true, passive: true, once: true });
  3999. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  4000. setTimeout(resolve, 900);
  4001. });
  4002. setTimeout(resolve, 1800);
  4003. });
  4004.  
  4005. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  4006. NO_PRELOAD_GENERATE_204_BYPASS = true;
  4007. headLinkCollection = null;
  4008. });
  4009.  
  4010.  
  4011. NATIVE_CANVAS_ANIMATION && (() => {
  4012.  
  4013. observablePromise(() => {
  4014. HTMLCanvasElement.prototype.animate = animate;
  4015. }, promiseForTamerTimeout).obtain();
  4016.  
  4017. })();
  4018.  
  4019. FIX_ytAction_ && (async () => {
  4020.  
  4021. const ytdApp = await new Promise(resolve => {
  4022.  
  4023. whenCEDefined('ytd-app').then(() => {
  4024. const ytdApp = document.querySelector('ytd-app');
  4025. if (ytdApp) {
  4026. resolve(ytdApp);
  4027. return;
  4028. }
  4029. let mo = new MutationObserver(() => {
  4030. const ytdApp = document.querySelector('ytd-app');
  4031. if (!ytdApp) return;
  4032. if (mo) {
  4033. mo.disconnect();
  4034. mo.takeRecords();
  4035. mo = null;
  4036. }
  4037. resolve(ytdApp);
  4038. });
  4039. mo.observe(document, { subtree: true, childList: true });
  4040. });
  4041.  
  4042. });
  4043.  
  4044. if (!ytdApp) return;
  4045. const cProto = insp(ytdApp).constructor.prototype;
  4046.  
  4047. if (!cProto) return;
  4048. let mbd = 0;
  4049.  
  4050. const fixer = (_ytdApp) => {
  4051. const ytdApp = insp(_ytdApp);
  4052. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  4053. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  4054. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  4055. mbd++;
  4056. }
  4057. }
  4058.  
  4059. observablePromise(() => {
  4060.  
  4061. if (typeof cProto.created === 'function' && !cProto.created56) {
  4062. cProto.created56 = cProto.created;
  4063. cProto.created = function (...args) {
  4064. const r = this.created56(...args);
  4065. fixer(this);
  4066. return r;
  4067. };
  4068. mbd++;
  4069. }
  4070.  
  4071. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  4072. cProto.onYtAction57_ = cProto.onYtAction_;
  4073. cProto.onYtAction_ = function (...args) {
  4074. Promise.resolve().then(() => this.onYtAction57_(...args));
  4075. };
  4076. mbd++;
  4077. }
  4078.  
  4079. if (ytdApp) fixer(ytdApp);
  4080.  
  4081. /*
  4082. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  4083. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  4084. actionRouter_.handleAction57 = actionRouter_.handleAction;
  4085. actionRouter_.handleAction = function (...args) {
  4086. Promise.resolve().then(() => this.handleAction57(...args));
  4087. }
  4088. mbd++;
  4089. }
  4090. */
  4091.  
  4092. // if(mbd === 3) return 1;
  4093. if (mbd >= 3) return 1;
  4094.  
  4095. }, new Promise(r => setTimeout(r, 1000))).obtain();
  4096.  
  4097. })();
  4098.  
  4099. const observablePromise = (proc, timeoutPromise) => {
  4100. let promise = null;
  4101. return {
  4102. obtain() {
  4103. if (!promise) {
  4104. promise = new Promise(resolve => {
  4105. let mo = null;
  4106. const f = () => {
  4107. let t = proc();
  4108. if (t) {
  4109. mo.disconnect();
  4110. mo.takeRecords();
  4111. mo = null;
  4112. resolve(t);
  4113. }
  4114. }
  4115. mo = new MutationObserver(f);
  4116. mo.observe(document, { subtree: true, childList: true })
  4117. f();
  4118. timeoutPromise && timeoutPromise.then(() => {
  4119. resolve(null)
  4120. });
  4121. });
  4122. }
  4123. return promise
  4124. }
  4125. }
  4126. }
  4127.  
  4128. // let _yt_player_promise = null;
  4129. /*
  4130. const getYtPlayerPromise = () => {
  4131. if (!_yt_player_promise) {
  4132. _yt_player_promise = new Promise(resolve => {
  4133. let cid = setInterval(() => {
  4134. let t = (((window || 0)._yt_player || 0) || 0);
  4135. if (t) {
  4136. clearInterval(cid);
  4137. resolve(t);
  4138. }
  4139. }, 1);
  4140. promiseForTamerTimeout.then(() => {
  4141. resolve(null)
  4142. });
  4143. });
  4144. }
  4145. return _yt_player_promise;
  4146. }
  4147. */
  4148. const _yt_player_observable = observablePromise(() => {
  4149. return (((window || 0)._yt_player || 0) || 0);
  4150. }, promiseForTamerTimeout);
  4151.  
  4152. const polymerObservable = observablePromise(() => {
  4153. const Polymer = window.Polymer;
  4154. if (typeof Polymer !== 'function') return;
  4155. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  4156. return Polymer;
  4157. }, promiseForTamerTimeout);
  4158.  
  4159. const schedulerInstanceObservable = observablePromise(() => {
  4160. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  4161. }, promiseForTamerTimeout);
  4162.  
  4163. const timelineObservable = observablePromise(() => {
  4164. let t = (((document || 0).timeline || 0) || 0);
  4165. if (t && typeof t._play === 'function') {
  4166. return t;
  4167. }
  4168. }, promiseForTamerTimeout);
  4169. const animationObservable = observablePromise(() => {
  4170. let t = (((window || 0).Animation || 0) || 0);
  4171. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  4172. return t;
  4173. }
  4174. }, promiseForTamerTimeout);
  4175.  
  4176.  
  4177.  
  4178.  
  4179. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  4180.  
  4181. const evKey = `${_evKey}`;
  4182. const fvKey = `${_fvKey}`;
  4183. const debug = !!_debug;
  4184.  
  4185. const _yt_player = await _yt_player_observable.obtain();
  4186.  
  4187.  
  4188. if (!_yt_player || typeof _yt_player !== 'object') return;
  4189.  
  4190.  
  4191. const getArr = (_yt_player) => {
  4192.  
  4193. let arr = [];
  4194.  
  4195. for (const [k, v] of Object.entries(_yt_player)) {
  4196.  
  4197. const p = typeof v === 'function' ? v.prototype : 0;
  4198. if (p
  4199. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  4200.  
  4201. ) {
  4202. arr = addProtoToArr(_yt_player, k, arr) || arr;
  4203.  
  4204. }
  4205.  
  4206. }
  4207.  
  4208. if (arr.length === 0) {
  4209.  
  4210. console.warn(`Key prop [${evKey}] does not exist.`);
  4211. } else {
  4212.  
  4213. return arr;
  4214. }
  4215.  
  4216. };
  4217.  
  4218. const arr = getArr(_yt_player);
  4219.  
  4220.  
  4221. if (!arr) return;
  4222.  
  4223. debug && console.log(`FIX_${evKey}`, arr);
  4224.  
  4225. const f = function (...args) {
  4226. Promise.resolve().then(() => this[fvKey](...args));
  4227. };
  4228.  
  4229.  
  4230. for (const k of arr) {
  4231.  
  4232. const g = _yt_player;
  4233. const gk = g[k];
  4234. const gkp = gk.prototype;
  4235.  
  4236. debug && console.log(237, k, gkp)
  4237.  
  4238. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  4239. gkp[fvKey] = gkp[evKey];
  4240. gkp[evKey] = f;
  4241. }
  4242. }
  4243.  
  4244.  
  4245.  
  4246.  
  4247. }
  4248.  
  4249. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  4250. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  4251. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  4252. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  4253. if (FIX_VideoEVENTS_v2) {
  4254. const FIX_VideoEVENTS_DEBUG = 0;
  4255. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  4256. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  4257. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  4258. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  4259. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  4260. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  4261. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  4262. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  4263. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  4264.  
  4265. }
  4266. // onMutedAutoplayChange
  4267. // onVolumeChange
  4268. // onPlaybackRateChange
  4269.  
  4270. // onAirPlayActiveChange
  4271. // onAirPlayAvailabilityChange
  4272. // onApiChange
  4273. // onAutoplayBlocked
  4274. // onDrmOutputRestricted
  4275. // onFullscreenChange
  4276. // onLoadProgress
  4277. // onLoadedMetadata
  4278. // onVideoDataChange
  4279. // onVideoProgress
  4280.  
  4281.  
  4282. (ENABLE_discreteTasking || UNLOAD_DETACHED_POLYMER) && (async () => {
  4283.  
  4284. const Polymer = await polymerObservable.obtain();
  4285. if (!Polymer) return;
  4286.  
  4287.  
  4288. if (UNLOAD_DETACHED_POLYMER && typeof Polymer.Base.detached === 'function' && !Polymer.Base.detached92 && Polymer.Base.detached.length === 0) {
  4289. Polymer.Base.detached92 = Polymer.Base.detached;
  4290.  
  4291. const detachedPlus = async function (elem) {
  4292. await delay300.then();
  4293. if (elem.isAttached !== false) return;
  4294. await delay300.then();
  4295. if (elem.isAttached !== false) return;
  4296.  
  4297. if (elem.__dataClientsReady === true) elem.__dataClientsReady = false;
  4298. // if (elem.__dataEnabled === true) elem.__dataEnabled = false;
  4299. if (elem.__dataReady === true) elem.__dataReady = false;
  4300.  
  4301. elem.__dataLinkedPaths = elem.__dataToNotify = elem.__dataPendingClients = null;
  4302. elem.__dataHasPaths = false;
  4303. // elem.__dataCompoundStorage = null;
  4304. elem.__dataHost = null;
  4305. elem.__dataTemp = null;
  4306. elem.__dataClientsInitialized = false;
  4307.  
  4308.  
  4309. // elem.data = {};
  4310. elem.data = null;
  4311. elem.__dataPending = null;
  4312. elem.__dataOld = null;
  4313. elem.__dataInstanceProps = null;
  4314.  
  4315. elem.__dataCounter = 0;
  4316. elem.__serializing = false;
  4317.  
  4318. }
  4319. Polymer.Base.detached = function () {
  4320. Promise.resolve(this).then(detachedPlus);
  4321. return Polymer.Base.detached92();
  4322. };
  4323. }
  4324.  
  4325.  
  4326. if (ENABLE_discreteTasking) {
  4327.  
  4328. Polymer.Base.__connInit__ = function () {
  4329. setupDiscreteTasks(this);
  4330. // if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  4331. // setupWeakRef(this)
  4332. // }
  4333. }
  4334.  
  4335.  
  4336. /** @type {Function} */
  4337. const connectedCallbackK = function (...args) {
  4338. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  4339. const r = this[qm53](...args);
  4340. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  4341. this.mh35 = 1;
  4342. return r;
  4343. };
  4344.  
  4345. connectedCallbackK.m353 = 1;
  4346.  
  4347.  
  4348. const qt53 = Polymer.Base.connectedCallback;
  4349. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  4350.  
  4351. Polymer.Base.connectedCallback = connectedCallbackK;
  4352.  
  4353.  
  4354. /** @type {Function} */
  4355. const createdK = function (...args) {
  4356. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  4357. const r = this[qn53](...args);
  4358. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  4359. this.mh36 = 1;
  4360. return r;
  4361. };
  4362.  
  4363.  
  4364. createdK.m353 = 1;
  4365. Polymer.Base[qn53] = Polymer.Base.created;
  4366. Polymer.Base.created = createdK;
  4367.  
  4368. }
  4369.  
  4370. })();
  4371.  
  4372.  
  4373. /*
  4374.  
  4375. e.nativeAppendChild = d.prototype.appendChild,
  4376. d.prototype.appendChild = function(h) {
  4377. return function(l) {
  4378. if (l instanceof DocumentFragment) {
  4379. var m = Array.from(l.children);
  4380. l = h.nativeAppendChild.call(this, l);
  4381. if (this.isConnected) {
  4382. m = g(m);
  4383. for (var p = m.next(); !p.done; p = m.next())
  4384. YD(p.value)
  4385. }
  4386. return l
  4387. }
  4388. m = l instanceof Element && l.isConnected;
  4389. p = h.nativeAppendChild.call(this, l);
  4390. m && ZD(l);
  4391. this.isConnected && YD(l);
  4392. return p
  4393. }
  4394. }(e),
  4395.  
  4396. */
  4397.  
  4398. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  4399.  
  4400. let __src__ = '';
  4401. const handlerCanplay = (evt) => {
  4402. const a = evt.target;
  4403. console.log('[yt-js-engine-tamer]', `video element added to dom | canplay`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  4404. if (a.currentTime < 1e-8 && a.currentTime > -1e-9 && a.autoplay === false) a.currentTime += 1e-8;
  4405. };
  4406.  
  4407. const handlerTimeupdate = (evt) => {
  4408. const a = evt.target;
  4409. console.log('[yt-js-engine-tamer]', `video element added to dom | ontimeupdate`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  4410. if (a.duration < 2.01 && a.duration > 1.99 && a.currentSrc === __src__) {
  4411. try {
  4412. URL.revokeObjectURL(__src__);
  4413. __src__ = '';
  4414. } finally {
  4415. console.log('[yt-js-engine-tamer]', `video element added to dom | revokeObjectURL`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  4416. }
  4417. }
  4418. };
  4419.  
  4420. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  4421. if (f) Node.prototype.appendChild = function (a) {
  4422. if (this instanceof Element) { // exclude DocumentFragment
  4423. try {
  4424. if (a instanceof HTMLVideoElement && FIX_VIDEO_BLOCKING) {
  4425. const src = `${a.src}`;
  4426. const b = src.length > 5 && src.startsWith('blob:') && typeof a.ontimeupdate === 'function' && a.autoplay === false && a.paused === true && a.isConnected === false && typeof nextBrowserTick === 'function' && typeof AbortSignal !== 'undefined';
  4427. if (b) {
  4428. __src__ = src;
  4429. a.addEventListener('canplay', handlerCanplay, { once: true, passive: true, capture: false });
  4430. a.addEventListener('timeupdate', handlerTimeupdate, { once: true, passive: true, capture: false });
  4431. }
  4432. console.log('[yt-js-engine-tamer]', `video element added to dom | treatment = ${b}`, mWeakRef(a), a.readyState, a.networkState);
  4433. } else {
  4434. let checkFragmentA = true;
  4435. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  4436. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  4437. for (const node of headLinkCollection) {
  4438. if (node.rel === 'preload' && node.as === 'fetch') {
  4439. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  4440. }
  4441. }
  4442. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  4443. checkFragmentA = false;
  4444. }
  4445. if ((a instanceof DocumentFragment) && checkFragmentA && a.firstElementChild === null) {
  4446. // no element in fragmentA
  4447. let doNormal = false;
  4448. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  4449. if (child.nodeType === 3) { doNormal = true; break; }
  4450. }
  4451. if (!doNormal) return a;
  4452. }
  4453. }
  4454. } catch (e) {
  4455. console.log(e);
  4456. }
  4457. }
  4458. return arguments.length === 1 && this.appendChild73 ? this.appendChild73(a) : (this.appendChild73 || Node.prototype.appendChild73 || f).apply(this, arguments);
  4459. }
  4460.  
  4461.  
  4462. })();
  4463.  
  4464. if (FIX_Shady) {
  4465.  
  4466. observablePromise(() => {
  4467. const { ShadyDOM, ShadyCSS } = window;
  4468. if (ShadyDOM) {
  4469. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  4470. ShadyDOM.noPatch = true; // 1 of 10
  4471. ShadyDOM.patchOnDemand = false; // 1 of 10
  4472. ShadyDOM.preferPerformance = true; // 1 of 10
  4473. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  4474. }
  4475. if (ShadyCSS) {
  4476. ShadyCSS.nativeCss = true; // 1 of 10
  4477. ShadyCSS.nativeShadow = true; // 6 of 10
  4478. ShadyCSS.cssBuild = undefined; // 1 of 10
  4479. ShadyCSS.disableRuntime = true; // 1 of 10
  4480. }
  4481. if (ShadyDOM && ShadyCSS) return 1;
  4482. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  4483.  
  4484. }
  4485.  
  4486.  
  4487. // let schedulerInstancePropOfTimerType = '';
  4488. // let schedulerInstancePropOfTimerId = '';
  4489. (FIX_schedulerInstanceInstance & 2) && (async () => {
  4490.  
  4491. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  4492.  
  4493. if (!schedulerInstanceInstance_) return;
  4494.  
  4495. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  4496. if (checkOK) {
  4497.  
  4498. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  4499.  
  4500. let requestingFn = null;
  4501. let requestingArgs = null;
  4502.  
  4503. const f = function () {
  4504. requestingFn = this.fn;
  4505. requestingArgs = [...arguments];
  4506. return 12373;
  4507. };
  4508.  
  4509. const fakeFns = [
  4510. f.bind({ fn: requestAnimationFrame }),
  4511. f.bind({ fn: setInterval }),
  4512. f.bind({ fn: setTimeout }),
  4513. f.bind({ fn: requestIdleCallback })
  4514. ];
  4515.  
  4516. let mzt = 0;
  4517.  
  4518. let _fnSelectorProp = null;
  4519. const mkFns = new Array(4);
  4520.  
  4521. /*
  4522. case 1:
  4523. var a = this.K;
  4524. this.g = this.I ? window.requestIdleCallback(a, {
  4525. timeout: 3E3
  4526. }) : window.setTimeout(a, ma);
  4527. break;
  4528. case 2:
  4529. this.g = window.setTimeout(this.M, this.N);
  4530. break;
  4531. case 3:
  4532. this.g = window.requestAnimationFrame(this.L);
  4533. break;
  4534. case 4:
  4535. this.g = window.setTimeout(this.J, 0)
  4536. }
  4537.  
  4538. */
  4539. const startFnHandler = {
  4540. get(target, prop, receiver) {
  4541. if (prop === '$$12377$$') return true;
  4542. if (prop === '$$12378$$') return target;
  4543.  
  4544. // console.log('get',prop)
  4545. return target[prop]
  4546. },
  4547. set(target, prop, value, receiver) {
  4548. // console.log('set', prop, value)
  4549.  
  4550. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  4551. if (value === 12373 && _fnSelectorProp) {
  4552.  
  4553. const schedulerTypeSelection = target[_fnSelectorProp];
  4554. const timerIdProp = prop;
  4555.  
  4556. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  4557. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  4558. // schedulerInstancePropOfTimerId = timerIdProp || '';
  4559. // }
  4560.  
  4561. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  4562. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  4563. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  4564. // rare
  4565. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  4566. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  4567. // often
  4568. if ((FIX_schedulerInstanceInstance & 4) && typeof nextBrowserTick == 'function') {
  4569. const f = requestingArgs[0];
  4570. const tir = ++mzt;
  4571. nextBrowserTick(() => {
  4572. if (target[timerIdProp] === -tir) f();
  4573. });
  4574. target[_fnSelectorProp] = 940;
  4575. target[timerIdProp] = -tir;
  4576. } else {
  4577. const f = requestingArgs[0];
  4578. const tir = ++mzt;
  4579. Promise.resolve().then(() => {
  4580. if (target[timerIdProp] === -tir) f();
  4581. });
  4582. target[_fnSelectorProp] = 930;
  4583. target[timerIdProp] = -tir;
  4584. }
  4585. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  4586. // often
  4587. if (requestingFn === requestIdleCallback) {
  4588. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  4589. } else {
  4590. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  4591. }
  4592. } else {
  4593. target[_fnSelectorProp] = 0;
  4594. target[timerIdProp] = 0;
  4595. }
  4596. } else {
  4597. target[prop] = value;
  4598. }
  4599. return true;
  4600. }
  4601. };
  4602.  
  4603. let startBusy = false;
  4604. schedulerInstanceInstance_.start = function () {
  4605. if (startBusy) return;
  4606. startBusy = true;
  4607. try {
  4608. mkFns[0] = window.requestAnimationFrame;
  4609. mkFns[1] = window.setInterval;
  4610. mkFns[2] = window.setTimeout;
  4611. mkFns[3] = window.requestIdleCallback;
  4612. const tThis = this['$$12378$$'] || this;
  4613. window.requestAnimationFrame = fakeFns[0]
  4614. window.setInterval = fakeFns[1]
  4615. window.setTimeout = fakeFns[2]
  4616. window.requestIdleCallback = fakeFns[3]
  4617. _fnSelectorProp = null;
  4618. tThis.start993.call(new Proxy(tThis, startFnHandler));
  4619. _fnSelectorProp = null;
  4620. window.requestAnimationFrame = mkFns[0];
  4621. window.setInterval = mkFns[1];
  4622. window.setTimeout = mkFns[2];
  4623. window.requestIdleCallback = mkFns[3];
  4624. } catch (e) {
  4625. console.warn(e);
  4626. }
  4627. startBusy = false;
  4628. }
  4629.  
  4630. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  4631.  
  4632. }
  4633. })();
  4634.  
  4635. FIX_yt_player && (async () => {
  4636. // rAf scheduling
  4637.  
  4638. const _yt_player = await _yt_player_observable.obtain();
  4639.  
  4640. if (!_yt_player || typeof _yt_player !== 'object') return;
  4641.  
  4642. let keyZqOu = getZqOu(_yt_player);
  4643.  
  4644.  
  4645. if (!keyZqOu) return;
  4646.  
  4647.  
  4648. const g = _yt_player
  4649. let k = keyZqOu
  4650.  
  4651. const gk = g[k];
  4652. if (typeof gk !== 'function') return;
  4653. const gkp = gk.prototype;
  4654.  
  4655. let dummyObject = new gk;
  4656. let nilFunc = () => { };
  4657.  
  4658. let nilObj = {};
  4659.  
  4660. // console.log(1111111111)
  4661.  
  4662. let keyBoolD = '';
  4663. let keyWindow = '';
  4664. let keyFuncC = '';
  4665. let keyCidj = '';
  4666.  
  4667. for (const [t, y] of Object.entries(dummyObject)) {
  4668. if (y instanceof Window) keyWindow = t;
  4669. }
  4670.  
  4671. const dummyObjectProxyHandler = {
  4672. get(target, prop) {
  4673. let v = target[prop]
  4674. if (v instanceof Window && !keyWindow) {
  4675. keyWindow = t;
  4676. }
  4677. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  4678. if (prop === keyWindow) y = {
  4679. requestAnimationFrame(f) {
  4680. return 3;
  4681. },
  4682. cancelAnimationFrame() {
  4683.  
  4684. }
  4685. }
  4686. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  4687. keyFuncC = prop;
  4688. }
  4689. // console.log('[get]', prop, typeof target[prop])
  4690.  
  4691.  
  4692. return y;
  4693. },
  4694. set(target, prop, value) {
  4695.  
  4696. if (typeof value === 'boolean' && !keyBoolD) {
  4697. keyBoolD = prop;
  4698. }
  4699. if (typeof value === 'number' && !keyCidj && value >= 2) {
  4700. keyCidj = prop;
  4701. }
  4702.  
  4703. // console.log('[set]', prop, value)
  4704. target[prop] = value
  4705.  
  4706. return true;
  4707. }
  4708. };
  4709.  
  4710. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  4711.  
  4712. // console.log('gkp.start',gkp.start);
  4713. // console.log('gkp.stop',gkp.stop);
  4714. gkp._activation = false;
  4715.  
  4716. gkp.start = function () {
  4717. // p59 || console.log(12100)
  4718. if (!this._activation) {
  4719. this._activation = true;
  4720. getRafPromise().then(() => {
  4721. this._activation = false;
  4722. if (this[keyCidj]) {
  4723. Promise.resolve().then(this[keyFuncC]);
  4724. }
  4725. });
  4726. }
  4727. this[keyCidj] = 1;
  4728. this[keyBoolD] = true;
  4729. }
  4730. ;
  4731. gkp.stop = function () {
  4732. this[keyCidj] = null
  4733. }
  4734.  
  4735.  
  4736. /*
  4737. g[k].start = function() {
  4738. this.stop();
  4739. this.D = true;
  4740. var a = requestAnimationFrame
  4741. , b = cancelAnimationFrame;
  4742. this.j = a.call(this.B, this.C)
  4743. }
  4744. ;
  4745. g[k].stop = function() {
  4746. if (this.isActive()) {
  4747. var a = requestAnimationFrame
  4748. , b = cancelAnimationFrame;
  4749. b.call(this.B, this.j)
  4750. }
  4751. this.j = null
  4752. }
  4753. */
  4754.  
  4755. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  4756.  
  4757. if (keyzo) {
  4758.  
  4759. k = keyzo;
  4760.  
  4761. const attrUpdateFn = g[k];
  4762. // console.log(5992, attrUpdateFn)
  4763. g['$$original$$' + k] = attrUpdateFn;
  4764. const zoTransform = async (a, c) => {
  4765.  
  4766. let transformType = '';
  4767. let transformValue = 0;
  4768. let transformUnit = '';
  4769. let transformTypeI = 0;
  4770.  
  4771. const aStyle = a.style;
  4772.  
  4773. if (c.length < 9) {
  4774.  
  4775. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  4776. let p = c.substring(7, c.length - 1);
  4777. let q = p.length >= 1 ? parseFloat(p) : -1;
  4778. if (q > -1e-5 && q < 1 + 1e-5) {
  4779. transformType = 'scaleX'
  4780. transformValue = q;
  4781. transformUnit = '';
  4782. transformTypeI = 1;
  4783. }
  4784. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  4785. let p = c.substring(11, c.length - 3);
  4786. let q = p.length >= 1 ? parseFloat(p) : NaN;
  4787. if (typeof q === 'number' && !isNaN(q)) {
  4788. transformType = 'translateX'
  4789. transformValue = q;
  4790. transformUnit = 'px';
  4791. transformTypeI = 2;
  4792. } else if (p === 'NaN') {
  4793. return;
  4794. }
  4795. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  4796. let p = c.substring(7, c.length - 1);
  4797. let q = p.length >= 1 ? parseFloat(p) : -1;
  4798. if (q > -1e-5 && q < 1 + 1e-5) {
  4799. transformType = 'scaleY'
  4800. transformValue = q;
  4801. transformUnit = '';
  4802. transformTypeI = 1;
  4803. }
  4804. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  4805. let p = c.substring(11, c.length - 3);
  4806. let q = p.length >= 1 ? parseFloat(p) : NaN;
  4807. if (typeof q === 'number' && !isNaN(q)) {
  4808. transformType = 'translateY'
  4809. transformValue = q;
  4810. transformUnit = 'px';
  4811. transformTypeI = 2;
  4812. } else if (p === 'NaN') {
  4813. return;
  4814. }
  4815. } else if (c.startsWith('scalex(') && c.includes('e-')) {
  4816. // scalex(1.252057684158767e-16)
  4817. // scalex(3.0393632069734948e-9)
  4818. let p = c.substring(7, c.length - 1);
  4819. let q = p.length >= 1 ? parseFloat(p) : -1;
  4820. if (q > -1e-5 && q < 1e-5) {
  4821. transformType = 'scaleX'
  4822. transformValue = 0;
  4823. transformUnit = '';
  4824. transformTypeI = 1;
  4825. }
  4826. } else if (c.startsWith('scaley(') && c.includes('e-')) {
  4827. let p = c.substring(7, c.length - 1);
  4828. let q = p.length >= 1 ? parseFloat(p) : -1;
  4829. if (q > -1e-5 && q < 1e-5) {
  4830. transformType = 'scaleY'
  4831. transformValue = 0;
  4832. transformUnit = '';
  4833. transformTypeI = 1;
  4834. }
  4835. }
  4836.  
  4837. if (transformTypeI === 1) {
  4838. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  4839. const vz = toFixed2(q, 3);
  4840. c = `${transformType}(${vz})`;
  4841. const cv = aStyle.transform;
  4842. if (c === cv) return;
  4843. aStyle.transform = c;
  4844. } else if (transformTypeI === 2) {
  4845. const q = transformValue;
  4846. const vz = toFixed2(q, 1);
  4847. c = `${transformType}(${vz}${transformUnit})`;
  4848. const cv = aStyle.transform;
  4849. if (c === cv) return;
  4850. aStyle.transform = c;
  4851. } else { // eg empty
  4852. const cv = aStyle.transform;
  4853. if (!c && !cv) return;
  4854. else if (c === cv) return;
  4855. aStyle.transform = c;
  4856. }
  4857.  
  4858. };
  4859.  
  4860. const elmTransformTemp = new WeakMap();
  4861. const elmPropTemps = {
  4862. 'display': new WeakMap(),
  4863. 'width': new WeakMap(),
  4864. 'height': new WeakMap(),
  4865. 'outlineWidth': new WeakMap(),
  4866. 'position': new WeakMap(),
  4867. 'padding': new WeakMap(),
  4868. "cssText": new WeakMap(),
  4869. "right": new WeakMap(),
  4870. "left": new WeakMap(),
  4871. "top": new WeakMap(),
  4872. "bottom": new WeakMap(),
  4873. "transitionDelay": new WeakMap(),
  4874. "marginLeft": new WeakMap(),
  4875. "marginTop": new WeakMap(),
  4876. "marginRight": new WeakMap(),
  4877. "marginBottom": new WeakMap(),
  4878. }
  4879.  
  4880. const ns5 = Symbol();
  4881. const nextModify = (a, c, m, f, immediate) => {
  4882. const a_ = a;
  4883. const m_ = m;
  4884. const noKey = !m_.has(a_);
  4885. if (immediate || noKey) {
  4886. m_.set(a_, ns5);
  4887. f(a_, c);
  4888. noKey && nextBrowserTick_(() => {
  4889. const d = m_.get(a_);
  4890. if (d === undefined) return;
  4891. m_.delete(a_);
  4892. if (d !== ns5) f(a_, d);
  4893. });
  4894. } else {
  4895. m_.set(a_, c);
  4896. }
  4897. };
  4898.  
  4899. const set66 = new Set();
  4900. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  4901.  
  4902. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  4903.  
  4904. // console.log(140000, a, b, c);
  4905. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement) {
  4906. const num = c;
  4907. c = `${num}`;
  4908. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  4909. }
  4910.  
  4911. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement) {
  4912.  
  4913. let elmPropTemp = null;
  4914.  
  4915. if (b === "transform") {
  4916.  
  4917. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  4918. return;
  4919.  
  4920. } else if (elmPropTemp = elmPropTemps[b]) {
  4921.  
  4922. // if (c.length > 5 && c.includes('.')) {
  4923. // console.log(123213, c)
  4924. // }
  4925.  
  4926. const b_ = b;
  4927. nextModify(a, c, elmPropTemp, (a, c) => {
  4928. const style = a.style;
  4929. const cv = style[b_];
  4930. if (!cv && !c) return;
  4931. if (cv === c) return;
  4932. style[b_] = c;
  4933. }, immediateChange);
  4934. return;
  4935.  
  4936. } else if (b === "outline-width") {
  4937.  
  4938. const b_ = 'outlineWidth';
  4939. elmPropTemp = elmPropTemps[b_];
  4940. nextModify(a, c, elmPropTemp, (a, c) => {
  4941. const style = a.style;
  4942. const cv = style[b_];
  4943. if (!cv && !c) return;
  4944. if (cv === c) return;
  4945. style[b_] = c;
  4946. }, immediateChange);
  4947. return;
  4948.  
  4949. } else if (b === 'maxWidth' || b === 'maxHeight') {
  4950. // I think these can be directly assigned.
  4951.  
  4952. const b_ = b;
  4953. const style = a.style;
  4954. const cv = style[b_];
  4955. if (!cv && !c) return;
  4956. if (cv === c) return;
  4957. style[b_] = c;
  4958. return;
  4959.  
  4960. } else {
  4961. // if(immediate && elmPropTemps[b]){
  4962. // console.log(5191, b)
  4963. // }
  4964. // caption-window
  4965. // margin-left max-height max-width font-family fill color font-size background white-space margin
  4966. // text-align background-color
  4967. // console.log(27304, a, b, c)
  4968. if (!set66.has(b)) {
  4969. set66.add(b);
  4970. nextBrowserTick_(() => {
  4971. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  4972. console.log(27304, a, b, c)
  4973. }
  4974. })
  4975. }
  4976. }
  4977.  
  4978. attrUpdateFn.call(this, a, b, c);
  4979. return;
  4980. } else if (typeof (b || 0) === 'object') {
  4981.  
  4982. // this is to fix caption positioning
  4983. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  4984. const immediate = (a.id || 0).length > 14;
  4985. for (const [k, v] of Object.entries(b)) {
  4986. modifiedFn.call(this, a, k, v, immediate);
  4987. }
  4988.  
  4989. } else {
  4990. console.log(27306, a, b, c);
  4991.  
  4992. attrUpdateFn.call(this, a, b, c);
  4993. return;
  4994. }
  4995.  
  4996. // console.log(130000, a, b, c);
  4997.  
  4998. };
  4999. g[k] = modifiedFn;
  5000.  
  5001.  
  5002. /*
  5003.  
  5004. g.zo = function(a, b, c) {
  5005. if ("string" === typeof b)
  5006. (b = yo(a, b)) && (a.style[b] = c);
  5007. else
  5008. for (var d in b) {
  5009. c = a;
  5010. var e = b[d]
  5011. , f = yo(c, d);
  5012. f && (c.style[f] = e)
  5013. }
  5014. }
  5015.  
  5016.  
  5017. */
  5018.  
  5019.  
  5020. }
  5021.  
  5022.  
  5023.  
  5024. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  5025.  
  5026. if (keyuG) {
  5027.  
  5028. k = keyuG;
  5029.  
  5030. const gk = g[k];
  5031. const gkp = gk.prototype;
  5032.  
  5033.  
  5034. /** @type { Map<string, WeakMap<any, any>> } */
  5035. const ntLogs = new Map();
  5036.  
  5037. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  5038.  
  5039. gkp.updateValue31 = gkp.updateValue;
  5040. gkp.updateValue = function (a, b) {
  5041. if (typeof a !== 'string') return this.updateValue31(a, b);
  5042.  
  5043. const element = this.element;
  5044. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  5045.  
  5046. let ntLog = ntLogs.get(a);
  5047. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  5048.  
  5049. let cache = ntLog.get(element);
  5050. if (cache && cache.value === b) {
  5051. return;
  5052. }
  5053. if (!cache) {
  5054. this.__oldValueByUpdateValue__ = null;
  5055. ntLog.set(element, cache = { value: b });
  5056. } else {
  5057. this.__oldValueByUpdateValue__ = cache.value;
  5058. cache.value = b;
  5059. }
  5060.  
  5061. return this.updateValue31(a, b);
  5062. }
  5063.  
  5064. /*
  5065. g.k.update = function(a) {
  5066. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  5067. c = c.value,
  5068. this.updateValue(c, a[c])
  5069. }
  5070. ;
  5071. g.k.updateValue = function(a, b) {
  5072. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  5073. }
  5074. */
  5075.  
  5076. }
  5077.  
  5078.  
  5079. }
  5080.  
  5081.  
  5082.  
  5083.  
  5084. })();
  5085.  
  5086.  
  5087. FIX_yt_player && FIX_SHORTCUTKEYS > 0 && (async () => {
  5088. // keyboard shortcut keys controller
  5089.  
  5090. const _yt_player = await _yt_player_observable.obtain();
  5091.  
  5092. if (!_yt_player || typeof _yt_player !== 'object') return;
  5093.  
  5094. keyboardController(_yt_player);
  5095.  
  5096. })();
  5097.  
  5098. FIX_yt_player && (async () => {
  5099. // timer scheduling
  5100.  
  5101. const _yt_player = await _yt_player_observable.obtain();
  5102.  
  5103. if (!_yt_player || typeof _yt_player !== 'object') return;
  5104.  
  5105. let keyZqQu = getZqQu(_yt_player);
  5106.  
  5107. if (!keyZqQu) return;
  5108.  
  5109. const g = _yt_player
  5110. let k = keyZqQu
  5111.  
  5112. const gk = g[k];
  5113. if (typeof gk !== 'function') return;
  5114. const gkp = gk.prototype;
  5115.  
  5116. const extractKeysZqQu = () => {
  5117.  
  5118.  
  5119. let _keyeC = '';
  5120. try {
  5121. gkp.stop.call(new Proxy({
  5122. isActive: () => { }
  5123. }, {
  5124. set(target, prop, value) {
  5125. if (value === 0) _keyeC = prop;
  5126. return true;
  5127. }
  5128. }));
  5129. } catch (e) { }
  5130. if (!_keyeC) return;
  5131. const keyeC = _keyeC;
  5132.  
  5133. let keyC = ''; // this.C = this.ST.bind(this)
  5134. let keyhj = ''; // 1000ms
  5135. try {
  5136. gkp.start.call(new Proxy({
  5137. stop: () => { },
  5138. [keyeC]: 0,
  5139. }, {
  5140. get(target, prop) {
  5141. if (prop in target) return target[prop];
  5142. if (!keyC) {
  5143. keyC = prop;
  5144. return null; // throw error
  5145. }
  5146. else if (!keyhj) {
  5147. keyhj = prop;
  5148. }
  5149.  
  5150. }
  5151. }));
  5152. } catch (e) {
  5153. if (!keyC || !keyhj) {
  5154. console.log(e)
  5155. }
  5156. }
  5157.  
  5158. if (!keyC || !keyhj) return;
  5159. let keyST = '';
  5160. let keyj = '';
  5161. let keyB = '';
  5162. let keyxa = '';
  5163.  
  5164. const possibleKs = new Set();
  5165.  
  5166. for (const [k, v] of Object.entries(gkp)) {
  5167. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  5168. continue;
  5169. }
  5170. if (typeof v === 'function') {
  5171. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  5172. if (m) {
  5173. keyST = k;
  5174. keyj = m[1];
  5175. keyB = m[2];
  5176. } else {
  5177. possibleKs.add(k);
  5178. }
  5179. }
  5180. }
  5181.  
  5182. if (!keyST || !keyj || !keyB) return;
  5183.  
  5184. for (const k of possibleKs) {
  5185. if (k === keyST || k === keyj || k === keyB) {
  5186. continue;
  5187. }
  5188. const v = gkp[k];
  5189. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  5190. keyxa = k;
  5191. }
  5192. }
  5193.  
  5194. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  5195.  
  5196. }
  5197.  
  5198. const keys = extractKeysZqQu();
  5199. if (!keys || !keys.length) return;
  5200. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  5201.  
  5202. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  5203.  
  5204. let disposeKeys = null;
  5205.  
  5206. gkp[keyxa] = function () {
  5207. // dispose
  5208. if (!disposeKeys) {
  5209. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  5210. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  5211. const t = typeof this[key];
  5212. return t === 'undefined' || t === 'object'
  5213. }
  5214. return false;
  5215. });
  5216. }
  5217. for (const key of disposeKeys) {
  5218. const v = this[key];
  5219. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  5220. }
  5221. if (this[keyeC] > 0) this.stop();
  5222. this[keyj] = null;
  5223. this[keyB] = null;
  5224. };
  5225.  
  5226. gkp.start = function (a) {
  5227. if (this[keyeC] > 0) this.stop();
  5228. const delay = void 0 !== a ? a : this[keyhj];
  5229. this[keyeC] = window.setTimeout(this[keyC], delay);
  5230. };
  5231. gkp.stop = function () {
  5232. if (this[keyeC] > 0) {
  5233. window.clearTimeout(this[keyeC]);
  5234. this[keyeC] = 0;
  5235. }
  5236. };
  5237.  
  5238. gkp.isActive = function () {
  5239. return this[keyeC] > 0;
  5240. };
  5241.  
  5242. gkp[keyST] = function () {
  5243. this.stop(); // this[keyeC] = 0;
  5244. const fn = this[keyj];
  5245. const obj = this[keyB];
  5246. let skip = false;
  5247. if (!fn) skip = true;
  5248. else if (IGNORE_bufferhealth_CHECK && obj) {
  5249. let m;
  5250. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  5251. if (m.has("bufferhealth")) skip = true;
  5252. }
  5253. }
  5254. if (!skip) {
  5255. fn.call(obj);
  5256. }
  5257. };
  5258.  
  5259.  
  5260.  
  5261.  
  5262. /*
  5263.  
  5264. g.k.eC = 0;
  5265. g.k.xa = function() {
  5266. g.Qu.Vf.xa.call(this);
  5267. this.stop();
  5268. delete this.j;
  5269. delete this.B
  5270. }
  5271. ;
  5272. g.k.start = function(a) {
  5273. this.stop();
  5274. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  5275. }
  5276. ;
  5277. g.k.stop = function() {
  5278. this.isActive() && g.Sa.clearTimeout(this.eC);
  5279. this.eC = 0
  5280. }
  5281. ;
  5282. g.k.isActive = function() {
  5283. return 0 != this.eC
  5284. }
  5285. ;
  5286. g.k.ST = function() {
  5287. this.eC = 0;
  5288. this.j && this.j.call(this.B)
  5289. }
  5290. ;
  5291. */
  5292.  
  5293.  
  5294.  
  5295.  
  5296. })();
  5297.  
  5298. FIX_Animation_n_timeline && (async () => {
  5299.  
  5300. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  5301.  
  5302. if (!timeline || !Animation) return;
  5303.  
  5304. const aniProto = Animation.prototype;
  5305. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  5306.  
  5307. const getXroto = (x) => {
  5308. try {
  5309. return x.__proto__;
  5310. } catch (e) { }
  5311. return null;
  5312. }
  5313. const timProto = getXroto(timeline);
  5314. if (!timProto) return;
  5315. if (
  5316. (
  5317. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  5318. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  5319. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  5320. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  5321. )
  5322.  
  5323. ) {
  5324.  
  5325. timProto.nofCQ = 1;
  5326. aniProto.nofYH = 1;
  5327.  
  5328. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  5329.  
  5330.  
  5331. /*
  5332. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  5333. return c._updatePromises();
  5334. });
  5335. */
  5336.  
  5337. const p = Array.prototype.filter;
  5338.  
  5339. let res = null;
  5340. Array.prototype.filter = function () {
  5341.  
  5342. res = this;
  5343. return this;
  5344.  
  5345. };
  5346.  
  5347. _updateAnimationsPromises.call({});
  5348.  
  5349. Array.prototype.filter = p;
  5350.  
  5351. if (res && typeof res.length === 'number') {
  5352. /** @type {any[]} */
  5353. const _res = res;
  5354. return _res;
  5355. }
  5356.  
  5357.  
  5358. return null;
  5359.  
  5360.  
  5361.  
  5362.  
  5363. })(timProto._updateAnimationsPromises);
  5364.  
  5365. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  5366.  
  5367. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  5368.  
  5369. aniProto._updatePromises31 = aniProto._updatePromises;
  5370.  
  5371. /*
  5372. aniProto._updatePromises = function(){
  5373. console.log('eff',this._oldPlayState, this.playState)
  5374. return this._updatePromises31.apply(this, arguments)
  5375. }
  5376. */
  5377.  
  5378. aniProto._updatePromises = function () {
  5379. var oldPlayState = this._oldPlayState;
  5380. var newPlayState = this.playState;
  5381. // console.log('ett', oldPlayState, newPlayState)
  5382. if (newPlayState !== oldPlayState) {
  5383. this._oldPlayState = newPlayState;
  5384. if (this._readyPromise) {
  5385. if ("idle" == newPlayState) {
  5386. this._rejectReadyPromise();
  5387. this._readyPromise = void 0;
  5388. } else if ("pending" == oldPlayState) {
  5389. this._resolveReadyPromise();
  5390. } else if ("pending" == newPlayState) {
  5391. this._readyPromise = void 0;
  5392. }
  5393. }
  5394. if (this._finishedPromise) {
  5395. if ("idle" == newPlayState) {
  5396. this._rejectFinishedPromise();
  5397. this._finishedPromise = void 0;
  5398. } else if ("finished" == newPlayState) {
  5399. this._resolveFinishedPromise();
  5400. } else if ("finished" == oldPlayState) {
  5401. this._finishedPromise = void 0;
  5402. }
  5403. }
  5404. }
  5405. return this._readyPromise || this._finishedPromise;
  5406. };
  5407.  
  5408.  
  5409. let restartWebAnimationsNextTickFlag = false;
  5410.  
  5411. const looperMethodT = () => {
  5412.  
  5413. const runnerFn = (hRes) => {
  5414. var b = timeline;
  5415. b.currentTime = hRes;
  5416. b._discardAnimations();
  5417. if (0 == b._animations.length) {
  5418. restartWebAnimationsNextTickFlag = false;
  5419. } else {
  5420. getRafPromise().then(runnerFn);
  5421. }
  5422. }
  5423.  
  5424. const restartWebAnimationsNextTick = () => {
  5425. if (!restartWebAnimationsNextTickFlag) {
  5426. restartWebAnimationsNextTickFlag = true;
  5427. getRafPromise().then(runnerFn);
  5428. }
  5429. }
  5430.  
  5431. return { restartWebAnimationsNextTick }
  5432. };
  5433.  
  5434.  
  5435. const looperMethodN = () => {
  5436.  
  5437. const acs = document.createElement('a-f');
  5438. acs.id = 'a-f';
  5439.  
  5440. if (!document.getElementById('afscript')) {
  5441. const style = document.createElement('style');
  5442. style.id = 'afscript';
  5443. style.textContent = `
  5444. @keyFrames aF1 {
  5445. 0% {
  5446. order: 0;
  5447. }
  5448. 100% {
  5449. order: 1;
  5450. }
  5451. }
  5452. #a-f[id] {
  5453. visibility: collapse !important;
  5454. position: fixed !important;
  5455. display: block !important;
  5456. top: -100px !important;
  5457. left: -100px !important;
  5458. margin:0 !important;
  5459. padding:0 !important;
  5460. outline:0 !important;
  5461. border:0 !important;
  5462. z-index:-1 !important;
  5463. width: 0px !important;
  5464. height: 0px !important;
  5465. contain: strict !important;
  5466. pointer-events: none !important;
  5467. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  5468. }
  5469. `;
  5470. (document.head || document.documentElement).appendChild(style);
  5471. }
  5472.  
  5473. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  5474.  
  5475. const _onanimationiteration = function (evt) {
  5476. const hRes = evt.timeStamp;
  5477. var b = timeline;
  5478. b.currentTime = hRes;
  5479. b._discardAnimations();
  5480. if (0 == b._animations.length) {
  5481. restartWebAnimationsNextTickFlag = false;
  5482. acs.onanimationiteration = null;
  5483. } else {
  5484. acs.onanimationiteration = _onanimationiteration;
  5485. }
  5486.  
  5487. }
  5488.  
  5489.  
  5490.  
  5491. const restartWebAnimationsNextTick = () => {
  5492. if (!restartWebAnimationsNextTickFlag) {
  5493. restartWebAnimationsNextTickFlag = true;
  5494. acs.onanimationiteration = _onanimationiteration;
  5495.  
  5496. }
  5497. }
  5498.  
  5499. return { restartWebAnimationsNextTick }
  5500. };
  5501.  
  5502.  
  5503.  
  5504. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  5505.  
  5506.  
  5507. // console.log(571, timProto);
  5508. timProto._play = function (c) {
  5509. c = new Animation(c, this);
  5510. this._animations.push(c);
  5511. restartWebAnimationsNextTick();
  5512. c._updatePromises();
  5513. c._animation.play();
  5514. c._updatePromises();
  5515. return c
  5516. }
  5517.  
  5518. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  5519. originalAnimationsWithPromises.length = 0;
  5520. originalAnimationsWithPromises.push = null;
  5521. originalAnimationsWithPromises.splice = null;
  5522. originalAnimationsWithPromises.slice = null;
  5523. originalAnimationsWithPromises.indexOf = null;
  5524. originalAnimationsWithPromises.unshift = null;
  5525. originalAnimationsWithPromises.shift = null;
  5526. originalAnimationsWithPromises.pop = null;
  5527. originalAnimationsWithPromises.filter = null;
  5528. originalAnimationsWithPromises.forEach = null;
  5529. originalAnimationsWithPromises.map = null;
  5530.  
  5531.  
  5532. const _updateAnimationsPromises = () => {
  5533. animationsWithPromisesMap.forEach(c => {
  5534. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  5535. });
  5536. /*
  5537. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  5538. return c._updatePromises();
  5539. });
  5540. */
  5541. }
  5542.  
  5543. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  5544.  
  5545. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  5546.  
  5547. delete timProto._updateAnimationsPromises;
  5548. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  5549. get() {
  5550. if (animationsWithPromisesMap.size === 0) return nilFn;
  5551. return _updateAnimationsPromises;
  5552. },
  5553. set(nv) {
  5554. delete this._updateAnimationsPromises;
  5555. this._updateAnimationsPromises = nv;
  5556. },
  5557. enumerable: true,
  5558. configurable: true,
  5559. });
  5560.  
  5561.  
  5562. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  5563. aniProto.__finished_native_get__ = pdFinished.get;
  5564. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  5565.  
  5566.  
  5567. Object.defineProperty(aniProto, 'finished', {
  5568. get() {
  5569. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  5570. this._finishedPromise = new Promise((resolve, reject) => {
  5571. this._resolveFinishedPromise = function () {
  5572. resolve(this)
  5573. };
  5574. this._rejectFinishedPromise = function () {
  5575. reject({
  5576. type: DOMException.ABORT_ERR,
  5577. name: "AbortError"
  5578. })
  5579. };
  5580. }),
  5581. "finished" == this.playState && this._resolveFinishedPromise());
  5582. return this._finishedPromise
  5583. },
  5584. set: undefined,
  5585. enumerable: true,
  5586. configurable: true
  5587. });
  5588.  
  5589. }
  5590.  
  5591.  
  5592.  
  5593. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  5594. aniProto.__ready_native_get__ = pdReady.get;
  5595. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  5596.  
  5597. Object.defineProperty(aniProto, 'ready', {
  5598. get() {
  5599. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  5600. this._readyPromise = new Promise((resolve, reject) => {
  5601. this._resolveReadyPromise = function () {
  5602. resolve(this)
  5603. };
  5604. this._rejectReadyPromise = function () {
  5605. reject({
  5606. type: DOMException.ABORT_ERR,
  5607. name: "AbortError"
  5608. })
  5609. };
  5610. }),
  5611. "pending" !== this.playState && this._resolveReadyPromise());
  5612. return this._readyPromise
  5613. },
  5614. set: undefined,
  5615. enumerable: true,
  5616. configurable: true
  5617. });
  5618.  
  5619. }
  5620.  
  5621.  
  5622. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  5623.  
  5624. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  5625. const _rebuildUnderlyingAnimation = function () {
  5626. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  5627. this.effect && this.effect._onsample && (this.effect._onsample = null);
  5628. return this._rebuildUnderlyingAnimation21();
  5629. }
  5630. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  5631. // delete aniProto._rebuildUnderlyingAnimation;
  5632. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  5633. // get() {
  5634. // if (isNaN(this._sequenceNumber)) return nilFn;
  5635. // return this._rebuildUnderlyingAnimation21;
  5636. // },
  5637. // set(nv) {
  5638. // delete this._rebuildUnderlyingAnimation;
  5639. // this._rebuildUnderlyingAnimation = nv;
  5640. // },
  5641. // enumerable: true,
  5642. // configurable: true
  5643. // });
  5644. }
  5645.  
  5646.  
  5647. /*
  5648.  
  5649.  
  5650. function f(c) {
  5651. var b = v.timeline;
  5652. b.currentTime = c;
  5653. b._discardAnimations();
  5654. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  5655. }
  5656. var h = window.requestAnimationFrame;
  5657. window.requestAnimationFrame = function(c) {
  5658. return h(function(b) {
  5659. v.timeline._updateAnimationsPromises();
  5660. c(b);
  5661. v.timeline._updateAnimationsPromises()
  5662. })
  5663. }
  5664. ;
  5665. v.AnimationTimeline = function() {
  5666. this._animations = [];
  5667. this.currentTime = void 0
  5668. }
  5669. ;
  5670. v.AnimationTimeline.prototype = {
  5671. getAnimations: function() {
  5672. this._discardAnimations();
  5673. return this._animations.slice()
  5674. },
  5675. _updateAnimationsPromises: function() {
  5676. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  5677. return c._updatePromises()
  5678. })
  5679. },
  5680. _discardAnimations: function() {
  5681. this._updateAnimationsPromises();
  5682. this._animations = this._animations.filter(function(c) {
  5683. return "finished" != c.playState && "idle" != c.playState
  5684. })
  5685. },
  5686. _play: function(c) {
  5687. c = new v.Animation(c,this);
  5688. this._animations.push(c);
  5689. v.restartWebAnimationsNextTick();
  5690. c._updatePromises();
  5691. c._animation.play();
  5692. c._updatePromises();
  5693. return c
  5694. },
  5695. play: function(c) {
  5696. c && c.remove();
  5697. return this._play(c)
  5698. }
  5699. };
  5700. var d = !1;
  5701. v.restartWebAnimationsNextTick = function() {
  5702. d || (d = !0,
  5703. requestAnimationFrame(f))
  5704. }
  5705. ;
  5706. var a = new v.AnimationTimeline;
  5707. v.timeline = a;
  5708. try {
  5709. Object.defineProperty(window.document, "timeline", {
  5710. configurable: !0,
  5711. get: function() {
  5712. return a
  5713. }
  5714. })
  5715. } catch (c) {}
  5716. try {
  5717. window.document.timeline = a
  5718. } catch (c) {}
  5719.  
  5720. */
  5721.  
  5722.  
  5723.  
  5724. /*
  5725.  
  5726. var g = window.getComputedStyle;
  5727. Object.defineProperty(window, "getComputedStyle", {
  5728. configurable: !0,
  5729. enumerable: !0,
  5730. value: function() {
  5731. v.timeline._updateAnimationsPromises();
  5732. var e = g.apply(this, arguments);
  5733. h() && (e = g.apply(this, arguments));
  5734. v.timeline._updateAnimationsPromises();
  5735. return e
  5736. }
  5737. });
  5738.  
  5739. */
  5740.  
  5741.  
  5742.  
  5743.  
  5744. }
  5745.  
  5746.  
  5747.  
  5748.  
  5749. })();
  5750.  
  5751. !isUrlInEmbed && Promise.resolve().then(() => {
  5752.  
  5753. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  5754.  
  5755.  
  5756.  
  5757. class LimitedSizeSet extends Set {
  5758. constructor(n) {
  5759. super();
  5760.  
  5761. this.limit = n;
  5762. }
  5763.  
  5764. add(key) {
  5765. if (!super.has(key)) {
  5766. super.add(key); // Set the key with a dummy value (true)
  5767. while (super.size > this.limit) {
  5768. const firstKey = super.values().next().value; // Get the first (oldest) key
  5769. super.delete(firstKey); // Delete the oldest key
  5770. }
  5771. }
  5772. }
  5773.  
  5774. removeAdd(key) {
  5775. super.delete(key);
  5776. super.add(key);
  5777. }
  5778.  
  5779. }
  5780.  
  5781. // const wk3 = new WeakMap();
  5782.  
  5783. // let mtxVideoId = '';
  5784. // let aje3 = [];
  5785. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  5786. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  5787. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  5788. let mtzCount = 0; // the key keeps unchanged
  5789. // let mjtNextMainKey = '';
  5790. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  5791. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  5792. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  5793. // let allowNoDelay322=false;
  5794. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  5795.  
  5796. let mpKey22 = ''; // last success continutation key & url pair
  5797. let mpUrl22 = ''; // last success continutation key & url pair
  5798. let mpKey21 = ''; // latest requested continutation key & url pair
  5799. let mpUrl21 = ''; // latest requested continutation key & url pair
  5800.  
  5801.  
  5802. async function sha1Hex(message) {
  5803. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  5804. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  5805. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  5806. const hashHex = hashArray
  5807. .map((b) => b.toString(16).padStart(2, "0"))
  5808. .join(""); // convert bytes to hex string
  5809. return hashHex;
  5810. }
  5811.  
  5812. async function continuationLog(a, ...args) {
  5813. let b = a;
  5814. try {
  5815. if (advanceLogging) b = await sha1Hex(a);
  5816. let c = args.map(e => {
  5817. return e === a ? b : e
  5818. });
  5819. console.log(...c)
  5820. } catch (e) { console.warn(e) }
  5821. }
  5822.  
  5823. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  5824.  
  5825.  
  5826. if (mfvContinuationRecorded.length > 0) {
  5827. for (const [e, d] of mfvContinuationRecorded) {
  5828. mfyContinuationIgnored.removeAdd(e);
  5829. }
  5830. toClearRecorded && mfvContinuationRecorded.clear();
  5831. }
  5832.  
  5833. }
  5834.  
  5835. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  5836.  
  5837. const tmProto = taskMgr.constructor.prototype;
  5838. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  5839.  
  5840. if (!tmProto.addJob714) {
  5841.  
  5842. tmProto.addJob714 = tmProto.addJob;
  5843.  
  5844. tmProto.addJob = function (a, b, c) {
  5845. const jobId = this.addJob714(a, b, c);
  5846. if (jobId > 0) {
  5847. // const ez = wk3.get(this);
  5848. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  5849. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  5850.  
  5851. this.__lastJobId863__ = jobId;
  5852. }
  5853. return jobId;
  5854. }
  5855.  
  5856. }
  5857.  
  5858. if (!tmProto.cancelJob714) {
  5859.  
  5860. tmProto.cancelJob714 = tmProto.cancelJob;
  5861.  
  5862. tmProto.cancelJob = function (a) {
  5863. const res = this.cancelJob714(a);
  5864. // if (a > 0) {
  5865. // for (const e of aje3) {
  5866. // if (e.jobId === a) e.cancelled = true;
  5867. // }
  5868. // }
  5869. return res;
  5870. }
  5871.  
  5872. }
  5873.  
  5874. }
  5875. }
  5876.  
  5877.  
  5878. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order;
  5879.  
  5880.  
  5881. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  5882. let dummy;
  5883. let cProto;
  5884. // let mc = 4;
  5885. // dummy = await observablePromise(() => {
  5886. // const r = document.querySelector('ytd-video-primary-info-renderer');
  5887. // if (!r) return;
  5888. // let cProto = insp(r).constructor.prototype;
  5889. // if (cProto.fetchUpdatedMetadata) return r;
  5890. // if (--mc < 0) return -1;
  5891. // return null;
  5892. // }).obtain();
  5893. dummy = document.createElement('ytd-video-primary-info-renderer');
  5894. if (!(dummy instanceof Element)) return;
  5895. // console.log(5022, dummy)
  5896. cProto = insp(dummy).constructor.prototype;
  5897.  
  5898. cProto.__getEmittorTaskMgr859__ = function () {
  5899. let taskMgr_ = null;
  5900. try {
  5901. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  5902. } catch (e) { }
  5903. return taskMgr_;
  5904. }
  5905. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  5906. // console.log(1234, cProto, cProto.is)
  5907. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  5908.  
  5909. let c_;
  5910. cProto.fetchUpdatedMetadata718 = function (a) {
  5911. // delay or immediate call the actual fetchUpdatedMetadata
  5912.  
  5913. let doImmediately = false;
  5914. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  5915.  
  5916. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  5917.  
  5918. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  5919.  
  5920. doImmediately = true;
  5921.  
  5922. }
  5923.  
  5924. if (mbCId322) {
  5925. clearTimeout(mbCId322);
  5926. mbCId322 = 0;
  5927. }
  5928.  
  5929. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  5930.  
  5931. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  5932.  
  5933. mbCId322 = setTimeout(() => {
  5934. this.fetchUpdatedMetadata717(a);
  5935. }, delay);
  5936.  
  5937. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  5938.  
  5939. }
  5940.  
  5941. cProto.fetchUpdatedMetadata = function (a) {
  5942.  
  5943. if (!pageSetupState) {
  5944. if (c_) clearTimeout(c_);
  5945. c_ = setTimeout(() => {
  5946. this.fetchUpdatedMetadata718(a);
  5947. }, 300);
  5948. return;
  5949. }
  5950.  
  5951. // pageSetupState == 0
  5952.  
  5953. try {
  5954.  
  5955. mbDelayBelowNCalls++;
  5956.  
  5957. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  5958. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  5959. }
  5960.  
  5961. // console.log('fum377', a)
  5962. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  5963. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  5964. return;
  5965. }
  5966.  
  5967. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  5968. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  5969. mjtLockPreviousKey = mjtRecordedPrevKey;
  5970. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  5971. }
  5972. // mjtNextMainKey = true;
  5973. mtzlastAllowedContinuation = '';
  5974. mtzCount = 0;
  5975. // allowNoDelay322 = false;
  5976. // fetch new metadata, cancel all previous continuations
  5977. copyPreviousContiuationToIgnored374(true);
  5978. } else if (typeof a === 'string') {
  5979. const videoPlayingId = videoPlayingY.videoId;
  5980.  
  5981. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  5982.  
  5983. let update21 = !!pageSetupVideoId;
  5984. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  5985. update21 = true;
  5986. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  5987. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  5988. return;
  5989. }
  5990. if (update21) {
  5991. mpKey21 = a;
  5992. mpUrl21 = pageSetupVideoId || videoPlayingId;
  5993. }
  5994.  
  5995. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  5996. }
  5997. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  5998. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  5999. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  6000. return this.fetchUpdatedMetadata718(a);
  6001.  
  6002. } catch (e) {
  6003. console.log('Code Error in fetchUpdatedMetadata', e);
  6004. }
  6005. return this.fetchUpdatedMetadata717(a)
  6006. }
  6007. }
  6008.  
  6009.  
  6010. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  6011. // console.log(1234, cProto, cProto.is)
  6012. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  6013. let mJob = null;
  6014.  
  6015. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  6016.  
  6017. try {
  6018.  
  6019. if (arguments.length > 0) {
  6020. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  6021. }
  6022. // mfy = mfv;
  6023.  
  6024. // mjtNextMainKey = '';
  6025. mtzlastAllowedContinuation = '';
  6026. mtzCount = 0;
  6027. if (mbCId322) {
  6028. clearTimeout(mbCId322);
  6029. mbCId322 = 0;
  6030. }
  6031. mbDelayBelowNCalls = 0;
  6032. // allowNoDelay322 = false;
  6033. copyPreviousContiuationToIgnored374(true);
  6034.  
  6035. const taskMgr = this.__getEmittorTaskMgr859__();
  6036. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  6037. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  6038. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  6039. }
  6040.  
  6041. // prevent depulicated schedule job by clearing previous JobId
  6042. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  6043.  
  6044. let res;
  6045.  
  6046. if (mJob) {
  6047. const job = mJob;
  6048. mJob = null;
  6049. console.log('cancelJob', job)
  6050. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  6051. // p.cancelJob(a,b);
  6052. }
  6053.  
  6054. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  6055.  
  6056. let pza = taskMgr.__lastJobId863__;
  6057. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  6058. let pzb = taskMgr.__lastJobId863__
  6059. if (pza !== pzb) {
  6060. mJob = pzb; // set [Interval Meta Update] jobId
  6061. }
  6062.  
  6063. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  6064. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  6065. // } else {
  6066. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  6067. // }
  6068.  
  6069. return res;
  6070.  
  6071. } else {
  6072. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  6073. }
  6074.  
  6075. } catch (e) {
  6076. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  6077. }
  6078.  
  6079.  
  6080. return this.scheduleInitialUpdatedMetadataRequest717();
  6081. }
  6082. }
  6083.  
  6084.  
  6085. });
  6086.  
  6087. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  6088. let dummy;
  6089. let cProto;
  6090. dummy = ytAppDom;
  6091. if (!(dummy instanceof Element)) return;
  6092. cProto = insp(dummy).constructor.prototype;
  6093. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  6094. // console.log(1234, cProto, cProto.is);
  6095. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  6096. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  6097. // console.log(123401, arguments);
  6098. // return this.handleServiceRequest717_(a, b, c, d);
  6099. // }
  6100.  
  6101. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  6102.  
  6103. // cProto.handleServiceRequest_ = function(a,b,c,d){
  6104. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  6105. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  6106. // console.log('mfv', c.continuation);
  6107. // mfv.add( c.continuation);
  6108. // }
  6109. // return this.handleServiceRequest717_(a,b,c,d);
  6110. // }
  6111.  
  6112. function extraArguments322(a, b, c) {
  6113. let is = (a || 0).is;
  6114. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  6115. let continuation = (c || 0).continuation;
  6116. if (typeof is !== 'string') is = null;
  6117. if (typeof videoId !== 'string') videoId = null;
  6118. if (typeof continuation !== 'string') continuation = null;
  6119. return { is, videoId, continuation };
  6120. }
  6121.  
  6122. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  6123. cProto.sendServiceAjax_ = function (a, b, c, d) {
  6124.  
  6125. // console.log(8001)
  6126. try {
  6127.  
  6128. const { is, videoId, continuation } = extraArguments322(a, b, c);
  6129.  
  6130. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  6131. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  6132. }
  6133.  
  6134. if (pageSetupVideoId && videoId && continuation) {
  6135. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  6136. mfyContinuationIgnored.removeAdd(continuation);
  6137. mfvContinuationRecorded.delete(continuation);
  6138. return;
  6139. }
  6140. }
  6141.  
  6142. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  6143. copyPreviousContiuationToIgnored374(false);
  6144. mfyContinuationIgnored.delete(continuation);
  6145. mfvContinuationRecorded.removeAdd(continuation);
  6146. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  6147. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  6148. mjtLockPreviousKey = '';
  6149. }
  6150. // if (mjtNextMainKey === continuation) {
  6151. // copyPreviousContiuationToIgnored(false);
  6152. // mfyContinuationIgnored.delete(continuation);
  6153. // mfvContinuationRecorded.add(continuation);
  6154. // }
  6155.  
  6156.  
  6157. if (mfyContinuationIgnored && continuation) {
  6158. if (mfyContinuationIgnored.has(continuation)) {
  6159. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  6160. return;
  6161. }
  6162. }
  6163.  
  6164. // console.log(59902, a?.is, b,c,d)
  6165. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  6166. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  6167. // console.log('mfv377', continuation);
  6168. mfvContinuationRecorded.add(continuation);
  6169. }
  6170.  
  6171. // if (videoId) {
  6172. // if (!pageSetupVideoId) return; // ignore page not ready
  6173. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  6174. // if (videoId !== pageSetupVideoId) {
  6175. // return;
  6176. // }
  6177. // }
  6178.  
  6179. } catch (e) {
  6180. console.log('Coding Error in sendServiceAjax_', e)
  6181. }
  6182. // console.log(8002)
  6183. // console.log(123402, arguments);
  6184. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  6185.  
  6186. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  6187. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  6188. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  6189. // get(target, prop, receiver){
  6190. // console.log('xxs99', target.videoId, mtx)
  6191. // if(prop ==='kdkw33') return 1;
  6192. // console.log(3322, prop, target)
  6193. // if(prop === 'initialDelayMs') {
  6194. // throw new Error("ABCC");
  6195. // }
  6196. // return target[prop];
  6197. // },
  6198. // set(target, prop, value, receiver){
  6199.  
  6200. // if(prop ==='kdkw33') return true;
  6201. // target[prop]=value;
  6202. // return true;
  6203. // }
  6204. // });
  6205. // }
  6206. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  6207. return this.sendServiceAjax717_(a, b, c, d);
  6208. }
  6209. }
  6210.  
  6211. function delayClearOtherKeys(lztContinuation) {
  6212. // // schedule delayed removal if mfyContinuationIgnored is not empty
  6213. // getRafPromise().then(() => {
  6214. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  6215. // // foreground page only
  6216.  
  6217. // });
  6218.  
  6219.  
  6220. if (lztContinuation !== mtzlastAllowedContinuation) return;
  6221. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  6222. if (!mfyContinuationIgnored.size) return;
  6223. if (mfyContinuationIgnored.size > 1) {
  6224. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  6225. }
  6226. mfyContinuationIgnored.forEach((value, key) => {
  6227. if (key !== lztContinuation) {
  6228. mfyContinuationIgnored.delete(key);
  6229. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  6230. }
  6231. });
  6232.  
  6233. }
  6234. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  6235. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  6236. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  6237.  
  6238. // console.log(8003)
  6239. try {
  6240.  
  6241.  
  6242. const { is, videoId, continuation } = extraArguments322(b, c, d);
  6243.  
  6244. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  6245. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  6246. }
  6247.  
  6248. if (pageSetupVideoId && videoId && continuation) {
  6249. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  6250. mfyContinuationIgnored.removeAdd(continuation);
  6251. mfvContinuationRecorded.delete(continuation);
  6252. return;
  6253. }
  6254. }
  6255.  
  6256. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  6257. copyPreviousContiuationToIgnored374(false);
  6258. mfyContinuationIgnored.delete(continuation);
  6259. mfvContinuationRecorded.removeAdd(continuation);
  6260. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  6261. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  6262. mjtLockPreviousKey = '';
  6263. }
  6264.  
  6265. // if (mjtNextMainKey === continuation) {
  6266. // copyPreviousContiuationToIgnored(false);
  6267. // mfyContinuationIgnored.delete(continuation);
  6268. // mfvContinuationRecorded.add(continuation);
  6269. // }
  6270.  
  6271. const lztContinuation = continuation;
  6272.  
  6273. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  6274. if (mfyContinuationIgnored.has(lztContinuation)) {
  6275. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  6276. return;
  6277. }
  6278. }
  6279.  
  6280. // if (videoId) {
  6281. // if (!pageSetupVideoId) return; // ignore page not ready
  6282. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  6283. // if (videoId !== pageSetupVideoId) {
  6284. // return;
  6285. // }
  6286. // }
  6287.  
  6288. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  6289. mtzlastAllowedContinuation = lztContinuation;
  6290. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  6291.  
  6292. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  6293. mjtRecordedPrevKey = lztContinuation;
  6294. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  6295. // if (mfyContinuationIgnored.size > 0) {
  6296. // delayClearOtherKeys(lztContinuation);
  6297. // }
  6298. mtzCount = 0;
  6299. // allowNoDelay322 = false;
  6300. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  6301. // repeated
  6302. if (mtzCount > 1e9) mtzCount = 1e4;
  6303. ++mtzCount;
  6304. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  6305.  
  6306. // if (mtzCount >= 3) allowNoDelay322 = true;
  6307. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  6308. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  6309. }
  6310. if (mtzCount === 5) {
  6311. mfvContinuationRecorded.clear();
  6312. mfvContinuationRecorded.add(lztContinuation);
  6313. }
  6314.  
  6315. }
  6316.  
  6317. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  6318. mpKey22 = lztContinuation;
  6319. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  6320. }
  6321.  
  6322. if (mbCId322) {
  6323. clearTimeout(mbCId322);
  6324. mbCId322 = 0;
  6325. }
  6326. } catch (e) {
  6327. console.log('Coding Error in getCancellableNetworkPromise_', e)
  6328. }
  6329.  
  6330. // console.log(8004)
  6331. // console.log(123403, arguments);
  6332. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  6333.  
  6334. // console.log(5163, a?.is,b,c,d,e);
  6335. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  6336. }
  6337. }
  6338. });
  6339.  
  6340. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  6341.  
  6342.  
  6343. FIX_ytdExpander_childrenChanged && whenCEDefined('ytd-expander').then(() => {
  6344.  
  6345. let dummy;
  6346. let cProto;
  6347.  
  6348. dummy = document.createElement('ytd-expander');
  6349. cProto = insp(dummy).constructor.prototype;
  6350.  
  6351. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  6352.  
  6353. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  6354. cProto.childrenChanged14 = cProto.childrenChanged;
  6355.  
  6356. cProto.initChildrenObserver = function () {
  6357. var a = this;
  6358. this.observer = new MutationObserver(function () {
  6359. a.childrenChanged()
  6360. }
  6361. );
  6362. this.observer.observe(this.content, {
  6363. subtree: !0,
  6364. childList: !0,
  6365. attributes: !0,
  6366. characterData: !0
  6367. });
  6368. this.childrenChanged()
  6369. }
  6370. ;
  6371. cProto.childrenChanged = function () {
  6372. if (this.alwaysToggleable) {
  6373. this.canToggle = this.alwaysToggleable;
  6374. } else if (!this.canToggleJobId) {
  6375. this.canToggleJobId = 1;
  6376. getRafPromise().then(() => {
  6377. this.canToggleJobId = 0;
  6378. this.calculateCanCollapse()
  6379. })
  6380. }
  6381. }
  6382.  
  6383. // console.log(cProto.initChildrenObserver)
  6384. console.debug('ytd-expander-fix-childrenChanged');
  6385.  
  6386. }
  6387.  
  6388. });
  6389.  
  6390.  
  6391. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  6392.  
  6393. let dummy;
  6394. let cProto;
  6395. dummy = document.createElement('paper-ripple');
  6396. cProto = insp(dummy).constructor.prototype;
  6397.  
  6398. if (fnIntegrity(cProto.animate, '0.74.5')) {
  6399.  
  6400.  
  6401. cProto.animate34 = cProto.animate;
  6402. cProto.animate = function () {
  6403. if (this._animating) {
  6404. var a;
  6405. const ripples = this.ripples;
  6406. for (a = 0; a < ripples.length; ++a) {
  6407. var b = ripples[a];
  6408. b.draw();
  6409. this.$.background.style.opacity = b.outerOpacity;
  6410. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  6411. }
  6412. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  6413. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  6414. getRafPromise().then(this._boundAnimate38);
  6415. } else {
  6416. this.onAnimationComplete()
  6417. }
  6418. }
  6419. }
  6420.  
  6421. console.debug('FIX_paper_ripple_animate')
  6422.  
  6423. // console.log(cProto.animate)
  6424.  
  6425. }
  6426.  
  6427. });
  6428.  
  6429. if (FIX_doIdomRender) {
  6430.  
  6431. const xsetTimeout = function (f, d) {
  6432. if (xsetTimeout.m511 === 1 && !d) {
  6433. xsetTimeout.m511 = 2;
  6434. getRafPromise().then(f);
  6435. } else {
  6436. return setTimeout.apply(window, arguments)
  6437. }
  6438.  
  6439. }
  6440.  
  6441. const xrequestAnimationFrame = function (f) {
  6442. const h = f + "";
  6443. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  6444. xsetTimeout.m511 = 1;
  6445. f();
  6446. xsetTimeout.m511 = 0;
  6447. } else if (h.includes("requestAninmationFrameResolver")) {
  6448. getRafPromise().then(f);
  6449. } else {
  6450. return requestAnimationFrame.apply(window, arguments);
  6451. }
  6452. }
  6453.  
  6454. let busy = false;
  6455. const doIdomRender = function () {
  6456. if (busy) {
  6457. return this.doIdomRender13.apply(this, arguments);
  6458. }
  6459. busy = true;
  6460. const { requestAnimationFrame, setTimeout } = window;
  6461. window.requestAnimationFrame = xrequestAnimationFrame;
  6462. window.setTimeout = xsetTimeout;
  6463. let r = this.doIdomRender13.apply(this, arguments);
  6464. window.requestAnimationFrame = requestAnimationFrame;
  6465. window.setTimeout = setTimeout;
  6466. busy = false;
  6467. return r;
  6468. };
  6469. for (const ytTag of ['ytd-lottie-player', 'yt-attributed-string', 'yt-image', 'yt-icon-shape', 'yt-button-shape', 'yt-button-view-model', 'yt-icon-badge-shape']) {
  6470.  
  6471.  
  6472. whenCEDefined(ytTag).then(() => {
  6473.  
  6474. let dummy;
  6475. let cProto;
  6476. dummy = document.createElement(ytTag);
  6477. cProto = insp(dummy).constructor.prototype;
  6478.  
  6479. cProto.doIdomRender13 = cProto.doIdomRender;
  6480. cProto.doIdomRender = doIdomRender;
  6481.  
  6482. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  6483.  
  6484. console.debug('FIX_doIdomRender', ytTag)
  6485.  
  6486.  
  6487.  
  6488. });
  6489.  
  6490. }
  6491.  
  6492. }
  6493.  
  6494.  
  6495.  
  6496. });
  6497.  
  6498. });
  6499.  
  6500.  
  6501.  
  6502.  
  6503. if (isMainWindow) {
  6504.  
  6505. console.groupCollapsed(
  6506. "%cYouTube JS Engine Tamer",
  6507. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  6508. );
  6509.  
  6510.  
  6511.  
  6512. console.log("Script is loaded.");
  6513. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  6514.  
  6515. console.log("This script is experimental and subject to further changes.");
  6516.  
  6517. console.log("This might boost your YouTube performance.");
  6518.  
  6519. console.log("CAUTION: This might break your YouTube.");
  6520.  
  6521.  
  6522. if (prepareLogs.length >= 1) {
  6523. console.log(" =========================================================================== ");
  6524.  
  6525. for (const msg of prepareLogs) {
  6526. console.log(msg)
  6527. }
  6528.  
  6529. console.log(" =========================================================================== ");
  6530. }
  6531.  
  6532. console.groupEnd();
  6533.  
  6534. }
  6535.  
  6536.  
  6537.  
  6538. })();