YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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