YouTube 超快聊天

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

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

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