YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2025-02-10 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址