YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-04-27 提交的版本,查看 最新版本

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