YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2025-01-07 提交的版本,查看 最新版本

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