YouTube 超快聊天

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

当前为 2024-06-29 提交的版本,查看 最新版本

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