YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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