YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.12.0
  6. // @license MIT
  7. // @author CY Fung
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/yt-engine.png
  9. // @description To 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;
  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. const FIX_ytAction_ = true; // ytd-app
  47. const FIX_onVideoDataChange = false;
  48. // const FIX_onClick = true;
  49. const FIX_onStateChange = true;
  50. const FIX_onLoopRangeChange = true;
  51. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  52. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  53.  
  54. const ENABLE_discreteTasking = true;
  55. // << if ENABLE_discreteTasking >>
  56. const FIX_stampDomArray_stableList = true;
  57. const ENABLE_weakenStampReferences = true; // disabled in old browsers
  58. // << end >>
  59.  
  60. const FIX_perfNow = true;
  61. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  62.  
  63. const UNLOAD_DETACHED_POLYMER = false; // unstable
  64.  
  65. const WEAK_REF_BINDING = true; // false if your browser is slow
  66. // << if WEAK_REF_BINDING >>
  67. const WEAK_REF_PROXY_DOLLAR = true; // false if your browser is slow
  68. // << end >>
  69.  
  70. const TO_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  71. const DEBUG_removePrune = false; // true for DEBUG
  72.  
  73. const FIX_XHR_REQUESTING = true;
  74. const FIX_VIDEO_BLOCKING = true; // usually it is a ads block issue
  75.  
  76. const LOG_FETCHMETA_UPDATE = false;
  77.  
  78. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  79.  
  80. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  81. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  82.  
  83. /*
  84. window.addEventListener('edm',()=>{
  85. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  86. });
  87.  
  88. window.addEventListener('edn',()=>{
  89. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  90. });
  91. window.addEventListener('edr',()=>{
  92. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  93. });
  94. */
  95.  
  96. // only for macOS with Chrome/Firefox 100+
  97. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  98.  
  99. const win = this instanceof Window ? this : window;
  100.  
  101. // Create a unique key for the script and check if it is already running
  102. const hkey_script = 'jswylcojvzts';
  103. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  104. win[hkey_script] = true;
  105.  
  106.  
  107. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  108. /** @type {(f: ()=>{})=>{}} */
  109. const nextBrowserTick = (self || 0).nextBrowserTick || 0;
  110. const nextBrowserTick_ = nextBrowserTick || (f => f());
  111.  
  112. let p59 = 0;
  113.  
  114. const Promise = (async () => { })().constructor;
  115.  
  116. const PromiseExternal = ((resolve_, reject_) => {
  117. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  118. return class PromiseExternal extends Promise {
  119. constructor(cb = h) {
  120. super(cb);
  121. if (cb === h) {
  122. /** @type {(value: any) => void} */
  123. this.resolve = resolve_;
  124. /** @type {(reason?: any) => void} */
  125. this.reject = reject_;
  126. }
  127. }
  128. };
  129. })();
  130.  
  131. /**
  132. @param {number} x
  133. @param {number} d */
  134. const toFixed2 = (x, d) => {
  135. let t = x.toFixed(d);
  136. let y = `${+t}`;
  137. return y.length > t.length ? t : y;
  138. }
  139.  
  140.  
  141. let pf31 = new PromiseExternal();
  142.  
  143. // native RAF
  144. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  145.  
  146. // 1st wrapped RAF
  147. const baseRAF = (callback) => {
  148. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  149. pf31.then(() => {
  150. callback(hRes);
  151. });
  152. });
  153. };
  154.  
  155. // 2nd wrapped RAF
  156. window.requestAnimationFrame = baseRAF;
  157.  
  158. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  159. const indr = o => insp(o).$ || o.$ || 0;
  160.  
  161. const prototypeInherit = (d, b) => {
  162. const m = Object.getOwnPropertyDescriptors(b);
  163. for (const p in m) {
  164. if (!Object.getOwnPropertyDescriptor(d, p)) {
  165. Object.defineProperty(d, p, m[p]);
  166. }
  167. }
  168. };
  169.  
  170. /** @type {(o: Object | null) => WeakRef | null} */
  171. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  172.  
  173. /** @type {(wr: Object | null) => Object | null} */
  174. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  175.  
  176. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  177. if (DENY_requestStorageAccess) {
  178. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  179. Document.prototype.requestStorageAccessFor = undefined;
  180. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  181. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  182. Document.prototype.requestStorageAccessFor = function () {
  183. return new Promise((resolve, reject) => {
  184. reject();
  185. });
  186. };
  187. }
  188. }
  189.  
  190. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  191. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  192. const f = performance.now23 = Performance.prototype.now;
  193.  
  194. let k = 0; // 0 <= k < 9998m
  195. let u = 0;
  196. let s = ((performance.timeOrigin % 7) + 1) / 7; // s >= 0.14
  197.  
  198. // By definition, performance.now() is mono increasing.
  199. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  200. performance.now = performance.now16 = function () {
  201. /**
  202. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  203. *
  204. * If consecutive session history entries had history.state.entryTime set to same value,
  205. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  206. * and modifying its return value slightly to make sure two close consecutive calls don't
  207. * get the same result helped with resolving the issue.
  208. */
  209. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  210. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  211.  
  212. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v >= 0.1
  213. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  214. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  215. else { // more than 9997 consecutive calls; in reality, the max no. of consecutive calls would be much below 7500
  216. k = 0;
  217. s += 1;
  218. }
  219. return v - 1e-2 / 7 + k; // 0 < v - M < v - M + k < v
  220. }
  221.  
  222. let loggerMsg = '';
  223. if (`${performance.now()}` === `${performance.now()}`) {
  224. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  225. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  226. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  227. }
  228. loggerMsg && console.warn(loggerMsg);
  229. })();
  230.  
  231. if (ENABLE_ASYNC_DISPATCHEVENT && nextBrowserTick) {
  232. const filter = new Set([
  233. 'yt-action',
  234. // 'iframe-src-replaced',
  235. 'shown-items-changed',
  236. 'can-show-more-changed', 'collapsed-changed',
  237.  
  238. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  239. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  240. 'yt-navigate-finish',
  241.  
  242. // 'data-changed','yt-watch-comments-ready'
  243. ])
  244. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  245. EventTarget.prototype.dispatchEvent = function (event) {
  246. const type = (event || 0).type;
  247. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  248. if (!filter.has(type) && !type.endsWith('-changed')) {
  249. if (this instanceof Node || this instanceof Window) {
  250. nextBrowserTick(() => this.dispatchEvent938(event));
  251. return true;
  252. }
  253. }
  254. }
  255. return this.dispatchEvent938(event);
  256. }
  257. }
  258.  
  259. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  260. const removePrune_propNeedles = () => {
  261. // const xhr = new XMLHttpRequest;
  262. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  263. if (!pdOri || pdOri.configurable !== true) return;
  264. let propNeedles = null;
  265. const pdNew = {
  266. configurable: true,
  267. enumerable: true,
  268. get: function () {
  269. propNeedles = this;
  270. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  271. throw new Error();
  272. }
  273. }
  274. Object.defineProperty(Map.prototype, 'size', pdNew);
  275. try {
  276. XMLHttpRequest.prototype.open.call(0);
  277. // xhr.open.call(null)
  278. } catch (e) { }
  279. Object.defineProperty(Map.prototype, 'size', pdOri);
  280. if (!propNeedles) return;
  281. const entries = [...propNeedles.entries()];
  282. propNeedles.clear();
  283. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  284. }
  285.  
  286. if (TO_REMOVE_PRUNE_propNeedles) {
  287. removePrune_propNeedles();
  288. }
  289.  
  290. if (FIX_XHR_REQUESTING) {
  291.  
  292. const URL = window.URL || new Function('return URL')();
  293. const createObjectURL = URL.createObjectURL.bind(URL);
  294.  
  295. XMLHttpRequest = (() => {
  296. const XMLHttpRequest_ = XMLHttpRequest;
  297. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  298. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  299. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  300. constructor(...args) {
  301. super(...args);
  302. }
  303. open(method, url, ...args) {
  304. let skip = false;
  305. if (!url || typeof url !== 'string') skip = true;
  306. else if (typeof url === 'string') {
  307. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  308. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  309. skip = true;
  310. } else if (turl.includes('.youtube.com/pagead/')) {
  311. skip = true;
  312. } else if (turl.includes('.youtube.com/ptracking')) {
  313. skip = true;
  314. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  315. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  316. skip = true;
  317. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  318. skip = true;
  319. } else {
  320. // skip = true; // for user activity logging e.g. watched videos
  321. }
  322. } else if (turl.includes('play.google.com/log')) {
  323. skip = true;
  324. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  325. skip = true;
  326. }
  327. }
  328. if (!skip) {
  329. this.__xmMc8__ = 1;
  330. return super.open(method, url, ...args);
  331. } else {
  332. this.__xmMc8__ = 2;
  333. return super.open('GET', url0);
  334. }
  335. }
  336. send(...args) {
  337. if (this.__xmMc8__ === 1) {
  338. return super.send(...args);
  339. } else if (this.__xmMc8__ === 2) {
  340. return super.send();
  341. } else {
  342. console.log('[yt-js-engine-tamer]', 'xhr warning');
  343. return super.send(...args);
  344. }
  345. }
  346. }
  347. c.prototype.__xmMc8__ = 0;
  348. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  349. return c;
  350. })();
  351. }
  352.  
  353.  
  354. const check_for_set_key_order = (() => {
  355.  
  356. let mySet = new Set();
  357.  
  358. mySet.add("value1");
  359. mySet.add("value2");
  360. mySet.add("value3");
  361.  
  362. // Function to convert Set values to an array
  363. function getSetValues(set) {
  364. return Array.from(set.values());
  365. }
  366.  
  367. // Function to test if the Set maintains insertion order
  368. function testSetOrder(set, expectedOrder) {
  369. let values = getSetValues(set);
  370. return expectedOrder.join(',') === values.join(',');
  371. }
  372.  
  373. // Test 1: Initial order
  374. if (mySet.values().next().value !== "value1") return false;
  375. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  376.  
  377. // Test 2: After deleting an element
  378. mySet.delete("value2");
  379. if (mySet.values().next().value !== "value1") return false;
  380. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  381.  
  382. // Test 3: After re-adding a deleted element
  383. mySet.add("value2");
  384. if (mySet.values().next().value !== "value1") return false;
  385. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  386.  
  387. // Test 4: After adding a new element
  388. mySet.add("value4");
  389. if (mySet.values().next().value !== "value1") return false;
  390. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  391.  
  392. // Test 5: Delete+Add
  393. mySet.delete("value1");
  394. mySet.delete("value3");
  395. mySet.add("value3");
  396. mySet.add("value1");
  397. if (mySet.values().next().value !== "value2") return false;
  398. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  399.  
  400. return true;
  401. })();
  402.  
  403.  
  404. // const qm47 = Symbol();
  405. const qm57 = Symbol();
  406. const qm53 = Symbol();
  407. const qn53 = Symbol();
  408.  
  409.  
  410. const ump3 = new WeakMap();
  411.  
  412. const stp = document.createElement('noscript');
  413. stp.id = 'weakref-placeholder'
  414.  
  415.  
  416. const setupD = typeof WeakRef !== 'undefined' ? (elm, s, usePlaceholder) => {
  417.  
  418. const z = `${s}72`;
  419.  
  420. if (s in elm) {
  421.  
  422. const p = elm[s];
  423.  
  424. delete elm[s];
  425.  
  426. Object.defineProperty(elm, s, {
  427. get() {
  428. const elm = this;
  429. const wr = elm[z];
  430. if (!wr) return null;
  431. const m = kRef(wr);
  432. if (!m && usePlaceholder) {
  433. if (typeof usePlaceholder === 'function') usePlaceholder(elm);
  434. return stp;
  435. }
  436. return m;
  437. },
  438. set(nv) {
  439. const elm = this;
  440. elm[z] = nv ? mWeakRef(nv) : null;
  441. return true;
  442. },
  443. configurable: true,
  444. enumerable: true
  445.  
  446. });
  447.  
  448. elm[s] = p;
  449. elm = null;
  450.  
  451.  
  452. }
  453. } : null;
  454.  
  455. const mxMap = new WeakMap();
  456.  
  457. const myMap = new WeakSet();
  458.  
  459. const setup$ = typeof WeakRef !== 'undefined' ? function (dh) {
  460.  
  461. const $ = dh.$;
  462.  
  463. if (WEAK_REF_PROXY_DOLLAR && $ && typeof $ === 'object' && !dh.$ky37) {
  464.  
  465. dh.$ky37 = 1;
  466.  
  467. if (!myMap.has($)) {
  468.  
  469. for (const [k, v] of Object.entries($)) {
  470. if (v instanceof Node) {
  471. $[k] = mWeakRef(v);
  472. }
  473. }
  474.  
  475. dh.$ = mxMap.get($) || new Proxy($, {
  476. get(obj, prop) {
  477. const val = obj[prop];
  478. if (typeof (val || 0).deref === 'function') {
  479. return val.deref();
  480. }
  481. return val;
  482. },
  483. set(obj, prop, val) {
  484. if (val instanceof Node) {
  485. obj[prop] = mWeakRef(val);
  486. } else {
  487. obj[prop] = val;
  488. }
  489. return true;
  490. }
  491. });
  492.  
  493. mxMap.set($, dh.$);
  494. myMap.add(dh.$);
  495.  
  496. }
  497.  
  498. }
  499.  
  500. } : null;
  501.  
  502.  
  503. const configureVisibilityObserverT_ = function () {
  504. const hostElement = this.hostElement;
  505. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  506. this.unobserve_();
  507. } else {
  508. return this.configureVisibilityObserver27_();
  509. }
  510. };
  511. const getParentRendererT = function () {
  512. const hostElement = this.hostElement;
  513. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  514. return null;
  515. } else {
  516. return this.getParentRenderer27();
  517. }
  518. }
  519.  
  520. const attachedT = function () {
  521. const hostElement = this.hostElement;
  522. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  523. if (this.isAttached === true) this.isAttached = false;
  524. return void 0;
  525. } else {
  526. return this.attached27();
  527. }
  528. }
  529.  
  530. const hostElementCleanUp = (dh) => {
  531. if (typeof dh.dispose === 'function') {
  532. try {
  533. if (dh.visibilityMonitor || dh.visibilityObserver) {
  534. dh.dispose();
  535. dh.visibilityMonitor = null;
  536. dh.visibilityObserver = null;
  537. }
  538. } catch (e) { }
  539. }
  540. if (typeof dh.detached === 'function') {
  541. try {
  542. if (dh.visibilityObserverForChild_ || dh.localVisibilityObserver_) {
  543. dh.detached();
  544. dh.visibilityObserverForChild_ = null;
  545. dh.localVisibilityObserver_ = null;
  546. }
  547. } catch (e) { }
  548. }
  549. };
  550. const setupDataHost = setupD && setup$ ? function (dh, opt) {
  551.  
  552. if (dh && typeof dh === 'object') {
  553.  
  554. if (typeof dh.configureVisibilityObserver_ === 'function' && !dh.configureVisibilityObserver27_) {
  555. dh.configureVisibilityObserver27_ = dh.configureVisibilityObserver_;
  556. dh.configureVisibilityObserver_ = configureVisibilityObserverT_;
  557. }
  558.  
  559. if (typeof dh.getParentRenderer === 'function' && !dh.getParentRenderer27) {
  560. dh.getParentRenderer27 = dh.getParentRenderer;
  561. dh.getParentRenderer = getParentRendererT;
  562. }
  563.  
  564. if (typeof dh.attached === 'function' && !dh.attached27) {
  565. dh.attached27 = dh.attached;
  566. dh.attached = attachedT;
  567. }
  568.  
  569. setupD(dh, 'hostElement', hostElementCleanUp);
  570. setupD(dh, 'parentComponent');
  571. setupD(dh, 'localVisibilityObserver_');
  572. setupD(dh, 'cachedProviderNode_');
  573.  
  574.  
  575. setupD(dh, '__template');
  576. setupD(dh, '__templatizeOwner');
  577. setupD(dh, '__templateInfo');
  578.  
  579. // setupD(dh, 'root', 1);
  580.  
  581. const elements_ = dh.elements_;
  582. if (elements_ && typeof elements_ === 'object' && Object.keys(elements_).length > 0) setupD(dh, 'elements_');
  583.  
  584. setup$(dh);
  585. }
  586.  
  587.  
  588.  
  589.  
  590. } : null;
  591.  
  592.  
  593. let delay300 = null;
  594.  
  595. if (UNLOAD_DETACHED_POLYMER || WEAK_REF_BINDING) {
  596. delay300 = new PromiseExternal();
  597. setInterval(() => {
  598. delay300.resolve();
  599. delay300 = new PromiseExternal();
  600. }, 300);
  601. }
  602.  
  603. const aDelay = async function () {
  604. await delay300.then();
  605. await delay300.then();
  606. }
  607.  
  608. const convertionFuncMap = new WeakMap();
  609. let val_kevlar_should_maintain_stable_list = null;
  610.  
  611. const createStampDomArrayFn_ = (fn) => {
  612. if (val_kevlar_should_maintain_stable_list === null) {
  613. const config_ = ((window.yt || 0).config_ || 0);
  614. val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true
  615. }
  616. const gn = function (a, b, c, d, e, h) {
  617. const isNonEmptyArray = (a || 0).length >= 1
  618. if (!isNonEmptyArray) {
  619. return fn.call(this, undefined, b, undefined, d);
  620. } else if (h === undefined && typeof b === 'string' && c && typeof c === 'object' && this.is && val_kevlar_should_maintain_stable_list) {
  621. if (c.clientSideToggleMenuItemRenderer) {
  622. h = false;
  623. } else {
  624. h = true;
  625. }
  626. }
  627. return fn.call(this, a, b, c, d, e, h)
  628. }
  629. gn.originalFn = fn;
  630. convertionFuncMap.set(fn, gn);
  631. return gn;
  632. }
  633.  
  634. const fixStampDomArrayStableList = (h) => {
  635. if (!h.stampDomArray_) return;
  636. const proto = h.__proto__;
  637. const f = proto.stampDomArray_;
  638. if (!proto.stampDomArrayF001_ && typeof f === 'function' && f.length === 6) {
  639. proto.stampDomArrayF001_ = 1;
  640. proto.stampDomArray_ = convertionFuncMap.get(f) || createStampDomArrayFn_(f);
  641. }
  642. }
  643.  
  644. const weakenStampReferences = (() => {
  645.  
  646. const DEBUG_STAMP = false;
  647.  
  648. const s1 = Symbol();
  649. const handler1 = {
  650. get(target, prop, receiver) {
  651. if (prop === 'object') {
  652. return kRef(target[s1]); // avoid memory leakage
  653. }
  654. if (prop === '__proxy312__') return 1;
  655. return target[prop];
  656. }
  657. };
  658. const handler2 = {
  659. get(target, prop, receiver) {
  660. if (prop === 'indexSplices') {
  661. return kRef(target[s1]); // avoid memory leakage
  662. }
  663. if (prop === '__proxy312__') return 1;
  664. return target[prop];
  665. }
  666. }
  667. return (h) => {
  668.  
  669. if (h.rendererStamperApplyChangeRecord_ || h.stampDomArraySplices_) {
  670. const proto = h.__proto__;
  671. if (!proto.yzxer && (proto.rendererStamperApplyChangeRecord_ || proto.stampDomArraySplices_)) {
  672. proto.yzxer = 1;
  673.  
  674. const list = [
  675. // "rendererStamperObserver_", // 3 ==> rendererStamperApplyChangeRecord_
  676. "rendererStamperApplyChangeRecord_", // 3
  677. "forwardRendererStamperChanges_", // 3
  678. "stampDomArraySplices_", // 3
  679. "stampDomArray_", // 6
  680. "deferRenderStamperBinding_", // 3
  681. ];
  682. for (const key of list) {
  683. const pey = `${key}$wq0iw_`;
  684. const vKey = proto[key];
  685. if (typeof vKey !== 'function') continue;
  686. if (proto[pey] || vKey.length === 0) continue;
  687.  
  688. if (key === 'stampDomArraySplices_' && vKey.length === 3) {
  689. proto[pey] = vKey;
  690. proto[key] = function (a, b, c) {
  691.  
  692. if (typeof a === 'string' && typeof b === 'string' && typeof c === 'object' && c && c.indexSplices && c.indexSplices.length >= 1 && !c.indexSplices.rzgjr) {
  693.  
  694. c.indexSplices = c.indexSplices.map(e => {
  695. if (e.__proxy312__) return e;
  696. e[s1] = mWeakRef(e.object);
  697. e.object = null;
  698. return new Proxy(e, handler1);
  699. });
  700. c.indexSplices.rzgjr = 1;
  701.  
  702. c[s1] = mWeakRef(c.indexSplices);
  703. c.indexSplices = null;
  704. c = new Proxy(c, handler2)
  705. arguments[2] = c;
  706.  
  707. }
  708. // console.log(key, arguments.length, [...arguments]);
  709. return proto[pey].call(this, a, b, c);
  710. }
  711.  
  712. } else if (key === 'rendererStamperApplyChangeRecord_' && vKey.length === 3) {
  713. // Nil
  714.  
  715. } else if (DEBUG_STAMP) {
  716.  
  717. console.log(proto.isRenderer_, 'ms_' + key, vKey.length, h.is)
  718. proto[pey] = vKey;
  719. proto[key] = function () {
  720. if (key === 'rendererStamperApplyChangeRecord_' && typeof arguments[3] === 'object') {
  721. console.log(key, arguments.length, { value: arguments[3].value, base: arguments[3].base, })
  722. }
  723. console.log(key, arguments.length, [...arguments]);
  724. return proto[pey].apply(this, arguments);
  725. }
  726.  
  727. }
  728.  
  729. }
  730.  
  731.  
  732. // const m = (Object.mkss = Object.mkss || new Set());
  733. // Object.keys(h.__proto__).filter(e => e.toLowerCase().includes('stamp') && typeof h[e] === 'function').forEach(e => m.add(e))
  734. // console.log([...m])
  735. }
  736. }
  737.  
  738. }
  739. })();
  740.  
  741. const setupDiscreteTasks = (h, rb) => {
  742.  
  743. if (rb) {
  744. if (h.ky36) return;
  745. }
  746.  
  747.  
  748. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  749. const f = h.onYtRendererstamperFinished;
  750. const g = ump3.get(f) || function () {
  751. if (this.updateChildVisibilityProperties && !this.markDirty) {
  752. return f.apply(this, arguments);
  753. }
  754. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  755. }
  756. ump3.set(f, g);
  757. g.km34 = 1;
  758. h.onYtRendererstamperFinished = g;
  759.  
  760. }
  761.  
  762. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  763. const f = h.onYtUpdateDescriptionAction;
  764. const g = ump3.get(f) || function (a) {
  765. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  766. }
  767. ump3.set(f, g);
  768. g.km34 = 1;
  769. h.onYtUpdateDescriptionAction = g;
  770.  
  771. }
  772.  
  773. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  774. const f = h.handleUpdateDescriptionAction;
  775. const g = ump3.get(f) || function (a) {
  776. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  777. }
  778. ump3.set(f, g);
  779. g.km34 = 1;
  780. h.handleUpdateDescriptionAction = g;
  781.  
  782. }
  783.  
  784. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  785. const f = h.handleUpdateLiveChatPollAction;
  786. const g = ump3.get(f) || function (a) {
  787. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  788. }
  789. ump3.set(f, g);
  790. g.km34 = 1;
  791. h.handleUpdateLiveChatPollAction = g;
  792.  
  793. }
  794.  
  795. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  796. const f = h.onTextChanged;
  797. const g = ump3.get(f) || function () {
  798. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  799. }
  800. ump3.set(f, g);
  801. g.km34 = 1;
  802. h.onTextChanged = g;
  803.  
  804. }
  805.  
  806. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  807. const f = h.onVideoDataChange;
  808. const g = ump3.get(f) || function (a) {
  809. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  810. }
  811. ump3.set(f, g);
  812. g.km34 = 1;
  813. h.onVideoDataChange = g;
  814.  
  815. }
  816.  
  817. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  818. const f = h.onVideoDataChange_;
  819. const g = ump3.get(f) || function () {
  820. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  821. }
  822. ump3.set(f, g);
  823. g.km34 = 1;
  824. h.onVideoDataChange_ = g;
  825.  
  826. }
  827.  
  828. if (typeof h.addTooltips === 'function' && !(h.addTooltips.km34)) {
  829.  
  830. const f = h.addTooltips;
  831. const g = ump3.get(f) || function () {
  832. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  833. }
  834. ump3.set(f, g);
  835. g.km34 = 1;
  836. h.addTooltips = g;
  837.  
  838. }
  839.  
  840. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  841.  
  842. const f = h.addTooltips_;
  843. const g = ump3.get(f) || function () {
  844. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  845. }
  846. ump3.set(f, g);
  847. g.km34 = 1;
  848. h.addTooltips_ = g;
  849.  
  850. }
  851.  
  852. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  853.  
  854. const f = h.updateRenderedElements;
  855. const g = ump3.get(f) || function () {
  856. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  857. }
  858. ump3.set(f, g);
  859. g.km34 = 1;
  860. h.updateRenderedElements = g;
  861.  
  862. }
  863.  
  864. if (typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  865. const f = h.loadPage_;
  866. const g = ump3.get(f) || function (a) {
  867. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  868. }
  869. ump3.set(f, g);
  870. g.km34 = 1;
  871. h.loadPage_ = g;
  872.  
  873. }
  874. if (typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  875. const f = h.updatePageData_;
  876. const g = ump3.get(f) || function (a) {
  877. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  878. }
  879. ump3.set(f, g);
  880. g.km34 = 1;
  881. h.updatePageData_ = g;
  882.  
  883. }
  884.  
  885. if (typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  886.  
  887. const f = h.onFocus_;
  888. const g = ump3.get(f) || function () {
  889. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  890. }
  891. ump3.set(f, g);
  892. g.km34 = 1;
  893. h.onFocus_ = g;
  894.  
  895. }
  896.  
  897. if (typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  898.  
  899. const f = h.onBlur_;
  900. const g = ump3.get(f) || function () {
  901. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  902. }
  903. ump3.set(f, g);
  904. g.km34 = 1;
  905. h.onBlur_ = g;
  906.  
  907. }
  908.  
  909. if (typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  910.  
  911. const f = h.buttonClassChanged_;
  912. const g = ump3.get(f) || function (a, b) {
  913. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  914. }
  915. ump3.set(f, g);
  916. g.km34 = 1;
  917. h.buttonClassChanged_ = g;
  918.  
  919. }
  920.  
  921. if (typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  922.  
  923. const f = h.buttonIconChanged_;
  924. const g = ump3.get(f) || function (a) {
  925. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  926. }
  927. ump3.set(f, g);
  928. g.km34 = 1;
  929. h.buttonIconChanged_ = g;
  930.  
  931. }
  932.  
  933. if (typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  934.  
  935. const f = h.dataChangedInBehavior_;
  936. const g = ump3.get(f) || function () {
  937. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  938. }
  939. ump3.set(f, g);
  940. g.km34 = 1;
  941. h.dataChangedInBehavior_ = g;
  942.  
  943. }
  944.  
  945. if (typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  946.  
  947. const f = h.continuationsChanged_;
  948. const g = ump3.get(f) || function () {
  949. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  950. }
  951. ump3.set(f, g);
  952. g.km34 = 1;
  953. h.continuationsChanged_ = g;
  954.  
  955. }
  956.  
  957. if (typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  958.  
  959. const f = h.forceChatPoll_;
  960. const g = ump3.get(f) || function (a) {
  961. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  962. }
  963. ump3.set(f, g);
  964. g.km34 = 1;
  965. h.forceChatPoll_ = g;
  966.  
  967. }
  968.  
  969. if (typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  970.  
  971. const f = h.onEndpointClick_;
  972. const g = ump3.get(f) || function (a) {
  973. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  974. }
  975. ump3.set(f, g);
  976. g.km34 = 1;
  977. h.onEndpointClick_ = g;
  978.  
  979. }
  980.  
  981. if (typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  982.  
  983. const f = h.onEndpointTap_;
  984. const g = ump3.get(f) || function (a) {
  985. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  986. }
  987. ump3.set(f, g);
  988. g.km34 = 1;
  989. h.onEndpointTap_ = g;
  990.  
  991. }
  992.  
  993. if (typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  994.  
  995. const f = h.handleClick_;
  996. const g = ump3.get(f) || function (a, b) {
  997. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  998. }
  999. ump3.set(f, g);
  1000. g.km34 = 1;
  1001. h.handleClick_ = g;
  1002.  
  1003. }
  1004.  
  1005. if (typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  1006.  
  1007. const f = h.onReadyStateChange_;
  1008. const g = ump3.get(f) || function () {
  1009. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1010. }
  1011. ump3.set(f, g);
  1012. g.km34 = 1;
  1013. h.onReadyStateChange_ = g;
  1014.  
  1015. }
  1016.  
  1017. if (typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  1018.  
  1019. const f = h.onReadyStateChangeEntryPoint_;
  1020. const g = ump3.get(f) || function () {
  1021. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1022. }
  1023. ump3.set(f, g);
  1024. g.km34 = 1;
  1025. h.onReadyStateChangeEntryPoint_ = g;
  1026.  
  1027. }
  1028.  
  1029. if (typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  1030.  
  1031. const f = h.readyStateChangeHandler_;
  1032. const g = ump3.get(f) || function (a) {
  1033. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1034. }
  1035. ump3.set(f, g);
  1036. g.km34 = 1;
  1037. h.readyStateChangeHandler_ = g;
  1038.  
  1039. }
  1040.  
  1041. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  1042.  
  1043. const f = h.xmlHttpHandler_;
  1044. const g = ump3.get(f) || function (a) {
  1045. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1046. }
  1047. ump3.set(f, g);
  1048. g.km34 = 1;
  1049. h.xmlHttpHandler_ = g;
  1050.  
  1051. }
  1052.  
  1053. if (typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  1054.  
  1055. const f = h.executeCallbacks_; // overloaded
  1056. const g = ump3.get(f) || function (a) {
  1057. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1058. }
  1059. ump3.set(f, g);
  1060. g.km34 = 1;
  1061. h.executeCallbacks_ = g;
  1062.  
  1063. }
  1064.  
  1065. if (typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  1066.  
  1067. const f = h.handleInvalidationData_;
  1068. const g = ump3.get(f) || function (a, b) {
  1069. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1070. }
  1071. ump3.set(f, g);
  1072. g.km34 = 1;
  1073. h.handleInvalidationData_ = g;
  1074.  
  1075. }
  1076.  
  1077. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  1078.  
  1079. const f = h.onInput_;
  1080. const g = ump3.get(f) || function () {
  1081. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1082. }
  1083. ump3.set(f, g);
  1084. g.km34 = 1;
  1085. h.onInput_ = g;
  1086.  
  1087. }
  1088.  
  1089. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  1090.  
  1091. const f = h.trigger_;
  1092. const g = ump3.get(f) || function (a) {
  1093. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1094. }
  1095. ump3.set(f, g);
  1096. g.km34 = 1;
  1097. h.trigger_ = g;
  1098.  
  1099. }
  1100.  
  1101. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  1102.  
  1103. const f = h.requestData_;
  1104. const g = ump3.get(f) || function (a) {
  1105. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1106. }
  1107. ump3.set(f, g);
  1108. g.km34 = 1;
  1109. h.requestData_ = g;
  1110.  
  1111. }
  1112.  
  1113. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  1114.  
  1115. const f = h.onLoadReloadContinuation_;
  1116. const g = ump3.get(f) || function (a, b) {
  1117. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1118. }
  1119. ump3.set(f, g);
  1120. g.km34 = 1;
  1121. h.onLoadReloadContinuation_ = g;
  1122.  
  1123. }
  1124.  
  1125. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  1126.  
  1127. const f = h.onLoadIncrementalContinuation_;
  1128. const g = ump3.get(f) || function (a, b) {
  1129. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1130. }
  1131. ump3.set(f, g);
  1132. g.km34 = 1;
  1133. h.onLoadIncrementalContinuation_ = g;
  1134.  
  1135. }
  1136.  
  1137. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  1138.  
  1139. const f = h.onLoadSeekContinuation_;
  1140. const g = ump3.get(f) || function (a, b) {
  1141. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1142. }
  1143. ump3.set(f, g);
  1144. g.km34 = 1;
  1145. h.onLoadSeekContinuation_ = g;
  1146.  
  1147. }
  1148. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  1149.  
  1150. const f = h.onLoadReplayContinuation_;
  1151. const g = ump3.get(f) || function (a, b) {
  1152. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1153. }
  1154. ump3.set(f, g);
  1155. g.km34 = 1;
  1156. h.onLoadReplayContinuation_ = g;
  1157.  
  1158. }
  1159. if (typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  1160.  
  1161. const f = h.onNavigate_;
  1162. const g = ump3.get(f) || function (a) {
  1163. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1164. }
  1165. ump3.set(f, g);
  1166. g.km34 = 1;
  1167. h.onNavigate_ = g;
  1168.  
  1169. }
  1170.  
  1171. if (typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  1172.  
  1173. const f = h.ytRendererBehaviorDataObserver_;
  1174. const g = ump3.get(f) || function () {
  1175. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1176. }
  1177. ump3.set(f, g);
  1178. g.km34 = 1;
  1179. h.ytRendererBehaviorDataObserver_ = g;
  1180.  
  1181. }
  1182.  
  1183. if (typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  1184.  
  1185. const f = h.ytRendererBehaviorTargetIdObserver_;
  1186. const g = ump3.get(f) || function () {
  1187. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1188. }
  1189. ump3.set(f, g);
  1190. g.km34 = 1;
  1191. h.ytRendererBehaviorTargetIdObserver_ = g;
  1192.  
  1193. }
  1194.  
  1195. if (typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  1196.  
  1197. const f = h.unregisterRenderer_;
  1198. const g = ump3.get(f) || function (a) {
  1199. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1200. }
  1201. ump3.set(f, g);
  1202. g.km34 = 1;
  1203. h.unregisterRenderer_ = g;
  1204.  
  1205. }
  1206.  
  1207. if (typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  1208.  
  1209. const f = h.textChanged_;
  1210. const g = ump3.get(f) || function (a) {
  1211. if (void 0 !== this.isAttached) {
  1212. const hostElement = this.hostElement;
  1213. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  1214. return;
  1215. }
  1216. }
  1217. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1218. }
  1219. ump3.set(f, g);
  1220. g.km34 = 1;
  1221. h.textChanged_ = g;
  1222.  
  1223. }
  1224.  
  1225.  
  1226. /**
  1227. *
  1228. * Neglect following
  1229. *
  1230. * h.onYtAction_
  1231. * h.startLoadingWatch [ buggy for yt-player-updated ]
  1232. * h.deferRenderStamperBinding_
  1233. *
  1234. * h.stampDomArray_
  1235. * h.stampDomArraySplices_
  1236. *
  1237. */
  1238.  
  1239.  
  1240. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  1241. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  1242. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  1243. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  1244. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  1245. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  1246.  
  1247. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  1248.  
  1249. const f = h.searchChanged_;
  1250. const g = ump3.get(f) || function () {
  1251. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1252. }
  1253. ump3.set(f, g);
  1254. g.km34 = 1;
  1255. h.searchChanged_ = g;
  1256.  
  1257. }
  1258.  
  1259. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  1260.  
  1261. const f = h.skinToneChanged_;
  1262. const g = ump3.get(f) || function (a) {
  1263. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1264. }
  1265. ump3.set(f, g);
  1266. g.km34 = 1;
  1267. h.skinToneChanged_ = g;
  1268.  
  1269. }
  1270.  
  1271. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  1272.  
  1273. const f = h.onEmojiHover_;
  1274. const g = ump3.get(f) || function (a) {
  1275. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1276. }
  1277. ump3.set(f, g);
  1278. g.km34 = 1;
  1279. h.onEmojiHover_ = g;
  1280.  
  1281. }
  1282.  
  1283. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  1284.  
  1285. const f = h.onSelectCategory_;
  1286. const g = ump3.get(f) || function (a) {
  1287. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1288. }
  1289. ump3.set(f, g);
  1290. g.km34 = 1;
  1291. h.onSelectCategory_ = g;
  1292.  
  1293. }
  1294.  
  1295. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  1296.  
  1297. const f = h.onShowEmojiVariantSelector;
  1298. const g = ump3.get(f) || function (a) {
  1299. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1300. }
  1301. ump3.set(f, g);
  1302. g.km34 = 1;
  1303. h.onShowEmojiVariantSelector = g;
  1304.  
  1305. }
  1306.  
  1307. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  1308.  
  1309. const f = h.updateCategoriesAndPlaceholder_;
  1310. const g = ump3.get(f) || function () {
  1311. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1312. }
  1313. ump3.set(f, g);
  1314. g.km34 = 1;
  1315. h.updateCategoriesAndPlaceholder_ = g;
  1316.  
  1317. }
  1318.  
  1319. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  1320.  
  1321. const f = h.watchPageActiveChanged_;
  1322. const g = ump3.get(f) || function () {
  1323. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1324. }
  1325. ump3.set(f, g);
  1326. g.km34 = 1;
  1327. h.watchPageActiveChanged_ = g;
  1328.  
  1329. }
  1330.  
  1331. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  1332.  
  1333. const f = h.activate_;
  1334. const g = ump3.get(f) || function () {
  1335. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1336. }
  1337. ump3.set(f, g);
  1338. g.km34 = 1;
  1339. h.activate_ = g;
  1340.  
  1341. }
  1342. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  1343.  
  1344. const f = h.onYtPlaylistDataUpdated_;
  1345. const g = ump3.get(f) || function () {
  1346. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1347. }
  1348. ump3.set(f, g);
  1349. g.km34 = 1;
  1350. h.onYtPlaylistDataUpdated_ = g;
  1351.  
  1352. }
  1353.  
  1354. FIX_stampDomArray_stableList && fixStampDomArrayStableList(h);
  1355. const ENABLE_weakenStampReferencesQ = ENABLE_weakenStampReferences && typeof DocumentTimeline !== 'undefined' && typeof WeakRef !== 'undefined';
  1356. ENABLE_weakenStampReferencesQ && weakenStampReferences(h);
  1357.  
  1358. /**
  1359. *
  1360. * Neglect following
  1361. *
  1362. * h.rendererStamperObserver_
  1363. * h.rendererStamperApplyChangeRecord_
  1364. * h.flushRenderStamperComponentBindings_
  1365. * h.forwardRendererStamperChanges_
  1366. *
  1367. */
  1368.  
  1369. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  1370.  
  1371. const f = h.tryRenderChunk_;
  1372. const g = ump3.get(f) || function () {
  1373. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1374. }
  1375. ump3.set(f, g);
  1376. g.km34 = 1;
  1377. h.tryRenderChunk_ = g;
  1378.  
  1379. }
  1380.  
  1381.  
  1382. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  1383.  
  1384. const f = h.renderChunk_;
  1385. const g = ump3.get(f) || function () {
  1386. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1387. }
  1388. ump3.set(f, g);
  1389. g.km34 = 1;
  1390. h.renderChunk_ = g;
  1391.  
  1392. }
  1393.  
  1394. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  1395.  
  1396. const f = h.deepLazyListObserver_;
  1397. const g = ump3.get(f) || function () {
  1398. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1399. }
  1400. ump3.set(f, g);
  1401. g.km34 = 1;
  1402. h.deepLazyListObserver_ = g;
  1403.  
  1404. }
  1405.  
  1406. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  1407.  
  1408. const f = h.onItemsUpdated_;
  1409. const g = ump3.get(f) || function () {
  1410. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1411. }
  1412. ump3.set(f, g);
  1413. g.km34 = 1;
  1414. h.onItemsUpdated_ = g;
  1415.  
  1416. }
  1417.  
  1418. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  1419.  
  1420. const f = h.requestRenderChunk_;
  1421. const g = ump3.get(f) || function () {
  1422. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1423. }
  1424. ump3.set(f, g);
  1425. g.km34 = 1;
  1426. h.requestRenderChunk_ = g;
  1427.  
  1428. }
  1429.  
  1430. /**
  1431. *
  1432. * Neglect following
  1433. *
  1434. * h.dataChanged_ [ buggy for page swtiching ]
  1435. *
  1436. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  1437. *
  1438. * h.cancelPendingTasks_
  1439. * h.fillRange_
  1440. * h.addTextNodes_
  1441. * h.updateText_
  1442. * h.stampTypeChanged_
  1443. *
  1444. */
  1445.  
  1446.  
  1447. }
  1448.  
  1449. const keyStConnectedCallback = Symbol(); // avoid copying the value
  1450.  
  1451. // const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  1452. const cmf = new WeakMap();
  1453. const dmf = new WeakMap();
  1454.  
  1455. const gvGenerator = (nv) => {
  1456. return function () {
  1457. const cnt = insp(this);
  1458. const hostElement = cnt.hostElement || 0;
  1459. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  1460. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  1461. if (p && (!dollar && !this.is)) {
  1462. const nodeName = hostElement.nodeName;
  1463. if (typeof nodeName !== 'string') {
  1464. // just in case
  1465. } else if (nodeName.startsWith("DOM-")) {
  1466. // dom-if, dom-repeat, etc
  1467. } else {
  1468. // yt element - new model, yt-xxxx, anixxxxxx
  1469. p = false;
  1470. }
  1471. }
  1472. if (p) {
  1473. if (typeof cnt.markDirty === 'function') {
  1474. // the yt element might call markDirty (occasionally)
  1475. p = false;
  1476. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  1477. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1478. p = false;
  1479. }
  1480. }
  1481. if (p) {
  1482.  
  1483. // << dom-repeat & dom-if >>
  1484.  
  1485. // sequence on the same instance
  1486. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  1487. } else {
  1488. nv.apply(this, arguments);
  1489. }
  1490. };
  1491. }
  1492.  
  1493. const setupWeakRef = (h) => {
  1494.  
  1495.  
  1496. if (WEAK_REF_BINDING && !h.kz62 && setup$ && setupD && setupDataHost && (h.is || h.__dataHost)) {
  1497.  
  1498. let skip = false;
  1499. // if (h.is && typeof h.is === 'string' && h.is.length > 15 && h.is.length < 30) {
  1500. // if (h.is.includes('yt-') && !h.$ && h.is.length !== 20 && h.is.length !== 21 && h.is.length !== 22) {
  1501. // skip = true;
  1502. // // return;
  1503. // }
  1504. // }
  1505.  
  1506. h.kz62 = 1;
  1507.  
  1508. //
  1509.  
  1510. setup$(h);
  1511. const hostElement = h.hostElement;
  1512.  
  1513. if (hostElement !== h) {
  1514.  
  1515. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  1516. setupD(h, s);
  1517. }
  1518.  
  1519. const dh = h.__dataHost;
  1520. setupDataHost(dh, skip);
  1521. }
  1522.  
  1523. if (hostElement) {
  1524.  
  1525. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  1526. setupD(hostElement, s);
  1527. }
  1528.  
  1529. const dh = hostElement.__dataHost;
  1530. setupDataHost(dh, skip);
  1531.  
  1532. aDelay().then(() => {
  1533. setupD(hostElement, '__CE_shadowRoot');
  1534. });
  1535.  
  1536. }
  1537.  
  1538. }
  1539.  
  1540. }
  1541.  
  1542.  
  1543. let nativeHTMLElement = window.HTMLElement;
  1544.  
  1545. try {
  1546.  
  1547. const q = document.createElement('template');
  1548. q.innerHTML = '<ytz-null361></ytz-null361>';
  1549. nativeHTMLElement = q.content.firstChild.constructor
  1550.  
  1551. } catch (e) { }
  1552.  
  1553. if (!nativeHTMLElement.prototype.connectedCallback) {
  1554. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  1555. nativeHTMLElement.prototype.connectedCallback = function () {
  1556. let r;
  1557. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  1558.  
  1559. if (WEAK_REF_BINDING && (this instanceof Node) && (this.is || this.__dataHost)) {
  1560. setupWeakRef(this)
  1561. // setupWeakRef(this.__dataHost)
  1562. }
  1563. return r;
  1564. }
  1565. }
  1566.  
  1567. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  1568. get() {
  1569. const f = this[keyStConnectedCallback];
  1570. if (this.is) {
  1571. setupDiscreteTasks(this, true);
  1572. if (f) this.ky36 = 1;
  1573. }
  1574. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  1575. setupWeakRef(this)
  1576. }
  1577. return f;
  1578. },
  1579. set(nv) {
  1580. let gv;
  1581. if (typeof nv === 'function') {
  1582.  
  1583. gv = cmf.get(nv) || gvGenerator(nv);
  1584. if (gv !== nv) {
  1585. cmf.set(nv, gv);
  1586. cmf.set(gv, gv);
  1587. dmf.set(gv, nv);
  1588. }
  1589.  
  1590. } else {
  1591. gv = nv;
  1592. }
  1593. this[keyStConnectedCallback] = gv; // proto or object
  1594. if (this.is) {
  1595. setupDiscreteTasks(this);
  1596. }
  1597. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  1598. setupWeakRef(this)
  1599. }
  1600. return true;
  1601. },
  1602. enumerable: false,
  1603. configurable: true
  1604.  
  1605. });
  1606.  
  1607. const pLoad = new Promise(resolve => {
  1608. if (document.readyState !== 'loading') {
  1609. resolve();
  1610. } else {
  1611. window.addEventListener("DOMContentLoaded", resolve, false);
  1612. }
  1613. });
  1614. pLoad.then(() => {
  1615.  
  1616. let nonce = document.querySelector('style[nonce]');
  1617. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1618. const st = document.createElement('style');
  1619. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1620. st.textContent = "none-element-k47{order:0}";
  1621. st.addEventListener('load', () => {
  1622. pf31.resolve();
  1623. p59 = 1;
  1624. }, false);
  1625. document.body.appendChild(st);
  1626.  
  1627. });
  1628.  
  1629. const prepareLogs = [];
  1630.  
  1631. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  1632.  
  1633. let winError00 = window.onerror;
  1634.  
  1635. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  1636.  
  1637. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  1638.  
  1639. ; FIX_Iframe_NULL_SRC && (() => {
  1640.  
  1641. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  1642. const lcOpt = { sensitivity: 'base' };
  1643. document.createElement24 = document.createElement;
  1644. document.createElement = function (t) {
  1645. if (typeof t === 'string' && t.length === 6) {
  1646. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  1647. const p = this.createElement24(t);
  1648. try {
  1649. const stack = new Error().stack;
  1650. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  1651. if (!isSearchbox) {
  1652. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  1653. }
  1654. } catch (e) { }
  1655. return p;
  1656. }
  1657. }
  1658. return this.createElement24.apply(this, arguments);
  1659. };
  1660.  
  1661. })();
  1662.  
  1663. ; fix_error_many_stack_state === 1 && (() => {
  1664.  
  1665.  
  1666. let p1 = winError00;
  1667.  
  1668. let stackNeedleDetails = null;
  1669.  
  1670. Object.defineProperty(Object.prototype, 'matchAll', {
  1671. get() {
  1672. stackNeedleDetails = this;
  1673. return true;
  1674. },
  1675. enumerable: true,
  1676. configurable: true
  1677. });
  1678.  
  1679. try {
  1680. JSON.parse("{}");
  1681. } catch (e) {
  1682. console.warn(e)
  1683. fix_error_many_stack_state = 0;
  1684. }
  1685.  
  1686. delete Object.prototype['matchAll'];
  1687.  
  1688. let p2 = window.onerror;
  1689.  
  1690. window.onerror = p1;
  1691.  
  1692. if (fix_error_many_stack_state === 0) return;
  1693.  
  1694. if (stackNeedleDetails) {
  1695. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1696. stackNeedleDetails.matchAll = true;
  1697. }
  1698.  
  1699. if (p1 === p2) return (fix_error_many_stack_state = 0);
  1700.  
  1701. // p1!==p2
  1702. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  1703.  
  1704. })();
  1705.  
  1706. ; fix_error_many_stack_state === 2 && (() => {
  1707.  
  1708.  
  1709. let p1 = winError00;
  1710.  
  1711. let objectPrune = null;
  1712. let stackNeedleDetails = null;
  1713.  
  1714. Object.defineProperty(Function.prototype, 'findOwner', {
  1715. get() {
  1716. objectPrune = this;
  1717. return this._findOwner;
  1718. },
  1719. set(nv) {
  1720. this._findOwner = nv;
  1721. return true;
  1722. },
  1723. enumerable: true,
  1724. configurable: true
  1725. });
  1726.  
  1727. Object.defineProperty(Object.prototype, 'matchAll', {
  1728. get() {
  1729. stackNeedleDetails = this;
  1730. return true;
  1731. },
  1732. enumerable: true,
  1733. configurable: true
  1734. });
  1735.  
  1736. try {
  1737. JSON.parse("{}");
  1738. } catch (e) {
  1739. console.warn(e)
  1740. fix_error_many_stack_state = 0;
  1741. }
  1742.  
  1743. delete Function.prototype['findOwner'];
  1744. delete Object.prototype['matchAll'];
  1745.  
  1746. let p2 = window.onerror;
  1747.  
  1748. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  1749.  
  1750. if (fix_error_many_stack_state == 0) return;
  1751.  
  1752. // the following will only execute when Brave's scriptlets.js is executed.
  1753.  
  1754. prepareLogs.push("fix_error_many_stack_state NB")
  1755.  
  1756. if (stackNeedleDetails) {
  1757. stackNeedleDetails.pattern = null;
  1758. stackNeedleDetails.re = null;
  1759. stackNeedleDetails.expect = null;
  1760. stackNeedleDetails.matchAll = true;
  1761. }
  1762.  
  1763. if (objectPrune) {
  1764. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  1765. delete objectPrune._findOwner;
  1766. }
  1767.  
  1768. fix_error_many_stack_state = 3;
  1769. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1770. JSON.parse.objectPrune = objectPrune;
  1771.  
  1772. })();
  1773.  
  1774. ; fix_error_many_stack_state === 3 && (() => {
  1775.  
  1776.  
  1777. let p1 = winError00;
  1778.  
  1779. try {
  1780. JSON.parse("{}");
  1781. } catch (e) {
  1782. console.warn(e)
  1783. fix_error_many_stack_state = 0;
  1784. }
  1785.  
  1786. let p2 = window.onerror;
  1787.  
  1788. if (p1 === p2) return;
  1789.  
  1790. window.onerror = p1;
  1791.  
  1792. if (fix_error_many_stack_state === 0) return;
  1793.  
  1794. fix_error_many_stack_state = 4; // p1 != p2
  1795.  
  1796.  
  1797. })();
  1798.  
  1799. fix_error_many_stack_state === 4 && (() => {
  1800.  
  1801. // the following will only execute when Brave's scriptlets.js is executed.
  1802.  
  1803. prepareLogs.push("fix_error_many_stack_state AB")
  1804.  
  1805. JSON.parseProxy = JSON.parse;
  1806.  
  1807. JSON.parse = ((parse) => {
  1808.  
  1809. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  1810. return function (text, reviver) {
  1811. const onerror = window.onerror;
  1812. window.onerror = null;
  1813. let r;
  1814. try {
  1815. r = parse(...arguments);
  1816. } catch (e) {
  1817. r = e;
  1818. }
  1819. window.onerror = onerror;
  1820. if (r instanceof Error) {
  1821. throw r;
  1822. }
  1823. return r;
  1824. }
  1825.  
  1826. })(JSON.parse);
  1827.  
  1828.  
  1829. })();
  1830.  
  1831.  
  1832. // << if FIX_yt_player >>
  1833.  
  1834. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  1835. const PERF_471489_ = true;
  1836. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  1837. // This script uses a much gentle way to tamer the JS engine instead.
  1838.  
  1839. // << end >>
  1840.  
  1841. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  1842.  
  1843.  
  1844.  
  1845. const nilFn = () => { };
  1846.  
  1847. let isMainWindow = false;
  1848. try {
  1849. isMainWindow = window.document === window.top.document
  1850. } catch (e) { }
  1851.  
  1852. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  1853. let headLinkCollection = null;
  1854.  
  1855. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  1856.  
  1857. const promiseForCustomYtElementsReady = isCustomElementsProvided ? null : new Promise((callback) => {
  1858. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1859. if (typeof customElements === 'undefined') {
  1860. if (!('__CE_registry' in document)) {
  1861. // https://github.com/webcomponents/polyfills/
  1862. Object.defineProperty(document, '__CE_registry', {
  1863. get() {
  1864. // return undefined
  1865. },
  1866. set(nv) {
  1867. if (typeof nv == 'object') {
  1868. delete this.__CE_registry;
  1869. this.__CE_registry = nv;
  1870. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1871. }
  1872. return true;
  1873. },
  1874. enumerable: false,
  1875. configurable: true
  1876. })
  1877. }
  1878. let eventHandler = (evt) => {
  1879. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1880. const f = callback;
  1881. callback = null;
  1882. eventHandler = null;
  1883. f();
  1884. };
  1885. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1886. } else {
  1887. callback();
  1888. }
  1889. });
  1890.  
  1891. const whenCEDefined = isCustomElementsProvided
  1892. ? (nodeName) => customElements.whenDefined(nodeName)
  1893. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  1894.  
  1895. // const assertor = (f) => f() || console.assert(false, f + "");
  1896.  
  1897. const fnIntegrity = (f, d) => {
  1898. if (!f || typeof f !== 'function') {
  1899. console.warn('f is not a function', f);
  1900. return;
  1901. }
  1902. let p = f + "", s = 0, j = -1, w = 0;
  1903. for (let i = 0, l = p.length; i < l; i++) {
  1904. const t = p[i];
  1905. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1906. if (j < i - 1) w++;
  1907. j = i;
  1908. } else {
  1909. s++;
  1910. }
  1911. }
  1912. let itz = `${f.length}.${s}.${w}`;
  1913. if (!d) {
  1914. return itz;
  1915. } else {
  1916. return itz === d;
  1917. }
  1918. };
  1919.  
  1920. const getZqOu = (_yt_player) => {
  1921.  
  1922. const w = 'ZqOu';
  1923.  
  1924. let arr = [];
  1925.  
  1926. for (const [k, v] of Object.entries(_yt_player)) {
  1927.  
  1928. const p = typeof v === 'function' ? v.prototype : 0;
  1929. if (p
  1930. && typeof p.start === 'function' && p.start.length === 0 // Ou
  1931. && typeof p.isActive === 'function' && p.isActive.length === 0
  1932. && typeof p.stop === 'function' && p.stop.length === 0
  1933. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  1934. && !p.send && !p.abort
  1935. && !p.sample && !p.initialize && !p.fail && !p.getName
  1936. // && !p.dispose && !p.isDisposed
  1937.  
  1938. ) {
  1939. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1940.  
  1941.  
  1942. }
  1943.  
  1944. }
  1945.  
  1946. if (arr.length === 0) {
  1947.  
  1948. console.warn(`Key does not exist. [${w}]`);
  1949. } else {
  1950.  
  1951. console.log(`[${w}]`, arr);
  1952. return arr[0];
  1953. }
  1954.  
  1955. }
  1956.  
  1957. const getZqQu = (_yt_player) => {
  1958.  
  1959. const w = 'ZqQu';
  1960.  
  1961. let arr = [];
  1962.  
  1963.  
  1964. for (const [k, v] of Object.entries(_yt_player)) {
  1965.  
  1966. const p = typeof v === 'function' ? v.prototype : 0;
  1967. if (p
  1968. && typeof p.start === 'function' && p.start.length === 1 // Qu
  1969. && typeof p.isActive === 'function' && p.isActive.length === 0
  1970. && typeof p.stop === 'function' && p.stop.length === 0
  1971. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  1972. && !p.send && !p.abort
  1973. && !p.sample && !p.initialize && !p.fail && !p.getName
  1974. // && !p.dispose && !p.isDisposed
  1975.  
  1976. ) {
  1977. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1978.  
  1979.  
  1980. }
  1981.  
  1982. }
  1983.  
  1984. if (arr.length === 0) {
  1985.  
  1986. console.warn(`Key does not exist. [${w}]`);
  1987. } else {
  1988.  
  1989. console.log(`[${w}]`, arr);
  1990. return arr[0];
  1991. }
  1992.  
  1993. }
  1994.  
  1995.  
  1996. const getVG = (_yt_player) => {
  1997. const w = 'VG';
  1998.  
  1999. let arr = [];
  2000.  
  2001. for (const [k, v] of Object.entries(_yt_player)) {
  2002.  
  2003. const p = typeof v === 'function' ? v.prototype : 0;
  2004. if (p
  2005. && typeof p.show === 'function' && p.show.length === 1
  2006. && typeof p.hide === 'function' && p.hide.length === 0
  2007. && typeof p.stop === 'function' && p.stop.length === 0) {
  2008.  
  2009. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2010.  
  2011. }
  2012.  
  2013. }
  2014.  
  2015.  
  2016. if (arr.length === 0) {
  2017.  
  2018. console.warn(`Key does not exist. [${w}]`);
  2019. } else {
  2020.  
  2021. console.log(`[${w}]`, arr);
  2022. return arr[0];
  2023. }
  2024.  
  2025.  
  2026.  
  2027. }
  2028.  
  2029.  
  2030. const getzo = (_yt_player) => {
  2031. const w = 'zo';
  2032.  
  2033. let arr = [];
  2034.  
  2035. for (const [k, v] of Object.entries(_yt_player)) {
  2036.  
  2037. if (
  2038. typeof v === 'function' && v.length === 3 && k.length < 3
  2039. && (v + "").includes("a.style[b]=c")
  2040. ) {
  2041.  
  2042. arr.push(k);
  2043.  
  2044. }
  2045.  
  2046. }
  2047.  
  2048.  
  2049. if (arr.length === 0) {
  2050.  
  2051. console.warn(`Key does not exist. [${w}]`);
  2052. } else {
  2053.  
  2054. console.log(`[${w}]`, arr);
  2055. return arr[0];
  2056. }
  2057.  
  2058. }
  2059.  
  2060. const addProtoToArr = (parent, key, arr) => {
  2061.  
  2062.  
  2063. let isChildProto = false;
  2064. for (const sr of arr) {
  2065. if (parent[key].prototype instanceof parent[sr]) {
  2066. isChildProto = true;
  2067. break;
  2068. }
  2069. }
  2070.  
  2071. if (isChildProto) return;
  2072.  
  2073. arr = arr.filter(sr => {
  2074. if (parent[sr].prototype instanceof parent[key]) {
  2075. return false;
  2076. }
  2077. return true;
  2078. });
  2079.  
  2080. arr.push(key);
  2081.  
  2082. return arr;
  2083.  
  2084.  
  2085. }
  2086.  
  2087. const getuG = (_yt_player) => {
  2088.  
  2089. const w = 'uG';
  2090.  
  2091. let arr = [];
  2092.  
  2093. for (const [k, v] of Object.entries(_yt_player)) {
  2094.  
  2095.  
  2096. const p = typeof v === 'function' ? v.prototype : 0;
  2097.  
  2098. if (p
  2099. && typeof p.createElement === 'function' && p.createElement.length === 2
  2100. && typeof p.detach === 'function' && p.detach.length === 0
  2101. && typeof p.update === 'function' && p.update.length === 1
  2102. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  2103. ) {
  2104.  
  2105. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2106.  
  2107. }
  2108.  
  2109. }
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115. if (arr.length === 0) {
  2116.  
  2117. console.warn(`Key does not exist. [${w}]`);
  2118. } else {
  2119.  
  2120. console.log(`[${w}]`, arr);
  2121. return arr[0];
  2122. }
  2123.  
  2124. }
  2125.  
  2126.  
  2127. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  2128.  
  2129. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  2130. let pageSetupState = 0;
  2131.  
  2132. isPrepareCachedV && (() => {
  2133.  
  2134. pageSetupVideoId = '';
  2135. const clearCachedV = () => {
  2136. pageSetupVideoId = '';
  2137. pageSetupState = 0;
  2138. }
  2139. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  2140. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  2141. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  2142. document.addEventListener('yt-navigate-finish', () => {
  2143. pageSetupState = 1;
  2144. try {
  2145. const url = new URL(location.href);
  2146. if (!url || url.pathname !== '/watch') {
  2147. pageSetupVideoId = '';
  2148. } else {
  2149. pageSetupVideoId = url.searchParams.get('v') || '';
  2150. }
  2151. } catch (e) {
  2152. pageSetupVideoId = '';
  2153. }
  2154. }, false);
  2155.  
  2156. })();
  2157.  
  2158. let videoPlayingY = null;
  2159.  
  2160. isPrepareCachedV && (() => {
  2161.  
  2162. let getNext = true;
  2163. let videoPlayingX = {
  2164. get videoId() {
  2165. if (getNext) {
  2166. getNext = false;
  2167.  
  2168. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  2169. const arr = [];
  2170. for (const element of elements) {
  2171. if (!element.closest('[hidden]')) arr.push(element);
  2172. }
  2173. if (arr.length !== 1) this.__videoId__ = '';
  2174. else {
  2175. this.__videoId__ = arr[0].getAttribute('video-id');
  2176. }
  2177.  
  2178. }
  2179. return this.__videoId__ || '';
  2180. }
  2181. }
  2182.  
  2183. videoPlayingY = videoPlayingX;
  2184. const handler = (evt) => {
  2185. const target = (evt || 0).target;
  2186. if (target instanceof HTMLVideoElement) {
  2187. getNext = true;
  2188. }
  2189. }
  2190. document.addEventListener('loadedmetadata', handler, true);
  2191. document.addEventListener('durationchange', handler, true);
  2192.  
  2193. })();
  2194.  
  2195.  
  2196.  
  2197. const cleanContext = async (win) => {
  2198. const waitFn = requestAnimationFrame; // shall have been binded to window
  2199. try {
  2200. let mx = 16; // MAX TRIAL
  2201. const frameId = 'vanillajs-iframe-v1';
  2202. /** @type {HTMLIFrameElement | null} */
  2203. let frame = document.getElementById(frameId);
  2204. let removeIframeFn = null;
  2205. if (!frame) {
  2206. frame = document.createElement('iframe');
  2207. frame.id = frameId;
  2208. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2209. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2210. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2211. n.appendChild(frame);
  2212. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2213. const root = document.documentElement;
  2214. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2215. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2216.  
  2217. removeIframeFn = (setTimeout) => {
  2218. const removeIframeOnDocumentReady = (e) => {
  2219. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2220. e = n;
  2221. n = win = removeIframeFn = 0;
  2222. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2223. }
  2224. if (!setTimeout || document.readyState !== 'loading') {
  2225. removeIframeOnDocumentReady();
  2226. } else {
  2227. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2228. }
  2229. }
  2230. }
  2231. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2232. const fc = frame.contentWindow;
  2233. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2234. try {
  2235. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  2236. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  2237. for (let k in res) res[k] = res[k].bind(win); // necessary
  2238. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2239. res.animate = fc.HTMLElement.prototype.animate;
  2240. res.perfNow = fc.performance.now;
  2241. return res;
  2242. } catch (e) {
  2243. if (removeIframeFn) removeIframeFn();
  2244. return null;
  2245. }
  2246. } catch (e) {
  2247. console.warn(e);
  2248. return null;
  2249. }
  2250. };
  2251.  
  2252. const promiseForYtActionCalled = new Promise(resolve => {
  2253. if (typeof AbortSignal !== 'undefined') {
  2254. let hn = () => {
  2255. if (!hn) return;
  2256. hn = null;
  2257. resolve(document.querySelector('ytd-app'));
  2258. };
  2259. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  2260. } else {
  2261. let hn = () => {
  2262. if (!hn) return;
  2263. document.removeEventListener('yt-action', hn, true);
  2264. hn = null;
  2265. resolve(document.querySelector('ytd-app'));
  2266. };
  2267. document.addEventListener('yt-action', hn, true);
  2268. }
  2269. });
  2270.  
  2271.  
  2272.  
  2273. cleanContext(window).then(__CONTEXT__ => {
  2274. if (!__CONTEXT__) return null;
  2275.  
  2276. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  2277.  
  2278.  
  2279. performance.now17 = perfNow.bind(performance);
  2280.  
  2281.  
  2282.  
  2283. __requestAnimationFrame__ = requestAnimationFrame;
  2284.  
  2285. let rafPromise = null;
  2286.  
  2287. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2288. requestAnimationFrame(hRes => {
  2289. rafPromise = null;
  2290. resolve(hRes);
  2291. });
  2292. }));
  2293.  
  2294.  
  2295. const wmComputedStyle = new WeakMap();
  2296.  
  2297. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  2298. window.__native__getComputedStyle__ = getComputedStyle;
  2299. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  2300. window.__original__getComputedStyle__ = window.getComputedStyle;
  2301. window.getComputedStyle = function (elem) {
  2302. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  2303. return window.__native__getComputedStyle__(...arguments);
  2304. }
  2305. let cs = wmComputedStyle.get(elem);
  2306. if (!cs) {
  2307. cs = window.__native__getComputedStyle__(elem);
  2308. wmComputedStyle.set(elem, cs);
  2309. }
  2310. return cs;
  2311. };
  2312. } else {
  2313. window.__original__getComputedStyle__ = null;
  2314. }
  2315. window.__jst__getComputedStyle__ = window.getComputedStyle;
  2316. }
  2317.  
  2318. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  2319. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  2320. window.getComputedStyle = window.__jst__getComputedStyle__;
  2321. }
  2322. });
  2323.  
  2324. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  2325. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  2326.  
  2327. const promiseForTamerTimeout = new Promise(resolve => {
  2328. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  2329. setTimeout(resolve, 480);
  2330. }, { capture: true, passive: true, once: true });
  2331. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  2332. setTimeout(resolve, 1200);
  2333. });
  2334. setTimeout(resolve, 3000);
  2335. });
  2336.  
  2337. const promiseForPageInitied = new Promise(resolve => {
  2338. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  2339. setTimeout(resolve, 450);
  2340. }, { capture: true, passive: true, once: true });
  2341. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  2342. setTimeout(resolve, 900);
  2343. });
  2344. setTimeout(resolve, 1800);
  2345. });
  2346.  
  2347. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  2348. NO_PRELOAD_GENERATE_204_BYPASS = true;
  2349. headLinkCollection = null;
  2350. });
  2351.  
  2352.  
  2353. NATIVE_CANVAS_ANIMATION && (() => {
  2354.  
  2355. observablePromise(() => {
  2356. HTMLCanvasElement.prototype.animate = animate;
  2357. }, promiseForTamerTimeout).obtain();
  2358.  
  2359. })();
  2360.  
  2361. FIX_ytAction_ && (async () => {
  2362.  
  2363. const ytdApp = await new Promise(resolve => {
  2364.  
  2365. whenCEDefined('ytd-app').then(() => {
  2366. const ytdApp = document.querySelector('ytd-app');
  2367. if (ytdApp) {
  2368. resolve(ytdApp);
  2369. return;
  2370. }
  2371. let mo = new MutationObserver(() => {
  2372. const ytdApp = document.querySelector('ytd-app');
  2373. if (!ytdApp) return;
  2374. if (mo) {
  2375. mo.disconnect();
  2376. mo.takeRecords();
  2377. mo = null;
  2378. }
  2379. resolve(ytdApp);
  2380. });
  2381. mo.observe(document, { subtree: true, childList: true });
  2382. });
  2383.  
  2384. });
  2385.  
  2386. if (!ytdApp) return;
  2387. const cProto = insp(ytdApp).constructor.prototype;
  2388.  
  2389. if (!cProto) return;
  2390. let mbd = 0;
  2391.  
  2392. const fixer = (_ytdApp) => {
  2393. const ytdApp = insp(_ytdApp);
  2394. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  2395. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  2396. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  2397. mbd++;
  2398. }
  2399. }
  2400.  
  2401. observablePromise(() => {
  2402.  
  2403. if (typeof cProto.created === 'function' && !cProto.created56) {
  2404. cProto.created56 = cProto.created;
  2405. cProto.created = function (...args) {
  2406. const r = this.created56(...args);
  2407. fixer(this);
  2408. return r;
  2409. };
  2410. mbd++;
  2411. }
  2412.  
  2413. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  2414. cProto.onYtAction57_ = cProto.onYtAction_;
  2415. cProto.onYtAction_ = function (...args) {
  2416. Promise.resolve().then(() => this.onYtAction57_(...args));
  2417. };
  2418. mbd++;
  2419. }
  2420.  
  2421. if (ytdApp) fixer(ytdApp);
  2422.  
  2423. /*
  2424. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  2425. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  2426. actionRouter_.handleAction57 = actionRouter_.handleAction;
  2427. actionRouter_.handleAction = function (...args) {
  2428. Promise.resolve().then(() => this.handleAction57(...args));
  2429. }
  2430. mbd++;
  2431. }
  2432. */
  2433.  
  2434. // if(mbd === 3) return 1;
  2435. if (mbd >= 3) return 1;
  2436.  
  2437. }, new Promise(r => setTimeout(r, 1000))).obtain();
  2438.  
  2439. })();
  2440.  
  2441. const observablePromise = (proc, timeoutPromise) => {
  2442. let promise = null;
  2443. return {
  2444. obtain() {
  2445. if (!promise) {
  2446. promise = new Promise(resolve => {
  2447. let mo = null;
  2448. const f = () => {
  2449. let t = proc();
  2450. if (t) {
  2451. mo.disconnect();
  2452. mo.takeRecords();
  2453. mo = null;
  2454. resolve(t);
  2455. }
  2456. }
  2457. mo = new MutationObserver(f);
  2458. mo.observe(document, { subtree: true, childList: true })
  2459. f();
  2460. timeoutPromise && timeoutPromise.then(() => {
  2461. resolve(null)
  2462. });
  2463. });
  2464. }
  2465. return promise
  2466. }
  2467. }
  2468. }
  2469.  
  2470. // let _yt_player_promise = null;
  2471. /*
  2472. const getYtPlayerPromise = () => {
  2473. if (!_yt_player_promise) {
  2474. _yt_player_promise = new Promise(resolve => {
  2475. let cid = setInterval(() => {
  2476. let t = (((window || 0)._yt_player || 0) || 0);
  2477. if (t) {
  2478. clearInterval(cid);
  2479. resolve(t);
  2480. }
  2481. }, 1);
  2482. promiseForTamerTimeout.then(() => {
  2483. resolve(null)
  2484. });
  2485. });
  2486. }
  2487. return _yt_player_promise;
  2488. }
  2489. */
  2490. const _yt_player_observable = observablePromise(() => {
  2491. return (((window || 0)._yt_player || 0) || 0);
  2492. }, promiseForTamerTimeout);
  2493.  
  2494. const polymerObservable = observablePromise(() => {
  2495. const Polymer = window.Polymer;
  2496. if (typeof Polymer !== 'function') return;
  2497. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  2498. return Polymer;
  2499. }, promiseForTamerTimeout);
  2500.  
  2501. const schedulerInstanceObservable = observablePromise(() => {
  2502. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2503. }, promiseForTamerTimeout);
  2504.  
  2505. const timelineObservable = observablePromise(() => {
  2506. let t = (((document || 0).timeline || 0) || 0);
  2507. if (t && typeof t._play === 'function') {
  2508. return t;
  2509. }
  2510. }, promiseForTamerTimeout);
  2511. const animationObservable = observablePromise(() => {
  2512. let t = (((window || 0).Animation || 0) || 0);
  2513. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  2514. return t;
  2515. }
  2516. }, promiseForTamerTimeout);
  2517.  
  2518.  
  2519.  
  2520.  
  2521. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  2522.  
  2523. const evKey = `${_evKey}`;
  2524. const fvKey = `${_fvKey}`;
  2525. const debug = !!_debug;
  2526.  
  2527. const _yt_player = await _yt_player_observable.obtain();
  2528.  
  2529.  
  2530. if (!_yt_player || typeof _yt_player !== 'object') return;
  2531.  
  2532.  
  2533. const getArr = (_yt_player) => {
  2534.  
  2535. let arr = [];
  2536.  
  2537. for (const [k, v] of Object.entries(_yt_player)) {
  2538.  
  2539. const p = typeof v === 'function' ? v.prototype : 0;
  2540. if (p
  2541. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  2542.  
  2543. ) {
  2544. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2545.  
  2546. }
  2547.  
  2548. }
  2549.  
  2550. if (arr.length === 0) {
  2551.  
  2552. console.warn(`Key prop [${evKey}] does not exist.`);
  2553. } else {
  2554.  
  2555. return arr;
  2556. }
  2557.  
  2558. };
  2559.  
  2560. const arr = getArr(_yt_player);
  2561.  
  2562.  
  2563. if (!arr) return;
  2564.  
  2565. debug && console.log(`FIX_${evKey}`, arr);
  2566.  
  2567. const f = function (...args) {
  2568. Promise.resolve().then(() => this[fvKey](...args));
  2569. };
  2570.  
  2571.  
  2572. for (const k of arr) {
  2573.  
  2574. const g = _yt_player;
  2575. const gk = g[k];
  2576. const gkp = gk.prototype;
  2577.  
  2578. debug && console.log(237, k, gkp)
  2579.  
  2580. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  2581. gkp[fvKey] = gkp[evKey];
  2582. gkp[evKey] = f;
  2583. }
  2584. }
  2585.  
  2586.  
  2587.  
  2588.  
  2589. }
  2590.  
  2591. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  2592. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  2593. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  2594. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  2595. if (FIX_VideoEVENTS_v2) {
  2596. const FIX_VideoEVENTS_DEBUG = 0;
  2597. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  2598. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  2599. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  2600. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  2601. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  2602. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  2603. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  2604. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  2605. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  2606.  
  2607. }
  2608. // onMutedAutoplayChange
  2609. // onVolumeChange
  2610. // onPlaybackRateChange
  2611.  
  2612. // onAirPlayActiveChange
  2613. // onAirPlayAvailabilityChange
  2614. // onApiChange
  2615. // onAutoplayBlocked
  2616. // onDrmOutputRestricted
  2617. // onFullscreenChange
  2618. // onLoadProgress
  2619. // onLoadedMetadata
  2620. // onVideoDataChange
  2621. // onVideoProgress
  2622.  
  2623.  
  2624. (ENABLE_discreteTasking || UNLOAD_DETACHED_POLYMER) && (async () => {
  2625.  
  2626. const Polymer = await polymerObservable.obtain();
  2627. if (!Polymer) return;
  2628.  
  2629.  
  2630. if (UNLOAD_DETACHED_POLYMER && typeof Polymer.Base.detached === 'function' && !Polymer.Base.detached92 && Polymer.Base.detached.length === 0) {
  2631. Polymer.Base.detached92 = Polymer.Base.detached;
  2632.  
  2633. const detachedPlus = async function (elem) {
  2634. await delay300.then();
  2635. if (elem.isAttached !== false) return;
  2636. await delay300.then();
  2637. if (elem.isAttached !== false) return;
  2638.  
  2639. if (elem.__dataClientsReady === true) elem.__dataClientsReady = false;
  2640. // if (elem.__dataEnabled === true) elem.__dataEnabled = false;
  2641. if (elem.__dataReady === true) elem.__dataReady = false;
  2642.  
  2643. elem.__dataLinkedPaths = elem.__dataToNotify = elem.__dataPendingClients = null;
  2644. elem.__dataHasPaths = false;
  2645. // elem.__dataCompoundStorage = null;
  2646. elem.__dataHost = null;
  2647. elem.__dataTemp = null;
  2648. elem.__dataClientsInitialized = false;
  2649.  
  2650.  
  2651. // elem.data = {};
  2652. elem.data = null;
  2653. elem.__dataPending = null;
  2654. elem.__dataOld = null;
  2655. elem.__dataInstanceProps = null;
  2656.  
  2657. elem.__dataCounter = 0;
  2658. elem.__serializing = false;
  2659.  
  2660. }
  2661. Polymer.Base.detached = function () {
  2662. Promise.resolve(this).then(detachedPlus);
  2663. return Polymer.Base.detached92();
  2664. };
  2665. }
  2666.  
  2667.  
  2668. if (ENABLE_discreteTasking) {
  2669.  
  2670. Polymer.Base.__connInit__ = function () {
  2671. setupDiscreteTasks(this);
  2672. // if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  2673. // setupWeakRef(this)
  2674. // }
  2675. }
  2676.  
  2677.  
  2678. /** @type {Function} */
  2679. const connectedCallbackK = function (...args) {
  2680. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2681. const r = this[qm53](...args);
  2682. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2683. this.mh35 = 1;
  2684. return r;
  2685. };
  2686.  
  2687. connectedCallbackK.m353 = 1;
  2688.  
  2689.  
  2690. const qt53 = Polymer.Base.connectedCallback;
  2691. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  2692.  
  2693. Polymer.Base.connectedCallback = connectedCallbackK;
  2694.  
  2695.  
  2696. /** @type {Function} */
  2697. const createdK = function (...args) {
  2698. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2699. const r = this[qn53](...args);
  2700. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2701. this.mh36 = 1;
  2702. return r;
  2703. };
  2704.  
  2705.  
  2706. createdK.m353 = 1;
  2707. Polymer.Base[qn53] = Polymer.Base.created;
  2708. Polymer.Base.created = createdK;
  2709.  
  2710. }
  2711.  
  2712. })();
  2713.  
  2714.  
  2715. /*
  2716.  
  2717. e.nativeAppendChild = d.prototype.appendChild,
  2718. d.prototype.appendChild = function(h) {
  2719. return function(l) {
  2720. if (l instanceof DocumentFragment) {
  2721. var m = Array.from(l.children);
  2722. l = h.nativeAppendChild.call(this, l);
  2723. if (this.isConnected) {
  2724. m = g(m);
  2725. for (var p = m.next(); !p.done; p = m.next())
  2726. YD(p.value)
  2727. }
  2728. return l
  2729. }
  2730. m = l instanceof Element && l.isConnected;
  2731. p = h.nativeAppendChild.call(this, l);
  2732. m && ZD(l);
  2733. this.isConnected && YD(l);
  2734. return p
  2735. }
  2736. }(e),
  2737.  
  2738. */
  2739.  
  2740. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  2741.  
  2742. let __src__ = '';
  2743. const handlerCanplay = (evt) => {
  2744. const a = evt.target;
  2745. console.log('[yt-js-engine-tamer]', `video element added to dom | canplay`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  2746. if (a.currentTime < 1e-8 && a.currentTime > -1e-9 && a.autoplay === false) a.currentTime += 1e-8;
  2747. };
  2748.  
  2749. const handlerTimeupdate = (evt) => {
  2750. const a = evt.target;
  2751. console.log('[yt-js-engine-tamer]', `video element added to dom | ontimeupdate`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  2752. if (a.duration < 2.01 && a.duration > 1.99 && a.currentSrc === __src__) {
  2753. try {
  2754. URL.revokeObjectURL(__src__);
  2755. __src__ = '';
  2756. } finally {
  2757. console.log('[yt-js-engine-tamer]', `video element added to dom | revokeObjectURL`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  2758. }
  2759. }
  2760. };
  2761.  
  2762. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  2763. if (f) Node.prototype.appendChild = function (a) {
  2764. if (this instanceof Element) { // exclude DocumentFragment
  2765. try {
  2766. if (a instanceof HTMLVideoElement && FIX_VIDEO_BLOCKING) {
  2767. const src = `${a.src}`;
  2768. 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';
  2769. if (b) {
  2770. __src__ = src;
  2771. a.addEventListener('canplay', handlerCanplay, { once: true, passive: true, capture: false });
  2772. a.addEventListener('timeupdate', handlerTimeupdate, { once: true, passive: true, capture: false });
  2773. }
  2774. console.log('[yt-js-engine-tamer]', `video element added to dom | treatment = ${b}`, mWeakRef(a), a.readyState, a.networkState);
  2775. } else {
  2776. let checkFragmentA = true;
  2777. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  2778. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  2779. for (const node of headLinkCollection) {
  2780. if (node.rel === 'preload' && node.as === 'fetch') {
  2781. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  2782. }
  2783. }
  2784. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  2785. checkFragmentA = false;
  2786. }
  2787. if ((a instanceof DocumentFragment) && checkFragmentA && a.firstElementChild === null) {
  2788. // no element in fragmentA
  2789. let doNormal = false;
  2790. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  2791. if (child.nodeType === 3) { doNormal = true; break; }
  2792. }
  2793. if (!doNormal) return a;
  2794. }
  2795. }
  2796. } catch (e) {
  2797. console.log(e);
  2798. }
  2799. }
  2800. return arguments.length === 1 && this.appendChild73 ? this.appendChild73(a) : (this.appendChild73 || Node.prototype.appendChild73 || f).apply(this, arguments);
  2801. }
  2802.  
  2803.  
  2804. })();
  2805.  
  2806. if (FIX_Shady) {
  2807.  
  2808. observablePromise(() => {
  2809. const { ShadyDOM, ShadyCSS } = window;
  2810. if (ShadyDOM) {
  2811. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  2812. ShadyDOM.noPatch = true; // 1 of 10
  2813. ShadyDOM.patchOnDemand = false; // 1 of 10
  2814. ShadyDOM.preferPerformance = true; // 1 of 10
  2815. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  2816. }
  2817. if (ShadyCSS) {
  2818. ShadyCSS.nativeCss = true; // 1 of 10
  2819. ShadyCSS.nativeShadow = true; // 6 of 10
  2820. ShadyCSS.cssBuild = undefined; // 1 of 10
  2821. ShadyCSS.disableRuntime = true; // 1 of 10
  2822. }
  2823. if (ShadyDOM && ShadyCSS) return 1;
  2824. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  2825.  
  2826. }
  2827.  
  2828.  
  2829. // let schedulerInstancePropOfTimerType = '';
  2830. // let schedulerInstancePropOfTimerId = '';
  2831. (FIX_schedulerInstanceInstance & 2) && (async () => {
  2832.  
  2833. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  2834.  
  2835. if (!schedulerInstanceInstance_) return;
  2836.  
  2837. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2838. if (checkOK) {
  2839.  
  2840. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  2841.  
  2842. let requestingFn = null;
  2843. let requestingArgs = null;
  2844.  
  2845. const f = function () {
  2846. requestingFn = this.fn;
  2847. requestingArgs = [...arguments];
  2848. return 12373;
  2849. };
  2850.  
  2851. const fakeFns = [
  2852. f.bind({ fn: requestAnimationFrame }),
  2853. f.bind({ fn: setInterval }),
  2854. f.bind({ fn: setTimeout }),
  2855. f.bind({ fn: requestIdleCallback })
  2856. ];
  2857.  
  2858. let mzt = 0;
  2859.  
  2860. let _fnSelectorProp = null;
  2861. const mkFns = new Array(4);
  2862.  
  2863. /*
  2864. case 1:
  2865. var a = this.K;
  2866. this.g = this.I ? window.requestIdleCallback(a, {
  2867. timeout: 3E3
  2868. }) : window.setTimeout(a, ma);
  2869. break;
  2870. case 2:
  2871. this.g = window.setTimeout(this.M, this.N);
  2872. break;
  2873. case 3:
  2874. this.g = window.requestAnimationFrame(this.L);
  2875. break;
  2876. case 4:
  2877. this.g = window.setTimeout(this.J, 0)
  2878. }
  2879.  
  2880. */
  2881. const startFnHandler = {
  2882. get(target, prop, receiver) {
  2883. if (prop === '$$12377$$') return true;
  2884. if (prop === '$$12378$$') return target;
  2885.  
  2886. // console.log('get',prop)
  2887. return target[prop]
  2888. },
  2889. set(target, prop, value, receiver) {
  2890. // console.log('set', prop, value)
  2891.  
  2892. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  2893. if (value === 12373 && _fnSelectorProp) {
  2894.  
  2895. const schedulerTypeSelection = target[_fnSelectorProp];
  2896. const timerIdProp = prop;
  2897.  
  2898. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  2899. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  2900. // schedulerInstancePropOfTimerId = timerIdProp || '';
  2901. // }
  2902.  
  2903. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  2904. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  2905. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  2906. // rare
  2907. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  2908. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  2909. // often
  2910. if ((FIX_schedulerInstanceInstance & 4) && typeof nextBrowserTick == 'function') {
  2911. const f = requestingArgs[0];
  2912. const tir = ++mzt;
  2913. nextBrowserTick(() => {
  2914. if (target[timerIdProp] === -tir) f();
  2915. });
  2916. target[_fnSelectorProp] = 940;
  2917. target[timerIdProp] = -tir;
  2918. } else {
  2919. const f = requestingArgs[0];
  2920. const tir = ++mzt;
  2921. Promise.resolve().then(() => {
  2922. if (target[timerIdProp] === -tir) f();
  2923. });
  2924. target[_fnSelectorProp] = 930;
  2925. target[timerIdProp] = -tir;
  2926. }
  2927. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  2928. // often
  2929. if (requestingFn === requestIdleCallback) {
  2930. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  2931. } else {
  2932. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  2933. }
  2934. } else {
  2935. target[_fnSelectorProp] = 0;
  2936. target[timerIdProp] = 0;
  2937. }
  2938. } else {
  2939. target[prop] = value;
  2940. }
  2941. return true;
  2942. }
  2943. };
  2944.  
  2945. let startBusy = false;
  2946. schedulerInstanceInstance_.start = function () {
  2947. if (startBusy) return;
  2948. startBusy = true;
  2949. try {
  2950. mkFns[0] = window.requestAnimationFrame;
  2951. mkFns[1] = window.setInterval;
  2952. mkFns[2] = window.setTimeout;
  2953. mkFns[3] = window.requestIdleCallback;
  2954. const tThis = this['$$12378$$'] || this;
  2955. window.requestAnimationFrame = fakeFns[0]
  2956. window.setInterval = fakeFns[1]
  2957. window.setTimeout = fakeFns[2]
  2958. window.requestIdleCallback = fakeFns[3]
  2959. _fnSelectorProp = null;
  2960. tThis.start993.call(new Proxy(tThis, startFnHandler));
  2961. _fnSelectorProp = null;
  2962. window.requestAnimationFrame = mkFns[0];
  2963. window.setInterval = mkFns[1];
  2964. window.setTimeout = mkFns[2];
  2965. window.requestIdleCallback = mkFns[3];
  2966. } catch (e) {
  2967. console.warn(e);
  2968. }
  2969. startBusy = false;
  2970. }
  2971.  
  2972. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  2973.  
  2974. }
  2975. })();
  2976.  
  2977. FIX_yt_player && (async () => {
  2978. // rAf scheduling
  2979.  
  2980. const _yt_player = await _yt_player_observable.obtain();
  2981.  
  2982. if (!_yt_player || typeof _yt_player !== 'object') return;
  2983.  
  2984. let keyZqOu = getZqOu(_yt_player);
  2985.  
  2986.  
  2987. if (!keyZqOu) return;
  2988.  
  2989.  
  2990. const g = _yt_player
  2991. let k = keyZqOu
  2992.  
  2993. const gk = g[k];
  2994. if (typeof gk !== 'function') return;
  2995. const gkp = gk.prototype;
  2996.  
  2997. let dummyObject = new gk;
  2998. let nilFunc = () => { };
  2999.  
  3000. let nilObj = {};
  3001.  
  3002. // console.log(1111111111)
  3003.  
  3004. let keyBoolD = '';
  3005. let keyWindow = '';
  3006. let keyFuncC = '';
  3007. let keyCidj = '';
  3008.  
  3009. for (const [t, y] of Object.entries(dummyObject)) {
  3010. if (y instanceof Window) keyWindow = t;
  3011. }
  3012.  
  3013. const dummyObjectProxyHandler = {
  3014. get(target, prop) {
  3015. let v = target[prop]
  3016. if (v instanceof Window && !keyWindow) {
  3017. keyWindow = t;
  3018. }
  3019. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  3020. if (prop === keyWindow) y = {
  3021. requestAnimationFrame(f) {
  3022. return 3;
  3023. },
  3024. cancelAnimationFrame() {
  3025.  
  3026. }
  3027. }
  3028. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  3029. keyFuncC = prop;
  3030. }
  3031. // console.log('[get]', prop, typeof target[prop])
  3032.  
  3033.  
  3034. return y;
  3035. },
  3036. set(target, prop, value) {
  3037.  
  3038. if (typeof value === 'boolean' && !keyBoolD) {
  3039. keyBoolD = prop;
  3040. }
  3041. if (typeof value === 'number' && !keyCidj && value >= 2) {
  3042. keyCidj = prop;
  3043. }
  3044.  
  3045. // console.log('[set]', prop, value)
  3046. target[prop] = value
  3047.  
  3048. return true;
  3049. }
  3050. };
  3051.  
  3052. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  3053.  
  3054. // console.log('gkp.start',gkp.start);
  3055. // console.log('gkp.stop',gkp.stop);
  3056. gkp._activation = false;
  3057.  
  3058. gkp.start = function () {
  3059. // p59 || console.log(12100)
  3060. if (!this._activation) {
  3061. this._activation = true;
  3062. getRafPromise().then(() => {
  3063. this._activation = false;
  3064. if (this[keyCidj]) {
  3065. Promise.resolve().then(this[keyFuncC]);
  3066. }
  3067. });
  3068. }
  3069. this[keyCidj] = 1;
  3070. this[keyBoolD] = true;
  3071. }
  3072. ;
  3073. gkp.stop = function () {
  3074. this[keyCidj] = null
  3075. }
  3076.  
  3077.  
  3078. /*
  3079. g[k].start = function() {
  3080. this.stop();
  3081. this.D = true;
  3082. var a = requestAnimationFrame
  3083. , b = cancelAnimationFrame;
  3084. this.j = a.call(this.B, this.C)
  3085. }
  3086. ;
  3087. g[k].stop = function() {
  3088. if (this.isActive()) {
  3089. var a = requestAnimationFrame
  3090. , b = cancelAnimationFrame;
  3091. b.call(this.B, this.j)
  3092. }
  3093. this.j = null
  3094. }
  3095. */
  3096.  
  3097. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  3098.  
  3099. if (keyzo) {
  3100.  
  3101. k = keyzo;
  3102.  
  3103. const attrUpdateFn = g[k];
  3104. // console.log(5992, attrUpdateFn)
  3105. g['$$original$$' + k] = attrUpdateFn;
  3106. const zoTransform = async (a, c) => {
  3107.  
  3108. let transformType = '';
  3109. let transformValue = 0;
  3110. let transformUnit = '';
  3111. let transformTypeI = 0;
  3112.  
  3113. const aStyle = a.style;
  3114.  
  3115. if (c.length < 9) {
  3116.  
  3117. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  3118. let p = c.substring(7, c.length - 1);
  3119. let q = p.length >= 1 ? parseFloat(p) : -1;
  3120. if (q > -1e-5 && q < 1 + 1e-5) {
  3121. transformType = 'scaleX'
  3122. transformValue = q;
  3123. transformUnit = '';
  3124. transformTypeI = 1;
  3125. }
  3126. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  3127. let p = c.substring(11, c.length - 3);
  3128. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3129. if (typeof q === 'number' && !isNaN(q)) {
  3130. transformType = 'translateX'
  3131. transformValue = q;
  3132. transformUnit = 'px';
  3133. transformTypeI = 2;
  3134. } else if (p === 'NaN') {
  3135. return;
  3136. }
  3137. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  3138. let p = c.substring(7, c.length - 1);
  3139. let q = p.length >= 1 ? parseFloat(p) : -1;
  3140. if (q > -1e-5 && q < 1 + 1e-5) {
  3141. transformType = 'scaleY'
  3142. transformValue = q;
  3143. transformUnit = '';
  3144. transformTypeI = 1;
  3145. }
  3146. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  3147. let p = c.substring(11, c.length - 3);
  3148. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3149. if (typeof q === 'number' && !isNaN(q)) {
  3150. transformType = 'translateY'
  3151. transformValue = q;
  3152. transformUnit = 'px';
  3153. transformTypeI = 2;
  3154. } else if (p === 'NaN') {
  3155. return;
  3156. }
  3157. } else if (c.startsWith('scalex(') && c.includes('e-')) {
  3158. // scalex(1.252057684158767e-16)
  3159. // scalex(3.0393632069734948e-9)
  3160. let p = c.substring(7, c.length - 1);
  3161. let q = p.length >= 1 ? parseFloat(p) : -1;
  3162. if (q > -1e-5 && q < 1e-5) {
  3163. transformType = 'scaleX'
  3164. transformValue = 0;
  3165. transformUnit = '';
  3166. transformTypeI = 1;
  3167. }
  3168. } else if (c.startsWith('scaley(') && c.includes('e-')) {
  3169. let p = c.substring(7, c.length - 1);
  3170. let q = p.length >= 1 ? parseFloat(p) : -1;
  3171. if (q > -1e-5 && q < 1e-5) {
  3172. transformType = 'scaleY'
  3173. transformValue = 0;
  3174. transformUnit = '';
  3175. transformTypeI = 1;
  3176. }
  3177. }
  3178.  
  3179. if (transformTypeI === 1) {
  3180. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  3181. const vz = toFixed2(q, 3);
  3182. c = `${transformType}(${vz})`;
  3183. const cv = aStyle.transform;
  3184. if (c === cv) return;
  3185. aStyle.transform = c;
  3186. } else if (transformTypeI === 2) {
  3187. const q = transformValue;
  3188. const vz = toFixed2(q, 1);
  3189. c = `${transformType}(${vz}${transformUnit})`;
  3190. const cv = aStyle.transform;
  3191. if (c === cv) return;
  3192. aStyle.transform = c;
  3193. } else { // eg empty
  3194. const cv = aStyle.transform;
  3195. if (!c && !cv) return;
  3196. else if (c === cv) return;
  3197. aStyle.transform = c;
  3198. }
  3199.  
  3200. };
  3201.  
  3202. const elmTransformTemp = new WeakMap();
  3203. const elmPropTemps = {
  3204. 'display': new WeakMap(),
  3205. 'width': new WeakMap(),
  3206. 'height': new WeakMap(),
  3207. 'outlineWidth': new WeakMap(),
  3208. 'position': new WeakMap(),
  3209. 'padding': new WeakMap(),
  3210. "cssText": new WeakMap(),
  3211. "right": new WeakMap(),
  3212. "left": new WeakMap(),
  3213. "top": new WeakMap(),
  3214. "bottom": new WeakMap(),
  3215. "transitionDelay": new WeakMap(),
  3216. "marginLeft": new WeakMap(),
  3217. "marginTop": new WeakMap(),
  3218. "marginRight": new WeakMap(),
  3219. "marginBottom": new WeakMap(),
  3220. }
  3221.  
  3222. const ns5 = Symbol();
  3223. const nextModify = (a, c, m, f, immediate) => {
  3224. const a_ = a;
  3225. const m_ = m;
  3226. const noKey = !m_.has(a_);
  3227. if (immediate || noKey) {
  3228. m_.set(a_, ns5);
  3229. f(a_, c);
  3230. noKey && nextBrowserTick_(() => {
  3231. const d = m_.get(a_);
  3232. if (d === undefined) return;
  3233. m_.delete(a_);
  3234. if (d !== ns5) f(a_, d);
  3235. });
  3236. } else {
  3237. m_.set(a_, c);
  3238. }
  3239. };
  3240.  
  3241. const set66 = new Set();
  3242. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  3243.  
  3244. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  3245.  
  3246. // console.log(140000, a, b, c);
  3247. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement) {
  3248. const num = c;
  3249. c = `${num}`;
  3250. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  3251. }
  3252.  
  3253. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement) {
  3254.  
  3255. let elmPropTemp = null;
  3256.  
  3257. if (b === "transform") {
  3258.  
  3259. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  3260. return;
  3261.  
  3262. } else if (elmPropTemp = elmPropTemps[b]) {
  3263.  
  3264. // if (c.length > 5 && c.includes('.')) {
  3265. // console.log(123213, c)
  3266. // }
  3267.  
  3268. const b_ = b;
  3269. nextModify(a, c, elmPropTemp, (a, c) => {
  3270. const style = a.style;
  3271. const cv = style[b_];
  3272. if (!cv && !c) return;
  3273. if (cv === c) return;
  3274. style[b_] = c;
  3275. }, immediateChange);
  3276. return;
  3277.  
  3278. } else if (b === "outline-width") {
  3279.  
  3280. const b_ = 'outlineWidth';
  3281. elmPropTemp = elmPropTemps[b_];
  3282. nextModify(a, c, elmPropTemp, (a, c) => {
  3283. const style = a.style;
  3284. const cv = style[b_];
  3285. if (!cv && !c) return;
  3286. if (cv === c) return;
  3287. style[b_] = c;
  3288. }, immediateChange);
  3289. return;
  3290.  
  3291. } else if (b === 'maxWidth' || b === 'maxHeight') {
  3292. // I think these can be directly assigned.
  3293.  
  3294. const b_ = b;
  3295. const style = a.style;
  3296. const cv = style[b_];
  3297. if (!cv && !c) return;
  3298. if (cv === c) return;
  3299. style[b_] = c;
  3300. return;
  3301.  
  3302. } else {
  3303. // if(immediate && elmPropTemps[b]){
  3304. // console.log(5191, b)
  3305. // }
  3306. // caption-window
  3307. // margin-left max-height max-width font-family fill color font-size background white-space margin
  3308. // text-align background-color
  3309. // console.log(27304, a, b, c)
  3310. if (!set66.has(b)) {
  3311. set66.add(b);
  3312. nextBrowserTick_(() => {
  3313. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  3314. console.log(27304, a, b, c)
  3315. }
  3316. })
  3317. }
  3318. }
  3319.  
  3320. attrUpdateFn.call(this, a, b, c);
  3321. return;
  3322. } else if (typeof (b || 0) === 'object') {
  3323.  
  3324. // this is to fix caption positioning
  3325. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  3326. const immediate = (a.id || 0).length > 14;
  3327. for (const [k, v] of Object.entries(b)) {
  3328. modifiedFn.call(this, a, k, v, immediate);
  3329. }
  3330.  
  3331. } else {
  3332. console.log(27306, a, b, c);
  3333.  
  3334. attrUpdateFn.call(this, a, b, c);
  3335. return;
  3336. }
  3337.  
  3338. // console.log(130000, a, b, c);
  3339.  
  3340. };
  3341. g[k] = modifiedFn;
  3342.  
  3343.  
  3344. /*
  3345.  
  3346. g.zo = function(a, b, c) {
  3347. if ("string" === typeof b)
  3348. (b = yo(a, b)) && (a.style[b] = c);
  3349. else
  3350. for (var d in b) {
  3351. c = a;
  3352. var e = b[d]
  3353. , f = yo(c, d);
  3354. f && (c.style[f] = e)
  3355. }
  3356. }
  3357.  
  3358.  
  3359. */
  3360.  
  3361.  
  3362. }
  3363.  
  3364.  
  3365.  
  3366. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  3367.  
  3368. if (keyuG) {
  3369.  
  3370. k = keyuG;
  3371.  
  3372. const gk = g[k];
  3373. const gkp = gk.prototype;
  3374.  
  3375.  
  3376. /** @type { Map<string, WeakMap<any, any>> } */
  3377. const ntLogs = new Map();
  3378.  
  3379. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  3380.  
  3381. gkp.updateValue31 = gkp.updateValue;
  3382. gkp.updateValue = function (a, b) {
  3383. if (typeof a !== 'string') return this.updateValue31(a, b);
  3384.  
  3385. const element = this.element;
  3386. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  3387.  
  3388. let ntLog = ntLogs.get(a);
  3389. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  3390.  
  3391. let cache = ntLog.get(element);
  3392. if (cache && cache.value === b) {
  3393. return;
  3394. }
  3395. if (!cache) {
  3396. this.__oldValueByUpdateValue__ = null;
  3397. ntLog.set(element, cache = { value: b });
  3398. } else {
  3399. this.__oldValueByUpdateValue__ = cache.value;
  3400. cache.value = b;
  3401. }
  3402.  
  3403. return this.updateValue31(a, b);
  3404. }
  3405.  
  3406. /*
  3407. g.k.update = function(a) {
  3408. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  3409. c = c.value,
  3410. this.updateValue(c, a[c])
  3411. }
  3412. ;
  3413. g.k.updateValue = function(a, b) {
  3414. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  3415. }
  3416. */
  3417.  
  3418. }
  3419.  
  3420.  
  3421. }
  3422.  
  3423.  
  3424.  
  3425.  
  3426. })();
  3427.  
  3428. FIX_yt_player && (async () => {
  3429. // timer scheduling
  3430.  
  3431. const _yt_player = await _yt_player_observable.obtain();
  3432.  
  3433. if (!_yt_player || typeof _yt_player !== 'object') return;
  3434.  
  3435. let keyZqQu = getZqQu(_yt_player);
  3436.  
  3437. if (!keyZqQu) return;
  3438.  
  3439. const g = _yt_player
  3440. let k = keyZqQu
  3441.  
  3442. const gk = g[k];
  3443. if (typeof gk !== 'function') return;
  3444. const gkp = gk.prototype;
  3445.  
  3446. const extractKeysZqQu = () => {
  3447.  
  3448.  
  3449. let _keyeC = '';
  3450. try {
  3451. gkp.stop.call(new Proxy({
  3452. isActive: () => { }
  3453. }, {
  3454. set(target, prop, value) {
  3455. if (value === 0) _keyeC = prop;
  3456. return true;
  3457. }
  3458. }));
  3459. } catch (e) { }
  3460. if (!_keyeC) return;
  3461. const keyeC = _keyeC;
  3462.  
  3463. let keyC = ''; // this.C = this.ST.bind(this)
  3464. let keyhj = ''; // 1000ms
  3465. try {
  3466. gkp.start.call(new Proxy({
  3467. stop: () => { },
  3468. [keyeC]: 0,
  3469. }, {
  3470. get(target, prop) {
  3471. if (prop in target) return target[prop];
  3472. if (!keyC) {
  3473. keyC = prop;
  3474. return null; // throw error
  3475. }
  3476. else if (!keyhj) {
  3477. keyhj = prop;
  3478. }
  3479.  
  3480. }
  3481. }));
  3482. } catch (e) {
  3483. if (!keyC || !keyhj) {
  3484. console.log(e)
  3485. }
  3486. }
  3487.  
  3488. if (!keyC || !keyhj) return;
  3489. let keyST = '';
  3490. let keyj = '';
  3491. let keyB = '';
  3492. let keyxa = '';
  3493.  
  3494. const possibleKs = new Set();
  3495.  
  3496. for (const [k, v] of Object.entries(gkp)) {
  3497. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  3498. continue;
  3499. }
  3500. if (typeof v === 'function') {
  3501. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  3502. if (m) {
  3503. keyST = k;
  3504. keyj = m[1];
  3505. keyB = m[2];
  3506. } else {
  3507. possibleKs.add(k);
  3508. }
  3509. }
  3510. }
  3511.  
  3512. if (!keyST || !keyj || !keyB) return;
  3513.  
  3514. for (const k of possibleKs) {
  3515. if (k === keyST || k === keyj || k === keyB) {
  3516. continue;
  3517. }
  3518. const v = gkp[k];
  3519. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  3520. keyxa = k;
  3521. }
  3522. }
  3523.  
  3524. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  3525.  
  3526. }
  3527.  
  3528. const keys = extractKeysZqQu();
  3529. if (!keys || !keys.length) return;
  3530. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  3531.  
  3532. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  3533.  
  3534. let disposeKeys = null;
  3535.  
  3536. gkp[keyxa] = function () {
  3537. // dispose
  3538. if (!disposeKeys) {
  3539. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  3540. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  3541. const t = typeof this[key];
  3542. return t === 'undefined' || t === 'object'
  3543. }
  3544. return false;
  3545. });
  3546. }
  3547. for (const key of disposeKeys) {
  3548. const v = this[key];
  3549. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  3550. }
  3551. if (this[keyeC] > 0) this.stop();
  3552. this[keyj] = null;
  3553. this[keyB] = null;
  3554. };
  3555.  
  3556. gkp.start = function (a) {
  3557. if (this[keyeC] > 0) this.stop();
  3558. const delay = void 0 !== a ? a : this[keyhj];
  3559. this[keyeC] = window.setTimeout(this[keyC], delay);
  3560. };
  3561. gkp.stop = function () {
  3562. if (this[keyeC] > 0) {
  3563. window.clearTimeout(this[keyeC]);
  3564. this[keyeC] = 0;
  3565. }
  3566. };
  3567.  
  3568. gkp.isActive = function () {
  3569. return this[keyeC] > 0;
  3570. };
  3571.  
  3572. gkp[keyST] = function () {
  3573. this.stop(); // this[keyeC] = 0;
  3574. const fn = this[keyj];
  3575. const obj = this[keyB];
  3576. let skip = false;
  3577. if (!fn) skip = true;
  3578. else if (IGNORE_bufferhealth_CHECK && obj) {
  3579. let m;
  3580. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  3581. if (m.has("bufferhealth")) skip = true;
  3582. }
  3583. }
  3584. if (!skip) {
  3585. fn.call(obj);
  3586. }
  3587. };
  3588.  
  3589.  
  3590.  
  3591.  
  3592. /*
  3593.  
  3594. g.k.eC = 0;
  3595. g.k.xa = function() {
  3596. g.Qu.Vf.xa.call(this);
  3597. this.stop();
  3598. delete this.j;
  3599. delete this.B
  3600. }
  3601. ;
  3602. g.k.start = function(a) {
  3603. this.stop();
  3604. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  3605. }
  3606. ;
  3607. g.k.stop = function() {
  3608. this.isActive() && g.Sa.clearTimeout(this.eC);
  3609. this.eC = 0
  3610. }
  3611. ;
  3612. g.k.isActive = function() {
  3613. return 0 != this.eC
  3614. }
  3615. ;
  3616. g.k.ST = function() {
  3617. this.eC = 0;
  3618. this.j && this.j.call(this.B)
  3619. }
  3620. ;
  3621. */
  3622.  
  3623.  
  3624.  
  3625.  
  3626. })();
  3627.  
  3628. FIX_Animation_n_timeline && (async () => {
  3629.  
  3630. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  3631.  
  3632. if (!timeline || !Animation) return;
  3633.  
  3634. const aniProto = Animation.prototype;
  3635. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  3636.  
  3637. const getXroto = (x) => {
  3638. try {
  3639. return x.__proto__;
  3640. } catch (e) { }
  3641. return null;
  3642. }
  3643. const timProto = getXroto(timeline);
  3644. if (!timProto) return;
  3645. if (
  3646. (
  3647. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  3648. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  3649. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  3650. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  3651. )
  3652.  
  3653. ) {
  3654.  
  3655. timProto.nofCQ = 1;
  3656. aniProto.nofYH = 1;
  3657.  
  3658. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  3659.  
  3660.  
  3661. /*
  3662. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3663. return c._updatePromises();
  3664. });
  3665. */
  3666.  
  3667. const p = Array.prototype.filter;
  3668.  
  3669. let res = null;
  3670. Array.prototype.filter = function () {
  3671.  
  3672. res = this;
  3673. return this;
  3674.  
  3675. };
  3676.  
  3677. _updateAnimationsPromises.call({});
  3678.  
  3679. Array.prototype.filter = p;
  3680.  
  3681. if (res && typeof res.length === 'number') {
  3682. /** @type {any[]} */
  3683. const _res = res;
  3684. return _res;
  3685. }
  3686.  
  3687.  
  3688. return null;
  3689.  
  3690.  
  3691.  
  3692.  
  3693. })(timProto._updateAnimationsPromises);
  3694.  
  3695. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  3696.  
  3697. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  3698.  
  3699. aniProto._updatePromises31 = aniProto._updatePromises;
  3700.  
  3701. /*
  3702. aniProto._updatePromises = function(){
  3703. console.log('eff',this._oldPlayState, this.playState)
  3704. return this._updatePromises31.apply(this, arguments)
  3705. }
  3706. */
  3707.  
  3708. aniProto._updatePromises = function () {
  3709. var oldPlayState = this._oldPlayState;
  3710. var newPlayState = this.playState;
  3711. // console.log('ett', oldPlayState, newPlayState)
  3712. if (newPlayState !== oldPlayState) {
  3713. this._oldPlayState = newPlayState;
  3714. if (this._readyPromise) {
  3715. if ("idle" == newPlayState) {
  3716. this._rejectReadyPromise();
  3717. this._readyPromise = void 0;
  3718. } else if ("pending" == oldPlayState) {
  3719. this._resolveReadyPromise();
  3720. } else if ("pending" == newPlayState) {
  3721. this._readyPromise = void 0;
  3722. }
  3723. }
  3724. if (this._finishedPromise) {
  3725. if ("idle" == newPlayState) {
  3726. this._rejectFinishedPromise();
  3727. this._finishedPromise = void 0;
  3728. } else if ("finished" == newPlayState) {
  3729. this._resolveFinishedPromise();
  3730. } else if ("finished" == oldPlayState) {
  3731. this._finishedPromise = void 0;
  3732. }
  3733. }
  3734. }
  3735. return this._readyPromise || this._finishedPromise;
  3736. };
  3737.  
  3738.  
  3739. let restartWebAnimationsNextTickFlag = false;
  3740.  
  3741. const looperMethodT = () => {
  3742.  
  3743. const runnerFn = (hRes) => {
  3744. var b = timeline;
  3745. b.currentTime = hRes;
  3746. b._discardAnimations();
  3747. if (0 == b._animations.length) {
  3748. restartWebAnimationsNextTickFlag = false;
  3749. } else {
  3750. getRafPromise().then(runnerFn);
  3751. }
  3752. }
  3753.  
  3754. const restartWebAnimationsNextTick = () => {
  3755. if (!restartWebAnimationsNextTickFlag) {
  3756. restartWebAnimationsNextTickFlag = true;
  3757. getRafPromise().then(runnerFn);
  3758. }
  3759. }
  3760.  
  3761. return { restartWebAnimationsNextTick }
  3762. };
  3763.  
  3764.  
  3765. const looperMethodN = () => {
  3766.  
  3767. const acs = document.createElement('a-f');
  3768. acs.id = 'a-f';
  3769.  
  3770. if (!document.getElementById('afscript')) {
  3771. const style = document.createElement('style');
  3772. style.id = 'afscript';
  3773. style.textContent = `
  3774. @keyFrames aF1 {
  3775. 0% {
  3776. order: 0;
  3777. }
  3778. 100% {
  3779. order: 1;
  3780. }
  3781. }
  3782. #a-f[id] {
  3783. visibility: collapse !important;
  3784. position: fixed !important;
  3785. display: block !important;
  3786. top: -100px !important;
  3787. left: -100px !important;
  3788. margin:0 !important;
  3789. padding:0 !important;
  3790. outline:0 !important;
  3791. border:0 !important;
  3792. z-index:-1 !important;
  3793. width: 0px !important;
  3794. height: 0px !important;
  3795. contain: strict !important;
  3796. pointer-events: none !important;
  3797. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  3798. }
  3799. `;
  3800. (document.head || document.documentElement).appendChild(style);
  3801. }
  3802.  
  3803. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  3804.  
  3805. const _onanimationiteration = function (evt) {
  3806. const hRes = evt.timeStamp;
  3807. var b = timeline;
  3808. b.currentTime = hRes;
  3809. b._discardAnimations();
  3810. if (0 == b._animations.length) {
  3811. restartWebAnimationsNextTickFlag = false;
  3812. acs.onanimationiteration = null;
  3813. } else {
  3814. acs.onanimationiteration = _onanimationiteration;
  3815. }
  3816.  
  3817. }
  3818.  
  3819.  
  3820.  
  3821. const restartWebAnimationsNextTick = () => {
  3822. if (!restartWebAnimationsNextTickFlag) {
  3823. restartWebAnimationsNextTickFlag = true;
  3824. acs.onanimationiteration = _onanimationiteration;
  3825.  
  3826. }
  3827. }
  3828.  
  3829. return { restartWebAnimationsNextTick }
  3830. };
  3831.  
  3832.  
  3833.  
  3834. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  3835.  
  3836.  
  3837. // console.log(571, timProto);
  3838. timProto._play = function (c) {
  3839. c = new Animation(c, this);
  3840. this._animations.push(c);
  3841. restartWebAnimationsNextTick();
  3842. c._updatePromises();
  3843. c._animation.play();
  3844. c._updatePromises();
  3845. return c
  3846. }
  3847.  
  3848. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  3849. originalAnimationsWithPromises.length = 0;
  3850. originalAnimationsWithPromises.push = null;
  3851. originalAnimationsWithPromises.splice = null;
  3852. originalAnimationsWithPromises.slice = null;
  3853. originalAnimationsWithPromises.indexOf = null;
  3854. originalAnimationsWithPromises.unshift = null;
  3855. originalAnimationsWithPromises.shift = null;
  3856. originalAnimationsWithPromises.pop = null;
  3857. originalAnimationsWithPromises.filter = null;
  3858. originalAnimationsWithPromises.forEach = null;
  3859. originalAnimationsWithPromises.map = null;
  3860.  
  3861.  
  3862. const _updateAnimationsPromises = () => {
  3863. animationsWithPromisesMap.forEach(c => {
  3864. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  3865. });
  3866. /*
  3867. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3868. return c._updatePromises();
  3869. });
  3870. */
  3871. }
  3872.  
  3873. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  3874.  
  3875. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  3876.  
  3877. delete timProto._updateAnimationsPromises;
  3878. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  3879. get() {
  3880. if (animationsWithPromisesMap.size === 0) return nilFn;
  3881. return _updateAnimationsPromises;
  3882. },
  3883. set(nv) {
  3884. delete this._updateAnimationsPromises;
  3885. this._updateAnimationsPromises = nv;
  3886. },
  3887. enumerable: true,
  3888. configurable: true,
  3889. });
  3890.  
  3891.  
  3892. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  3893. aniProto.__finished_native_get__ = pdFinished.get;
  3894. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  3895.  
  3896.  
  3897. Object.defineProperty(aniProto, 'finished', {
  3898. get() {
  3899. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3900. this._finishedPromise = new Promise((resolve, reject) => {
  3901. this._resolveFinishedPromise = function () {
  3902. resolve(this)
  3903. };
  3904. this._rejectFinishedPromise = function () {
  3905. reject({
  3906. type: DOMException.ABORT_ERR,
  3907. name: "AbortError"
  3908. })
  3909. };
  3910. }),
  3911. "finished" == this.playState && this._resolveFinishedPromise());
  3912. return this._finishedPromise
  3913. },
  3914. set: undefined,
  3915. enumerable: true,
  3916. configurable: true
  3917. });
  3918.  
  3919. }
  3920.  
  3921.  
  3922.  
  3923. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  3924. aniProto.__ready_native_get__ = pdReady.get;
  3925. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  3926.  
  3927. Object.defineProperty(aniProto, 'ready', {
  3928. get() {
  3929. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3930. this._readyPromise = new Promise((resolve, reject) => {
  3931. this._resolveReadyPromise = function () {
  3932. resolve(this)
  3933. };
  3934. this._rejectReadyPromise = function () {
  3935. reject({
  3936. type: DOMException.ABORT_ERR,
  3937. name: "AbortError"
  3938. })
  3939. };
  3940. }),
  3941. "pending" !== this.playState && this._resolveReadyPromise());
  3942. return this._readyPromise
  3943. },
  3944. set: undefined,
  3945. enumerable: true,
  3946. configurable: true
  3947. });
  3948.  
  3949. }
  3950.  
  3951.  
  3952. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  3953.  
  3954. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  3955. const _rebuildUnderlyingAnimation = function () {
  3956. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  3957. this.effect && this.effect._onsample && (this.effect._onsample = null);
  3958. return this._rebuildUnderlyingAnimation21();
  3959. }
  3960. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  3961. // delete aniProto._rebuildUnderlyingAnimation;
  3962. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  3963. // get() {
  3964. // if (isNaN(this._sequenceNumber)) return nilFn;
  3965. // return this._rebuildUnderlyingAnimation21;
  3966. // },
  3967. // set(nv) {
  3968. // delete this._rebuildUnderlyingAnimation;
  3969. // this._rebuildUnderlyingAnimation = nv;
  3970. // },
  3971. // enumerable: true,
  3972. // configurable: true
  3973. // });
  3974. }
  3975.  
  3976.  
  3977. /*
  3978.  
  3979.  
  3980. function f(c) {
  3981. var b = v.timeline;
  3982. b.currentTime = c;
  3983. b._discardAnimations();
  3984. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  3985. }
  3986. var h = window.requestAnimationFrame;
  3987. window.requestAnimationFrame = function(c) {
  3988. return h(function(b) {
  3989. v.timeline._updateAnimationsPromises();
  3990. c(b);
  3991. v.timeline._updateAnimationsPromises()
  3992. })
  3993. }
  3994. ;
  3995. v.AnimationTimeline = function() {
  3996. this._animations = [];
  3997. this.currentTime = void 0
  3998. }
  3999. ;
  4000. v.AnimationTimeline.prototype = {
  4001. getAnimations: function() {
  4002. this._discardAnimations();
  4003. return this._animations.slice()
  4004. },
  4005. _updateAnimationsPromises: function() {
  4006. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  4007. return c._updatePromises()
  4008. })
  4009. },
  4010. _discardAnimations: function() {
  4011. this._updateAnimationsPromises();
  4012. this._animations = this._animations.filter(function(c) {
  4013. return "finished" != c.playState && "idle" != c.playState
  4014. })
  4015. },
  4016. _play: function(c) {
  4017. c = new v.Animation(c,this);
  4018. this._animations.push(c);
  4019. v.restartWebAnimationsNextTick();
  4020. c._updatePromises();
  4021. c._animation.play();
  4022. c._updatePromises();
  4023. return c
  4024. },
  4025. play: function(c) {
  4026. c && c.remove();
  4027. return this._play(c)
  4028. }
  4029. };
  4030. var d = !1;
  4031. v.restartWebAnimationsNextTick = function() {
  4032. d || (d = !0,
  4033. requestAnimationFrame(f))
  4034. }
  4035. ;
  4036. var a = new v.AnimationTimeline;
  4037. v.timeline = a;
  4038. try {
  4039. Object.defineProperty(window.document, "timeline", {
  4040. configurable: !0,
  4041. get: function() {
  4042. return a
  4043. }
  4044. })
  4045. } catch (c) {}
  4046. try {
  4047. window.document.timeline = a
  4048. } catch (c) {}
  4049.  
  4050. */
  4051.  
  4052.  
  4053.  
  4054. /*
  4055.  
  4056. var g = window.getComputedStyle;
  4057. Object.defineProperty(window, "getComputedStyle", {
  4058. configurable: !0,
  4059. enumerable: !0,
  4060. value: function() {
  4061. v.timeline._updateAnimationsPromises();
  4062. var e = g.apply(this, arguments);
  4063. h() && (e = g.apply(this, arguments));
  4064. v.timeline._updateAnimationsPromises();
  4065. return e
  4066. }
  4067. });
  4068.  
  4069. */
  4070.  
  4071.  
  4072.  
  4073.  
  4074. }
  4075.  
  4076.  
  4077.  
  4078.  
  4079. })();
  4080.  
  4081. !isUrlInEmbed && Promise.resolve().then(() => {
  4082.  
  4083. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  4084.  
  4085.  
  4086.  
  4087. class LimitedSizeSet extends Set {
  4088. constructor(n) {
  4089. super();
  4090.  
  4091. this.limit = n;
  4092. }
  4093.  
  4094. add(key) {
  4095. if (!super.has(key)) {
  4096. super.add(key); // Set the key with a dummy value (true)
  4097. while (super.size > this.limit) {
  4098. const firstKey = super.values().next().value; // Get the first (oldest) key
  4099. super.delete(firstKey); // Delete the oldest key
  4100. }
  4101. }
  4102. }
  4103.  
  4104. removeAdd(key) {
  4105. super.delete(key);
  4106. super.add(key);
  4107. }
  4108.  
  4109. }
  4110.  
  4111. // const wk3 = new WeakMap();
  4112.  
  4113. // let mtxVideoId = '';
  4114. // let aje3 = [];
  4115. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  4116. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  4117. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  4118. let mtzCount = 0; // the key keeps unchanged
  4119. // let mjtNextMainKey = '';
  4120. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  4121. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  4122. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  4123. // let allowNoDelay322=false;
  4124. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  4125.  
  4126. let mpKey22 = ''; // last success continutation key & url pair
  4127. let mpUrl22 = ''; // last success continutation key & url pair
  4128. let mpKey21 = ''; // latest requested continutation key & url pair
  4129. let mpUrl21 = ''; // latest requested continutation key & url pair
  4130.  
  4131.  
  4132. async function sha1Hex(message) {
  4133. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  4134. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  4135. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  4136. const hashHex = hashArray
  4137. .map((b) => b.toString(16).padStart(2, "0"))
  4138. .join(""); // convert bytes to hex string
  4139. return hashHex;
  4140. }
  4141.  
  4142. async function continuationLog(a, ...args) {
  4143. let b = a;
  4144. try {
  4145. if (advanceLogging) b = await sha1Hex(a);
  4146. let c = args.map(e => {
  4147. return e === a ? b : e
  4148. });
  4149. console.log(...c)
  4150. } catch (e) { console.warn(e) }
  4151. }
  4152.  
  4153. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  4154.  
  4155.  
  4156. if (mfvContinuationRecorded.length > 0) {
  4157. for (const [e, d] of mfvContinuationRecorded) {
  4158. mfyContinuationIgnored.removeAdd(e);
  4159. }
  4160. toClearRecorded && mfvContinuationRecorded.clear();
  4161. }
  4162.  
  4163. }
  4164.  
  4165. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  4166.  
  4167. const tmProto = taskMgr.constructor.prototype;
  4168. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  4169.  
  4170. if (!tmProto.addJob714) {
  4171.  
  4172. tmProto.addJob714 = tmProto.addJob;
  4173.  
  4174. tmProto.addJob = function (a, b, c) {
  4175. const jobId = this.addJob714(a, b, c);
  4176. if (jobId > 0) {
  4177. // const ez = wk3.get(this);
  4178. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  4179. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  4180.  
  4181. this.__lastJobId863__ = jobId;
  4182. }
  4183. return jobId;
  4184. }
  4185.  
  4186. }
  4187.  
  4188. if (!tmProto.cancelJob714) {
  4189.  
  4190. tmProto.cancelJob714 = tmProto.cancelJob;
  4191.  
  4192. tmProto.cancelJob = function (a) {
  4193. const res = this.cancelJob714(a);
  4194. // if (a > 0) {
  4195. // for (const e of aje3) {
  4196. // if (e.jobId === a) e.cancelled = true;
  4197. // }
  4198. // }
  4199. return res;
  4200. }
  4201.  
  4202. }
  4203.  
  4204. }
  4205. }
  4206.  
  4207.  
  4208. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order;
  4209.  
  4210.  
  4211. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  4212. let dummy;
  4213. let cProto;
  4214. // let mc = 4;
  4215. // dummy = await observablePromise(() => {
  4216. // const r = document.querySelector('ytd-video-primary-info-renderer');
  4217. // if (!r) return;
  4218. // let cProto = insp(r).constructor.prototype;
  4219. // if (cProto.fetchUpdatedMetadata) return r;
  4220. // if (--mc < 0) return -1;
  4221. // return null;
  4222. // }).obtain();
  4223. dummy = document.createElement('ytd-video-primary-info-renderer');
  4224. if (!(dummy instanceof Element)) return;
  4225. // console.log(5022, dummy)
  4226. cProto = insp(dummy).constructor.prototype;
  4227.  
  4228. cProto.__getEmittorTaskMgr859__ = function () {
  4229. let taskMgr_ = null;
  4230. try {
  4231. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  4232. } catch (e) { }
  4233. return taskMgr_;
  4234. }
  4235. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  4236. // console.log(1234, cProto, cProto.is)
  4237. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  4238.  
  4239. let c_;
  4240. cProto.fetchUpdatedMetadata718 = function (a) {
  4241. // delay or immediate call the actual fetchUpdatedMetadata
  4242.  
  4243. let doImmediately = false;
  4244. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  4245.  
  4246. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  4247.  
  4248. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  4249.  
  4250. doImmediately = true;
  4251.  
  4252. }
  4253.  
  4254. if (mbCId322) {
  4255. clearTimeout(mbCId322);
  4256. mbCId322 = 0;
  4257. }
  4258.  
  4259. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  4260.  
  4261. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  4262.  
  4263. mbCId322 = setTimeout(() => {
  4264. this.fetchUpdatedMetadata717(a);
  4265. }, delay);
  4266.  
  4267. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  4268.  
  4269. }
  4270.  
  4271. cProto.fetchUpdatedMetadata = function (a) {
  4272.  
  4273. if (!pageSetupState) {
  4274. if (c_) clearTimeout(c_);
  4275. c_ = setTimeout(() => {
  4276. this.fetchUpdatedMetadata718(a);
  4277. }, 300);
  4278. return;
  4279. }
  4280.  
  4281. // pageSetupState == 0
  4282.  
  4283. try {
  4284.  
  4285. mbDelayBelowNCalls++;
  4286.  
  4287. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  4288. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  4289. }
  4290.  
  4291. // console.log('fum377', a)
  4292. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  4293. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  4294. return;
  4295. }
  4296.  
  4297. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  4298. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  4299. mjtLockPreviousKey = mjtRecordedPrevKey;
  4300. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  4301. }
  4302. // mjtNextMainKey = true;
  4303. mtzlastAllowedContinuation = '';
  4304. mtzCount = 0;
  4305. // allowNoDelay322 = false;
  4306. // fetch new metadata, cancel all previous continuations
  4307. copyPreviousContiuationToIgnored374(true);
  4308. } else if (typeof a === 'string') {
  4309. const videoPlayingId = videoPlayingY.videoId;
  4310.  
  4311. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  4312.  
  4313. let update21 = !!pageSetupVideoId;
  4314. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  4315. update21 = true;
  4316. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  4317. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  4318. return;
  4319. }
  4320. if (update21) {
  4321. mpKey21 = a;
  4322. mpUrl21 = pageSetupVideoId || videoPlayingId;
  4323. }
  4324.  
  4325. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  4326. }
  4327. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  4328. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  4329. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  4330. return this.fetchUpdatedMetadata718(a);
  4331.  
  4332. } catch (e) {
  4333. console.log('Code Error in fetchUpdatedMetadata', e);
  4334. }
  4335. return this.fetchUpdatedMetadata717(a)
  4336. }
  4337. }
  4338.  
  4339.  
  4340. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  4341. // console.log(1234, cProto, cProto.is)
  4342. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  4343. let mJob = null;
  4344.  
  4345. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  4346.  
  4347. try {
  4348.  
  4349. if (arguments.length > 0) {
  4350. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  4351. }
  4352. // mfy = mfv;
  4353.  
  4354. // mjtNextMainKey = '';
  4355. mtzlastAllowedContinuation = '';
  4356. mtzCount = 0;
  4357. if (mbCId322) {
  4358. clearTimeout(mbCId322);
  4359. mbCId322 = 0;
  4360. }
  4361. mbDelayBelowNCalls = 0;
  4362. // allowNoDelay322 = false;
  4363. copyPreviousContiuationToIgnored374(true);
  4364.  
  4365. const taskMgr = this.__getEmittorTaskMgr859__();
  4366. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  4367. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  4368. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  4369. }
  4370.  
  4371. // prevent depulicated schedule job by clearing previous JobId
  4372. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  4373.  
  4374. let res;
  4375.  
  4376. if (mJob) {
  4377. const job = mJob;
  4378. mJob = null;
  4379. console.log('cancelJob', job)
  4380. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  4381. // p.cancelJob(a,b);
  4382. }
  4383.  
  4384. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  4385.  
  4386. let pza = taskMgr.__lastJobId863__;
  4387. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  4388. let pzb = taskMgr.__lastJobId863__
  4389. if (pza !== pzb) {
  4390. mJob = pzb; // set [Interval Meta Update] jobId
  4391. }
  4392.  
  4393. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  4394. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  4395. // } else {
  4396. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  4397. // }
  4398.  
  4399. return res;
  4400.  
  4401. } else {
  4402. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  4403. }
  4404.  
  4405. } catch (e) {
  4406. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  4407. }
  4408.  
  4409.  
  4410. return this.scheduleInitialUpdatedMetadataRequest717();
  4411. }
  4412. }
  4413.  
  4414.  
  4415. });
  4416.  
  4417. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  4418. let dummy;
  4419. let cProto;
  4420. dummy = ytAppDom;
  4421. if (!(dummy instanceof Element)) return;
  4422. cProto = insp(dummy).constructor.prototype;
  4423. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  4424. // console.log(1234, cProto, cProto.is);
  4425. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  4426. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  4427. // console.log(123401, arguments);
  4428. // return this.handleServiceRequest717_(a, b, c, d);
  4429. // }
  4430.  
  4431. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  4432.  
  4433. // cProto.handleServiceRequest_ = function(a,b,c,d){
  4434. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  4435. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  4436. // console.log('mfv', c.continuation);
  4437. // mfv.add( c.continuation);
  4438. // }
  4439. // return this.handleServiceRequest717_(a,b,c,d);
  4440. // }
  4441.  
  4442. function extraArguments322(a, b, c) {
  4443. let is = (a || 0).is;
  4444. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  4445. let continuation = (c || 0).continuation;
  4446. if (typeof is !== 'string') is = null;
  4447. if (typeof videoId !== 'string') videoId = null;
  4448. if (typeof continuation !== 'string') continuation = null;
  4449. return { is, videoId, continuation };
  4450. }
  4451.  
  4452. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  4453. cProto.sendServiceAjax_ = function (a, b, c, d) {
  4454.  
  4455. // console.log(8001)
  4456. try {
  4457.  
  4458. const { is, videoId, continuation } = extraArguments322(a, b, c);
  4459.  
  4460. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  4461. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  4462. }
  4463.  
  4464. if (pageSetupVideoId && videoId && continuation) {
  4465. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  4466. mfyContinuationIgnored.removeAdd(continuation);
  4467. mfvContinuationRecorded.delete(continuation);
  4468. return;
  4469. }
  4470. }
  4471.  
  4472. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  4473. copyPreviousContiuationToIgnored374(false);
  4474. mfyContinuationIgnored.delete(continuation);
  4475. mfvContinuationRecorded.removeAdd(continuation);
  4476. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  4477. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  4478. mjtLockPreviousKey = '';
  4479. }
  4480. // if (mjtNextMainKey === continuation) {
  4481. // copyPreviousContiuationToIgnored(false);
  4482. // mfyContinuationIgnored.delete(continuation);
  4483. // mfvContinuationRecorded.add(continuation);
  4484. // }
  4485.  
  4486.  
  4487. if (mfyContinuationIgnored && continuation) {
  4488. if (mfyContinuationIgnored.has(continuation)) {
  4489. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  4490. return;
  4491. }
  4492. }
  4493.  
  4494. // console.log(59902, a?.is, b,c,d)
  4495. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  4496. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  4497. // console.log('mfv377', continuation);
  4498. mfvContinuationRecorded.add(continuation);
  4499. }
  4500.  
  4501. // if (videoId) {
  4502. // if (!pageSetupVideoId) return; // ignore page not ready
  4503. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  4504. // if (videoId !== pageSetupVideoId) {
  4505. // return;
  4506. // }
  4507. // }
  4508.  
  4509. } catch (e) {
  4510. console.log('Coding Error in sendServiceAjax_', e)
  4511. }
  4512. // console.log(8002)
  4513. // console.log(123402, arguments);
  4514. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  4515.  
  4516. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  4517. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  4518. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  4519. // get(target, prop, receiver){
  4520. // console.log('xxs99', target.videoId, mtx)
  4521. // if(prop ==='kdkw33') return 1;
  4522. // console.log(3322, prop, target)
  4523. // if(prop === 'initialDelayMs') {
  4524. // throw new Error("ABCC");
  4525. // }
  4526. // return target[prop];
  4527. // },
  4528. // set(target, prop, value, receiver){
  4529.  
  4530. // if(prop ==='kdkw33') return true;
  4531. // target[prop]=value;
  4532. // return true;
  4533. // }
  4534. // });
  4535. // }
  4536. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  4537. return this.sendServiceAjax717_(a, b, c, d);
  4538. }
  4539. }
  4540.  
  4541. function delayClearOtherKeys(lztContinuation) {
  4542. // // schedule delayed removal if mfyContinuationIgnored is not empty
  4543. // getRafPromise().then(() => {
  4544. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  4545. // // foreground page only
  4546.  
  4547. // });
  4548.  
  4549.  
  4550. if (lztContinuation !== mtzlastAllowedContinuation) return;
  4551. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  4552. if (!mfyContinuationIgnored.size) return;
  4553. if (mfyContinuationIgnored.size > 1) {
  4554. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  4555. }
  4556. mfyContinuationIgnored.forEach((value, key) => {
  4557. if (key !== lztContinuation) {
  4558. mfyContinuationIgnored.delete(key);
  4559. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  4560. }
  4561. });
  4562.  
  4563. }
  4564. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  4565. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  4566. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  4567.  
  4568. // console.log(8003)
  4569. try {
  4570.  
  4571.  
  4572. const { is, videoId, continuation } = extraArguments322(b, c, d);
  4573.  
  4574. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  4575. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  4576. }
  4577.  
  4578. if (pageSetupVideoId && videoId && continuation) {
  4579. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  4580. mfyContinuationIgnored.removeAdd(continuation);
  4581. mfvContinuationRecorded.delete(continuation);
  4582. return;
  4583. }
  4584. }
  4585.  
  4586. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  4587. copyPreviousContiuationToIgnored374(false);
  4588. mfyContinuationIgnored.delete(continuation);
  4589. mfvContinuationRecorded.removeAdd(continuation);
  4590. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  4591. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  4592. mjtLockPreviousKey = '';
  4593. }
  4594.  
  4595. // if (mjtNextMainKey === continuation) {
  4596. // copyPreviousContiuationToIgnored(false);
  4597. // mfyContinuationIgnored.delete(continuation);
  4598. // mfvContinuationRecorded.add(continuation);
  4599. // }
  4600.  
  4601. const lztContinuation = continuation;
  4602.  
  4603. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  4604. if (mfyContinuationIgnored.has(lztContinuation)) {
  4605. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  4606. return;
  4607. }
  4608. }
  4609.  
  4610. // if (videoId) {
  4611. // if (!pageSetupVideoId) return; // ignore page not ready
  4612. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  4613. // if (videoId !== pageSetupVideoId) {
  4614. // return;
  4615. // }
  4616. // }
  4617.  
  4618. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  4619. mtzlastAllowedContinuation = lztContinuation;
  4620. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  4621.  
  4622. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  4623. mjtRecordedPrevKey = lztContinuation;
  4624. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  4625. // if (mfyContinuationIgnored.size > 0) {
  4626. // delayClearOtherKeys(lztContinuation);
  4627. // }
  4628. mtzCount = 0;
  4629. // allowNoDelay322 = false;
  4630. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  4631. // repeated
  4632. if (mtzCount > 1e9) mtzCount = 1e4;
  4633. ++mtzCount;
  4634. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  4635.  
  4636. // if (mtzCount >= 3) allowNoDelay322 = true;
  4637. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  4638. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  4639. }
  4640. if (mtzCount === 5) {
  4641. mfvContinuationRecorded.clear();
  4642. mfvContinuationRecorded.add(lztContinuation);
  4643. }
  4644.  
  4645. }
  4646.  
  4647. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  4648. mpKey22 = lztContinuation;
  4649. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  4650. }
  4651.  
  4652. if (mbCId322) {
  4653. clearTimeout(mbCId322);
  4654. mbCId322 = 0;
  4655. }
  4656. } catch (e) {
  4657. console.log('Coding Error in getCancellableNetworkPromise_', e)
  4658. }
  4659.  
  4660. // console.log(8004)
  4661. // console.log(123403, arguments);
  4662. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  4663.  
  4664. // console.log(5163, a?.is,b,c,d,e);
  4665. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  4666. }
  4667. }
  4668. });
  4669.  
  4670. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  4671.  
  4672.  
  4673. FIX_ytdExpander_childrenChanged && whenCEDefined('ytd-expander').then(() => {
  4674.  
  4675. let dummy;
  4676. let cProto;
  4677.  
  4678. dummy = document.createElement('ytd-expander');
  4679. cProto = insp(dummy).constructor.prototype;
  4680.  
  4681. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  4682.  
  4683. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  4684. cProto.childrenChanged14 = cProto.childrenChanged;
  4685.  
  4686. cProto.initChildrenObserver = function () {
  4687. var a = this;
  4688. this.observer = new MutationObserver(function () {
  4689. a.childrenChanged()
  4690. }
  4691. );
  4692. this.observer.observe(this.content, {
  4693. subtree: !0,
  4694. childList: !0,
  4695. attributes: !0,
  4696. characterData: !0
  4697. });
  4698. this.childrenChanged()
  4699. }
  4700. ;
  4701. cProto.childrenChanged = function () {
  4702. if (this.alwaysToggleable) {
  4703. this.canToggle = this.alwaysToggleable;
  4704. } else if (!this.canToggleJobId) {
  4705. this.canToggleJobId = 1;
  4706. getRafPromise().then(() => {
  4707. this.canToggleJobId = 0;
  4708. this.calculateCanCollapse()
  4709. })
  4710. }
  4711. }
  4712.  
  4713. // console.log(cProto.initChildrenObserver)
  4714. console.debug('ytd-expander-fix-childrenChanged');
  4715.  
  4716. }
  4717.  
  4718. });
  4719.  
  4720.  
  4721. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  4722.  
  4723. let dummy;
  4724. let cProto;
  4725. dummy = document.createElement('paper-ripple');
  4726. cProto = insp(dummy).constructor.prototype;
  4727.  
  4728. if (fnIntegrity(cProto.animate, '0.74.5')) {
  4729.  
  4730.  
  4731. cProto.animate34 = cProto.animate;
  4732. cProto.animate = function () {
  4733. if (this._animating) {
  4734. var a;
  4735. const ripples = this.ripples;
  4736. for (a = 0; a < ripples.length; ++a) {
  4737. var b = ripples[a];
  4738. b.draw();
  4739. this.$.background.style.opacity = b.outerOpacity;
  4740. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  4741. }
  4742. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  4743. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  4744. getRafPromise().then(this._boundAnimate38);
  4745. } else {
  4746. this.onAnimationComplete()
  4747. }
  4748. }
  4749. }
  4750.  
  4751. console.debug('FIX_paper_ripple_animate')
  4752.  
  4753. // console.log(cProto.animate)
  4754.  
  4755. }
  4756.  
  4757. });
  4758.  
  4759. if (FIX_doIdomRender) {
  4760.  
  4761. const xsetTimeout = function (f, d) {
  4762. if (xsetTimeout.m511 === 1 && !d) {
  4763. xsetTimeout.m511 = 2;
  4764. getRafPromise().then(f);
  4765. } else {
  4766. return setTimeout.apply(window, arguments)
  4767. }
  4768.  
  4769. }
  4770.  
  4771. const xrequestAnimationFrame = function (f) {
  4772. const h = f + "";
  4773. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  4774. xsetTimeout.m511 = 1;
  4775. f();
  4776. xsetTimeout.m511 = 0;
  4777. } else if (h.includes("requestAninmationFrameResolver")) {
  4778. getRafPromise().then(f);
  4779. } else {
  4780. return requestAnimationFrame.apply(window, arguments);
  4781. }
  4782. }
  4783.  
  4784. let busy = false;
  4785. const doIdomRender = function () {
  4786. if (busy) {
  4787. return this.doIdomRender13.apply(this, arguments);
  4788. }
  4789. busy = true;
  4790. const { requestAnimationFrame, setTimeout } = window;
  4791. window.requestAnimationFrame = xrequestAnimationFrame;
  4792. window.setTimeout = xsetTimeout;
  4793. let r = this.doIdomRender13.apply(this, arguments);
  4794. window.requestAnimationFrame = requestAnimationFrame;
  4795. window.setTimeout = setTimeout;
  4796. busy = false;
  4797. return r;
  4798. };
  4799. 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']) {
  4800.  
  4801.  
  4802. whenCEDefined(ytTag).then(() => {
  4803.  
  4804. let dummy;
  4805. let cProto;
  4806. dummy = document.createElement(ytTag);
  4807. cProto = insp(dummy).constructor.prototype;
  4808.  
  4809. cProto.doIdomRender13 = cProto.doIdomRender;
  4810. cProto.doIdomRender = doIdomRender;
  4811.  
  4812. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  4813.  
  4814. console.debug('FIX_doIdomRender', ytTag)
  4815.  
  4816.  
  4817.  
  4818. });
  4819.  
  4820. }
  4821.  
  4822. }
  4823.  
  4824.  
  4825.  
  4826. });
  4827.  
  4828. });
  4829.  
  4830.  
  4831.  
  4832.  
  4833. if (isMainWindow) {
  4834.  
  4835. console.groupCollapsed(
  4836. "%cYouTube JS Engine Tamer",
  4837. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  4838. );
  4839.  
  4840.  
  4841.  
  4842. console.log("Script is loaded.");
  4843. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  4844.  
  4845. console.log("This script is experimental and subject to further changes.");
  4846.  
  4847. console.log("This might boost your YouTube performance.");
  4848.  
  4849. console.log("CAUTION: This might break your YouTube.");
  4850.  
  4851.  
  4852. if (prepareLogs.length >= 1) {
  4853. console.log(" =========================================================================== ");
  4854.  
  4855. for (const msg of prepareLogs) {
  4856. console.log(msg)
  4857. }
  4858.  
  4859. console.log(" =========================================================================== ");
  4860. }
  4861.  
  4862. console.groupEnd();
  4863.  
  4864. }
  4865.  
  4866.  
  4867.  
  4868. })();