YouTube 超快聊天

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

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

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