YouTube 超快聊天

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

当前为 2024-05-21 提交的版本,查看 最新版本

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