YouTube 超快聊天

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

当前为 2024-04-07 提交的版本,查看 最新版本

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