YouTube 超快聊天

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

目前为 2023-10-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.60.17
  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 items = (tickerRenderer.$ || 0).items || 0;
  3103. if (!items) return;
  3104. const template = document.createElement('template');
  3105. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  3106. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  3107. dimmed="" [dummy777]>
  3108. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  3109. 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));">
  3110. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  3111. <yt-img-shadow777 id="author-photo" height="24" width="24"
  3112. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  3113. style="background-color: transparent;" loaded=""><img id="img"
  3114. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  3115. src="${dummyImgURL}"></yt-img-shadow777>
  3116.  
  3117. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  3118. </div>
  3119. </div>
  3120. </yt-live-chat-ticker-dummy777-item-renderer>`;
  3121. const dummy777 = template.content.firstElementChild;
  3122. items.appendChild(dummy777);
  3123. Promise.resolve(dummy777).then((dummy777) => {
  3124. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  3125. if (container.isConnected === true) {
  3126.  
  3127. const evaluated = `${getComputedStyle(container).background}`;
  3128.  
  3129. container = null;
  3130. dummy777.remove();
  3131. dummy777.textContent = '';
  3132. dummy777 = null;
  3133.  
  3134. if (evaluated.indexOf('0.') < 4) {
  3135.  
  3136. // not fulfilling
  3137. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3138.  
  3139. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3140. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3141. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3142. );
  3143. 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');
  3144. console.groupEnd();
  3145.  
  3146. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  3147.  
  3148. } else {
  3149.  
  3150. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3151. }
  3152. }
  3153. });
  3154.  
  3155. }, 800);
  3156. }
  3157.  
  3158. }
  3159. }
  3160.  
  3161. return { setupMutObserver };
  3162.  
  3163.  
  3164.  
  3165. })();
  3166.  
  3167. const setupEvents = () => {
  3168.  
  3169.  
  3170. let scrollCount = 0;
  3171.  
  3172. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  3173.  
  3174.  
  3175. const delayFlushActiveItemsAfterUserActionK_ = () => {
  3176.  
  3177. const lcRenderer = lcRendererElm();
  3178. if (lcRenderer) {
  3179. const cnt = (lcRenderer.inst || lcRenderer);
  3180. if (!cnt.hasUserJustInteracted11_) return;
  3181. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  3182. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  3183. }
  3184. }
  3185.  
  3186. }
  3187.  
  3188. document.addEventListener('scroll', (evt) => {
  3189. if (!evt || !evt.isTrusted) return;
  3190. // lastScroll = dateNow();
  3191. if (++scrollCount > 1e9) scrollCount = 9;
  3192. }, passiveCapture); // support contain => support passive
  3193.  
  3194. let lastScrollCount = -1;
  3195. document.addEventListener('wheel', (evt) => {
  3196. if (!evt || !evt.isTrusted) return;
  3197. if (lastScrollCount === scrollCount) return;
  3198. lastScrollCount = scrollCount;
  3199. lastWheel = dateNow();
  3200. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3201. }, passiveCapture); // support contain => support passive
  3202.  
  3203. document.addEventListener('mousedown', (evt) => {
  3204. if (!evt || !evt.isTrusted) return;
  3205. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3206. lastMouseDown = dateNow();
  3207. currentMouseDown = true;
  3208. lastUserInteraction = lastMouseDown;
  3209. }, passiveCapture);
  3210.  
  3211. document.addEventListener('pointerdown', (evt) => {
  3212. if (!evt || !evt.isTrusted) return;
  3213. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3214. lastMouseDown = dateNow();
  3215. currentMouseDown = true;
  3216. lastUserInteraction = lastMouseDown;
  3217. }, passiveCapture);
  3218.  
  3219. document.addEventListener('click', (evt) => {
  3220. if (!evt || !evt.isTrusted) return;
  3221. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3222. lastMouseDown = lastMouseUp = dateNow();
  3223. currentMouseDown = false;
  3224. lastUserInteraction = lastMouseDown;
  3225. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3226. }, passiveCapture);
  3227.  
  3228. document.addEventListener('tap', (evt) => {
  3229. if (!evt || !evt.isTrusted) return;
  3230. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3231. lastMouseDown = lastMouseUp = dateNow();
  3232. currentMouseDown = false;
  3233. lastUserInteraction = lastMouseDown;
  3234. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3235. }, passiveCapture);
  3236.  
  3237.  
  3238. document.addEventListener('mouseup', (evt) => {
  3239. if (!evt || !evt.isTrusted) return;
  3240. if (currentMouseDown) {
  3241. lastMouseUp = dateNow();
  3242. currentMouseDown = false;
  3243. lastUserInteraction = lastMouseUp;
  3244. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3245. }
  3246. }, passiveCapture);
  3247.  
  3248.  
  3249. document.addEventListener('pointerup', (evt) => {
  3250. if (!evt || !evt.isTrusted) return;
  3251. if (currentMouseDown) {
  3252. lastMouseUp = dateNow();
  3253. currentMouseDown = false;
  3254. lastUserInteraction = lastMouseUp;
  3255. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3256. }
  3257. }, passiveCapture);
  3258.  
  3259. document.addEventListener('touchstart', (evt) => {
  3260. if (!evt || !evt.isTrusted) return;
  3261. lastTouchDown = dateNow();
  3262. currentTouchDown = true;
  3263. lastUserInteraction = lastTouchDown;
  3264. }, passiveCapture);
  3265.  
  3266. document.addEventListener('touchmove', (evt) => {
  3267. if (!evt || !evt.isTrusted) return;
  3268. lastTouchDown = dateNow();
  3269. currentTouchDown = true;
  3270. lastUserInteraction = lastTouchDown;
  3271. }, passiveCapture);
  3272.  
  3273. document.addEventListener('touchend', (evt) => {
  3274. if (!evt || !evt.isTrusted) return;
  3275. if (currentTouchDown) {
  3276. lastTouchUp = dateNow();
  3277. currentTouchDown = false;
  3278. lastUserInteraction = lastTouchUp;
  3279. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3280. }
  3281. }, passiveCapture);
  3282.  
  3283. document.addEventListener('touchcancel', (evt) => {
  3284. if (!evt || !evt.isTrusted) return;
  3285. if (currentTouchDown) {
  3286. lastTouchUp = dateNow();
  3287. currentTouchDown = false;
  3288. lastUserInteraction = lastTouchUp;
  3289. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3290. }
  3291. }, passiveCapture);
  3292.  
  3293.  
  3294. }
  3295.  
  3296. const getTimestampUsec = (itemRenderer) => {
  3297. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  3298. return itemRenderer.timestampUsec
  3299. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  3300. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  3301. if (messageRenderer) {
  3302.  
  3303. const messageRendererKey = firstObjectKey(messageRenderer);
  3304. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  3305. const messageRendererData = messageRenderer[messageRendererKey];
  3306. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  3307. return messageRendererData.timestampUsec
  3308. }
  3309. }
  3310. }
  3311. }
  3312. return null;
  3313. }
  3314.  
  3315. const onRegistryReadyForDOMOperations = () => {
  3316.  
  3317. let firstCheckedOnYtInit = false;
  3318.  
  3319. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  3320.  
  3321. const mightFirstCheckOnYtInit = () => {
  3322. if (firstCheckedOnYtInit) return;
  3323. firstCheckedOnYtInit = true;
  3324.  
  3325. if (!document.body || !document.head) return;
  3326. if (!assertorURL()) return;
  3327.  
  3328. addCssManaged();
  3329.  
  3330. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  3331. if (efsContainer && efsContainer.parentNode !== document.body) {
  3332. document.body.appendChild(efsContainer);
  3333. }
  3334.  
  3335. };
  3336.  
  3337. if (!assertorURL()) return;
  3338. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  3339.  
  3340. if (document.documentElement && document.head) {
  3341. addCssManaged();
  3342. }
  3343. // console.log(document.body===null)
  3344.  
  3345. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  3346. getLCRDummy().then(async (lcrDummy) => {
  3347.  
  3348. const tag = "yt-live-chat-renderer"
  3349. const dummy = lcrDummy;
  3350.  
  3351. const cProto = getProto(dummy);
  3352. if (!cProto || !cProto.attached) {
  3353. console.warn(`proto.attached for ${tag} is unavailable.`);
  3354. return;
  3355. }
  3356.  
  3357. mightFirstCheckOnYtInit();
  3358. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  3359. console.log("[Begin]");
  3360.  
  3361.  
  3362.  
  3363.  
  3364.  
  3365.  
  3366. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  3367.  
  3368. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  3369.  
  3370. const pop078 = function () {
  3371. const r = this.pop78();
  3372.  
  3373. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  3374. for (const action of r.actions) {
  3375.  
  3376. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  3377. if (itemActionKey) {
  3378.  
  3379. const itemAction = action[itemActionKey];
  3380. const item = (itemAction || 0).item;
  3381. if (typeof item === 'object') {
  3382.  
  3383. const rendererKey = firstObjectKey(item);
  3384. if (rendererKey) {
  3385. const renderer = item[rendererKey];
  3386. if (renderer && typeof renderer === 'object') {
  3387. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  3388. renderer.__progressAt__ = playerProgressChangedArg1;
  3389. }
  3390.  
  3391. }
  3392.  
  3393. }
  3394. }
  3395. }
  3396. }
  3397. return r;
  3398. }
  3399.  
  3400. cProto.playerProgressChanged_ = function (a, b, c) {
  3401. playerProgressChangedArg1 = a;
  3402. playerProgressChangedArg2 = b;
  3403. playerProgressChangedArg3 = c;
  3404. const replayBuffer_ = this.replayBuffer_;
  3405. if (replayBuffer_) {
  3406. const replayQueue = replayBuffer_.replayQueue
  3407. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  3408.  
  3409. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, {
  3410. get(target, prop, receiver) {
  3411. if (prop === 'qe3') return 1;
  3412. const v = target[prop];
  3413. if (prop === 'front_') {
  3414. if (v && typeof v.length === 'number') {
  3415. if (!v.pop78) {
  3416. v.pop78 = v.pop;
  3417. v.pop = pop078;
  3418. }
  3419. }
  3420. }
  3421. return v;
  3422. }
  3423. });
  3424.  
  3425. }
  3426. }
  3427. return this.playerProgressChanged32_.apply(this, arguments);
  3428. };
  3429.  
  3430. }
  3431.  
  3432. // if (typeof cProto.immediatelyApplyLiveChatActions === 'function' && !cProto.immediatelyApplyLiveChatActions32) {
  3433.  
  3434. // cProto.immediatelyApplyLiveChatActions32 = cProto.immediatelyApplyLiveChatActions;
  3435.  
  3436. // cProto.immediatelyApplyLiveChatActions = function (a) {
  3437. // // if (a.length > 8) {
  3438. // // console.log(a)
  3439. // // }
  3440. // // console.log(a)
  3441. // /*
  3442. // let arr=a.slice();
  3443.  
  3444. // if(arr.length >= 2){
  3445. // arr.sort((a, b)=>{
  3446. // let ak = firstObjectKey(a);
  3447. // let bk = firstObjectKey(b);
  3448. // if(!ak||!bk) return 0;
  3449. // const ax = +a[ak]._timestampUsec57;
  3450. // const bx = +b[bk]._timestampUsec57;
  3451. // if(ax >0 && bx >0){
  3452. // const c = bx - ax ;
  3453.  
  3454. // return c > 0.1 ? -1 : c< -0.1 ? 1 : 0;
  3455. // }
  3456. // return 0;
  3457.  
  3458. // });
  3459. // console.log('sort', JSON.parse(JSON.stringify(arr)));
  3460. // }
  3461. // a=arr;
  3462. // */
  3463.  
  3464. // if (a && typeof a === 'object' && a.length >= 1) {
  3465. // const d = Date.now();
  3466. // const m = [];
  3467. // for (let i = 0, l = a.length; i < l; i++) {
  3468. // const action = a[i];
  3469. // const key = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  3470. // if (key === 'addChatItemAction' || key === 'addLiveChatTickerItemAction') {
  3471. // const itemAction = action[key] || 0;
  3472. // const item = itemAction.item || 0;
  3473. // if (item && typeof item === 'object') {
  3474. // let rendererKey = firstObjectKey(item);
  3475. // const renderer = item[rendererKey];
  3476. // let timestampUsec = getTimestampUsec(renderer);
  3477. // if (timestampUsec !== null) {
  3478. // renderer._timestampUsec57 = timestampUsec;
  3479. // }
  3480. // m.push(renderer);
  3481. // // if(timestampUsec!==null){
  3482. // // if(key==='addLiveChatTickerItemAction')console.log(renderer, rendererKey, key)
  3483. // // m.push(renderer);
  3484.  
  3485. // // }
  3486. // }
  3487. // }
  3488. // }
  3489. // if (m.length >= 1) {
  3490.  
  3491. // let lastUsec = null;
  3492. // for (let i = 0, l = m.length; i < l; i++) {
  3493. // const renderer = m[i];
  3494. // if ('_timestampUsec57' in renderer) {
  3495. // lastUsec = +renderer._timestampUsec57 / 1E3;
  3496. // renderer.__lcrTime__ = d;
  3497. // renderer.__actionAt__ = d;
  3498. // }
  3499. // }
  3500.  
  3501.  
  3502. // if (lastUsec !== null) {
  3503.  
  3504. // const refUsec = lastUsec
  3505.  
  3506. // let prevUsec = null;
  3507. // for (let i = 0, l = m.length; i < l; i++) {
  3508. // const renderer = m[i];
  3509. // if ('_timestampUsec57' in renderer) {
  3510.  
  3511. // let actualTime = +renderer._timestampUsec57 / 1E3; // ms
  3512. // let lcrTime = d - Math.round(refUsec - actualTime); // ms
  3513.  
  3514. // renderer.__lcrTime__ = lcrTime; // ms
  3515. // renderer.__actionAt__ = d;
  3516.  
  3517. // prevUsec = lcrTime
  3518. // } else {
  3519.  
  3520. // renderer._prevUsec57 = prevUsec;
  3521. // }
  3522. // }
  3523.  
  3524.  
  3525. // let nextUsec = null;
  3526. // for (let i = m.length - 1; i >= 0; i--) {
  3527. // const renderer = m[i];
  3528. // if ('_timestampUsec57' in renderer) {
  3529.  
  3530. // nextUsec = renderer.__lcrTime__
  3531. // } else {
  3532.  
  3533. // renderer._nextUsec57 = nextUsec;
  3534.  
  3535. // if (renderer._nextUsec57 > 0 && renderer._prevUsec57 > 0 && renderer._nextUsec57 > renderer._prevUsec57) {
  3536. // renderer.__lcrTime__ = (renderer._nextUsec57 + renderer._prevUsec57) / 2;
  3537. // renderer.__actionAt__ = d;
  3538. // }
  3539. // }
  3540. // }
  3541.  
  3542.  
  3543. // }
  3544.  
  3545.  
  3546. // }
  3547. // }
  3548. // return this.immediatelyApplyLiveChatActions32.apply(this, arguments)
  3549. // }
  3550.  
  3551.  
  3552. // }
  3553.  
  3554.  
  3555.  
  3556. console.log("[End]");
  3557. console.groupEnd();
  3558.  
  3559.  
  3560. });
  3561.  
  3562. }
  3563.  
  3564. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  3565.  
  3566. const tag = "yt-live-chat-item-list-renderer"
  3567. const dummy = document.createElement(tag);
  3568.  
  3569. const cProto = getProto(dummy);
  3570. if (!cProto || !cProto.attached) {
  3571. console.warn(`proto.attached for ${tag} is unavailable.`);
  3572. return;
  3573. }
  3574.  
  3575. mightFirstCheckOnYtInit();
  3576. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  3577. console.log("[Begin]");
  3578.  
  3579. const mclp = cProto;
  3580. try {
  3581. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  3582. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  3583. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  3584. assertor(() => typeof mclp.setAtBottom === 'function');
  3585. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  3586. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  3587. } catch (e) { }
  3588.  
  3589.  
  3590. try {
  3591. assertor(() => typeof mclp.attached === 'function');
  3592. assertor(() => typeof mclp.detached === 'function');
  3593. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  3594. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  3595. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  3596. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  3597. assertor(() => typeof mclp.smoothScroll_ === 'function');
  3598. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  3599. } catch (e) { }
  3600.  
  3601. mclp.__intermediate_delay__ = null;
  3602.  
  3603. let mzk = 0;
  3604. let myk = 0;
  3605. let mlf = 0;
  3606. let myw = 0;
  3607. let mzt = 0;
  3608. let zarr = null;
  3609. let mlg = 0;
  3610.  
  3611. if ((mclp.clearList || 0).length === 0) {
  3612. assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  3613. mclp.clearList66 = mclp.clearList;
  3614. mclp.clearList = function () {
  3615. mzk++;
  3616. myk++;
  3617. mlf++;
  3618. myw++;
  3619. mzt++;
  3620. mlg++;
  3621. zarr = null;
  3622. this.__intermediate_delay__ = null;
  3623. this.clearList66();
  3624. };
  3625. console.log("clearList", "OK");
  3626. } else {
  3627. console.log("clearList", "NG");
  3628. }
  3629.  
  3630.  
  3631. let onListRendererAttachedDone = false;
  3632.  
  3633. function setList(itemOffset, items) {
  3634.  
  3635. const isFirstTime = onListRendererAttachedDone === false;
  3636.  
  3637. if (isFirstTime) {
  3638. onListRendererAttachedDone = true;
  3639. Promise.resolve().then(watchUserCSS);
  3640. addCssManaged();
  3641. setupEvents();
  3642. }
  3643.  
  3644. setupStyle(itemOffset, items);
  3645.  
  3646. setupMutObserver(items);
  3647. }
  3648.  
  3649. mclp.attached419 = async function () {
  3650.  
  3651. if (!this.isAttached) return;
  3652.  
  3653. let maxTrial = 16;
  3654. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  3655. if (--maxTrial < 0 || !this.isAttached) return;
  3656. await new Promise(requestAnimationFrame);
  3657. }
  3658.  
  3659. if (this.isAttached !== true) return;
  3660.  
  3661. if (!this.$) {
  3662. console.warn("!this.$");
  3663. return;
  3664. }
  3665. if (!this.$) return;
  3666. /** @type {HTMLElement | null} */
  3667. const itemScroller = this.$['item-scroller'];
  3668. /** @type {HTMLElement | null} */
  3669. const itemOffset = this.$['item-offset'];
  3670. /** @type {HTMLElement | null} */
  3671. const items = this.$['items'];
  3672.  
  3673. if (!itemScroller || !itemOffset || !items) {
  3674. console.warn("items.parentNode !== itemOffset");
  3675. return;
  3676. }
  3677.  
  3678. if (nodeParent(items) !== itemOffset) {
  3679.  
  3680. console.warn("items.parentNode !== itemOffset");
  3681. return;
  3682. }
  3683.  
  3684.  
  3685. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  3686.  
  3687. console.warn("id incorrect");
  3688. return;
  3689. }
  3690.  
  3691. 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')
  3692.  
  3693. if (!isTargetItems) {
  3694. console.warn("!isTargetItems");
  3695. return;
  3696. }
  3697.  
  3698. setList(itemOffset, items);
  3699.  
  3700. }
  3701.  
  3702. mclp.attached331 = mclp.attached;
  3703. mclp.attached = function () {
  3704. this.attached419 && this.attached419();
  3705. return this.attached331();
  3706. }
  3707.  
  3708. mclp.detached331 = mclp.detached;
  3709.  
  3710. mclp.detached = function () {
  3711. setupMutObserver();
  3712. return this.detached331();
  3713. }
  3714.  
  3715. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  3716. for (const t29 of t29s) {
  3717. if ((t29.inst || t29).isAttached === true) {
  3718. t29.attached419();
  3719. }
  3720. }
  3721.  
  3722. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  3723.  
  3724. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  3725. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  3726.  
  3727. /** @type {Map<number, any>} */
  3728. const aMap = new Map();
  3729. let count = 6150;
  3730. mclp.async66 = mclp.async;
  3731. mclp.async = function (e, f) {
  3732. // ensure the previous operation is done
  3733. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  3734. const hasF = arguments.length === 2;
  3735. const stack = new Error().stack;
  3736. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  3737. if (count > 1e9) count = 6159;
  3738. const resId = ++count;
  3739. aMap.set(resId, e);
  3740. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  3741. const rp = aMap.get(resId);
  3742. if (typeof rp !== 'function') {
  3743. return;
  3744. }
  3745. let cancelCall = false;
  3746. if (isFlushAsync) {
  3747. if (rk < 0) {
  3748. cancelCall = true;
  3749. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  3750. cancelCall = true;
  3751. }
  3752. }
  3753. if (cancelCall) {
  3754. aMap.delete(resId);
  3755. } else {
  3756. const asyncEn = function () {
  3757. aMap.delete(resId);
  3758. return rp.apply(this, arguments);
  3759. };
  3760. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  3761. }
  3762. });
  3763.  
  3764. return resId;
  3765. }
  3766.  
  3767. mclp.cancelAsync66 = mclp.cancelAsync;
  3768. mclp.cancelAsync = function (resId) {
  3769. if (resId <= 6150) {
  3770. this.cancelAsync66(resId);
  3771. } else if (aMap.has(resId)) {
  3772. const rp = aMap.get(resId);
  3773. aMap.delete(resId);
  3774. if (typeof rp !== 'function') {
  3775. this.cancelAsync66(rp);
  3776. }
  3777. }
  3778. }
  3779.  
  3780. console.log("async", "OK");
  3781. } else {
  3782. console.log("async", "NG");
  3783. }
  3784.  
  3785.  
  3786. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  3787.  
  3788. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  3789. mclp.showNewItems66_ = mclp.showNewItems_;
  3790.  
  3791. mclp.showNewItems77_ = async function () {
  3792. if (myk > 1e9) myk = 9;
  3793. let tid = ++myk;
  3794.  
  3795. await new Promise(requestAnimationFrame);
  3796.  
  3797. if (tid !== myk) {
  3798. return;
  3799. }
  3800.  
  3801. const cnt = this;
  3802.  
  3803. await Promise.resolve();
  3804. cnt.showNewItems66_();
  3805.  
  3806. await Promise.resolve();
  3807.  
  3808. }
  3809.  
  3810. mclp.showNewItems_ = function () {
  3811.  
  3812. const cnt = this;
  3813. cnt.__intermediate_delay__ = new Promise(resolve => {
  3814. cnt.showNewItems77_().then(() => {
  3815. resolve();
  3816. });
  3817. });
  3818. }
  3819.  
  3820. console.log("showNewItems_", "OK");
  3821. } else {
  3822. console.log("showNewItems_", "NG");
  3823. }
  3824.  
  3825.  
  3826. if ((mclp.flushActiveItems_ || 0).length === 0) {
  3827.  
  3828. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.137.81'));
  3829.  
  3830. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  3831.  
  3832. let contensWillChangeController = null;
  3833.  
  3834. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  3835.  
  3836. mclp.flushActiveItems78_ = async function (tid) {
  3837. try {
  3838. if (tid !== mlf) return;
  3839. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3840. let logger = false;
  3841. const cnt = this;
  3842. let immd = cnt.__intermediate_delay__;
  3843. await new Promise(requestAnimationFrame);
  3844.  
  3845. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3846. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  3847.  
  3848. mlf++;
  3849. if (mlg > 1e9) mlg = 9;
  3850. ++mlg;
  3851.  
  3852. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  3853. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  3854. let changeMaxItemsToDisplay = false;
  3855. const activeItemsLen = this.activeItems_.length;
  3856. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  3857. logger = true;
  3858.  
  3859. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  3860.  
  3861. logger && console.log('[Begin]')
  3862.  
  3863. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  3864. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  3865. console.log('reduce maxitems');
  3866. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3867. // as all the rendered chats are already "outdated"
  3868. // all old chats shall remove and reduced number of few chats will be rendered
  3869. // then restore to the original number
  3870. changeMaxItemsToDisplay = true;
  3871. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  3872. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  3873. }
  3874. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  3875. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3876.  
  3877. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3878. } else {
  3879. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  3880.  
  3881. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3882. }
  3883. }
  3884. // it is found that it will render all stacked chats after switching back from background
  3885. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  3886. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  3887.  
  3888.  
  3889. const items = (cnt.$ || 0).items;
  3890.  
  3891. if (USE_WILL_CHANGE_CONTROLLER) {
  3892. if (contensWillChangeController && contensWillChangeController.element !== items) {
  3893. contensWillChangeController.release();
  3894. contensWillChangeController = null;
  3895. }
  3896. if (!contensWillChangeController) contensWillChangeController = new WillChangeController(items, 'contents');
  3897. }
  3898. const wcController = contensWillChangeController;
  3899. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  3900. wcController && wcController.beforeOper();
  3901. await Promise.resolve();
  3902. const acItems = cnt.activeItems_;
  3903. const len1 = acItems.length;
  3904. if (!len1) console.warn('cnt.activeItems_.length = 0');
  3905. let waitFor = [];
  3906.  
  3907.  
  3908. /** @type {Set<string>} */
  3909. const imageLinks = new Set();
  3910.  
  3911. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  3912. for (const item of acItems) {
  3913. fixLiveChatItem(item, imageLinks);
  3914. }
  3915. }
  3916. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  3917. if (emojiPrefetched.size > PREFETCH_LIMITED_SIZE_EMOJI) emojiPrefetched.clear();
  3918. if (authorPhotoPrefetched.size > PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO) authorPhotoPrefetched.clear();
  3919.  
  3920. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  3921. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  3922. // preload performs the high priority fetching.
  3923. // prefetch delays the chat display if the video resoruce is demanding.
  3924.  
  3925. if (rel) {
  3926.  
  3927. imageLinks.forEach(imageLink => {
  3928. let d = false;
  3929. const isEmoji = imageLink.includes('/emoji/');
  3930. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  3931. if (!pretechedSet.has(imageLink)) {
  3932. pretechedSet.add(imageLink);
  3933. d = true;
  3934. }
  3935. if (d) {
  3936. waitFor.push(linker(null, rel, imageLink, 'image'));
  3937.  
  3938. }
  3939. })
  3940.  
  3941. }
  3942.  
  3943. }
  3944.  
  3945. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  3946. skipDontRender = noVisibleItem1;
  3947. // console.log('ss1', Date.now())
  3948. if (waitFor.length > 0) {
  3949. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  3950. }
  3951. waitFor.length = 0;
  3952. waitFor = null;
  3953. // console.log('ss2', Date.now())
  3954. cnt.flushActiveItems66_();
  3955. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  3956. skipDontRender = noVisibleItem2;
  3957. const len2 = cnt.activeItems_.length;
  3958. const bAsync = len1 !== len2;
  3959. await Promise.resolve();
  3960. if (wcController) {
  3961. if (bAsync) {
  3962. cnt.async(() => {
  3963. wcController.afterOper();
  3964. });
  3965. } else {
  3966. wcController.afterOper();
  3967. }
  3968. }
  3969. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3970. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  3971.  
  3972. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  3973. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3974. } else if (changeMaxItemsToDisplay) {
  3975.  
  3976. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  3977. maxItemsToDisplay: this.data.maxItemsToDisplay,
  3978. reducedMaxItemsToDisplay,
  3979. originalMaxItemsToDisplay: tmpMaxItemsCount
  3980. });
  3981. }
  3982. logger && console.log('[End]');
  3983.  
  3984. logger && console.groupEnd();
  3985.  
  3986. if (noVisibleItem1 && !noVisibleItem2) {
  3987. // fix possible no auto scroll issue.
  3988. setTimeout(() => cnt.setAtBottom(), 1);
  3989. }
  3990.  
  3991. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  3992.  
  3993.  
  3994. const ff = () => {
  3995.  
  3996. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3997. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3998. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  3999. cnt.scrollToBottom_();
  4000.  
  4001. Promise.resolve().then(() => {
  4002.  
  4003. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4004. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  4005. });
  4006.  
  4007.  
  4008. }
  4009. }
  4010.  
  4011. ff();
  4012.  
  4013.  
  4014. Promise.resolve().then(ff);
  4015.  
  4016. // requestAnimationFrame(ff);
  4017. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  4018.  
  4019. const knt = cnt;
  4020. if (!scrollChatFn) {
  4021. const cnt = knt;
  4022. const f = () => {
  4023. const itemScroller = cnt.itemScroller;
  4024. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  4025. if (!cnt.atBottom) {
  4026. cnt.scrollToBottom_();
  4027. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  4028. itemScroller.scrollTop = itemScroller.scrollHeight;
  4029. }
  4030. };
  4031. scrollChatFn = () => Promise.resolve().then(f).then(f);
  4032. }
  4033.  
  4034. if (!ENABLE_DELAYED_CHAT_OCCURRENCE) scrollChatFn();
  4035. }
  4036.  
  4037. return 1;
  4038.  
  4039.  
  4040. } catch (e) {
  4041. console.warn(e);
  4042. }
  4043. }
  4044.  
  4045. mclp.flushActiveItems77_ = function () {
  4046.  
  4047. return new Promise(resResolve => {
  4048. try {
  4049. const cnt = this;
  4050. if (mlf > 1e9) mlf = 9;
  4051. let tid = ++mlf;
  4052. const hostElement = cnt.hostElement || cnt;
  4053. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  4054. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  4055.  
  4056. // 4 times to maxItems to avoid frequent trimming.
  4057. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  4058.  
  4059. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  4060. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  4061. if (cnt.canScrollToBottom_()) {
  4062. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  4063. .then(() => cnt.flushActiveItems78_(tid)) // async function
  4064. .then((asyncResult) => {
  4065. resResolve(asyncResult); // either undefined or 1
  4066. resResolve = null;
  4067. }).catch((e) => {
  4068. console.warn(e);
  4069. if (resResolve) resResolve();
  4070. });
  4071. } else {
  4072. resResolve(2);
  4073. resResolve = null;
  4074. }
  4075. } catch (e) {
  4076. console.warn(e);
  4077. if (resResolve) resResolve();
  4078. }
  4079.  
  4080.  
  4081. });
  4082.  
  4083. }
  4084.  
  4085. mclp.flushActiveItems_ = function () {
  4086. const cnt = this;
  4087.  
  4088. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  4089.  
  4090. if (cnt.activeItems_.length === 0) {
  4091. cnt.__intermediate_delay__ = null;
  4092. return;
  4093. }
  4094.  
  4095. const cntData = ((cnt || 0).data || 0);
  4096. if (cntData.maxItemsToDisplay944 === undefined) {
  4097. cntData.maxItemsToDisplay944 = null;
  4098. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  4099. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  4100. }
  4101.  
  4102. // ignore previous __intermediate_delay__ and create a new one
  4103. cnt.__intermediate_delay__ = new Promise(resolve => {
  4104. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  4105. if (rt === 1) {
  4106. resolve(1); // success, scroll to bottom
  4107. if (hasMoreMessageState === 1) {
  4108. hasMoreMessageState = 0;
  4109. const showMore = (cnt.$ || 0)['show-more'];
  4110. if (showMore) {
  4111. showMore.classList.remove('has-new-messages-miuzp');
  4112. }
  4113. }
  4114. }
  4115. else if (rt === 2) {
  4116. resolve(2); // success, trim
  4117. if (hasMoreMessageState === 0) {
  4118. hasMoreMessageState = 1;
  4119. const showMore = cnt.$['show-more'];
  4120. if (showMore) {
  4121. showMore.classList.add('has-new-messages-miuzp');
  4122. }
  4123. }
  4124. }
  4125. else resolve(-1); // skip
  4126. }).catch(e => {
  4127. console.warn(e);
  4128. });
  4129. });
  4130.  
  4131. }
  4132. console.log("flushActiveItems_", "OK");
  4133. } else {
  4134. console.log("flushActiveItems_", "NG");
  4135. }
  4136.  
  4137. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  4138. try {
  4139. if (mlg > 1e9) mlg = 9;
  4140. const tid = ++mlg;
  4141. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  4142. const runCond = () => this.canScrollToBottom_();
  4143. if (!keepTrialCond()) return;
  4144. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  4145. await new Promise(r => setTimeout(r, 80));
  4146. if (!keepTrialCond()) return;
  4147. if (runCond()) return this.flushActiveItems_() | 1;
  4148. await new Promise(requestAnimationFrame);
  4149. if (runCond()) return this.flushActiveItems_() | 1;
  4150. } catch (e) {
  4151. console.warn(e);
  4152. }
  4153. }
  4154.  
  4155. if ((mclp.atBottomChanged_ || 0).length === 1) {
  4156. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  4157. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.75.39'));
  4158.  
  4159. const querySelector = HTMLElement.prototype.querySelector;
  4160. const U = (element) => ({
  4161. querySelector: (selector) => querySelector.call(element, selector)
  4162. });
  4163.  
  4164. let qid = 0;
  4165. mclp.atBottomChanged_ = function (a) {
  4166. let tid = ++qid;
  4167. let b = this;
  4168. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  4169. if (tid !== qid) return;
  4170. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  4171. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  4172. this.hideShowMoreAsync_ = null,
  4173. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  4174. }
  4175.  
  4176. console.log("atBottomChanged_", "OK");
  4177. } else {
  4178. console.log("atBottomChanged_", "NG");
  4179. }
  4180.  
  4181. if ((mclp.onScrollItems_ || 0).length === 1) {
  4182.  
  4183. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  4184. mclp.onScrollItems66_ = mclp.onScrollItems_;
  4185. mclp.onScrollItems77_ = async function (evt) {
  4186. if (myw > 1e9) myw = 9;
  4187. let tid = ++myw;
  4188.  
  4189. await new Promise(requestAnimationFrame);
  4190.  
  4191. if (tid !== myw) {
  4192. return;
  4193. }
  4194.  
  4195. const cnt = this;
  4196.  
  4197. await Promise.resolve();
  4198. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  4199. await Promise.resolve().then(() => {
  4200. this.ytRendererBehavior.onScroll(evt);
  4201. }).then(() => {
  4202. if (this.canScrollToBottom_()) {
  4203. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  4204. if (hasUserJustInteracted) {
  4205. // only when there is an user action
  4206. this.setAtBottom();
  4207. return 1;
  4208. }
  4209. } else {
  4210. // no message inserting
  4211. this.setAtBottom();
  4212. return 1;
  4213. }
  4214. }).then((r) => {
  4215.  
  4216. if (this.activeItems_.length) {
  4217.  
  4218. if (this.canScrollToBottom_()) {
  4219. this.flushActiveItems_();
  4220. return 1 && r;
  4221. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  4222. // delayed due to user action
  4223. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  4224. return 0;
  4225. }
  4226. }
  4227. }).then((r) => {
  4228. if (r) {
  4229. // ensure setAtBottom is correctly set
  4230. this.setAtBottom();
  4231. }
  4232. });
  4233. } else {
  4234. cnt.onScrollItems66_(evt);
  4235. }
  4236.  
  4237. await Promise.resolve();
  4238.  
  4239. }
  4240.  
  4241. mclp.onScrollItems_ = function (evt) {
  4242.  
  4243. const cnt = this;
  4244. cnt.__intermediate_delay__ = new Promise(resolve => {
  4245. cnt.onScrollItems77_(evt).then(() => {
  4246. resolve();
  4247. });
  4248. });
  4249. }
  4250. console.log("onScrollItems_", "OK");
  4251. } else {
  4252. console.log("onScrollItems_", "NG");
  4253. }
  4254.  
  4255. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  4256.  
  4257. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  4258. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  4259.  
  4260. mclp.handleLiveChatActions77_ = async function (arr) {
  4261. if (typeof (arr || 0).length !== 'number') {
  4262. this.handleLiveChatActions66_(arr);
  4263. return;
  4264. }
  4265. if (mzt > 1e9) mzt = 9;
  4266. let tid = ++mzt;
  4267.  
  4268. if (zarr === null) zarr = arr;
  4269. else Array.prototype.push.apply(zarr, arr);
  4270. arr = null;
  4271.  
  4272. await new Promise(requestAnimationFrame);
  4273.  
  4274. if (tid !== mzt || zarr === null) {
  4275. return;
  4276. }
  4277.  
  4278. const carr = zarr;
  4279. zarr = null;
  4280.  
  4281. await Promise.resolve();
  4282. this.handleLiveChatActions66_(carr);
  4283. await Promise.resolve();
  4284.  
  4285. }
  4286.  
  4287. mclp.handleLiveChatActions_ = function (arr) {
  4288.  
  4289. const cnt = this;
  4290. cnt.__intermediate_delay__ = new Promise(resolve => {
  4291. cnt.handleLiveChatActions77_(arr).then(() => {
  4292. resolve();
  4293. });
  4294. });
  4295. }
  4296. console.log("handleLiveChatActions_", "OK");
  4297. } else {
  4298. console.log("handleLiveChatActions_", "NG");
  4299. }
  4300.  
  4301. mclp.hasUserJustInteracted11_ = () => {
  4302. const t = dateNow();
  4303. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  4304. }
  4305.  
  4306. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  4307.  
  4308. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  4309.  
  4310. mclp.canScrollToBottom_ = function () {
  4311. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  4312. }
  4313.  
  4314. console.log("canScrollToBottom_", "OK");
  4315. } else {
  4316. console.log("canScrollToBottom_", "NG");
  4317. }
  4318.  
  4319. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  4320.  
  4321. mclp.isSmoothScrollEnabled_ = function () {
  4322. return false;
  4323. }
  4324.  
  4325. mclp.maybeResizeScrollContainer_ = function () {
  4326. //
  4327. }
  4328.  
  4329. mclp.refreshOffsetContainerHeight_ = function () {
  4330. //
  4331. }
  4332.  
  4333. mclp.smoothScroll_ = function () {
  4334. //
  4335. }
  4336.  
  4337. mclp.resetSmoothScroll_ = function () {
  4338. //
  4339. }
  4340. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  4341. } else {
  4342. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  4343. }
  4344.  
  4345. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  4346.  
  4347. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  4348. mclp.handleAddChatItemAction_ = function (a) {
  4349. try {
  4350. if (a && typeof a === 'object' && !('length' in a)) {
  4351. fixLiveChatItem(a.item, null);
  4352. console.assert(arguments[0] === a);
  4353. }
  4354. } catch (e) { console.warn(e) }
  4355. return this.handleAddChatItemAction66_.apply(this, arguments);
  4356. }
  4357.  
  4358. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  4359. } else {
  4360.  
  4361. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  4362. }
  4363.  
  4364.  
  4365. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  4366.  
  4367. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  4368. mclp.handleReplaceChatItemAction_ = function (a) {
  4369. try {
  4370. if (a && typeof a === 'object' && !('length' in a)) {
  4371. fixLiveChatItem(a.replacementItem, null);
  4372. console.assert(arguments[0] === a);
  4373. }
  4374. } catch (e) { console.warn(e) }
  4375. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  4376. }
  4377.  
  4378. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  4379. } else {
  4380.  
  4381. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  4382. }
  4383.  
  4384. console.log("[End]");
  4385. console.groupEnd();
  4386.  
  4387. }).catch(console.warn);
  4388.  
  4389.  
  4390. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  4391.  
  4392. let yd = (this.__dataHost || (this.inst || 0).__dataHost || 0).__data;
  4393.  
  4394. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  4395.  
  4396. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  4397. let v = `${attrValue}`;
  4398. // conside a ticker is 101px width
  4399. // 1% = 1.01px
  4400. // 0.2% = 0.202px
  4401.  
  4402.  
  4403. const ratio1 = (yd.ratio * 100);
  4404. if (ratio1 > -1) { // avoid NaN
  4405.  
  4406. // countdownDurationMs
  4407. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  4408. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  4409. // 150000 - 1% <1% = 1.5s>
  4410. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  4411. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  4412.  
  4413. // 99px * 5% = 4.95px
  4414.  
  4415. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  4416.  
  4417.  
  4418. // 1% Duration
  4419.  
  4420. let ratio2 = ratio1;
  4421.  
  4422. const ydd = yd.data;
  4423. if (ydd) {
  4424.  
  4425. const d1 = ydd.durationSec;
  4426. const d2 = ydd.fullDurationSec;
  4427.  
  4428. // @ step timing [min. 0.2%]
  4429. let numOfSteps = 500;
  4430. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  4431. if (d2 > 400) numOfSteps = 500; // 0.2%
  4432. else if (d2 > 200) numOfSteps = 200; // 0.5%
  4433. else if (d2 > 100) numOfSteps = 100; // 1%
  4434. else if (d2 > 50) numOfSteps = 50; // 2%
  4435. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  4436. else numOfSteps = 20;
  4437. }
  4438. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4439. if (numOfSteps < 5) numOfSteps = 5;
  4440.  
  4441. const rd = numOfSteps / 100.0;
  4442.  
  4443. ratio2 = Math.round(ratio2 * rd) / rd;
  4444.  
  4445. // ratio2 = Math.round(ratio2 * 5) / 5;
  4446. ratio2 = ratio2.toFixed(1);
  4447. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  4448.  
  4449. if (yd.__style_last__ === v) return;
  4450. yd.__style_last__ = v;
  4451. // do not consider any delay here.
  4452. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  4453.  
  4454. }
  4455. }
  4456.  
  4457. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  4458.  
  4459.  
  4460. } else {
  4461. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  4462. }
  4463.  
  4464. };
  4465.  
  4466.  
  4467. const fpTicker = (renderer) => {
  4468. const cnt = renderer.inst || renderer;
  4469. assertor(() => typeof (cnt || 0).is === 'string');
  4470. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  4471. const container = (cnt.$ || 0).container;
  4472. if (container) {
  4473. assertor(() => (container || 0).nodeType === 1);
  4474. assertor(() => typeof container.setAttribute === 'function');
  4475. container.setAttribute = tickerContainerSetAttribute;
  4476. } else {
  4477. console.warn(`"container" does not exist in ${cnt.is}`);
  4478. }
  4479. };
  4480.  
  4481.  
  4482. const tags = [
  4483. "yt-live-chat-ticker-paid-message-item-renderer",
  4484. "yt-live-chat-ticker-paid-sticker-item-renderer",
  4485. "yt-live-chat-ticker-renderer",
  4486. "yt-live-chat-ticker-sponsor-item-renderer"
  4487. ];
  4488.  
  4489.  
  4490. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  4491.  
  4492. mightFirstCheckOnYtInit();
  4493. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  4494. console.log("[Begin]");
  4495.  
  4496. let dummyValueForStyleReturn = null;
  4497.  
  4498. const genDummyValueForStyleReturn = () => {
  4499. let s = `--nx:82;`
  4500. let ro = {
  4501. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4502. "implementsGoogStringTypedString": true
  4503. };
  4504. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4505. return ro;
  4506. }
  4507.  
  4508. const isCSSPropertySupported = () => {
  4509.  
  4510. // @property --ticker-rtime
  4511.  
  4512. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return;
  4513. const documentElement = document.documentElement;
  4514. if (!documentElement) {
  4515. console.warn('document.documentElement is not found');
  4516. return false;
  4517. }
  4518. if (`${getComputedStyle(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  4519. return false;
  4520. }
  4521. return true;
  4522.  
  4523. };
  4524.  
  4525.  
  4526. let windowShownAt = -1;
  4527. const setupEventForWindowShownAt = () => {
  4528. window.addEventListener('visibilitychange', () => {
  4529. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  4530. else windowShownAt = 0;
  4531. }, false);
  4532. }
  4533.  
  4534. const dProto = {
  4535.  
  4536. attachedForTickerInit: function () {
  4537.  
  4538. fpTicker(this.hostElement || this);
  4539. return this.attached77();
  4540.  
  4541. },
  4542.  
  4543.  
  4544. // doAnimator
  4545.  
  4546. _makeAnimator: function () {
  4547. if (this._r782) return;
  4548. // if (!this.isAttached) return;
  4549. if (!this._runnerAE) {
  4550. /** @type {HTMLElement | null} */
  4551. const aElement = (this.$ || 0).container;
  4552. if (!aElement) return console.warn("this.$.container is undefined");
  4553. const da = this.data;
  4554. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  4555. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  4556. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  4557. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  4558.  
  4559. // if (!this.__tickerBackgroundInitialChecked__) {
  4560. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  4561. // console.log('__tickerBackgroundInitialChecked__')
  4562. // this._checkTickerBackgroundChanged();
  4563. // }
  4564.  
  4565. aElement.style.setProperty('--ticker-c1', c1);
  4566. aElement.style.setProperty('--ticker-c2', c2);
  4567. aElement.classList.add(runTickerClassName);
  4568. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  4569. // this._aeStartV = this.countdownMs;
  4570. // this._aeStartT = this.countdownDurationMs;
  4571. if (!(p >= 0 && p <= 100)) {
  4572. console.warn('incorrect time ratio', p);
  4573. } else {
  4574. /*
  4575. const u0 = p.toFixed(4) + '%';
  4576. this._runnerAE = animate.call(aElement,
  4577. [
  4578. { '--ticker-rtime': u0 },
  4579. { '--ticker-rtime': '0%' }
  4580. ]
  4581. ,
  4582. {
  4583. fill: "forwards",
  4584. duration: this.countdownMs,
  4585. easing: "linear"
  4586. }
  4587. );
  4588. */
  4589.  
  4590. let timingFn = 'linear';
  4591.  
  4592. const totalDuration = this.countdownDurationMs;
  4593.  
  4594. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  4595.  
  4596. // @ step timing [min. 0.2%]
  4597. let stepInterval = 0.2; // unit: %
  4598. if (totalDuration > 400000) stepInterval = 0.2;
  4599. else if (totalDuration > 200000) stepInterval = 0.5;
  4600. else if (totalDuration > 100000) stepInterval = 1;
  4601. else if (totalDuration > 50000) stepInterval = 2;
  4602. else if (totalDuration > 25000) stepInterval = 5;
  4603. else stepInterval = 5;
  4604.  
  4605. let numOfSteps = Math.round(100 / stepInterval);
  4606.  
  4607. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4608. if (numOfSteps < 5) numOfSteps = 5;
  4609.  
  4610. timingFn = `steps(${numOfSteps}, end)`;
  4611.  
  4612. }
  4613.  
  4614.  
  4615. /** @type {Animation} */
  4616. const ae = animate.call(aElement,
  4617. [
  4618. { '--ticker-rtime': '100%' },
  4619. { '--ticker-rtime': '0%' }
  4620. ]
  4621. ,
  4622. {
  4623. fill: "forwards",
  4624. duration: totalDuration,
  4625. easing: timingFn
  4626. }
  4627. );
  4628.  
  4629. this._runnerAE = ae;
  4630.  
  4631. ae.onfinish = (event) => {
  4632. this.onfinish = null;
  4633. if (this._runnerAE !== ae) return;
  4634. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  4635. this._aeFinished(event);
  4636. }
  4637. }
  4638.  
  4639. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  4640.  
  4641. if (bq >= 0 && bq <= totalDuration) {
  4642.  
  4643. if (bq > totalDuration - 1) {
  4644. ae.currentTime = bq;
  4645. // setTimeout(() => {
  4646. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  4647. // }, 1);
  4648. } else {
  4649. ae.currentTime = bq;
  4650. }
  4651. } else {
  4652. console.warn('Error on setting _runnerAE.currentTime!');
  4653. }
  4654.  
  4655.  
  4656. aeConstructor = ae.constructor; // constructor is from iframe
  4657. return ae;
  4658. }
  4659. } else {
  4660. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  4661. // assume just time update
  4662. const ae = this._runnerAE;
  4663. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  4664. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  4665. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  4666. if (!(p >= 0 && p <= 100)) {
  4667. console.warn('incorrect time ratio', p);
  4668. } else {
  4669. // let u0 = p.toFixed(4) + '%'
  4670. /*
  4671. ae.effect.setKeyframes([
  4672. { '--ticker-rtime': u0 },
  4673. { '--ticker-rtime': '0%' }
  4674. ]);
  4675. ae.effect.updateTiming({ duration: this.countdownMs });
  4676. */
  4677. // ae.currentTime = 0;
  4678.  
  4679.  
  4680.  
  4681. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  4682. if (bq >= 0 && bq <= this.countdownDurationMs) {
  4683.  
  4684. this._runnerAE.currentTime = bq
  4685. } else {
  4686. console.warn('Error on setting _runnerAE.currentTime!');
  4687. }
  4688.  
  4689.  
  4690. ae.play();
  4691. return ae;
  4692. }
  4693. }
  4694. },
  4695.  
  4696. _aeFinished: function (event) {
  4697.  
  4698. if (this._r782) return;
  4699.  
  4700. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4701. this._throwOut();
  4702. return;
  4703. }
  4704.  
  4705. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4706.  
  4707. let lc = window.performance.now();
  4708. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4709. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4710. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  4711. if (this.countdownMs > 76) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs, this, event); // just warning.
  4712.  
  4713. this.countdownMs = 0;
  4714. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null;
  4715.  
  4716. if (this.isAttached) {
  4717. let fastRemoved = false;
  4718. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  4719. // no animation if the video page is switched from background to foreground
  4720. // this.hostElement.style.display = 'none';
  4721. const id = (this.data || 0).id || 0;
  4722. if (!id) this.data = { id: 1 }
  4723. try {
  4724. this.requestRemoval();
  4725. fastRemoved = true;
  4726. } catch (e) {
  4727.  
  4728. }
  4729. }
  4730.  
  4731. if (!fastRemoved) {
  4732. "auto" === this.hostElement.style.width && this.setContainerWidth();
  4733. this.slideDown();
  4734. }
  4735. }
  4736.  
  4737.  
  4738.  
  4739. },
  4740.  
  4741.  
  4742. /** @type {()} */
  4743. _throwOut: function () {
  4744. this._r782 = 1;
  4745. Promise.resolve().then(() => {
  4746. if (typeof this.requestRemoval === 'function') {
  4747. const id = (this.data || 0).id;
  4748. if (!id) this.data = { id: 1 };
  4749. try {
  4750. this.requestRemoval();
  4751. } catch (e) { }
  4752. }
  4753. this.detached();
  4754. this.data = null;
  4755. this.countdownMs = 0;
  4756. this.lastCountdownTimeMs = null;
  4757. if (this.__dataClientsReady === true) this.__dataClientsReady = false;
  4758. if (this.__dataEnabled === true) this.__dataEnabled = false;
  4759. if (this.__dataReady === true) this.__dataReady = false;
  4760. const hm = this.hostElement || this;
  4761. if (hm.parentNode) hm.remove();
  4762. if (hm.firstChild) hm.textContent = '';
  4763. }).catch(e => {
  4764. console.warn(e);
  4765. });
  4766. },
  4767.  
  4768.  
  4769. // doTimerFnModification
  4770.  
  4771.  
  4772. /** @type {(a, b)} */
  4773. startCountdownForTimerFnModA: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4774. try {
  4775. // a.durationSec [s] => countdownMs [ms]
  4776. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4777. // lastCountdownTimeMs => raf ongoing
  4778. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4779.  
  4780. if (this._r782) return;
  4781.  
  4782. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4783. this._throwOut();
  4784. return;
  4785. }
  4786.  
  4787. // TimerFnModA
  4788.  
  4789. b = void 0 === b ? 0 : b;
  4790. if (void 0 !== a) {
  4791.  
  4792. this.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  4793. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs; // constant throughout the animation
  4794. if (!(this.lastCountdownTimeMs || this.isAnimationPaused)) {
  4795. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = performance.now()
  4796. this.rafId = 1
  4797. if (this._runnerAE) console.warn('Error in .startCountdown; this._runnerAE already created.')
  4798. this.detlaSincePausedSecs = 0;
  4799. const ae = this._makeAnimator();
  4800. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4801.  
  4802. // if (playerProgressChangedArg1 === null) {
  4803. // console.log('startCountdownForTimerFnModA', this.data)
  4804. // }
  4805.  
  4806. if (isPlayProgressTriggered && this.isAnimationPaused !== true && this.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__) {
  4807.  
  4808.  
  4809.  
  4810.  
  4811. this.playerProgressSec = lastPlayerProgress > 0 ? lastPlayerProgress : 0; // save the progress first
  4812. this.isAnimationPaused = true; // trigger isAnimationPausedChanged
  4813. this.detlaSincePausedSecs = 0;
  4814. this._forceNoDetlaSincePausedSecs783 = 1; // reset this.detlaSincePausedSecs = 0 when resumed
  4815.  
  4816. relayPromise = relayPromise || new PromiseExternal();
  4817.  
  4818. relayPromise.then(() => {
  4819. if (this.isAttached === true && this.countdownDurationMs > 0 && this.isAnimationPaused === true && this.isReplayPaused !== true) {
  4820. this.isAnimationPaused = false;
  4821. }
  4822. });
  4823.  
  4824.  
  4825. }
  4826.  
  4827.  
  4828.  
  4829. }
  4830. }
  4831.  
  4832. } catch (e) {
  4833. console.warn(e);
  4834. }
  4835.  
  4836. },
  4837.  
  4838.  
  4839.  
  4840. /** @type {(a, b)} */
  4841. startCountdownForTimerFnModT: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4842. try {
  4843. // a.durationSec [s] => countdownMs [ms]
  4844. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4845. // lastCountdownTimeMs => raf ongoing
  4846. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4847.  
  4848. if (this._r782) return;
  4849.  
  4850. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4851. this._throwOut();
  4852. return;
  4853. }
  4854.  
  4855. // TimerFnModT
  4856.  
  4857. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4858. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4859. b = void 0 === b ? 0 : b;
  4860. void 0 !== a && (this.countdownMs = 1E3 * a,
  4861. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs,
  4862. this.ratio = 1,
  4863. this.lastCountdownTimeMs || this.isAnimationPaused || (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = performance.now(),
  4864. this.rafId = rafHub.request(this.boundUpdateTimeout37_)))
  4865.  
  4866. } catch (e) {
  4867. console.warn(e);
  4868. }
  4869.  
  4870. },
  4871.  
  4872.  
  4873. /** @type {(a,)} */
  4874. updateTimeoutForTimerFnModA: function (a) {
  4875.  
  4876. try {
  4877.  
  4878. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  4879.  
  4880. if (this._r782) return;
  4881.  
  4882. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4883. this._throwOut();
  4884. return;
  4885. }
  4886.  
  4887. // TimerFnModA
  4888.  
  4889. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4890. if (this.lastCountdownTimeMs !== this._lastCountdownTimeMsX0) {
  4891. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4892. }
  4893. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4894. if (this.isAttached && this.countdownMs) {
  4895. this.lastCountdownTimeMs = a
  4896. const ae = this._makeAnimator(); // request raf
  4897. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4898. } else {
  4899. (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null,
  4900. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4901. this.slideDown()));
  4902. }
  4903.  
  4904. } catch (e) {
  4905. console.warn(e);
  4906. }
  4907.  
  4908.  
  4909. },
  4910.  
  4911. /** @type {(a,)} */
  4912. updateTimeoutForTimerFnModT: function (a) {
  4913.  
  4914. try {
  4915.  
  4916. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  4917.  
  4918. if (this._r782) return;
  4919.  
  4920. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4921. this._throwOut();
  4922. return;
  4923. }
  4924.  
  4925. // TimerFnModT
  4926.  
  4927. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4928. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4929. if (this.lastCountdownTimeMs !== this._lastCountdownTimeMsX0) {
  4930. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4931. }
  4932. // console.log(703, this.countdownMs)
  4933. this.ratio = this.countdownMs / this.countdownDurationMs;
  4934. this.isAttached && this.countdownMs ? (this.lastCountdownTimeMs = a,
  4935. this.rafId = rafHub.request(this.boundUpdateTimeout37_)) : (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null,
  4936. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4937. this.slideDown()))
  4938.  
  4939.  
  4940. } catch (e) {
  4941. console.warn(e);
  4942. }
  4943. },
  4944.  
  4945. /** @type {(a,b)} */
  4946. isAnimationPausedChangedForTimerFnModA: function (a, b) {
  4947.  
  4948. if (this._r782) return;
  4949.  
  4950. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4951. this._throwOut();
  4952. return;
  4953. }
  4954. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  4955. this._forceNoDetlaSincePausedSecs783 = 0;
  4956.  
  4957. Promise.resolve().then(() => {
  4958.  
  4959. if (a) {
  4960.  
  4961. if (this._runnerAE && this._runnerAE.playState === 'running') {
  4962.  
  4963. this._runnerAE.pause()
  4964. let lc = window.performance.now();
  4965. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4966. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4967. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  4968. }
  4969.  
  4970. } else if (!a && b) {
  4971.  
  4972.  
  4973. if (forceNoDetlaSincePausedSecs783) this.detlaSincePausedSecs = 0;
  4974. a = this.detlaSincePausedSecs ? (this.lastCountdownTimeMs || 0) + 1000 * this.detlaSincePausedSecs : (this.lastCountdownTimeMs || 0);
  4975. this.detlaSincePausedSecs = 0;
  4976. this.updateTimeout(a);
  4977. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = window.performance.now();
  4978.  
  4979. }
  4980.  
  4981.  
  4982. }).catch(e => {
  4983. console.log(e);
  4984. });
  4985.  
  4986.  
  4987.  
  4988. },
  4989.  
  4990.  
  4991. /** @type {(a,b)} */
  4992. isAnimationPausedChangedForTimerFnModT: function (a, b) {
  4993.  
  4994. if (this._r782) return;
  4995.  
  4996. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4997. this._throwOut();
  4998. return;
  4999. }
  5000. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  5001. this._forceNoDetlaSincePausedSecs783 = 0;
  5002.  
  5003. Promise.resolve().then(() => {
  5004.  
  5005. // TimerFnModT
  5006.  
  5007. // ez++;
  5008. // if(ez> 1e9) ez=9;
  5009. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  5010. a ? rafHub.cancel(this.rafId) : !a && b && (a = this.lastCountdownTimeMs || 0,
  5011. this.detlaSincePausedSecs && (a = (this.lastCountdownTimeMs || 0) + 1E3 * this.detlaSincePausedSecs,
  5012. this.detlaSincePausedSecs = 0),
  5013. this.boundUpdateTimeout37_(a),
  5014. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = window.performance.now())
  5015.  
  5016.  
  5017. }).catch(e => {
  5018. console.log(e);
  5019. });
  5020.  
  5021.  
  5022.  
  5023. },
  5024.  
  5025.  
  5026. /** @type {(a,b)} */
  5027. computeContainerStyleForAnimatorEnabled: function (a, b) {
  5028.  
  5029. if (this._r782) return;
  5030.  
  5031. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5032. this._throwOut();
  5033. return;
  5034. }
  5035.  
  5036. return (dummyValueForStyleReturn || (dummyValueForStyleReturn = genDummyValueForStyleReturn()));
  5037.  
  5038. },
  5039.  
  5040.  
  5041.  
  5042. /** @type {()} */
  5043. handlePauseReplayForPlaybackProgressState: function () {
  5044. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  5045.  
  5046. if (onPlayStateChangePromise) {
  5047.  
  5048. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  5049. const tid = ++this.rtu;
  5050.  
  5051. onPlayStateChangePromise.then(() => {
  5052. if (tid === this.rtu && !onPlayStateChangePromise) this.handlePauseReplay.apply(this, arguments);
  5053. });
  5054.  
  5055. return;
  5056. }
  5057.  
  5058. if (playerState !== 2) return;
  5059. if (this.isAttached) {
  5060. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  5061. const tid = ++this.rtk;
  5062. const tc = relayCount;
  5063. foregroundPromiseFn().then(() => {
  5064. if (tid === this.rtk && tc === relayCount && playerState === 2 && _playerState === playerState) {
  5065. this.handlePauseReplay66();
  5066. }
  5067.  
  5068. })
  5069. }
  5070. },
  5071.  
  5072. /** @type {()} */
  5073. handleResumeReplayForPlaybackProgressState: function () {
  5074. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  5075.  
  5076.  
  5077. if (onPlayStateChangePromise) {
  5078.  
  5079. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  5080. const tid = ++this.rtv;
  5081.  
  5082. onPlayStateChangePromise.then(() => {
  5083. if (tid === this.rtv && !onPlayStateChangePromise) this.handleResumeReplay.apply(this, arguments);
  5084. });
  5085.  
  5086. return;
  5087. }
  5088.  
  5089.  
  5090. if (playerState !== 1) return;
  5091. if (this.isAttached) {
  5092. const tc = relayCount;
  5093.  
  5094. relayPromise = relayPromise || new PromiseExternal();
  5095. relayPromise.then(() => {
  5096. if (relayCount > tc && playerState === 1 && _playerState === playerState) {
  5097. this.handleResumeReplay66();
  5098. }
  5099. });
  5100. }
  5101. },
  5102.  
  5103. /** @type {(a,)} */
  5104. handleReplayProgressForPlaybackProgressState: function (a) {
  5105. if (this.isAttached) {
  5106. const tid = ++this.rtk;
  5107. foregroundPromiseFn().then(() => {
  5108. if (tid === this.rtk) {
  5109. this.handleReplayProgress66(a);
  5110. }
  5111. })
  5112. }
  5113. }
  5114.  
  5115.  
  5116. }
  5117.  
  5118.  
  5119. for (const tag of tags) { // ##tag##
  5120. const dummy = document.createElement(tag);
  5121.  
  5122. const cProto = getProto(dummy);
  5123. if (!cProto || !cProto.attached) {
  5124. console.warn(`proto.attached for ${tag} is unavailable.`);
  5125. continue;
  5126. }
  5127.  
  5128. cProto.attached77 = cProto.attached;
  5129.  
  5130. cProto.attached = dProto.attachedForTickerInit;
  5131.  
  5132. let rafHackState = 0;
  5133.  
  5134. let isTimingFunctionHackable = false;
  5135.  
  5136. let urt = 0;
  5137.  
  5138. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  5139.  
  5140. // console.log('startCountdown', typeof cProto.startCountdown)
  5141. // console.log('updateTimeout', typeof cProto.updateTimeout)
  5142. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  5143.  
  5144. isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  5145.  
  5146. } else {
  5147. console.log(`Skip Timing Function Modification for ${tag}`);
  5148. continue;
  5149. }
  5150.  
  5151.  
  5152. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  5153.  
  5154. // cancelable - this.rafId < isAnimationPausedChanged >
  5155. rafHackState = 1;
  5156.  
  5157. if (isTimingFunctionHackable) {
  5158. rafHackState = 2;
  5159.  
  5160. } else {
  5161. rafHackState = 4;
  5162. }
  5163.  
  5164. }
  5165.  
  5166. const doAnimator = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  5167.  
  5168. const doRAFHack = rafHackState === 2;
  5169.  
  5170. cProto._throwOut = dProto._throwOut;
  5171.  
  5172. cProto._makeAnimator = doAnimator ? dProto._makeAnimator : null;
  5173.  
  5174. cProto._aeFinished = doAnimator ? dProto._aeFinished : null;
  5175.  
  5176.  
  5177. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  5178.  
  5179.  
  5180.  
  5181. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  5182. urt++;
  5183. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  5184. } else {
  5185. console.log('Error for setting cProto.handlePauseReplay', tag)
  5186. }
  5187.  
  5188. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handlePauseReplay.length === 0) {
  5189. urt++;
  5190. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  5191. } else {
  5192. console.log('Error for setting cProto.handleResumeReplay', tag)
  5193. }
  5194.  
  5195. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  5196. urt++;
  5197. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  5198. } else {
  5199. console.log('Error for setting cProto.handleReplayProgress', tag)
  5200. }
  5201.  
  5202.  
  5203.  
  5204. }
  5205.  
  5206. const ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED = ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX && urt === 3;
  5207. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  5208.  
  5209. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  5210.  
  5211. cProto.rtk = 0;
  5212. cProto.rtu = 0;
  5213. cProto.rtv = 0;
  5214.  
  5215. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  5216. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  5217.  
  5218. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  5219. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  5220.  
  5221. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  5222. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  5223.  
  5224. }
  5225.  
  5226. const doTimerFnModification = (doRAFHack || doAnimator);
  5227.  
  5228. if (doAnimator && windowShownAt < 0) {
  5229. windowShownAt = 0;
  5230. setupEventForWindowShownAt();
  5231. }
  5232.  
  5233. if (doTimerFnModification) {
  5234.  
  5235. cProto.startCountdown = (
  5236. doAnimator ? dProto.startCountdownForTimerFnModA : dProto.startCountdownForTimerFnModT
  5237. );
  5238.  
  5239. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  5240. cProto.updateTimeout = (
  5241. doAnimator ? dProto.updateTimeoutForTimerFnModA : dProto.updateTimeoutForTimerFnModT
  5242. );
  5243.  
  5244.  
  5245. // let ez = 0;
  5246. cProto.isAnimationPausedChanged = (
  5247. doAnimator ? dProto.isAnimationPausedChangedForTimerFnModA : dProto.isAnimationPausedChangedForTimerFnModT
  5248. );
  5249.  
  5250. }
  5251.  
  5252. if (doAnimator) {
  5253.  
  5254. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.81.31'));
  5255.  
  5256. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  5257.  
  5258. cProto.computeContainerStyle = dProto.computeContainerStyleForAnimatorEnabled;
  5259.  
  5260. }
  5261.  
  5262. if (doTimerFnModification === true) hasTimerModified = true;
  5263.  
  5264. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  5265. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  5266. }
  5267.  
  5268. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  5269. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  5270. }
  5271.  
  5272. }
  5273.  
  5274. const selector = tags.join(', ');
  5275. const elements = document.querySelectorAll(selector);
  5276. if (elements.length >= 1) {
  5277. for (const elm of elements) {
  5278. if ((elm || elm.inst).isAttached === true) {
  5279. fpTicker(elm);
  5280. }
  5281. }
  5282. }
  5283.  
  5284. console.log("[End]");
  5285. console.groupEnd();
  5286.  
  5287.  
  5288. }).catch(console.warn);
  5289.  
  5290. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  5291.  
  5292. mightFirstCheckOnYtInit();
  5293. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  5294. console.log("[Begin]");
  5295. (() => {
  5296.  
  5297. /* pending!!
  5298.  
  5299. handleLiveChatAction
  5300.  
  5301. removeTickerItemById
  5302.  
  5303. _itemsChanged
  5304. itemsChanged
  5305.  
  5306. handleMarkChatItemAsDeletedAction
  5307. handleMarkChatItemsByAuthorAsDeletedAction
  5308. handleRemoveChatItemByAuthorAction
  5309.  
  5310.  
  5311. */
  5312.  
  5313. const tag = "yt-live-chat-ticker-renderer"
  5314. const dummy = document.createElement(tag);
  5315.  
  5316. const cProto = getProto(dummy);
  5317. if (!cProto || !cProto.attached) {
  5318. console.warn(`proto.attached for ${tag} is unavailable.`);
  5319. return;
  5320. }
  5321.  
  5322. if (AMEND_TICKER_handleLiveChatAction
  5323. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && fnIntegrity(cProto.handleLiveChatAction) === '1.63.48'
  5324. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && fnIntegrity(cProto.handleLiveChatActions) === '1.23.12'
  5325. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  5326. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  5327. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  5328. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  5329. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  5330. ) {
  5331.  
  5332. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  5333.  
  5334. cProto.handleLiveChatActions = function (a) {
  5335. /**
  5336. *
  5337. f.handleLiveChatActions = function(a) {
  5338. a.length && (a.forEach(this.handleLiveChatAction, this),
  5339. this.updateHighlightedItem(),
  5340. this.shouldAnimateIn = !0)
  5341. }
  5342. *
  5343. */
  5344.  
  5345. if (a.length) {
  5346. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  5347. const len = a.length;
  5348. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  5349. // Primarily for the initial batch, this is due to replayBuffer._back.
  5350. const entries = [];
  5351. const entriesI = [];
  5352. for (let i = 0; i < len; i++) {
  5353. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  5354. if (item) {
  5355. const itemRendererKey = firstObjectKey(item);
  5356. const itemRenderer = item[itemRendererKey];
  5357. if (itemRenderer) {
  5358. let timestampUsec = getTimestampUsec(itemRenderer);
  5359. if (timestampUsec !== null) {
  5360. timestampUsec = parseInt(timestampUsec);
  5361. if (timestampUsec > 0) {
  5362. entriesI.push(i);
  5363. entries.push({ e: a[i], timestampUsec })
  5364. }
  5365. }
  5366. }
  5367. }
  5368. }
  5369. const mLen = entries.length;
  5370. if (mLen >= 2) {
  5371. entries.sort((a, b) => {
  5372. const diff = a.timestampUsec - b.timestampUsec;
  5373. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  5374. });
  5375. for (let j = 0; j < mLen; j++) {
  5376. const i = entriesI[j];
  5377. a[i] = entries[j].e;
  5378. }
  5379. }
  5380. entries.length = 0;
  5381. entriesI.length = 0;
  5382. }
  5383. for (const action of a) {
  5384. action.__batchId45__ = batchToken;
  5385. this.handleLiveChatAction(action);
  5386. }
  5387. }
  5388. }
  5389.  
  5390. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  5391.  
  5392.  
  5393.  
  5394. cProto._nszlv_ = 0;
  5395. cProto._stackedLCAs_ = null;
  5396. cProto._lastAddItem_ = null;
  5397. cProto._lastAddItemInStack_ = false;
  5398. cProto.handleLiveChatAction = function (a) {
  5399.  
  5400.  
  5401. /**
  5402. *
  5403. *
  5404. f.handleLiveChatAction = function(a) {
  5405. var b = C(a, xO)
  5406. , c = C(a, yO)
  5407. , d = C(a, o1a)
  5408. , e = C(a, p1a);
  5409. a = C(a, A1a);
  5410. b ? this.unshift("items", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : a && this.handleRemoveChatItemByAuthorAction(a)
  5411. }
  5412. *
  5413. */
  5414.  
  5415. // return this.handleLiveChatAction45(a)
  5416. const { addChatItemAction, addLiveChatTickerItemAction, markChatItemAsDeletedAction,
  5417. removeChatItemAction, markChatItemsByAuthorAsDeletedAction, removeChatItemByAuthorAction, __batchId45__ } = a
  5418.  
  5419. if (addChatItemAction) return;
  5420.  
  5421.  
  5422. const d = Date.now();
  5423.  
  5424.  
  5425. // console.log(Object.keys(a));
  5426.  
  5427. if (this._stackedLCAs_ === null) this._stackedLCAs_ = [];
  5428. const stackArr = this._stackedLCAs_;
  5429. let newStackEntry = null;
  5430. if (addLiveChatTickerItemAction) {
  5431. let isDuplicated = false;
  5432.  
  5433. const newItem = addLiveChatTickerItemAction.item;
  5434. const tickerType = firstObjectKey(newItem);
  5435. if (!tickerType) return;
  5436. const tickerItem = newItem[tickerType];
  5437. const tickerId = tickerItem.id;
  5438. if (!tickerId) return;
  5439.  
  5440. if (this._lastAddItem_ && this._lastAddItem_.id === tickerId) {
  5441. let prevTickerItem = null;
  5442. if (this._lastAddItemInStack_) {
  5443. const entry = stackArr[stackArr.length - 1]; // only consider the last entry
  5444. if (entry && entry.action === 'addItem') {
  5445. prevTickerItem = entry.data; // only consider the first item;
  5446. }
  5447. } else {
  5448. prevTickerItem = this.items[0]; // only consider the first item;
  5449. }
  5450. if (prevTickerItem && prevTickerItem[tickerType]) {
  5451. if (prevTickerItem[tickerType].id === tickerId) {
  5452. isDuplicated = true;
  5453. }
  5454. }
  5455. }
  5456. if (!isDuplicated) {
  5457. this._lastAddItem_ = tickerItem;
  5458. this._lastAddItemInStack_ = true;
  5459. // console.log('newItem', newItem)
  5460.  
  5461. const item = newItem;
  5462. const key = firstObjectKey(item);
  5463. if (key) {
  5464. const itemRenderer = item[key] || 0;
  5465. if (itemRenderer.fullDurationSec > 0) {
  5466. itemRenderer.__actionAt__ = d;
  5467. }
  5468. }
  5469.  
  5470.  
  5471. newStackEntry = { action: 'addItem', data: newItem };
  5472.  
  5473. } else {
  5474. console.log('handleLiveChatAction Repeated Item', tickerItem.id, tickerItem); // happen in both live and playback. Reason Unknown.
  5475. return;
  5476. }
  5477.  
  5478. } else {
  5479. markChatItemAsDeletedAction && (newStackEntry = { action: 'mcItemD', data: markChatItemAsDeletedAction });
  5480. removeChatItemAction && (newStackEntry = { action: 'removeItemById', data: removeChatItemAction.targetId });
  5481. markChatItemsByAuthorAsDeletedAction && (newStackEntry = { action: 'mcItemAD', data: markChatItemsByAuthorAsDeletedAction });
  5482. removeChatItemByAuthorAction && (newStackEntry = { action: 'removeItemA', data: removeChatItemByAuthorAction })
  5483. }
  5484.  
  5485.  
  5486. if (!newStackEntry) return;
  5487. stackArr.push(newStackEntry);
  5488.  
  5489.  
  5490. this._nszlv_++;
  5491. if (this._nszlv_ > 1e9) this._nszlv_ = 9;
  5492. const tid = this._nszlv_;
  5493.  
  5494. newStackEntry.__batchId45__ = __batchId45__ || '';
  5495. newStackEntry.dateTime = Date.now();
  5496.  
  5497.  
  5498. foregroundPromiseFn().then(() => {
  5499.  
  5500. if (tid !== this._nszlv_) return;
  5501. const dateNow = Date.now(); // time difference to shift animation start time shall be considered. (pending)
  5502. const stackArr = this._stackedLCAs_.slice(0);
  5503. this._stackedLCAs_.length = 0;
  5504. this._lastAddItemInStack_ = false;
  5505. let lastDateTime = 0;
  5506. let prevBatchId = '';
  5507. const addItems = [];
  5508. // const previousShouldAnimateIn = this.shouldAnimateIn;
  5509.  
  5510. const addItemsFx = () => {
  5511.  
  5512. if (addItems.length >= 1) {
  5513. const eArr = addItems.slice(0);
  5514. addItems.length = 0;
  5515. if (ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME) {
  5516.  
  5517. const arr = []; // size of arr <= size of eArr
  5518. const d = Date.now();
  5519. for (const item of eArr) {
  5520. const key = firstObjectKey(item);
  5521. if (key) {
  5522.  
  5523.  
  5524. const itemRenderer = item[key] || 0;
  5525. const { durationSec, fullDurationSec, __actionAt__ } = itemRenderer;
  5526. if (__actionAt__ > 0 && durationSec > 0 && fullDurationSec > 0) {
  5527.  
  5528.  
  5529. const offset = d - __actionAt__;
  5530. if (offset > 0 && typeof durationSec === 'number' && typeof fullDurationSec === 'number' && fullDurationSec >= durationSec) {
  5531. const adjustedDurationSec = durationSec - Math.floor(offset / 1000);
  5532. if (adjustedDurationSec < durationSec) { // prevent NaN
  5533. // console.log('adjustedDurationSec', adjustedDurationSec);
  5534. if (adjustedDurationSec > 0) {
  5535. // console.log('offset Sec', Math.floor(offset / 1000));
  5536. itemRenderer.durationSec = adjustedDurationSec;
  5537. } else {
  5538. // if adjustedDurationSec equal 0 or invalid
  5539. continue; // skip adding
  5540. }
  5541. }
  5542.  
  5543. }
  5544.  
  5545. }
  5546.  
  5547. if (fullDurationSec > 0 && durationSec < 1) continue; // fallback check
  5548.  
  5549.  
  5550.  
  5551. }
  5552. arr.push(item)
  5553. // arr.unshift(item);
  5554. }
  5555.  
  5556.  
  5557. // console.log(arr.slice(0))
  5558. this.unshift("items", ...arr);
  5559. } else {
  5560. this.unshift("items", ...eArr);
  5561. }
  5562. }
  5563. }
  5564.  
  5565. for (const entry of stackArr) {
  5566.  
  5567. const { action, data, dateTime, __batchId45__ } = entry;
  5568.  
  5569. const finishLastAction = (
  5570. (prevBatchId !== __batchId45__ && prevBatchId)
  5571. || (dateNow - lastDateTime >= 1000 && dateNow - dateTime < 1000)
  5572. );
  5573.  
  5574. const addPrevItems = addItems.length >= 1 && (finishLastAction || action !== 'addItem');
  5575. lastDateTime = dateTime;
  5576. prevBatchId = __batchId45__;
  5577.  
  5578. // if (dateNow - dateTime >= 1000 && this.shouldAnimateIn) this.shouldAnimateIn = false;
  5579.  
  5580.  
  5581. if (addPrevItems) {
  5582. addItemsFx();
  5583. }
  5584. // if (finishLastAction) {
  5585. // this.updateHighlightedItem();
  5586. // if (!this.shouldAnimateIn) this.shouldAnimateIn = true;
  5587. // }
  5588.  
  5589.  
  5590. if (action === 'addItem') addItems.unshift(data);
  5591. else if (action === 'mcItemD') this.handleMarkChatItemAsDeletedAction(data);
  5592. else if (action === 'removeItemById') this.removeTickerItemById(data);
  5593. else if (action === 'mcItemAD') this.handleMarkChatItemsByAuthorAsDeletedAction(data);
  5594. else if (action === 'removeItemA') this.handleRemoveChatItemByAuthorAction(data);
  5595.  
  5596. }
  5597.  
  5598.  
  5599. // if (previousShouldAnimateIn && !this.shouldAnimateIn) this.shouldAnimateIn = true;
  5600.  
  5601. addItemsFx();
  5602.  
  5603. // if (prevBatchId || dateNow - lastDateTime >= 1000) {
  5604. // this.updateHighlightedItem();
  5605. // if (!this.shouldAnimateIn) this.shouldAnimateIn = true;
  5606. // }
  5607.  
  5608. })
  5609.  
  5610. }
  5611.  
  5612. console.log("AMEND_TICKER_handleLiveChatAction - OK");
  5613. } else {
  5614. console.log("AMEND_TICKER_handleLiveChatAction - NG");
  5615. }
  5616.  
  5617. if (RAF_FIX_keepScrollClamped) {
  5618.  
  5619. // to be improved
  5620.  
  5621. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  5622.  
  5623. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  5624. cProto.keepScrollClamped = function () {
  5625. this._bound_keepScrollClamped = this._bound_keepScrollClamped || this.keepScrollClamped.bind(this);
  5626. this.scrollClampRaf = requestAnimationFrame(this._bound_keepScrollClamped);
  5627. this.maybeClampScroll()
  5628. }
  5629.  
  5630. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  5631. } else {
  5632.  
  5633. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  5634. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  5635. }
  5636.  
  5637. }
  5638.  
  5639.  
  5640. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function' && fnIntegrity(cProto.startScrolling) === '1.44.32' && fnIntegrity(cProto.scrollIncrementally) === '1.82.43') {
  5641. // to be replaced by animator
  5642.  
  5643. cProto.startScrolling = function (a) {
  5644. this.scrollStopHandle && this.cancelAsync(this.scrollStopHandle);
  5645. this.asyncHandle && cancelAnimationFrame(this.asyncHandle);
  5646. this.lastFrameTimestamp = this.scrollStartTime = performance.now();
  5647. this.scrollRatePixelsPerSecond = a;
  5648. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5649. this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally)
  5650. };
  5651.  
  5652. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  5653.  
  5654. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  5655. const b = a - (this.lastFrameTimestamp || 0);
  5656. const rate = this.scrollRatePixelsPerSecond
  5657. const q = b / 1E3 * (rate || 0);
  5658.  
  5659. const sl = this.$.items.scrollLeft;
  5660. // console.log(rate, sl, q)
  5661. if (this.lastFrameTimestamp == this.scrollStartTime) {
  5662.  
  5663. } else if (q > -1e-5 && q < 1e-5) {
  5664.  
  5665. } else {
  5666. let cond1 = sl > 0 && rate > 0 && q > 0;
  5667. let cond2 = sl > 0 && rate < 0 && q < 0;
  5668. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  5669. if (cond1 || cond2 || cond3) {
  5670. this.$.items.scrollLeft += q;
  5671. this.maybeClampScroll();
  5672. this.updateArrows();
  5673. }
  5674. }
  5675.  
  5676. this.lastFrameTimestamp = a;
  5677. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5678. 0 < this.$.items.scrollLeft || rate && 0 < rate ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  5679. } : function (a) {
  5680. const b = a - (this.lastFrameTimestamp || 0);
  5681. this.$.items.scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  5682. this.maybeClampScroll();
  5683. this.updateArrows();
  5684. this.lastFrameTimestamp = a;
  5685. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5686. 0 < this.$.items.scrollLeft || this.scrollRatePixelsPerSecond && 0 < this.scrollRatePixelsPerSecond ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  5687. };
  5688.  
  5689. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  5690. } else {
  5691. assertor(() => fnIntegrity(cProto.startScrolling, '1.44.32'));
  5692. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.82.43'));
  5693. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  5694. }
  5695.  
  5696.  
  5697. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  5698.  
  5699. cProto.attached37 = cProto.attached;
  5700. cProto.detached37 = cProto.detached;
  5701.  
  5702. let naohzId = 0;
  5703. cProto.__naohzId__ = 0;
  5704. cProto.attached = function () {
  5705. Promise.resolve().then(() => {
  5706.  
  5707. const hostElement = this.hostElement || this;
  5708. if (!(hostElement instanceof HTMLElement)) return;
  5709. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  5710. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  5711. // or #chat-messages
  5712. if (!ironPage) return;
  5713.  
  5714. if (this.__naohzId__) removeEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5715. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  5716. this.__naohzId__ = ++naohzId;
  5717. ironPage.setAttribute('naohz', `${+this.__naohzId__}`);
  5718.  
  5719. addEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5720.  
  5721. });
  5722. return this.attached37.apply(this, arguments);
  5723. };
  5724. cProto.detached = function () {
  5725. Promise.resolve().then(() => {
  5726.  
  5727. const ironPage = document.querySelector(`iron-pages[naohz="${+this.__naohzId__}"]`);
  5728. if (!ironPage) return;
  5729.  
  5730. removeEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5731.  
  5732. });
  5733. return this.detached37.apply(this, arguments);
  5734. };
  5735.  
  5736. const clickFade = (u) => {
  5737. u.click();
  5738. };
  5739. cProto.messageBoxClickHandlerForFade = async (evt) => {
  5740.  
  5741. const target = (evt || 0).target || 0;
  5742. if (!target) return;
  5743.  
  5744. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  5745. const is = p.is;
  5746. if (typeof is === 'string' && is) {
  5747.  
  5748. if (is === 'yt-live-chat-pinned-message-renderer') {
  5749. return;
  5750. }
  5751. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  5752. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  5753. if (fade) {
  5754. Promise.resolve(fade).then(clickFade);
  5755. evt && evt.stopPropagation();
  5756. }
  5757. return;
  5758. }
  5759. if (is !== 'yt-live-chat-ticker-renderer') {
  5760. if (is.startsWith('yt-live-chat-ticker-')) return;
  5761. if (!is.endsWith('-renderer')) return;
  5762. }
  5763.  
  5764. } else {
  5765. if ((p.nodeName || '').includes('BUTTON')) return;
  5766. }
  5767.  
  5768. }
  5769. };
  5770.  
  5771. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  5772.  
  5773. } else {
  5774. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  5775. }
  5776.  
  5777.  
  5778. })();
  5779.  
  5780. console.log("[End]");
  5781.  
  5782. console.groupEnd();
  5783.  
  5784. }).catch(console.warn);
  5785.  
  5786.  
  5787. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  5788.  
  5789.  
  5790. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  5791.  
  5792. mightFirstCheckOnYtInit();
  5793. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  5794. console.log("[Begin]");
  5795. (() => {
  5796.  
  5797. const tag = "yt-live-chat-message-input-renderer"
  5798. const dummy = document.createElement(tag);
  5799.  
  5800. const cProto = getProto(dummy);
  5801. if (!cProto || !cProto.attached) {
  5802. console.warn(`proto.attached for ${tag} is unavailable.`);
  5803. return;
  5804. }
  5805.  
  5806. let doHack = false;
  5807. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  5808.  
  5809. // not cancellable
  5810.  
  5811.  
  5812. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  5813.  
  5814. }
  5815.  
  5816. if (doHack) {
  5817.  
  5818. cProto.handleTimeout = function (a) {
  5819. console.log('cProto.handleTimeout', tag)
  5820. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  5821. this.timeoutDurationMs = this.timeoutMs = a;
  5822. this.countdownRatio = 1;
  5823. 0 === this.lastTimeoutTimeMs && rafHub.request(this.boundUpdateTimeout38_)
  5824. };
  5825. cProto.updateTimeout = function (a) {
  5826. console.log('cProto.updateTimeout', tag)
  5827. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  5828. this.lastTimeoutTimeMs && (this.timeoutMs = Math.max(0, this.timeoutMs - (a - this.lastTimeoutTimeMs)),
  5829. this.countdownRatio = this.timeoutMs / this.timeoutDurationMs);
  5830. this.isAttached && this.timeoutMs ? (this.lastTimeoutTimeMs = a,
  5831. rafHub.request(this.boundUpdateTimeout38_)) : this.lastTimeoutTimeMs = 0
  5832. };
  5833.  
  5834. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  5835. } else {
  5836.  
  5837. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  5838. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  5839.  
  5840. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  5841. }
  5842.  
  5843. })();
  5844.  
  5845. console.log("[End]");
  5846.  
  5847. console.groupEnd();
  5848.  
  5849.  
  5850. })
  5851.  
  5852.  
  5853. }
  5854.  
  5855. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  5856.  
  5857.  
  5858. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  5859.  
  5860. mightFirstCheckOnYtInit();
  5861. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  5862. console.log("[Begin]");
  5863. (() => {
  5864.  
  5865. const tag = "yt-emoji-picker-renderer"
  5866. const dummy = document.createElement(tag);
  5867.  
  5868. const cProto = getProto(dummy);
  5869. if (!cProto || !cProto.attached) {
  5870. console.warn(`proto.attached for ${tag} is unavailable.`);
  5871. return;
  5872. }
  5873.  
  5874. let doHack = false;
  5875. if (typeof cProto.animateScroll_ === 'function') {
  5876.  
  5877. // not cancellable
  5878. console.log('animateScroll_', typeof cProto.animateScroll_)
  5879.  
  5880. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  5881.  
  5882. }
  5883.  
  5884. if (doHack) {
  5885.  
  5886. const querySelector = HTMLElement.prototype.querySelector;
  5887. const U = (element) => ({
  5888. querySelector: (selector) => querySelector.call(element, selector)
  5889. });
  5890.  
  5891. cProto.animateScroll_ = function (a) {
  5892. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  5893. if (!this.boundAnimateScroll39_) this.boundAnimateScroll39_ = this.animateScroll_.bind(this);
  5894. this.lastAnimationTime_ || (this.lastAnimationTime_ = a);
  5895. a -= this.lastAnimationTime_;
  5896. 200 > a ? (U(this.hostElement).querySelector("#categories").scrollTop = this.animationStart_ + (this.animationEnd_ - this.animationStart_) * a / 200,
  5897. rafHub.request(this.boundAnimateScroll39_)) : (null != this.animationEnd_ && (U(this.hostElement).querySelector("#categories").scrollTop = this.animationEnd_),
  5898. this.animationEnd_ = this.animationStart_ = null,
  5899. this.lastAnimationTime_ = 0);
  5900. this.updateButtons_()
  5901. }
  5902.  
  5903. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  5904. } else {
  5905.  
  5906. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  5907. }
  5908.  
  5909. })();
  5910.  
  5911. console.log("[End]");
  5912.  
  5913. console.groupEnd();
  5914. });
  5915. }
  5916.  
  5917. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  5918.  
  5919.  
  5920. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  5921.  
  5922. mightFirstCheckOnYtInit();
  5923. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  5924. console.log("[Begin]");
  5925. (() => {
  5926.  
  5927. const tag = "yt-live-chat-docked-message"
  5928. const dummy = document.createElement(tag);
  5929.  
  5930. const cProto = getProto(dummy);
  5931. if (!cProto || !cProto.attached) {
  5932. console.warn(`proto.attached for ${tag} is unavailable.`);
  5933. return;
  5934. }
  5935.  
  5936. let doHack = false;
  5937. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  5938.  
  5939. // cancelable - this.intersectRAF <detached>
  5940. // yt-live-chat-docked-message
  5941. // boundCheckIntersections <-> checkIntersections
  5942. // onDockableMessagesChanged
  5943. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  5944.  
  5945. console.log('detached', typeof cProto.detached)
  5946. console.log('checkIntersections', typeof cProto.checkIntersections)
  5947. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  5948.  
  5949. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  5950.  
  5951. }
  5952.  
  5953. if (doHack) {
  5954.  
  5955. cProto.checkIntersections = function () {
  5956. // console.log('cProto.checkIntersections', tag)
  5957. if (this.dockableMessages.length) {
  5958. this.intersectRAF = rafHub.request(this.boundCheckIntersections);
  5959. let a = this.dockableMessages[0]
  5960. , b = this.hostElement.getBoundingClientRect();
  5961. a = a.getBoundingClientRect();
  5962. let c = a.top - b.top
  5963. , d = 8 >= c;
  5964. c = 8 >= c - this.hostElement.clientHeight;
  5965. if (d) {
  5966. let e;
  5967. for (; d;) {
  5968. e = this.dockableMessages.shift();
  5969. d = this.dockableMessages[0];
  5970. if (!d)
  5971. break;
  5972. d = d.getBoundingClientRect();
  5973. c = d.top - b.top;
  5974. let f = 8 >= c;
  5975. if (8 >= c - a.height)
  5976. if (f)
  5977. a = d;
  5978. else
  5979. return;
  5980. d = f
  5981. }
  5982. this.dock(e)
  5983. } else
  5984. c && this.dockedItem && this.clear()
  5985. } else
  5986. this.intersectRAF = 0
  5987. }
  5988.  
  5989. cProto.onDockableMessagesChanged = function () {
  5990. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  5991. this.dockableMessages.length && !this.intersectRAF && (this.intersectRAF = rafHub.request(this.boundCheckIntersections))
  5992. }
  5993.  
  5994. cProto.detached = function () {
  5995. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  5996. }
  5997.  
  5998. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  5999. } else {
  6000.  
  6001. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  6002. }
  6003.  
  6004. })();
  6005.  
  6006. console.log("[End]");
  6007.  
  6008. console.groupEnd();
  6009.  
  6010. }).catch(console.warn);
  6011.  
  6012. }
  6013.  
  6014. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  6015.  
  6016.  
  6017. customElements.whenDefined("yt-img-shadow").then(() => {
  6018.  
  6019. mightFirstCheckOnYtInit();
  6020. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  6021. console.log("[Begin]");
  6022. (() => {
  6023.  
  6024. const tag = "yt-img-shadow"
  6025. const dummy = document.createElement(tag);
  6026.  
  6027. const cProto = getProto(dummy);
  6028. if (!cProto || !cProto.attached) {
  6029. console.warn(`proto.attached for ${tag} is unavailable.`);
  6030. return;
  6031. }
  6032.  
  6033. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  6034.  
  6035. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  6036. cProto.thumbnailChanged_ = function (a) {
  6037.  
  6038. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  6039. if (!this.oldThumbnail_ && !this.thumbnail) return;
  6040.  
  6041. return this.thumbnailChanged66_.apply(this, arguments)
  6042.  
  6043. }
  6044. console.log("cProto.thumbnailChanged_ - OK");
  6045.  
  6046. } else {
  6047. console.log("cProto.thumbnailChanged_ - NG");
  6048.  
  6049. }
  6050. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  6051.  
  6052. cProto.setSrc66_ = cProto.setSrc_;
  6053. cProto.setSrc_ = function (a) {
  6054. if ((((this || 0).$ || 0).img || 0).src === a) return;
  6055. return this.setSrc66_.apply(this, arguments)
  6056. }
  6057.  
  6058. console.log("cProto.setSrc_ - OK");
  6059. } else {
  6060.  
  6061. console.log("cProto.setSrc_ - NG");
  6062. }
  6063.  
  6064. })();
  6065.  
  6066. console.log("[End]");
  6067.  
  6068. console.groupEnd();
  6069.  
  6070. }).catch(console.warn);
  6071.  
  6072. }
  6073.  
  6074. if (FIX_THUMBNAIL_DATACHANGED) {
  6075.  
  6076.  
  6077.  
  6078. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  6079.  
  6080. mightFirstCheckOnYtInit();
  6081. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  6082. console.log("[Begin]");
  6083. (() => {
  6084.  
  6085. const tag = "yt-live-chat-author-badge-renderer"
  6086. const dummy = document.createElement(tag);
  6087.  
  6088. const cProto = getProto(dummy);
  6089. if (!cProto || !cProto.attached) {
  6090. console.warn(`proto.attached for ${tag} is unavailable.`);
  6091. return;
  6092. }
  6093.  
  6094.  
  6095. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && fnIntegrity(cProto.dataChanged) === '1.159.97') {
  6096.  
  6097.  
  6098.  
  6099. cProto.dataChanged86 = cProto.dataChanged;
  6100. cProto.dataChanged = function (a) {
  6101.  
  6102. /*
  6103.  
  6104. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  6105. b.removeChild(b.firstChild);
  6106. if (a)
  6107. if (a.icon) {
  6108. var c = document.createElement("yt-icon");
  6109. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  6110. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  6111. b.appendChild(c)
  6112. } else if (a.customThumbnail) {
  6113. c = document.createElement("img");
  6114. var d;
  6115. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  6116. b.appendChild(c),
  6117. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  6118. }
  6119.  
  6120. */
  6121.  
  6122. const image = ((this || 0).$ || 0).image
  6123. if (image && a && image.firstElementChild) {
  6124. let exisiting = image.firstElementChild;
  6125. if (exisiting === image.lastElementChild) {
  6126.  
  6127.  
  6128. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  6129.  
  6130. let c = exisiting;
  6131. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  6132. if (c.icon !== "yt-sys-icons:shield-filled") c.icon = "yt-sys-icons:shield-filled";
  6133. if (c.defaultToFilled !== true) c.defaultToFilled = true;
  6134. } else {
  6135. let p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  6136. if (c.icon !== p) c.icon = p;
  6137. if (c.defaultToFilled !== false) c.defaultToFilled = false;
  6138. }
  6139. return;
  6140.  
  6141.  
  6142. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  6143.  
  6144. let c = exisiting;
  6145. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  6146.  
  6147. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  6148. return;
  6149. }
  6150. /*
  6151.  
  6152. var d;
  6153. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  6154.  
  6155.  
  6156. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  6157. */
  6158. }
  6159.  
  6160.  
  6161. }
  6162. }
  6163. return this.dataChanged86.apply(this, arguments)
  6164.  
  6165. }
  6166. console.log("cProto.dataChanged - OK");
  6167.  
  6168. } else {
  6169. assertor(() => fnIntegrity(cProto.dataChanged, '1.159.97'));
  6170. console.log("cProto.dataChanged - NG");
  6171.  
  6172. }
  6173.  
  6174. })();
  6175.  
  6176. console.log("[End]");
  6177.  
  6178. console.groupEnd();
  6179.  
  6180. }).catch(console.warn);
  6181.  
  6182.  
  6183. }
  6184.  
  6185.  
  6186. if (FIX_TOOLTIP_DISPLAY) {
  6187.  
  6188.  
  6189. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  6190.  
  6191. mightFirstCheckOnYtInit();
  6192. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  6193. console.log("[Begin]");
  6194. (() => {
  6195.  
  6196. const tag = "tp-yt-paper-tooltip"
  6197. const dummy = document.createElement(tag);
  6198.  
  6199. const cProto = getProto(dummy);
  6200. if (!cProto || !cProto.attached) {
  6201. console.warn(`proto.attached for ${tag} is unavailable.`);
  6202. return;
  6203. }
  6204.  
  6205. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  6206.  
  6207. cProto._readyClients43 = cProto._readyClients;
  6208. cProto._readyClients = function () {
  6209. let r = cProto._readyClients43.apply(this, arguments);
  6210. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  6211. return r;
  6212. }
  6213.  
  6214. console.log("_readyClients - OK");
  6215.  
  6216. } else {
  6217. console.log("_readyClients - NG");
  6218.  
  6219. }
  6220.  
  6221. if (typeof cProto.show === 'function' && !cProto.show17) {
  6222. cProto.show17 = cProto.show;
  6223. cProto.show = function () {
  6224.  
  6225. let r = this.show17.apply(this, arguments);
  6226. this._showing === true && Promise.resolve().then(() => {
  6227. const tooltip = (this.$ || 0).tooltip;
  6228.  
  6229. if (tooltip && tooltip.firstElementChild === null) {
  6230. let text = tooltip.textContent;
  6231. if (typeof text === 'string' && text.length >= 2) {
  6232. tooltip.textContent = text.trim();
  6233. }
  6234. }
  6235. }).catch(console.warn)
  6236. return r;
  6237. }
  6238.  
  6239. console.log("trim tooltip content - OK");
  6240.  
  6241. } else {
  6242. console.log("trim tooltip content - NG");
  6243.  
  6244. }
  6245.  
  6246. /*
  6247. cProto.updatePosition61 = cProto.updatePosition;
  6248.  
  6249.  
  6250. cProto.updatePosition = function () {
  6251.  
  6252.  
  6253. if (this._target && this.offsetParent) {
  6254. var a = this.offset;
  6255. 14 != this.marginTop && 14 == this.offset && (a = this.marginTop);
  6256. var b = this.offsetParent.getBoundingClientRect()
  6257. , c = this._target.getBoundingClientRect()
  6258. , d = this.getBoundingClientRect()
  6259. , e = (c.width - d.width) / 2
  6260. , h = (c.height - d.height) / 2
  6261. , l = c.left - b.left
  6262. , m = c.top - b.top;
  6263. switch (this.position) {
  6264. case "top":
  6265. var p = l + e;
  6266. var q = m - d.height - a;
  6267. break;
  6268. case "bottom":
  6269. p = l + e;
  6270. q = m + c.height + a;
  6271. break;
  6272. case "left":
  6273. p = l - d.width - a;
  6274. q = m + h;
  6275. break;
  6276. case "right":
  6277. p = l + c.width + a,
  6278. q = m + h;
  6279. }
  6280.  
  6281. if(this.ascee) {
  6282. this.fitToVisibleBounds = false;
  6283. }
  6284. this.fitToVisibleBounds ? (b.left + p + d.width > window.innerWidth ? (this.style.right = "0px",
  6285. this.style.left = "auto") : (this.style.left = Math.max(0, p) + "px",
  6286. this.style.right = "auto"),
  6287. b.top + q + d.height > window.innerHeight ? (this.style.bottom = b.height + "px",
  6288. this.style.top = "auto") : (this.style.top = Math.max(-b.top, q) + "px",
  6289. this.style.bottom = "auto")) : (this.style.left = p + "px",
  6290. this.style.top = q + "px")
  6291. }
  6292. }
  6293.  
  6294. cProto.updateStyles61 = cProto.updateStyles;
  6295. cProto.updateStyles= function(){
  6296. if(this.ascee) return;
  6297. return this.updateStyles61.apply(this,arguments);
  6298. }
  6299. */
  6300.  
  6301.  
  6302. })();
  6303.  
  6304. console.log("[End]");
  6305.  
  6306. console.groupEnd();
  6307.  
  6308. }).catch(console.warn);
  6309.  
  6310.  
  6311.  
  6312. }
  6313.  
  6314.  
  6315.  
  6316. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  6317.  
  6318.  
  6319. const hookDocumentMouseDownSetupFn = () => {
  6320.  
  6321.  
  6322.  
  6323. let muzTimestamp = 0;
  6324. let nszDropdown = null;
  6325.  
  6326.  
  6327.  
  6328. const handlerObject = {
  6329.  
  6330. // mdHandler282 : function (evt) {
  6331. // // console.log(evt, 1, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6332. // if (!evt || !evt.isTrusted) return;
  6333. // muzTimestamp = 0;
  6334. // nszDropdown = null;
  6335.  
  6336. // const hostElement = this.hostElement || this;
  6337. // if (!evt || !evt.isTrusted || !hostElement.hasAttribute('menu-visible')) return;
  6338. // if (!hostElement.contains(evt.target)) return;
  6339. // let targetDropDown = null;
  6340. // for(const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')){
  6341. // if(dropdown && dropdown.positionTarget && hostElement.contains( dropdown.positionTarget)){
  6342. // targetDropDown = dropdown;
  6343. // }
  6344. // }
  6345. // if ((nszDropdown = targetDropDown)) {
  6346. // muzTimestamp = Date.now();
  6347. // evt.stopImmediatePropagation();
  6348. // evt.stopPropagation();
  6349. // }
  6350.  
  6351. // },
  6352.  
  6353.  
  6354. muHandler282: function (evt) {
  6355. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6356. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6357. const dropdown = nszDropdown;
  6358. muzTimestamp = 0;
  6359. nszDropdown = null;
  6360.  
  6361. const kurMPC = kRef(currentMenuPivotWR) || 0;
  6362. const hostElement = kurMPC.hostElement || kurMPC;
  6363. if (!hostElement.hasAttribute('menu-visible')) return;
  6364.  
  6365. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  6366. if (chatBanner) return;
  6367.  
  6368. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  6369.  
  6370. /*
  6371. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6372. if(parentButton) return;
  6373. */
  6374.  
  6375. muzTimestamp = Date.now();
  6376. evt.stopImmediatePropagation();
  6377. evt.stopPropagation();
  6378. Promise.resolve(dropdown).then((dropdown) => {
  6379. dropdown.cancel();
  6380. });
  6381. // document.body.click();
  6382. }
  6383.  
  6384. },
  6385.  
  6386. mlHandler282: function (evt) {
  6387. muzTimestamp = 0;
  6388. nszDropdown = null;
  6389. },
  6390.  
  6391. ckHandler282: function (evt) {
  6392. // console.log(evt, 3, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6393.  
  6394. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6395. if (Date.now() - muzTimestamp < 40) {
  6396.  
  6397. /*
  6398. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6399. if(parentButton) return;
  6400. */
  6401.  
  6402. muzTimestamp = Date.now();
  6403. evt.stopImmediatePropagation();
  6404. evt.stopPropagation();
  6405. }
  6406.  
  6407. },
  6408.  
  6409. tapHandler282: function (evt) {
  6410. // console.log(evt, 2, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6411.  
  6412. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6413. if (Date.now() - muzTimestamp < 40) {
  6414.  
  6415. /*
  6416. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6417. if(parentButton) return;
  6418. */
  6419.  
  6420. muzTimestamp = Date.now();
  6421. evt.stopImmediatePropagation();
  6422. evt.stopPropagation();
  6423. }
  6424.  
  6425. },
  6426.  
  6427.  
  6428. handleEvent(evt) {
  6429.  
  6430.  
  6431. if (evt) {
  6432. const kurMPC = kRef(currentMenuPivotWR) || 0;
  6433. const cnt = kurMPC.inst || kurMPC;
  6434. const hostElement = cnt.hostElement || cnt;
  6435. if (!cnt || cnt.isAttached !== true || hostElement.isConnected !== true) return;
  6436. switch (evt.type) {
  6437. // case 'mousedown':
  6438. // return this.mdHandler282.call(kurMPC, evt);
  6439. case 'mouseup':
  6440. return this.muHandler282(evt);
  6441. case 'mouseleave':
  6442. return this.mlHandler282(evt);
  6443. case 'tap':
  6444. return this.tapHandler282(evt);
  6445. case 'click':
  6446. return this.ckHandler282(evt);
  6447. }
  6448. }
  6449.  
  6450. }
  6451.  
  6452.  
  6453.  
  6454. }
  6455.  
  6456. document.addEventListener('mousedown', function (evt) {
  6457.  
  6458. if (!evt || !evt.isTrusted || !evt.target) return;
  6459.  
  6460.  
  6461.  
  6462. muzTimestamp = 0;
  6463. nszDropdown = null;
  6464.  
  6465. /*
  6466. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6467. if(parentButton){
  6468. const kurMPC = HTMLElement.prototype.closest.call(parentButton, '[whole-message-clickable]') || 0;
  6469. if(kurMPC){
  6470. evt.preventDefault();
  6471. evt.stopImmediatePropagation();
  6472. evt.stopPropagation();
  6473. }
  6474. return;
  6475. }
  6476. */
  6477.  
  6478. /** @type {HTMLElement | null} */
  6479. const kurMP = kRef(currentMenuPivotWR);
  6480. if (!kurMP) return;
  6481. const kurMPC = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0;
  6482.  
  6483. if (!kurMPC || !kurMPC.hasAttribute('whole-message-clickable')) return;
  6484.  
  6485. if (!kurMPC.isClickableChatRow111 || !kurMPC.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPC, evt.target)) return;
  6486.  
  6487. const chatBanner = HTMLElement.prototype.closest.call(kurMPC, 'yt-live-chat-banner-renderer') || 0;
  6488. if (chatBanner) return;
  6489.  
  6490.  
  6491. let targetDropDown = null;
  6492. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  6493. if (dropdown && dropdown.positionTarget === kurMP) {
  6494. targetDropDown = dropdown;
  6495. }
  6496. }
  6497.  
  6498. if (!targetDropDown) return;
  6499.  
  6500.  
  6501. /*
  6502. if (parentButton) {
  6503. evt.preventDefault();
  6504. evt.stopImmediatePropagation();
  6505. evt.stopPropagation();
  6506. currentMenuPivotWR = mWeakRef(kurMPC);
  6507. return;
  6508. }
  6509. */
  6510.  
  6511. if ((nszDropdown = targetDropDown)) {
  6512. muzTimestamp = Date.now();
  6513. evt.stopImmediatePropagation();
  6514. evt.stopPropagation();
  6515. currentMenuPivotWR = mWeakRef(kurMPC);
  6516.  
  6517. const listenOpts = { capture: true, passive: false, once: true };
  6518.  
  6519. // remove unexcecuted eventHandler
  6520. document.removeEventListener('mouseup', handlerObject, listenOpts);
  6521. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  6522. document.removeEventListener('tap', handlerObject, listenOpts);
  6523. document.removeEventListener('click', handlerObject, listenOpts);
  6524.  
  6525. // inject one time eventHandler to by pass events
  6526. document.addEventListener('mouseup', handlerObject, listenOpts);
  6527. document.addEventListener('mouseleave', handlerObject, listenOpts);
  6528. document.addEventListener('tap', handlerObject, listenOpts);
  6529. document.addEventListener('click', handlerObject, listenOpts);
  6530.  
  6531. }
  6532.  
  6533. }, true);
  6534.  
  6535. }
  6536.  
  6537.  
  6538. // yt-live-chat-paid-message-renderer ??
  6539.  
  6540. /*
  6541.  
  6542. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  6543.  
  6544.  
  6545. "yt-live-chat-ticker-paid-message-item-renderer"
  6546. "yt-live-chat-ticker-paid-sticker-item-renderer"
  6547. "yt-live-chat-paid-message-renderer"
  6548. "yt-live-chat-text-message-renderer"
  6549. "yt-live-chat-paid-sticker-renderer"
  6550.  
  6551. */
  6552.  
  6553.  
  6554. whenDefinedMultiple([
  6555.  
  6556. "yt-live-chat-paid-message-renderer",
  6557. "yt-live-chat-membership-item-renderer",
  6558. "yt-live-chat-paid-sticker-renderer",
  6559. "yt-live-chat-text-message-renderer",
  6560. "yt-live-chat-auto-mod-message-renderer",
  6561.  
  6562. /*
  6563. "yt-live-chat-ticker-paid-message-item-renderer",
  6564. "yt-live-chat-ticker-paid-sticker-item-renderer",
  6565. "yt-live-chat-paid-message-renderer",
  6566. "yt-live-chat-text-message-renderer",
  6567. "yt-live-chat-paid-sticker-renderer",
  6568.  
  6569. "yt-live-chat-ticker-sponsor-item-renderer",
  6570. "yt-live-chat-banner-header-renderer",
  6571. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6572. "ytd-sponsorships-live-chat-header-renderer",
  6573. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6574.  
  6575.  
  6576.  
  6577.  
  6578. "yt-live-chat-auto-mod-message-renderer",
  6579. "yt-live-chat-text-message-renderer",
  6580. "yt-live-chat-paid-message-renderer",
  6581.  
  6582. "yt-live-chat-legacy-paid-message-renderer",
  6583. "yt-live-chat-membership-item-renderer",
  6584. "yt-live-chat-paid-sticker-renderer",
  6585. "yt-live-chat-donation-announcement-renderer",
  6586. "yt-live-chat-moderation-message-renderer",
  6587. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6588. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6589. "yt-live-chat-viewer-engagement-message-renderer",
  6590.  
  6591. */
  6592.  
  6593.  
  6594. ]).then(sTags => {
  6595.  
  6596.  
  6597. mightFirstCheckOnYtInit();
  6598. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  6599. console.log("[Begin]");
  6600. let doMouseHook = false;
  6601.  
  6602. const dProto = {
  6603. isClickableChatRow111: function () {
  6604. return (
  6605. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  6606. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  6607. ); // follow .onItemTap(a)
  6608. }
  6609. };
  6610.  
  6611. for (const sTag of sTags) { // ##tag##
  6612.  
  6613.  
  6614. (() => {
  6615.  
  6616.  
  6617.  
  6618. const tag = sTag;
  6619. const dummy = document.createElement(tag);
  6620.  
  6621. const cProto = getProto(dummy);
  6622. if (!cProto || !cProto.attached) {
  6623. console.warn(`proto.attached for ${tag} is unavailable.`);
  6624. return;
  6625. }
  6626.  
  6627.  
  6628. const dCnt = dummy || dummy.inst || 0;
  6629. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  6630.  
  6631.  
  6632.  
  6633.  
  6634.  
  6635.  
  6636. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  6637.  
  6638.  
  6639.  
  6640. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  6641.  
  6642. if (toHookDocumentMouseDown) {
  6643. doMouseHook = true;
  6644. }
  6645.  
  6646.  
  6647.  
  6648. console.log("shouldSupportWholeItemClick Y", tag);
  6649.  
  6650.  
  6651. } else {
  6652.  
  6653. console.log("shouldSupportWholeItemClick N", tag);
  6654. }
  6655.  
  6656.  
  6657.  
  6658. })();
  6659.  
  6660. }
  6661.  
  6662.  
  6663. if (doMouseHook) {
  6664.  
  6665. hookDocumentMouseDownSetupFn();
  6666.  
  6667.  
  6668. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  6669. }
  6670.  
  6671. console.log("[End]");
  6672.  
  6673. console.groupEnd();
  6674.  
  6675.  
  6676. }).catch(console.warn);
  6677.  
  6678.  
  6679. // https://www.youtube.com/watch?v=oQzFi1NO7io
  6680.  
  6681.  
  6682. }
  6683.  
  6684.  
  6685. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  6686.  
  6687. let rr = null;
  6688. const p1 = new Promise(resolve => {
  6689. rr = resolve;
  6690. });
  6691.  
  6692. const p1unlock = () => {
  6693. const f = rr;
  6694. if (f) {
  6695. rr = null;
  6696. f();
  6697. }
  6698. }
  6699.  
  6700. return {
  6701. p1,
  6702. p1unlock,
  6703. assignLock: (targetCnt, timeout) => {
  6704. targetCnt.__showContextMenu_assign_lock__(p1);
  6705. if (timeout) setTimeout(p1unlock, timeout);
  6706. }
  6707. }
  6708.  
  6709. }
  6710.  
  6711. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  6712.  
  6713. document.addEventListener('mousedown', function (evt) {
  6714.  
  6715. const maxloopDOMTreeElements = 4;
  6716. const maxloopYtCompontents = 4;
  6717. let j1 = 0;
  6718. let j2 = 0;
  6719. let target = (evt || 0).target || 0;
  6720. if (!target) return;
  6721.  
  6722.  
  6723. while (target instanceof HTMLElement) {
  6724. if (++j1 > maxloopDOMTreeElements) break;
  6725. if (typeof (target.is || (target.inst || 0).is || null) === 'string') break;
  6726. target = nodeParent(target);
  6727. }
  6728. const components = [];
  6729. while (target instanceof HTMLElement) {
  6730. if (++j2 > maxloopYtCompontents) break;
  6731. if (typeof (target.is || (target.inst || 0).is || null) === 'string') {
  6732. components.push(target);
  6733. }
  6734. if (typeof (target.inst || target).showContextMenu === 'function') break;
  6735. target = target.parentComponent || (target.inst || 0).parentComponent || null;
  6736. }
  6737. if (!(target instanceof HTMLElement)) return;
  6738. const targetCnt = target.inst || target;
  6739. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  6740. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  6741. return;
  6742. }
  6743.  
  6744. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  6745. if (!endpoint) return;
  6746. if (targetCnt.opened || !targetCnt.isAttached) return;
  6747.  
  6748. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  6749. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  6750. }
  6751.  
  6752. let doPreRequest = false;
  6753. if (components.length >= 2 && components[0].id === 'menu-button' && (target.$ || 0)['menu-button'] === components[0]) {
  6754. doPreRequest = true;
  6755. } else if (components.length === 1 && components[0] === target) {
  6756. doPreRequest = true;
  6757. } else if (components.length >= 2 && components[0].id === 'author-photo' && (target.$ || 0)['author-photo'] === components[0]) {
  6758. doPreRequest = true;
  6759. }
  6760. if (doPreRequest === false) {
  6761. console.log('doPreRequest = fasle on showContextMenu', components);
  6762. return;
  6763. }
  6764.  
  6765. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  6766.  
  6767. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  6768. console.log('preRequest on showContextMenu aborted due to stacked network request');
  6769. return;
  6770. }
  6771.  
  6772.  
  6773. const onSuccess = (a) => {
  6774. /*
  6775.  
  6776. dQ() && (a = a.response);
  6777. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  6778. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  6779.  
  6780. */
  6781.  
  6782. a = a.response || a;
  6783.  
  6784. if (!a) {
  6785. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  6786. return;
  6787. }
  6788.  
  6789. let z = null;
  6790. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  6791.  
  6792. if (z) {
  6793. a = z;
  6794. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  6795. }
  6796.  
  6797. };
  6798. const onFailure = (a) => {
  6799.  
  6800. /*
  6801.  
  6802. if (a instanceof Error || a instanceof Object || a instanceof String)
  6803. var b = a;
  6804. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  6805.  
  6806. */
  6807.  
  6808. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  6809. // console.log('onFailure', a)
  6810.  
  6811. };
  6812.  
  6813. if (doPreRequest) {
  6814.  
  6815. let propertyCounter = 0;
  6816. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  6817. const p1Timeout = 800;
  6818. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  6819.  
  6820. try {
  6821.  
  6822. const onSuccessHelperFn = function () {
  6823. pm1.p1unlock();
  6824. if (propertyCounter !== 5) {
  6825. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  6826. return;
  6827. }
  6828. if (this[proxyKey] !== targetCnt) {
  6829. console.log('Error in prerequest for showContextMenu.this');
  6830. return;
  6831. }
  6832. onSuccess(...arguments);
  6833. };
  6834. const onFailureHelperFn = function () {
  6835. pm1.p1unlock();
  6836. if (propertyCounter !== 5) {
  6837. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  6838. return;
  6839. }
  6840. if (this[proxyKey] !== targetCnt) {
  6841. console.log('Error in prerequest for showContextMenu.this');
  6842. return;
  6843. }
  6844. onFailure(...arguments);
  6845.  
  6846. }
  6847. const fakeTargetCnt = new Proxy({
  6848. __showContextMenu_forceNativeRequest__: 1,
  6849. __showContextMenu_sync_mode_request__: 1,
  6850. get handleGetContextMenuResponse_() {
  6851. propertyCounter += 2;
  6852. return onSuccessHelperFn;
  6853. },
  6854. get handleGetContextMenuError() {
  6855. propertyCounter += 3;
  6856. return onFailureHelperFn;
  6857. }
  6858. }, {
  6859. get(_, key, receiver) {
  6860. if (key in _) return _[key];
  6861. if (key === proxyKey) return targetCnt;
  6862.  
  6863. let giveNative = false;
  6864. if (key in targetCnt) {
  6865. if (key === 'data') giveNative = true;
  6866. else if (typeof targetCnt[key] === 'function') giveNative = true;
  6867. }
  6868. if (giveNative) return targetCnt[key];
  6869. }
  6870. });
  6871.  
  6872. const fakeEvent = (() => {
  6873. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  6874. const nf = function () { }
  6875. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  6876.  
  6877. return {
  6878. type: 'tap',
  6879. eventPhase: 0,
  6880. isTrusted: false,
  6881. __composed: true,
  6882. bubbles, cancelable, cancelBubble, timeStamp,
  6883. target, srcElement, defaultPrevented, currentTarget, composed,
  6884. stopPropagation, stopImmediatePropagation, preventDefault
  6885. };
  6886. })(evt);
  6887. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  6888.  
  6889.  
  6890. } catch (e) {
  6891. console.warn(e);
  6892. propertyCounter = 7;
  6893.  
  6894. }
  6895. if (propertyCounter !== 5) {
  6896. console.log('Error in prerequest for showContextMenu', propertyCounter);
  6897. return;
  6898. }
  6899.  
  6900. pm1.assignLock(targetCnt, p1Timeout);
  6901.  
  6902. }
  6903.  
  6904.  
  6905.  
  6906.  
  6907.  
  6908.  
  6909. }, true);
  6910.  
  6911.  
  6912. }
  6913.  
  6914.  
  6915.  
  6916. /*
  6917.  
  6918. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  6919.  
  6920. */
  6921.  
  6922. whenDefinedMultiple([
  6923. "yt-live-chat-ticker-sponsor-item-renderer",
  6924. "yt-live-chat-banner-header-renderer",
  6925. "yt-live-chat-text-message-renderer",
  6926. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6927. "ytd-sponsorships-live-chat-header-renderer",
  6928. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6929.  
  6930. "yt-live-chat-paid-sticker-renderer",
  6931. "yt-live-chat-viewer-engagement-message-renderer",
  6932. "yt-live-chat-paid-message-renderer"
  6933.  
  6934.  
  6935.  
  6936.  
  6937. ]).then(sTags => {
  6938.  
  6939. mightFirstCheckOnYtInit();
  6940. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  6941. console.log("[Begin]");
  6942.  
  6943.  
  6944. const __showContextMenu_mutex__ = new Mutex();
  6945. let __showContextMenu_mutex_unlock__ = null;
  6946. let lastShowMenuTarget = null;
  6947.  
  6948.  
  6949.  
  6950.  
  6951. const wm37 = new WeakMap();
  6952.  
  6953. const dProto = {
  6954.  
  6955.  
  6956. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  6957.  
  6958. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  6959. if (a) {
  6960. if (doDeepCopy) a = deepCopy(a);
  6961. wm37.set(endpoint, a);
  6962. } else {
  6963. wm37.remove(endpoint);
  6964. }
  6965. },
  6966. __getCachedEndpointData__: function (endpoint) {
  6967. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  6968. if (endpoint) return wm37.get(endpoint);
  6969. return null;
  6970. },
  6971. /** @type {(resolvedEndpoint: any) => void 0} */
  6972. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  6973.  
  6974. resolvedEndpoint = deepCopy(resolvedEndpoint);
  6975. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  6976. Promise.resolve(resolvedEndpoint).then(() => {
  6977. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  6978. this.showContextMenu_(resolvedEndpoint);
  6979. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  6980. });
  6981.  
  6982.  
  6983. },
  6984.  
  6985.  
  6986.  
  6987. showContextMenuForCacheReopen: function (a) {
  6988. if (!this.__showContextMenu_forceNativeRequest__) {
  6989. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  6990. if (endpoint) {
  6991. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  6992. if (resolvedEndpoint) {
  6993. this.__showCachedContextMenu__(resolvedEndpoint);
  6994. a && a.stopPropagation()
  6995. return;
  6996. }
  6997. }
  6998. }
  6999. return this.showContextMenu37(a);
  7000. },
  7001.  
  7002. showContextMenuForCacheReopen_: function (a) {
  7003. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  7004. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7005. if (endpoint) {
  7006. const f = this.__cacheResolvedEndpointData__;
  7007. if (typeof f === 'function') f(endpoint, a, true);
  7008. }
  7009. }
  7010. return this.showContextMenu37_(a);
  7011. },
  7012.  
  7013. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  7014.  
  7015. showContextMenuWithDisableScroll: function (a) {
  7016.  
  7017. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7018. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  7019.  
  7020. const parentComponent = this.parentComponent;
  7021. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  7022. parentComponent.allowScroll = false;
  7023. }
  7024. }
  7025.  
  7026. return this.showContextMenu48.apply(this, arguments);
  7027.  
  7028. },
  7029.  
  7030. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  7031.  
  7032. __showContextMenu_mutex_unlock_isEmpty__: () => {
  7033. return __showContextMenu_mutex_unlock__ === null;
  7034. },
  7035.  
  7036. __showContextMenu_assign_lock__: function (p) {
  7037.  
  7038. const mutex = __showContextMenu_mutex__;
  7039.  
  7040. mutex.lockWith(unlock => {
  7041. p.then(unlock);
  7042. });
  7043.  
  7044. },
  7045.  
  7046. showContextMenuWithMutex: function (a) {
  7047. lastShowMenuTarget = this;
  7048.  
  7049. if (this.__showContextMenu_sync_mode_request__) {
  7050.  
  7051. return this.showContextMenu47(a);
  7052. } else {
  7053.  
  7054. const mutex = __showContextMenu_mutex__;
  7055.  
  7056. mutex.lockWith(unlock => {
  7057. if (lastShowMenuTarget !== this) {
  7058. unlock();
  7059. return;
  7060. }
  7061.  
  7062. setTimeout(unlock, 800); // in case network failure
  7063. __showContextMenu_mutex_unlock__ = unlock;
  7064. try {
  7065. this.showContextMenu47(a);
  7066. } catch (e) {
  7067. console.warn(e);
  7068. unlock(); // in case function script error
  7069. }
  7070.  
  7071. });
  7072.  
  7073. }
  7074.  
  7075.  
  7076. },
  7077.  
  7078. showContextMenuWithMutex_: function (a) {
  7079.  
  7080. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  7081. __showContextMenu_mutex_unlock__();
  7082. __showContextMenu_mutex_unlock__ = null;
  7083. }
  7084. return this.showContextMenu47_(a);
  7085.  
  7086. }
  7087.  
  7088. }
  7089.  
  7090. for (const tag of sTags) { // ##tag##
  7091.  
  7092.  
  7093.  
  7094. (() => {
  7095.  
  7096. const dummy = document.createElement(tag);
  7097.  
  7098. const cProto = getProto(dummy);
  7099. if (!cProto || !cProto.attached) {
  7100. console.warn(`proto.attached for ${tag} is unavailable.`);
  7101. return;
  7102. }
  7103.  
  7104.  
  7105.  
  7106.  
  7107. 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) {
  7108.  
  7109. cProto.showContextMenu37_ = cProto.showContextMenu_;
  7110. cProto.showContextMenu37 = cProto.showContextMenu;
  7111.  
  7112. cProto.__showContextMenu_forceNativeRequest__ = 0;
  7113. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  7114. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  7115. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  7116.  
  7117. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  7118.  
  7119. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  7120.  
  7121.  
  7122. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  7123.  
  7124.  
  7125.  
  7126. } else {
  7127.  
  7128. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  7129.  
  7130. }
  7131.  
  7132.  
  7133.  
  7134. 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) {
  7135.  
  7136.  
  7137. cProto.showContextMenu48 = cProto.showContextMenu;
  7138.  
  7139.  
  7140. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  7141.  
  7142.  
  7143.  
  7144. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  7145.  
  7146.  
  7147.  
  7148. } else {
  7149.  
  7150. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  7151.  
  7152. }
  7153.  
  7154.  
  7155.  
  7156.  
  7157.  
  7158. 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) {
  7159.  
  7160. cProto.showContextMenu47_ = cProto.showContextMenu_;
  7161. cProto.showContextMenu47 = cProto.showContextMenu;
  7162.  
  7163. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  7164. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  7165. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  7166. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  7167.  
  7168. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  7169.  
  7170.  
  7171.  
  7172. } else {
  7173.  
  7174. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  7175.  
  7176. }
  7177.  
  7178.  
  7179.  
  7180.  
  7181. })();
  7182.  
  7183. }
  7184.  
  7185.  
  7186.  
  7187. console.log("[End]");
  7188.  
  7189. console.groupEnd();
  7190.  
  7191. }).catch(console.warn);
  7192.  
  7193.  
  7194.  
  7195. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  7196.  
  7197. mightFirstCheckOnYtInit();
  7198. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  7199. console.log("[Begin]");
  7200. (() => {
  7201.  
  7202. const tag = "tp-yt-iron-dropdown";
  7203. const dummy = document.createElement(tag);
  7204.  
  7205. const cProto = getProto(dummy);
  7206. if (!cProto || !cProto.attached) {
  7207. console.warn(`proto.attached for ${tag} is unavailable.`);
  7208. return;
  7209. }
  7210.  
  7211.  
  7212. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  7213. cProto.__deraf_hn__ = function (sId, fn) {
  7214. const rhKey = `_rafHandler_${sId}`;
  7215. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  7216. if (m.has(fn)) return m.get(fn);
  7217. const resFn = () => {
  7218. this.__rafs[sId] = null;
  7219. fn.call(this)
  7220. };
  7221. m.set(fn, resFn);
  7222. m.set(resFn, resFn);
  7223. return resFn;
  7224. };
  7225. cProto.__deraf34 = cProto.__deraf;
  7226. cProto.__deraf = function (a, b) { // sId, fn
  7227. let c = this.__rafs;
  7228. null !== c[a] && cancelAnimationFrame(c[a]);
  7229. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  7230. };
  7231. console.log("USE_VANILLA_DEREF - OK");
  7232. } else {
  7233. console.log("USE_VANILLA_DEREF - NG");
  7234. }
  7235.  
  7236. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  7237. cProto.__deraf66 = cProto.__deraf;
  7238. cProto.__deraf = function (sId, fn) {
  7239. if (this.__byPassRAF__) {
  7240. Promise.resolve().then(() => {
  7241. fn.call(this);
  7242. });
  7243. }
  7244. let r = this.__deraf66.apply(this, arguments);
  7245. return r;
  7246. }
  7247. console.log("FIX_DROPDOWN_DERAF - OK");
  7248. } else {
  7249. console.log("FIX_DROPDOWN_DERAF - NG");
  7250. }
  7251.  
  7252.  
  7253. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  7254.  
  7255. let lastClose = null;
  7256. let lastOpen = null;
  7257. let cid = 0;
  7258.  
  7259. cProto.__mtChanged__ = function (b) {
  7260.  
  7261. Promise.resolve().then(() => {
  7262. this._applyFocus();
  7263. }).then(() => {
  7264. b ? this._renderOpened() : this._renderClosed();
  7265. }).catch(console.warn);
  7266.  
  7267. };
  7268.  
  7269. const __moChanged__ = () => {
  7270. if (!cid) return;
  7271. // console.log(553, !!lastOpen, !!lastClose);
  7272. cid = 0;
  7273. if (lastOpen && !lastClose && lastOpen.isAttached) {
  7274. lastOpen.__mtChanged__(1)
  7275. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  7276. lastClose.__mtChanged__(0);
  7277. }
  7278. lastOpen = null;
  7279. lastClose = null;
  7280. };
  7281.  
  7282.  
  7283. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  7284. cProto._openedChanged66 = cProto._openedChanged;
  7285. cProto._openedChanged = function () {
  7286. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  7287. this.__byPassRAF__ = true;
  7288. let r = this._openedChanged66.apply(this, arguments);
  7289. this.__byPassRAF__ = false;
  7290. return r;
  7291. }
  7292. }
  7293.  
  7294. const pSetGet = (key, pdThis, pdBase) => {
  7295. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  7296. return {
  7297. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  7298. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  7299. };
  7300. };
  7301.  
  7302. cProto.__modifiedMenuPropsFn__ = function () {
  7303. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  7304. const pdBase = Object.getOwnPropertyDescriptors(this)
  7305.  
  7306. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  7307. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  7308. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  7309.  
  7310. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  7311. console.warn('there is setter/getter for autoFitOnAttach');
  7312. return;
  7313. }
  7314. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  7315. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  7316. return;
  7317. }
  7318. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  7319. console.warn('there is NO setter-getter for allowOutsideScroll');
  7320. return;
  7321. }
  7322.  
  7323. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  7324.  
  7325. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  7326.  
  7327. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  7328.  
  7329. Object.defineProperties(this, {
  7330. autoFitOnAttach: {
  7331. get() {
  7332. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  7333. return autoFitOnAttach;
  7334. },
  7335. set(nv) {
  7336. autoFitOnAttach = nv;
  7337. return true;
  7338. },
  7339. enumerable: true,
  7340. configurable: true
  7341. }, expandSizingTargetForScrollbars: {
  7342. get() {
  7343. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  7344. return expandSizingTargetForScrollbars;
  7345. },
  7346. set(nv) {
  7347. expandSizingTargetForScrollbars = nv;
  7348. return true;
  7349. },
  7350. enumerable: true,
  7351. configurable: true
  7352. }, allowOutsideScroll: {
  7353. get() {
  7354. if (this._modifiedMenuPropOn062__) return true;
  7355. return allowOutsideScroll;
  7356. },
  7357. set(nv) {
  7358. allowOutsideScroll = nv;
  7359. this.__AllowOutsideScrollPD__.set.call(this, nv);
  7360. return true;
  7361. },
  7362. enumerable: true,
  7363. configurable: true
  7364. }
  7365. })
  7366. };
  7367.  
  7368. /*
  7369. // ***** position() to be changed. *****
  7370. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  7371.  
  7372. overflow: visible !important;
  7373. min-width: max-content !important;
  7374. max-width: max-content !important;
  7375. max-height: max-content !important;
  7376. min-height: max-content !important;
  7377. white-space: nowrap;
  7378. }
  7379.  
  7380. */
  7381. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  7382.  
  7383. let m34 = 0;
  7384. cProto.__refitByPosition__ = function () {
  7385. m34++;
  7386. if (m34 <= 0) m34 = 0;
  7387. if (m34 !== 1) return;
  7388. const hostElement = this.hostElement || this;
  7389. if (document.visibilityState === 'visible') {
  7390. const sizingTarget = this.sizingTarget;
  7391. if (!sizingTarget) {
  7392. m34 = 0;
  7393. return;
  7394. }
  7395.  
  7396. /*
  7397. let useVisibilityCollapse = true;
  7398. if (HTMLElement.prototype.querySelector.call(sizingTarget, 'yt-icon:empty')) {
  7399. useVisibilityCollapse = false;
  7400. }
  7401.  
  7402. if (useVisibilityCollapse) {
  7403. hostElement.style.visibility = 'collapse';
  7404. sizingTarget.style.visibility = 'collapse';
  7405. } else {
  7406. hostElement.setAttribute('rNgzQ', '');
  7407. sizingTarget.setAttribute('rNgzQ', '');
  7408. }
  7409. */
  7410. hostElement.setAttribute('rNgzQ', '');
  7411. sizingTarget.setAttribute('rNgzQ', '');
  7412.  
  7413. const gn = () => {
  7414. /*
  7415. if (useVisibilityCollapse) {
  7416. hostElement.style.visibility = '';
  7417. sizingTarget.style.visibility = '';
  7418. } else {
  7419. hostElement.removeAttribute('rNgzQ');
  7420. sizingTarget.removeAttribute('rNgzQ');
  7421. }
  7422. */
  7423. hostElement.removeAttribute('rNgzQ');
  7424. sizingTarget.removeAttribute('rNgzQ');
  7425. }
  7426.  
  7427. const an = async () => {
  7428. while (m34 >= 1) {
  7429. await renderReadyPn(sizingTarget);
  7430. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  7431. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  7432. }
  7433. m34--;
  7434. }
  7435. m34 = 0;
  7436. Promise.resolve().then(gn);
  7437. }
  7438. setTimeout(an, 4); // wait those resizing function calls
  7439.  
  7440.  
  7441. } else {
  7442. m34 = 0;
  7443. }
  7444. }
  7445. cProto.position34 = cProto.position
  7446. cProto.position = function () {
  7447. if (this._positionInitialize_) {
  7448. this._positionInitialize_ = 0;
  7449. this.__refitByPosition__();
  7450. }
  7451. let r = cProto.position34.apply(this, arguments);
  7452. return r;
  7453. }
  7454. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  7455.  
  7456. } else {
  7457.  
  7458. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  7459.  
  7460. }
  7461.  
  7462.  
  7463.  
  7464. cProto.__openedChanged = function () {
  7465. this._positionInitialize_ = 1;
  7466. // this.removeAttribute('horizontal-align')
  7467. // this.removeAttribute('vertical-align')
  7468. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  7469. this.__menuTypeCheck__ = true;
  7470. if (CHAT_MENU_SCROLL_UNLOCKING) {
  7471. this._modifiedMenuPropOn062__ = false;
  7472. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7473. // this.autoFitOnAttach = true;
  7474. // this.expandSizingTargetForScrollbars = true;
  7475. // this.allowOutsideScroll = true;
  7476. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  7477. this.__modifiedMenuPropsFn__();
  7478. // this.constrain= function(){}
  7479. // this.position= function(){}
  7480.  
  7481. // this.autoFitOnAttach = true;
  7482. // this.expandSizingTargetForScrollbars = true;
  7483. // this.allowOutsideScroll = true;
  7484. }
  7485. }
  7486. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  7487. let newValue = null;
  7488. const positionTarget = this.positionTarget;
  7489. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  7490. if (this._modifiedMenuPropOn062__ === false) {
  7491. newValue = true;
  7492. }
  7493. } else if (this._modifiedMenuPropOn062__ === true) {
  7494. newValue = false;
  7495. }
  7496. if (newValue !== null) {
  7497. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  7498. this._modifiedMenuPropOn062__ = newValue;
  7499. const afterAllowOutsideScroll = this.allowOutsideScroll;
  7500. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  7501. }
  7502. }
  7503.  
  7504. if (this.opened) {
  7505.  
  7506. Promise.resolve().then(() => {
  7507.  
  7508. this._prepareRenderOpened();
  7509. }).then(() => {
  7510. this._manager.addOverlay(this);
  7511. if (this._manager._overlays.length === 1) {
  7512. lastOpen = this;
  7513. lastClose = null;
  7514. } else {
  7515. return 1;
  7516. }
  7517. // if (cid) {
  7518. // clearTimeout(cid);
  7519. // cid = -1;
  7520. // this.__moChanged__();
  7521. // cid = 0;
  7522. // } else {
  7523. // cid = -1;
  7524. // this.__moChanged__();
  7525. // cid = 0;
  7526. // }
  7527. // cid = cid > 0 ? clearTimeout(cid) : 0;
  7528. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7529. // cid = cid || setTimeout(__moChanged__, delay1);
  7530. cid = cid || requestAnimationFrame(__moChanged__);
  7531. }).then((r) => {
  7532.  
  7533. if (r) this.__mtChanged__(1);
  7534. }).catch(console.warn);
  7535.  
  7536. } else {
  7537. Promise.resolve().then(() => {
  7538. this._manager.removeOverlay(this);
  7539. if (this._manager._overlays.length === 0) {
  7540. lastClose = this;
  7541. lastOpen = null;
  7542. } else {
  7543. return 1;
  7544. }
  7545. // cid = cid > 0 ? clearTimeout(cid) : 0;
  7546. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7547. // cid = cid || setTimeout(__moChanged__, delay1);
  7548. cid = cid || requestAnimationFrame(__moChanged__);
  7549. }).then((r) => {
  7550. if (r) this.__mtChanged__(0);
  7551. }).catch(console.warn);
  7552.  
  7553. }
  7554.  
  7555. }
  7556. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  7557.  
  7558. } else {
  7559.  
  7560. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  7561. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  7562.  
  7563. }
  7564.  
  7565.  
  7566. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  7567.  
  7568. cProto.__openedChanged82 = cProto.__openedChanged;
  7569.  
  7570.  
  7571. cProto.__openedChanged = function () {
  7572.  
  7573. // currentMenuPivotWR = null;
  7574. // console.log(1480, '__openedChanged.A', this.positionTarget)
  7575.  
  7576.  
  7577.  
  7578. // if (this.opened && this.positionTarget) {
  7579.  
  7580. // const positionTarget = this.positionTarget;
  7581. // console.log(1480, '__openedChanged.B', positionTarget)
  7582. // currentMenuPivotWR = mWeakRef(positionTarget);
  7583.  
  7584. // }
  7585.  
  7586. const positionTarget = this.positionTarget;
  7587. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  7588. return this.__openedChanged82.apply(this, arguments);
  7589. }
  7590. }
  7591.  
  7592.  
  7593. // if(FIX_MENU_CAPTURE_SCROLL && typeof cProto.__onCaptureScroll === 'function' && !cProto.__onCaptureScroll66){
  7594.  
  7595. // cProto.__onCaptureScroll66 = cProto.__onCaptureScroll;
  7596.  
  7597. // cProto.__onCaptureScroll = function(a){
  7598.  
  7599. // const q = true;
  7600. // if(this.scrollAction === 'lock' && q && this.opened){
  7601.  
  7602. // // console.log(9107, this.scrollAction, this.__isAnimating, this.opened, a); // lock; __isAnimating = false
  7603. // async function af() {
  7604. // this.__isAnimating && this._finishRenderOpened();
  7605. // if (!this.opened) return;
  7606. // this.__restoreScrollPosition();
  7607. // await new Promise(r => requestAnimationFrame(r));
  7608. // if (!this.opened) return;
  7609. // this.opened && this.__isAnimating && this._finishRenderOpened();
  7610. // if (!this.opened) return;
  7611. // this.__restoreScrollPosition();
  7612. // await new Promise(r => requestAnimationFrame(r));
  7613. // if (!this.opened) return;
  7614. // this.opened && this.__isAnimating && this._finishRenderOpened();
  7615. // if (!this.opened) return;
  7616. // this.opened && !this.__isAnimating && this.refit();
  7617. // }
  7618. // Promise.resolve().then(af);
  7619.  
  7620. // return cProto.__onCaptureScroll66.apply(this, arguments);
  7621. // }else{
  7622.  
  7623. // // console.log(9102, this.scrollAction, this.__isAnimating, this.opened, a); // lock
  7624.  
  7625. // return cProto.__onCaptureScroll66.apply(this, arguments);
  7626. // }
  7627. // }
  7628. // console.log("FIX_MENU_CAPTURE_SCROLL - OK");
  7629. // }else{
  7630. // console.log("FIX_MENU_CAPTURE_SCROLL - NG");
  7631.  
  7632. // }
  7633.  
  7634.  
  7635. })();
  7636.  
  7637. console.log("[End]");
  7638.  
  7639. console.groupEnd();
  7640.  
  7641. }).catch(console.warn);
  7642.  
  7643.  
  7644.  
  7645.  
  7646.  
  7647.  
  7648.  
  7649.  
  7650. /*
  7651.  
  7652.  
  7653.  
  7654.  
  7655.  
  7656. var FU = function() {
  7657. var a = this;
  7658. this.nextHandle_ = 1;
  7659. this.clients_ = {};
  7660. this.JSC$10323_callbacks_ = {};
  7661. this.unsubscribeAsyncHandles_ = {};
  7662. this.subscribe = vl(function(b, c, d) {
  7663. var e = Geb(b);
  7664. if (e in a.clients_)
  7665. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  7666. else {
  7667. a: {
  7668. var h = Geb(b), l;
  7669. for (l in a.unsubscribeAsyncHandles_) {
  7670. var m = a.clients_[l];
  7671. if (m instanceof KO) {
  7672. delete a.clients_[l];
  7673. delete a.JSC$10323_callbacks_[l];
  7674. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  7675. delete a.unsubscribeAsyncHandles_[l];
  7676. i6a(m);
  7677. m.objectId_ = new FQa(h);
  7678. m.register();
  7679. d = m;
  7680. break a
  7681. }
  7682. }
  7683. d.objectSource = b.invalidationId.objectSource;
  7684. d.objectId = h;
  7685. if (b = b.webAuthConfigurationData)
  7686. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  7687. b.pageId && (d.pageId = b.pageId);
  7688. d = new KO(d,a.handleInvalidationData_.bind(a));
  7689. d.register()
  7690. }
  7691. a.clients_[e] = d;
  7692. a.JSC$10323_callbacks_[e] = {}
  7693. }
  7694. d = a.nextHandle_++;
  7695. a.JSC$10323_callbacks_[e][d] = c;
  7696. return d
  7697. })
  7698. };
  7699. FU.prototype.unsubscribe = function(a, b) {
  7700. var c = Geb(a);
  7701. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  7702. !this.JSC$10323_callbacks_[c].length)) {
  7703. var d = this.clients_[c];
  7704. b = Jq.run(function() {
  7705. ei(d);
  7706. delete this.clients_[c];
  7707. delete this.unsubscribeAsyncHandles_[c]
  7708. }
  7709. .bind(this));
  7710. this.unsubscribeAsyncHandles_[c] = b
  7711. }
  7712. }
  7713. ;
  7714.  
  7715.  
  7716. */
  7717.  
  7718.  
  7719.  
  7720.  
  7721. const onManagerFound = (dummyManager) => {
  7722. if (!dummyManager || typeof dummyManager !== 'object') return;
  7723.  
  7724. const mgrProto = dummyManager.constructor.prototype;
  7725.  
  7726. let keyCallbackStore = '';
  7727. for (const [key, v] of Object.entries(dummyManager)) {
  7728. if (key.includes('_callbacks_')) keyCallbackStore = key;
  7729. }
  7730.  
  7731. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  7732.  
  7733. if (mgrProto.unsubscribe16) return;
  7734.  
  7735. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  7736.  
  7737. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  7738. console.log("[Begin]");
  7739.  
  7740.  
  7741. // const isEmptyObject = (a) => Object.keys(a).length === 0;
  7742. const isEmptyObject = ((obj) => (firstKey(obj) === null));
  7743.  
  7744. const idMapper = new Map();
  7745.  
  7746. const convertId = function (objectId) {
  7747. if (!objectId || typeof objectId !== 'string') return null;
  7748.  
  7749. let result = idMapper.get(objectId)
  7750. if (result) return result;
  7751. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  7752. idMapper.set(objectId, result)
  7753. return result;
  7754. }
  7755.  
  7756.  
  7757. const rafHandleHolder = [];
  7758.  
  7759. let pzw = 0;
  7760. let lza = 0;
  7761. const rafHandlerFn = () => {
  7762. pzw = 0;
  7763. if (rafHandleHolder.length === 1) {
  7764. const f = rafHandleHolder[0];
  7765. rafHandleHolder.length = 0;
  7766. f();
  7767. } else if (rafHandleHolder.length > 1) {
  7768. const arr = rafHandleHolder.slice(0);
  7769. rafHandleHolder.length = 0;
  7770. for (const fn of arr) fn();
  7771. }
  7772. };
  7773.  
  7774.  
  7775. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  7776.  
  7777. const checkIntegrityForSubscribe = (mgr) => {
  7778. if (mgr
  7779. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  7780. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  7781.  
  7782. const ns = new Set(Object.keys(mgr));
  7783. const ms = new Set(Object.keys(mgr.constructor.prototype));
  7784.  
  7785. if (ns.size >= 6 && ms.size >= 4) {
  7786. // including 'subscribe18'
  7787. // 'unsubscribe16', 'subscribe19'
  7788.  
  7789. let r = 0;
  7790. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  7791. r += ns.has(k) ? 1 : 0;
  7792. }
  7793. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  7794. r += ms.has(k) ? 1 : 0;
  7795. }
  7796. if (r === 10) {
  7797. const isObject = (c) => (c || 0).constructor === Object;
  7798.  
  7799. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  7800.  
  7801. return true;
  7802. }
  7803.  
  7804.  
  7805. }
  7806.  
  7807. }
  7808.  
  7809.  
  7810. }
  7811. return false;
  7812. }
  7813.  
  7814. mgrProto.subscribe19 = function (o, f, opts) {
  7815.  
  7816. const ct_clients_ = this.clients_ || 0;
  7817. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  7818.  
  7819. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  7820.  
  7821. let objectId = ((o || 0).invalidationId || 0).objectId;
  7822. if (!objectId) return this.subscribe18.apply(this, arguments);
  7823. objectId = convertId(objectId);
  7824.  
  7825. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  7826.  
  7827. if (ct_clients_[objectId]) {
  7828. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  7829. }
  7830.  
  7831. return this.subscribe18.apply(this, arguments);
  7832. }
  7833.  
  7834. mgrProto.unsubscribe = function (o, d) {
  7835. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  7836. this.subscribe18 = this.subscribe;
  7837. this.subscribe = this.subscribe19;
  7838. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  7839. }
  7840. const ct_clients_ = this.clients_;
  7841. const ct_handles_ = this.unsubscribeAsyncHandles_;
  7842. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  7843.  
  7844. let objectId = ((o || 0).invalidationId || 0).objectId;
  7845. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  7846.  
  7847. objectId = convertId(objectId);
  7848.  
  7849.  
  7850. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  7851.  
  7852. const callbacks = this[keyCallbackStore] || 0;
  7853. const callbackObj = callbacks[objectId] || 0;
  7854.  
  7855.  
  7856. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  7857. const w = ct_clients_[objectId];
  7858. --lza;
  7859. if (lza < -1e9) lza = -1;
  7860. const qta = lza;
  7861. rafHandleHolder.push(() => {
  7862. if (qta === ct_handles_[objectId]) {
  7863. const o = {
  7864. callbacks, callbackObj,
  7865. client: ct_clients_[objectId],
  7866. handle: ct_handles_[objectId]
  7867. };
  7868. let p = 0;
  7869. try {
  7870. if (ct_clients_[objectId] === w) {
  7871. w && "function" === typeof w.dispose && w.dispose();
  7872. delete ct_clients_[objectId];
  7873. delete ct_handles_[objectId];
  7874. p = 1;
  7875. } else {
  7876. // w && "function" === typeof w.dispose && w.dispose();
  7877. // delete ct_clients_[objectId];
  7878. // delete ct_handles_[objectId];
  7879. p = 2;
  7880. }
  7881. } catch (e) {
  7882. console.warn(e);
  7883. }
  7884. console.log(`unsubscribed: ${p}`, this, o);
  7885. }
  7886. });
  7887. ct_handles_[objectId] = qta;
  7888. if (pzw === 0) {
  7889. pzw = requestAnimationFrame(rafHandlerFn);
  7890. }
  7891. }
  7892. }
  7893.  
  7894.  
  7895. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  7896.  
  7897. } else {
  7898.  
  7899. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  7900. }
  7901.  
  7902. console.log("[End]");
  7903.  
  7904. console.groupEnd();
  7905.  
  7906. }
  7907.  
  7908.  
  7909.  
  7910. /*
  7911.  
  7912.  
  7913. a.prototype.async = function(e, h) {
  7914. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  7915. }
  7916. ;
  7917. a.prototype.cancelAsync = function(e) {
  7918. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  7919. }
  7920.  
  7921. */
  7922.  
  7923.  
  7924.  
  7925. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  7926.  
  7927. let __dummyManager__ = null;
  7928.  
  7929. mightFirstCheckOnYtInit();
  7930. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  7931. console.log("[Begin]");
  7932. (() => {
  7933.  
  7934. const tag = "yt-invalidation-continuation"
  7935. const dummy = document.createElement(tag);
  7936.  
  7937. const cProto = getProto(dummy);
  7938. if (!cProto || !cProto.attached) {
  7939. console.warn(`proto.attached for ${tag} is unavailable.`);
  7940. return;
  7941. }
  7942.  
  7943. const dummyManager = (dummy.inst || dummy).manager_ || 0;
  7944. __dummyManager__ = dummyManager;
  7945.  
  7946. 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) {
  7947.  
  7948.  
  7949. const rafHub = new RAFHub();
  7950.  
  7951. rafHub.keepRAF = true;
  7952. cProto.async71 = cProto.async;
  7953. cProto.cancelAsync71 = cProto.cancelAsync;
  7954.  
  7955. // mostly for subscription timeoutMs 10000ms
  7956. let mcw = 1; // 1, 3, 5, ...
  7957. let arr = new Map();
  7958.  
  7959. let __asyncInited__ = 0;
  7960. let __timeoutStartId__ = null;
  7961. const __asyncInit__ = () => {
  7962.  
  7963. if (__asyncInited__) return;
  7964. __asyncInited__ = 1;
  7965.  
  7966. __timeoutStartId__ = setTimeout(() => { });
  7967. mcw = __timeoutStartId__ * 2 + 1;
  7968.  
  7969. setInterval(() => {
  7970.  
  7971. if (!arr.length) return;
  7972.  
  7973. const p = Date.now();
  7974. let deleteKeys = [];
  7975. arr.forEach((entry, key) => {
  7976.  
  7977.  
  7978. if (entry.cid === -1) {
  7979. entry.cid = -2;
  7980. } else if (entry.cid === -2) {
  7981.  
  7982. let offset = p - entry.add
  7983. if (offset < 0) offset = 0;
  7984. let delay2 = entry.delay - offset;
  7985. if (delay2 < 0) delay2 = 0;
  7986. entry.cid = setTimeout(entry.q(), delay2);
  7987. entry.q = null;
  7988.  
  7989. } else if (entry.add + entry.delay < p) {
  7990. deleteKeys.push(key);
  7991.  
  7992. }
  7993.  
  7994. })
  7995.  
  7996. for (const key of deleteKeys) arr.delete(key);
  7997.  
  7998. }, 2000)
  7999.  
  8000. }
  8001.  
  8002.  
  8003.  
  8004.  
  8005. cProto.async = function (e, h) {
  8006.  
  8007. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  8008.  
  8009. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  8010.  
  8011. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  8012.  
  8013.  
  8014. if (!this.__asyncInited__) {
  8015. this.__asyncInited__ = 1;
  8016. __asyncInit__();
  8017. }
  8018. mcw += 2; // 2K+3, 2K+4, ...
  8019. if (mcw > 1e9) mcw = mcw % 1e4;
  8020. const cid = mcw;
  8021. const q = () => {
  8022. return () => {
  8023. console.log('async h > 8000');
  8024. e.call(this);
  8025. }
  8026. }
  8027. // setTimeout(q, delay)
  8028. arr.set(cid, {
  8029. cid: -1, // -1 -> -2 -> cid
  8030. add: Date.now(),
  8031. q,
  8032. delay: h
  8033. });
  8034. // console.log('cid-async', cid)
  8035. return cid;
  8036.  
  8037. }
  8038.  
  8039.  
  8040. cProto.cancelAsync = function (e) {
  8041.  
  8042. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  8043.  
  8044. // console.log('cid-unasync', e)
  8045.  
  8046. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  8047.  
  8048. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  8049.  
  8050. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  8051.  
  8052. if (!arr.has(e)) return; // duplciated cancel
  8053.  
  8054. const entry = arr.get(e);
  8055. if (entry.cid < 0) {
  8056. entry.cid = 0;
  8057. arr.delete(e);
  8058. } else {
  8059. clearTimeout(entry.cid); // cid >= 1
  8060. entry.cid = 0;
  8061. arr.delete(e);
  8062. }
  8063.  
  8064. } else {
  8065.  
  8066. return this.cancelAsync71(e);
  8067.  
  8068. }
  8069.  
  8070. }
  8071.  
  8072. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  8073.  
  8074. } else {
  8075. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  8076.  
  8077. }
  8078.  
  8079. })();
  8080.  
  8081. console.log("[End]");
  8082.  
  8083. console.groupEnd();
  8084.  
  8085.  
  8086.  
  8087. onManagerFound(__dummyManager__);
  8088.  
  8089. }).catch(console.warn);
  8090.  
  8091.  
  8092.  
  8093.  
  8094. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  8095.  
  8096.  
  8097. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  8098.  
  8099.  
  8100. mightFirstCheckOnYtInit();
  8101. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  8102. console.log("[Begin]");
  8103. (() => {
  8104.  
  8105. const tag = "yt-live-interactivity-component-background"
  8106. const dummy = document.createElement(tag);
  8107.  
  8108. const cProto = getProto(dummy);
  8109. if (!cProto || !cProto.attached) {
  8110. console.warn(`proto.attached for ${tag} is unavailable.`);
  8111. return;
  8112. }
  8113.  
  8114.  
  8115. cProto.__toStopAfterRun__ = function (hostElement) {
  8116. let mo = new MutationObserver(() => {
  8117. mo.disconnect();
  8118. mo.takeRecords();
  8119. mo = null;
  8120. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  8121. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  8122. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  8123. });
  8124. });
  8125. mo.observe(hostElement, { subtree: true, childList: true });
  8126. }
  8127.  
  8128. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  8129.  
  8130. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  8131. cProto.maybeLoadAnimationBackground = function () {
  8132. let toRun = true;
  8133. let stopAfterRun = false;
  8134. if (!this.__bypassDisableAnimationBackground__) {
  8135. let doFix = false;
  8136. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  8137. if (!this.lottieAnimation) {
  8138. doFix = true;
  8139. }
  8140. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  8141. doFix = true;
  8142. }
  8143. if (doFix) {
  8144. if (this.useAnimationBackground === true) {
  8145. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  8146. }
  8147. toRun = true;
  8148. stopAfterRun = true;
  8149. }
  8150. }
  8151. if (toRun) {
  8152. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  8153. this.__toStopAfterRun__(this.hostElement); // primary
  8154. }
  8155. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  8156. if (stopAfterRun && this.lottieAnimation) {
  8157. this.lottieAnimation.stop(); // fallback if no mutation
  8158. }
  8159. return r;
  8160. }
  8161. }
  8162.  
  8163. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION${INTERACTIVITY_BACKGROUND_ANIMATION} - OK`);
  8164.  
  8165. } else {
  8166. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION${INTERACTIVITY_BACKGROUND_ANIMATION} - NG`);
  8167.  
  8168. }
  8169.  
  8170. })();
  8171.  
  8172. console.log("[End]");
  8173.  
  8174. console.groupEnd();
  8175.  
  8176.  
  8177. }).catch(console.warn);
  8178.  
  8179. }
  8180.  
  8181.  
  8182. }
  8183.  
  8184.  
  8185.  
  8186.  
  8187. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  8188.  
  8189. const fixJsonParse = () => {
  8190.  
  8191. let p1 = window.onerror;
  8192.  
  8193. try {
  8194. JSON.parse("{}");
  8195. } catch (e) {
  8196. console.warn(e);
  8197. }
  8198.  
  8199. let p2 = window.onerror;
  8200.  
  8201. if (p1 !== p2) {
  8202.  
  8203.  
  8204. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  8205. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  8206. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  8207. );
  8208.  
  8209. 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");
  8210.  
  8211. console.groupEnd();
  8212.  
  8213. }
  8214.  
  8215. }
  8216.  
  8217. if (CHECK_JSONPRUNE) {
  8218. promiseForCustomYtElementsReady.then(fixJsonParse);
  8219. }
  8220.  
  8221. });
  8222.  
  8223.  
  8224.  
  8225. })({ IntersectionObserver });