YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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