Greasy Fork 还支持 简体中文。

YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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