YouTube 超快聊天

YouTube直播聊天的终极性能提升

当前为 2023-11-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.60.23
  4. // @license MIT
  5. // @name:ja YouTube スーパーファーストチャット
  6. // @name:zh-TW YouTube 超快聊天
  7. // @name:zh-CN YouTube 超快聊天
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/super-fast-chat.png
  9. // @namespace UserScript
  10. // @match https://www.youtube.com/live_chat*
  11. // @match https://www.youtube.com/live_chat_replay*
  12. // @author CY Fung
  13. // @run-at document-start
  14. // @grant none
  15. // @unwrap
  16. // @allFrames true
  17. // @inject-into page
  18. // @require https://greasyfork.org/scripts/475632-ytconfighacks/code/ytConfigHacks.js?version=1252732
  19. //
  20. // @compatible firefox Violentmonkey
  21. // @compatible firefox Tampermonkey
  22. // @compatible firefox FireMonkey
  23. // @compatible chrome Violentmonkey
  24. // @compatible chrome Tampermonkey
  25. // @compatible opera Violentmonkey
  26. // @compatible opera Tampermonkey
  27. // @compatible safari Stay
  28. // @compatible edge Violentmonkey
  29. // @compatible edge Tampermonkey
  30. // @compatible brave Violentmonkey
  31. // @compatible brave Tampermonkey
  32. //
  33. // @description Ultimate Performance Boost for YouTube Live Chats
  34. // @description:ja YouTubeのライブチャットの究極のパフォーマンスブースト
  35. // @description:zh-TW YouTube直播聊天的終極性能提升
  36. // @description:zh-CN YouTube直播聊天的终极性能提升
  37. //
  38. // ==/UserScript==
  39.  
  40. ((__CONTEXT__) => {
  41. 'use strict';
  42.  
  43. const ENABLE_REDUCED_MAXITEMS_FOR_FLUSH = true; // TRUE to enable trimming down to MAX_ITEMS_FOR_FULL_FLUSH (25) messages when there are too many unrendered messages
  44. const MAX_ITEMS_FOR_TOTAL_DISPLAY = 90; // By default, 250 latest messages will be displayed, but displaying MAX_ITEMS_FOR_TOTAL_DISPLAY (90) messages is already sufficient.
  45. const MAX_ITEMS_FOR_FULL_FLUSH = 25; // If there are too many new (stacked) messages not yet rendered, clean all and flush MAX_ITEMS_FOR_FULL_FLUSH (25) latest messages then incrementally added back to MAX_ITEMS_FOR_TOTAL_DISPLAY (90) messages
  46.  
  47. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages
  48. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  49. const USE_WILL_CHANGE_CONTROLLER = false; // FALSE for the majority
  50. const ENABLE_DELAYED_CHAT_OCCURRENCE_PREFERRED = true; // In Chrome, the rendering of new chat messages could be too fast for no smooth transform. 80ms delay of displaying new messages should be sufficient for element rendering.
  51. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  52.  
  53. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  54. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  55. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  56. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  57.  
  58. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  59. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  60.  
  61. // Replace requestAnimationFrame timers with custom implementation
  62. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  63. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  64. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  65. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  66.  
  67. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  68. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  69.  
  70. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  71. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  72.  
  73. // Data Manipulation for Participants (Participant List)
  74. // << if DO_PARTICIPANT_LIST_HACKS >>
  75. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  76. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  77. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  78. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  79. // << end >>
  80.  
  81. // show more button
  82. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  83.  
  84. // faster stampDomArray_ for participants list creation
  85. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  86. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  87.  
  88. // reuse yt components
  89. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  90.  
  91. // images <Group#I01>
  92. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  93. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  94. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  95.  
  96. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  97. // << if DO_LINK_PREFETCH >>
  98. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  99. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  100. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  101. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  102. // << end >>
  103.  
  104. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  105. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  106. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  107.  
  108. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  109. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  110.  
  111. const ATTEMPT_ANIMATED_TICKER_BACKGROUND = 'steps' // false OR '' for disabled, 'linear', 'steps' for easing-function
  112. // << if ATTEMPT_ANIMATED_TICKER_BACKGROUND >>
  113. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  114. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  115. // [limiting 500 max steps] is recommended for "confortable visual change"
  116. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  117. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  118. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  119. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  120. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  121. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  122. // << end >>
  123.  
  124. const FIX_TOOLTIP_DISPLAY = true;
  125. const USE_VANILLA_DEREF = true;
  126. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  127.  
  128.  
  129. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  130. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = true; // pause auto scroll faster when the context menu is about to show
  131. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  132.  
  133. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  134. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  135. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  136. // const FIX_MENU_CAPTURE_SCROLL = true;
  137. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  138.  
  139. const RAF_FIX_keepScrollClamped = true;
  140. const RAF_FIX_scrollIncrementally = 2; // 0: no action; 1: basic fix; 2: also fix scroll position
  141.  
  142. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  143. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  144.  
  145. const CHECK_JSONPRUNE = true; // This is a bug in Brave
  146. // << end >>
  147.  
  148. // const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = false;
  149.  
  150. const CHANGE_DATA_FLUSH_ASYNC = false;
  151. // CHANGE_DATA_FLUSH_ASYNC is disabled due to bug report: https://greasyfork.org/scripts/469878-youtube-super-fast-chat/discussions/199479
  152. // to be further investigated
  153.  
  154. const CHANGE_MANAGER_UNSUBSCRIBE = true;
  155.  
  156. const INTERACTIVITY_BACKGROUND_ANIMATION = 1; // mostly for pinned message
  157. // 0 = default Yt animation background [= no fix];
  158. // 1 = disable default animation background [= keep special animation];
  159. // 2 = disable all animation backgrounds [= no animation backbround]
  160.  
  161. const CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED = true;
  162.  
  163. const MAX_TOOLTIP_NO_WRAP_WIDTH = '72vw'; // '' for disable; accept values like '60px', '25vw'
  164.  
  165. const AMEND_TICKER_handleLiveChatAction = true; // to fix ticker duplication and unresponsively fast ticker generation
  166.  
  167. const ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION = true;
  168. const ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME = true;
  169. const FIX_BATCH_TICKER_ORDER = true;
  170.  
  171. const DISABLE_Translation_By_Google = true;
  172.  
  173. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  174. /*
  175.  
  176. ### Time Approach
  177.  
  178. // all below values can make the time interval > 250ms
  179. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  180. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  181. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  182. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  183. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  184. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  185.  
  186. ### Pixel Check
  187. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  188. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  189. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  190.  
  191. ### Example - totalDuration = 280000
  192. totalDuration 280000
  193. stepInterval 0.5
  194. numOfSteps = Math.round(100 / stepInterval) = 200
  195. time interval = 280000 / 200 = 1400ms <acceptable>
  196.  
  197. ### Example - totalDuration = 18000
  198. totalDuration 18000
  199. stepInterval 5
  200. numOfSteps = Math.round(100 / stepInterval) = 20
  201. time interval = 18000 / 20 = 900ms <acceptable>
  202.  
  203. ### Example - totalDuration = 5000
  204. totalDuration 5000
  205. stepInterval 5
  206. numOfSteps = Math.round(100 / stepInterval) = 20
  207. time interval = 5000 / 20 = 250ms <threshold value>
  208.  
  209. ### Example - totalDuration = 3600
  210. totalDuration 3600
  211. stepInterval 5
  212. numOfSteps = Math.round(100 / stepInterval) = 20
  213. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  214.  
  215. */
  216.  
  217. // =======================================================================================================
  218.  
  219. // AUTOMAICALLY DETERMINED
  220. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  221. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  222. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  223. let runTickerClassName = 'run-ticker';
  224.  
  225. const dummyImgURL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  226. /*
  227. WebP: data:image/webp;base64,UklGRjAB
  228. PNG: data:image/png;base64,iVBORw0KGg==
  229. JPEG: data:image/jpeg;base64,/9j/4AA=
  230. GIF: data:image/gif;base64,R0lGODlhAQABAIA=
  231. BMP: data:image/bmp;base64,Qk1oAAAA
  232. SVG: data:image/svg+xml;base64,PHN2Zy8+Cg==
  233.  
  234. WebP: data:image/webp;base64,AAAAAAA=
  235. PNG: data:image/png;base64,AAAAAAA=
  236. JPEG: data:image/jpeg;base64,AAAAAAA=
  237. GIF: data:image/gif;base64,AAAAAAA=
  238. BMP: data:image/bmp;base64,AAAAAAA=
  239.  
  240. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  241.  
  242.  
  243. */
  244.  
  245. // image sizing code
  246. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  247.  
  248.  
  249. // function KC(a, b, c, d) {
  250. // d = void 0 === d ? "width" : d;
  251. // if (!a || !a.length)
  252. // return null;
  253. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  254. // var e = window.devicePixelRatio;
  255. // z("kevlar_tuner_should_clamp_device_pixel_ratio") ? e = Math.min(e, zl("kevlar_tuner_clamp_device_pixel_ratio")) : z("kevlar_tuner_should_use_thumbnail_factor") && (e = zl("kevlar_tuner_thumbnail_factor"));
  256. // HC = e
  257. // } else
  258. // HC || (HC = window.devicePixelRatio);
  259. // e = HC;
  260. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  261. // if (z("kevlar_tuner_min_thumbnail_quality"))
  262. // return a[0].url || null;
  263. // e = a.length;
  264. // if (z("kevlar_tuner_max_thumbnail_quality"))
  265. // return a[e - 1].url || null;
  266. // if (c)
  267. // for (var h = 0; h < e; h++)
  268. // if (0 <= a[h].url.indexOf(c))
  269. // return a[h].url || null;
  270. // for (c = 0; c < e; c++)
  271. // if (a[c][d] >= b)
  272. // return a[c].url || null;
  273. // for (b = e - 1; 0 < b; b--)
  274. // if (a[b][d])
  275. // return a[b].url || null;
  276. // return a[0].url || null
  277. // }
  278.  
  279. const { IntersectionObserver } = __CONTEXT__;
  280.  
  281. /** @type {globalThis.PromiseConstructor} */
  282. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  283.  
  284. // let jsonParseFix = null;
  285.  
  286. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  287. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  288.  
  289. // necessity of cssText3_smooth_transform_position to be checked.
  290. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  291.  
  292. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  293. position: static !important;
  294. }
  295.  
  296. `: '';
  297.  
  298. // fallback if dummy style fn fails
  299. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  300.  
  301. /* optional */
  302. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  303. height: auto !important;
  304. min-height: unset !important;
  305. }
  306.  
  307. #items.style-scope.yt-live-chat-item-list-renderer {
  308. transform: translateY(0px) !important;
  309. }
  310.  
  311. /* optional */
  312.  
  313. `: '';
  314.  
  315. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  316.  
  317. /* ------------------------------------------------------------------------------------------------------------- */
  318.  
  319. yt-live-chat-author-chip #chat-badges.yt-live-chat-author-chip, yt-live-chat-author-chip #chat-badges.yt-live-chat-author-chip yt-live-chat-author-badge-renderer, yt-live-chat-author-chip #chat-badges.yt-live-chat-author-chip yt-live-chat-author-badge-renderer #image, yt-live-chat-author-chip #chat-badges.yt-live-chat-author-chip yt-live-chat-author-badge-renderer #image img {
  320. contain: layout style;
  321. }
  322.  
  323. #items.style-scope.yt-live-chat-item-list-renderer {
  324. contain: layout paint style;
  325. }
  326.  
  327. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  328. contain: style;
  329. }
  330.  
  331. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  332. contain: size style;
  333. }
  334.  
  335. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  336. contain: size layout paint style;
  337. }
  338.  
  339. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  340. contain: layout paint style;
  341. }
  342.  
  343. yt-live-chat-text-message-renderer.style-scope.yt-live-chat-item-list-renderer, yt-live-chat-membership-item-renderer.style-scope.yt-live-chat-item-list-renderer, yt-live-chat-paid-message-renderer.style-scope.yt-live-chat-item-list-renderer, yt-live-chat-banner-manager.style-scope.yt-live-chat-item-list-renderer {
  344. contain: layout style;
  345. }
  346.  
  347. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  348. contain: layout paint style;
  349. }
  350.  
  351. /* ------------------------------------------------------------------------------------------------------------- */
  352.  
  353. ` : '';
  354.  
  355. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  356.  
  357. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  358. top: 4px;
  359. transition-property: top;
  360. bottom: unset;
  361. }
  362.  
  363. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  364. top: -42px;
  365. }
  366.  
  367. `: '';
  368.  
  369. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  370.  
  371. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  372. contain: layout style;
  373. }
  374.  
  375. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  376. overflow: visible;
  377. }
  378.  
  379. `: '';
  380.  
  381. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  382.  
  383. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  384. --yt-live-chat-action-panel-top-border: none;
  385. }
  386.  
  387. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  388. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  389. }
  390.  
  391. html #panel-pages.yt-live-chat-renderer {
  392. border-top: 0;
  393. border-bottom: 0;
  394. }
  395.  
  396. `: '';
  397.  
  398. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  399.  
  400. img,
  401. yt-img-shadow[height][width],
  402. yt-img-shadow {
  403. content-visibility: visible !important;
  404. }
  405.  
  406. ` : '';
  407.  
  408. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  409.  
  410. /* remove YouTube constant will-change */
  411. /* constant value will slow down the performance; default auto */
  412.  
  413. /* www-player.css */
  414. html .ytp-contextmenu,
  415. html .ytp-settings-menu {
  416. will-change: unset;
  417. }
  418.  
  419. /* frequently matched elements */
  420. html .fill.yt-interaction,
  421. html .stroke.yt-interaction,
  422. html .yt-spec-touch-feedback-shape__fill,
  423. html .yt-spec-touch-feedback-shape__stroke {
  424. will-change: unset;
  425. }
  426.  
  427. /* live_chat_polymer.js */
  428. /*
  429. html .toggle-button.tp-yt-paper-toggle-button,
  430. html #primaryProgress.tp-yt-paper-progress,
  431. html #secondaryProgress.tp-yt-paper-progress,
  432. html #onRadio.tp-yt-paper-radio-button,
  433. html .fill.yt-interaction,
  434. html .stroke.yt-interaction,
  435. html .yt-spec-touch-feedback-shape__fill,
  436. html .yt-spec-touch-feedback-shape__stroke {
  437. will-change: unset;
  438. }
  439. */
  440.  
  441. /* desktop_polymer_enable_wil_icons.js */
  442. /* html .fill.yt-interaction,
  443. html .stroke.yt-interaction, */
  444. html tp-yt-app-header::before,
  445. html tp-yt-iron-list,
  446. html #items.tp-yt-iron-list > *,
  447. html #onRadio.tp-yt-paper-radio-button,
  448. html .toggle-button.tp-yt-paper-toggle-button,
  449. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  450. html #items.ytd-post-multi-image-renderer,
  451. html #items.ytd-horizontal-card-list-renderer,
  452. html #items.yt-horizontal-list-renderer,
  453. html #left-arrow.yt-horizontal-list-renderer,
  454. html #right-arrow.yt-horizontal-list-renderer,
  455. html #items.ytd-video-description-infocards-section-renderer,
  456. html #items.ytd-video-description-music-section-renderer,
  457. html #chips.ytd-feed-filter-chip-bar-renderer,
  458. html #chips.yt-chip-cloud-renderer,
  459. html #items.ytd-merch-shelf-renderer,
  460. html #items.ytd-product-details-image-carousel-renderer,
  461. html ytd-video-preview,
  462. html #player-container.ytd-video-preview,
  463. html #primaryProgress.tp-yt-paper-progress,
  464. html #secondaryProgress.tp-yt-paper-progress,
  465. html ytd-miniplayer[enabled] /* ,
  466. html .yt-spec-touch-feedback-shape__fill,
  467. html .yt-spec-touch-feedback-shape__stroke */ {
  468. will-change: unset;
  469. }
  470.  
  471. /* other */
  472. .ytp-videowall-still-info-content[class],
  473. .ytp-suggestion-image[class] {
  474. will-change: unset !important;
  475. }
  476.  
  477. ` : '';
  478.  
  479. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  480. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  481.  
  482. elzm-fonts {
  483. visibility: collapse;
  484. position: fixed;
  485. top: -10px;
  486. left: -10px;
  487. font-size: 10pt;
  488. line-height: 100%;
  489. width: 100px;
  490. height: 100px;
  491. transform: scale(0.1);
  492. transform: scale(0.01);
  493. transform: scale(0.001);
  494. transform-origin: 0 0;
  495. contain: strict;
  496. display: block;
  497.  
  498. pointer-events: none !important;
  499. user-select: none !important;
  500. }
  501.  
  502. elzm-fonts[id]#elzm-fonts-yk75g {
  503. user-select: none !important;
  504. pointer-events: none !important;
  505. }
  506.  
  507. elzm-font {
  508. visibility: collapse;
  509. position: absolute;
  510. line-height: 100%;
  511. width: 100px;
  512. height: 100px;
  513. contain: strict;
  514. display: block;
  515.  
  516. user-select: none !important;
  517. pointer-events: none !important;
  518. }
  519.  
  520. elzm-font::before {
  521. visibility: collapse;
  522. position: absolute;
  523. line-height: 100%;
  524. width: 100px;
  525. height: 100px;
  526. contain: strict;
  527. display: block;
  528.  
  529. content: '0aZ!@#$~^&*()_-+[]{}|;:><?\\0460\\0301\\0900\\1F00\\0370\\0102\\0100\\28EB2\\28189\\26DA0\\25A9C\\249BB\\23F61\\22E8B\\21927\\21076\\2048E\\1F6F5\\FF37\\F94F\\F0B2\\9F27\\9D9A\\9BEA\\9A6B\\98EC\\9798\\9602\\949D\\9370\\926B\\913A\\8FA9\\8E39\\8CC1\\8B26\\8983\\8804\\8696\\8511\\83BC\\828D\\8115\\7F9A\\7E5B\\7D07\\7B91\\7A2C\\78D2\\776C\\7601\\74AA\\73B9\\7265\\70FE\\6FBC\\6E88\\6D64\\6C3F\\6A9C\\6957\\67FE\\66B3\\6535\\63F2\\628E\\612F\\5FE7\\5E6C\\5CEE\\5B6D\\5A33\\58BC\\575B\\5611\\54BF\\536E\\51D0\\505D\\4F22\\4AD1\\41DB\\3B95\\3572\\2F3F\\26FD\\25A1\\2477\\208D\\1D0A\\1FB\\A1\\A3\\B4\\2CB\\60\\10C\\E22\\A5\\4E08\\B0\\627\\2500\\5E\\201C\\3C\\B7\\23\\26\\3E\\D\\20\\25EE8\\1F235\\FFD7\\FA10\\F92D\\9E8B\\9C3E\\9AE5\\98EB\\971D\\944A\\92BC\\9143\\8F52\\8DC0\\8B2D\\8973\\87E2\\8655\\84B4\\82E8\\814A\\7F77\\7D57\\7BC8\\7A17\\7851\\768C\\7511\\736C\\7166\\6F58\\6D7C\\6B85\\69DD\\6855\\667E\\64D2\\62CF\\6117\\5F6C\\5D9B\\5BBC\\598B\\57B3\\5616\\543F\\528D\\50DD\\4F57\\4093\\3395\\32B5\\31C8\\3028\\2F14\\25E4\\24D1\\2105\\2227\\A8\\2D9\\2CA\\2467\\B1\\2020\\2466\\251C\\266B\\AF\\4E91\\221E\\2464\\2266\\2207\\4E32\\25B3\\2463\\2010\\2103\\3014\\25C7\\24\\25BD\\4E18\\2460\\21D2\\2015\\2193\\4E03\\7E\\25CB\\2191\\25BC\\3D\\500D\\4E01\\25\\30F6\\2605\\266A\\40\\2B\\4E16\\7C\\A9\\4E\\21\\1F1E9\\FEE3\\F0A7\\9F3D\\9DFA\\9C3B\\9A5F\\98C8\\972A\\95B9\\94E7\\9410\\92B7\\914C\\8FE2\\8E2D\\8CAF\\8B5E\\8A02\\8869\\86E4\\8532\\83B4\\82A9\\814D\\7FFA\\7ED7\\7DC4\\7CCC\\7BC3\\7ACA\\797C\\783E\\770F\\760A\\74EF\\73E7\\72DD\\719C\\7005\\6ED8\\6DC3\\6CB2\\6A01\\68E1\\6792\\663A\\64F8\\63BC\\623B\\60FA\\5FD1\\5EA3\\5D32\\5BF5\\5AB2\\5981\\5831\\570A\\5605\\5519\\53FB\\52A2\\5110\\4FE3\\4EB8\\3127\\279C\\2650\\254B\\23E9\\207B\\1D34\\2AE\\176\\221A\\161\\200B\\300C\\4E4C\\1F921\\FF78\\FA0A\\F78A\\9EB9\\9D34\\9BD3\\9A6F\\9912\\97C6\\964E\\950C\\93E4\\92E5\\91F0\\90BB\\8F68\\8E18\\8B6C\\89F6\\889B\\874C\\8602\\84B1\\8378\\826E\\8113\\7FB1\\7EAF\\7D89\\7C20\\7AFB\\7988\\7840\\7705\\75CC\\749A\\73B3\\727F\\7113\\6FE8\\6ED6\\6DD3\\6CDA\\6BBB\\6A31\\6900\\67D9\\66A7\\655D\\6427\\630D\\61C6\\60AC\\5F78\\5E34\\5CE0\\5B80\\5A51\\590B\\57A1\\566F\\5551\\543D\\52DB\\518F\\5032\\3A17\\305C\\2749\\264A\\2567\\2476\\2139\\1EC0\\11AF\\2C8\\1AF\\E17\\2190\\2022\\2502\\2312\\2025\\50';
  530.  
  531. user-select: none !important;
  532. pointer-events: none !important;
  533. }
  534.  
  535. `: '';
  536.  
  537. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  538. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  539. -webkit-backdrop-filter: none;
  540. backdrop-filter: none;
  541. }
  542. `: '';
  543.  
  544. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  545.  
  546. @keyframes blinker-miuzp {
  547. 0%, 60%, 100% {
  548. opacity: 1;
  549. }
  550. 30% {
  551. opacity: 0.6;
  552. }
  553. }
  554.  
  555. yt-icon-button#show-more.has-new-messages-miuzp {
  556. animation: blinker-miuzp 1.74s linear infinite;
  557. }
  558.  
  559. `: '';
  560.  
  561. const cssText11_entire_message_clickable = FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK ? `
  562.  
  563. yt-live-chat-paid-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  564. pointer-events: none !important;
  565. }
  566.  
  567. yt-live-chat-membership-item-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  568. pointer-events: none !important;
  569. }
  570.  
  571. yt-live-chat-paid-sticker-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  572. pointer-events: none !important;
  573. }
  574.  
  575. yt-live-chat-text-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  576. pointer-events: none !important;
  577. }
  578.  
  579. yt-live-chat-auto-mod-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  580. pointer-events: none !important;
  581. }
  582.  
  583. `: '';
  584.  
  585. const cssText12_nowrap_tooltip = MAX_TOOLTIP_NO_WRAP_WIDTH && typeof MAX_TOOLTIP_NO_WRAP_WIDTH === 'string' ? `
  586.  
  587.  
  588. tp-yt-paper-tooltip[role="tooltip"] {
  589. box-sizing: content-box !important;
  590. margin: 0px !important;
  591. padding: 0px !important;
  592. contain: none !important;
  593. }
  594.  
  595. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"] {
  596. box-sizing: content-box !important;
  597. display: inline-block;
  598. contain: none !important;
  599. }
  600.  
  601.  
  602. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"]{
  603. max-width: ${MAX_TOOLTIP_NO_WRAP_WIDTH};
  604. width: max-content;
  605. text-overflow: ellipsis;
  606. overflow: hidden;
  607. white-space: nowrap;
  608. }
  609.  
  610.  
  611. `: '';
  612.  
  613.  
  614. const cssText13_no_text_select_when_menu_visible = `
  615. [menu-visible] {
  616. --sfc47-text-select: none;
  617. }
  618. [menu-visible] #header[id][class],
  619. [menu-visible] #content[id][class],
  620. [menu-visible] #header[id][class] *,
  621. [menu-visible] #content[id][class] * {
  622. user-select: var(--sfc47-text-select) !important;
  623. }
  624. [menu-visible] #menu {
  625. --sfc47-text-select: inherit;
  626. }
  627. `
  628.  
  629.  
  630. const addCss = () => `
  631.  
  632. @property --ticker-rtime {
  633. syntax: "<percentage>";
  634. inherits: false;
  635. initial-value: 0%;
  636. }
  637.  
  638. /*
  639. .run-ticker {
  640. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  641. }
  642.  
  643. .run-ticker-test {
  644. background: #00000001;
  645. }
  646.  
  647. .run-ticker-forced,
  648. yt-live-chat-ticker-renderer #items > * > #container.run-ticker-forced,
  649. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker-forced[class]
  650. {
  651. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2)) !important;
  652. }
  653. */
  654.  
  655. .run-ticker {
  656. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  657. }
  658.  
  659. .run-ticker,
  660. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  661. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  662. {
  663. background: var(--ticker-bg) !important;
  664. }
  665.  
  666. yt-live-chat-ticker-dummy777-item-renderer {
  667. background: #00000001;
  668. }
  669.  
  670. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  671. position: fixed !important;
  672. top: -1000px !important;
  673. left: -1000px !important;
  674. font-size: 1px !important;
  675. color: transparent !important;
  676. pointer-events: none !important;
  677. z-index: -1 !important;
  678. contain: strict !important;
  679. box-sizing: border-box !important;
  680. pointer-events: none !important;
  681. user-select: none !important;
  682. max-width: 1px !important;
  683. max-height: 1px !important;
  684. overflow: hidden !important;
  685. visibility: collapse !important;
  686. display: none !important;
  687. }
  688.  
  689. yt-live-chat-ticker-dummy777-item-renderer #container {
  690. background: inherit;
  691. }
  692.  
  693.  
  694. ${cssText8_fonts_pre_render}
  695.  
  696. ${cssText9_no_backdrop_filter_when_menu_shown}
  697.  
  698. @supports (contain: layout paint style) {
  699.  
  700. ${cssText5}
  701.  
  702. }
  703.  
  704. @supports (color: var(--general)) {
  705.  
  706. html {
  707. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  708. }
  709.  
  710. ${cssText3_smooth_transform_position}
  711.  
  712. ${cssText7c_will_change_unset}
  713.  
  714. ${cssText7b_content_visibility_unset}
  715.  
  716. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  717. overflow-y: scroll;
  718. padding-right: 0;
  719. }
  720.  
  721. ${cssText4_smooth_transform_forced_props}
  722.  
  723. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  724. pointer-events: none !important;
  725. }
  726.  
  727. #continuations, #continuations * {
  728. contain: strict;
  729. position: fixed;
  730. top: 2px;
  731. height: 1px;
  732. width: 2px;
  733. height: 1px;
  734. visibility: collapse;
  735. }
  736.  
  737. ${cssText6b_show_more_button}
  738.  
  739. ${cssText6d_input_panel_border}
  740.  
  741. ${cssText6c_input_panel_overflow}
  742.  
  743. }
  744.  
  745.  
  746. @supports (overflow-anchor: auto) {
  747.  
  748. .no-anchor * {
  749. overflow-anchor: none;
  750. }
  751. .no-anchor > item-anchor {
  752. overflow-anchor: auto;
  753. }
  754.  
  755. item-anchor {
  756.  
  757. height:1px;
  758. width: 100%;
  759. transform: scaleY(0.00001);
  760. transform-origin:0 0;
  761. contain: strict;
  762. opacity:0;
  763. display:flex;
  764. position:relative;
  765. flex-shrink:0;
  766. flex-grow:0;
  767. margin-bottom:0;
  768. overflow:hidden;
  769. box-sizing:border-box;
  770. visibility: visible;
  771. content-visibility: visible;
  772. contain-intrinsic-size: auto 1px;
  773. pointer-events:none !important;
  774.  
  775. }
  776.  
  777. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  778. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  779. }
  780.  
  781. html item-anchor {
  782.  
  783. height: 1px;
  784. width: 1px;
  785. top: auto;
  786. left: auto;
  787. right: auto;
  788. bottom: auto;
  789. transform: translateY(-1px);
  790. position: absolute;
  791. z-index: -1;
  792.  
  793. }
  794.  
  795. }
  796.  
  797. @supports (color: var(--pre-rendering)) {
  798.  
  799. @keyframes dontRenderAnimation {
  800. 0% {
  801. background-position-x: 3px;
  802. }
  803. 100% {
  804. background-position-x: 4px;
  805. }
  806. }
  807.  
  808. .dont-render[class] {
  809. /* visibility: collapse !important; */
  810. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://greasyfork.org/scripts/469878/discussions/197267 */
  811.  
  812. transform: scale(0.01) !important;
  813. transform: scale(0.00001) !important;
  814. transform: scale(0.0000001) !important;
  815. transform-origin: 0 0 !important;
  816. z-index: -1 !important;
  817. contain: strict !important;
  818. box-sizing: border-box !important;
  819.  
  820. height: 1px !important;
  821. height: 0.1px !important;
  822. height: 0.01px !important;
  823. height: 0.0001px !important;
  824. height: 0.000001px !important;
  825.  
  826. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  827.  
  828. pointer-events: none !important;
  829. user-select: none !important;
  830.  
  831. }
  832.  
  833. #sk35z {
  834. display: block !important;
  835.  
  836. visibility: collapse !important;
  837.  
  838. transform: scale(0.01) !important;
  839. transform: scale(0.00001) !important;
  840. transform: scale(0.0000001) !important;
  841. transform-origin: 0 0 !important;
  842. z-index: -1 !important;
  843. contain: strict !important;
  844. box-sizing: border-box !important;
  845.  
  846. height: 1px !important;
  847. height: 0.1px !important;
  848. height: 0.01px !important;
  849. height: 0.0001px !important;
  850. height: 0.000001px !important;
  851.  
  852. position: absolute !important;
  853. top: -1000px !important;
  854. left: -1000px !important;
  855.  
  856. }
  857.  
  858. }
  859.  
  860. [rNgzQ] {
  861. opacity: 0 !important;
  862. pointer-events: none !important;
  863. }
  864.  
  865.  
  866. ${cssText10_show_more_blinker}
  867.  
  868. ${cssText11_entire_message_clickable}
  869.  
  870. ${cssText12_nowrap_tooltip}
  871.  
  872. ${cssText13_no_text_select_when_menu_visible}
  873.  
  874. `;
  875.  
  876. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  877.  
  878. // Create a unique key for the script and check if it is already running
  879. const hkey_script = 'mchbwnoasqph';
  880. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  881. win[hkey_script] = true;
  882.  
  883. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  884.  
  885. let te4 = setTimeout(() => { }); // dummy; skip timerId only;
  886. if (te4 < 3) {
  887. setTimeout(() => { });
  888. setTimeout(() => { });
  889. }
  890.  
  891. }
  892.  
  893. const firstKey = (obj) => {
  894. for (const key in obj) {
  895. if (obj.hasOwnProperty(key)) return key;
  896. }
  897. return null;
  898. }
  899.  
  900. const firstObjectKey = (obj) => {
  901. for (const key in obj) {
  902. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  903. }
  904. return null;
  905. }
  906.  
  907. function removeElementFromArray(arr, index) {
  908. if (index >= 0 && index < arr.length) {
  909. arr.splice(index, 1);
  910. }
  911. }
  912.  
  913. function getRandomInt(a, b) {
  914. // Ensure that 'a' and 'b' are integers
  915. a = Math.ceil(a);
  916. b = Math.floor(b);
  917.  
  918. // Generate a random integer in the range [a, b]
  919. return Math.floor(Math.random() * (b - a + 1)) + a;
  920. }
  921.  
  922. function deepCopy(obj, skipKeys) {
  923. skipKeys = skipKeys || [];
  924. if (!obj || typeof obj !== 'object') return obj;
  925. if (Array.isArray(obj)) {
  926. return obj.map(item => deepCopy(item, skipKeys));
  927. }
  928. const copy = {};
  929. for (let key in obj) {
  930. if (!skipKeys.includes(key)) {
  931. copy[key] = deepCopy(obj[key], skipKeys);
  932. }
  933. }
  934. return copy;
  935. }
  936.  
  937. class Mutex {
  938.  
  939. constructor() {
  940. this.p = Promise.resolve()
  941. }
  942.  
  943. /**
  944. * @param {(lockResolve: () => void)} f
  945. */
  946. lockWith(f) {
  947. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  948. }
  949.  
  950. }
  951.  
  952. const PromiseExternal = ((resolve_, reject_) => {
  953. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  954. return class PromiseExternal extends Promise {
  955. constructor(cb = h) {
  956. super(cb);
  957. if (cb === h) {
  958. /** @type {(value: any) => void} */
  959. this.resolve = resolve_;
  960. /** @type {(reason?: any) => void} */
  961. this.reject = reject_;
  962. }
  963. }
  964. };
  965. })();
  966.  
  967. /** @type {typeof PromiseExternal.prototype | null} */
  968. let relayPromise = null;
  969.  
  970.  
  971. /** @type {typeof PromiseExternal.prototype | null} */
  972. let onPlayStateChangePromise = null;
  973.  
  974.  
  975.  
  976. let playEventsStack = Promise.resolve();
  977.  
  978.  
  979. let playerProgressChangedArg1 = null;
  980. let playerProgressChangedArg2 = null;
  981. let playerProgressChangedArg3 = null;
  982.  
  983.  
  984. function dr(s) {
  985. // reserved for future use
  986. return s;
  987. // return window.deWeakJS ? window.deWeakJS(s) : s;
  988. }
  989.  
  990. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  991. const indr = o => insp(o).$ || o.$ || 0;
  992.  
  993. const getProto = (element) => {
  994. if (element) {
  995. const cnt = insp(element);
  996. return cnt.constructor.prototype || null;
  997. }
  998. return null;
  999. }
  1000.  
  1001. const assertor = (f) => f() || console.assert(false, f + "");
  1002.  
  1003. const fnIntegrity = (f, d) => {
  1004. if (!f || typeof f !== 'function') {
  1005. console.warn('f is not a function', f);
  1006. return;
  1007. }
  1008. let p = f + "", s = 0, j = -1, w = 0;
  1009. for (let i = 0, l = p.length; i < l; i++) {
  1010. const t = p[i];
  1011. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1012. if (j < i - 1) w++;
  1013. j = i;
  1014. } else {
  1015. s++;
  1016. }
  1017. }
  1018. let itz = `${f.length}.${s}.${w}`;
  1019. if (!d) {
  1020. return itz;
  1021. } else if (itz !== d) {
  1022. console.warn('fnIntegrity=false', itz);
  1023. return false;
  1024. } else {
  1025. return true;
  1026. }
  1027. }
  1028.  
  1029.  
  1030. ; (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS) && (() => {
  1031.  
  1032. const _config_ = () => {
  1033. try {
  1034. return ytcfg.data_;
  1035. } catch (e) { }
  1036. return null;
  1037. };
  1038.  
  1039. const flagsFn = (EXPERIMENT_FLAGS) => {
  1040.  
  1041. // console.log(700)
  1042.  
  1043. if (!EXPERIMENT_FLAGS) return;
  1044.  
  1045. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1046. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1047. EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true;
  1048. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1049. // console.log(701)
  1050. }
  1051. }
  1052.  
  1053. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1054. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1055. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1056. // console.log(702);
  1057. }
  1058.  
  1059. };
  1060.  
  1061. const uf = (config_) => {
  1062. config_ = config_ || _config_();
  1063. if (config_) {
  1064. const { EXPERIMENT_FLAGS, EXPERIMENTS_FORCED_FLAGS } = config_;
  1065. if (EXPERIMENT_FLAGS) {
  1066. flagsFn(EXPERIMENT_FLAGS);
  1067. if (EXPERIMENTS_FORCED_FLAGS) flagsFn(EXPERIMENTS_FORCED_FLAGS);
  1068. }
  1069. }
  1070. }
  1071.  
  1072. window._ytConfigHacks.add((config_) => {
  1073. uf(config_);
  1074. });
  1075.  
  1076. uf();
  1077.  
  1078. })();
  1079.  
  1080. if (DISABLE_Translation_By_Google) {
  1081.  
  1082. let mo = new MutationObserver(() => {
  1083.  
  1084. if (!mo) return;
  1085. let h = document.head;
  1086. if (!h) return;
  1087. mo.disconnect();
  1088. mo.takeRecords();
  1089. mo = null;
  1090.  
  1091. let meta = document.createElement('meta');
  1092. meta.setAttribute('name', 'google');
  1093. meta.setAttribute('content', 'notranslate');
  1094. h.appendChild(meta);
  1095.  
  1096.  
  1097. });
  1098. mo.observe(document, { subtree: true, childList: true });
  1099. }
  1100.  
  1101.  
  1102. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  1103.  
  1104. let ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE = false;
  1105. const isContainSupport = CSS.supports('contain', 'layout paint style');
  1106. if (!isContainSupport) {
  1107. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  1108. } else {
  1109. ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE = true;
  1110. }
  1111.  
  1112. let ENABLE_OVERFLOW_ANCHOR_CAPABLE = false;
  1113. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  1114. if (!isOverflowAnchorSupport) {
  1115. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  1116. } else {
  1117. ENABLE_OVERFLOW_ANCHOR_CAPABLE = true;
  1118. }
  1119.  
  1120. const NOT_FIREFOX = !CSS.supports('-moz-appearance', 'none'); // 1. Firefox does not have the flicking issue; 2. Firefox's OVERFLOW_ANCHOR is less effective than Chromium's.
  1121.  
  1122. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && ENABLE_OVERFLOW_ANCHOR_CAPABLE && ENABLE_NO_SMOOTH_TRANSFORM;
  1123. const ENABLE_DELAYED_CHAT_OCCURRENCE = ENABLE_DELAYED_CHAT_OCCURRENCE_PREFERRED && ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE && ENABLE_OVERFLOW_ANCHOR && ENABLE_NO_SMOOTH_TRANSFORM && NOT_FIREFOX;
  1124.  
  1125. let hasTimerModified = null;
  1126. const DO_CHECK_TICKER_BACKGROUND_OVERRIDED = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND || ENABLE_RAF_HACK_TICKERS;
  1127.  
  1128. const fxOperator = (proto, propertyName) => {
  1129. let propertyDescriptorGetter = null;
  1130. try {
  1131. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  1132. } catch (e) { }
  1133. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  1134. try {
  1135.  
  1136. return propertyDescriptorGetter.call(dr(e));
  1137. } catch (e) { }
  1138. return e[propertyName];
  1139. } : (e) => e[propertyName];
  1140. };
  1141.  
  1142. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  1143. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  1144. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  1145. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  1146. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  1147.  
  1148. const groupCollapsed = (text1, text2) => {
  1149.  
  1150. console.groupCollapsed(`%c${text1}%c${text2}`,
  1151. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1152. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1153. );
  1154. }
  1155.  
  1156. // const microNow = () => performance.now() + (performance.timeOrigin || performance.timing.navigationStart);
  1157.  
  1158.  
  1159. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1160. const onRegistryReady = (callback) => {
  1161. if (typeof customElements === 'undefined') {
  1162. if (!('__CE_registry' in document)) {
  1163. // https://github.com/webcomponents/polyfills/
  1164. Object.defineProperty(document, '__CE_registry', {
  1165. get() {
  1166. // return undefined
  1167. },
  1168. set(nv) {
  1169. if (typeof nv == 'object') {
  1170. delete this.__CE_registry;
  1171. this.__CE_registry = nv;
  1172. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1173. }
  1174. return true;
  1175. },
  1176. enumerable: false,
  1177. configurable: true
  1178. })
  1179. }
  1180. let eventHandler = (evt) => {
  1181. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1182. const f = callback;
  1183. callback = null;
  1184. eventHandler = null;
  1185. f();
  1186. };
  1187. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1188. } else {
  1189. callback();
  1190. }
  1191. };
  1192.  
  1193. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  1194.  
  1195. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  1196.  
  1197. return new Promise(resolve => {
  1198.  
  1199. let ro = new ResizeObserver(entries => {
  1200. if (entries && entries.length >= 1) {
  1201. resolve();
  1202. ro.disconnect();
  1203. ro = null;
  1204. }
  1205. });
  1206. ro.observe(sizingTarget);
  1207.  
  1208.  
  1209.  
  1210. });
  1211.  
  1212. } : (sizingTarget) => {
  1213.  
  1214.  
  1215. return new Promise(resolve => {
  1216.  
  1217. let io = new IntersectionObserver(entries => {
  1218. if (entries && entries.length >= 1) {
  1219. resolve();
  1220. io.disconnect();
  1221. io = null;
  1222. }
  1223. });
  1224. io.observe(sizingTarget);
  1225.  
  1226.  
  1227.  
  1228. });
  1229.  
  1230. };
  1231.  
  1232. /* globals WeakRef:false */
  1233.  
  1234. /** @type {(o: Object | null) => WeakRef | null} */
  1235. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1236.  
  1237. /** @type {(wr: Object | null) => Object | null} */
  1238. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1239.  
  1240. const getLCRDummy = () => {
  1241. // direct createElement or createComponent_ will make the emoji rendering crashed. reason TBC
  1242.  
  1243. return Promise.all([customElements.whenDefined('yt-live-chat-app'), customElements.whenDefined('yt-live-chat-renderer')]).then(async () => {
  1244.  
  1245. const tag = "yt-live-chat-renderer"
  1246. let dummy = document.querySelector(tag);
  1247. if (!dummy) {
  1248.  
  1249. let mo = null;
  1250.  
  1251. const ytLiveChatApp = document.querySelector('yt-live-chat-app') || document.createElement('yt-live-chat-app');
  1252.  
  1253. const lcaProto = getProto(ytLiveChatApp);
  1254.  
  1255. dummy = await new Promise(resolve => {
  1256.  
  1257. if (typeof lcaProto.createComponent_ === 'function' && !lcaProto.createComponent99_) {
  1258.  
  1259. lcaProto.createComponent99_ = lcaProto.createComponent_;
  1260. lcaProto.createComponent98_ = function (a, b, c) {
  1261. // (3) ['yt-live-chat-renderer', {…}, true]
  1262. const r = this.createComponent99_.apply(this, arguments);
  1263. if (a === 'yt-live-chat-renderer') {
  1264. resolve(r);
  1265. }
  1266. return r;
  1267. };
  1268. lcaProto.createComponent_ = lcaProto.createComponent98_;
  1269.  
  1270. } else {
  1271.  
  1272. mo = new MutationObserver(() => {
  1273. const t = document.querySelector(tag);
  1274. if (t) {
  1275. resolve(t);
  1276. }
  1277. });
  1278. mo.observe(document, { subtree: true, childList: true })
  1279. }
  1280.  
  1281. });
  1282.  
  1283. if (mo) {
  1284. mo.disconnect();
  1285. mo.takeRecords();
  1286. mo = null;
  1287. }
  1288.  
  1289. if (lcaProto.createComponent99_ && lcaProto.createComponent_ && lcaProto.createComponent98_ === lcaProto.createComponent_) {
  1290. lcaProto.createComponent_ = lcaProto.createComponent99_;
  1291. lcaProto.createComponent99_ = null;
  1292. lcaProto.createComponent98_ = null;
  1293. }
  1294.  
  1295. }
  1296. return dummy;
  1297.  
  1298. });
  1299. }
  1300.  
  1301. const { addCssManaged } = (() => {
  1302.  
  1303. const addFontPreRendering = () => {
  1304.  
  1305. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  1306.  
  1307. let efsContainer = document.createElement('elzm-fonts');
  1308. efsContainer.id = 'elzm-fonts-yk75g'
  1309.  
  1310. const arr = [];
  1311. let p = document.createElement('elzm-font');
  1312. arr.push(p);
  1313.  
  1314. if (ENABLE_FONT_PRE_RENDERING & 1) {
  1315. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1316.  
  1317. p = document.createElement('elzm-font');
  1318. p.style.fontWeight = size;
  1319. arr.push(p);
  1320. }
  1321. }
  1322.  
  1323. if (ENABLE_FONT_PRE_RENDERING & 2) {
  1324. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1325.  
  1326. p = document.createElement('elzm-font');
  1327. p.style.fontFamily = 'Roboto';
  1328. p.style.fontWeight = size;
  1329. arr.push(p);
  1330. }
  1331. }
  1332.  
  1333. if (ENABLE_FONT_PRE_RENDERING & 4) {
  1334. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1335.  
  1336. p = document.createElement('elzm-font');
  1337. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  1338. p.style.fontWeight = size;
  1339. arr.push(p);
  1340. }
  1341. }
  1342.  
  1343.  
  1344. if (ENABLE_FONT_PRE_RENDERING & 8) {
  1345. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1346.  
  1347. p = document.createElement('elzm-font');
  1348. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  1349. p.style.fontWeight = size;
  1350. arr.push(p);
  1351. }
  1352. }
  1353.  
  1354.  
  1355. if (ENABLE_FONT_PRE_RENDERING & 16) {
  1356. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1357.  
  1358. p = document.createElement('elzm-font');
  1359. p.style.fontFamily = 'sans-serif';
  1360. p.style.fontWeight = size;
  1361. arr.push(p);
  1362. }
  1363. }
  1364.  
  1365. console.log('number of elzm-font elements', arr.length);
  1366.  
  1367. HTMLElement.prototype.append.apply(efsContainer, arr);
  1368.  
  1369. (document.body || document.documentElement).appendChild(efsContainer);
  1370.  
  1371.  
  1372. console.log('elzm-font elements have been added to the page for rendering.');
  1373.  
  1374. console.groupEnd();
  1375.  
  1376. }
  1377.  
  1378. let isCssAdded = false;
  1379.  
  1380. function addCssElement() {
  1381. let s = document.createElement('style');
  1382. s.id = 'ewRvC';
  1383. return s;
  1384. }
  1385.  
  1386. const addCssManaged = () => {
  1387. if (!isCssAdded && document.documentElement && document.head) {
  1388. isCssAdded = true;
  1389. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  1390. if (ENABLE_FONT_PRE_RENDERING) {
  1391. Promise.resolve().then(addFontPreRendering)
  1392. }
  1393. }
  1394. }
  1395.  
  1396. return { addCssManaged };
  1397. })();
  1398.  
  1399.  
  1400. const { setupStyle } = (() => {
  1401.  
  1402. const sp7 = Symbol();
  1403.  
  1404. const proxyHelperFn = (dummy) => ({
  1405.  
  1406. get(target, prop) {
  1407. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  1408. },
  1409. set(target, prop, value) {
  1410. if (!(prop in dummy)) {
  1411. target[prop] = value;
  1412. }
  1413. return true;
  1414. },
  1415. has(target, prop) {
  1416. return (prop in target);
  1417. },
  1418. deleteProperty(target, prop) {
  1419. return true;
  1420. },
  1421. ownKeys(target) {
  1422. return Object.keys(target);
  1423. },
  1424. defineProperty(target, key, descriptor) {
  1425. return Object.defineProperty(target, key, descriptor);
  1426. },
  1427. getOwnPropertyDescriptor(target, key) {
  1428. return Object.getOwnPropertyDescriptor(target, key);
  1429. },
  1430.  
  1431. });
  1432.  
  1433. const setupStyle = (m1, m2) => {
  1434. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  1435.  
  1436. const dummy1v = {
  1437. transform: '',
  1438. height: '',
  1439. minHeight: '',
  1440. paddingBottom: '',
  1441. paddingTop: ''
  1442. };
  1443.  
  1444. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  1445. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  1446. dummy1v[k] = dummyStyleFn(k);
  1447. }
  1448.  
  1449. const dummy1p = proxyHelperFn(dummy1v);
  1450. const sp1v = new Proxy(m1.style, dummy1p);
  1451. const sp2v = new Proxy(m2.style, dummy1p);
  1452. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  1453. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  1454. m1.removeAttribute("style");
  1455. m2.removeAttribute("style");
  1456.  
  1457. }
  1458.  
  1459. return { setupStyle };
  1460.  
  1461. })();
  1462.  
  1463.  
  1464.  
  1465. function setThumbnails(config) {
  1466.  
  1467. const { baseObject, thumbnails, flag0, imageLinks } = config;
  1468.  
  1469. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  1470.  
  1471.  
  1472. if (thumbnails && thumbnails.length > 0) {
  1473. if (flag0 > 0 && thumbnails.length > 1) {
  1474. let pSize = 0;
  1475. let newThumbnails = [];
  1476. for (const thumbnail of thumbnails) {
  1477. if (!thumbnail || !thumbnail.url) continue;
  1478. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  1479. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  1480. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  1481. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  1482. newThumbnails.push(thumbnail);
  1483. if (imageLinks) imageLinks.add(thumbnail.url);
  1484. }
  1485. if (squarePhoto && condSize && leastSizeFulfilled) {
  1486. pSize = thumbnail.width;
  1487. }
  1488. }
  1489. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  1490. baseObject.thumbnails = newThumbnails;
  1491. } else {
  1492. newThumbnails.length = 0;
  1493. }
  1494. newThumbnails = null;
  1495. } else {
  1496. for (const thumbnail of thumbnails) {
  1497. if (thumbnail && thumbnail.url) {
  1498. if (imageLinks) imageLinks.add(thumbnail.url);
  1499. }
  1500. }
  1501. }
  1502. }
  1503.  
  1504. }
  1505. }
  1506.  
  1507. function fixLiveChatItem(item, imageLinks) {
  1508. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  1509. if (liveChatTextMessageRenderer) {
  1510. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  1511. if (messageRuns && messageRuns.length > 0) {
  1512. for (const run of messageRuns) {
  1513. const emojiImage = (((run || 0).emoji || 0).image || 0);
  1514. setThumbnails({
  1515. baseObject: emojiImage,
  1516. thumbnails: emojiImage.thumbnails,
  1517. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  1518. imageLinks
  1519. });
  1520. }
  1521. }
  1522. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  1523. setThumbnails({
  1524. baseObject: authorPhoto,
  1525. thumbnails: authorPhoto.thumbnails,
  1526. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  1527. imageLinks
  1528. });
  1529. }
  1530. }
  1531.  
  1532.  
  1533.  
  1534. let kptPF = null;
  1535. const emojiPrefetched = new Set();
  1536. const authorPhotoPrefetched = new Set();
  1537.  
  1538. function linker(link, rel, href, _as) {
  1539. return new Promise(resolve => {
  1540. if (!link) link = document.createElement('link');
  1541. link.rel = rel;
  1542. if (_as) link.setAttribute('as', _as);
  1543. link.onload = function () {
  1544. resolve({
  1545. link: this,
  1546. success: true
  1547. })
  1548. this.remove();
  1549. };
  1550. link.onerror = function () {
  1551. resolve({
  1552. link: this,
  1553. success: false
  1554. });
  1555. this.remove();
  1556. };
  1557. link.href = href;
  1558. document.head.appendChild(link);
  1559. link = null;
  1560. });
  1561. }
  1562.  
  1563.  
  1564.  
  1565. const cleanContext = async (win) => {
  1566. const waitFn = requestAnimationFrame; // shall have been binded to window
  1567. try {
  1568. let mx = 16; // MAX TRIAL
  1569. const frameId = 'vanillajs-iframe-v1';
  1570. /** @type {HTMLIFrameElement | null} */
  1571. let frame = document.getElementById(frameId);
  1572. let removeIframeFn = null;
  1573. if (!frame) {
  1574. frame = document.createElement('iframe');
  1575. frame.id = frameId;
  1576. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  1577. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  1578. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  1579. n.appendChild(frame);
  1580. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  1581. const root = document.documentElement;
  1582. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  1583. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  1584.  
  1585. removeIframeFn = (setTimeout) => {
  1586. const removeIframeOnDocumentReady = (e) => {
  1587. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1588. e = n;
  1589. n = win = removeIframeFn = 0;
  1590. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  1591. }
  1592. if (!setTimeout || document.readyState !== 'loading') {
  1593. removeIframeOnDocumentReady();
  1594. } else {
  1595. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1596. }
  1597. }
  1598. }
  1599. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  1600. const fc = frame.contentWindow;
  1601. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  1602. try {
  1603. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle } = fc;
  1604. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle };
  1605. for (let k in res) res[k] = res[k].bind(win); // necessary
  1606. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  1607.  
  1608. /** @type {HTMLElement} */
  1609. const HTMLElementProto = fc.HTMLElement.prototype;
  1610. /** @type {EventTarget} */
  1611. const EventTargetProto = fc.EventTarget.prototype;
  1612. // jsonParseFix = {
  1613. // _JSON: fc.JSON, _parse: fc.JSON.parse
  1614. // }
  1615. return {
  1616. ...res,
  1617. animate: HTMLElementProto.animate,
  1618. addEventListener: EventTargetProto.addEventListener,
  1619. removeEventListener: EventTargetProto.removeEventListener
  1620. };
  1621. } catch (e) {
  1622. if (removeIframeFn) removeIframeFn();
  1623. return null;
  1624. }
  1625. } catch (e) {
  1626. console.warn(e);
  1627. return null;
  1628. }
  1629. };
  1630.  
  1631. cleanContext(win).then(__CONTEXT__ => {
  1632. if (!__CONTEXT__) return null;
  1633.  
  1634. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, getComputedStyle, addEventListener, removeEventListener } = __CONTEXT__;
  1635.  
  1636.  
  1637. let foregroundPromise = null;
  1638. const foregroundPromiseFn = () => (foregroundPromise = (foregroundPromise || new Promise(resolve => {
  1639. requestAnimationFrame(() => {
  1640. foregroundPromise = null;
  1641. resolve();
  1642. });
  1643. })));
  1644.  
  1645. let playerState = null;
  1646. let _playerState = null;
  1647. let lastPlayerProgress = null;
  1648. let relayCount = 0;
  1649. let playerEventsByIframeRelay = false;
  1650. let isPlayProgressTriggered = false;
  1651. let waitForInitialDataCompletion = 0;
  1652.  
  1653.  
  1654.  
  1655. let aeConstructor = null;
  1656.  
  1657. // << __openedChanged82 >>
  1658. let currentMenuPivotWR = null;
  1659.  
  1660. // << if DO_PARTICIPANT_LIST_HACKS >>
  1661. const beforeParticipantsMap = new WeakMap();
  1662. // << end >>
  1663.  
  1664.  
  1665.  
  1666. // << if onRegistryReadyForDOMOperations >>
  1667.  
  1668. let dt0 = Date.now() - 2000;
  1669. const dateNow = () => Date.now() - dt0;
  1670. // let lastScroll = 0;
  1671. // let lastLShow = 0;
  1672. let lastWheel = 0;
  1673. let lastMouseDown = 0;
  1674. let lastMouseUp = 0;
  1675. let currentMouseDown = false;
  1676. let lastTouchDown = 0;
  1677. let lastTouchUp = 0;
  1678. let currentTouchDown = false;
  1679. let lastUserInteraction = 0;
  1680.  
  1681. let scrollChatFn = null;
  1682.  
  1683. let skipDontRender = true; // true first; false by flushActiveItems_
  1684. let allowDontRender = null;
  1685.  
  1686. // ---- #items mutation ----
  1687. let sk35zResolveFn = null;
  1688. let firstList = true;
  1689.  
  1690. // << end >>
  1691.  
  1692. class RAFHub {
  1693. constructor() {
  1694. /** @type {number} */
  1695. this.startAt = 8170;
  1696. /** @type {number} */
  1697. this.counter = 0;
  1698. /** @type {number} */
  1699. this.rid = 0;
  1700. /** @type {Map<number, FrameRequestCallback>} */
  1701. this.funcs = new Map();
  1702. const funcs = this.funcs;
  1703. /** @type {FrameRequestCallback} */
  1704. this.bCallback = this.mCallback.bind(this);
  1705. this.pClear = () => funcs.clear();
  1706. this.keepRAF = false;
  1707. }
  1708. /** @param {DOMHighResTimeStamp} highResTime */
  1709. mCallback(highResTime) {
  1710. this.rid = 0;
  1711. Promise.resolve().then(this.pClear);
  1712. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  1713. }
  1714. /** @param {FrameRequestCallback} f */
  1715. request(f) {
  1716. if (this.counter > 1e9) this.counter = 9;
  1717. let cid = this.startAt + (++this.counter);
  1718. this.funcs.set(cid, f);
  1719. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  1720. return cid;
  1721. }
  1722. /** @param {number} cid */
  1723. cancel(cid) {
  1724. cid = +cid;
  1725. if (cid > 0) {
  1726. if (cid <= this.startAt) {
  1727. return cancelAnimationFrame(cid);
  1728. }
  1729. if (this.rid > 0) {
  1730. this.funcs.delete(cid);
  1731. if (this.funcs.size === 0 && !this.keepRAF) {
  1732. cancelAnimationFrame(this.rid);
  1733. this.rid = 0;
  1734. }
  1735. }
  1736. }
  1737. }
  1738. }
  1739.  
  1740. function basePrefetching() {
  1741.  
  1742. new Promise(resolve => {
  1743.  
  1744. if (document.readyState !== 'loading') {
  1745. resolve();
  1746. } else {
  1747. win.addEventListener("DOMContentLoaded", resolve, false);
  1748. }
  1749.  
  1750. }).then(() => {
  1751. const hostL1 = [
  1752. 'https://www.youtube.com', 'https://googlevideo.com',
  1753. 'https://googleapis.com', 'https://accounts.youtube.com',
  1754. 'https://www.gstatic.com', 'https://ggpht.com',
  1755. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  1756. ];
  1757.  
  1758. const hostL2 = [
  1759. 'https://youtube.com',
  1760. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  1761. ];
  1762.  
  1763. let link = null;
  1764.  
  1765. function kn() {
  1766.  
  1767. link = document.createElement('link');
  1768. if (link.relList && link.relList.supports) {
  1769. kptPF = (link.relList.supports('dns-prefetch') ? 1 : 0) + (link.relList.supports('preconnect') ? 2 : 0) + (link.relList.supports('prefetch') ? 4 : 0) + (link.relList.supports('subresource') ? 8 : 0) + (link.relList.supports('preload') ? 16 : 0)
  1770. } else {
  1771. kptPF = 0;
  1772. }
  1773.  
  1774. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  1775. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  1776. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  1777. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  1778. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  1779. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  1780. console.groupEnd();
  1781.  
  1782. }
  1783.  
  1784. for (const h of hostL1) {
  1785.  
  1786. if (kptPF === null) kn();
  1787. if (ENABLE_BASE_PREFETCHING) {
  1788. // if (kptPF & 1) {
  1789. // linker(link, 'dns-prefetch', h);
  1790. // link = null;
  1791. // }
  1792. if (kptPF & 2) {
  1793. linker(link, 'preconnect', h);
  1794. link = null;
  1795. }
  1796. }
  1797. }
  1798.  
  1799. for (const h of hostL2) {
  1800. if (kptPF === null) kn();
  1801. if (ENABLE_BASE_PREFETCHING) {
  1802. if (kptPF & 1) {
  1803. linker(link, 'dns-prefetch', h);
  1804. link = null;
  1805. }
  1806. }
  1807. }
  1808.  
  1809. })
  1810.  
  1811.  
  1812. }
  1813.  
  1814. if (DO_LINK_PREFETCH) basePrefetching();
  1815.  
  1816. const { notifyPath7081 } = (() => {
  1817. // DO_PARTICIPANT_LIST_HACKS
  1818.  
  1819. const mutexParticipants = new Mutex();
  1820.  
  1821. let uvid = 0;
  1822. let r95dm = 0;
  1823. let c95dm = -1;
  1824.  
  1825. const foundMap = (base, content) => {
  1826. /*
  1827. let lastSearch = 0;
  1828. let founds = base.map(baseEntry => {
  1829. let search = content.indexOf(baseEntry, lastSearch);
  1830. if (search < 0) return false;
  1831. lastSearch = search + 1;
  1832. return true;
  1833. });
  1834. return founds;
  1835. */
  1836. const contentSet = new Set(content);
  1837. return base.map(baseEntry => contentSet.has(baseEntry));
  1838.  
  1839. }
  1840.  
  1841.  
  1842.  
  1843. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  1844.  
  1845. const handler1 = {
  1846. get(target, prop, receiver) {
  1847. if (prop === 'object') {
  1848. return participants; // avoid memory leakage
  1849. }
  1850. if (prop === 'type') {
  1851. return 'splice';
  1852. }
  1853. return target[prop];
  1854. }
  1855. };
  1856. const releaser = () => {
  1857. participants = null;
  1858. }
  1859.  
  1860. let foundsForAfter = foundMap(idsAfter, idsBefore);
  1861. let foundsForBefore = foundMap(idsBefore, idsAfter);
  1862.  
  1863. let indexSplices = [];
  1864. let contentUpdates = [];
  1865. for (let i = 0, j = 0; i < foundsForBefore.length || j < foundsForAfter.length;) {
  1866. if (beforeParticipants[i] === participants[j]) {
  1867. i++; j++;
  1868. } else if (idsBefore[i] === idsAfter[j]) {
  1869. // content changed
  1870. contentUpdates.push({ indexI: i, indexJ: j })
  1871. i++; j++;
  1872. } else {
  1873. let addedCount = 0;
  1874. for (let q = j; q < foundsForAfter.length; q++) {
  1875. if (foundsForAfter[q] === false) addedCount++;
  1876. else break;
  1877. }
  1878. let removedCount = 0;
  1879. for (let q = i; q < foundsForBefore.length; q++) {
  1880. if (foundsForBefore[q] === false) removedCount++;
  1881. else break;
  1882. }
  1883. if (!addedCount && !removedCount) {
  1884. throw 'ERROR(0xFF32): spliceIndicesFunc';
  1885. }
  1886. indexSplices.push(new Proxy({
  1887. index: j,
  1888. addedCount: addedCount,
  1889. removed: removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  1890. }, handler1));
  1891. i += removedCount;
  1892. j += addedCount;
  1893. }
  1894. }
  1895. foundsForBefore = null;
  1896. foundsForAfter = null;
  1897. idsBefore = null;
  1898. idsAfter = null;
  1899. beforeParticipants = null;
  1900. return { indexSplices, contentUpdates, releaser };
  1901.  
  1902. }
  1903.  
  1904. /*
  1905.  
  1906. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  1907.  
  1908. VM63631:1 Error
  1909. at customElements.get.notifyPath (<anonymous>:1:122)
  1910. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  1911. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  1912. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  1913. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  1914. at ju (live_chat_polymer.js:1674:217)
  1915. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  1916. at b._flushProperties (live_chat_polymer.js:1597:200)
  1917. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  1918. at a.notifyPath (live_chat_polymer.js:1741:182)
  1919.  
  1920. */
  1921.  
  1922. function convertToIds(participants) {
  1923. return participants.map(participant => {
  1924. if (!participant || typeof participant !== 'object') {
  1925. console.warn('Error(0xFA41): convertToIds', participant);
  1926. return participant; // just in case
  1927. }
  1928. let keys = Object.keys(participant);
  1929. // liveChatTextMessageRenderer
  1930. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  1931. // liveChatPaidMessageRenderer
  1932. /*
  1933.  
  1934. 'yt-live-chat-participant-renderer' utilizes the following:
  1935. authorName.simpleText: string
  1936. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  1937. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  1938. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  1939. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  1940.  
  1941. */
  1942. if (keys.length !== 1) {
  1943. console.warn('Error(0xFA42): convertToIds', participant);
  1944. return participant; // just in case
  1945. }
  1946. let key = keys[0];
  1947. let renderer = (participant[key] || 0);
  1948. let authorName = (renderer.authorName || 0);
  1949. let text = `${authorName.simpleText || authorName.text}`
  1950. let res = participant; // fallback if it is not a vaild entry
  1951. if (typeof text !== 'string') {
  1952. console.warn('Error(0xFA53): convertToIds', participant);
  1953. } else {
  1954. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  1955. if (text.length > 1) res = text;
  1956. }
  1957. return res;
  1958. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  1959. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  1960. });
  1961. }
  1962.  
  1963. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  1964. // just update when content is changed.
  1965. if (p1.authorName !== p2.authorName) return true;
  1966. if (p1.authorPhoto !== p2.authorPhoto) return true;
  1967. if (p1.authorBadges !== p2.authorBadges) return true;
  1968. return false;
  1969. } : (p1, p2) => {
  1970. // keep integrity all the time.
  1971. return p1 !== p2; // always true
  1972. }
  1973.  
  1974. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  1975.  
  1976. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  1977. if (path !== "participantsManager.participants") {
  1978. return this.__notifyPath5036__.apply(this, arguments);
  1979. }
  1980. if (c95dm === r95dm) return;
  1981. } else {
  1982. const stack = new Error().stack;
  1983. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  1984. return this.__notifyPath5036__.apply(this, arguments);
  1985. }
  1986. }
  1987.  
  1988. if (uvid > 1e8) uvid = uvid % 100;
  1989. let tid = ++uvid;
  1990.  
  1991. const cnt = this; // "yt-live-chat-participant-list-renderer"
  1992. mutexParticipants.lockWith(lockResolve => {
  1993.  
  1994. const participants00 = cnt.participantsManager.participants;
  1995.  
  1996. if (tid !== uvid || typeof (participants00 || 0).splice !== 'function') {
  1997. lockResolve();
  1998. return;
  1999. }
  2000.  
  2001. let doUpdate = false;
  2002.  
  2003. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2004.  
  2005. if (!participants00.r94dm) {
  2006. participants00.r94dm = 1;
  2007. if (++r95dm > 1e9) r95dm = 9;
  2008. participants00.push = function () {
  2009. if (++r95dm > 1e9) r95dm = 9;
  2010. return Array.prototype.push.apply(this, arguments);
  2011. }
  2012. participants00.pop = function () {
  2013. if (++r95dm > 1e9) r95dm = 9;
  2014. return Array.prototype.pop.apply(this, arguments);
  2015. }
  2016. participants00.shift = function () {
  2017. if (++r95dm > 1e9) r95dm = 9;
  2018. return Array.prototype.shift.apply(this, arguments);
  2019. }
  2020. participants00.unshift = function () {
  2021. if (++r95dm > 1e9) r95dm = 9;
  2022. return Array.prototype.unshift.apply(this, arguments);
  2023. }
  2024. participants00.splice = function () {
  2025. if (++r95dm > 1e9) r95dm = 9;
  2026. return Array.prototype.splice.apply(this, arguments);
  2027. }
  2028. participants00.sort = function () {
  2029. if (++r95dm > 1e9) r95dm = 9;
  2030. return Array.prototype.sort.apply(this, arguments);
  2031. }
  2032. participants00.reverse = function () {
  2033. if (++r95dm > 1e9) r95dm = 9;
  2034. return Array.prototype.reverse.apply(this, arguments);
  2035. }
  2036. }
  2037.  
  2038. if (c95dm !== r95dm) {
  2039. c95dm = r95dm;
  2040. doUpdate = true;
  2041. }
  2042.  
  2043. } else {
  2044. doUpdate = true;
  2045. }
  2046.  
  2047. if (!doUpdate) {
  2048. lockResolve();
  2049. return;
  2050. }
  2051.  
  2052. const participants = participants00.slice(0);
  2053. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  2054. beforeParticipantsMap.set(cnt, participants);
  2055.  
  2056. const resPromise = (async () => {
  2057.  
  2058. if (beforeParticipants.length === 0) {
  2059. // not error
  2060. return 0;
  2061. }
  2062.  
  2063. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  2064.  
  2065. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  2066. if (beforeParticipants.length !== countOfElements) {
  2067. // there is somewrong for the cache. - sometimes happen
  2068. return 0;
  2069. }
  2070.  
  2071. const idsBefore = convertToIds(beforeParticipants);
  2072. const idsAfter = convertToIds(participants);
  2073.  
  2074. let { indexSplices, contentUpdates, releaser } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  2075.  
  2076. let res = 1; // default 1 for no update
  2077.  
  2078. if (indexSplices.length >= 1) {
  2079.  
  2080.  
  2081. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  2082. // let p1 = indexSplices[0].removed;
  2083. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  2084.  
  2085. /* folllow
  2086. a.notifyPath(c + ".splices", d);
  2087. a.notifyPath(c + ".length", b.length);
  2088. */
  2089. // stampDomArraySplices_
  2090.  
  2091.  
  2092. await new Promise(resolve => {
  2093. cnt.resolveForDOMRendering781 = resolve;
  2094.  
  2095. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  2096. indexSplices
  2097. });
  2098. indexSplices = null;
  2099. releaser();
  2100. releaser = null;
  2101. cnt.__notifyPath5036__("participantsManager.participants.length",
  2102. participants.length
  2103. );
  2104.  
  2105. });
  2106.  
  2107. await Promise.resolve(0); // play safe for the change of 'length'
  2108. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  2109.  
  2110. let wrongSize = participants.length !== countOfElements
  2111. if (wrongSize) {
  2112. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  2113. return 0;
  2114. }
  2115.  
  2116. res = 2 | 4;
  2117.  
  2118. } else {
  2119.  
  2120. indexSplices = null;
  2121. releaser();
  2122. releaser = null;
  2123.  
  2124. if (participants.length !== countOfElements) {
  2125. // other unhandled cases
  2126. return 0;
  2127. }
  2128.  
  2129. }
  2130.  
  2131. // participants.length === countOfElements before contentUpdates
  2132. if (contentUpdates.length >= 1) {
  2133. for (const contentUpdate of contentUpdates) {
  2134. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  2135. if (isChanged) {
  2136. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  2137. res |= 4 | 8;
  2138. }
  2139. }
  2140. }
  2141. contentUpdates = null;
  2142.  
  2143. return res;
  2144.  
  2145.  
  2146. })();
  2147.  
  2148.  
  2149. resPromise.then(resValue => {
  2150.  
  2151. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  2152. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  2153. if (resValue === 0) {
  2154. new Promise(resolve => {
  2155. cnt.resolveForDOMRendering781 = resolve;
  2156. isLogRequired && console.log("Full Refresh begins");
  2157. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  2158. }).then(() => {
  2159. isLogRequired && console.log("Full Refresh ends");
  2160. console.groupEnd();
  2161. }).then(lockResolve);
  2162. return;
  2163. }
  2164.  
  2165. const delayLockResolve = (resValue & 4) === 4;
  2166.  
  2167. if (delayLockResolve) {
  2168. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  2169. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  2170. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  2171. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  2172. isLogRequired && console.groupEnd();
  2173. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  2174. // mutex lock with requestAnimationFrame can also disable participants update in background
  2175. requestAnimationFrame(lockResolve);
  2176. } else {
  2177. lockResolve();
  2178. }
  2179.  
  2180. });
  2181.  
  2182. });
  2183.  
  2184. }
  2185.  
  2186. return { notifyPath7081 };
  2187.  
  2188. })();
  2189.  
  2190. const whenDefinedMultiple = async (tags) => {
  2191.  
  2192. const sTags = [...new Set(tags)];
  2193. const len = sTags.length;
  2194.  
  2195. const pTags = new Array(len);
  2196. for (let i = 0; i < len; i++) {
  2197. pTags[i] = customElements.whenDefined(sTags[i]);
  2198. }
  2199.  
  2200. await Promise.all(pTags);
  2201. pTags.length = 0;
  2202.  
  2203. return sTags;
  2204.  
  2205. }
  2206.  
  2207. const onRegistryReadyForDataManipulation = () => {
  2208.  
  2209. function dummy5035(a, b, c) { }
  2210. function dummy411(a, b, c) { }
  2211.  
  2212.  
  2213.  
  2214. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  2215.  
  2216. if (!DO_PARTICIPANT_LIST_HACKS) return;
  2217.  
  2218. const tag = "yt-live-chat-participant-list-renderer";
  2219. const cProto = getProto(document.createElement(tag));
  2220. if (!cProto || typeof cProto.attached !== 'function') {
  2221. // for _registered, proto.attached shall exist when the element is defined.
  2222. // for controller extraction, attached shall exist when instance creates.
  2223. console.warn(`proto.attached for ${tag} is unavailable.`);
  2224. return;
  2225. }
  2226.  
  2227.  
  2228. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  2229.  
  2230. const fgsArr = ['kevlar_tuner_should_test_maintain_stable_list', 'kevlar_should_maintain_stable_list', 'kevlar_tuner_should_test_reuse_components', 'kevlar_tuner_should_reuse_components'];
  2231. const fgs = {};
  2232. for (const key of fgsArr) fgs[key] = undefined;
  2233.  
  2234. try {
  2235. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  2236. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  2237. } catch (e) { }
  2238. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  2239.  
  2240. const canDoReplacement = (() => {
  2241. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  2242. console.warn('YouTube Live Chat Tamer is running.');
  2243. return;
  2244. }
  2245.  
  2246. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  2247. console.warn('YouTube Live Chat Tamer is running.');
  2248. return;
  2249. }
  2250.  
  2251. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  2252. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  2253.  
  2254. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  2255. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  2256. return;
  2257. }
  2258.  
  2259. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  2260. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  2261. return;
  2262. }
  2263.  
  2264. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  2265. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  2266. return;
  2267. }
  2268. return true;
  2269. })();
  2270.  
  2271. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  2272.  
  2273. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  2274. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  2275. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  2276. const s = fiRSCB.split('.');
  2277. if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  2278. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  2279. } else {
  2280. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - NG`);
  2281. }
  2282. } else {
  2283. console.log("flushRenderStamperComponentBindings_ - not found");
  2284. }
  2285. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  2286.  
  2287. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  2288. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  2289. cProto.flushRenderStamperComponentBindings_ = function () {
  2290. // console.log('flushRenderStamperComponentBindings_')
  2291. this.flushRenderStamperComponentBindings66_();
  2292. if (this.resolveForDOMRendering781) {
  2293. this.resolveForDOMRendering781();
  2294. this.resolveForDOMRendering781 = null;
  2295. }
  2296. };
  2297. }
  2298.  
  2299. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  2300. const container = ((this || 0).$ || 0).participants;
  2301. if (!container) return 0;
  2302. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  2303. }
  2304.  
  2305. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  2306.  
  2307. cProto.__attached412__ = cProto.attached;
  2308. const fpPList = function (hostElement) {
  2309. const cnt = insp(hostElement);
  2310. if (beforeParticipantsMap.has(cnt)) return;
  2311. hostElement.classList.add('n9fJ3');
  2312.  
  2313. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  2314. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  2315. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  2316. return;
  2317. }
  2318.  
  2319. groupCollapsed("Participant List attached", "");
  2320. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  2321. // console.log(123, 'appendChild');
  2322. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  2323. // }
  2324.  
  2325. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  2326. // console.log(123, 'insertBefore');
  2327. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  2328. // }
  2329.  
  2330. cnt.__notifyPath5036__ = cnt.notifyPath
  2331. const participants = ((cnt.participantsManager || 0).participants || 0);
  2332. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  2333. console.log(`initial number of participants: ${participants.length}`);
  2334. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  2335. beforeParticipantsMap.set(cnt, newParticipants);
  2336. cnt.notifyPath = notifyPath7081;
  2337. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  2338. console.groupEnd();
  2339. }
  2340. cProto.attached = function () {
  2341. fpPList(this.hostElement || this);
  2342. this.__attached412__.apply(this, arguments);
  2343. };
  2344.  
  2345.  
  2346. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  2347.  
  2348. /** @type {boolean | (()=>boolean)} */
  2349. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  2350. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  2351.  
  2352. let lastMessageDate = 0;
  2353. cProto.stampDomArray66_ = cProto.stampDomArray_;
  2354.  
  2355. cProto.stampDomArray_ = function (...args) {
  2356. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  2357. if (typeof toUseMaintainStableList === 'function') {
  2358. toUseMaintainStableList = toUseMaintainStableList();
  2359. }
  2360. args[5] = toUseMaintainStableList;
  2361. let currentDate = Date.now();
  2362. if (currentDate - lastMessageDate > 440) {
  2363. lastMessageDate = currentDate;
  2364. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  2365. }
  2366. }
  2367. return this.stampDomArray66_.apply(this, args);
  2368. }
  2369.  
  2370. cProto.stampDomArray_.nIegT = 1;
  2371.  
  2372. }
  2373. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  2374. } else {
  2375. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  2376. }
  2377.  
  2378. console.groupEnd();
  2379.  
  2380. if (onPageElements.length >= 1) {
  2381. for (const s of onPageElements) {
  2382. if (insp(s).isAttached === true) {
  2383. fpPList(s);
  2384. }
  2385. }
  2386. }
  2387.  
  2388. }).catch(console.warn);
  2389.  
  2390. };
  2391.  
  2392. if (DO_PARTICIPANT_LIST_HACKS) {
  2393. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  2394. }
  2395.  
  2396.  
  2397.  
  2398. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  2399.  
  2400.  
  2401.  
  2402.  
  2403. const bnForDelayChatOccurrence = () => {
  2404.  
  2405. document.addEventListener('animationstart', (evt) => {
  2406.  
  2407. if (evt.animationName === 'dontRenderAnimation') {
  2408. evt.target.classList.remove('dont-render');
  2409. if (scrollChatFn) scrollChatFn();
  2410. }
  2411.  
  2412. }, true);
  2413.  
  2414. const f = (elm) => {
  2415. if (elm && elm.nodeType === 1) {
  2416. if (!skipDontRender && allowDontRender === true) {
  2417. // innerTextFixFn();
  2418. elm.classList.add('dont-render');
  2419. }
  2420. }
  2421. }
  2422.  
  2423. Node.prototype.__appendChild931__ = function (a) {
  2424. a = dr(a);
  2425. if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  2426. if (a && a.nodeType === 1) f(a);
  2427. else if (a instanceof DocumentFragment) {
  2428. for (let n = a.firstChild; n; n = n.nextSibling) {
  2429. f(n);
  2430. }
  2431. }
  2432. }
  2433. }
  2434.  
  2435. Node.prototype.__appendChild932__ = function () {
  2436. this.__appendChild931__.apply(this, arguments);
  2437. return Node.prototype.appendChild.apply(this, arguments);
  2438. }
  2439.  
  2440.  
  2441. };
  2442.  
  2443. const watchUserCSS = () => {
  2444.  
  2445. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  2446.  
  2447. const getElemFromWR = (nr) => {
  2448. const n = kRef(nr);
  2449. if (n && n.isConnected) return n;
  2450. return null;
  2451. }
  2452.  
  2453. const clearContentVisibilitySizing = () => {
  2454. Promise.resolve().then(() => {
  2455.  
  2456. const e = document.querySelector('#show-more[disabled]');
  2457. let btnShowMoreWR = e ? mWeakRef(e) : null;
  2458.  
  2459. let lastVisibleItemWR = null;
  2460. for (const elm of document.querySelectorAll('[wSr93]')) {
  2461. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  2462. elm.setAttribute('wSr93', '');
  2463. // custom CSS property --wsr94 not working when attribute wSr93 removed
  2464. }
  2465. requestAnimationFrame(() => {
  2466. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  2467. if (btnShowMore) btnShowMore.click();
  2468. else {
  2469. // would not work if switch it frequently
  2470. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  2471. if (lastVisibleItem) {
  2472.  
  2473. Promise.resolve()
  2474. .then(() => lastVisibleItem.scrollIntoView())
  2475. .then(() => lastVisibleItem.scrollIntoView(false))
  2476. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  2477. .catch(e => { }) // break the chain when method not callable
  2478.  
  2479. }
  2480. }
  2481. });
  2482.  
  2483. });
  2484.  
  2485. }
  2486.  
  2487. const mutObserver = new MutationObserver((mutations) => {
  2488. for (const mutation of mutations) {
  2489. if ((mutation.addedNodes || 0).length >= 1) {
  2490. for (const addedNode of mutation.addedNodes) {
  2491. if (addedNode.nodeName === 'STYLE') {
  2492. clearContentVisibilitySizing();
  2493. return;
  2494. }
  2495. }
  2496. }
  2497. if ((mutation.removedNodes || 0).length >= 1) {
  2498. for (const removedNode of mutation.removedNodes) {
  2499. if (removedNode.nodeName === 'STYLE') {
  2500. clearContentVisibilitySizing();
  2501. return;
  2502. }
  2503. }
  2504. }
  2505. }
  2506. });
  2507.  
  2508. mutObserver.observe(document.documentElement, {
  2509. childList: true,
  2510. subtree: false
  2511. });
  2512. mutObserver.observe(document.head, {
  2513. childList: true,
  2514. subtree: false
  2515. });
  2516. mutObserver.observe(document.body, {
  2517. childList: true,
  2518. subtree: false
  2519. });
  2520.  
  2521. }
  2522.  
  2523.  
  2524. class WillChangeController {
  2525. constructor(itemScroller, willChangeValue) {
  2526. this.element = itemScroller;
  2527. this.counter = 0;
  2528. this.active = false;
  2529. this.willChangeValue = willChangeValue;
  2530. }
  2531.  
  2532. beforeOper() {
  2533. if (!this.active) {
  2534. this.active = true;
  2535. this.element.style.willChange = this.willChangeValue;
  2536. }
  2537. this.counter++;
  2538. }
  2539.  
  2540. afterOper() {
  2541. const c = this.counter;
  2542. requestAnimationFrame(() => {
  2543. if (c === this.counter) {
  2544. this.active = false;
  2545. this.element.style.willChange = '';
  2546. }
  2547. });
  2548. }
  2549.  
  2550. release() {
  2551. const element = this.element;
  2552. this.element = null;
  2553. this.counter = 1e16;
  2554. this.active = false;
  2555. try {
  2556. element.style.willChange = '';
  2557. } catch (e) { }
  2558. }
  2559.  
  2560. }
  2561.  
  2562.  
  2563. const skzData = (skz) => skz.data = {
  2564. "message": {
  2565. "runs": [
  2566. {
  2567. "text": "em2o"
  2568. },
  2569. {
  2570. "emoji": {
  2571. "emojiId": "cm35z",
  2572. "shortcuts": [
  2573. ":_s:",
  2574. ":s:"
  2575. ],
  2576. "searchTerms": [
  2577. "_s",
  2578. "s"
  2579. ],
  2580. "image": {
  2581. "thumbnails": [
  2582. {
  2583. "url": dummyImgURL,
  2584. "width": 48,
  2585. "height": 48
  2586. }
  2587. ],
  2588. "accessibility": {
  2589. "accessibilityData": {
  2590. "label": "s"
  2591. }
  2592. }
  2593. },
  2594. "isCustomEmoji": true
  2595. }
  2596. },
  2597. {
  2598. "text": "ji"
  2599. }
  2600. ]
  2601. },
  2602. "authorName": {
  2603. "simpleText": "N"
  2604. },
  2605. "authorPhoto": {
  2606. "thumbnails": [
  2607. {
  2608. "url": dummyImgURL,
  2609. "width": 64,
  2610. "height": 64
  2611. }
  2612. ]
  2613. },
  2614. "contextMenuEndpoint": {
  2615. "commandMetadata": {
  2616. "webCommandMetadata": {
  2617. "ignoreNavigation": true
  2618. }
  2619. },
  2620. "liveChatItemContextMenuEndpoint": {
  2621. "params": "123=="
  2622. }
  2623. },
  2624. "id": "sk35z",
  2625. "timestampUsec": "1232302352350000",
  2626. "authorBadges": [
  2627. {
  2628. "liveChatAuthorBadgeRenderer": {
  2629. "customThumbnail": {
  2630. "thumbnails": [
  2631. {
  2632. "url": dummyImgURL,
  2633. "width": 16,
  2634. "height": 16
  2635. },
  2636. {
  2637. "url": dummyImgURL,
  2638. "width": 32,
  2639. "height": 32
  2640. }
  2641. ]
  2642. },
  2643. "tooltip": "T",
  2644. "accessibility": {
  2645. "accessibilityData": {
  2646. "label": "E"
  2647. }
  2648. }
  2649. }
  2650. }
  2651. ],
  2652. "authorExternalChannelId": "A",
  2653. "contextMenuAccessibility": {
  2654. "accessibilityData": {
  2655. "label": "E"
  2656. }
  2657. },
  2658. "timestampText": {
  2659. "simpleText": "0:43"
  2660. }
  2661. };
  2662.  
  2663.  
  2664.  
  2665. const { lcRendererElm, visObserver } = (() => {
  2666.  
  2667.  
  2668.  
  2669. let lcRendererWR = null;
  2670.  
  2671. const lcRendererElm = () => {
  2672. let lcRenderer = kRef(lcRendererWR);
  2673. if (!lcRenderer || !lcRenderer.isConnected) {
  2674. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  2675. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  2676. }
  2677. return lcRenderer;
  2678. };
  2679.  
  2680.  
  2681. let hasFirstShowMore = false;
  2682.  
  2683. const visObserverFn = (entry) => {
  2684.  
  2685. const target = entry.target;
  2686. if (!target) return;
  2687. // if(target.classList.contains('dont-render')) return;
  2688. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  2689. // const h = entry.boundingClientRect.height;
  2690. /*
  2691. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  2692. // e.g. under fullscreen. the element created but not rendered.
  2693. target.setAttribute('wSr93', '');
  2694. return;
  2695. }
  2696. */
  2697. if (isVisible) {
  2698. // target.style.setProperty('--wsr94', h + 'px');
  2699. target.setAttribute('wSr93', 'visible');
  2700. if (nNextElem(target) === null) {
  2701.  
  2702. // firstVisibleItemDetected = true;
  2703. /*
  2704. if (dateNow() - lastScroll < 80) {
  2705. lastLShow = 0;
  2706. lastScroll = 0;
  2707. Promise.resolve().then(clickShowMore);
  2708. } else {
  2709. lastLShow = dateNow();
  2710. }
  2711. */
  2712. // lastLShow = dateNow();
  2713. } else if (!hasFirstShowMore) { // should more than one item being visible
  2714. // implement inside visObserver to ensure there is sufficient delay
  2715. hasFirstShowMore = true;
  2716. requestAnimationFrame(() => {
  2717. // foreground page
  2718. // page visibly ready -> load the latest comments at initial loading
  2719. const lcRenderer = lcRendererElm();
  2720. if (lcRenderer) {
  2721. insp(lcRenderer).scrollToBottom_();
  2722. }
  2723. });
  2724. }
  2725. }
  2726. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  2727.  
  2728. // target.style.setProperty('--wsr94', h + 'px');
  2729. target.setAttribute('wSr93', 'hidden');
  2730. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  2731.  
  2732. }
  2733.  
  2734.  
  2735.  
  2736. const visObserver = new IntersectionObserver((entries) => {
  2737.  
  2738. for (const entry of entries) {
  2739.  
  2740. Promise.resolve(entry).then(visObserverFn);
  2741.  
  2742. }
  2743.  
  2744. }, {
  2745. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  2746. rootMargin: "0px",
  2747. threshold: [0.05, 0.95],
  2748. });
  2749.  
  2750.  
  2751. return { lcRendererElm, visObserver }
  2752.  
  2753.  
  2754. })();
  2755.  
  2756. const { setupMutObserver } = (() => {
  2757.  
  2758. const mutFn = (items) => {
  2759. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  2760. if (node.hasAttribute('wSr93')) break;
  2761. node.setAttribute('wSr93', '');
  2762. visObserver.observe(node);
  2763. }
  2764. }
  2765.  
  2766. const mutObserver = new MutationObserver((mutations) => {
  2767. const items = (mutations[0] || 0).target;
  2768. if (!items) return;
  2769. if (sk35zResolveFn) {
  2770. sk35zResolveFn();
  2771. sk35zResolveFn = null;
  2772. }
  2773. mutFn(items);
  2774. });
  2775.  
  2776. const setupMutObserver = (m2) => {
  2777. scrollChatFn = null;
  2778. mutObserver.disconnect();
  2779. mutObserver.takeRecords();
  2780. if (m2) {
  2781. ENABLE_DELAYED_CHAT_OCCURRENCE && bnForDelayChatOccurrence();
  2782. if (typeof m2.__appendChild932__ === 'function') {
  2783. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  2784. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  2785. }
  2786. mutObserver.observe(m2, {
  2787. childList: true,
  2788. subtree: false
  2789. });
  2790. mutFn(m2);
  2791.  
  2792. const isFirstList = firstList;
  2793. firstList = false;
  2794.  
  2795. if (ENABLE_OVERFLOW_ANCHOR) {
  2796.  
  2797. let items = m2;
  2798. let addedAnchor = false;
  2799. if (items) {
  2800. if (items.nextElementSibling === null) {
  2801. items.classList.add('no-anchor');
  2802. addedAnchor = true;
  2803. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  2804. }
  2805. }
  2806.  
  2807.  
  2808.  
  2809. if (addedAnchor) {
  2810. nodeParent(m2).classList.add('no-anchor'); // required
  2811. }
  2812.  
  2813. }
  2814.  
  2815. // let div = document.createElement('div');
  2816. // div.id = 'qwcc';
  2817. // HTMLElement.prototype.appendChild.call(document.querySelector('yt-live-chat-item-list-renderer'), div )
  2818. // bufferRegion =div;
  2819.  
  2820. // buffObserver.takeRecords();
  2821. // buffObserver.disconnect();
  2822. // buffObserver.observe(div, {
  2823. // childList: true,
  2824. // subtree: false
  2825. // })
  2826.  
  2827. if (ENABLE_DELAYED_CHAT_OCCURRENCE && isFirstList) {
  2828.  
  2829. promiseForCustomYtElementsReady.then(() => {
  2830.  
  2831. customElements.whenDefined('yt-live-chat-text-message-renderer').then(() => {
  2832.  
  2833.  
  2834.  
  2835.  
  2836. setTimeout(() => {
  2837.  
  2838. /** @type {HTMLTemplateElement} */
  2839. let skz = document.createElement('yt-live-chat-text-message-renderer');
  2840.  
  2841. let cz1 = null;
  2842.  
  2843. if (skz && 'data' in skz && 'attached' in skz) {
  2844.  
  2845. const deferredZy1 = new Promise(resolve => {
  2846.  
  2847. skz.attached = function () {
  2848. cz1 = HTMLElement.prototype.querySelector.call(skz, '#message img') !== null;
  2849. resolve(skz.textContent);
  2850. }
  2851. skz.detached = function () {
  2852.  
  2853. }
  2854.  
  2855. });
  2856. skz.id = 'sk35z';
  2857. skzData(skz);
  2858.  
  2859.  
  2860. sk35zResolveFn = null;
  2861. const deferredMutation = new Promise(resolve => {
  2862. sk35zResolveFn = resolve;
  2863. HTMLElement.prototype.appendChild.call(m2, skz);
  2864. });
  2865.  
  2866. Promise.all([deferredZy1, deferredMutation]).then(async (res) => {
  2867. const [zy1, _] = res;
  2868. function fn() {
  2869. const zy2 = skz.textContent;
  2870. const cz2 = HTMLElement.prototype.querySelector.call(skz, '#message img') !== null;
  2871. if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  2872. allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  2873. }
  2874. if (allowDontRender === false) {
  2875.  
  2876. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2877. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2878. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2879. );
  2880.  
  2881. console.warn(`%cWarning:\n\tYou might have added a userscript or extension that stops YouTube Super Fast Chat's quick loading.\n\tTo figure out which one affects the script, turn them off one by one and let the author know.`, 'color: #bada55');
  2882.  
  2883. console.groupEnd();
  2884. } else if (allowDontRender === true) {
  2885. return true;
  2886. }
  2887. }
  2888. await new Promise(r => setTimeout(r, 1));
  2889. if (fn()) {
  2890. await new Promise(r => requestAnimationFrame(r));
  2891. if (fn()) {
  2892. skz.remove();
  2893. skz.textContent = '';
  2894. console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2895. }
  2896. }
  2897. });
  2898.  
  2899. }
  2900.  
  2901. }, 1);
  2902.  
  2903. }).catch(console.warn);
  2904.  
  2905. })
  2906.  
  2907. }
  2908.  
  2909.  
  2910. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  2911.  
  2912. (() => {
  2913.  
  2914. const tag = 'yt-iframed-player-events-relay'
  2915. const dummy = document.createElement(tag);
  2916.  
  2917. const cProto = getProto(dummy);
  2918. if (!cProto || !cProto.handlePostMessage_) {
  2919. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  2920. return;
  2921. }
  2922.  
  2923. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_) {
  2924.  
  2925. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  2926.  
  2927. cProto.handlePostMessage67_ = function (a) {
  2928.  
  2929. const da = a.data;
  2930.  
  2931.  
  2932.  
  2933. playEventsStack = playEventsStack.then(() => {
  2934.  
  2935.  
  2936.  
  2937. if ('yt-player-state-change' in da) {
  2938.  
  2939. const qc = da['yt-player-state-change'];
  2940.  
  2941.  
  2942. let isQcChanged = false;
  2943.  
  2944. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  2945. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  2946. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  2947.  
  2948.  
  2949. if ((isQcChanged) && playerState !== _playerState) {
  2950. playerEventsByIframeRelay = true;
  2951. onPlayStateChangePromise = new Promise((resolve) => {
  2952. let k = _playerState;
  2953. foregroundPromiseFn().then(() => {
  2954. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  2955. onPlayStateChangePromise = null;
  2956. resolve();
  2957. })
  2958. }).catch(console.warn);
  2959.  
  2960. }
  2961.  
  2962. } else if ('yt-player-video-progress' in da) {
  2963. const vp = da['yt-player-video-progress'];
  2964.  
  2965.  
  2966. relayCount++;
  2967. lastPlayerProgress = vp > 0 ? vp : 0;
  2968.  
  2969.  
  2970. if (relayPromise && vp > 0 && relayCount >= 2) {
  2971. if (onPlayStateChangePromise) {
  2972. onPlayStateChangePromise.then(() => {
  2973. relayPromise && relayPromise.resolve();
  2974. relayPromise = null;
  2975. })
  2976. } else {
  2977. relayPromise.resolve();
  2978. relayPromise = null;
  2979. }
  2980. }
  2981.  
  2982.  
  2983.  
  2984. }
  2985.  
  2986.  
  2987.  
  2988.  
  2989.  
  2990.  
  2991. return this.handlePostMessage66_(a);
  2992.  
  2993.  
  2994.  
  2995. }).catch(console.warn);
  2996.  
  2997. }
  2998.  
  2999.  
  3000. cProto.handlePostMessage_ = function (a) {
  3001.  
  3002.  
  3003. const da = (a || 0).data || 0;
  3004.  
  3005. if (typeof da !== 'object') return;
  3006.  
  3007. if (waitForInitialDataCompletion === 1) return;
  3008.  
  3009. if (!isPlayProgressTriggered) {
  3010. isPlayProgressTriggered = true;
  3011.  
  3012. if ('yt-player-video-progress' in da) {
  3013. waitForInitialDataCompletion = 1;
  3014.  
  3015. const wrapWith = (data) => {
  3016. const { origin } = a;
  3017. return {
  3018. origin,
  3019. data
  3020. };
  3021. }
  3022.  
  3023. this.handlePostMessage67_(wrapWith({
  3024. "yt-iframed-parent-ready": true
  3025. }));
  3026.  
  3027.  
  3028.  
  3029. playEventsStack = playEventsStack.then(() => {
  3030.  
  3031.  
  3032.  
  3033. const lcr = document.querySelector('yt-live-chat-renderer');
  3034. const psc = document.querySelector("yt-player-seek-continuation");
  3035. if (lcr && psc && lcr.replayBuffer_) {
  3036.  
  3037.  
  3038. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  3039. const daProgress = da['yt-player-video-progress'] * 1000
  3040. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  3041.  
  3042.  
  3043. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  3044. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  3045.  
  3046.  
  3047. // console.log(deepCopy( front_))
  3048. // console.log(deepCopy( back_))
  3049. // console.log(rbProgress, daProgress, )
  3050. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  3051. // no action
  3052. // console.log('ss1')
  3053. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  3054. // daProgress - 1200 < rbProgress < daProgress + 3400
  3055. // console.log('ss2')
  3056. } else {
  3057.  
  3058. // console.log('ss3')
  3059. // lcr.replayBuffer_.replayQueue.back_.length= 0;
  3060. // lcr.replayBuffer_.replayQueue.front_.length= 0;
  3061.  
  3062. // lcr
  3063. lcr.previousProgressSec = 1E-5;
  3064. // lcr._setIsSeeking(!0),
  3065. lcr.replayBuffer_.clear()
  3066. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  3067. }
  3068.  
  3069. }
  3070.  
  3071.  
  3072. waitForInitialDataCompletion = 2;
  3073.  
  3074. this.handlePostMessage_(a);
  3075.  
  3076.  
  3077. }).catch(console.warn);
  3078.  
  3079.  
  3080.  
  3081. return;
  3082.  
  3083. }
  3084.  
  3085. }
  3086.  
  3087.  
  3088.  
  3089. this.handlePostMessage67_(a);
  3090.  
  3091.  
  3092.  
  3093. }
  3094.  
  3095. }
  3096.  
  3097.  
  3098. })();
  3099.  
  3100. }
  3101.  
  3102. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  3103. setTimeout(() => {
  3104. if (!hasTimerModified) return;
  3105. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  3106. if (!tickerRenderer) return;
  3107.  
  3108. const tickerRendererDollar = indr(tickerRenderer);
  3109. const items = (tickerRendererDollar || 0).items || 0;
  3110. if (!items) return;
  3111. const template = document.createElement('template');
  3112. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  3113. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  3114. dimmed="" [dummy777]>
  3115. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  3116. style="--background:linear-gradient(90deg, rgba(1,2,3,1),rgba(1,2,3,1) 7%,rgba(4,0,0,1) 7%,rgba(4,0,0,1));">
  3117. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  3118. <yt-img-shadow777 id="author-photo" height="24" width="24"
  3119. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  3120. style="background-color: transparent;" loaded=""><img id="img"
  3121. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  3122. src="${dummyImgURL}"></yt-img-shadow777>
  3123.  
  3124. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  3125. </div>
  3126. </div>
  3127. </yt-live-chat-ticker-dummy777-item-renderer>`;
  3128. const dummy777 = template.content.firstElementChild;
  3129. items.appendChild(dummy777);
  3130. Promise.resolve(dummy777).then((dummy777) => {
  3131. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  3132. if (container.isConnected === true) {
  3133.  
  3134. const evaluated = `${getComputedStyle(container).background}`;
  3135.  
  3136. container = null;
  3137. dummy777.remove();
  3138. dummy777.textContent = '';
  3139. dummy777 = null;
  3140.  
  3141. if (evaluated.indexOf('0.') < 4) {
  3142.  
  3143. // not fulfilling
  3144. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3145.  
  3146. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3147. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3148. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3149. );
  3150. console.warn(`%cWarning:\n\tYou might have added a userscript or extension that also modifies the ticker background.\n\tYouTube Super Fast Chat is taking over.`, 'color: #bada55');
  3151. console.groupEnd();
  3152.  
  3153. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  3154.  
  3155. } else {
  3156.  
  3157. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3158. }
  3159. }
  3160. });
  3161.  
  3162. }, 800);
  3163. }
  3164.  
  3165. }
  3166. }
  3167.  
  3168. return { setupMutObserver };
  3169.  
  3170.  
  3171.  
  3172. })();
  3173.  
  3174. const setupEvents = () => {
  3175.  
  3176.  
  3177. let scrollCount = 0;
  3178.  
  3179. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  3180.  
  3181.  
  3182. const delayFlushActiveItemsAfterUserActionK_ = () => {
  3183.  
  3184. const lcRenderer = lcRendererElm();
  3185. if (lcRenderer) {
  3186. const cnt = insp(lcRenderer);
  3187. if (!cnt.hasUserJustInteracted11_) return;
  3188. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  3189. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  3190. }
  3191. }
  3192.  
  3193. }
  3194.  
  3195. document.addEventListener('scroll', (evt) => {
  3196. if (!evt || !evt.isTrusted) return;
  3197. // lastScroll = dateNow();
  3198. if (++scrollCount > 1e9) scrollCount = 9;
  3199. }, passiveCapture); // support contain => support passive
  3200.  
  3201. let lastScrollCount = -1;
  3202. document.addEventListener('wheel', (evt) => {
  3203. if (!evt || !evt.isTrusted) return;
  3204. if (lastScrollCount === scrollCount) return;
  3205. lastScrollCount = scrollCount;
  3206. lastWheel = dateNow();
  3207. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3208. }, passiveCapture); // support contain => support passive
  3209.  
  3210. document.addEventListener('mousedown', (evt) => {
  3211. if (!evt || !evt.isTrusted) return;
  3212. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3213. lastMouseDown = dateNow();
  3214. currentMouseDown = true;
  3215. lastUserInteraction = lastMouseDown;
  3216. }, passiveCapture);
  3217.  
  3218. document.addEventListener('pointerdown', (evt) => {
  3219. if (!evt || !evt.isTrusted) return;
  3220. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3221. lastMouseDown = dateNow();
  3222. currentMouseDown = true;
  3223. lastUserInteraction = lastMouseDown;
  3224. }, passiveCapture);
  3225.  
  3226. document.addEventListener('click', (evt) => {
  3227. if (!evt || !evt.isTrusted) return;
  3228. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3229. lastMouseDown = lastMouseUp = dateNow();
  3230. currentMouseDown = false;
  3231. lastUserInteraction = lastMouseDown;
  3232. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3233. }, passiveCapture);
  3234.  
  3235. document.addEventListener('tap', (evt) => {
  3236. if (!evt || !evt.isTrusted) return;
  3237. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3238. lastMouseDown = lastMouseUp = dateNow();
  3239. currentMouseDown = false;
  3240. lastUserInteraction = lastMouseDown;
  3241. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3242. }, passiveCapture);
  3243.  
  3244.  
  3245. document.addEventListener('mouseup', (evt) => {
  3246. if (!evt || !evt.isTrusted) return;
  3247. if (currentMouseDown) {
  3248. lastMouseUp = dateNow();
  3249. currentMouseDown = false;
  3250. lastUserInteraction = lastMouseUp;
  3251. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3252. }
  3253. }, passiveCapture);
  3254.  
  3255.  
  3256. document.addEventListener('pointerup', (evt) => {
  3257. if (!evt || !evt.isTrusted) return;
  3258. if (currentMouseDown) {
  3259. lastMouseUp = dateNow();
  3260. currentMouseDown = false;
  3261. lastUserInteraction = lastMouseUp;
  3262. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3263. }
  3264. }, passiveCapture);
  3265.  
  3266. document.addEventListener('touchstart', (evt) => {
  3267. if (!evt || !evt.isTrusted) return;
  3268. lastTouchDown = dateNow();
  3269. currentTouchDown = true;
  3270. lastUserInteraction = lastTouchDown;
  3271. }, passiveCapture);
  3272.  
  3273. document.addEventListener('touchmove', (evt) => {
  3274. if (!evt || !evt.isTrusted) return;
  3275. lastTouchDown = dateNow();
  3276. currentTouchDown = true;
  3277. lastUserInteraction = lastTouchDown;
  3278. }, passiveCapture);
  3279.  
  3280. document.addEventListener('touchend', (evt) => {
  3281. if (!evt || !evt.isTrusted) return;
  3282. if (currentTouchDown) {
  3283. lastTouchUp = dateNow();
  3284. currentTouchDown = false;
  3285. lastUserInteraction = lastTouchUp;
  3286. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3287. }
  3288. }, passiveCapture);
  3289.  
  3290. document.addEventListener('touchcancel', (evt) => {
  3291. if (!evt || !evt.isTrusted) return;
  3292. if (currentTouchDown) {
  3293. lastTouchUp = dateNow();
  3294. currentTouchDown = false;
  3295. lastUserInteraction = lastTouchUp;
  3296. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3297. }
  3298. }, passiveCapture);
  3299.  
  3300.  
  3301. }
  3302.  
  3303. const getTimestampUsec = (itemRenderer) => {
  3304. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  3305. return itemRenderer.timestampUsec
  3306. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  3307. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  3308. if (messageRenderer) {
  3309.  
  3310. const messageRendererKey = firstObjectKey(messageRenderer);
  3311. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  3312. const messageRendererData = messageRenderer[messageRendererKey];
  3313. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  3314. return messageRendererData.timestampUsec
  3315. }
  3316. }
  3317. }
  3318. }
  3319. return null;
  3320. }
  3321.  
  3322. const onRegistryReadyForDOMOperations = () => {
  3323.  
  3324. let firstCheckedOnYtInit = false;
  3325.  
  3326. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  3327.  
  3328. const mightFirstCheckOnYtInit = () => {
  3329. if (firstCheckedOnYtInit) return;
  3330. firstCheckedOnYtInit = true;
  3331.  
  3332. if (!document.body || !document.head) return;
  3333. if (!assertorURL()) return;
  3334.  
  3335. addCssManaged();
  3336.  
  3337. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  3338. if (efsContainer && efsContainer.parentNode !== document.body) {
  3339. document.body.appendChild(efsContainer);
  3340. }
  3341.  
  3342. };
  3343.  
  3344. if (!assertorURL()) return;
  3345. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  3346.  
  3347. if (document.documentElement && document.head) {
  3348. addCssManaged();
  3349. }
  3350. // console.log(document.body===null)
  3351.  
  3352. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  3353. getLCRDummy().then(async (lcrDummy) => {
  3354.  
  3355. const tag = "yt-live-chat-renderer"
  3356. const dummy = lcrDummy;
  3357.  
  3358. const cProto = getProto(dummy);
  3359. if (!cProto || !cProto.attached) {
  3360. console.warn(`proto.attached for ${tag} is unavailable.`);
  3361. return;
  3362. }
  3363.  
  3364. mightFirstCheckOnYtInit();
  3365. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  3366. console.log("[Begin]");
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372.  
  3373. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  3374.  
  3375. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  3376.  
  3377. const pop078 = function () {
  3378. const r = this.pop78();
  3379.  
  3380. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  3381. for (const action of r.actions) {
  3382.  
  3383. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  3384. if (itemActionKey) {
  3385.  
  3386. const itemAction = action[itemActionKey];
  3387. const item = (itemAction || 0).item;
  3388. if (typeof item === 'object') {
  3389.  
  3390. const rendererKey = firstObjectKey(item);
  3391. if (rendererKey) {
  3392. const renderer = item[rendererKey];
  3393. if (renderer && typeof renderer === 'object') {
  3394. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  3395. renderer.__progressAt__ = playerProgressChangedArg1;
  3396. }
  3397.  
  3398. }
  3399.  
  3400. }
  3401. }
  3402. }
  3403. }
  3404. return r;
  3405. }
  3406.  
  3407. cProto.playerProgressChanged_ = function (a, b, c) {
  3408. playerProgressChangedArg1 = a;
  3409. playerProgressChangedArg2 = b;
  3410. playerProgressChangedArg3 = c;
  3411. const replayBuffer_ = this.replayBuffer_;
  3412. if (replayBuffer_) {
  3413. const replayQueue = replayBuffer_.replayQueue
  3414. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  3415.  
  3416. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, {
  3417. get(target, prop, receiver) {
  3418. if (prop === 'qe3') return 1;
  3419. const v = target[prop];
  3420. if (prop === 'front_') {
  3421. if (v && typeof v.length === 'number') {
  3422. if (!v.pop78) {
  3423. v.pop78 = v.pop;
  3424. v.pop = pop078;
  3425. }
  3426. }
  3427. }
  3428. return v;
  3429. }
  3430. });
  3431.  
  3432. }
  3433. }
  3434. return this.playerProgressChanged32_.apply(this, arguments);
  3435. };
  3436.  
  3437. }
  3438.  
  3439. // if (typeof cProto.immediatelyApplyLiveChatActions === 'function' && !cProto.immediatelyApplyLiveChatActions32) {
  3440.  
  3441. // cProto.immediatelyApplyLiveChatActions32 = cProto.immediatelyApplyLiveChatActions;
  3442.  
  3443. // cProto.immediatelyApplyLiveChatActions = function (a) {
  3444. // // if (a.length > 8) {
  3445. // // console.log(a)
  3446. // // }
  3447. // // console.log(a)
  3448. // /*
  3449. // let arr=a.slice();
  3450.  
  3451. // if(arr.length >= 2){
  3452. // arr.sort((a, b)=>{
  3453. // let ak = firstObjectKey(a);
  3454. // let bk = firstObjectKey(b);
  3455. // if(!ak||!bk) return 0;
  3456. // const ax = +a[ak]._timestampUsec57;
  3457. // const bx = +b[bk]._timestampUsec57;
  3458. // if(ax >0 && bx >0){
  3459. // const c = bx - ax ;
  3460.  
  3461. // return c > 0.1 ? -1 : c< -0.1 ? 1 : 0;
  3462. // }
  3463. // return 0;
  3464.  
  3465. // });
  3466. // console.log('sort', JSON.parse(JSON.stringify(arr)));
  3467. // }
  3468. // a=arr;
  3469. // */
  3470.  
  3471. // if (a && typeof a === 'object' && a.length >= 1) {
  3472. // const d = Date.now();
  3473. // const m = [];
  3474. // for (let i = 0, l = a.length; i < l; i++) {
  3475. // const action = a[i];
  3476. // const key = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  3477. // if (key === 'addChatItemAction' || key === 'addLiveChatTickerItemAction') {
  3478. // const itemAction = action[key] || 0;
  3479. // const item = itemAction.item || 0;
  3480. // if (item && typeof item === 'object') {
  3481. // let rendererKey = firstObjectKey(item);
  3482. // const renderer = item[rendererKey];
  3483. // let timestampUsec = getTimestampUsec(renderer);
  3484. // if (timestampUsec !== null) {
  3485. // renderer._timestampUsec57 = timestampUsec;
  3486. // }
  3487. // m.push(renderer);
  3488. // // if(timestampUsec!==null){
  3489. // // if(key==='addLiveChatTickerItemAction')console.log(renderer, rendererKey, key)
  3490. // // m.push(renderer);
  3491.  
  3492. // // }
  3493. // }
  3494. // }
  3495. // }
  3496. // if (m.length >= 1) {
  3497.  
  3498. // let lastUsec = null;
  3499. // for (let i = 0, l = m.length; i < l; i++) {
  3500. // const renderer = m[i];
  3501. // if ('_timestampUsec57' in renderer) {
  3502. // lastUsec = +renderer._timestampUsec57 / 1E3;
  3503. // renderer.__lcrTime__ = d;
  3504. // renderer.__actionAt__ = d;
  3505. // }
  3506. // }
  3507.  
  3508.  
  3509. // if (lastUsec !== null) {
  3510.  
  3511. // const refUsec = lastUsec
  3512.  
  3513. // let prevUsec = null;
  3514. // for (let i = 0, l = m.length; i < l; i++) {
  3515. // const renderer = m[i];
  3516. // if ('_timestampUsec57' in renderer) {
  3517.  
  3518. // let actualTime = +renderer._timestampUsec57 / 1E3; // ms
  3519. // let lcrTime = d - Math.round(refUsec - actualTime); // ms
  3520.  
  3521. // renderer.__lcrTime__ = lcrTime; // ms
  3522. // renderer.__actionAt__ = d;
  3523.  
  3524. // prevUsec = lcrTime
  3525. // } else {
  3526.  
  3527. // renderer._prevUsec57 = prevUsec;
  3528. // }
  3529. // }
  3530.  
  3531.  
  3532. // let nextUsec = null;
  3533. // for (let i = m.length - 1; i >= 0; i--) {
  3534. // const renderer = m[i];
  3535. // if ('_timestampUsec57' in renderer) {
  3536.  
  3537. // nextUsec = renderer.__lcrTime__
  3538. // } else {
  3539.  
  3540. // renderer._nextUsec57 = nextUsec;
  3541.  
  3542. // if (renderer._nextUsec57 > 0 && renderer._prevUsec57 > 0 && renderer._nextUsec57 > renderer._prevUsec57) {
  3543. // renderer.__lcrTime__ = (renderer._nextUsec57 + renderer._prevUsec57) / 2;
  3544. // renderer.__actionAt__ = d;
  3545. // }
  3546. // }
  3547. // }
  3548.  
  3549.  
  3550. // }
  3551.  
  3552.  
  3553. // }
  3554. // }
  3555. // return this.immediatelyApplyLiveChatActions32.apply(this, arguments)
  3556. // }
  3557.  
  3558.  
  3559. // }
  3560.  
  3561.  
  3562.  
  3563. console.log("[End]");
  3564. console.groupEnd();
  3565.  
  3566.  
  3567. });
  3568.  
  3569. }
  3570.  
  3571. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  3572.  
  3573. const tag = "yt-live-chat-item-list-renderer"
  3574. const dummy = document.createElement(tag);
  3575.  
  3576. const cProto = getProto(dummy);
  3577. if (!cProto || !cProto.attached) {
  3578. console.warn(`proto.attached for ${tag} is unavailable.`);
  3579. return;
  3580. }
  3581.  
  3582. mightFirstCheckOnYtInit();
  3583. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  3584. console.log("[Begin]");
  3585.  
  3586. const mclp = cProto;
  3587. try {
  3588. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  3589. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  3590. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  3591. assertor(() => typeof mclp.setAtBottom === 'function');
  3592. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  3593. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  3594. } catch (e) { }
  3595.  
  3596.  
  3597. try {
  3598. assertor(() => typeof mclp.attached === 'function');
  3599. assertor(() => typeof mclp.detached === 'function');
  3600. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  3601. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  3602. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  3603. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  3604. assertor(() => typeof mclp.smoothScroll_ === 'function');
  3605. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  3606. } catch (e) { }
  3607.  
  3608. mclp.__intermediate_delay__ = null;
  3609.  
  3610. let mzk = 0;
  3611. let myk = 0;
  3612. let mlf = 0;
  3613. let myw = 0;
  3614. let mzt = 0;
  3615. let zarr = null;
  3616. let mlg = 0;
  3617.  
  3618. if ((mclp.clearList || 0).length === 0) {
  3619. assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  3620. mclp.clearList66 = mclp.clearList;
  3621. mclp.clearList = function () {
  3622. mzk++;
  3623. myk++;
  3624. mlf++;
  3625. myw++;
  3626. mzt++;
  3627. mlg++;
  3628. zarr = null;
  3629. this.__intermediate_delay__ = null;
  3630. this.clearList66();
  3631. };
  3632. console.log("clearList", "OK");
  3633. } else {
  3634. console.log("clearList", "NG");
  3635. }
  3636.  
  3637.  
  3638. let onListRendererAttachedDone = false;
  3639.  
  3640. function setList(itemOffset, items) {
  3641.  
  3642. const isFirstTime = onListRendererAttachedDone === false;
  3643.  
  3644. if (isFirstTime) {
  3645. onListRendererAttachedDone = true;
  3646. Promise.resolve().then(watchUserCSS);
  3647. addCssManaged();
  3648. setupEvents();
  3649. }
  3650.  
  3651. setupStyle(itemOffset, items);
  3652.  
  3653. setupMutObserver(items);
  3654. }
  3655.  
  3656. mclp.attached419 = async function () {
  3657.  
  3658. if (!this.isAttached) return;
  3659.  
  3660. let maxTrial = 16;
  3661. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  3662. if (--maxTrial < 0 || !this.isAttached) return;
  3663. await new Promise(requestAnimationFrame);
  3664. }
  3665.  
  3666. if (this.isAttached !== true) return;
  3667.  
  3668. if (!this.$) {
  3669. console.warn("!this.$");
  3670. return;
  3671. }
  3672. if (!this.$) return;
  3673. /** @type {HTMLElement | null} */
  3674. const itemScroller = this.$['item-scroller'];
  3675. /** @type {HTMLElement | null} */
  3676. const itemOffset = this.$['item-offset'];
  3677. /** @type {HTMLElement | null} */
  3678. const items = this.$['items'];
  3679.  
  3680. if (!itemScroller || !itemOffset || !items) {
  3681. console.warn("items.parentNode !== itemOffset");
  3682. return;
  3683. }
  3684.  
  3685. if (nodeParent(items) !== itemOffset) {
  3686.  
  3687. console.warn("items.parentNode !== itemOffset");
  3688. return;
  3689. }
  3690.  
  3691.  
  3692. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  3693.  
  3694. console.warn("id incorrect");
  3695. return;
  3696. }
  3697.  
  3698. const isTargetItems = HTMLElement.prototype.matches.call(items, '#item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer')
  3699.  
  3700. if (!isTargetItems) {
  3701. console.warn("!isTargetItems");
  3702. return;
  3703. }
  3704.  
  3705. setList(itemOffset, items);
  3706.  
  3707. }
  3708.  
  3709. mclp.attached331 = mclp.attached;
  3710. mclp.attached = function () {
  3711. this.attached419 && this.attached419();
  3712. return this.attached331();
  3713. }
  3714.  
  3715. mclp.detached331 = mclp.detached;
  3716.  
  3717. mclp.detached = function () {
  3718. setupMutObserver();
  3719. return this.detached331();
  3720. }
  3721.  
  3722. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  3723. for (const t29 of t29s) {
  3724. if (insp(t29).isAttached === true) {
  3725. t29.attached419();
  3726. }
  3727. }
  3728.  
  3729. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  3730.  
  3731. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  3732. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  3733.  
  3734. /** @type {Map<number, any>} */
  3735. const aMap = new Map();
  3736. let count = 6150;
  3737. mclp.async66 = mclp.async;
  3738. mclp.async = function (e, f) {
  3739. // ensure the previous operation is done
  3740. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  3741. const hasF = arguments.length === 2;
  3742. const stack = new Error().stack;
  3743. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  3744. if (count > 1e9) count = 6159;
  3745. const resId = ++count;
  3746. aMap.set(resId, e);
  3747. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  3748. const rp = aMap.get(resId);
  3749. if (typeof rp !== 'function') {
  3750. return;
  3751. }
  3752. let cancelCall = false;
  3753. if (isFlushAsync) {
  3754. if (rk < 0) {
  3755. cancelCall = true;
  3756. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  3757. cancelCall = true;
  3758. }
  3759. }
  3760. if (cancelCall) {
  3761. aMap.delete(resId);
  3762. } else {
  3763. const asyncEn = function () {
  3764. aMap.delete(resId);
  3765. return rp.apply(this, arguments);
  3766. };
  3767. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  3768. }
  3769. });
  3770.  
  3771. return resId;
  3772. }
  3773.  
  3774. mclp.cancelAsync66 = mclp.cancelAsync;
  3775. mclp.cancelAsync = function (resId) {
  3776. if (resId <= 6150) {
  3777. this.cancelAsync66(resId);
  3778. } else if (aMap.has(resId)) {
  3779. const rp = aMap.get(resId);
  3780. aMap.delete(resId);
  3781. if (typeof rp !== 'function') {
  3782. this.cancelAsync66(rp);
  3783. }
  3784. }
  3785. }
  3786.  
  3787. console.log("async", "OK");
  3788. } else {
  3789. console.log("async", "NG");
  3790. }
  3791.  
  3792.  
  3793. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  3794.  
  3795. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  3796. mclp.showNewItems66_ = mclp.showNewItems_;
  3797.  
  3798. mclp.showNewItems77_ = async function () {
  3799. if (myk > 1e9) myk = 9;
  3800. let tid = ++myk;
  3801.  
  3802. await new Promise(requestAnimationFrame);
  3803.  
  3804. if (tid !== myk) {
  3805. return;
  3806. }
  3807.  
  3808. const cnt = this;
  3809.  
  3810. await Promise.resolve();
  3811. cnt.showNewItems66_();
  3812.  
  3813. await Promise.resolve();
  3814.  
  3815. }
  3816.  
  3817. mclp.showNewItems_ = function () {
  3818.  
  3819. const cnt = this;
  3820. cnt.__intermediate_delay__ = new Promise(resolve => {
  3821. cnt.showNewItems77_().then(() => {
  3822. resolve();
  3823. });
  3824. });
  3825. }
  3826.  
  3827. console.log("showNewItems_", "OK");
  3828. } else {
  3829. console.log("showNewItems_", "NG");
  3830. }
  3831.  
  3832.  
  3833. if ((mclp.flushActiveItems_ || 0).length === 0) {
  3834.  
  3835. const sfi = fnIntegrity(mclp.flushActiveItems_);
  3836. if (sfi === '0.137.81' || sfi === '0.138.81') {
  3837. } else {
  3838. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.137.81'));
  3839. }
  3840.  
  3841. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  3842.  
  3843. let contensWillChangeController = null;
  3844.  
  3845. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  3846.  
  3847. mclp.flushActiveItems78_ = async function (tid) {
  3848. try {
  3849. if (tid !== mlf) return;
  3850. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3851. let logger = false;
  3852. const cnt = this;
  3853. let immd = cnt.__intermediate_delay__;
  3854. await new Promise(requestAnimationFrame);
  3855.  
  3856. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3857. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  3858.  
  3859. mlf++;
  3860. if (mlg > 1e9) mlg = 9;
  3861. ++mlg;
  3862.  
  3863. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  3864. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  3865. let changeMaxItemsToDisplay = false;
  3866. const activeItemsLen = this.activeItems_.length;
  3867. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  3868. logger = true;
  3869.  
  3870. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  3871.  
  3872. logger && console.log('[Begin]')
  3873.  
  3874. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  3875. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  3876. console.log('reduce maxitems');
  3877. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3878. // as all the rendered chats are already "outdated"
  3879. // all old chats shall remove and reduced number of few chats will be rendered
  3880. // then restore to the original number
  3881. changeMaxItemsToDisplay = true;
  3882. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  3883. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  3884. }
  3885. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  3886. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3887.  
  3888. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3889. } else {
  3890. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  3891.  
  3892. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3893. }
  3894. }
  3895. // it is found that it will render all stacked chats after switching back from background
  3896. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  3897. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  3898.  
  3899.  
  3900. const items = (cnt.$ || 0).items;
  3901.  
  3902. if (USE_WILL_CHANGE_CONTROLLER) {
  3903. if (contensWillChangeController && contensWillChangeController.element !== items) {
  3904. contensWillChangeController.release();
  3905. contensWillChangeController = null;
  3906. }
  3907. if (!contensWillChangeController) contensWillChangeController = new WillChangeController(items, 'contents');
  3908. }
  3909. const wcController = contensWillChangeController;
  3910. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  3911. wcController && wcController.beforeOper();
  3912. await Promise.resolve();
  3913. const acItems = cnt.activeItems_;
  3914. const len1 = acItems.length;
  3915. if (!len1) console.warn('cnt.activeItems_.length = 0');
  3916. let waitFor = [];
  3917.  
  3918.  
  3919. /** @type {Set<string>} */
  3920. const imageLinks = new Set();
  3921.  
  3922. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  3923. for (const item of acItems) {
  3924. fixLiveChatItem(item, imageLinks);
  3925. }
  3926. }
  3927. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  3928. if (emojiPrefetched.size > PREFETCH_LIMITED_SIZE_EMOJI) emojiPrefetched.clear();
  3929. if (authorPhotoPrefetched.size > PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO) authorPhotoPrefetched.clear();
  3930.  
  3931. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  3932. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  3933. // preload performs the high priority fetching.
  3934. // prefetch delays the chat display if the video resoruce is demanding.
  3935.  
  3936. if (rel) {
  3937.  
  3938. imageLinks.forEach(imageLink => {
  3939. let d = false;
  3940. const isEmoji = imageLink.includes('/emoji/');
  3941. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  3942. if (!pretechedSet.has(imageLink)) {
  3943. pretechedSet.add(imageLink);
  3944. d = true;
  3945. }
  3946. if (d) {
  3947. waitFor.push(linker(null, rel, imageLink, 'image'));
  3948.  
  3949. }
  3950. })
  3951.  
  3952. }
  3953.  
  3954. }
  3955.  
  3956. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  3957. skipDontRender = noVisibleItem1;
  3958. // console.log('ss1', Date.now())
  3959. if (waitFor.length > 0) {
  3960. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  3961. }
  3962. waitFor.length = 0;
  3963. waitFor = null;
  3964. // console.log('ss2', Date.now())
  3965. cnt.flushActiveItems66_();
  3966. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  3967. skipDontRender = noVisibleItem2;
  3968. const len2 = cnt.activeItems_.length;
  3969. const bAsync = len1 !== len2;
  3970. await Promise.resolve();
  3971. if (wcController) {
  3972. if (bAsync) {
  3973. cnt.async(() => {
  3974. wcController.afterOper();
  3975. });
  3976. } else {
  3977. wcController.afterOper();
  3978. }
  3979. }
  3980. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3981. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  3982.  
  3983. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  3984. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3985. } else if (changeMaxItemsToDisplay) {
  3986.  
  3987. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  3988. maxItemsToDisplay: this.data.maxItemsToDisplay,
  3989. reducedMaxItemsToDisplay,
  3990. originalMaxItemsToDisplay: tmpMaxItemsCount
  3991. });
  3992. }
  3993. logger && console.log('[End]');
  3994.  
  3995. logger && console.groupEnd();
  3996.  
  3997. if (noVisibleItem1 && !noVisibleItem2) {
  3998. // fix possible no auto scroll issue.
  3999. setTimeout(() => cnt.setAtBottom(), 1);
  4000. }
  4001.  
  4002. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  4003.  
  4004.  
  4005. const ff = () => {
  4006.  
  4007. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4008. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4009. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  4010. cnt.scrollToBottom_();
  4011.  
  4012. Promise.resolve().then(() => {
  4013.  
  4014. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4015. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  4016. });
  4017.  
  4018.  
  4019. }
  4020. }
  4021.  
  4022. ff();
  4023.  
  4024.  
  4025. Promise.resolve().then(ff);
  4026.  
  4027. // requestAnimationFrame(ff);
  4028. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  4029.  
  4030. const knt = cnt;
  4031. if (!scrollChatFn) {
  4032. const cnt = knt;
  4033. const f = () => {
  4034. const itemScroller = cnt.itemScroller;
  4035. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  4036. if (!cnt.atBottom) {
  4037. cnt.scrollToBottom_();
  4038. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  4039. itemScroller.scrollTop = itemScroller.scrollHeight;
  4040. }
  4041. };
  4042. scrollChatFn = () => Promise.resolve().then(f).then(f);
  4043. }
  4044.  
  4045. if (!ENABLE_DELAYED_CHAT_OCCURRENCE) scrollChatFn();
  4046. }
  4047.  
  4048. return 1;
  4049.  
  4050.  
  4051. } catch (e) {
  4052. console.warn(e);
  4053. }
  4054. }
  4055.  
  4056. mclp.flushActiveItems77_ = function () {
  4057.  
  4058. return new Promise(resResolve => {
  4059. try {
  4060. const cnt = this;
  4061. if (mlf > 1e9) mlf = 9;
  4062. let tid = ++mlf;
  4063. const hostElement = cnt.hostElement || cnt;
  4064. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  4065. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  4066.  
  4067. // 4 times to maxItems to avoid frequent trimming.
  4068. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  4069.  
  4070. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  4071. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  4072. if (cnt.canScrollToBottom_()) {
  4073. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  4074. .then(() => cnt.flushActiveItems78_(tid)) // async function
  4075. .then((asyncResult) => {
  4076. resResolve(asyncResult); // either undefined or 1
  4077. resResolve = null;
  4078. }).catch((e) => {
  4079. console.warn(e);
  4080. if (resResolve) resResolve();
  4081. });
  4082. } else {
  4083. resResolve(2);
  4084. resResolve = null;
  4085. }
  4086. } catch (e) {
  4087. console.warn(e);
  4088. if (resResolve) resResolve();
  4089. }
  4090.  
  4091.  
  4092. });
  4093.  
  4094. }
  4095.  
  4096. mclp.flushActiveItems_ = function () {
  4097. const cnt = this;
  4098.  
  4099. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  4100.  
  4101. if (cnt.activeItems_.length === 0) {
  4102. cnt.__intermediate_delay__ = null;
  4103. return;
  4104. }
  4105.  
  4106. const cntData = ((cnt || 0).data || 0);
  4107. if (cntData.maxItemsToDisplay944 === undefined) {
  4108. cntData.maxItemsToDisplay944 = null;
  4109. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  4110. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  4111. }
  4112.  
  4113. // ignore previous __intermediate_delay__ and create a new one
  4114. cnt.__intermediate_delay__ = new Promise(resolve => {
  4115. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  4116. if (rt === 1) {
  4117. resolve(1); // success, scroll to bottom
  4118. if (hasMoreMessageState === 1) {
  4119. hasMoreMessageState = 0;
  4120. const showMore = (cnt.$ || 0)['show-more'];
  4121. if (showMore) {
  4122. showMore.classList.remove('has-new-messages-miuzp');
  4123. }
  4124. }
  4125. }
  4126. else if (rt === 2) {
  4127. resolve(2); // success, trim
  4128. if (hasMoreMessageState === 0) {
  4129. hasMoreMessageState = 1;
  4130. const showMore = cnt.$['show-more'];
  4131. if (showMore) {
  4132. showMore.classList.add('has-new-messages-miuzp');
  4133. }
  4134. }
  4135. }
  4136. else resolve(-1); // skip
  4137. }).catch(e => {
  4138. console.warn(e);
  4139. });
  4140. });
  4141.  
  4142. }
  4143. console.log("flushActiveItems_", "OK");
  4144. } else {
  4145. console.log("flushActiveItems_", "NG");
  4146. }
  4147.  
  4148. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  4149. try {
  4150. if (mlg > 1e9) mlg = 9;
  4151. const tid = ++mlg;
  4152. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  4153. const runCond = () => this.canScrollToBottom_();
  4154. if (!keepTrialCond()) return;
  4155. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  4156. await new Promise(r => setTimeout(r, 80));
  4157. if (!keepTrialCond()) return;
  4158. if (runCond()) return this.flushActiveItems_() | 1;
  4159. await new Promise(requestAnimationFrame);
  4160. if (runCond()) return this.flushActiveItems_() | 1;
  4161. } catch (e) {
  4162. console.warn(e);
  4163. }
  4164. }
  4165.  
  4166. if ((mclp.atBottomChanged_ || 0).length === 1) {
  4167. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  4168. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.75.39'));
  4169.  
  4170. const querySelector = HTMLElement.prototype.querySelector;
  4171. const U = (element) => ({
  4172. querySelector: (selector) => querySelector.call(element, selector)
  4173. });
  4174.  
  4175. let qid = 0;
  4176. mclp.atBottomChanged_ = function (a) {
  4177. let tid = ++qid;
  4178. let b = this;
  4179. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  4180. if (tid !== qid) return;
  4181. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  4182. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  4183. this.hideShowMoreAsync_ = null,
  4184. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  4185. }
  4186.  
  4187. console.log("atBottomChanged_", "OK");
  4188. } else {
  4189. console.log("atBottomChanged_", "NG");
  4190. }
  4191.  
  4192. if ((mclp.onScrollItems_ || 0).length === 1) {
  4193.  
  4194. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  4195. mclp.onScrollItems66_ = mclp.onScrollItems_;
  4196. mclp.onScrollItems77_ = async function (evt) {
  4197. if (myw > 1e9) myw = 9;
  4198. let tid = ++myw;
  4199.  
  4200. await new Promise(requestAnimationFrame);
  4201.  
  4202. if (tid !== myw) {
  4203. return;
  4204. }
  4205.  
  4206. const cnt = this;
  4207.  
  4208. await Promise.resolve();
  4209. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  4210. await Promise.resolve().then(() => {
  4211. this.ytRendererBehavior.onScroll(evt);
  4212. }).then(() => {
  4213. if (this.canScrollToBottom_()) {
  4214. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  4215. if (hasUserJustInteracted) {
  4216. // only when there is an user action
  4217. this.setAtBottom();
  4218. return 1;
  4219. }
  4220. } else {
  4221. // no message inserting
  4222. this.setAtBottom();
  4223. return 1;
  4224. }
  4225. }).then((r) => {
  4226.  
  4227. if (this.activeItems_.length) {
  4228.  
  4229. if (this.canScrollToBottom_()) {
  4230. this.flushActiveItems_();
  4231. return 1 && r;
  4232. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  4233. // delayed due to user action
  4234. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  4235. return 0;
  4236. }
  4237. }
  4238. }).then((r) => {
  4239. if (r) {
  4240. // ensure setAtBottom is correctly set
  4241. this.setAtBottom();
  4242. }
  4243. });
  4244. } else {
  4245. cnt.onScrollItems66_(evt);
  4246. }
  4247.  
  4248. await Promise.resolve();
  4249.  
  4250. }
  4251.  
  4252. mclp.onScrollItems_ = function (evt) {
  4253.  
  4254. const cnt = this;
  4255. cnt.__intermediate_delay__ = new Promise(resolve => {
  4256. cnt.onScrollItems77_(evt).then(() => {
  4257. resolve();
  4258. });
  4259. });
  4260. }
  4261. console.log("onScrollItems_", "OK");
  4262. } else {
  4263. console.log("onScrollItems_", "NG");
  4264. }
  4265.  
  4266. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  4267.  
  4268. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  4269. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  4270.  
  4271. mclp.handleLiveChatActions77_ = async function (arr) {
  4272. if (typeof (arr || 0).length !== 'number') {
  4273. this.handleLiveChatActions66_(arr);
  4274. return;
  4275. }
  4276. if (mzt > 1e9) mzt = 9;
  4277. let tid = ++mzt;
  4278.  
  4279. if (zarr === null) zarr = arr;
  4280. else Array.prototype.push.apply(zarr, arr);
  4281. arr = null;
  4282.  
  4283. await new Promise(requestAnimationFrame);
  4284.  
  4285. if (tid !== mzt || zarr === null) {
  4286. return;
  4287. }
  4288.  
  4289. const carr = zarr;
  4290. zarr = null;
  4291.  
  4292. await Promise.resolve();
  4293. this.handleLiveChatActions66_(carr);
  4294. await Promise.resolve();
  4295.  
  4296. }
  4297.  
  4298. mclp.handleLiveChatActions_ = function (arr) {
  4299.  
  4300. const cnt = this;
  4301. cnt.__intermediate_delay__ = new Promise(resolve => {
  4302. cnt.handleLiveChatActions77_(arr).then(() => {
  4303. resolve();
  4304. });
  4305. });
  4306. }
  4307. console.log("handleLiveChatActions_", "OK");
  4308. } else {
  4309. console.log("handleLiveChatActions_", "NG");
  4310. }
  4311.  
  4312. mclp.hasUserJustInteracted11_ = () => {
  4313. const t = dateNow();
  4314. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  4315. }
  4316.  
  4317. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  4318.  
  4319. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  4320.  
  4321. mclp.canScrollToBottom_ = function () {
  4322. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  4323. }
  4324.  
  4325. console.log("canScrollToBottom_", "OK");
  4326. } else {
  4327. console.log("canScrollToBottom_", "NG");
  4328. }
  4329.  
  4330. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  4331.  
  4332. mclp.isSmoothScrollEnabled_ = function () {
  4333. return false;
  4334. }
  4335.  
  4336. mclp.maybeResizeScrollContainer_ = function () {
  4337. //
  4338. }
  4339.  
  4340. mclp.refreshOffsetContainerHeight_ = function () {
  4341. //
  4342. }
  4343.  
  4344. mclp.smoothScroll_ = function () {
  4345. //
  4346. }
  4347.  
  4348. mclp.resetSmoothScroll_ = function () {
  4349. //
  4350. }
  4351. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  4352. } else {
  4353. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  4354. }
  4355.  
  4356. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  4357.  
  4358. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  4359. mclp.handleAddChatItemAction_ = function (a) {
  4360. try {
  4361. if (a && typeof a === 'object' && !('length' in a)) {
  4362. fixLiveChatItem(a.item, null);
  4363. console.assert(arguments[0] === a);
  4364. }
  4365. } catch (e) { console.warn(e) }
  4366. return this.handleAddChatItemAction66_.apply(this, arguments);
  4367. }
  4368.  
  4369. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  4370. } else {
  4371.  
  4372. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  4373. }
  4374.  
  4375.  
  4376. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  4377.  
  4378. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  4379. mclp.handleReplaceChatItemAction_ = function (a) {
  4380. try {
  4381. if (a && typeof a === 'object' && !('length' in a)) {
  4382. fixLiveChatItem(a.replacementItem, null);
  4383. console.assert(arguments[0] === a);
  4384. }
  4385. } catch (e) { console.warn(e) }
  4386. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  4387. }
  4388.  
  4389. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  4390. } else {
  4391.  
  4392. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  4393. }
  4394.  
  4395. console.log("[End]");
  4396. console.groupEnd();
  4397.  
  4398. }).catch(console.warn);
  4399.  
  4400.  
  4401. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  4402.  
  4403. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  4404.  
  4405. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  4406.  
  4407. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  4408. let v = `${attrValue}`;
  4409. // conside a ticker is 101px width
  4410. // 1% = 1.01px
  4411. // 0.2% = 0.202px
  4412.  
  4413.  
  4414. const ratio1 = (yd.ratio * 100);
  4415. if (ratio1 > -1) { // avoid NaN
  4416.  
  4417. // countdownDurationMs
  4418. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  4419. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  4420. // 150000 - 1% <1% = 1.5s>
  4421. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  4422. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  4423.  
  4424. // 99px * 5% = 4.95px
  4425.  
  4426. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  4427.  
  4428.  
  4429. // 1% Duration
  4430.  
  4431. let ratio2 = ratio1;
  4432.  
  4433. const ydd = yd.data;
  4434. if (ydd) {
  4435.  
  4436. const d1 = ydd.durationSec;
  4437. const d2 = ydd.fullDurationSec;
  4438.  
  4439. // @ step timing [min. 0.2%]
  4440. let numOfSteps = 500;
  4441. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  4442. if (d2 > 400) numOfSteps = 500; // 0.2%
  4443. else if (d2 > 200) numOfSteps = 200; // 0.5%
  4444. else if (d2 > 100) numOfSteps = 100; // 1%
  4445. else if (d2 > 50) numOfSteps = 50; // 2%
  4446. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  4447. else numOfSteps = 20;
  4448. }
  4449. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4450. if (numOfSteps < 5) numOfSteps = 5;
  4451.  
  4452. const rd = numOfSteps / 100.0;
  4453.  
  4454. ratio2 = Math.round(ratio2 * rd) / rd;
  4455.  
  4456. // ratio2 = Math.round(ratio2 * 5) / 5;
  4457. ratio2 = ratio2.toFixed(1);
  4458. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  4459.  
  4460. if (yd.__style_last__ === v) return;
  4461. yd.__style_last__ = v;
  4462. // do not consider any delay here.
  4463. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  4464.  
  4465. }
  4466. }
  4467.  
  4468. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  4469.  
  4470.  
  4471. } else {
  4472. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  4473. }
  4474.  
  4475. };
  4476.  
  4477.  
  4478. const fpTicker = (renderer) => {
  4479. const cnt = insp(renderer);
  4480. assertor(() => typeof (cnt || 0).is === 'string');
  4481. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  4482. const container = (cnt.$ || 0).container;
  4483. if (container) {
  4484. assertor(() => (container || 0).nodeType === 1);
  4485. assertor(() => typeof container.setAttribute === 'function');
  4486. container.setAttribute = tickerContainerSetAttribute;
  4487. } else {
  4488. console.warn(`"container" does not exist in ${cnt.is}`);
  4489. }
  4490. };
  4491.  
  4492.  
  4493. const tags = [
  4494. "yt-live-chat-ticker-paid-message-item-renderer",
  4495. "yt-live-chat-ticker-paid-sticker-item-renderer",
  4496. "yt-live-chat-ticker-renderer",
  4497. "yt-live-chat-ticker-sponsor-item-renderer"
  4498. ];
  4499.  
  4500.  
  4501. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  4502.  
  4503. mightFirstCheckOnYtInit();
  4504. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  4505. console.log("[Begin]");
  4506.  
  4507. let dummyValueForStyleReturn = null;
  4508.  
  4509. const genDummyValueForStyleReturn = () => {
  4510. let s = `--nx:82;`
  4511. let ro = {
  4512. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4513. "implementsGoogStringTypedString": true
  4514. };
  4515. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4516. return ro;
  4517. }
  4518.  
  4519. const isCSSPropertySupported = () => {
  4520.  
  4521. // @property --ticker-rtime
  4522.  
  4523. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return;
  4524. const documentElement = document.documentElement;
  4525. if (!documentElement) {
  4526. console.warn('document.documentElement is not found');
  4527. return false;
  4528. }
  4529. if (`${getComputedStyle(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  4530. return false;
  4531. }
  4532. return true;
  4533.  
  4534. };
  4535.  
  4536.  
  4537. let windowShownAt = -1;
  4538. const setupEventForWindowShownAt = () => {
  4539. window.addEventListener('visibilitychange', () => {
  4540. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  4541. else windowShownAt = 0;
  4542. }, false);
  4543. }
  4544.  
  4545. const dProto = {
  4546.  
  4547. attachedForTickerInit: function () {
  4548.  
  4549. fpTicker(this.hostElement || this);
  4550. return this.attached77();
  4551.  
  4552. },
  4553.  
  4554.  
  4555. // doAnimator
  4556.  
  4557. _makeAnimator: function () {
  4558. if (this._r782) return;
  4559. // if (!this.isAttached) return;
  4560. if (!this._runnerAE) {
  4561. /** @type {HTMLElement | null} */
  4562. const aElement = (this.$ || 0).container;
  4563. if (!aElement) return console.warn("this.$.container is undefined");
  4564. const da = this.data;
  4565. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  4566. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  4567. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  4568. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  4569.  
  4570. // if (!this.__tickerBackgroundInitialChecked__) {
  4571. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  4572. // console.log('__tickerBackgroundInitialChecked__')
  4573. // this._checkTickerBackgroundChanged();
  4574. // }
  4575.  
  4576. aElement.style.setProperty('--ticker-c1', c1);
  4577. aElement.style.setProperty('--ticker-c2', c2);
  4578. aElement.classList.add(runTickerClassName);
  4579. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  4580. // this._aeStartV = this.countdownMs;
  4581. // this._aeStartT = this.countdownDurationMs;
  4582. if (!(p >= 0 && p <= 100)) {
  4583. console.warn('incorrect time ratio', p);
  4584. } else {
  4585. /*
  4586. const u0 = p.toFixed(4) + '%';
  4587. this._runnerAE = animate.call(aElement,
  4588. [
  4589. { '--ticker-rtime': u0 },
  4590. { '--ticker-rtime': '0%' }
  4591. ]
  4592. ,
  4593. {
  4594. fill: "forwards",
  4595. duration: this.countdownMs,
  4596. easing: "linear"
  4597. }
  4598. );
  4599. */
  4600.  
  4601. let timingFn = 'linear';
  4602.  
  4603. const totalDuration = this.countdownDurationMs;
  4604.  
  4605. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  4606.  
  4607. // @ step timing [min. 0.2%]
  4608. let stepInterval = 0.2; // unit: %
  4609. if (totalDuration > 400000) stepInterval = 0.2;
  4610. else if (totalDuration > 200000) stepInterval = 0.5;
  4611. else if (totalDuration > 100000) stepInterval = 1;
  4612. else if (totalDuration > 50000) stepInterval = 2;
  4613. else if (totalDuration > 25000) stepInterval = 5;
  4614. else stepInterval = 5;
  4615.  
  4616. let numOfSteps = Math.round(100 / stepInterval);
  4617.  
  4618. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4619. if (numOfSteps < 5) numOfSteps = 5;
  4620.  
  4621. timingFn = `steps(${numOfSteps}, end)`;
  4622.  
  4623. }
  4624.  
  4625.  
  4626. /** @type {Animation} */
  4627. const ae = animate.call(aElement,
  4628. [
  4629. { '--ticker-rtime': '100%' },
  4630. { '--ticker-rtime': '0%' }
  4631. ]
  4632. ,
  4633. {
  4634. fill: "forwards",
  4635. duration: totalDuration,
  4636. easing: timingFn
  4637. }
  4638. );
  4639.  
  4640. this._runnerAE = ae;
  4641.  
  4642. ae.onfinish = (event) => {
  4643. this.onfinish = null;
  4644. if (this._runnerAE !== ae) return;
  4645. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  4646. this._aeFinished(event);
  4647. }
  4648. }
  4649.  
  4650. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  4651.  
  4652. if (bq >= 0 && bq <= totalDuration) {
  4653.  
  4654. if (bq > totalDuration - 1) {
  4655. ae.currentTime = bq;
  4656. // setTimeout(() => {
  4657. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  4658. // }, 1);
  4659. } else {
  4660. ae.currentTime = bq;
  4661. }
  4662. } else {
  4663. console.warn('Error on setting _runnerAE.currentTime!');
  4664. }
  4665.  
  4666.  
  4667. aeConstructor = ae.constructor; // constructor is from iframe
  4668. return ae;
  4669. }
  4670. } else {
  4671. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  4672. // assume just time update
  4673. const ae = this._runnerAE;
  4674. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  4675. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  4676. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  4677. if (!(p >= 0 && p <= 100)) {
  4678. console.warn('incorrect time ratio', p);
  4679. } else {
  4680. // let u0 = p.toFixed(4) + '%'
  4681. /*
  4682. ae.effect.setKeyframes([
  4683. { '--ticker-rtime': u0 },
  4684. { '--ticker-rtime': '0%' }
  4685. ]);
  4686. ae.effect.updateTiming({ duration: this.countdownMs });
  4687. */
  4688. // ae.currentTime = 0;
  4689.  
  4690.  
  4691.  
  4692. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  4693. if (bq >= 0 && bq <= this.countdownDurationMs) {
  4694.  
  4695. this._runnerAE.currentTime = bq
  4696. } else {
  4697. console.warn('Error on setting _runnerAE.currentTime!');
  4698. }
  4699.  
  4700.  
  4701. ae.play();
  4702. return ae;
  4703. }
  4704. }
  4705. },
  4706.  
  4707. _aeFinished: function (event) {
  4708.  
  4709. if (this._r782) return;
  4710.  
  4711. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4712. this._throwOut();
  4713. return;
  4714. }
  4715.  
  4716. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4717.  
  4718. let lc = window.performance.now();
  4719. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4720. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4721. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  4722. if (this.countdownMs > 76) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs, this, event); // just warning.
  4723.  
  4724. this.countdownMs = 0;
  4725. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null;
  4726.  
  4727. if (this.isAttached) {
  4728. let fastRemoved = false;
  4729. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  4730. // no animation if the video page is switched from background to foreground
  4731. // this.hostElement.style.display = 'none';
  4732. const id = (this.data || 0).id || 0;
  4733. if (!id) this.data = { id: 1 }
  4734. try {
  4735. this.requestRemoval();
  4736. fastRemoved = true;
  4737. } catch (e) {
  4738.  
  4739. }
  4740. }
  4741.  
  4742. if (!fastRemoved) {
  4743. "auto" === this.hostElement.style.width && this.setContainerWidth();
  4744. this.slideDown();
  4745. }
  4746. }
  4747.  
  4748.  
  4749.  
  4750. },
  4751.  
  4752.  
  4753. /** @type {()} */
  4754. _throwOut: function () {
  4755. this._r782 = 1;
  4756. Promise.resolve().then(() => {
  4757. if (typeof this.requestRemoval === 'function') {
  4758. const id = (this.data || 0).id;
  4759. if (!id) this.data = { id: 1 };
  4760. try {
  4761. this.requestRemoval();
  4762. } catch (e) { }
  4763. }
  4764. this.detached();
  4765. this.data = null;
  4766. this.countdownMs = 0;
  4767. this.lastCountdownTimeMs = null;
  4768. if (this.__dataClientsReady === true) this.__dataClientsReady = false;
  4769. if (this.__dataEnabled === true) this.__dataEnabled = false;
  4770. if (this.__dataReady === true) this.__dataReady = false;
  4771. const hm = this.hostElement || this;
  4772. if (hm.parentNode) hm.remove();
  4773. if (hm.firstChild) hm.textContent = '';
  4774. }).catch(e => {
  4775. console.warn(e);
  4776. });
  4777. },
  4778.  
  4779.  
  4780. // doTimerFnModification
  4781.  
  4782.  
  4783. /** @type {(a, b)} */
  4784. startCountdownForTimerFnModA: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4785. try {
  4786. // a.durationSec [s] => countdownMs [ms]
  4787. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4788. // lastCountdownTimeMs => raf ongoing
  4789. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4790.  
  4791. if (this._r782) return;
  4792.  
  4793. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4794. this._throwOut();
  4795. return;
  4796. }
  4797.  
  4798. // TimerFnModA
  4799.  
  4800. b = void 0 === b ? 0 : b;
  4801. if (void 0 !== a) {
  4802.  
  4803. this.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  4804. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs; // constant throughout the animation
  4805. if (!(this.lastCountdownTimeMs || this.isAnimationPaused)) {
  4806. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = performance.now()
  4807. this.rafId = 1
  4808. if (this._runnerAE) console.warn('Error in .startCountdown; this._runnerAE already created.')
  4809. this.detlaSincePausedSecs = 0;
  4810. const ae = this._makeAnimator();
  4811. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4812.  
  4813. // if (playerProgressChangedArg1 === null) {
  4814. // console.log('startCountdownForTimerFnModA', this.data)
  4815. // }
  4816.  
  4817. if (isPlayProgressTriggered && this.isAnimationPaused !== true && this.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__) {
  4818.  
  4819.  
  4820.  
  4821.  
  4822. this.playerProgressSec = lastPlayerProgress > 0 ? lastPlayerProgress : 0; // save the progress first
  4823. this.isAnimationPaused = true; // trigger isAnimationPausedChanged
  4824. this.detlaSincePausedSecs = 0;
  4825. this._forceNoDetlaSincePausedSecs783 = 1; // reset this.detlaSincePausedSecs = 0 when resumed
  4826.  
  4827. relayPromise = relayPromise || new PromiseExternal();
  4828.  
  4829. relayPromise.then(() => {
  4830. if (this.isAttached === true && this.countdownDurationMs > 0 && this.isAnimationPaused === true && this.isReplayPaused !== true) {
  4831. this.isAnimationPaused = false;
  4832. }
  4833. });
  4834.  
  4835.  
  4836. }
  4837.  
  4838.  
  4839.  
  4840. }
  4841. }
  4842.  
  4843. } catch (e) {
  4844. console.warn(e);
  4845. }
  4846.  
  4847. },
  4848.  
  4849.  
  4850.  
  4851. /** @type {(a, b)} */
  4852. startCountdownForTimerFnModT: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4853. try {
  4854. // a.durationSec [s] => countdownMs [ms]
  4855. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4856. // lastCountdownTimeMs => raf ongoing
  4857. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4858.  
  4859. if (this._r782) return;
  4860.  
  4861. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4862. this._throwOut();
  4863. return;
  4864. }
  4865.  
  4866. // TimerFnModT
  4867.  
  4868. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4869. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4870. b = void 0 === b ? 0 : b;
  4871. void 0 !== a && (this.countdownMs = 1E3 * a,
  4872. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs,
  4873. this.ratio = 1,
  4874. this.lastCountdownTimeMs || this.isAnimationPaused || (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = performance.now(),
  4875. this.rafId = rafHub.request(this.boundUpdateTimeout37_)))
  4876.  
  4877. } catch (e) {
  4878. console.warn(e);
  4879. }
  4880.  
  4881. },
  4882.  
  4883.  
  4884. /** @type {(a,)} */
  4885. updateTimeoutForTimerFnModA: function (a) {
  4886.  
  4887. try {
  4888.  
  4889. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  4890.  
  4891. if (this._r782) return;
  4892.  
  4893. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4894. this._throwOut();
  4895. return;
  4896. }
  4897.  
  4898. // TimerFnModA
  4899.  
  4900. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4901. if (this.lastCountdownTimeMs !== this._lastCountdownTimeMsX0) {
  4902. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4903. }
  4904. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4905. if (this.isAttached && this.countdownMs) {
  4906. this.lastCountdownTimeMs = a
  4907. const ae = this._makeAnimator(); // request raf
  4908. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4909. } else {
  4910. (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null,
  4911. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4912. this.slideDown()));
  4913. }
  4914.  
  4915. } catch (e) {
  4916. console.warn(e);
  4917. }
  4918.  
  4919.  
  4920. },
  4921.  
  4922. /** @type {(a,)} */
  4923. updateTimeoutForTimerFnModT: function (a) {
  4924.  
  4925. try {
  4926.  
  4927. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  4928.  
  4929. if (this._r782) return;
  4930.  
  4931. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4932. this._throwOut();
  4933. return;
  4934. }
  4935.  
  4936. // TimerFnModT
  4937.  
  4938. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4939. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4940. if (this.lastCountdownTimeMs !== this._lastCountdownTimeMsX0) {
  4941. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4942. }
  4943. // console.log(703, this.countdownMs)
  4944. this.ratio = this.countdownMs / this.countdownDurationMs;
  4945. this.isAttached && this.countdownMs ? (this.lastCountdownTimeMs = a,
  4946. this.rafId = rafHub.request(this.boundUpdateTimeout37_)) : (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null,
  4947. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4948. this.slideDown()))
  4949.  
  4950.  
  4951. } catch (e) {
  4952. console.warn(e);
  4953. }
  4954. },
  4955.  
  4956. /** @type {(a,b)} */
  4957. isAnimationPausedChangedForTimerFnModA: function (a, b) {
  4958.  
  4959. if (this._r782) return;
  4960.  
  4961. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4962. this._throwOut();
  4963. return;
  4964. }
  4965. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  4966. this._forceNoDetlaSincePausedSecs783 = 0;
  4967.  
  4968. Promise.resolve().then(() => {
  4969.  
  4970. if (a) {
  4971.  
  4972. if (this._runnerAE && this._runnerAE.playState === 'running') {
  4973.  
  4974. this._runnerAE.pause()
  4975. let lc = window.performance.now();
  4976. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4977. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4978. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  4979. }
  4980.  
  4981. } else if (!a && b) {
  4982.  
  4983.  
  4984. if (forceNoDetlaSincePausedSecs783) this.detlaSincePausedSecs = 0;
  4985. a = this.detlaSincePausedSecs ? (this.lastCountdownTimeMs || 0) + 1000 * this.detlaSincePausedSecs : (this.lastCountdownTimeMs || 0);
  4986. this.detlaSincePausedSecs = 0;
  4987. this.updateTimeout(a);
  4988. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = window.performance.now();
  4989.  
  4990. }
  4991.  
  4992.  
  4993. }).catch(e => {
  4994. console.log(e);
  4995. });
  4996.  
  4997.  
  4998.  
  4999. },
  5000.  
  5001.  
  5002. /** @type {(a,b)} */
  5003. isAnimationPausedChangedForTimerFnModT: function (a, b) {
  5004.  
  5005. if (this._r782) return;
  5006.  
  5007. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5008. this._throwOut();
  5009. return;
  5010. }
  5011. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  5012. this._forceNoDetlaSincePausedSecs783 = 0;
  5013.  
  5014. Promise.resolve().then(() => {
  5015.  
  5016. // TimerFnModT
  5017.  
  5018. // ez++;
  5019. // if(ez> 1e9) ez=9;
  5020. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  5021. a ? rafHub.cancel(this.rafId) : !a && b && (a = this.lastCountdownTimeMs || 0,
  5022. this.detlaSincePausedSecs && (a = (this.lastCountdownTimeMs || 0) + 1E3 * this.detlaSincePausedSecs,
  5023. this.detlaSincePausedSecs = 0),
  5024. this.boundUpdateTimeout37_(a),
  5025. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = window.performance.now())
  5026.  
  5027.  
  5028. }).catch(e => {
  5029. console.log(e);
  5030. });
  5031.  
  5032.  
  5033.  
  5034. },
  5035.  
  5036.  
  5037. /** @type {(a,b)} */
  5038. computeContainerStyleForAnimatorEnabled: function (a, b) {
  5039.  
  5040. if (this._r782) return;
  5041.  
  5042. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5043. this._throwOut();
  5044. return;
  5045. }
  5046.  
  5047. return (dummyValueForStyleReturn || (dummyValueForStyleReturn = genDummyValueForStyleReturn()));
  5048.  
  5049. },
  5050.  
  5051.  
  5052.  
  5053. /** @type {()} */
  5054. handlePauseReplayForPlaybackProgressState: function () {
  5055. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  5056.  
  5057. if (onPlayStateChangePromise) {
  5058.  
  5059. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  5060. const tid = ++this.rtu;
  5061.  
  5062. onPlayStateChangePromise.then(() => {
  5063. if (tid === this.rtu && !onPlayStateChangePromise) this.handlePauseReplay.apply(this, arguments);
  5064. });
  5065.  
  5066. return;
  5067. }
  5068.  
  5069. if (playerState !== 2) return;
  5070. if (this.isAttached) {
  5071. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  5072. const tid = ++this.rtk;
  5073. const tc = relayCount;
  5074. foregroundPromiseFn().then(() => {
  5075. if (tid === this.rtk && tc === relayCount && playerState === 2 && _playerState === playerState) {
  5076. this.handlePauseReplay66();
  5077. }
  5078.  
  5079. })
  5080. }
  5081. },
  5082.  
  5083. /** @type {()} */
  5084. handleResumeReplayForPlaybackProgressState: function () {
  5085. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  5086.  
  5087.  
  5088. if (onPlayStateChangePromise) {
  5089.  
  5090. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  5091. const tid = ++this.rtv;
  5092.  
  5093. onPlayStateChangePromise.then(() => {
  5094. if (tid === this.rtv && !onPlayStateChangePromise) this.handleResumeReplay.apply(this, arguments);
  5095. });
  5096.  
  5097. return;
  5098. }
  5099.  
  5100.  
  5101. if (playerState !== 1) return;
  5102. if (this.isAttached) {
  5103. const tc = relayCount;
  5104.  
  5105. relayPromise = relayPromise || new PromiseExternal();
  5106. relayPromise.then(() => {
  5107. if (relayCount > tc && playerState === 1 && _playerState === playerState) {
  5108. this.handleResumeReplay66();
  5109. }
  5110. });
  5111. }
  5112. },
  5113.  
  5114. /** @type {(a,)} */
  5115. handleReplayProgressForPlaybackProgressState: function (a) {
  5116. if (this.isAttached) {
  5117. const tid = ++this.rtk;
  5118. foregroundPromiseFn().then(() => {
  5119. if (tid === this.rtk) {
  5120. this.handleReplayProgress66(a);
  5121. }
  5122. })
  5123. }
  5124. }
  5125.  
  5126.  
  5127. }
  5128.  
  5129.  
  5130. for (const tag of tags) { // ##tag##
  5131. const dummy = document.createElement(tag);
  5132.  
  5133. const cProto = getProto(dummy);
  5134. if (!cProto || !cProto.attached) {
  5135. console.warn(`proto.attached for ${tag} is unavailable.`);
  5136. continue;
  5137. }
  5138.  
  5139. cProto.attached77 = cProto.attached;
  5140.  
  5141. cProto.attached = dProto.attachedForTickerInit;
  5142.  
  5143. let rafHackState = 0;
  5144.  
  5145. let isTimingFunctionHackable = false;
  5146.  
  5147. let urt = 0;
  5148.  
  5149. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  5150.  
  5151. // console.log('startCountdown', typeof cProto.startCountdown)
  5152. // console.log('updateTimeout', typeof cProto.updateTimeout)
  5153. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  5154.  
  5155. isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  5156.  
  5157. } else {
  5158. console.log(`Skip Timing Function Modification for ${tag}`);
  5159. continue;
  5160. }
  5161.  
  5162.  
  5163. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  5164.  
  5165. // cancelable - this.rafId < isAnimationPausedChanged >
  5166. rafHackState = 1;
  5167.  
  5168. if (isTimingFunctionHackable) {
  5169. rafHackState = 2;
  5170.  
  5171. } else {
  5172. rafHackState = 4;
  5173. }
  5174.  
  5175. }
  5176.  
  5177. const doAnimator = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  5178.  
  5179. const doRAFHack = rafHackState === 2;
  5180.  
  5181. cProto._throwOut = dProto._throwOut;
  5182.  
  5183. cProto._makeAnimator = doAnimator ? dProto._makeAnimator : null;
  5184.  
  5185. cProto._aeFinished = doAnimator ? dProto._aeFinished : null;
  5186.  
  5187.  
  5188. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  5189.  
  5190.  
  5191.  
  5192. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  5193. urt++;
  5194. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  5195. } else {
  5196. console.log('Error for setting cProto.handlePauseReplay', tag)
  5197. }
  5198.  
  5199. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handlePauseReplay.length === 0) {
  5200. urt++;
  5201. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  5202. } else {
  5203. console.log('Error for setting cProto.handleResumeReplay', tag)
  5204. }
  5205.  
  5206. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  5207. urt++;
  5208. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  5209. } else {
  5210. console.log('Error for setting cProto.handleReplayProgress', tag)
  5211. }
  5212.  
  5213.  
  5214.  
  5215. }
  5216.  
  5217. const ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED = ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX && urt === 3;
  5218. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  5219.  
  5220. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  5221.  
  5222. cProto.rtk = 0;
  5223. cProto.rtu = 0;
  5224. cProto.rtv = 0;
  5225.  
  5226. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  5227. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  5228.  
  5229. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  5230. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  5231.  
  5232. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  5233. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  5234.  
  5235. }
  5236.  
  5237. const doTimerFnModification = (doRAFHack || doAnimator);
  5238.  
  5239. if (doAnimator && windowShownAt < 0) {
  5240. windowShownAt = 0;
  5241. setupEventForWindowShownAt();
  5242. }
  5243.  
  5244. if (doTimerFnModification) {
  5245.  
  5246. cProto.startCountdown = (
  5247. doAnimator ? dProto.startCountdownForTimerFnModA : dProto.startCountdownForTimerFnModT
  5248. );
  5249.  
  5250. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  5251. cProto.updateTimeout = (
  5252. doAnimator ? dProto.updateTimeoutForTimerFnModA : dProto.updateTimeoutForTimerFnModT
  5253. );
  5254.  
  5255.  
  5256. // let ez = 0;
  5257. cProto.isAnimationPausedChanged = (
  5258. doAnimator ? dProto.isAnimationPausedChangedForTimerFnModA : dProto.isAnimationPausedChangedForTimerFnModT
  5259. );
  5260.  
  5261. }
  5262.  
  5263. if (doAnimator) {
  5264.  
  5265. const s = fnIntegrity(cProto.computeContainerStyle);
  5266. // 2.44.29 or 2.81.31
  5267. if (s === '2.44.29' || s === '2.81.31') {
  5268.  
  5269. // var ofb = da([""])
  5270. // pfb = da("background:linear-gradient(90deg, {,{ {,{ {,{);".split("{"))
  5271.  
  5272. // f.computeContainerStyle = function(a, b) {
  5273. // if (!a)
  5274. // return pi(ofb);
  5275. // var c = this.colorFromDecimal(a.startBackgroundColor);
  5276. // a = this.colorFromDecimal(a.endBackgroundColor);
  5277. // b = 100 * b + "%";
  5278. // return pi(pfb, c, c, b, a, b, a)
  5279. // }
  5280.  
  5281. } else {
  5282. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.44.29'));
  5283. }
  5284.  
  5285. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  5286.  
  5287. cProto.computeContainerStyle = dProto.computeContainerStyleForAnimatorEnabled;
  5288.  
  5289. }
  5290.  
  5291. if (doTimerFnModification === true) hasTimerModified = true;
  5292.  
  5293. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  5294. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  5295. }
  5296.  
  5297. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  5298. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  5299. }
  5300.  
  5301. }
  5302.  
  5303. const selector = tags.join(', ');
  5304. const elements = document.querySelectorAll(selector);
  5305. if (elements.length >= 1) {
  5306. for (const elm of elements) {
  5307. if (insp(elm).isAttached === true) {
  5308. fpTicker(elm);
  5309. }
  5310. }
  5311. }
  5312.  
  5313. console.log("[End]");
  5314. console.groupEnd();
  5315.  
  5316.  
  5317. }).catch(console.warn);
  5318.  
  5319. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  5320.  
  5321. mightFirstCheckOnYtInit();
  5322. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  5323. console.log("[Begin]");
  5324. (() => {
  5325.  
  5326. /* pending!!
  5327.  
  5328. handleLiveChatAction
  5329.  
  5330. removeTickerItemById
  5331.  
  5332. _itemsChanged
  5333. itemsChanged
  5334.  
  5335. handleMarkChatItemAsDeletedAction
  5336. handleMarkChatItemsByAuthorAsDeletedAction
  5337. handleRemoveChatItemByAuthorAction
  5338.  
  5339.  
  5340. */
  5341.  
  5342. const tag = "yt-live-chat-ticker-renderer"
  5343. const dummy = document.createElement(tag);
  5344.  
  5345. const cProto = getProto(dummy);
  5346. if (!cProto || !cProto.attached) {
  5347. console.warn(`proto.attached for ${tag} is unavailable.`);
  5348. return;
  5349. }
  5350.  
  5351. if (AMEND_TICKER_handleLiveChatAction
  5352. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && fnIntegrity(cProto.handleLiveChatAction) === '1.63.48'
  5353. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && fnIntegrity(cProto.handleLiveChatActions) === '1.23.12'
  5354. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  5355. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  5356. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  5357. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  5358. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  5359. ) {
  5360.  
  5361. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  5362.  
  5363. cProto.handleLiveChatActions = function (a) {
  5364. /**
  5365. *
  5366. f.handleLiveChatActions = function(a) {
  5367. a.length && (a.forEach(this.handleLiveChatAction, this),
  5368. this.updateHighlightedItem(),
  5369. this.shouldAnimateIn = !0)
  5370. }
  5371. *
  5372. */
  5373.  
  5374. if (a.length) {
  5375. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  5376. const len = a.length;
  5377. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  5378. // Primarily for the initial batch, this is due to replayBuffer._back.
  5379. const entries = [];
  5380. const entriesI = [];
  5381. for (let i = 0; i < len; i++) {
  5382. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  5383. if (item) {
  5384. const itemRendererKey = firstObjectKey(item);
  5385. const itemRenderer = item[itemRendererKey];
  5386. if (itemRenderer) {
  5387. let timestampUsec = getTimestampUsec(itemRenderer);
  5388. if (timestampUsec !== null) {
  5389. timestampUsec = parseInt(timestampUsec);
  5390. if (timestampUsec > 0) {
  5391. entriesI.push(i);
  5392. entries.push({ e: a[i], timestampUsec })
  5393. }
  5394. }
  5395. }
  5396. }
  5397. }
  5398. const mLen = entries.length;
  5399. if (mLen >= 2) {
  5400. entries.sort((a, b) => {
  5401. const diff = a.timestampUsec - b.timestampUsec;
  5402. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  5403. });
  5404. for (let j = 0; j < mLen; j++) {
  5405. const i = entriesI[j];
  5406. a[i] = entries[j].e;
  5407. }
  5408. }
  5409. entries.length = 0;
  5410. entriesI.length = 0;
  5411. }
  5412. for (const action of a) {
  5413. action.__batchId45__ = batchToken;
  5414. this.handleLiveChatAction(action);
  5415. }
  5416. }
  5417. }
  5418.  
  5419. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  5420.  
  5421.  
  5422.  
  5423. cProto._nszlv_ = 0;
  5424. cProto._stackedLCAs_ = null;
  5425. cProto._lastAddItem_ = null;
  5426. cProto._lastAddItemInStack_ = false;
  5427. cProto.handleLiveChatAction = function (a) {
  5428.  
  5429.  
  5430. /**
  5431. *
  5432. *
  5433. f.handleLiveChatAction = function(a) {
  5434. var b = C(a, xO)
  5435. , c = C(a, yO)
  5436. , d = C(a, o1a)
  5437. , e = C(a, p1a);
  5438. a = C(a, A1a);
  5439. b ? this.unshift("items", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : a && this.handleRemoveChatItemByAuthorAction(a)
  5440. }
  5441. *
  5442. */
  5443.  
  5444. // return this.handleLiveChatAction45(a)
  5445. const { addChatItemAction, addLiveChatTickerItemAction, markChatItemAsDeletedAction,
  5446. removeChatItemAction, markChatItemsByAuthorAsDeletedAction, removeChatItemByAuthorAction, __batchId45__ } = a
  5447.  
  5448. if (addChatItemAction) return;
  5449.  
  5450.  
  5451. const d = Date.now();
  5452.  
  5453.  
  5454. // console.log(Object.keys(a));
  5455.  
  5456. if (this._stackedLCAs_ === null) this._stackedLCAs_ = [];
  5457. const stackArr = this._stackedLCAs_;
  5458. let newStackEntry = null;
  5459. if (addLiveChatTickerItemAction) {
  5460. let isDuplicated = false;
  5461.  
  5462. const newItem = addLiveChatTickerItemAction.item;
  5463. const tickerType = firstObjectKey(newItem);
  5464. if (!tickerType) return;
  5465. const tickerItem = newItem[tickerType];
  5466. const tickerId = tickerItem.id;
  5467. if (!tickerId) return;
  5468.  
  5469. if (this._lastAddItem_ && this._lastAddItem_.id === tickerId) {
  5470. let prevTickerItem = null;
  5471. if (this._lastAddItemInStack_) {
  5472. const entry = stackArr[stackArr.length - 1]; // only consider the last entry
  5473. if (entry && entry.action === 'addItem') {
  5474. prevTickerItem = entry.data; // only consider the first item;
  5475. }
  5476. } else {
  5477. prevTickerItem = this.items[0]; // only consider the first item;
  5478. }
  5479. if (prevTickerItem && prevTickerItem[tickerType]) {
  5480. if (prevTickerItem[tickerType].id === tickerId) {
  5481. isDuplicated = true;
  5482. }
  5483. }
  5484. }
  5485. if (!isDuplicated) {
  5486. this._lastAddItem_ = tickerItem;
  5487. this._lastAddItemInStack_ = true;
  5488. // console.log('newItem', newItem)
  5489.  
  5490. const item = newItem;
  5491. const key = firstObjectKey(item);
  5492. if (key) {
  5493. const itemRenderer = item[key] || 0;
  5494. if (itemRenderer.fullDurationSec > 0) {
  5495. itemRenderer.__actionAt__ = d;
  5496. }
  5497. }
  5498.  
  5499.  
  5500. newStackEntry = { action: 'addItem', data: newItem };
  5501.  
  5502. } else {
  5503. console.log('handleLiveChatAction Repeated Item', tickerItem.id, tickerItem); // happen in both live and playback. Reason Unknown.
  5504. return;
  5505. }
  5506.  
  5507. } else {
  5508. markChatItemAsDeletedAction && (newStackEntry = { action: 'mcItemD', data: markChatItemAsDeletedAction });
  5509. removeChatItemAction && (newStackEntry = { action: 'removeItemById', data: removeChatItemAction.targetId });
  5510. markChatItemsByAuthorAsDeletedAction && (newStackEntry = { action: 'mcItemAD', data: markChatItemsByAuthorAsDeletedAction });
  5511. removeChatItemByAuthorAction && (newStackEntry = { action: 'removeItemA', data: removeChatItemByAuthorAction })
  5512. }
  5513.  
  5514.  
  5515. if (!newStackEntry) return;
  5516. stackArr.push(newStackEntry);
  5517.  
  5518.  
  5519. this._nszlv_++;
  5520. if (this._nszlv_ > 1e9) this._nszlv_ = 9;
  5521. const tid = this._nszlv_;
  5522.  
  5523. newStackEntry.__batchId45__ = __batchId45__ || '';
  5524. newStackEntry.dateTime = Date.now();
  5525.  
  5526.  
  5527. foregroundPromiseFn().then(() => {
  5528.  
  5529. if (tid !== this._nszlv_) return;
  5530. const dateNow = Date.now(); // time difference to shift animation start time shall be considered. (pending)
  5531. const stackArr = this._stackedLCAs_.slice(0);
  5532. this._stackedLCAs_.length = 0;
  5533. this._lastAddItemInStack_ = false;
  5534. let lastDateTime = 0;
  5535. let prevBatchId = '';
  5536. const addItems = [];
  5537. // const previousShouldAnimateIn = this.shouldAnimateIn;
  5538.  
  5539. const addItemsFx = () => {
  5540.  
  5541. if (addItems.length >= 1) {
  5542. const eArr = addItems.slice(0);
  5543. addItems.length = 0;
  5544. if (ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME) {
  5545.  
  5546. const arr = []; // size of arr <= size of eArr
  5547. const d = Date.now();
  5548. for (const item of eArr) {
  5549. const key = firstObjectKey(item);
  5550. if (key) {
  5551.  
  5552.  
  5553. const itemRenderer = item[key] || 0;
  5554. const { durationSec, fullDurationSec, __actionAt__ } = itemRenderer;
  5555. if (__actionAt__ > 0 && durationSec > 0 && fullDurationSec > 0) {
  5556.  
  5557.  
  5558. const offset = d - __actionAt__;
  5559. if (offset > 0 && typeof durationSec === 'number' && typeof fullDurationSec === 'number' && fullDurationSec >= durationSec) {
  5560. const adjustedDurationSec = durationSec - Math.floor(offset / 1000);
  5561. if (adjustedDurationSec < durationSec) { // prevent NaN
  5562. // console.log('adjustedDurationSec', adjustedDurationSec);
  5563. if (adjustedDurationSec > 0) {
  5564. // console.log('offset Sec', Math.floor(offset / 1000));
  5565. itemRenderer.durationSec = adjustedDurationSec;
  5566. } else {
  5567. // if adjustedDurationSec equal 0 or invalid
  5568. continue; // skip adding
  5569. }
  5570. }
  5571.  
  5572. }
  5573.  
  5574. }
  5575.  
  5576. if (fullDurationSec > 0 && durationSec < 1) continue; // fallback check
  5577.  
  5578.  
  5579.  
  5580. }
  5581. arr.push(item)
  5582. // arr.unshift(item);
  5583. }
  5584.  
  5585.  
  5586. // console.log(arr.slice(0))
  5587. this.unshift("items", ...arr);
  5588. } else {
  5589. this.unshift("items", ...eArr);
  5590. }
  5591. }
  5592. }
  5593.  
  5594. for (const entry of stackArr) {
  5595.  
  5596. const { action, data, dateTime, __batchId45__ } = entry;
  5597.  
  5598. const finishLastAction = (
  5599. (prevBatchId !== __batchId45__ && prevBatchId)
  5600. || (dateNow - lastDateTime >= 1000 && dateNow - dateTime < 1000)
  5601. );
  5602.  
  5603. const addPrevItems = addItems.length >= 1 && (finishLastAction || action !== 'addItem');
  5604. lastDateTime = dateTime;
  5605. prevBatchId = __batchId45__;
  5606.  
  5607. // if (dateNow - dateTime >= 1000 && this.shouldAnimateIn) this.shouldAnimateIn = false;
  5608.  
  5609.  
  5610. if (addPrevItems) {
  5611. addItemsFx();
  5612. }
  5613. // if (finishLastAction) {
  5614. // this.updateHighlightedItem();
  5615. // if (!this.shouldAnimateIn) this.shouldAnimateIn = true;
  5616. // }
  5617.  
  5618.  
  5619. if (action === 'addItem') addItems.unshift(data);
  5620. else if (action === 'mcItemD') this.handleMarkChatItemAsDeletedAction(data);
  5621. else if (action === 'removeItemById') this.removeTickerItemById(data);
  5622. else if (action === 'mcItemAD') this.handleMarkChatItemsByAuthorAsDeletedAction(data);
  5623. else if (action === 'removeItemA') this.handleRemoveChatItemByAuthorAction(data);
  5624.  
  5625. }
  5626.  
  5627.  
  5628. // if (previousShouldAnimateIn && !this.shouldAnimateIn) this.shouldAnimateIn = true;
  5629.  
  5630. addItemsFx();
  5631.  
  5632. // if (prevBatchId || dateNow - lastDateTime >= 1000) {
  5633. // this.updateHighlightedItem();
  5634. // if (!this.shouldAnimateIn) this.shouldAnimateIn = true;
  5635. // }
  5636.  
  5637. })
  5638.  
  5639. }
  5640.  
  5641. console.log("AMEND_TICKER_handleLiveChatAction - OK");
  5642. } else {
  5643. console.log("AMEND_TICKER_handleLiveChatAction - NG");
  5644. }
  5645.  
  5646. if (RAF_FIX_keepScrollClamped) {
  5647.  
  5648. // to be improved
  5649.  
  5650. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  5651.  
  5652. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  5653. cProto.keepScrollClamped = function () {
  5654. this._bound_keepScrollClamped = this._bound_keepScrollClamped || this.keepScrollClamped.bind(this);
  5655. this.scrollClampRaf = requestAnimationFrame(this._bound_keepScrollClamped);
  5656. this.maybeClampScroll()
  5657. }
  5658.  
  5659. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  5660. } else {
  5661.  
  5662. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  5663. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  5664. }
  5665.  
  5666. }
  5667.  
  5668.  
  5669. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function' && fnIntegrity(cProto.startScrolling) === '1.43.31' && fnIntegrity(cProto.scrollIncrementally) === '1.82.43') {
  5670. // to be replaced by animator
  5671.  
  5672. cProto.startScrolling = function (a) {
  5673. this.scrollStopHandle && this.cancelAsync(this.scrollStopHandle);
  5674. this.asyncHandle && cancelAnimationFrame(this.asyncHandle);
  5675. this.lastFrameTimestamp = this.scrollStartTime = performance.now();
  5676. this.scrollRatePixelsPerSecond = a;
  5677. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5678. this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally)
  5679. };
  5680.  
  5681. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  5682.  
  5683. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  5684. const b = a - (this.lastFrameTimestamp || 0);
  5685. const rate = this.scrollRatePixelsPerSecond
  5686. const q = b / 1E3 * (rate || 0);
  5687.  
  5688. const sl = this.$.items.scrollLeft;
  5689. // console.log(rate, sl, q)
  5690. if (this.lastFrameTimestamp == this.scrollStartTime) {
  5691.  
  5692. } else if (q > -1e-5 && q < 1e-5) {
  5693.  
  5694. } else {
  5695. let cond1 = sl > 0 && rate > 0 && q > 0;
  5696. let cond2 = sl > 0 && rate < 0 && q < 0;
  5697. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  5698. if (cond1 || cond2 || cond3) {
  5699. this.$.items.scrollLeft += q;
  5700. this.maybeClampScroll();
  5701. this.updateArrows();
  5702. }
  5703. }
  5704.  
  5705. this.lastFrameTimestamp = a;
  5706. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5707. 0 < this.$.items.scrollLeft || rate && 0 < rate ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  5708. } : function (a) {
  5709. const b = a - (this.lastFrameTimestamp || 0);
  5710. this.$.items.scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  5711. this.maybeClampScroll();
  5712. this.updateArrows();
  5713. this.lastFrameTimestamp = a;
  5714. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5715. 0 < this.$.items.scrollLeft || this.scrollRatePixelsPerSecond && 0 < this.scrollRatePixelsPerSecond ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  5716. };
  5717.  
  5718. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  5719. } else {
  5720. assertor(() => fnIntegrity(cProto.startScrolling, '1.43.31'));
  5721. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.82.43'));
  5722. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  5723. }
  5724.  
  5725.  
  5726. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  5727.  
  5728. cProto.attached37 = cProto.attached;
  5729. cProto.detached37 = cProto.detached;
  5730.  
  5731. let naohzId = 0;
  5732. cProto.__naohzId__ = 0;
  5733. cProto.attached = function () {
  5734. Promise.resolve().then(() => {
  5735.  
  5736. const hostElement = this.hostElement || this;
  5737. if (!(hostElement instanceof HTMLElement)) return;
  5738. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  5739. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  5740. // or #chat-messages
  5741. if (!ironPage) return;
  5742.  
  5743. if (this.__naohzId__) removeEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5744. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  5745. this.__naohzId__ = ++naohzId;
  5746. ironPage.setAttribute('naohz', `${+this.__naohzId__}`);
  5747.  
  5748. addEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5749.  
  5750. });
  5751. return this.attached37.apply(this, arguments);
  5752. };
  5753. cProto.detached = function () {
  5754. Promise.resolve().then(() => {
  5755.  
  5756. const ironPage = document.querySelector(`iron-pages[naohz="${+this.__naohzId__}"]`);
  5757. if (!ironPage) return;
  5758.  
  5759. removeEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5760.  
  5761. });
  5762. return this.detached37.apply(this, arguments);
  5763. };
  5764.  
  5765. const clickFade = (u) => {
  5766. u.click();
  5767. };
  5768. cProto.messageBoxClickHandlerForFade = async (evt) => {
  5769.  
  5770. const target = (evt || 0).target || 0;
  5771. if (!target) return;
  5772.  
  5773. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  5774. const is = p.is;
  5775. if (typeof is === 'string' && is) {
  5776.  
  5777. if (is === 'yt-live-chat-pinned-message-renderer') {
  5778. return;
  5779. }
  5780. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  5781. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  5782. if (fade) {
  5783. Promise.resolve(fade).then(clickFade);
  5784. evt && evt.stopPropagation();
  5785. }
  5786. return;
  5787. }
  5788. if (is !== 'yt-live-chat-ticker-renderer') {
  5789. if (is.startsWith('yt-live-chat-ticker-')) return;
  5790. if (!is.endsWith('-renderer')) return;
  5791. }
  5792.  
  5793. } else {
  5794. if ((p.nodeName || '').includes('BUTTON')) return;
  5795. }
  5796.  
  5797. }
  5798. };
  5799.  
  5800. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  5801.  
  5802. } else {
  5803. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  5804. }
  5805.  
  5806.  
  5807. })();
  5808.  
  5809. console.log("[End]");
  5810.  
  5811. console.groupEnd();
  5812.  
  5813. }).catch(console.warn);
  5814.  
  5815.  
  5816. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  5817.  
  5818.  
  5819. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  5820.  
  5821. mightFirstCheckOnYtInit();
  5822. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  5823. console.log("[Begin]");
  5824. (() => {
  5825.  
  5826. const tag = "yt-live-chat-message-input-renderer"
  5827. const dummy = document.createElement(tag);
  5828.  
  5829. const cProto = getProto(dummy);
  5830. if (!cProto || !cProto.attached) {
  5831. console.warn(`proto.attached for ${tag} is unavailable.`);
  5832. return;
  5833. }
  5834.  
  5835. let doHack = false;
  5836. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  5837.  
  5838. // not cancellable
  5839.  
  5840.  
  5841. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  5842.  
  5843. }
  5844.  
  5845. if (doHack) {
  5846.  
  5847. cProto.handleTimeout = function (a) {
  5848. console.log('cProto.handleTimeout', tag)
  5849. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  5850. this.timeoutDurationMs = this.timeoutMs = a;
  5851. this.countdownRatio = 1;
  5852. 0 === this.lastTimeoutTimeMs && rafHub.request(this.boundUpdateTimeout38_)
  5853. };
  5854. cProto.updateTimeout = function (a) {
  5855. console.log('cProto.updateTimeout', tag)
  5856. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  5857. this.lastTimeoutTimeMs && (this.timeoutMs = Math.max(0, this.timeoutMs - (a - this.lastTimeoutTimeMs)),
  5858. this.countdownRatio = this.timeoutMs / this.timeoutDurationMs);
  5859. this.isAttached && this.timeoutMs ? (this.lastTimeoutTimeMs = a,
  5860. rafHub.request(this.boundUpdateTimeout38_)) : this.lastTimeoutTimeMs = 0
  5861. };
  5862.  
  5863. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  5864. } else {
  5865.  
  5866. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  5867. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  5868.  
  5869. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  5870. }
  5871.  
  5872. })();
  5873.  
  5874. console.log("[End]");
  5875.  
  5876. console.groupEnd();
  5877.  
  5878.  
  5879. })
  5880.  
  5881.  
  5882. }
  5883.  
  5884. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  5885.  
  5886.  
  5887. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  5888.  
  5889. mightFirstCheckOnYtInit();
  5890. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  5891. console.log("[Begin]");
  5892. (() => {
  5893.  
  5894. const tag = "yt-emoji-picker-renderer"
  5895. const dummy = document.createElement(tag);
  5896.  
  5897. const cProto = getProto(dummy);
  5898. if (!cProto || !cProto.attached) {
  5899. console.warn(`proto.attached for ${tag} is unavailable.`);
  5900. return;
  5901. }
  5902.  
  5903. let doHack = false;
  5904. if (typeof cProto.animateScroll_ === 'function') {
  5905.  
  5906. // not cancellable
  5907. console.log('animateScroll_', typeof cProto.animateScroll_)
  5908.  
  5909. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  5910.  
  5911. }
  5912.  
  5913. if (doHack) {
  5914.  
  5915. const querySelector = HTMLElement.prototype.querySelector;
  5916. const U = (element) => ({
  5917. querySelector: (selector) => querySelector.call(element, selector)
  5918. });
  5919.  
  5920. cProto.animateScroll_ = function (a) {
  5921. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  5922. if (!this.boundAnimateScroll39_) this.boundAnimateScroll39_ = this.animateScroll_.bind(this);
  5923. this.lastAnimationTime_ || (this.lastAnimationTime_ = a);
  5924. a -= this.lastAnimationTime_;
  5925. 200 > a ? (U(this.hostElement).querySelector("#categories").scrollTop = this.animationStart_ + (this.animationEnd_ - this.animationStart_) * a / 200,
  5926. rafHub.request(this.boundAnimateScroll39_)) : (null != this.animationEnd_ && (U(this.hostElement).querySelector("#categories").scrollTop = this.animationEnd_),
  5927. this.animationEnd_ = this.animationStart_ = null,
  5928. this.lastAnimationTime_ = 0);
  5929. this.updateButtons_()
  5930. }
  5931.  
  5932. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  5933. } else {
  5934.  
  5935. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  5936. }
  5937.  
  5938. })();
  5939.  
  5940. console.log("[End]");
  5941.  
  5942. console.groupEnd();
  5943. });
  5944. }
  5945.  
  5946. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  5947.  
  5948.  
  5949. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  5950.  
  5951. mightFirstCheckOnYtInit();
  5952. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  5953. console.log("[Begin]");
  5954. (() => {
  5955.  
  5956. const tag = "yt-live-chat-docked-message"
  5957. const dummy = document.createElement(tag);
  5958.  
  5959. const cProto = getProto(dummy);
  5960. if (!cProto || !cProto.attached) {
  5961. console.warn(`proto.attached for ${tag} is unavailable.`);
  5962. return;
  5963. }
  5964.  
  5965. let doHack = false;
  5966. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  5967.  
  5968. // cancelable - this.intersectRAF <detached>
  5969. // yt-live-chat-docked-message
  5970. // boundCheckIntersections <-> checkIntersections
  5971. // onDockableMessagesChanged
  5972. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  5973.  
  5974. console.log('detached', typeof cProto.detached)
  5975. console.log('checkIntersections', typeof cProto.checkIntersections)
  5976. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  5977.  
  5978. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  5979.  
  5980. }
  5981.  
  5982. if (doHack) {
  5983.  
  5984. cProto.checkIntersections = function () {
  5985. // console.log('cProto.checkIntersections', tag)
  5986. if (this.dockableMessages.length) {
  5987. this.intersectRAF = rafHub.request(this.boundCheckIntersections);
  5988. let a = this.dockableMessages[0]
  5989. , b = this.hostElement.getBoundingClientRect();
  5990. a = a.getBoundingClientRect();
  5991. let c = a.top - b.top
  5992. , d = 8 >= c;
  5993. c = 8 >= c - this.hostElement.clientHeight;
  5994. if (d) {
  5995. let e;
  5996. for (; d;) {
  5997. e = this.dockableMessages.shift();
  5998. d = this.dockableMessages[0];
  5999. if (!d)
  6000. break;
  6001. d = d.getBoundingClientRect();
  6002. c = d.top - b.top;
  6003. let f = 8 >= c;
  6004. if (8 >= c - a.height)
  6005. if (f)
  6006. a = d;
  6007. else
  6008. return;
  6009. d = f
  6010. }
  6011. this.dock(e)
  6012. } else
  6013. c && this.dockedItem && this.clear()
  6014. } else
  6015. this.intersectRAF = 0
  6016. }
  6017.  
  6018. cProto.onDockableMessagesChanged = function () {
  6019. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  6020. this.dockableMessages.length && !this.intersectRAF && (this.intersectRAF = rafHub.request(this.boundCheckIntersections))
  6021. }
  6022.  
  6023. cProto.detached = function () {
  6024. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  6025. }
  6026.  
  6027. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  6028. } else {
  6029.  
  6030. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  6031. }
  6032.  
  6033. })();
  6034.  
  6035. console.log("[End]");
  6036.  
  6037. console.groupEnd();
  6038.  
  6039. }).catch(console.warn);
  6040.  
  6041. }
  6042.  
  6043. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  6044.  
  6045.  
  6046. customElements.whenDefined("yt-img-shadow").then(() => {
  6047.  
  6048. mightFirstCheckOnYtInit();
  6049. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  6050. console.log("[Begin]");
  6051. (() => {
  6052.  
  6053. const tag = "yt-img-shadow"
  6054. const dummy = document.createElement(tag);
  6055.  
  6056. const cProto = getProto(dummy);
  6057. if (!cProto || !cProto.attached) {
  6058. console.warn(`proto.attached for ${tag} is unavailable.`);
  6059. return;
  6060. }
  6061.  
  6062. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  6063.  
  6064. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  6065. cProto.thumbnailChanged_ = function (a) {
  6066.  
  6067. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  6068. if (!this.oldThumbnail_ && !this.thumbnail) return;
  6069.  
  6070. return this.thumbnailChanged66_.apply(this, arguments)
  6071.  
  6072. }
  6073. console.log("cProto.thumbnailChanged_ - OK");
  6074.  
  6075. } else {
  6076. console.log("cProto.thumbnailChanged_ - NG");
  6077.  
  6078. }
  6079. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  6080.  
  6081. cProto.setSrc66_ = cProto.setSrc_;
  6082. cProto.setSrc_ = function (a) {
  6083. if ((((this || 0).$ || 0).img || 0).src === a) return;
  6084. return this.setSrc66_.apply(this, arguments)
  6085. }
  6086.  
  6087. console.log("cProto.setSrc_ - OK");
  6088. } else {
  6089.  
  6090. console.log("cProto.setSrc_ - NG");
  6091. }
  6092.  
  6093. })();
  6094.  
  6095. console.log("[End]");
  6096.  
  6097. console.groupEnd();
  6098.  
  6099. }).catch(console.warn);
  6100.  
  6101. }
  6102.  
  6103. if (FIX_THUMBNAIL_DATACHANGED) {
  6104.  
  6105.  
  6106.  
  6107. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  6108.  
  6109. mightFirstCheckOnYtInit();
  6110. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  6111. console.log("[Begin]");
  6112. (() => {
  6113.  
  6114. const tag = "yt-live-chat-author-badge-renderer"
  6115. const dummy = document.createElement(tag);
  6116.  
  6117. const cProto = getProto(dummy);
  6118. if (!cProto || !cProto.attached) {
  6119. console.warn(`proto.attached for ${tag} is unavailable.`);
  6120. return;
  6121. }
  6122.  
  6123.  
  6124. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && fnIntegrity(cProto.dataChanged) === '1.159.97') {
  6125.  
  6126.  
  6127.  
  6128. cProto.dataChanged86 = cProto.dataChanged;
  6129. cProto.dataChanged = function (a) {
  6130.  
  6131. /*
  6132.  
  6133. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  6134. b.removeChild(b.firstChild);
  6135. if (a)
  6136. if (a.icon) {
  6137. var c = document.createElement("yt-icon");
  6138. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  6139. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  6140. b.appendChild(c)
  6141. } else if (a.customThumbnail) {
  6142. c = document.createElement("img");
  6143. var d;
  6144. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  6145. b.appendChild(c),
  6146. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  6147. }
  6148.  
  6149. */
  6150.  
  6151. const image = ((this || 0).$ || 0).image
  6152. if (image && a && image.firstElementChild) {
  6153. let exisiting = image.firstElementChild;
  6154. if (exisiting === image.lastElementChild) {
  6155.  
  6156.  
  6157. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  6158.  
  6159. let c = exisiting;
  6160. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  6161. if (c.icon !== "yt-sys-icons:shield-filled") c.icon = "yt-sys-icons:shield-filled";
  6162. if (c.defaultToFilled !== true) c.defaultToFilled = true;
  6163. } else {
  6164. let p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  6165. if (c.icon !== p) c.icon = p;
  6166. if (c.defaultToFilled !== false) c.defaultToFilled = false;
  6167. }
  6168. return;
  6169.  
  6170.  
  6171. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  6172.  
  6173. let c = exisiting;
  6174. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  6175.  
  6176. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  6177. return;
  6178. }
  6179. /*
  6180.  
  6181. var d;
  6182. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  6183.  
  6184.  
  6185. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  6186. */
  6187. }
  6188.  
  6189.  
  6190. }
  6191. }
  6192. return this.dataChanged86.apply(this, arguments)
  6193.  
  6194. }
  6195. console.log("cProto.dataChanged - OK");
  6196.  
  6197. } else {
  6198. assertor(() => fnIntegrity(cProto.dataChanged, '1.159.97'));
  6199. console.log("cProto.dataChanged - NG");
  6200.  
  6201. }
  6202.  
  6203. })();
  6204.  
  6205. console.log("[End]");
  6206.  
  6207. console.groupEnd();
  6208.  
  6209. }).catch(console.warn);
  6210.  
  6211.  
  6212. }
  6213.  
  6214.  
  6215. if (FIX_TOOLTIP_DISPLAY) {
  6216.  
  6217.  
  6218. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  6219.  
  6220. mightFirstCheckOnYtInit();
  6221. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  6222. console.log("[Begin]");
  6223. (() => {
  6224.  
  6225. const tag = "tp-yt-paper-tooltip"
  6226. const dummy = document.createElement(tag);
  6227.  
  6228. const cProto = getProto(dummy);
  6229. if (!cProto || !cProto.attached) {
  6230. console.warn(`proto.attached for ${tag} is unavailable.`);
  6231. return;
  6232. }
  6233.  
  6234. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  6235.  
  6236. cProto._readyClients43 = cProto._readyClients;
  6237. cProto._readyClients = function () {
  6238. let r = cProto._readyClients43.apply(this, arguments);
  6239. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  6240. return r;
  6241. }
  6242.  
  6243. console.log("_readyClients - OK");
  6244.  
  6245. } else {
  6246. console.log("_readyClients - NG");
  6247.  
  6248. }
  6249.  
  6250. if (typeof cProto.show === 'function' && !cProto.show17) {
  6251. cProto.show17 = cProto.show;
  6252. cProto.show = function () {
  6253.  
  6254. let r = this.show17.apply(this, arguments);
  6255. this._showing === true && Promise.resolve().then(() => {
  6256. const tooltip = (this.$ || 0).tooltip;
  6257.  
  6258. if (tooltip && tooltip.firstElementChild === null) {
  6259. let text = tooltip.textContent;
  6260. if (typeof text === 'string' && text.length >= 2) {
  6261. tooltip.textContent = text.trim();
  6262. }
  6263. }
  6264. }).catch(console.warn)
  6265. return r;
  6266. }
  6267.  
  6268. console.log("trim tooltip content - OK");
  6269.  
  6270. } else {
  6271. console.log("trim tooltip content - NG");
  6272.  
  6273. }
  6274.  
  6275. /*
  6276. cProto.updatePosition61 = cProto.updatePosition;
  6277.  
  6278.  
  6279. cProto.updatePosition = function () {
  6280.  
  6281.  
  6282. if (this._target && this.offsetParent) {
  6283. var a = this.offset;
  6284. 14 != this.marginTop && 14 == this.offset && (a = this.marginTop);
  6285. var b = this.offsetParent.getBoundingClientRect()
  6286. , c = this._target.getBoundingClientRect()
  6287. , d = this.getBoundingClientRect()
  6288. , e = (c.width - d.width) / 2
  6289. , h = (c.height - d.height) / 2
  6290. , l = c.left - b.left
  6291. , m = c.top - b.top;
  6292. switch (this.position) {
  6293. case "top":
  6294. var p = l + e;
  6295. var q = m - d.height - a;
  6296. break;
  6297. case "bottom":
  6298. p = l + e;
  6299. q = m + c.height + a;
  6300. break;
  6301. case "left":
  6302. p = l - d.width - a;
  6303. q = m + h;
  6304. break;
  6305. case "right":
  6306. p = l + c.width + a,
  6307. q = m + h;
  6308. }
  6309.  
  6310. if(this.ascee) {
  6311. this.fitToVisibleBounds = false;
  6312. }
  6313. this.fitToVisibleBounds ? (b.left + p + d.width > window.innerWidth ? (this.style.right = "0px",
  6314. this.style.left = "auto") : (this.style.left = Math.max(0, p) + "px",
  6315. this.style.right = "auto"),
  6316. b.top + q + d.height > window.innerHeight ? (this.style.bottom = b.height + "px",
  6317. this.style.top = "auto") : (this.style.top = Math.max(-b.top, q) + "px",
  6318. this.style.bottom = "auto")) : (this.style.left = p + "px",
  6319. this.style.top = q + "px")
  6320. }
  6321. }
  6322.  
  6323. cProto.updateStyles61 = cProto.updateStyles;
  6324. cProto.updateStyles= function(){
  6325. if(this.ascee) return;
  6326. return this.updateStyles61.apply(this,arguments);
  6327. }
  6328. */
  6329.  
  6330.  
  6331. })();
  6332.  
  6333. console.log("[End]");
  6334.  
  6335. console.groupEnd();
  6336.  
  6337. }).catch(console.warn);
  6338.  
  6339.  
  6340.  
  6341. }
  6342.  
  6343.  
  6344.  
  6345. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  6346.  
  6347.  
  6348. const hookDocumentMouseDownSetupFn = () => {
  6349.  
  6350.  
  6351.  
  6352. let muzTimestamp = 0;
  6353. let nszDropdown = null;
  6354.  
  6355.  
  6356.  
  6357. const handlerObject = {
  6358.  
  6359. // mdHandler282 : function (evt) {
  6360. // // console.log(evt, 1, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6361. // if (!evt || !evt.isTrusted) return;
  6362. // muzTimestamp = 0;
  6363. // nszDropdown = null;
  6364.  
  6365. // const hostElement = this.hostElement || this;
  6366. // if (!evt || !evt.isTrusted || !hostElement.hasAttribute('menu-visible')) return;
  6367. // if (!hostElement.contains(evt.target)) return;
  6368. // let targetDropDown = null;
  6369. // for(const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')){
  6370. // if(dropdown && dropdown.positionTarget && hostElement.contains( dropdown.positionTarget)){
  6371. // targetDropDown = dropdown;
  6372. // }
  6373. // }
  6374. // if ((nszDropdown = targetDropDown)) {
  6375. // muzTimestamp = Date.now();
  6376. // evt.stopImmediatePropagation();
  6377. // evt.stopPropagation();
  6378. // }
  6379.  
  6380. // },
  6381.  
  6382.  
  6383. muHandler282: function (evt) {
  6384. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6385. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6386. const dropdown = nszDropdown;
  6387. muzTimestamp = 0;
  6388. nszDropdown = null;
  6389.  
  6390. const kurMPC = kRef(currentMenuPivotWR) || 0;
  6391. const hostElement = kurMPC.hostElement || kurMPC;
  6392. if (!hostElement.hasAttribute('menu-visible')) return;
  6393.  
  6394. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  6395. if (chatBanner) return;
  6396.  
  6397. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  6398.  
  6399. /*
  6400. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6401. if(parentButton) return;
  6402. */
  6403.  
  6404. muzTimestamp = Date.now();
  6405. evt.stopImmediatePropagation();
  6406. evt.stopPropagation();
  6407. Promise.resolve(dropdown).then((dropdown) => {
  6408. dropdown.cancel();
  6409. });
  6410. // document.body.click();
  6411. }
  6412.  
  6413. },
  6414.  
  6415. mlHandler282: function (evt) {
  6416. muzTimestamp = 0;
  6417. nszDropdown = null;
  6418. },
  6419.  
  6420. ckHandler282: function (evt) {
  6421. // console.log(evt, 3, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6422.  
  6423. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6424. if (Date.now() - muzTimestamp < 40) {
  6425.  
  6426. /*
  6427. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6428. if(parentButton) return;
  6429. */
  6430.  
  6431. muzTimestamp = Date.now();
  6432. evt.stopImmediatePropagation();
  6433. evt.stopPropagation();
  6434. }
  6435.  
  6436. },
  6437.  
  6438. tapHandler282: function (evt) {
  6439. // console.log(evt, 2, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6440.  
  6441. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6442. if (Date.now() - muzTimestamp < 40) {
  6443.  
  6444. /*
  6445. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6446. if(parentButton) return;
  6447. */
  6448.  
  6449. muzTimestamp = Date.now();
  6450. evt.stopImmediatePropagation();
  6451. evt.stopPropagation();
  6452. }
  6453.  
  6454. },
  6455.  
  6456.  
  6457. handleEvent(evt) {
  6458.  
  6459.  
  6460. if (evt) {
  6461. const kurMPC = kRef(currentMenuPivotWR) || 0;
  6462. const cnt = insp(kurMPC);
  6463. const hostElement = cnt.hostElement || cnt;
  6464. if (!cnt || cnt.isAttached !== true || hostElement.isConnected !== true) return;
  6465. switch (evt.type) {
  6466. // case 'mousedown':
  6467. // return this.mdHandler282.call(kurMPC, evt);
  6468. case 'mouseup':
  6469. return this.muHandler282(evt);
  6470. case 'mouseleave':
  6471. return this.mlHandler282(evt);
  6472. case 'tap':
  6473. return this.tapHandler282(evt);
  6474. case 'click':
  6475. return this.ckHandler282(evt);
  6476. }
  6477. }
  6478.  
  6479. }
  6480.  
  6481.  
  6482.  
  6483. }
  6484.  
  6485. document.addEventListener('mousedown', function (evt) {
  6486.  
  6487. if (!evt || !evt.isTrusted || !evt.target) return;
  6488.  
  6489.  
  6490.  
  6491. muzTimestamp = 0;
  6492. nszDropdown = null;
  6493.  
  6494. /*
  6495. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6496. if(parentButton){
  6497. const kurMPC = HTMLElement.prototype.closest.call(parentButton, '[whole-message-clickable]') || 0;
  6498. if(kurMPC){
  6499. evt.preventDefault();
  6500. evt.stopImmediatePropagation();
  6501. evt.stopPropagation();
  6502. }
  6503. return;
  6504. }
  6505. */
  6506.  
  6507. /** @type {HTMLElement | null} */
  6508. const kurMP = kRef(currentMenuPivotWR);
  6509. if (!kurMP) return;
  6510. const kurMPC = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0;
  6511.  
  6512. if (!kurMPC || !kurMPC.hasAttribute('whole-message-clickable')) return;
  6513.  
  6514. if (!kurMPC.isClickableChatRow111 || !kurMPC.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPC, evt.target)) return;
  6515.  
  6516. const chatBanner = HTMLElement.prototype.closest.call(kurMPC, 'yt-live-chat-banner-renderer') || 0;
  6517. if (chatBanner) return;
  6518.  
  6519.  
  6520. let targetDropDown = null;
  6521. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  6522. if (dropdown && dropdown.positionTarget === kurMP) {
  6523. targetDropDown = dropdown;
  6524. }
  6525. }
  6526.  
  6527. if (!targetDropDown) return;
  6528.  
  6529.  
  6530. /*
  6531. if (parentButton) {
  6532. evt.preventDefault();
  6533. evt.stopImmediatePropagation();
  6534. evt.stopPropagation();
  6535. currentMenuPivotWR = mWeakRef(kurMPC);
  6536. return;
  6537. }
  6538. */
  6539.  
  6540. if ((nszDropdown = targetDropDown)) {
  6541. muzTimestamp = Date.now();
  6542. evt.stopImmediatePropagation();
  6543. evt.stopPropagation();
  6544. currentMenuPivotWR = mWeakRef(kurMPC);
  6545.  
  6546. const listenOpts = { capture: true, passive: false, once: true };
  6547.  
  6548. // remove unexcecuted eventHandler
  6549. document.removeEventListener('mouseup', handlerObject, listenOpts);
  6550. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  6551. document.removeEventListener('tap', handlerObject, listenOpts);
  6552. document.removeEventListener('click', handlerObject, listenOpts);
  6553.  
  6554. // inject one time eventHandler to by pass events
  6555. document.addEventListener('mouseup', handlerObject, listenOpts);
  6556. document.addEventListener('mouseleave', handlerObject, listenOpts);
  6557. document.addEventListener('tap', handlerObject, listenOpts);
  6558. document.addEventListener('click', handlerObject, listenOpts);
  6559.  
  6560. }
  6561.  
  6562. }, true);
  6563.  
  6564. }
  6565.  
  6566.  
  6567. // yt-live-chat-paid-message-renderer ??
  6568.  
  6569. /*
  6570.  
  6571. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  6572.  
  6573.  
  6574. "yt-live-chat-ticker-paid-message-item-renderer"
  6575. "yt-live-chat-ticker-paid-sticker-item-renderer"
  6576. "yt-live-chat-paid-message-renderer"
  6577. "yt-live-chat-text-message-renderer"
  6578. "yt-live-chat-paid-sticker-renderer"
  6579.  
  6580. */
  6581.  
  6582.  
  6583. whenDefinedMultiple([
  6584.  
  6585. "yt-live-chat-paid-message-renderer",
  6586. "yt-live-chat-membership-item-renderer",
  6587. "yt-live-chat-paid-sticker-renderer",
  6588. "yt-live-chat-text-message-renderer",
  6589. "yt-live-chat-auto-mod-message-renderer",
  6590.  
  6591. /*
  6592. "yt-live-chat-ticker-paid-message-item-renderer",
  6593. "yt-live-chat-ticker-paid-sticker-item-renderer",
  6594. "yt-live-chat-paid-message-renderer",
  6595. "yt-live-chat-text-message-renderer",
  6596. "yt-live-chat-paid-sticker-renderer",
  6597.  
  6598. "yt-live-chat-ticker-sponsor-item-renderer",
  6599. "yt-live-chat-banner-header-renderer",
  6600. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6601. "ytd-sponsorships-live-chat-header-renderer",
  6602. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6603.  
  6604.  
  6605.  
  6606.  
  6607. "yt-live-chat-auto-mod-message-renderer",
  6608. "yt-live-chat-text-message-renderer",
  6609. "yt-live-chat-paid-message-renderer",
  6610.  
  6611. "yt-live-chat-legacy-paid-message-renderer",
  6612. "yt-live-chat-membership-item-renderer",
  6613. "yt-live-chat-paid-sticker-renderer",
  6614. "yt-live-chat-donation-announcement-renderer",
  6615. "yt-live-chat-moderation-message-renderer",
  6616. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6617. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6618. "yt-live-chat-viewer-engagement-message-renderer",
  6619.  
  6620. */
  6621.  
  6622.  
  6623. ]).then(sTags => {
  6624.  
  6625.  
  6626. mightFirstCheckOnYtInit();
  6627. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  6628. console.log("[Begin]");
  6629. let doMouseHook = false;
  6630.  
  6631. const dProto = {
  6632. isClickableChatRow111: function () {
  6633. return (
  6634. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  6635. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  6636. ); // follow .onItemTap(a)
  6637. }
  6638. };
  6639.  
  6640. for (const sTag of sTags) { // ##tag##
  6641.  
  6642.  
  6643. (() => {
  6644.  
  6645. const tag = sTag;
  6646. const dummy = document.createElement(tag);
  6647.  
  6648. const cProto = getProto(dummy);
  6649. if (!cProto || !cProto.attached) {
  6650. console.warn(`proto.attached for ${tag} is unavailable.`);
  6651. return;
  6652. }
  6653.  
  6654. const dCnt = insp(dummy);
  6655. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  6656.  
  6657. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  6658.  
  6659. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  6660.  
  6661. if (toHookDocumentMouseDown) {
  6662. doMouseHook = true;
  6663. }
  6664.  
  6665. console.log("shouldSupportWholeItemClick Y", tag);
  6666.  
  6667. } else {
  6668.  
  6669. console.log("shouldSupportWholeItemClick N", tag);
  6670. }
  6671.  
  6672.  
  6673. })();
  6674.  
  6675. }
  6676.  
  6677.  
  6678. if (doMouseHook) {
  6679.  
  6680. hookDocumentMouseDownSetupFn();
  6681.  
  6682.  
  6683. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  6684. }
  6685.  
  6686. console.log("[End]");
  6687.  
  6688. console.groupEnd();
  6689.  
  6690.  
  6691. }).catch(console.warn);
  6692.  
  6693.  
  6694. // https://www.youtube.com/watch?v=oQzFi1NO7io
  6695.  
  6696.  
  6697. }
  6698.  
  6699.  
  6700. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  6701.  
  6702. let rr = null;
  6703. const p1 = new Promise(resolve => {
  6704. rr = resolve;
  6705. });
  6706.  
  6707. const p1unlock = () => {
  6708. const f = rr;
  6709. if (f) {
  6710. rr = null;
  6711. f();
  6712. }
  6713. }
  6714.  
  6715. return {
  6716. p1,
  6717. p1unlock,
  6718. assignLock: (targetCnt, timeout) => {
  6719. targetCnt.__showContextMenu_assign_lock__(p1);
  6720. if (timeout) setTimeout(p1unlock, timeout);
  6721. }
  6722. }
  6723.  
  6724. }
  6725.  
  6726. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  6727.  
  6728. document.addEventListener('mousedown', function (evt) {
  6729.  
  6730. const maxloopDOMTreeElements = 4;
  6731. const maxloopYtCompontents = 4;
  6732. let j1 = 0;
  6733. let j2 = 0;
  6734. let target = (evt || 0).target || 0;
  6735. if (!target) return;
  6736.  
  6737.  
  6738. while (target instanceof HTMLElement) {
  6739. if (++j1 > maxloopDOMTreeElements) break;
  6740. if (typeof (target.is || insp(target).is || null) === 'string') break;
  6741. target = nodeParent(target);
  6742. }
  6743. const components = [];
  6744. while (target instanceof HTMLElement) {
  6745. if (++j2 > maxloopYtCompontents) break;
  6746. const cnt = insp(target);
  6747. if (typeof (target.is || cnt.is || null) === 'string') {
  6748. components.push(target);
  6749. }
  6750. if (typeof cnt.showContextMenu === 'function') break;
  6751. target = target.parentComponent || cnt.parentComponent || null;
  6752. }
  6753. if (!(target instanceof HTMLElement)) return;
  6754. const targetCnt = insp(target);
  6755. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  6756. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  6757. return;
  6758. }
  6759.  
  6760. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  6761. if (!endpoint) return;
  6762. if (targetCnt.opened || !targetCnt.isAttached) return;
  6763.  
  6764. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  6765. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  6766. }
  6767.  
  6768. const targetDollar = indr(target);
  6769.  
  6770. let doPreRequest = false;
  6771. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  6772. doPreRequest = true;
  6773. } else if (components.length === 1 && components[0] === target) {
  6774. doPreRequest = true;
  6775. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  6776. doPreRequest = true;
  6777. }
  6778. if (doPreRequest === false) {
  6779. console.log('doPreRequest = fasle on showContextMenu', components);
  6780. return;
  6781. }
  6782.  
  6783. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  6784.  
  6785. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  6786. console.log('preRequest on showContextMenu aborted due to stacked network request');
  6787. return;
  6788. }
  6789.  
  6790.  
  6791. const onSuccess = (a) => {
  6792. /*
  6793.  
  6794. dQ() && (a = a.response);
  6795. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  6796. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  6797.  
  6798. */
  6799.  
  6800. a = a.response || a;
  6801.  
  6802. if (!a) {
  6803. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  6804. return;
  6805. }
  6806.  
  6807. let z = null;
  6808. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  6809.  
  6810. if (z) {
  6811. a = z;
  6812. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  6813. }
  6814.  
  6815. };
  6816. const onFailure = (a) => {
  6817.  
  6818. /*
  6819.  
  6820. if (a instanceof Error || a instanceof Object || a instanceof String)
  6821. var b = a;
  6822. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  6823.  
  6824. */
  6825.  
  6826. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  6827. // console.log('onFailure', a)
  6828.  
  6829. };
  6830.  
  6831. if (doPreRequest) {
  6832.  
  6833. let propertyCounter = 0;
  6834. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  6835. const p1Timeout = 800;
  6836. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  6837.  
  6838. try {
  6839.  
  6840. const onSuccessHelperFn = function () {
  6841. pm1.p1unlock();
  6842. if (propertyCounter !== 5) {
  6843. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  6844. return;
  6845. }
  6846. if (this[proxyKey] !== targetCnt) {
  6847. console.log('Error in prerequest for showContextMenu.this');
  6848. return;
  6849. }
  6850. onSuccess(...arguments);
  6851. };
  6852. const onFailureHelperFn = function () {
  6853. pm1.p1unlock();
  6854. if (propertyCounter !== 5) {
  6855. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  6856. return;
  6857. }
  6858. if (this[proxyKey] !== targetCnt) {
  6859. console.log('Error in prerequest for showContextMenu.this');
  6860. return;
  6861. }
  6862. onFailure(...arguments);
  6863.  
  6864. }
  6865. const fakeTargetCnt = new Proxy({
  6866. __showContextMenu_forceNativeRequest__: 1,
  6867. __showContextMenu_sync_mode_request__: 1,
  6868. get handleGetContextMenuResponse_() {
  6869. propertyCounter += 2;
  6870. return onSuccessHelperFn;
  6871. },
  6872. get handleGetContextMenuError() {
  6873. propertyCounter += 3;
  6874. return onFailureHelperFn;
  6875. }
  6876. }, {
  6877. get(_, key, receiver) {
  6878. if (key in _) return _[key];
  6879. if (key === proxyKey) return targetCnt;
  6880.  
  6881. let giveNative = false;
  6882. if (key in targetCnt) {
  6883. if (key === 'data') giveNative = true;
  6884. else if (typeof targetCnt[key] === 'function') giveNative = true;
  6885. }
  6886. if (giveNative) return targetCnt[key];
  6887. }
  6888. });
  6889.  
  6890. const fakeEvent = (() => {
  6891. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  6892. const nf = function () { }
  6893. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  6894.  
  6895. return {
  6896. type: 'tap',
  6897. eventPhase: 0,
  6898. isTrusted: false,
  6899. __composed: true,
  6900. bubbles, cancelable, cancelBubble, timeStamp,
  6901. target, srcElement, defaultPrevented, currentTarget, composed,
  6902. stopPropagation, stopImmediatePropagation, preventDefault
  6903. };
  6904. })(evt);
  6905. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  6906.  
  6907.  
  6908. } catch (e) {
  6909. console.warn(e);
  6910. propertyCounter = 7;
  6911.  
  6912. }
  6913. if (propertyCounter !== 5) {
  6914. console.log('Error in prerequest for showContextMenu', propertyCounter);
  6915. return;
  6916. }
  6917.  
  6918. pm1.assignLock(targetCnt, p1Timeout);
  6919.  
  6920. }
  6921.  
  6922.  
  6923.  
  6924.  
  6925.  
  6926.  
  6927. }, true);
  6928.  
  6929.  
  6930. }
  6931.  
  6932.  
  6933.  
  6934. /*
  6935.  
  6936. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  6937.  
  6938. */
  6939.  
  6940. whenDefinedMultiple([
  6941. "yt-live-chat-ticker-sponsor-item-renderer",
  6942. "yt-live-chat-banner-header-renderer",
  6943. "yt-live-chat-text-message-renderer",
  6944. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6945. "ytd-sponsorships-live-chat-header-renderer",
  6946. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6947.  
  6948. "yt-live-chat-paid-sticker-renderer",
  6949. "yt-live-chat-viewer-engagement-message-renderer",
  6950. "yt-live-chat-paid-message-renderer"
  6951.  
  6952.  
  6953.  
  6954.  
  6955. ]).then(sTags => {
  6956.  
  6957. mightFirstCheckOnYtInit();
  6958. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  6959. console.log("[Begin]");
  6960.  
  6961.  
  6962. const __showContextMenu_mutex__ = new Mutex();
  6963. let __showContextMenu_mutex_unlock__ = null;
  6964. let lastShowMenuTarget = null;
  6965.  
  6966.  
  6967.  
  6968.  
  6969. const wm37 = new WeakMap();
  6970.  
  6971. const dProto = {
  6972.  
  6973.  
  6974. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  6975.  
  6976. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  6977. if (a) {
  6978. if (doDeepCopy) a = deepCopy(a);
  6979. wm37.set(endpoint, a);
  6980. } else {
  6981. wm37.remove(endpoint);
  6982. }
  6983. },
  6984. __getCachedEndpointData__: function (endpoint) {
  6985. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  6986. if (endpoint) return wm37.get(endpoint);
  6987. return null;
  6988. },
  6989. /** @type {(resolvedEndpoint: any) => void 0} */
  6990. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  6991.  
  6992. resolvedEndpoint = deepCopy(resolvedEndpoint);
  6993. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  6994. Promise.resolve(resolvedEndpoint).then(() => {
  6995. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  6996. this.showContextMenu_(resolvedEndpoint);
  6997. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  6998. });
  6999.  
  7000.  
  7001. },
  7002.  
  7003.  
  7004.  
  7005. showContextMenuForCacheReopen: function (a) {
  7006. if (!this.__showContextMenu_forceNativeRequest__) {
  7007. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7008. if (endpoint) {
  7009. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  7010. if (resolvedEndpoint) {
  7011. this.__showCachedContextMenu__(resolvedEndpoint);
  7012. a && a.stopPropagation()
  7013. return;
  7014. }
  7015. }
  7016. }
  7017. return this.showContextMenu37(a);
  7018. },
  7019.  
  7020. showContextMenuForCacheReopen_: function (a) {
  7021. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  7022. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7023. if (endpoint) {
  7024. const f = this.__cacheResolvedEndpointData__;
  7025. if (typeof f === 'function') f(endpoint, a, true);
  7026. }
  7027. }
  7028. return this.showContextMenu37_(a);
  7029. },
  7030.  
  7031. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  7032.  
  7033. showContextMenuWithDisableScroll: function (a) {
  7034.  
  7035. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7036. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  7037.  
  7038. const parentComponent = this.parentComponent;
  7039. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  7040. parentComponent.allowScroll = false;
  7041. }
  7042. }
  7043.  
  7044. return this.showContextMenu48.apply(this, arguments);
  7045.  
  7046. },
  7047.  
  7048. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  7049.  
  7050. __showContextMenu_mutex_unlock_isEmpty__: () => {
  7051. return __showContextMenu_mutex_unlock__ === null;
  7052. },
  7053.  
  7054. __showContextMenu_assign_lock__: function (p) {
  7055.  
  7056. const mutex = __showContextMenu_mutex__;
  7057.  
  7058. mutex.lockWith(unlock => {
  7059. p.then(unlock);
  7060. });
  7061.  
  7062. },
  7063.  
  7064. showContextMenuWithMutex: function (a) {
  7065. lastShowMenuTarget = this;
  7066.  
  7067. if (this.__showContextMenu_sync_mode_request__) {
  7068.  
  7069. return this.showContextMenu47(a);
  7070. } else {
  7071.  
  7072. const mutex = __showContextMenu_mutex__;
  7073.  
  7074. mutex.lockWith(unlock => {
  7075. if (lastShowMenuTarget !== this) {
  7076. unlock();
  7077. return;
  7078. }
  7079.  
  7080. setTimeout(unlock, 800); // in case network failure
  7081. __showContextMenu_mutex_unlock__ = unlock;
  7082. try {
  7083. this.showContextMenu47(a);
  7084. } catch (e) {
  7085. console.warn(e);
  7086. unlock(); // in case function script error
  7087. }
  7088.  
  7089. });
  7090.  
  7091. }
  7092.  
  7093.  
  7094. },
  7095.  
  7096. showContextMenuWithMutex_: function (a) {
  7097.  
  7098. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  7099. __showContextMenu_mutex_unlock__();
  7100. __showContextMenu_mutex_unlock__ = null;
  7101. }
  7102. return this.showContextMenu47_(a);
  7103.  
  7104. }
  7105.  
  7106. }
  7107.  
  7108. for (const tag of sTags) { // ##tag##
  7109.  
  7110.  
  7111.  
  7112. (() => {
  7113.  
  7114. const dummy = document.createElement(tag);
  7115.  
  7116. const cProto = getProto(dummy);
  7117. if (!cProto || !cProto.attached) {
  7118. console.warn(`proto.attached for ${tag} is unavailable.`);
  7119. return;
  7120. }
  7121.  
  7122.  
  7123.  
  7124.  
  7125. if (CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN && typeof cProto.showContextMenu === 'function' && typeof cProto.showContextMenu_ === 'function' && !cProto.showContextMenu37 && !cProto.showContextMenu37_ && cProto.showContextMenu.length === 1 && cProto.showContextMenu_.length === 1) {
  7126.  
  7127. cProto.showContextMenu37_ = cProto.showContextMenu_;
  7128. cProto.showContextMenu37 = cProto.showContextMenu;
  7129.  
  7130. cProto.__showContextMenu_forceNativeRequest__ = 0;
  7131. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  7132. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  7133. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  7134.  
  7135. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  7136.  
  7137. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  7138.  
  7139.  
  7140. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  7141.  
  7142.  
  7143.  
  7144. } else {
  7145.  
  7146. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  7147.  
  7148. }
  7149.  
  7150.  
  7151.  
  7152. if (ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU && typeof cProto.showContextMenu === 'function' && typeof cProto.showContextMenu_ === 'function' && !cProto.showContextMenu48 && !cProto.showContextMenu48_ && cProto.showContextMenu.length === 1 && cProto.showContextMenu_.length === 1) {
  7153.  
  7154.  
  7155. cProto.showContextMenu48 = cProto.showContextMenu;
  7156.  
  7157.  
  7158. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  7159.  
  7160.  
  7161.  
  7162. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  7163.  
  7164.  
  7165.  
  7166. } else {
  7167.  
  7168. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  7169.  
  7170. }
  7171.  
  7172.  
  7173.  
  7174.  
  7175.  
  7176. if (ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU && typeof cProto.showContextMenu === 'function' && typeof cProto.showContextMenu_ === 'function' && !cProto.showContextMenu47 && !cProto.showContextMenu47_ && cProto.showContextMenu.length === 1 && cProto.showContextMenu_.length === 1) {
  7177.  
  7178. cProto.showContextMenu47_ = cProto.showContextMenu_;
  7179. cProto.showContextMenu47 = cProto.showContextMenu;
  7180.  
  7181. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  7182. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  7183. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  7184. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  7185.  
  7186. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  7187.  
  7188.  
  7189.  
  7190. } else {
  7191.  
  7192. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  7193.  
  7194. }
  7195.  
  7196.  
  7197.  
  7198.  
  7199. })();
  7200.  
  7201. }
  7202.  
  7203.  
  7204.  
  7205. console.log("[End]");
  7206.  
  7207. console.groupEnd();
  7208.  
  7209. }).catch(console.warn);
  7210.  
  7211.  
  7212.  
  7213. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  7214.  
  7215. mightFirstCheckOnYtInit();
  7216. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  7217. console.log("[Begin]");
  7218. (() => {
  7219.  
  7220. const tag = "tp-yt-iron-dropdown";
  7221. const dummy = document.createElement(tag);
  7222.  
  7223. const cProto = getProto(dummy);
  7224. if (!cProto || !cProto.attached) {
  7225. console.warn(`proto.attached for ${tag} is unavailable.`);
  7226. return;
  7227. }
  7228.  
  7229.  
  7230. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  7231. cProto.__deraf_hn__ = function (sId, fn) {
  7232. const rhKey = `_rafHandler_${sId}`;
  7233. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  7234. if (m.has(fn)) return m.get(fn);
  7235. const resFn = () => {
  7236. this.__rafs[sId] = null;
  7237. fn.call(this)
  7238. };
  7239. m.set(fn, resFn);
  7240. m.set(resFn, resFn);
  7241. return resFn;
  7242. };
  7243. cProto.__deraf34 = cProto.__deraf;
  7244. cProto.__deraf = function (a, b) { // sId, fn
  7245. let c = this.__rafs;
  7246. null !== c[a] && cancelAnimationFrame(c[a]);
  7247. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  7248. };
  7249. console.log("USE_VANILLA_DEREF - OK");
  7250. } else {
  7251. console.log("USE_VANILLA_DEREF - NG");
  7252. }
  7253.  
  7254. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  7255. cProto.__deraf66 = cProto.__deraf;
  7256. cProto.__deraf = function (sId, fn) {
  7257. if (this.__byPassRAF__) {
  7258. Promise.resolve().then(() => {
  7259. fn.call(this);
  7260. });
  7261. }
  7262. let r = this.__deraf66.apply(this, arguments);
  7263. return r;
  7264. }
  7265. console.log("FIX_DROPDOWN_DERAF - OK");
  7266. } else {
  7267. console.log("FIX_DROPDOWN_DERAF - NG");
  7268. }
  7269.  
  7270.  
  7271. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  7272.  
  7273. let lastClose = null;
  7274. let lastOpen = null;
  7275. let cid = 0;
  7276.  
  7277. cProto.__mtChanged__ = function (b) {
  7278.  
  7279. Promise.resolve().then(() => {
  7280. this._applyFocus();
  7281. }).then(() => {
  7282. b ? this._renderOpened() : this._renderClosed();
  7283. }).catch(console.warn);
  7284.  
  7285. };
  7286.  
  7287. const __moChanged__ = () => {
  7288. if (!cid) return;
  7289. // console.log(553, !!lastOpen, !!lastClose);
  7290. cid = 0;
  7291. if (lastOpen && !lastClose && lastOpen.isAttached) {
  7292. lastOpen.__mtChanged__(1)
  7293. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  7294. lastClose.__mtChanged__(0);
  7295. }
  7296. lastOpen = null;
  7297. lastClose = null;
  7298. };
  7299.  
  7300.  
  7301. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  7302. cProto._openedChanged66 = cProto._openedChanged;
  7303. cProto._openedChanged = function () {
  7304. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  7305. this.__byPassRAF__ = true;
  7306. let r = this._openedChanged66.apply(this, arguments);
  7307. this.__byPassRAF__ = false;
  7308. return r;
  7309. }
  7310. }
  7311.  
  7312. const pSetGet = (key, pdThis, pdBase) => {
  7313. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  7314. return {
  7315. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  7316. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  7317. };
  7318. };
  7319.  
  7320. cProto.__modifiedMenuPropsFn__ = function () {
  7321. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  7322. const pdBase = Object.getOwnPropertyDescriptors(this)
  7323.  
  7324. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  7325. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  7326. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  7327.  
  7328. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  7329. console.warn('there is setter/getter for autoFitOnAttach');
  7330. return;
  7331. }
  7332. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  7333. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  7334. return;
  7335. }
  7336. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  7337. console.warn('there is NO setter-getter for allowOutsideScroll');
  7338. return;
  7339. }
  7340.  
  7341. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  7342.  
  7343. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  7344.  
  7345. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  7346.  
  7347. Object.defineProperties(this, {
  7348. autoFitOnAttach: {
  7349. get() {
  7350. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  7351. return autoFitOnAttach;
  7352. },
  7353. set(nv) {
  7354. autoFitOnAttach = nv;
  7355. return true;
  7356. },
  7357. enumerable: true,
  7358. configurable: true
  7359. }, expandSizingTargetForScrollbars: {
  7360. get() {
  7361. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  7362. return expandSizingTargetForScrollbars;
  7363. },
  7364. set(nv) {
  7365. expandSizingTargetForScrollbars = nv;
  7366. return true;
  7367. },
  7368. enumerable: true,
  7369. configurable: true
  7370. }, allowOutsideScroll: {
  7371. get() {
  7372. if (this._modifiedMenuPropOn062__) return true;
  7373. return allowOutsideScroll;
  7374. },
  7375. set(nv) {
  7376. allowOutsideScroll = nv;
  7377. this.__AllowOutsideScrollPD__.set.call(this, nv);
  7378. return true;
  7379. },
  7380. enumerable: true,
  7381. configurable: true
  7382. }
  7383. })
  7384. };
  7385.  
  7386. /*
  7387. // ***** position() to be changed. *****
  7388. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  7389.  
  7390. overflow: visible !important;
  7391. min-width: max-content !important;
  7392. max-width: max-content !important;
  7393. max-height: max-content !important;
  7394. min-height: max-content !important;
  7395. white-space: nowrap;
  7396. }
  7397.  
  7398. */
  7399. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  7400.  
  7401. let m34 = 0;
  7402. cProto.__refitByPosition__ = function () {
  7403. m34++;
  7404. if (m34 <= 0) m34 = 0;
  7405. if (m34 !== 1) return;
  7406. const hostElement = this.hostElement || this;
  7407. if (document.visibilityState === 'visible') {
  7408. const sizingTarget = this.sizingTarget;
  7409. if (!sizingTarget) {
  7410. m34 = 0;
  7411. return;
  7412. }
  7413.  
  7414. /*
  7415. let useVisibilityCollapse = true;
  7416. if (HTMLElement.prototype.querySelector.call(sizingTarget, 'yt-icon:empty')) {
  7417. useVisibilityCollapse = false;
  7418. }
  7419.  
  7420. if (useVisibilityCollapse) {
  7421. hostElement.style.visibility = 'collapse';
  7422. sizingTarget.style.visibility = 'collapse';
  7423. } else {
  7424. hostElement.setAttribute('rNgzQ', '');
  7425. sizingTarget.setAttribute('rNgzQ', '');
  7426. }
  7427. */
  7428. hostElement.setAttribute('rNgzQ', '');
  7429. sizingTarget.setAttribute('rNgzQ', '');
  7430.  
  7431. const gn = () => {
  7432. /*
  7433. if (useVisibilityCollapse) {
  7434. hostElement.style.visibility = '';
  7435. sizingTarget.style.visibility = '';
  7436. } else {
  7437. hostElement.removeAttribute('rNgzQ');
  7438. sizingTarget.removeAttribute('rNgzQ');
  7439. }
  7440. */
  7441. hostElement.removeAttribute('rNgzQ');
  7442. sizingTarget.removeAttribute('rNgzQ');
  7443. }
  7444.  
  7445. const an = async () => {
  7446. while (m34 >= 1) {
  7447. await renderReadyPn(sizingTarget);
  7448. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  7449. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  7450. }
  7451. m34--;
  7452. }
  7453. m34 = 0;
  7454. Promise.resolve().then(gn);
  7455. }
  7456. setTimeout(an, 4); // wait those resizing function calls
  7457.  
  7458.  
  7459. } else {
  7460. m34 = 0;
  7461. }
  7462. }
  7463. cProto.position34 = cProto.position
  7464. cProto.position = function () {
  7465. if (this._positionInitialize_) {
  7466. this._positionInitialize_ = 0;
  7467. this.__refitByPosition__();
  7468. }
  7469. let r = cProto.position34.apply(this, arguments);
  7470. return r;
  7471. }
  7472. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  7473.  
  7474. } else {
  7475.  
  7476. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  7477.  
  7478. }
  7479.  
  7480.  
  7481.  
  7482. cProto.__openedChanged = function () {
  7483. this._positionInitialize_ = 1;
  7484. // this.removeAttribute('horizontal-align')
  7485. // this.removeAttribute('vertical-align')
  7486. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  7487. this.__menuTypeCheck__ = true;
  7488. if (CHAT_MENU_SCROLL_UNLOCKING) {
  7489. this._modifiedMenuPropOn062__ = false;
  7490. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7491. // this.autoFitOnAttach = true;
  7492. // this.expandSizingTargetForScrollbars = true;
  7493. // this.allowOutsideScroll = true;
  7494. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  7495. this.__modifiedMenuPropsFn__();
  7496. // this.constrain= function(){}
  7497. // this.position= function(){}
  7498.  
  7499. // this.autoFitOnAttach = true;
  7500. // this.expandSizingTargetForScrollbars = true;
  7501. // this.allowOutsideScroll = true;
  7502. }
  7503. }
  7504. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  7505. let newValue = null;
  7506. const positionTarget = this.positionTarget;
  7507. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  7508. if (this._modifiedMenuPropOn062__ === false) {
  7509. newValue = true;
  7510. }
  7511. } else if (this._modifiedMenuPropOn062__ === true) {
  7512. newValue = false;
  7513. }
  7514. if (newValue !== null) {
  7515. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  7516. this._modifiedMenuPropOn062__ = newValue;
  7517. const afterAllowOutsideScroll = this.allowOutsideScroll;
  7518. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  7519. }
  7520. }
  7521.  
  7522. if (this.opened) {
  7523.  
  7524. Promise.resolve().then(() => {
  7525.  
  7526. this._prepareRenderOpened();
  7527. }).then(() => {
  7528. this._manager.addOverlay(this);
  7529. if (this._manager._overlays.length === 1) {
  7530. lastOpen = this;
  7531. lastClose = null;
  7532. } else {
  7533. return 1;
  7534. }
  7535. // if (cid) {
  7536. // clearTimeout(cid);
  7537. // cid = -1;
  7538. // this.__moChanged__();
  7539. // cid = 0;
  7540. // } else {
  7541. // cid = -1;
  7542. // this.__moChanged__();
  7543. // cid = 0;
  7544. // }
  7545. // cid = cid > 0 ? clearTimeout(cid) : 0;
  7546. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7547. // cid = cid || setTimeout(__moChanged__, delay1);
  7548. cid = cid || requestAnimationFrame(__moChanged__);
  7549. }).then((r) => {
  7550.  
  7551. if (r) this.__mtChanged__(1);
  7552. }).catch(console.warn);
  7553.  
  7554. } else {
  7555. Promise.resolve().then(() => {
  7556. this._manager.removeOverlay(this);
  7557. if (this._manager._overlays.length === 0) {
  7558. lastClose = this;
  7559. lastOpen = null;
  7560. } else {
  7561. return 1;
  7562. }
  7563. // cid = cid > 0 ? clearTimeout(cid) : 0;
  7564. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7565. // cid = cid || setTimeout(__moChanged__, delay1);
  7566. cid = cid || requestAnimationFrame(__moChanged__);
  7567. }).then((r) => {
  7568. if (r) this.__mtChanged__(0);
  7569. }).catch(console.warn);
  7570.  
  7571. }
  7572.  
  7573. }
  7574. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  7575.  
  7576. } else {
  7577.  
  7578. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  7579. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  7580.  
  7581. }
  7582.  
  7583.  
  7584. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  7585.  
  7586. cProto.__openedChanged82 = cProto.__openedChanged;
  7587.  
  7588.  
  7589. cProto.__openedChanged = function () {
  7590.  
  7591. // currentMenuPivotWR = null;
  7592. // console.log(1480, '__openedChanged.A', this.positionTarget)
  7593.  
  7594.  
  7595.  
  7596. // if (this.opened && this.positionTarget) {
  7597.  
  7598. // const positionTarget = this.positionTarget;
  7599. // console.log(1480, '__openedChanged.B', positionTarget)
  7600. // currentMenuPivotWR = mWeakRef(positionTarget);
  7601.  
  7602. // }
  7603.  
  7604. const positionTarget = this.positionTarget;
  7605. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  7606. return this.__openedChanged82.apply(this, arguments);
  7607. }
  7608. }
  7609.  
  7610.  
  7611. // if(FIX_MENU_CAPTURE_SCROLL && typeof cProto.__onCaptureScroll === 'function' && !cProto.__onCaptureScroll66){
  7612.  
  7613. // cProto.__onCaptureScroll66 = cProto.__onCaptureScroll;
  7614.  
  7615. // cProto.__onCaptureScroll = function(a){
  7616.  
  7617. // const q = true;
  7618. // if(this.scrollAction === 'lock' && q && this.opened){
  7619.  
  7620. // // console.log(9107, this.scrollAction, this.__isAnimating, this.opened, a); // lock; __isAnimating = false
  7621. // async function af() {
  7622. // this.__isAnimating && this._finishRenderOpened();
  7623. // if (!this.opened) return;
  7624. // this.__restoreScrollPosition();
  7625. // await new Promise(r => requestAnimationFrame(r));
  7626. // if (!this.opened) return;
  7627. // this.opened && this.__isAnimating && this._finishRenderOpened();
  7628. // if (!this.opened) return;
  7629. // this.__restoreScrollPosition();
  7630. // await new Promise(r => requestAnimationFrame(r));
  7631. // if (!this.opened) return;
  7632. // this.opened && this.__isAnimating && this._finishRenderOpened();
  7633. // if (!this.opened) return;
  7634. // this.opened && !this.__isAnimating && this.refit();
  7635. // }
  7636. // Promise.resolve().then(af);
  7637.  
  7638. // return cProto.__onCaptureScroll66.apply(this, arguments);
  7639. // }else{
  7640.  
  7641. // // console.log(9102, this.scrollAction, this.__isAnimating, this.opened, a); // lock
  7642.  
  7643. // return cProto.__onCaptureScroll66.apply(this, arguments);
  7644. // }
  7645. // }
  7646. // console.log("FIX_MENU_CAPTURE_SCROLL - OK");
  7647. // }else{
  7648. // console.log("FIX_MENU_CAPTURE_SCROLL - NG");
  7649.  
  7650. // }
  7651.  
  7652.  
  7653. })();
  7654.  
  7655. console.log("[End]");
  7656.  
  7657. console.groupEnd();
  7658.  
  7659. }).catch(console.warn);
  7660.  
  7661.  
  7662.  
  7663.  
  7664.  
  7665.  
  7666.  
  7667.  
  7668. /*
  7669.  
  7670.  
  7671.  
  7672.  
  7673.  
  7674. var FU = function() {
  7675. var a = this;
  7676. this.nextHandle_ = 1;
  7677. this.clients_ = {};
  7678. this.JSC$10323_callbacks_ = {};
  7679. this.unsubscribeAsyncHandles_ = {};
  7680. this.subscribe = vl(function(b, c, d) {
  7681. var e = Geb(b);
  7682. if (e in a.clients_)
  7683. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  7684. else {
  7685. a: {
  7686. var h = Geb(b), l;
  7687. for (l in a.unsubscribeAsyncHandles_) {
  7688. var m = a.clients_[l];
  7689. if (m instanceof KO) {
  7690. delete a.clients_[l];
  7691. delete a.JSC$10323_callbacks_[l];
  7692. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  7693. delete a.unsubscribeAsyncHandles_[l];
  7694. i6a(m);
  7695. m.objectId_ = new FQa(h);
  7696. m.register();
  7697. d = m;
  7698. break a
  7699. }
  7700. }
  7701. d.objectSource = b.invalidationId.objectSource;
  7702. d.objectId = h;
  7703. if (b = b.webAuthConfigurationData)
  7704. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  7705. b.pageId && (d.pageId = b.pageId);
  7706. d = new KO(d,a.handleInvalidationData_.bind(a));
  7707. d.register()
  7708. }
  7709. a.clients_[e] = d;
  7710. a.JSC$10323_callbacks_[e] = {}
  7711. }
  7712. d = a.nextHandle_++;
  7713. a.JSC$10323_callbacks_[e][d] = c;
  7714. return d
  7715. })
  7716. };
  7717. FU.prototype.unsubscribe = function(a, b) {
  7718. var c = Geb(a);
  7719. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  7720. !this.JSC$10323_callbacks_[c].length)) {
  7721. var d = this.clients_[c];
  7722. b = Jq.run(function() {
  7723. ei(d);
  7724. delete this.clients_[c];
  7725. delete this.unsubscribeAsyncHandles_[c]
  7726. }
  7727. .bind(this));
  7728. this.unsubscribeAsyncHandles_[c] = b
  7729. }
  7730. }
  7731. ;
  7732.  
  7733.  
  7734. */
  7735.  
  7736.  
  7737.  
  7738.  
  7739. const onManagerFound = (dummyManager) => {
  7740. if (!dummyManager || typeof dummyManager !== 'object') return;
  7741.  
  7742. const mgrProto = dummyManager.constructor.prototype;
  7743.  
  7744. let keyCallbackStore = '';
  7745. for (const [key, v] of Object.entries(dummyManager)) {
  7746. if (key.includes('_callbacks_')) keyCallbackStore = key;
  7747. }
  7748.  
  7749. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  7750.  
  7751. if (mgrProto.unsubscribe16) return;
  7752.  
  7753. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  7754.  
  7755. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  7756. console.log("[Begin]");
  7757.  
  7758.  
  7759. // const isEmptyObject = (a) => Object.keys(a).length === 0;
  7760. const isEmptyObject = ((obj) => (firstKey(obj) === null));
  7761.  
  7762. const idMapper = new Map();
  7763.  
  7764. const convertId = function (objectId) {
  7765. if (!objectId || typeof objectId !== 'string') return null;
  7766.  
  7767. let result = idMapper.get(objectId)
  7768. if (result) return result;
  7769. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  7770. idMapper.set(objectId, result)
  7771. return result;
  7772. }
  7773.  
  7774.  
  7775. const rafHandleHolder = [];
  7776.  
  7777. let pzw = 0;
  7778. let lza = 0;
  7779. const rafHandlerFn = () => {
  7780. pzw = 0;
  7781. if (rafHandleHolder.length === 1) {
  7782. const f = rafHandleHolder[0];
  7783. rafHandleHolder.length = 0;
  7784. f();
  7785. } else if (rafHandleHolder.length > 1) {
  7786. const arr = rafHandleHolder.slice(0);
  7787. rafHandleHolder.length = 0;
  7788. for (const fn of arr) fn();
  7789. }
  7790. };
  7791.  
  7792.  
  7793. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  7794.  
  7795. const checkIntegrityForSubscribe = (mgr) => {
  7796. if (mgr
  7797. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  7798. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  7799.  
  7800. const ns = new Set(Object.keys(mgr));
  7801. const ms = new Set(Object.keys(mgr.constructor.prototype));
  7802.  
  7803. if (ns.size >= 6 && ms.size >= 4) {
  7804. // including 'subscribe18'
  7805. // 'unsubscribe16', 'subscribe19'
  7806.  
  7807. let r = 0;
  7808. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  7809. r += ns.has(k) ? 1 : 0;
  7810. }
  7811. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  7812. r += ms.has(k) ? 1 : 0;
  7813. }
  7814. if (r === 10) {
  7815. const isObject = (c) => (c || 0).constructor === Object;
  7816.  
  7817. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  7818.  
  7819. return true;
  7820. }
  7821.  
  7822.  
  7823. }
  7824.  
  7825. }
  7826.  
  7827.  
  7828. }
  7829. return false;
  7830. }
  7831.  
  7832. mgrProto.subscribe19 = function (o, f, opts) {
  7833.  
  7834. const ct_clients_ = this.clients_ || 0;
  7835. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  7836.  
  7837. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  7838.  
  7839. let objectId = ((o || 0).invalidationId || 0).objectId;
  7840. if (!objectId) return this.subscribe18.apply(this, arguments);
  7841. objectId = convertId(objectId);
  7842.  
  7843. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  7844.  
  7845. if (ct_clients_[objectId]) {
  7846. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  7847. }
  7848.  
  7849. return this.subscribe18.apply(this, arguments);
  7850. }
  7851.  
  7852. mgrProto.unsubscribe = function (o, d) {
  7853. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  7854. this.subscribe18 = this.subscribe;
  7855. this.subscribe = this.subscribe19;
  7856. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  7857. }
  7858. const ct_clients_ = this.clients_;
  7859. const ct_handles_ = this.unsubscribeAsyncHandles_;
  7860. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  7861.  
  7862. let objectId = ((o || 0).invalidationId || 0).objectId;
  7863. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  7864.  
  7865. objectId = convertId(objectId);
  7866.  
  7867.  
  7868. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  7869.  
  7870. const callbacks = this[keyCallbackStore] || 0;
  7871. const callbackObj = callbacks[objectId] || 0;
  7872.  
  7873.  
  7874. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  7875. const w = ct_clients_[objectId];
  7876. --lza;
  7877. if (lza < -1e9) lza = -1;
  7878. const qta = lza;
  7879. rafHandleHolder.push(() => {
  7880. if (qta === ct_handles_[objectId]) {
  7881. const o = {
  7882. callbacks, callbackObj,
  7883. client: ct_clients_[objectId],
  7884. handle: ct_handles_[objectId]
  7885. };
  7886. let p = 0;
  7887. try {
  7888. if (ct_clients_[objectId] === w) {
  7889. w && "function" === typeof w.dispose && w.dispose();
  7890. delete ct_clients_[objectId];
  7891. delete ct_handles_[objectId];
  7892. p = 1;
  7893. } else {
  7894. // w && "function" === typeof w.dispose && w.dispose();
  7895. // delete ct_clients_[objectId];
  7896. // delete ct_handles_[objectId];
  7897. p = 2;
  7898. }
  7899. } catch (e) {
  7900. console.warn(e);
  7901. }
  7902. console.log(`unsubscribed: ${p}`, this, o);
  7903. }
  7904. });
  7905. ct_handles_[objectId] = qta;
  7906. if (pzw === 0) {
  7907. pzw = requestAnimationFrame(rafHandlerFn);
  7908. }
  7909. }
  7910. }
  7911.  
  7912.  
  7913. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  7914.  
  7915. } else {
  7916.  
  7917. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  7918. }
  7919.  
  7920. console.log("[End]");
  7921.  
  7922. console.groupEnd();
  7923.  
  7924. }
  7925.  
  7926.  
  7927.  
  7928. /*
  7929.  
  7930.  
  7931. a.prototype.async = function(e, h) {
  7932. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  7933. }
  7934. ;
  7935. a.prototype.cancelAsync = function(e) {
  7936. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  7937. }
  7938.  
  7939. */
  7940.  
  7941.  
  7942.  
  7943. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  7944.  
  7945. let __dummyManager__ = null;
  7946.  
  7947. mightFirstCheckOnYtInit();
  7948. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  7949. console.log("[Begin]");
  7950. (() => {
  7951.  
  7952. const tag = "yt-invalidation-continuation"
  7953. const dummy = document.createElement(tag);
  7954.  
  7955. const cProto = getProto(dummy);
  7956. if (!cProto || !cProto.attached) {
  7957. console.warn(`proto.attached for ${tag} is unavailable.`);
  7958. return;
  7959. }
  7960.  
  7961. const dummyManager = insp(dummy).manager_ || 0;
  7962. __dummyManager__ = dummyManager;
  7963.  
  7964. if (CHANGE_DATA_FLUSH_ASYNC && typeof cProto.async === 'function' && !cProto.async71 && cProto.async.length === 2 && typeof cProto.cancelAsync === 'function' && !cProto.cancelAsync71 && cProto.cancelAsync.length === 1) {
  7965.  
  7966.  
  7967. const rafHub = new RAFHub();
  7968.  
  7969. rafHub.keepRAF = true;
  7970. cProto.async71 = cProto.async;
  7971. cProto.cancelAsync71 = cProto.cancelAsync;
  7972.  
  7973. // mostly for subscription timeoutMs 10000ms
  7974. let mcw = 1; // 1, 3, 5, ...
  7975. let arr = new Map();
  7976.  
  7977. let __asyncInited__ = 0;
  7978. let __timeoutStartId__ = null;
  7979. const __asyncInit__ = () => {
  7980.  
  7981. if (__asyncInited__) return;
  7982. __asyncInited__ = 1;
  7983.  
  7984. __timeoutStartId__ = setTimeout(() => { });
  7985. mcw = __timeoutStartId__ * 2 + 1;
  7986.  
  7987. setInterval(() => {
  7988.  
  7989. if (!arr.length) return;
  7990.  
  7991. const p = Date.now();
  7992. let deleteKeys = [];
  7993. arr.forEach((entry, key) => {
  7994.  
  7995.  
  7996. if (entry.cid === -1) {
  7997. entry.cid = -2;
  7998. } else if (entry.cid === -2) {
  7999.  
  8000. let offset = p - entry.add
  8001. if (offset < 0) offset = 0;
  8002. let delay2 = entry.delay - offset;
  8003. if (delay2 < 0) delay2 = 0;
  8004. entry.cid = setTimeout(entry.q(), delay2);
  8005. entry.q = null;
  8006.  
  8007. } else if (entry.add + entry.delay < p) {
  8008. deleteKeys.push(key);
  8009.  
  8010. }
  8011.  
  8012. })
  8013.  
  8014. for (const key of deleteKeys) arr.delete(key);
  8015.  
  8016. }, 2000)
  8017.  
  8018. }
  8019.  
  8020.  
  8021.  
  8022.  
  8023. cProto.async = function (e, h) {
  8024.  
  8025. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  8026.  
  8027. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  8028.  
  8029. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  8030.  
  8031.  
  8032. if (!this.__asyncInited__) {
  8033. this.__asyncInited__ = 1;
  8034. __asyncInit__();
  8035. }
  8036. mcw += 2; // 2K+3, 2K+4, ...
  8037. if (mcw > 1e9) mcw = mcw % 1e4;
  8038. const cid = mcw;
  8039. const q = () => {
  8040. return () => {
  8041. console.log('async h > 8000');
  8042. e.call(this);
  8043. }
  8044. }
  8045. // setTimeout(q, delay)
  8046. arr.set(cid, {
  8047. cid: -1, // -1 -> -2 -> cid
  8048. add: Date.now(),
  8049. q,
  8050. delay: h
  8051. });
  8052. // console.log('cid-async', cid)
  8053. return cid;
  8054.  
  8055. }
  8056.  
  8057.  
  8058. cProto.cancelAsync = function (e) {
  8059.  
  8060. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  8061.  
  8062. // console.log('cid-unasync', e)
  8063.  
  8064. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  8065.  
  8066. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  8067.  
  8068. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  8069.  
  8070. if (!arr.has(e)) return; // duplciated cancel
  8071.  
  8072. const entry = arr.get(e);
  8073. if (entry.cid < 0) {
  8074. entry.cid = 0;
  8075. arr.delete(e);
  8076. } else {
  8077. clearTimeout(entry.cid); // cid >= 1
  8078. entry.cid = 0;
  8079. arr.delete(e);
  8080. }
  8081.  
  8082. } else {
  8083.  
  8084. return this.cancelAsync71(e);
  8085.  
  8086. }
  8087.  
  8088. }
  8089.  
  8090. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  8091.  
  8092. } else {
  8093. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  8094.  
  8095. }
  8096.  
  8097. })();
  8098.  
  8099. console.log("[End]");
  8100.  
  8101. console.groupEnd();
  8102.  
  8103.  
  8104.  
  8105. onManagerFound(__dummyManager__);
  8106.  
  8107. }).catch(console.warn);
  8108.  
  8109.  
  8110.  
  8111.  
  8112. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  8113.  
  8114.  
  8115. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  8116.  
  8117.  
  8118. mightFirstCheckOnYtInit();
  8119. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  8120. console.log("[Begin]");
  8121. (() => {
  8122.  
  8123. const tag = "yt-live-interactivity-component-background"
  8124. const dummy = document.createElement(tag);
  8125.  
  8126. const cProto = getProto(dummy);
  8127. if (!cProto || !cProto.attached) {
  8128. console.warn(`proto.attached for ${tag} is unavailable.`);
  8129. return;
  8130. }
  8131.  
  8132.  
  8133. cProto.__toStopAfterRun__ = function (hostElement) {
  8134. let mo = new MutationObserver(() => {
  8135. mo.disconnect();
  8136. mo.takeRecords();
  8137. mo = null;
  8138. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  8139. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  8140. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  8141. });
  8142. });
  8143. mo.observe(hostElement, { subtree: true, childList: true });
  8144. }
  8145.  
  8146. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  8147.  
  8148. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  8149. cProto.maybeLoadAnimationBackground = function () {
  8150. let toRun = true;
  8151. let stopAfterRun = false;
  8152. if (!this.__bypassDisableAnimationBackground__) {
  8153. let doFix = false;
  8154. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  8155. if (!this.lottieAnimation) {
  8156. doFix = true;
  8157. }
  8158. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  8159. doFix = true;
  8160. }
  8161. if (doFix) {
  8162. if (this.useAnimationBackground === true) {
  8163. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  8164. }
  8165. toRun = true;
  8166. stopAfterRun = true;
  8167. }
  8168. }
  8169. if (toRun) {
  8170. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  8171. this.__toStopAfterRun__(this.hostElement); // primary
  8172. }
  8173. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  8174. if (stopAfterRun && this.lottieAnimation) {
  8175. this.lottieAnimation.stop(); // fallback if no mutation
  8176. }
  8177. return r;
  8178. }
  8179. }
  8180.  
  8181. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION${INTERACTIVITY_BACKGROUND_ANIMATION} - OK`);
  8182.  
  8183. } else {
  8184. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION${INTERACTIVITY_BACKGROUND_ANIMATION} - NG`);
  8185.  
  8186. }
  8187.  
  8188. })();
  8189.  
  8190. console.log("[End]");
  8191.  
  8192. console.groupEnd();
  8193.  
  8194.  
  8195. }).catch(console.warn);
  8196.  
  8197. }
  8198.  
  8199.  
  8200. }
  8201.  
  8202.  
  8203.  
  8204.  
  8205. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  8206.  
  8207. const fixJsonParse = () => {
  8208.  
  8209. let p1 = window.onerror;
  8210.  
  8211. try {
  8212. JSON.parse("{}");
  8213. } catch (e) {
  8214. console.warn(e);
  8215. }
  8216.  
  8217. let p2 = window.onerror;
  8218.  
  8219. if (p1 !== p2) {
  8220.  
  8221.  
  8222. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  8223. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  8224. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  8225. );
  8226.  
  8227. console.warn("\nJSON.parse is hacked (e.g. Brave's script injection) which causes window.onerror changes on every JSON.parse call.\nPlease install https://greasyfork.org/scripts/473972-youtube-js-engine-tamer to fix the issue.\n");
  8228.  
  8229. console.groupEnd();
  8230.  
  8231. }
  8232.  
  8233. }
  8234.  
  8235. if (CHECK_JSONPRUNE) {
  8236. promiseForCustomYtElementsReady.then(fixJsonParse);
  8237. }
  8238.  
  8239. });
  8240.  
  8241.  
  8242.  
  8243. })({ IntersectionObserver });