YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-05-02 提交的版本,查看 最新版本

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