YouTube 超快聊天

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

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

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