YouTube 超快聊天

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

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

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