YouTube 超快聊天

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

目前为 2023-08-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.30.3
  4. // @license MIT
  5. // @name:ja YouTube スーパーファーストチャット
  6. // @name:zh-TW YouTube 超快聊天
  7. // @name:zh-CN YouTube 超快聊天
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/super-fast-chat.png
  9. // @namespace UserScript
  10. // @match https://www.youtube.com/live_chat*
  11. // @match https://www.youtube.com/live_chat_replay*
  12. // @author CY Fung
  13. // @run-at document-start
  14. // @grant none
  15. // @unwrap
  16. // @allFrames true
  17. // @inject-into page
  18. //
  19. // @compatible firefox Violentmonkey
  20. // @compatible firefox Tampermonkey
  21. // @compatible firefox FireMonkey
  22. // @compatible chrome Violentmonkey
  23. // @compatible chrome Tampermonkey
  24. // @compatible opera Violentmonkey
  25. // @compatible opera Tampermonkey
  26. // @compatible safari Stay
  27. // @compatible edge Violentmonkey
  28. // @compatible edge Tampermonkey
  29. // @compatible brave Violentmonkey
  30. // @compatible brave Tampermonkey
  31. //
  32. // @description Ultimate Performance Boost for YouTube Live Chats
  33. // @description:ja YouTubeのライブチャットの究極のパフォーマンスブースト
  34. // @description:zh-TW YouTube直播聊天的終極性能提升
  35. // @description:zh-CN YouTube直播聊天的终极性能提升
  36. //
  37. // ==/UserScript==
  38.  
  39. ((__CONTEXT__) => {
  40. 'use strict';
  41.  
  42. 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
  43. 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.
  44. 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
  45.  
  46. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages
  47. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  48. const USE_WILL_CHANGE_CONTROLLER = false; // FALSE for the majority
  49. const ENABLE_DELAYED_CHAT_OCCURRENCE_PREFERRED = true; // 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.
  50. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  51.  
  52. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  53. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  54. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  55. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  56.  
  57. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  58. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  59.  
  60. // Replace requestAnimationFrame timers with custom implementation
  61. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  62. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  63. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  64. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  65.  
  66. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  67. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  68.  
  69. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  70. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  71.  
  72. // Data Manipulation for Participants (Participant List)
  73. // << if DO_PARTICIPANT_LIST_HACKS >>
  74. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  75. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  76. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  77. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  78. // << end >>
  79.  
  80. // show more button
  81. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  82.  
  83. // faster stampDomArray_ for participants list creation
  84. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  85. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  86.  
  87. // reuse yt components
  88. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  89.  
  90. // images <Group#I01>
  91. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  92. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  93. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  94.  
  95. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  96. // << if DO_LINK_PREFETCH >>
  97. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  98. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  99. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  100. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  101. // << end >>
  102.  
  103. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  104. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  105. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  106.  
  107. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  108. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  109.  
  110. const ATTEMPT_ANIMATED_TICKER_BACKGROUND = 'steps' // false OR '' for disabled, 'linear', 'steps' for easing-function
  111. // << if ATTEMPT_ANIMATED_TICKER_BACKGROUND >>
  112. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  113. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  114. // [limiting 500 max steps] is recommended for "confortable visual change"
  115. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  116. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  117. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  118. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  119. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  120. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  121. // << end >>
  122.  
  123. const FIX_TOOLTIP_DISPLAY = true;
  124. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true;
  125. const USE_VANILLA_DEREF = true;
  126. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  127. const FIX_MENU_REOPEN_RENDER_PERFORMANCE = true;
  128. // const FIX_MENU_CAPTURE_SCROLL = true;
  129. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  130.  
  131. const RAF_FIX_keepScrollClamped = true;
  132. const RAF_FIX_scrollIncrementally = true;
  133.  
  134. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  135.  
  136. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  137. /*
  138.  
  139. ### Time Approach
  140.  
  141. // all below values can make the time interval > 250ms
  142. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  143. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  144. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  145. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  146. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  147. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  148.  
  149. ### Pixel Check
  150. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  151. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  152. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  153.  
  154. ### Example - totalDuration = 280000
  155. totalDuration 280000
  156. stepInterval 0.5
  157. numOfSteps = Math.round(100 / stepInterval) = 200
  158. time interval = 280000 / 200 = 1400ms <acceptable>
  159.  
  160. ### Example - totalDuration = 18000
  161. totalDuration 18000
  162. stepInterval 5
  163. numOfSteps = Math.round(100 / stepInterval) = 20
  164. time interval = 18000 / 20 = 900ms <acceptable>
  165.  
  166. ### Example - totalDuration = 5000
  167. totalDuration 5000
  168. stepInterval 5
  169. numOfSteps = Math.round(100 / stepInterval) = 20
  170. time interval = 5000 / 20 = 250ms <threshold value>
  171.  
  172. ### Example - totalDuration = 3600
  173. totalDuration 3600
  174. stepInterval 5
  175. numOfSteps = Math.round(100 / stepInterval) = 20
  176. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  177.  
  178. */
  179.  
  180. // =======================================================================================================
  181.  
  182. // AUTOMAICALLY DETERMINED
  183. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  184. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  185. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  186. let runTickerClassName = 'run-ticker';
  187.  
  188. const dummyImgURL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  189. /*
  190. WebP: data:image/webp;base64,UklGRjAB
  191. PNG: data:image/png;base64,iVBORw0KGg==
  192. JPEG: data:image/jpeg;base64,/9j/4AA=
  193. GIF: data:image/gif;base64,R0lGODlhAQABAIA=
  194. BMP: data:image/bmp;base64,Qk1oAAAA
  195. SVG: data:image/svg+xml;base64,PHN2Zy8+Cg==
  196.  
  197. WebP: data:image/webp;base64,AAAAAAA=
  198. PNG: data:image/png;base64,AAAAAAA=
  199. JPEG: data:image/jpeg;base64,AAAAAAA=
  200. GIF: data:image/gif;base64,AAAAAAA=
  201. BMP: data:image/bmp;base64,AAAAAAA=
  202.  
  203. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  204.  
  205.  
  206. */
  207.  
  208. // image sizing code
  209. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  210.  
  211.  
  212. // function KC(a, b, c, d) {
  213. // d = void 0 === d ? "width" : d;
  214. // if (!a || !a.length)
  215. // return null;
  216. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  217. // var e = window.devicePixelRatio;
  218. // 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"));
  219. // HC = e
  220. // } else
  221. // HC || (HC = window.devicePixelRatio);
  222. // e = HC;
  223. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  224. // if (z("kevlar_tuner_min_thumbnail_quality"))
  225. // return a[0].url || null;
  226. // e = a.length;
  227. // if (z("kevlar_tuner_max_thumbnail_quality"))
  228. // return a[e - 1].url || null;
  229. // if (c)
  230. // for (var h = 0; h < e; h++)
  231. // if (0 <= a[h].url.indexOf(c))
  232. // return a[h].url || null;
  233. // for (c = 0; c < e; c++)
  234. // if (a[c][d] >= b)
  235. // return a[c].url || null;
  236. // for (b = e - 1; 0 < b; b--)
  237. // if (a[b][d])
  238. // return a[b].url || null;
  239. // return a[0].url || null
  240. // }
  241.  
  242. const { IntersectionObserver } = __CONTEXT__;
  243.  
  244. /** @type {globalThis.PromiseConstructor} */
  245. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  246.  
  247. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  248. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  249.  
  250. // necessity of cssText3_smooth_transform_position to be checked.
  251. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  252.  
  253. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  254. position: static !important;
  255. }
  256.  
  257. `: '';
  258.  
  259. // fallback if dummy style fn fails
  260. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  261.  
  262. /* optional */
  263. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  264. height: auto !important;
  265. min-height: unset !important;
  266. }
  267.  
  268. #items.style-scope.yt-live-chat-item-list-renderer {
  269. transform: translateY(0px) !important;
  270. }
  271.  
  272. /* optional */
  273.  
  274. `: '';
  275.  
  276. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  277.  
  278. /* ------------------------------------------------------------------------------------------------------------- */
  279.  
  280. 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 {
  281. contain: layout style;
  282. }
  283.  
  284. #items.style-scope.yt-live-chat-item-list-renderer {
  285. contain: layout paint style;
  286. }
  287.  
  288. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  289. contain: style;
  290. }
  291.  
  292. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  293. contain: size style;
  294. }
  295.  
  296. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  297. contain: size layout paint style;
  298. }
  299.  
  300. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  301. contain: layout paint style;
  302. }
  303.  
  304. 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 {
  305. contain: layout style;
  306. }
  307.  
  308. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  309. contain: layout paint style;
  310. }
  311.  
  312. /* ------------------------------------------------------------------------------------------------------------- */
  313.  
  314. ` : '';
  315.  
  316. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  317.  
  318. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  319. top: 4px;
  320. transition-property: top;
  321. bottom: unset;
  322. }
  323.  
  324. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  325. top: -42px;
  326. }
  327.  
  328. `: '';
  329.  
  330. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  331.  
  332. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  333. contain: layout style;
  334. }
  335.  
  336. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  337. overflow: visible;
  338. }
  339.  
  340. `: '';
  341.  
  342. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  343.  
  344. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  345. --yt-live-chat-action-panel-top-border: none;
  346. }
  347.  
  348. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  349. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  350. }
  351.  
  352. html #panel-pages.yt-live-chat-renderer {
  353. border-top: 0;
  354. border-bottom: 0;
  355. }
  356.  
  357. `: '';
  358.  
  359. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  360.  
  361. img,
  362. yt-img-shadow[height][width],
  363. yt-img-shadow {
  364. content-visibility: visible !important;
  365. }
  366.  
  367. ` : '';
  368.  
  369. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  370.  
  371. /* remove YouTube constant will-change */
  372. /* constant value will slow down the performance; default auto */
  373.  
  374. /* www-player.css */
  375. html .ytp-contextmenu,
  376. html .ytp-settings-menu {
  377. will-change: unset;
  378. }
  379.  
  380. /* frequently matched elements */
  381. html .fill.yt-interaction,
  382. html .stroke.yt-interaction,
  383. html .yt-spec-touch-feedback-shape__fill,
  384. html .yt-spec-touch-feedback-shape__stroke {
  385. will-change: unset;
  386. }
  387.  
  388. /* live_chat_polymer.js */
  389. /*
  390. html .toggle-button.tp-yt-paper-toggle-button,
  391. html #primaryProgress.tp-yt-paper-progress,
  392. html #secondaryProgress.tp-yt-paper-progress,
  393. html #onRadio.tp-yt-paper-radio-button,
  394. html .fill.yt-interaction,
  395. html .stroke.yt-interaction,
  396. html .yt-spec-touch-feedback-shape__fill,
  397. html .yt-spec-touch-feedback-shape__stroke {
  398. will-change: unset;
  399. }
  400. */
  401.  
  402. /* desktop_polymer_enable_wil_icons.js */
  403. /* html .fill.yt-interaction,
  404. html .stroke.yt-interaction, */
  405. html tp-yt-app-header::before,
  406. html tp-yt-iron-list,
  407. html #items.tp-yt-iron-list > *,
  408. html #onRadio.tp-yt-paper-radio-button,
  409. html .toggle-button.tp-yt-paper-toggle-button,
  410. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  411. html #items.ytd-post-multi-image-renderer,
  412. html #items.ytd-horizontal-card-list-renderer,
  413. html #items.yt-horizontal-list-renderer,
  414. html #left-arrow.yt-horizontal-list-renderer,
  415. html #right-arrow.yt-horizontal-list-renderer,
  416. html #items.ytd-video-description-infocards-section-renderer,
  417. html #items.ytd-video-description-music-section-renderer,
  418. html #chips.ytd-feed-filter-chip-bar-renderer,
  419. html #chips.yt-chip-cloud-renderer,
  420. html #items.ytd-merch-shelf-renderer,
  421. html #items.ytd-product-details-image-carousel-renderer,
  422. html ytd-video-preview,
  423. html #player-container.ytd-video-preview,
  424. html #primaryProgress.tp-yt-paper-progress,
  425. html #secondaryProgress.tp-yt-paper-progress,
  426. html ytd-miniplayer[enabled] /* ,
  427. html .yt-spec-touch-feedback-shape__fill,
  428. html .yt-spec-touch-feedback-shape__stroke */ {
  429. will-change: unset;
  430. }
  431.  
  432. /* other */
  433. .ytp-videowall-still-info-content[class],
  434. .ytp-suggestion-image[class] {
  435. will-change: unset !important;
  436. }
  437.  
  438. ` : '';
  439.  
  440. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  441. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  442.  
  443. elzm-fonts {
  444. visibility: collapse;
  445. position: fixed;
  446. top: -10px;
  447. left: -10px;
  448. font-size: 10pt;
  449. line-height: 100%;
  450. width: 100px;
  451. height: 100px;
  452. transform: scale(0.1);
  453. transform: scale(0.01);
  454. transform: scale(0.001);
  455. transform-origin: 0 0;
  456. contain: strict;
  457. display: block;
  458.  
  459. pointer-events: none !important;
  460. user-select: none !important;
  461. }
  462.  
  463. elzm-fonts[id]#elzm-fonts-yk75g {
  464. user-select: none !important;
  465. pointer-events: none !important;
  466. }
  467.  
  468. elzm-font {
  469. visibility: collapse;
  470. position: absolute;
  471. line-height: 100%;
  472. width: 100px;
  473. height: 100px;
  474. contain: strict;
  475. display: block;
  476.  
  477. user-select: none !important;
  478. pointer-events: none !important;
  479. }
  480.  
  481. elzm-font::before {
  482. visibility: collapse;
  483. position: absolute;
  484. line-height: 100%;
  485. width: 100px;
  486. height: 100px;
  487. contain: strict;
  488. display: block;
  489.  
  490. 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';
  491.  
  492. user-select: none !important;
  493. pointer-events: none !important;
  494. }
  495.  
  496. `: '';
  497.  
  498. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  499. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  500. -webkit-backdrop-filter: none;
  501. backdrop-filter: none;
  502. }
  503. `: '';
  504.  
  505. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  506.  
  507. @keyframes blinker-miuzp {
  508. 0%, 60%, 100% {
  509. opacity: 1;
  510. }
  511. 30% {
  512. opacity: 0.6;
  513. }
  514. }
  515.  
  516. yt-icon-button#show-more.has-new-messages-miuzp {
  517. animation: blinker-miuzp 1.74s linear infinite;
  518. }
  519.  
  520. `: '';
  521.  
  522.  
  523. const addCss = () => `
  524.  
  525. @property --ticker-rtime {
  526. syntax: "<percentage>";
  527. inherits: false;
  528. initial-value: 0%;
  529. }
  530.  
  531. /*
  532. .run-ticker {
  533. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  534. }
  535.  
  536. .run-ticker-test {
  537. background: #00000001;
  538. }
  539.  
  540. .run-ticker-forced,
  541. yt-live-chat-ticker-renderer #items > * > #container.run-ticker-forced,
  542. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker-forced[class]
  543. {
  544. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2)) !important;
  545. }
  546. */
  547.  
  548. .run-ticker {
  549. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  550. }
  551.  
  552. .run-ticker,
  553. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  554. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  555. {
  556. background: var(--ticker-bg) !important;
  557. }
  558.  
  559. yt-live-chat-ticker-dummy777-item-renderer {
  560. background: #00000001;
  561. }
  562.  
  563. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  564. position: fixed !important;
  565. top: -1000px !important;
  566. left: -1000px !important;
  567. font-size: 1px !important;
  568. color: transparent !important;
  569. pointer-events: none !important;
  570. z-index: -1 !important;
  571. contain: strict !important;
  572. box-sizing: border-box !important;
  573. pointer-events: none !important;
  574. user-select: none !important;
  575. max-width: 1px !important;
  576. max-height: 1px !important;
  577. overflow: hidden !important;
  578. visibility: collapse !important;
  579. display: none !important;
  580. }
  581.  
  582. yt-live-chat-ticker-dummy777-item-renderer #container {
  583. background: inherit;
  584. }
  585.  
  586.  
  587. ${cssText8_fonts_pre_render}
  588.  
  589. ${cssText9_no_backdrop_filter_when_menu_shown}
  590.  
  591. @supports (contain: layout paint style) {
  592.  
  593. ${cssText5}
  594.  
  595. }
  596.  
  597. @supports (color: var(--general)) {
  598.  
  599. html {
  600. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  601. }
  602.  
  603. ${cssText3_smooth_transform_position}
  604.  
  605. ${cssText7c_will_change_unset}
  606.  
  607. ${cssText7b_content_visibility_unset}
  608.  
  609. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  610. overflow-y: scroll;
  611. padding-right: 0;
  612. }
  613.  
  614. ${cssText4_smooth_transform_forced_props}
  615.  
  616. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  617. pointer-events: none !important;
  618. }
  619.  
  620. #continuations, #continuations * {
  621. contain: strict;
  622. position: fixed;
  623. top: 2px;
  624. height: 1px;
  625. width: 2px;
  626. height: 1px;
  627. visibility: collapse;
  628. }
  629.  
  630. ${cssText6b_show_more_button}
  631.  
  632. ${cssText6d_input_panel_border}
  633.  
  634. ${cssText6c_input_panel_overflow}
  635.  
  636. }
  637.  
  638.  
  639. @supports (overflow-anchor: auto) {
  640.  
  641. .no-anchor * {
  642. overflow-anchor: none;
  643. }
  644. .no-anchor > item-anchor {
  645. overflow-anchor: auto;
  646. }
  647.  
  648. item-anchor {
  649.  
  650. height:1px;
  651. width: 100%;
  652. transform: scaleY(0.00001);
  653. transform-origin:0 0;
  654. contain: strict;
  655. opacity:0;
  656. display:flex;
  657. position:relative;
  658. flex-shrink:0;
  659. flex-grow:0;
  660. margin-bottom:0;
  661. overflow:hidden;
  662. box-sizing:border-box;
  663. visibility: visible;
  664. content-visibility: visible;
  665. contain-intrinsic-size: auto 1px;
  666. pointer-events:none !important;
  667.  
  668. }
  669.  
  670. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  671. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  672. }
  673.  
  674. html item-anchor {
  675.  
  676. height: 1px;
  677. width: 1px;
  678. top: auto;
  679. left: auto;
  680. right: auto;
  681. bottom: auto;
  682. transform: translateY(-1px);
  683. position: absolute;
  684. z-index: -1;
  685.  
  686. }
  687.  
  688. }
  689.  
  690. @supports (color: var(--pre-rendering)) {
  691.  
  692. @keyframes dontRenderAnimation {
  693. 0% {
  694. background-position-x: 3px;
  695. }
  696. 100% {
  697. background-position-x: 4px;
  698. }
  699. }
  700.  
  701. .dont-render[class] {
  702. /* visibility: collapse !important; */
  703. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://greasyfork.org/scripts/469878/discussions/197267 */
  704.  
  705. transform: scale(0.01) !important;
  706. transform: scale(0.00001) !important;
  707. transform: scale(0.0000001) !important;
  708. transform-origin: 0 0 !important;
  709. z-index: -1 !important;
  710. contain: strict !important;
  711. box-sizing: border-box !important;
  712.  
  713. height: 1px !important;
  714. height: 0.1px !important;
  715. height: 0.01px !important;
  716. height: 0.0001px !important;
  717. height: 0.000001px !important;
  718.  
  719. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  720.  
  721. pointer-events: none !important;
  722. user-select: none !important;
  723.  
  724. }
  725.  
  726. #sk35z {
  727. display: block !important;
  728.  
  729. visibility: collapse !important;
  730.  
  731. transform: scale(0.01) !important;
  732. transform: scale(0.00001) !important;
  733. transform: scale(0.0000001) !important;
  734. transform-origin: 0 0 !important;
  735. z-index: -1 !important;
  736. contain: strict !important;
  737. box-sizing: border-box !important;
  738.  
  739. height: 1px !important;
  740. height: 0.1px !important;
  741. height: 0.01px !important;
  742. height: 0.0001px !important;
  743. height: 0.000001px !important;
  744.  
  745. position: absolute !important;
  746. top: -1000px !important;
  747. left: -1000px !important;
  748.  
  749. }
  750.  
  751. }
  752.  
  753. [rNgzQ] {
  754. opacity: 0.1 !important;
  755. opacity: 0.01 !important;
  756. opacity: 0.001 !important;
  757. opacity: 0.0001 !important;
  758. opacity: 0.00001 !important;
  759. opacity: 0.00000001 !important;
  760.  
  761. pointer-events: none !important;
  762. }
  763.  
  764. ${cssText10_show_more_blinker}
  765.  
  766. `;
  767.  
  768.  
  769. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  770.  
  771. // Create a unique key for the script and check if it is already running
  772. const hkey_script = 'mchbwnoasqph';
  773. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  774. win[hkey_script] = true;
  775.  
  776. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  777.  
  778. let te4 = setTimeout(() => { }); // dummy; skip timerId only;
  779. if (te4 < 3) {
  780. setTimeout(() => { });
  781. setTimeout(() => { });
  782. }
  783.  
  784. }
  785.  
  786. class Mutex {
  787.  
  788. constructor() {
  789. this.p = Promise.resolve()
  790. }
  791.  
  792. /**
  793. * @param {(lockResolve: () => void)} f
  794. */
  795. lockWith(f) {
  796. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  797. }
  798.  
  799. }
  800.  
  801. function dr(s) {
  802. // reserved for future use
  803. return s;
  804. // return window.deWeakJS ? window.deWeakJS(s) : s;
  805. }
  806.  
  807. const getProto = (element) => {
  808. if (element) {
  809. const cnt = element.inst || element;
  810. return cnt.constructor.prototype || null;
  811. }
  812. return null;
  813. }
  814.  
  815. const assertor = (f) => f() || console.assert(false, f + "");
  816.  
  817. const fnIntegrity = (f, d) => {
  818. if (!f || typeof f !== 'function') {
  819. console.warn('f is not a function', f);
  820. return;
  821. }
  822. let p = f + "", s = 0, j = -1, w = 0;
  823. for (let i = 0, l = p.length; i < l; i++) {
  824. const t = p[i];
  825. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  826. if (j < i - 1) w++;
  827. j = i;
  828. } else {
  829. s++;
  830. }
  831. }
  832. let itz = `${f.length}.${s}.${w}`;
  833. if (!d) {
  834. return itz;
  835. } else {
  836. return itz === d;
  837. }
  838. }
  839.  
  840.  
  841. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  842.  
  843. let ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE = false;
  844. const isContainSupport = CSS.supports('contain', 'layout paint style');
  845. if (!isContainSupport) {
  846. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  847. } else {
  848. ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE = true;
  849. }
  850.  
  851. let ENABLE_OVERFLOW_ANCHOR_CAPABLE = false;
  852. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  853. if (!isOverflowAnchorSupport) {
  854. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  855. } else {
  856. ENABLE_OVERFLOW_ANCHOR_CAPABLE = true;
  857. }
  858.  
  859. 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.
  860.  
  861. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && ENABLE_OVERFLOW_ANCHOR_CAPABLE && ENABLE_NO_SMOOTH_TRANSFORM;
  862. const ENABLE_DELAYED_CHAT_OCCURRENCE = ENABLE_DELAYED_CHAT_OCCURRENCE_PREFERRED && ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE && ENABLE_OVERFLOW_ANCHOR && ENABLE_NO_SMOOTH_TRANSFORM && NOT_FIREFOX;
  863.  
  864. let hasTimerModified = null;
  865. const DO_CHECK_TICKER_BACKGROUND_OVERRIDED = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND || ENABLE_RAF_HACK_TICKERS;
  866.  
  867. const fxOperator = (proto, propertyName) => {
  868. let propertyDescriptorGetter = null;
  869. try {
  870. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  871. } catch (e) { }
  872. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  873. try {
  874.  
  875. return propertyDescriptorGetter.call(dr(e));
  876. } catch (e) { }
  877. return e[propertyName];
  878. } : (e) => e[propertyName];
  879. };
  880.  
  881. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  882. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  883. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  884. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  885. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  886.  
  887. const groupCollapsed = (text1, text2) => {
  888.  
  889. console.groupCollapsed(`%c${text1}%c${text2}`,
  890. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  891. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  892. );
  893. }
  894.  
  895.  
  896. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  897. const onRegistryReady = (callback) => {
  898. if (typeof customElements === 'undefined') {
  899. if (!('__CE_registry' in document)) {
  900. // https://github.com/webcomponents/polyfills/
  901. Object.defineProperty(document, '__CE_registry', {
  902. get() {
  903. // return undefined
  904. },
  905. set(nv) {
  906. if (typeof nv == 'object') {
  907. delete this.__CE_registry;
  908. this.__CE_registry = nv;
  909. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  910. }
  911. return true;
  912. },
  913. enumerable: false,
  914. configurable: true
  915. })
  916. }
  917. let eventHandler = (evt) => {
  918. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  919. const f = callback;
  920. callback = null;
  921. eventHandler = null;
  922. f();
  923. };
  924. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  925. } else {
  926. callback();
  927. }
  928. };
  929.  
  930. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  931.  
  932. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  933.  
  934. return new Promise(resolve => {
  935.  
  936. let ro = new ResizeObserver(entries => {
  937. if (entries && entries.length >= 1) {
  938. resolve();
  939. ro.disconnect();
  940. ro = null;
  941. }
  942. });
  943. ro.observe(sizingTarget);
  944.  
  945.  
  946.  
  947. });
  948.  
  949. } : (sizingTarget) => {
  950.  
  951.  
  952. return new Promise(resolve => {
  953.  
  954. let io = new IntersectionObserver(entries => {
  955. if (entries && entries.length >= 1) {
  956. resolve();
  957. io.disconnect();
  958. io = null;
  959. }
  960. });
  961. io.observe(sizingTarget);
  962.  
  963.  
  964.  
  965. });
  966.  
  967. };
  968.  
  969. /* globals WeakRef:false */
  970.  
  971. /** @type {(o: Object | null) => WeakRef | null} */
  972. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  973.  
  974. /** @type {(wr: Object | null) => Object | null} */
  975. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  976.  
  977. const { addCssManaged } = (() => {
  978.  
  979. const addFontPreRendering = () => {
  980.  
  981. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  982.  
  983. let efsContainer = document.createElement('elzm-fonts');
  984. efsContainer.id = 'elzm-fonts-yk75g'
  985.  
  986. const arr = [];
  987. let p = document.createElement('elzm-font');
  988. arr.push(p);
  989.  
  990. if (ENABLE_FONT_PRE_RENDERING & 1) {
  991. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  992.  
  993. p = document.createElement('elzm-font');
  994. p.style.fontWeight = size;
  995. arr.push(p);
  996. }
  997. }
  998.  
  999. if (ENABLE_FONT_PRE_RENDERING & 2) {
  1000. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1001.  
  1002. p = document.createElement('elzm-font');
  1003. p.style.fontFamily = 'Roboto';
  1004. p.style.fontWeight = size;
  1005. arr.push(p);
  1006. }
  1007. }
  1008.  
  1009. if (ENABLE_FONT_PRE_RENDERING & 4) {
  1010. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1011.  
  1012. p = document.createElement('elzm-font');
  1013. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  1014. p.style.fontWeight = size;
  1015. arr.push(p);
  1016. }
  1017. }
  1018.  
  1019.  
  1020. if (ENABLE_FONT_PRE_RENDERING & 8) {
  1021. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1022.  
  1023. p = document.createElement('elzm-font');
  1024. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  1025. p.style.fontWeight = size;
  1026. arr.push(p);
  1027. }
  1028. }
  1029.  
  1030.  
  1031. if (ENABLE_FONT_PRE_RENDERING & 16) {
  1032. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1033.  
  1034. p = document.createElement('elzm-font');
  1035. p.style.fontFamily = 'sans-serif';
  1036. p.style.fontWeight = size;
  1037. arr.push(p);
  1038. }
  1039. }
  1040.  
  1041. console.log('number of elzm-font elements', arr.length);
  1042.  
  1043. HTMLElement.prototype.append.apply(efsContainer, arr);
  1044.  
  1045. (document.body || document.documentElement).appendChild(efsContainer);
  1046.  
  1047.  
  1048. console.log('elzm-font elements have been added to the page for rendering.');
  1049.  
  1050. console.groupEnd();
  1051.  
  1052. }
  1053.  
  1054. let isCssAdded = false;
  1055.  
  1056. function addCssElement() {
  1057. let s = document.createElement('style');
  1058. s.id = 'ewRvC';
  1059. return s;
  1060. }
  1061.  
  1062. const addCssManaged = () => {
  1063. if (!isCssAdded && document.documentElement && document.head) {
  1064. isCssAdded = true;
  1065. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  1066. if (ENABLE_FONT_PRE_RENDERING) {
  1067. Promise.resolve().then(addFontPreRendering)
  1068. }
  1069. }
  1070. }
  1071.  
  1072. return { addCssManaged };
  1073. })();
  1074.  
  1075.  
  1076. const { setupStyle } = (() => {
  1077.  
  1078. const sp7 = Symbol();
  1079.  
  1080. const proxyHelperFn = (dummy) => ({
  1081.  
  1082. get(target, prop) {
  1083. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  1084. },
  1085. set(target, prop, value) {
  1086. if (!(prop in dummy)) {
  1087. target[prop] = value;
  1088. }
  1089. return true;
  1090. },
  1091. has(target, prop) {
  1092. return (prop in target);
  1093. },
  1094. deleteProperty(target, prop) {
  1095. return true;
  1096. },
  1097. ownKeys(target) {
  1098. return Object.keys(target);
  1099. },
  1100. defineProperty(target, key, descriptor) {
  1101. return Object.defineProperty(target, key, descriptor);
  1102. },
  1103. getOwnPropertyDescriptor(target, key) {
  1104. return Object.getOwnPropertyDescriptor(target, key);
  1105. },
  1106.  
  1107. });
  1108.  
  1109. const setupStyle = (m1, m2) => {
  1110. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  1111.  
  1112. const dummy1v = {
  1113. transform: '',
  1114. height: '',
  1115. minHeight: '',
  1116. paddingBottom: '',
  1117. paddingTop: ''
  1118. };
  1119.  
  1120. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  1121. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  1122. dummy1v[k] = dummyStyleFn(k);
  1123. }
  1124.  
  1125. const dummy1p = proxyHelperFn(dummy1v);
  1126. const sp1v = new Proxy(m1.style, dummy1p);
  1127. const sp2v = new Proxy(m2.style, dummy1p);
  1128. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  1129. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  1130. m1.removeAttribute("style");
  1131. m2.removeAttribute("style");
  1132.  
  1133. }
  1134.  
  1135. return { setupStyle };
  1136.  
  1137. })();
  1138.  
  1139.  
  1140.  
  1141. function setThumbnails(config) {
  1142.  
  1143. const { baseObject, thumbnails, flag0, imageLinks } = config;
  1144.  
  1145. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  1146.  
  1147.  
  1148. if (thumbnails && thumbnails.length > 0) {
  1149. if (flag0 > 0 && thumbnails.length > 1) {
  1150. let pSize = 0;
  1151. let newThumbnails = [];
  1152. for (const thumbnail of thumbnails) {
  1153. if (!thumbnail || !thumbnail.url) continue;
  1154. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  1155. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  1156. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  1157. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  1158. newThumbnails.push(thumbnail);
  1159. if (imageLinks) imageLinks.add(thumbnail.url);
  1160. }
  1161. if (squarePhoto && condSize && leastSizeFulfilled) {
  1162. pSize = thumbnail.width;
  1163. }
  1164. }
  1165. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  1166. baseObject.thumbnails = newThumbnails;
  1167. } else {
  1168. newThumbnails.length = 0;
  1169. }
  1170. newThumbnails = null;
  1171. } else {
  1172. for (const thumbnail of thumbnails) {
  1173. if (thumbnail && thumbnail.url) {
  1174. if (imageLinks) imageLinks.add(thumbnail.url);
  1175. }
  1176. }
  1177. }
  1178. }
  1179.  
  1180. }
  1181. }
  1182.  
  1183. function fixLiveChatItem(item, imageLinks) {
  1184. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  1185. if (liveChatTextMessageRenderer) {
  1186. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  1187. if (messageRuns && messageRuns.length > 0) {
  1188. for (const run of messageRuns) {
  1189. const emojiImage = (((run || 0).emoji || 0).image || 0);
  1190. setThumbnails({
  1191. baseObject: emojiImage,
  1192. thumbnails: emojiImage.thumbnails,
  1193. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  1194. imageLinks
  1195. });
  1196. }
  1197. }
  1198. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  1199. setThumbnails({
  1200. baseObject: authorPhoto,
  1201. thumbnails: authorPhoto.thumbnails,
  1202. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  1203. imageLinks
  1204. });
  1205. }
  1206. }
  1207.  
  1208.  
  1209. const flagsFnOnInterval = (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS) ? (() => {
  1210.  
  1211. const flags = () => {
  1212. try {
  1213. return ytcfg.data_.EXPERIMENT_FLAGS;
  1214. } catch (e) { }
  1215. return null;
  1216. };
  1217.  
  1218. const flagsForced = () => {
  1219. try {
  1220. return ytcfg.data_.EXPERIMENTS_FORCED_FLAGS;
  1221. } catch (e) { }
  1222. return null;
  1223. };
  1224.  
  1225. const flagsFn = (EXPERIMENT_FLAGS) => {
  1226.  
  1227. if (!EXPERIMENT_FLAGS) return;
  1228.  
  1229. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1230. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1231. EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true;
  1232. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1233. }
  1234. }
  1235.  
  1236. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1237. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1238. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1239. }
  1240.  
  1241. };
  1242.  
  1243. const uf = (EXPERIMENT_FLAGS) => {
  1244. if (EXPERIMENT_FLAGS === undefined) EXPERIMENT_FLAGS = flags();
  1245. if (EXPERIMENT_FLAGS) {
  1246. flagsFn(EXPERIMENT_FLAGS);
  1247. flagsFn(flagsForced());
  1248. }
  1249. }
  1250.  
  1251. uf();
  1252.  
  1253. const flagsFnOnInterval = (setInterval, clearInterval) => {
  1254.  
  1255. uf();
  1256. let cidFlags = 0;
  1257. let kd = 0;
  1258. new Promise(flagResolve => {
  1259.  
  1260. const flagTimer = () => {
  1261. const EXPERIMENT_FLAGS = flags();
  1262. if (!EXPERIMENT_FLAGS) return;
  1263. uf(EXPERIMENT_FLAGS);
  1264. if (kd > 0) return;
  1265. kd = 1;
  1266. const delay1000 = new Promise(resolve => setTimeout(resolve, 1000));
  1267. const moDeferred = new Promise(resolve => {
  1268. let mo = new MutationObserver(() => {
  1269. if (mo) {
  1270. mo.disconnect();
  1271. mo.takeRecords();
  1272. mo = null;
  1273. resolve();
  1274. }
  1275. });
  1276. mo.observe(document, { subtree: true, childList: true });
  1277. });
  1278. Promise.race([delay1000, moDeferred]).then(flagResolve);
  1279. };
  1280.  
  1281. uf();
  1282. cidFlags = setInterval(flagTimer, 1);
  1283. }).then(() => {
  1284. if (cidFlags > 0) clearInterval(cidFlags);
  1285. cidFlags = 0;
  1286. uf();
  1287. });
  1288.  
  1289. }
  1290.  
  1291. return flagsFnOnInterval;
  1292.  
  1293. })() : null;
  1294.  
  1295. let kptPF = null;
  1296. const emojiPrefetched = new Set();
  1297. const authorPhotoPrefetched = new Set();
  1298.  
  1299. function linker(link, rel, href, _as) {
  1300. return new Promise(resolve => {
  1301. if (!link) link = document.createElement('link');
  1302. link.rel = rel;
  1303. if (_as) link.setAttribute('as', _as);
  1304. link.onload = function () {
  1305. resolve({
  1306. link: this,
  1307. success: true
  1308. })
  1309. this.remove();
  1310. };
  1311. link.onerror = function () {
  1312. resolve({
  1313. link: this,
  1314. success: false
  1315. });
  1316. this.remove();
  1317. };
  1318. link.href = href;
  1319. document.head.appendChild(link);
  1320. link = null;
  1321. });
  1322. }
  1323.  
  1324.  
  1325. const cleanContext = async (win) => {
  1326. const waitFn = requestAnimationFrame; // shall have been binded to window
  1327. try {
  1328. let mx = 16; // MAX TRIAL
  1329. const frameId = 'vanillajs-iframe-v1';
  1330. /** @type {HTMLIFrameElement | null} */
  1331. let frame = document.getElementById(frameId);
  1332. let removeIframeFn = null;
  1333. if (!frame) {
  1334. frame = document.createElement('iframe');
  1335. frame.id = 'vanillajs-iframe-v1';
  1336. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  1337. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  1338. n.appendChild(frame);
  1339. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  1340. const root = document.documentElement;
  1341. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  1342. removeIframeFn = (setTimeout) => {
  1343. const removeIframeOnDocumentReady = (e) => {
  1344. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1345. win = null;
  1346. setTimeout(() => {
  1347. n.remove();
  1348. n = null;
  1349. }, 200);
  1350. }
  1351. if (document.readyState !== 'loading') {
  1352. removeIframeOnDocumentReady();
  1353. } else {
  1354. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1355. }
  1356. }
  1357. }
  1358. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  1359. const fc = frame.contentWindow;
  1360. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  1361. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval } = fc;
  1362. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval };
  1363. for (let k in res) res[k] = res[k].bind(win); // necessary
  1364. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  1365. res.animate = HTMLElement.prototype.animate;
  1366. return res;
  1367. } catch (e) {
  1368. console.warn(e);
  1369. return null;
  1370. }
  1371. };
  1372.  
  1373. cleanContext(win).then(__CONTEXT__ => {
  1374. if (!__CONTEXT__) return null;
  1375.  
  1376. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate } = __CONTEXT__;
  1377.  
  1378. let aeConstructor = null;
  1379.  
  1380. // << if ENABLE_VIDEO_PROGRESS_STATE_FIX >>
  1381. let pairForPauseResume = 0; // each increasion = number of ticker
  1382. let pairForPauseResumeM = 0;
  1383. // << end >>
  1384.  
  1385. // << __openedChanged82 >>
  1386. let currentMenuPivotWR = null;
  1387.  
  1388. // << if DO_PARTICIPANT_LIST_HACKS >>
  1389. const beforeParticipantsMap = new WeakMap();
  1390. // << end >>
  1391.  
  1392.  
  1393.  
  1394. // << if onRegistryReadyForDOMOperations >>
  1395.  
  1396. let dt0 = Date.now() - 2000;
  1397. const dateNow = () => Date.now() - dt0;
  1398. // let lastScroll = 0;
  1399. // let lastLShow = 0;
  1400. let lastWheel = 0;
  1401. let lastMouseDown = 0;
  1402. let lastMouseUp = 0;
  1403. let currentMouseDown = false;
  1404. let lastTouchDown = 0;
  1405. let lastTouchUp = 0;
  1406. let currentTouchDown = false;
  1407. let lastUserInteraction = 0;
  1408.  
  1409. let scrollChatFn = null;
  1410.  
  1411. let skipDontRender = true; // true first; false by flushActiveItems_
  1412. let allowDontRender = null;
  1413.  
  1414. // ---- #items mutation ----
  1415. let sk35zResolveFn = null;
  1416. let firstList = true;
  1417.  
  1418. // << end >>
  1419.  
  1420. class RAFHub {
  1421. constructor() {
  1422. /** @type {number} */
  1423. this.startAt = 8170;
  1424. /** @type {number} */
  1425. this.counter = 0;
  1426. /** @type {number} */
  1427. this.rid = 0;
  1428. /** @type {Map<number, FrameRequestCallback>} */
  1429. this.funcs = new Map();
  1430. const funcs = this.funcs;
  1431. /** @type {FrameRequestCallback} */
  1432. this.bCallback = this.mCallback.bind(this);
  1433. this.pClear = () => funcs.clear();
  1434. }
  1435. /** @param {DOMHighResTimeStamp} highResTime */
  1436. mCallback(highResTime) {
  1437. this.rid = 0;
  1438. Promise.resolve().then(this.pClear);
  1439. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  1440. }
  1441. /** @param {FrameRequestCallback} f */
  1442. request(f) {
  1443. if (this.counter > 1e9) this.counter = 9;
  1444. let cid = this.startAt + (++this.counter);
  1445. this.funcs.set(cid, f);
  1446. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  1447. return cid;
  1448. }
  1449. /** @param {number} cid */
  1450. cancel(cid) {
  1451. cid = +cid;
  1452. if (cid > 0) {
  1453. if (cid <= this.startAt) {
  1454. return cancelAnimationFrame(cid);
  1455. }
  1456. if (this.rid > 0) {
  1457. this.funcs.delete(cid);
  1458. if (this.funcs.size === 0) {
  1459. cancelAnimationFrame(this.rid);
  1460. this.rid = 0;
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466.  
  1467. function basePrefetching() {
  1468.  
  1469. new Promise(resolve => {
  1470.  
  1471. if (document.readyState !== 'loading') {
  1472. resolve();
  1473. } else {
  1474. win.addEventListener("DOMContentLoaded", resolve, false);
  1475. }
  1476.  
  1477. }).then(() => {
  1478. const hostL1 = [
  1479. 'https://www.youtube.com', 'https://googlevideo.com',
  1480. 'https://googleapis.com', 'https://accounts.youtube.com',
  1481. 'https://www.gstatic.com', 'https://ggpht.com',
  1482. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  1483. ];
  1484.  
  1485. const hostL2 = [
  1486. 'https://youtube.com',
  1487. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  1488. ];
  1489.  
  1490. let link = null;
  1491.  
  1492. function kn() {
  1493.  
  1494. link = document.createElement('link');
  1495. if (link.relList && link.relList.supports) {
  1496. 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)
  1497. } else {
  1498. kptPF = 0;
  1499. }
  1500.  
  1501. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  1502. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  1503. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  1504. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  1505. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  1506. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  1507. console.groupEnd();
  1508.  
  1509. }
  1510.  
  1511. for (const h of hostL1) {
  1512.  
  1513. if (kptPF === null) kn();
  1514. if (ENABLE_BASE_PREFETCHING) {
  1515. // if (kptPF & 1) {
  1516. // linker(link, 'dns-prefetch', h);
  1517. // link = null;
  1518. // }
  1519. if (kptPF & 2) {
  1520. linker(link, 'preconnect', h);
  1521. link = null;
  1522. }
  1523. }
  1524. }
  1525.  
  1526. for (const h of hostL2) {
  1527. if (kptPF === null) kn();
  1528. if (ENABLE_BASE_PREFETCHING) {
  1529. if (kptPF & 1) {
  1530. linker(link, 'dns-prefetch', h);
  1531. link = null;
  1532. }
  1533. }
  1534. }
  1535.  
  1536. })
  1537.  
  1538.  
  1539. }
  1540.  
  1541. if (flagsFnOnInterval) flagsFnOnInterval(setInterval, clearInterval);
  1542.  
  1543. if (DO_LINK_PREFETCH) basePrefetching();
  1544.  
  1545. const { notifyPath7081 } = (() => {
  1546. // DO_PARTICIPANT_LIST_HACKS
  1547.  
  1548. const mutexParticipants = new Mutex();
  1549.  
  1550. let uvid = 0;
  1551. let r95dm = 0;
  1552. let c95dm = -1;
  1553.  
  1554. const foundMap = (base, content) => {
  1555. /*
  1556. let lastSearch = 0;
  1557. let founds = base.map(baseEntry => {
  1558. let search = content.indexOf(baseEntry, lastSearch);
  1559. if (search < 0) return false;
  1560. lastSearch = search + 1;
  1561. return true;
  1562. });
  1563. return founds;
  1564. */
  1565. const contentSet = new Set(content);
  1566. return base.map(baseEntry => contentSet.has(baseEntry));
  1567.  
  1568. }
  1569.  
  1570.  
  1571.  
  1572. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  1573.  
  1574. const handler1 = {
  1575. get(target, prop, receiver) {
  1576. if (prop === 'object') {
  1577. return participants; // avoid memory leakage
  1578. }
  1579. if (prop === 'type') {
  1580. return 'splice';
  1581. }
  1582. return target[prop];
  1583. }
  1584. };
  1585. const releaser = () => {
  1586. participants = null;
  1587. }
  1588.  
  1589. let foundsForAfter = foundMap(idsAfter, idsBefore);
  1590. let foundsForBefore = foundMap(idsBefore, idsAfter);
  1591.  
  1592. let indexSplices = [];
  1593. let contentUpdates = [];
  1594. for (let i = 0, j = 0; i < foundsForBefore.length || j < foundsForAfter.length;) {
  1595. if (beforeParticipants[i] === participants[j]) {
  1596. i++; j++;
  1597. } else if (idsBefore[i] === idsAfter[j]) {
  1598. // content changed
  1599. contentUpdates.push({ indexI: i, indexJ: j })
  1600. i++; j++;
  1601. } else {
  1602. let addedCount = 0;
  1603. for (let q = j; q < foundsForAfter.length; q++) {
  1604. if (foundsForAfter[q] === false) addedCount++;
  1605. else break;
  1606. }
  1607. let removedCount = 0;
  1608. for (let q = i; q < foundsForBefore.length; q++) {
  1609. if (foundsForBefore[q] === false) removedCount++;
  1610. else break;
  1611. }
  1612. if (!addedCount && !removedCount) {
  1613. throw 'ERROR(0xFF32): spliceIndicesFunc';
  1614. }
  1615. indexSplices.push(new Proxy({
  1616. index: j,
  1617. addedCount: addedCount,
  1618. removed: removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  1619. }, handler1));
  1620. i += removedCount;
  1621. j += addedCount;
  1622. }
  1623. }
  1624. foundsForBefore = null;
  1625. foundsForAfter = null;
  1626. idsBefore = null;
  1627. idsAfter = null;
  1628. beforeParticipants = null;
  1629. return { indexSplices, contentUpdates, releaser };
  1630.  
  1631. }
  1632.  
  1633. /*
  1634.  
  1635. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  1636.  
  1637. VM63631:1 Error
  1638. at customElements.get.notifyPath (<anonymous>:1:122)
  1639. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  1640. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  1641. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  1642. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  1643. at ju (live_chat_polymer.js:1674:217)
  1644. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  1645. at b._flushProperties (live_chat_polymer.js:1597:200)
  1646. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  1647. at a.notifyPath (live_chat_polymer.js:1741:182)
  1648.  
  1649. */
  1650.  
  1651. function convertToIds(participants) {
  1652. return participants.map(participant => {
  1653. if (!participant || typeof participant !== 'object') {
  1654. console.warn('Error(0xFA41): convertToIds', participant);
  1655. return participant; // just in case
  1656. }
  1657. let keys = Object.keys(participant);
  1658. // liveChatTextMessageRenderer
  1659. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  1660. // liveChatPaidMessageRenderer
  1661. /*
  1662.  
  1663. 'yt-live-chat-participant-renderer' utilizes the following:
  1664. authorName.simpleText: string
  1665. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  1666. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  1667. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  1668. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  1669.  
  1670. */
  1671. if (keys.length !== 1) {
  1672. console.warn('Error(0xFA42): convertToIds', participant);
  1673. return participant; // just in case
  1674. }
  1675. let key = keys[0];
  1676. let renderer = (participant[key] || 0);
  1677. let authorName = (renderer.authorName || 0);
  1678. let text = `${authorName.simpleText || authorName.text}`
  1679. let res = participant; // fallback if it is not a vaild entry
  1680. if (typeof text !== 'string') {
  1681. console.warn('Error(0xFA53): convertToIds', participant);
  1682. } else {
  1683. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  1684. if (text.length > 1) res = text;
  1685. }
  1686. return res;
  1687. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  1688. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  1689. });
  1690. }
  1691.  
  1692. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  1693. // just update when content is changed.
  1694. if (p1.authorName !== p2.authorName) return true;
  1695. if (p1.authorPhoto !== p2.authorPhoto) return true;
  1696. if (p1.authorBadges !== p2.authorBadges) return true;
  1697. return false;
  1698. } : (p1, p2) => {
  1699. // keep integrity all the time.
  1700. return p1 !== p2; // always true
  1701. }
  1702.  
  1703. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  1704.  
  1705. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  1706. if (path !== "participantsManager.participants") {
  1707. return this.__notifyPath5036__.apply(this, arguments);
  1708. }
  1709. if (c95dm === r95dm) return;
  1710. } else {
  1711. const stack = new Error().stack;
  1712. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  1713. return this.__notifyPath5036__.apply(this, arguments);
  1714. }
  1715. }
  1716.  
  1717. if (uvid > 1e8) uvid = uvid % 100;
  1718. let tid = ++uvid;
  1719.  
  1720. const cnt = this; // "yt-live-chat-participant-list-renderer"
  1721. mutexParticipants.lockWith(lockResolve => {
  1722.  
  1723. const participants00 = cnt.participantsManager.participants;
  1724.  
  1725. if (tid !== uvid || typeof (participants00 || 0).splice !== 'function') {
  1726. lockResolve();
  1727. return;
  1728. }
  1729.  
  1730. let doUpdate = false;
  1731.  
  1732. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  1733.  
  1734. if (!participants00.r94dm) {
  1735. participants00.r94dm = 1;
  1736. if (++r95dm > 1e9) r95dm = 9;
  1737. participants00.push = function () {
  1738. if (++r95dm > 1e9) r95dm = 9;
  1739. return Array.prototype.push.apply(this, arguments);
  1740. }
  1741. participants00.pop = function () {
  1742. if (++r95dm > 1e9) r95dm = 9;
  1743. return Array.prototype.pop.apply(this, arguments);
  1744. }
  1745. participants00.shift = function () {
  1746. if (++r95dm > 1e9) r95dm = 9;
  1747. return Array.prototype.shift.apply(this, arguments);
  1748. }
  1749. participants00.unshift = function () {
  1750. if (++r95dm > 1e9) r95dm = 9;
  1751. return Array.prototype.unshift.apply(this, arguments);
  1752. }
  1753. participants00.splice = function () {
  1754. if (++r95dm > 1e9) r95dm = 9;
  1755. return Array.prototype.splice.apply(this, arguments);
  1756. }
  1757. participants00.sort = function () {
  1758. if (++r95dm > 1e9) r95dm = 9;
  1759. return Array.prototype.sort.apply(this, arguments);
  1760. }
  1761. participants00.reverse = function () {
  1762. if (++r95dm > 1e9) r95dm = 9;
  1763. return Array.prototype.reverse.apply(this, arguments);
  1764. }
  1765. }
  1766.  
  1767. if (c95dm !== r95dm) {
  1768. c95dm = r95dm;
  1769. doUpdate = true;
  1770. }
  1771.  
  1772. } else {
  1773. doUpdate = true;
  1774. }
  1775.  
  1776. if (!doUpdate) {
  1777. lockResolve();
  1778. return;
  1779. }
  1780.  
  1781. const participants = participants00.slice(0);
  1782. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  1783. beforeParticipantsMap.set(cnt, participants);
  1784.  
  1785. const resPromise = (async () => {
  1786.  
  1787. if (beforeParticipants.length === 0) {
  1788. // not error
  1789. return 0;
  1790. }
  1791.  
  1792. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  1793.  
  1794. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  1795. if (beforeParticipants.length !== countOfElements) {
  1796. // there is somewrong for the cache. - sometimes happen
  1797. return 0;
  1798. }
  1799.  
  1800. const idsBefore = convertToIds(beforeParticipants);
  1801. const idsAfter = convertToIds(participants);
  1802.  
  1803. let { indexSplices, contentUpdates, releaser } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  1804.  
  1805. let res = 1; // default 1 for no update
  1806.  
  1807. if (indexSplices.length >= 1) {
  1808.  
  1809.  
  1810. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  1811. // let p1 = indexSplices[0].removed;
  1812. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  1813.  
  1814. /* folllow
  1815. a.notifyPath(c + ".splices", d);
  1816. a.notifyPath(c + ".length", b.length);
  1817. */
  1818. // stampDomArraySplices_
  1819.  
  1820.  
  1821. await new Promise(resolve => {
  1822. cnt.resolveForDOMRendering781 = resolve;
  1823.  
  1824. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  1825. indexSplices
  1826. });
  1827. indexSplices = null;
  1828. releaser();
  1829. releaser = null;
  1830. cnt.__notifyPath5036__("participantsManager.participants.length",
  1831. participants.length
  1832. );
  1833.  
  1834. });
  1835.  
  1836. await Promise.resolve(0); // play safe for the change of 'length'
  1837. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  1838.  
  1839. let wrongSize = participants.length !== countOfElements
  1840. if (wrongSize) {
  1841. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  1842. return 0;
  1843. }
  1844.  
  1845. res = 2 | 4;
  1846.  
  1847. } else {
  1848.  
  1849. indexSplices = null;
  1850. releaser();
  1851. releaser = null;
  1852.  
  1853. if (participants.length !== countOfElements) {
  1854. // other unhandled cases
  1855. return 0;
  1856. }
  1857.  
  1858. }
  1859.  
  1860. // participants.length === countOfElements before contentUpdates
  1861. if (contentUpdates.length >= 1) {
  1862. for (const contentUpdate of contentUpdates) {
  1863. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  1864. if (isChanged) {
  1865. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  1866. res |= 4 | 8;
  1867. }
  1868. }
  1869. }
  1870. contentUpdates = null;
  1871.  
  1872. return res;
  1873.  
  1874.  
  1875. })();
  1876.  
  1877.  
  1878. resPromise.then(resValue => {
  1879.  
  1880. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  1881. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  1882. if (resValue === 0) {
  1883. new Promise(resolve => {
  1884. cnt.resolveForDOMRendering781 = resolve;
  1885. isLogRequired && console.log("Full Refresh begins");
  1886. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  1887. }).then(() => {
  1888. isLogRequired && console.log("Full Refresh ends");
  1889. console.groupEnd();
  1890. }).then(lockResolve);
  1891. return;
  1892. }
  1893.  
  1894. const delayLockResolve = (resValue & 4) === 4;
  1895.  
  1896. if (delayLockResolve) {
  1897. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  1898. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  1899. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  1900. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  1901. isLogRequired && console.groupEnd();
  1902. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  1903. // mutex lock with requestAnimationFrame can also disable participants update in background
  1904. requestAnimationFrame(lockResolve);
  1905. } else {
  1906. lockResolve();
  1907. }
  1908.  
  1909. });
  1910.  
  1911. });
  1912.  
  1913. }
  1914.  
  1915. return { notifyPath7081 };
  1916.  
  1917. })();
  1918.  
  1919.  
  1920. const onRegistryReadyForDataManipulation = () => {
  1921.  
  1922. function dummy5035(a, b, c) { }
  1923. function dummy411(a, b, c) { }
  1924.  
  1925. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  1926.  
  1927. if (!DO_PARTICIPANT_LIST_HACKS) return;
  1928.  
  1929. const tag = "yt-live-chat-participant-list-renderer";
  1930. const cProto = getProto(document.createElement(tag));
  1931. if (!cProto || typeof cProto.attached !== 'function') {
  1932. // for _registered, proto.attached shall exist when the element is defined.
  1933. // for controller extraction, attached shall exist when instance creates.
  1934. console.warn(`proto.attached for ${tag} is unavailable.`);
  1935. return;
  1936. }
  1937.  
  1938.  
  1939. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  1940.  
  1941. 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'];
  1942. const fgs = {};
  1943. for (const key of fgsArr) fgs[key] = undefined;
  1944.  
  1945. try {
  1946. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  1947. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  1948. } catch (e) { }
  1949. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  1950.  
  1951. const canDoReplacement = (() => {
  1952. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  1953. console.warn('YouTube Live Chat Tamer is running.');
  1954. return;
  1955. }
  1956.  
  1957. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  1958. console.warn('YouTube Live Chat Tamer is running.');
  1959. return;
  1960. }
  1961.  
  1962. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  1963. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  1964.  
  1965. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  1966. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  1967. return;
  1968. }
  1969.  
  1970. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  1971. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  1972. return;
  1973. }
  1974.  
  1975. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  1976. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  1977. return;
  1978. }
  1979. return true;
  1980. })();
  1981.  
  1982. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  1983.  
  1984. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  1985. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  1986. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  1987. const s = fiRSCB.split('.');
  1988. if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  1989. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  1990. } else {
  1991. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - Failed`);
  1992. }
  1993. } else {
  1994. console.log("flushRenderStamperComponentBindings_ - not found");
  1995. }
  1996. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  1997.  
  1998. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  1999. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  2000. cProto.flushRenderStamperComponentBindings_ = function () {
  2001. // console.log('flushRenderStamperComponentBindings_')
  2002. this.flushRenderStamperComponentBindings66_();
  2003. if (this.resolveForDOMRendering781) {
  2004. this.resolveForDOMRendering781();
  2005. this.resolveForDOMRendering781 = null;
  2006. }
  2007. };
  2008. }
  2009.  
  2010. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  2011. const container = ((this || 0).$ || 0).participants;
  2012. if (!container) return 0;
  2013. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  2014. }
  2015.  
  2016. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  2017.  
  2018. cProto.__attached412__ = cProto.attached;
  2019. const fpPList = function (hostElement) {
  2020. const cnt = hostElement.inst || hostElement;
  2021. if (beforeParticipantsMap.has(cnt)) return;
  2022. hostElement.classList.add('n9fJ3');
  2023.  
  2024. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  2025. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  2026. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  2027. return;
  2028. }
  2029.  
  2030. groupCollapsed("Participant List attached", "");
  2031. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  2032. // console.log(123, 'appendChild');
  2033. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  2034. // }
  2035.  
  2036. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  2037. // console.log(123, 'insertBefore');
  2038. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  2039. // }
  2040.  
  2041. cnt.__notifyPath5036__ = cnt.notifyPath
  2042. const participants = ((cnt.participantsManager || 0).participants || 0);
  2043. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  2044. console.log(`initial number of participants: ${participants.length}`);
  2045. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  2046. beforeParticipantsMap.set(cnt, newParticipants);
  2047. cnt.notifyPath = notifyPath7081;
  2048. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  2049. console.groupEnd();
  2050. }
  2051. cProto.attached = function () {
  2052. fpPList(this.hostElement || this);
  2053. this.__attached412__.apply(this, arguments);
  2054. };
  2055.  
  2056.  
  2057. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  2058.  
  2059. /** @type {boolean | (()=>boolean)} */
  2060. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  2061. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  2062.  
  2063. let lastMessageDate = 0;
  2064. cProto.stampDomArray66_ = cProto.stampDomArray_;
  2065.  
  2066. cProto.stampDomArray_ = function (...args) {
  2067. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  2068. if (typeof toUseMaintainStableList === 'function') {
  2069. toUseMaintainStableList = toUseMaintainStableList();
  2070. }
  2071. args[5] = toUseMaintainStableList;
  2072. let currentDate = Date.now();
  2073. if (currentDate - lastMessageDate > 440) {
  2074. lastMessageDate = currentDate;
  2075. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  2076. }
  2077. }
  2078. return this.stampDomArray66_.apply(this, args);
  2079. }
  2080.  
  2081. cProto.stampDomArray_.nIegT = 1;
  2082.  
  2083. }
  2084. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  2085. } else {
  2086. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  2087. }
  2088.  
  2089. console.groupEnd();
  2090.  
  2091. if (onPageElements.length >= 1) {
  2092. for (const s of onPageElements) {
  2093. if ((s.inst || s).isAttached === true) {
  2094. fpPList(s);
  2095. }
  2096. }
  2097. }
  2098.  
  2099. }).catch(console.warn);
  2100.  
  2101. };
  2102.  
  2103. if (DO_PARTICIPANT_LIST_HACKS) {
  2104. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  2105. }
  2106.  
  2107.  
  2108.  
  2109. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  2110.  
  2111.  
  2112.  
  2113.  
  2114. const bnForDelayChatOccurrence = () => {
  2115.  
  2116. document.addEventListener('animationstart', (evt) => {
  2117.  
  2118. if (evt.animationName === 'dontRenderAnimation') {
  2119. evt.target.classList.remove('dont-render');
  2120. if (scrollChatFn) scrollChatFn();
  2121. }
  2122.  
  2123. }, true);
  2124.  
  2125. const f = (elm) => {
  2126. if (elm && elm.nodeType === 1) {
  2127. if (!skipDontRender && allowDontRender === true) {
  2128. // innerTextFixFn();
  2129. elm.classList.add('dont-render');
  2130. }
  2131. }
  2132. }
  2133.  
  2134. Node.prototype.__appendChild931__ = function (a) {
  2135. a = dr(a);
  2136. if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  2137. if (a && a.nodeType === 1) f(a);
  2138. else if (a instanceof DocumentFragment) {
  2139. for (let n = a.firstChild; n; n = n.nextSibling) {
  2140. f(n);
  2141. }
  2142. }
  2143. }
  2144. }
  2145.  
  2146. Node.prototype.__appendChild932__ = function () {
  2147. this.__appendChild931__.apply(this, arguments);
  2148. return Node.prototype.appendChild.apply(this, arguments);
  2149. }
  2150.  
  2151.  
  2152. };
  2153.  
  2154. const watchUserCSS = () => {
  2155.  
  2156. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  2157.  
  2158. const getElemFromWR = (nr) => {
  2159. const n = kRef(nr);
  2160. if (n && n.isConnected) return n;
  2161. return null;
  2162. }
  2163.  
  2164. const clearContentVisibilitySizing = () => {
  2165. Promise.resolve().then(() => {
  2166.  
  2167. const e = document.querySelector('#show-more[disabled]');
  2168. let btnShowMoreWR = e ? mWeakRef(e) : null;
  2169.  
  2170. let lastVisibleItemWR = null;
  2171. for (const elm of document.querySelectorAll('[wSr93]')) {
  2172. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  2173. elm.setAttribute('wSr93', '');
  2174. // custom CSS property --wsr94 not working when attribute wSr93 removed
  2175. }
  2176. requestAnimationFrame(() => {
  2177. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  2178. if (btnShowMore) btnShowMore.click();
  2179. else {
  2180. // would not work if switch it frequently
  2181. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  2182. if (lastVisibleItem) {
  2183.  
  2184. Promise.resolve()
  2185. .then(() => lastVisibleItem.scrollIntoView())
  2186. .then(() => lastVisibleItem.scrollIntoView(false))
  2187. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  2188. .catch(e => { }) // break the chain when method not callable
  2189.  
  2190. }
  2191. }
  2192. });
  2193.  
  2194. });
  2195.  
  2196. }
  2197.  
  2198. const mutObserver = new MutationObserver((mutations) => {
  2199. for (const mutation of mutations) {
  2200. if ((mutation.addedNodes || 0).length >= 1) {
  2201. for (const addedNode of mutation.addedNodes) {
  2202. if (addedNode.nodeName === 'STYLE') {
  2203. clearContentVisibilitySizing();
  2204. return;
  2205. }
  2206. }
  2207. }
  2208. if ((mutation.removedNodes || 0).length >= 1) {
  2209. for (const removedNode of mutation.removedNodes) {
  2210. if (removedNode.nodeName === 'STYLE') {
  2211. clearContentVisibilitySizing();
  2212. return;
  2213. }
  2214. }
  2215. }
  2216. }
  2217. });
  2218.  
  2219. mutObserver.observe(document.documentElement, {
  2220. childList: true,
  2221. subtree: false
  2222. });
  2223. mutObserver.observe(document.head, {
  2224. childList: true,
  2225. subtree: false
  2226. });
  2227. mutObserver.observe(document.body, {
  2228. childList: true,
  2229. subtree: false
  2230. });
  2231.  
  2232. }
  2233.  
  2234.  
  2235. class WillChangeController {
  2236. constructor(itemScroller, willChangeValue) {
  2237. this.element = itemScroller;
  2238. this.counter = 0;
  2239. this.active = false;
  2240. this.willChangeValue = willChangeValue;
  2241. }
  2242.  
  2243. beforeOper() {
  2244. if (!this.active) {
  2245. this.active = true;
  2246. this.element.style.willChange = this.willChangeValue;
  2247. }
  2248. this.counter++;
  2249. }
  2250.  
  2251. afterOper() {
  2252. const c = this.counter;
  2253. requestAnimationFrame(() => {
  2254. if (c === this.counter) {
  2255. this.active = false;
  2256. this.element.style.willChange = '';
  2257. }
  2258. });
  2259. }
  2260.  
  2261. release() {
  2262. const element = this.element;
  2263. this.element = null;
  2264. this.counter = 1e16;
  2265. this.active = false;
  2266. try {
  2267. element.style.willChange = '';
  2268. } catch (e) { }
  2269. }
  2270.  
  2271. }
  2272.  
  2273.  
  2274. const skzData = (skz) => skz.data = {
  2275. "message": {
  2276. "runs": [
  2277. {
  2278. "text": "em2o"
  2279. },
  2280. {
  2281. "emoji": {
  2282. "emojiId": "cm35z",
  2283. "shortcuts": [
  2284. ":_s:",
  2285. ":s:"
  2286. ],
  2287. "searchTerms": [
  2288. "_s",
  2289. "s"
  2290. ],
  2291. "image": {
  2292. "thumbnails": [
  2293. {
  2294. "url": dummyImgURL,
  2295. "width": 48,
  2296. "height": 48
  2297. }
  2298. ],
  2299. "accessibility": {
  2300. "accessibilityData": {
  2301. "label": "s"
  2302. }
  2303. }
  2304. },
  2305. "isCustomEmoji": true
  2306. }
  2307. },
  2308. {
  2309. "text": "ji"
  2310. }
  2311. ]
  2312. },
  2313. "authorName": {
  2314. "simpleText": "N"
  2315. },
  2316. "authorPhoto": {
  2317. "thumbnails": [
  2318. {
  2319. "url": dummyImgURL,
  2320. "width": 64,
  2321. "height": 64
  2322. }
  2323. ]
  2324. },
  2325. "contextMenuEndpoint": {
  2326. "commandMetadata": {
  2327. "webCommandMetadata": {
  2328. "ignoreNavigation": true
  2329. }
  2330. },
  2331. "liveChatItemContextMenuEndpoint": {
  2332. "params": "123=="
  2333. }
  2334. },
  2335. "id": "sk35z",
  2336. "timestampUsec": "1232302352350000",
  2337. "authorBadges": [
  2338. {
  2339. "liveChatAuthorBadgeRenderer": {
  2340. "customThumbnail": {
  2341. "thumbnails": [
  2342. {
  2343. "url": dummyImgURL,
  2344. "width": 16,
  2345. "height": 16
  2346. },
  2347. {
  2348. "url": dummyImgURL,
  2349. "width": 32,
  2350. "height": 32
  2351. }
  2352. ]
  2353. },
  2354. "tooltip": "T",
  2355. "accessibility": {
  2356. "accessibilityData": {
  2357. "label": "E"
  2358. }
  2359. }
  2360. }
  2361. }
  2362. ],
  2363. "authorExternalChannelId": "A",
  2364. "contextMenuAccessibility": {
  2365. "accessibilityData": {
  2366. "label": "E"
  2367. }
  2368. },
  2369. "timestampText": {
  2370. "simpleText": "0:43"
  2371. }
  2372. };
  2373.  
  2374.  
  2375.  
  2376. const { lcRendererElm, visObserver } = (() => {
  2377.  
  2378.  
  2379.  
  2380. let lcRendererWR = null;
  2381.  
  2382. const lcRendererElm = () => {
  2383. let lcRenderer = kRef(lcRendererWR);
  2384. if (!lcRenderer || !lcRenderer.isConnected) {
  2385. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  2386. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  2387. }
  2388. return lcRenderer;
  2389. };
  2390.  
  2391.  
  2392. let hasFirstShowMore = false;
  2393.  
  2394. const visObserverFn = (entry) => {
  2395.  
  2396. const target = entry.target;
  2397. if (!target) return;
  2398. // if(target.classList.contains('dont-render')) return;
  2399. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  2400. // const h = entry.boundingClientRect.height;
  2401. /*
  2402. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  2403. // e.g. under fullscreen. the element created but not rendered.
  2404. target.setAttribute('wSr93', '');
  2405. return;
  2406. }
  2407. */
  2408. if (isVisible) {
  2409. // target.style.setProperty('--wsr94', h + 'px');
  2410. target.setAttribute('wSr93', 'visible');
  2411. if (nNextElem(target) === null) {
  2412.  
  2413. // firstVisibleItemDetected = true;
  2414. /*
  2415. if (dateNow() - lastScroll < 80) {
  2416. lastLShow = 0;
  2417. lastScroll = 0;
  2418. Promise.resolve().then(clickShowMore);
  2419. } else {
  2420. lastLShow = dateNow();
  2421. }
  2422. */
  2423. // lastLShow = dateNow();
  2424. } else if (!hasFirstShowMore) { // should more than one item being visible
  2425. // implement inside visObserver to ensure there is sufficient delay
  2426. hasFirstShowMore = true;
  2427. requestAnimationFrame(() => {
  2428. // foreground page
  2429. // page visibly ready -> load the latest comments at initial loading
  2430. const lcRenderer = lcRendererElm();
  2431. if (lcRenderer) {
  2432. (lcRenderer.inst || lcRenderer).scrollToBottom_();
  2433. }
  2434. });
  2435. }
  2436. }
  2437. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  2438.  
  2439. // target.style.setProperty('--wsr94', h + 'px');
  2440. target.setAttribute('wSr93', 'hidden');
  2441. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  2442.  
  2443. }
  2444.  
  2445.  
  2446.  
  2447. const visObserver = new IntersectionObserver((entries) => {
  2448.  
  2449. for (const entry of entries) {
  2450.  
  2451. Promise.resolve(entry).then(visObserverFn);
  2452.  
  2453. }
  2454.  
  2455. }, {
  2456. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  2457. rootMargin: "0px",
  2458. threshold: [0.05, 0.95],
  2459. });
  2460.  
  2461.  
  2462. return { lcRendererElm, visObserver }
  2463.  
  2464.  
  2465. })();
  2466.  
  2467. const { setupMutObserver } = (() => {
  2468.  
  2469. const mutFn = (items) => {
  2470. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  2471. if (node.hasAttribute('wSr93')) break;
  2472. node.setAttribute('wSr93', '');
  2473. visObserver.observe(node);
  2474. }
  2475. }
  2476.  
  2477. const mutObserver = new MutationObserver((mutations) => {
  2478. const items = (mutations[0] || 0).target;
  2479. if (!items) return;
  2480. if (sk35zResolveFn) {
  2481. sk35zResolveFn();
  2482. sk35zResolveFn = null;
  2483. }
  2484. mutFn(items);
  2485. });
  2486.  
  2487. const setupMutObserver = (m2) => {
  2488. scrollChatFn = null;
  2489. mutObserver.disconnect();
  2490. mutObserver.takeRecords();
  2491. if (m2) {
  2492. ENABLE_DELAYED_CHAT_OCCURRENCE && bnForDelayChatOccurrence();
  2493. if (typeof m2.__appendChild932__ === 'function') {
  2494. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  2495. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  2496. }
  2497. mutObserver.observe(m2, {
  2498. childList: true,
  2499. subtree: false
  2500. });
  2501. mutFn(m2);
  2502.  
  2503. const isFirstList = firstList;
  2504. firstList = false;
  2505.  
  2506. if (ENABLE_OVERFLOW_ANCHOR) {
  2507.  
  2508. let items = m2;
  2509. let addedAnchor = false;
  2510. if (items) {
  2511. if (items.nextElementSibling === null) {
  2512. items.classList.add('no-anchor');
  2513. addedAnchor = true;
  2514. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  2515. }
  2516. }
  2517.  
  2518.  
  2519.  
  2520. if (addedAnchor) {
  2521. nodeParent(m2).classList.add('no-anchor'); // required
  2522. }
  2523.  
  2524. }
  2525.  
  2526. // let div = document.createElement('div');
  2527. // div.id = 'qwcc';
  2528. // HTMLElement.prototype.appendChild.call(document.querySelector('yt-live-chat-item-list-renderer'), div )
  2529. // bufferRegion =div;
  2530.  
  2531. // buffObserver.takeRecords();
  2532. // buffObserver.disconnect();
  2533. // buffObserver.observe(div, {
  2534. // childList: true,
  2535. // subtree: false
  2536. // })
  2537.  
  2538. if (ENABLE_DELAYED_CHAT_OCCURRENCE && isFirstList) {
  2539.  
  2540. promiseForCustomYtElementsReady.then(() => {
  2541.  
  2542. customElements.whenDefined('yt-live-chat-text-message-renderer').then(() => {
  2543.  
  2544.  
  2545.  
  2546.  
  2547. setTimeout(() => {
  2548.  
  2549. /** @type {HTMLTemplateElement} */
  2550. let skz = document.createElement('yt-live-chat-text-message-renderer');
  2551.  
  2552. let cz1 = null;
  2553.  
  2554. if (skz && 'data' in skz && 'attached' in skz) {
  2555.  
  2556. const deferredZy1 = new Promise(resolve => {
  2557.  
  2558. skz.attached = function () {
  2559. cz1 = HTMLElement.prototype.querySelector.call(skz, '#message img') !== null;
  2560. resolve(skz.textContent);
  2561. }
  2562. skz.detached = function () {
  2563.  
  2564. }
  2565.  
  2566. });
  2567. skz.id = 'sk35z';
  2568. skzData(skz);
  2569.  
  2570.  
  2571. sk35zResolveFn = null;
  2572. const deferredMutation = new Promise(resolve => {
  2573. sk35zResolveFn = resolve;
  2574. HTMLElement.prototype.appendChild.call(m2, skz);
  2575. });
  2576.  
  2577. Promise.all([deferredZy1, deferredMutation]).then(async (res) => {
  2578. const [zy1, _] = res;
  2579. function fn() {
  2580. const zy2 = skz.textContent;
  2581. const cz2 = HTMLElement.prototype.querySelector.call(skz, '#message img') !== null;
  2582. if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  2583. allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  2584. }
  2585. if (allowDontRender === false) {
  2586.  
  2587. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2588. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2589. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2590. );
  2591.  
  2592. 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');
  2593.  
  2594. console.groupEnd();
  2595. } else if (allowDontRender === true) {
  2596. return true;
  2597. }
  2598. }
  2599. await new Promise(r => setTimeout(r, 1));
  2600. if (fn()) {
  2601. await new Promise(r => requestAnimationFrame(r));
  2602. if (fn()) {
  2603. skz.remove();
  2604. skz.textContent = '';
  2605. console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2606. }
  2607. }
  2608. });
  2609.  
  2610. }
  2611.  
  2612. }, 1);
  2613.  
  2614. }).catch(console.warn);
  2615.  
  2616. })
  2617.  
  2618. }
  2619.  
  2620.  
  2621. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  2622.  
  2623. (() => {
  2624.  
  2625. const tag = 'yt-iframed-player-events-relay'
  2626. const dummy = document.createElement(tag);
  2627.  
  2628. const cProto = getProto(dummy);
  2629. if (!cProto || !cProto.handlePostMessage_) {
  2630. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  2631. return;
  2632. }
  2633.  
  2634. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_) {
  2635.  
  2636. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  2637.  
  2638. cProto.handlePostMessage_ = function (a) {
  2639.  
  2640. const da = (a || 0).data || 0;
  2641. if (typeof da === 'object') {
  2642.  
  2643. // console.log('handlePostMessage_', da)
  2644. const qc = da['yt-player-state-change'];
  2645. if (qc === 3) { // pause
  2646. pairForPauseResume++;
  2647. pairForPauseResumeM++;
  2648. } else if (qc === 1) { // pause
  2649. pairForPauseResume++;
  2650. pairForPauseResumeM++;
  2651. } else if (qc === 2) {
  2652. pairForPauseResume++;
  2653. pairForPauseResumeM++;
  2654. }
  2655. if (pairForPauseResume > 1e9) pairForPauseResume = pairForPauseResume % 1e4;
  2656. if (pairForPauseResumeM > 1e9) pairForPauseResumeM = pairForPauseResumeM % 1e4;
  2657. return this.handlePostMessage66_(a);
  2658.  
  2659. }
  2660.  
  2661.  
  2662. }
  2663.  
  2664. }
  2665.  
  2666.  
  2667. })();
  2668.  
  2669. }
  2670.  
  2671. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  2672. setTimeout(() => {
  2673. if (!hasTimerModified) return;
  2674. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  2675. if (!tickerRenderer) return;
  2676.  
  2677. const items = (tickerRenderer.$ || 0).items || 0;
  2678. if (!items) return;
  2679. const template = document.createElement('template');
  2680. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  2681. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  2682. dimmed="" [dummy777]>
  2683. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  2684. 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));">
  2685. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  2686. <yt-img-shadow777 id="author-photo" height="24" width="24"
  2687. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  2688. style="background-color: transparent;" loaded=""><img id="img"
  2689. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  2690. src="${dummyImgURL}"></yt-img-shadow777>
  2691.  
  2692. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  2693. </div>
  2694. </div>
  2695. </yt-live-chat-ticker-dummy777-item-renderer>`;
  2696. const dummy777 = template.content.firstElementChild;
  2697. items.appendChild(dummy777);
  2698. Promise.resolve(dummy777).then((dummy777) => {
  2699. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  2700. if (container.isConnected === true) {
  2701.  
  2702. const evaluated = `${window.getComputedStyle(container).background}`;
  2703.  
  2704. container = null;
  2705. dummy777.remove();
  2706. dummy777.textContent = '';
  2707. dummy777 = null;
  2708.  
  2709. if (evaluated.indexOf('0.') < 4) {
  2710.  
  2711. // not fulfilling
  2712. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  2713.  
  2714. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2715. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2716. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2717. );
  2718. 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');
  2719. console.groupEnd();
  2720.  
  2721. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  2722.  
  2723. } else {
  2724.  
  2725. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2726. }
  2727. }
  2728. });
  2729.  
  2730. }, 800);
  2731. }
  2732.  
  2733. }
  2734. }
  2735.  
  2736. return { setupMutObserver };
  2737.  
  2738.  
  2739.  
  2740. })();
  2741.  
  2742. const setupEvents = () => {
  2743.  
  2744.  
  2745. let scrollCount = 0;
  2746.  
  2747. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  2748.  
  2749.  
  2750. const delayFlushActiveItemsAfterUserActionK_ = () => {
  2751.  
  2752. const lcRenderer = lcRendererElm();
  2753. if (lcRenderer) {
  2754. const cnt = (lcRenderer.inst || lcRenderer);
  2755. if (!cnt.hasUserJustInteracted11_) return;
  2756. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  2757. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  2758. }
  2759. }
  2760.  
  2761. }
  2762.  
  2763. document.addEventListener('scroll', (evt) => {
  2764. if (!evt || !evt.isTrusted) return;
  2765. // lastScroll = dateNow();
  2766. if (++scrollCount > 1e9) scrollCount = 9;
  2767. }, passiveCapture); // support contain => support passive
  2768.  
  2769. let lastScrollCount = -1;
  2770. document.addEventListener('wheel', (evt) => {
  2771. if (!evt || !evt.isTrusted) return;
  2772. if (lastScrollCount === scrollCount) return;
  2773. lastScrollCount = scrollCount;
  2774. lastWheel = dateNow();
  2775. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2776. }, passiveCapture); // support contain => support passive
  2777.  
  2778. document.addEventListener('mousedown', (evt) => {
  2779. if (!evt || !evt.isTrusted) return;
  2780. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2781. lastMouseDown = dateNow();
  2782. currentMouseDown = true;
  2783. lastUserInteraction = lastMouseDown;
  2784. }, passiveCapture);
  2785.  
  2786. document.addEventListener('pointerdown', (evt) => {
  2787. if (!evt || !evt.isTrusted) return;
  2788. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2789. lastMouseDown = dateNow();
  2790. currentMouseDown = true;
  2791. lastUserInteraction = lastMouseDown;
  2792. }, passiveCapture);
  2793.  
  2794. document.addEventListener('click', (evt) => {
  2795. if (!evt || !evt.isTrusted) return;
  2796. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2797. lastMouseDown = lastMouseUp = dateNow();
  2798. currentMouseDown = false;
  2799. lastUserInteraction = lastMouseDown;
  2800. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2801. }, passiveCapture);
  2802.  
  2803. document.addEventListener('tap', (evt) => {
  2804. if (!evt || !evt.isTrusted) return;
  2805. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2806. lastMouseDown = lastMouseUp = dateNow();
  2807. currentMouseDown = false;
  2808. lastUserInteraction = lastMouseDown;
  2809. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2810. }, passiveCapture);
  2811.  
  2812.  
  2813. document.addEventListener('mouseup', (evt) => {
  2814. if (!evt || !evt.isTrusted) return;
  2815. if (currentMouseDown) {
  2816. lastMouseUp = dateNow();
  2817. currentMouseDown = false;
  2818. lastUserInteraction = lastMouseUp;
  2819. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2820. }
  2821. }, passiveCapture);
  2822.  
  2823.  
  2824. document.addEventListener('pointerup', (evt) => {
  2825. if (!evt || !evt.isTrusted) return;
  2826. if (currentMouseDown) {
  2827. lastMouseUp = dateNow();
  2828. currentMouseDown = false;
  2829. lastUserInteraction = lastMouseUp;
  2830. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2831. }
  2832. }, passiveCapture);
  2833.  
  2834. document.addEventListener('touchstart', (evt) => {
  2835. if (!evt || !evt.isTrusted) return;
  2836. lastTouchDown = dateNow();
  2837. currentTouchDown = true;
  2838. lastUserInteraction = lastTouchDown;
  2839. }, passiveCapture);
  2840.  
  2841. document.addEventListener('touchmove', (evt) => {
  2842. if (!evt || !evt.isTrusted) return;
  2843. lastTouchDown = dateNow();
  2844. currentTouchDown = true;
  2845. lastUserInteraction = lastTouchDown;
  2846. }, passiveCapture);
  2847.  
  2848. document.addEventListener('touchend', (evt) => {
  2849. if (!evt || !evt.isTrusted) return;
  2850. if (currentTouchDown) {
  2851. lastTouchUp = dateNow();
  2852. currentTouchDown = false;
  2853. lastUserInteraction = lastTouchUp;
  2854. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2855. }
  2856. }, passiveCapture);
  2857.  
  2858. document.addEventListener('touchcancel', (evt) => {
  2859. if (!evt || !evt.isTrusted) return;
  2860. if (currentTouchDown) {
  2861. lastTouchUp = dateNow();
  2862. currentTouchDown = false;
  2863. lastUserInteraction = lastTouchUp;
  2864. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2865. }
  2866. }, passiveCapture);
  2867.  
  2868.  
  2869. }
  2870.  
  2871.  
  2872. const onRegistryReadyForDOMOperations = () => {
  2873.  
  2874. let firstCheckedOnYtInit = false;
  2875.  
  2876. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  2877.  
  2878. const mightFirstCheckOnYtInit = () => {
  2879. if (firstCheckedOnYtInit) return;
  2880. firstCheckedOnYtInit = true;
  2881.  
  2882. if (!document.body || !document.head) return;
  2883. if (!assertorURL()) return;
  2884.  
  2885. addCssManaged();
  2886.  
  2887. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  2888. if (efsContainer && efsContainer.parentNode !== document.body) {
  2889. document.body.appendChild(efsContainer);
  2890. }
  2891.  
  2892. };
  2893.  
  2894. if (!assertorURL()) return;
  2895. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  2896.  
  2897. if (document.documentElement && document.head) {
  2898. addCssManaged();
  2899. }
  2900. // console.log(document.body===null)
  2901.  
  2902. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  2903.  
  2904. const tag = "yt-live-chat-item-list-renderer"
  2905. const dummy = document.createElement(tag);
  2906.  
  2907. const cProto = getProto(dummy);
  2908. if (!cProto || !cProto.attached) {
  2909. console.warn(`proto.attached for ${tag} is unavailable.`);
  2910. return;
  2911. }
  2912.  
  2913. mightFirstCheckOnYtInit();
  2914. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  2915. console.log("[Begin]");
  2916.  
  2917. const mclp = cProto;
  2918. try {
  2919. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  2920. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  2921. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  2922. assertor(() => typeof mclp.setAtBottom === 'function');
  2923. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  2924. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  2925. } catch (e) { }
  2926.  
  2927.  
  2928. try {
  2929. assertor(() => typeof mclp.attached === 'function');
  2930. assertor(() => typeof mclp.detached === 'function');
  2931. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  2932. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  2933. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  2934. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  2935. assertor(() => typeof mclp.smoothScroll_ === 'function');
  2936. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  2937. } catch (e) { }
  2938.  
  2939. mclp.__intermediate_delay__ = null;
  2940.  
  2941. let mzk = 0;
  2942. let myk = 0;
  2943. let mlf = 0;
  2944. let myw = 0;
  2945. let mzt = 0;
  2946. let zarr = null;
  2947. let mlg = 0;
  2948.  
  2949. if ((mclp.clearList || 0).length === 0) {
  2950. assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  2951. mclp.clearList66 = mclp.clearList;
  2952. mclp.clearList = function () {
  2953. mzk++;
  2954. myk++;
  2955. mlf++;
  2956. myw++;
  2957. mzt++;
  2958. mlg++;
  2959. zarr = null;
  2960. this.__intermediate_delay__ = null;
  2961. this.clearList66();
  2962. };
  2963. console.log("clearList", "OK");
  2964. } else {
  2965. console.log("clearList", "NG");
  2966. }
  2967.  
  2968.  
  2969. let onListRendererAttachedDone = false;
  2970.  
  2971. function setList(itemOffset, items) {
  2972.  
  2973. const isFirstTime = onListRendererAttachedDone === false;
  2974.  
  2975. if (isFirstTime) {
  2976. onListRendererAttachedDone = true;
  2977. Promise.resolve().then(watchUserCSS);
  2978. addCssManaged();
  2979. setupEvents();
  2980. }
  2981.  
  2982. setupStyle(itemOffset, items);
  2983.  
  2984. setupMutObserver(items);
  2985. }
  2986.  
  2987. mclp.attached419 = async function () {
  2988.  
  2989. if (!this.isAttached) return;
  2990.  
  2991. let maxTrial = 16;
  2992. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  2993. if (--maxTrial < 0 || !this.isAttached) return;
  2994. await new Promise(requestAnimationFrame);
  2995. }
  2996.  
  2997. if (this.isAttached !== true) return;
  2998.  
  2999. if (!this.$) {
  3000. console.warn("!this.$");
  3001. return;
  3002. }
  3003. if (!this.$) return;
  3004. /** @type {HTMLElement | null} */
  3005. const itemScroller = this.$['item-scroller'];
  3006. /** @type {HTMLElement | null} */
  3007. const itemOffset = this.$['item-offset'];
  3008. /** @type {HTMLElement | null} */
  3009. const items = this.$['items'];
  3010.  
  3011. if (!itemScroller || !itemOffset || !items) {
  3012. console.warn("items.parentNode !== itemOffset");
  3013. return;
  3014. }
  3015.  
  3016. if (nodeParent(items) !== itemOffset) {
  3017.  
  3018. console.warn("items.parentNode !== itemOffset");
  3019. return;
  3020. }
  3021.  
  3022.  
  3023. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  3024.  
  3025. console.warn("id incorrect");
  3026. return;
  3027. }
  3028.  
  3029. 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')
  3030.  
  3031. if (!isTargetItems) {
  3032. console.warn("!isTargetItems");
  3033. return;
  3034. }
  3035.  
  3036. setList(itemOffset, items);
  3037.  
  3038. }
  3039.  
  3040. mclp.attached331 = mclp.attached;
  3041. mclp.attached = function () {
  3042. this.attached419 && this.attached419();
  3043. return this.attached331();
  3044. }
  3045.  
  3046. mclp.detached331 = mclp.detached;
  3047.  
  3048. mclp.detached = function () {
  3049. setupMutObserver();
  3050. return this.detached331();
  3051. }
  3052.  
  3053. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  3054. for (const t29 of t29s) {
  3055. if ((t29.inst || t29).isAttached === true) {
  3056. t29.attached419();
  3057. }
  3058. }
  3059.  
  3060. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  3061.  
  3062. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  3063. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  3064.  
  3065. /** @type {Map<number, any>} */
  3066. const aMap = new Map();
  3067. let count = 6150;
  3068. mclp.async66 = mclp.async;
  3069. mclp.async = function (e, f) {
  3070. // ensure the previous operation is done
  3071. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  3072. const hasF = arguments.length === 2;
  3073. const stack = new Error().stack;
  3074. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  3075. if (count > 1e9) count = 6159;
  3076. const resId = ++count;
  3077. aMap.set(resId, e);
  3078. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  3079. const rp = aMap.get(resId);
  3080. if (typeof rp !== 'function') {
  3081. return;
  3082. }
  3083. let cancelCall = false;
  3084. if (isFlushAsync) {
  3085. if (rk < 0) {
  3086. cancelCall = true;
  3087. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  3088. cancelCall = true;
  3089. }
  3090. }
  3091. if (cancelCall) {
  3092. aMap.delete(resId);
  3093. } else {
  3094. const asyncEn = function () {
  3095. aMap.delete(resId);
  3096. return rp.apply(this, arguments);
  3097. };
  3098. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  3099. }
  3100. });
  3101.  
  3102. return resId;
  3103. }
  3104.  
  3105. mclp.cancelAsync66 = mclp.cancelAsync;
  3106. mclp.cancelAsync = function (resId) {
  3107. if (resId <= 6150) {
  3108. this.cancelAsync66(resId);
  3109. } else if (aMap.has(resId)) {
  3110. const rp = aMap.get(resId);
  3111. aMap.delete(resId);
  3112. if (typeof rp !== 'function') {
  3113. this.cancelAsync66(rp);
  3114. }
  3115. }
  3116. }
  3117.  
  3118. console.log("async", "OK");
  3119. } else {
  3120. console.log("async", "NG");
  3121. }
  3122.  
  3123.  
  3124. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  3125.  
  3126. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  3127. mclp.showNewItems66_ = mclp.showNewItems_;
  3128.  
  3129. mclp.showNewItems77_ = async function () {
  3130. if (myk > 1e9) myk = 9;
  3131. let tid = ++myk;
  3132.  
  3133. await new Promise(requestAnimationFrame);
  3134.  
  3135. if (tid !== myk) {
  3136. return;
  3137. }
  3138.  
  3139. const cnt = this;
  3140.  
  3141. await Promise.resolve();
  3142. cnt.showNewItems66_();
  3143.  
  3144. await Promise.resolve();
  3145.  
  3146. }
  3147.  
  3148. mclp.showNewItems_ = function () {
  3149.  
  3150. const cnt = this;
  3151. cnt.__intermediate_delay__ = new Promise(resolve => {
  3152. cnt.showNewItems77_().then(() => {
  3153. resolve();
  3154. });
  3155. });
  3156. }
  3157.  
  3158. console.log("showNewItems_", "OK");
  3159. } else {
  3160. console.log("showNewItems_", "NG");
  3161. }
  3162.  
  3163.  
  3164. if ((mclp.flushActiveItems_ || 0).length === 0) {
  3165.  
  3166. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.137.81'));
  3167.  
  3168. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  3169.  
  3170. let contensWillChangeController = null;
  3171.  
  3172. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  3173.  
  3174. mclp.flushActiveItems78_ = async function (tid) {
  3175. try {
  3176. if (tid !== mlf) return;
  3177. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3178. let logger = false;
  3179. const cnt = this;
  3180. let immd = cnt.__intermediate_delay__;
  3181. await new Promise(requestAnimationFrame);
  3182.  
  3183. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3184. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  3185.  
  3186. mlf++;
  3187. if (mlg > 1e9) mlg = 9;
  3188. ++mlg;
  3189.  
  3190. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  3191. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  3192. let changeMaxItemsToDisplay = false;
  3193. const activeItemsLen = this.activeItems_.length;
  3194. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  3195. logger = true;
  3196.  
  3197. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  3198.  
  3199. logger && console.log('[Begin]')
  3200.  
  3201. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  3202. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  3203. console.log('reduce maxitems');
  3204. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3205. // as all the rendered chats are already "outdated"
  3206. // all old chats shall remove and reduced number of few chats will be rendered
  3207. // then restore to the original number
  3208. changeMaxItemsToDisplay = true;
  3209. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  3210. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  3211. }
  3212. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  3213. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3214.  
  3215. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3216. } else {
  3217. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  3218.  
  3219. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3220. }
  3221. }
  3222. // it is found that it will render all stacked chats after switching back from background
  3223. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  3224. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  3225.  
  3226.  
  3227. const items = (cnt.$ || 0).items;
  3228.  
  3229. if (USE_WILL_CHANGE_CONTROLLER) {
  3230. if (contensWillChangeController && contensWillChangeController.element !== items) {
  3231. contensWillChangeController.release();
  3232. contensWillChangeController = null;
  3233. }
  3234. if (!contensWillChangeController) contensWillChangeController = new WillChangeController(items, 'contents');
  3235. }
  3236. const wcController = contensWillChangeController;
  3237. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  3238. wcController && wcController.beforeOper();
  3239. await Promise.resolve();
  3240. const acItems = cnt.activeItems_;
  3241. const len1 = acItems.length;
  3242. if (!len1) console.warn('cnt.activeItems_.length = 0');
  3243. let waitFor = [];
  3244.  
  3245.  
  3246. /** @type {Set<string>} */
  3247. const imageLinks = new Set();
  3248.  
  3249. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  3250. for (const item of acItems) {
  3251. fixLiveChatItem(item, imageLinks);
  3252. }
  3253. }
  3254. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  3255. if (emojiPrefetched.size > PREFETCH_LIMITED_SIZE_EMOJI) emojiPrefetched.clear();
  3256. if (authorPhotoPrefetched.size > PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO) authorPhotoPrefetched.clear();
  3257.  
  3258. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  3259. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  3260. // preload performs the high priority fetching.
  3261. // prefetch delays the chat display if the video resoruce is demanding.
  3262.  
  3263. if (rel) {
  3264.  
  3265. imageLinks.forEach(imageLink => {
  3266. let d = false;
  3267. const isEmoji = imageLink.includes('/emoji/');
  3268. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  3269. if (!pretechedSet.has(imageLink)) {
  3270. pretechedSet.add(imageLink);
  3271. d = true;
  3272. }
  3273. if (d) {
  3274. waitFor.push(linker(null, rel, imageLink, 'image'));
  3275.  
  3276. }
  3277. })
  3278.  
  3279. }
  3280.  
  3281. }
  3282.  
  3283. skipDontRender = ((cnt.visibleItems || 0).length || 0) === 0;
  3284. // console.log('ss1', Date.now())
  3285. if (waitFor.length > 0) {
  3286. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  3287. }
  3288. waitFor.length = 0;
  3289. waitFor = null;
  3290. // console.log('ss2', Date.now())
  3291. cnt.flushActiveItems66_();
  3292. skipDontRender = ((cnt.visibleItems || 0).length || 0) === 0;
  3293. const len2 = cnt.activeItems_.length;
  3294. const bAsync = len1 !== len2;
  3295. await Promise.resolve();
  3296. if (wcController) {
  3297. if (bAsync) {
  3298. cnt.async(() => {
  3299. wcController.afterOper();
  3300. });
  3301. } else {
  3302. wcController.afterOper();
  3303. }
  3304. }
  3305. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3306. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  3307.  
  3308. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  3309. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3310. } else if (changeMaxItemsToDisplay) {
  3311.  
  3312. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  3313. maxItemsToDisplay: this.data.maxItemsToDisplay,
  3314. reducedMaxItemsToDisplay,
  3315. originalMaxItemsToDisplay: tmpMaxItemsCount
  3316. });
  3317. }
  3318. logger && console.log('[End]')
  3319.  
  3320. logger && console.groupEnd();
  3321.  
  3322. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  3323.  
  3324.  
  3325. const ff = () => {
  3326.  
  3327. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3328. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3329. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  3330. cnt.scrollToBottom_();
  3331.  
  3332. Promise.resolve().then(() => {
  3333.  
  3334. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3335. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  3336. });
  3337.  
  3338.  
  3339. }
  3340. }
  3341.  
  3342. ff();
  3343.  
  3344.  
  3345. Promise.resolve().then(ff);
  3346.  
  3347. // requestAnimationFrame(ff);
  3348. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  3349.  
  3350. const knt = cnt;
  3351. if (!scrollChatFn) {
  3352. const cnt = knt;
  3353. const f = () => {
  3354. const itemScroller = cnt.itemScroller;
  3355. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  3356. if (!cnt.atBottom) {
  3357. cnt.scrollToBottom_();
  3358. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  3359. itemScroller.scrollTop = itemScroller.scrollHeight;
  3360. }
  3361. };
  3362. scrollChatFn = () => Promise.resolve().then(f).then(f);
  3363. }
  3364.  
  3365. if (!ENABLE_DELAYED_CHAT_OCCURRENCE) scrollChatFn();
  3366. }
  3367.  
  3368. return 1;
  3369.  
  3370.  
  3371. } catch (e) {
  3372. console.warn(e);
  3373. }
  3374. }
  3375.  
  3376. mclp.flushActiveItems77_ = function () {
  3377.  
  3378. return new Promise(resResolve => {
  3379. try {
  3380. const cnt = this;
  3381. if (mlf > 1e9) mlf = 9;
  3382. let tid = ++mlf;
  3383. const hostElement = cnt.hostElement || cnt;
  3384. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  3385. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  3386.  
  3387. // 4 times to maxItems to avoid frequent trimming.
  3388. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  3389.  
  3390. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3391. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  3392. if (cnt.canScrollToBottom_()) {
  3393. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  3394. .then(() => cnt.flushActiveItems78_(tid)) // async function
  3395. .then((asyncResult) => {
  3396. resResolve(asyncResult); // either undefined or 1
  3397. resResolve = null;
  3398. }).catch((e) => {
  3399. console.warn(e);
  3400. if (resResolve) resResolve();
  3401. });
  3402. } else {
  3403. resResolve(2);
  3404. resResolve = null;
  3405. }
  3406. } catch (e) {
  3407. console.warn(e);
  3408. if (resResolve) resResolve();
  3409. }
  3410.  
  3411.  
  3412. });
  3413.  
  3414. }
  3415.  
  3416. mclp.flushActiveItems_ = function () {
  3417. const cnt = this;
  3418.  
  3419. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  3420.  
  3421. if (cnt.activeItems_.length === 0) {
  3422. cnt.__intermediate_delay__ = null;
  3423. return;
  3424. }
  3425.  
  3426. const cntData = ((cnt || 0).data || 0);
  3427. if (cntData.maxItemsToDisplay944 === undefined) {
  3428. cntData.maxItemsToDisplay944 = null;
  3429. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  3430. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  3431. }
  3432.  
  3433. // ignore previous __intermediate_delay__ and create a new one
  3434. cnt.__intermediate_delay__ = new Promise(resolve => {
  3435. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  3436. if (rt === 1) {
  3437. resolve(1); // success, scroll to bottom
  3438. if (hasMoreMessageState === 1) {
  3439. hasMoreMessageState = 0;
  3440. const showMore = (cnt.$ || 0)['show-more'];
  3441. if (showMore) {
  3442. showMore.classList.remove('has-new-messages-miuzp');
  3443. }
  3444. }
  3445. }
  3446. else if (rt === 2) {
  3447. resolve(2); // success, trim
  3448. if (hasMoreMessageState === 0) {
  3449. hasMoreMessageState = 1;
  3450. const showMore = cnt.$['show-more'];
  3451. if (showMore) {
  3452. showMore.classList.add('has-new-messages-miuzp');
  3453. }
  3454. }
  3455. }
  3456. else resolve(-1); // skip
  3457. }).catch(e => {
  3458. console.warn(e);
  3459. });
  3460. });
  3461.  
  3462. }
  3463. console.log("flushActiveItems_", "OK");
  3464. } else {
  3465. console.log("flushActiveItems_", "NG");
  3466. }
  3467.  
  3468. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  3469. try {
  3470. if (mlg > 1e9) mlg = 9;
  3471. const tid = ++mlg;
  3472. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  3473. const runCond = () => this.canScrollToBottom_();
  3474. if (!keepTrialCond()) return;
  3475. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  3476. await new Promise(r => setTimeout(r, 80));
  3477. if (!keepTrialCond()) return;
  3478. if (runCond()) return this.flushActiveItems_() | 1;
  3479. await new Promise(requestAnimationFrame);
  3480. if (runCond()) return this.flushActiveItems_() | 1;
  3481. } catch (e) {
  3482. console.warn(e);
  3483. }
  3484. }
  3485.  
  3486. if ((mclp.atBottomChanged_ || 0).length === 1) {
  3487. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  3488. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.75.39'));
  3489.  
  3490. const querySelector = HTMLElement.prototype.querySelector;
  3491. const U = (element) => ({
  3492. querySelector: (selector) => querySelector.call(element, selector)
  3493. });
  3494.  
  3495. let qid = 0;
  3496. mclp.atBottomChanged_ = function (a) {
  3497. let tid = ++qid;
  3498. let b = this;
  3499. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  3500. if (tid !== qid) return;
  3501. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  3502. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  3503. this.hideShowMoreAsync_ = null,
  3504. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  3505. }
  3506.  
  3507. console.log("atBottomChanged_", "OK");
  3508. } else {
  3509. console.log("atBottomChanged_", "NG");
  3510. }
  3511.  
  3512. if ((mclp.onScrollItems_ || 0).length === 1) {
  3513.  
  3514. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  3515. mclp.onScrollItems66_ = mclp.onScrollItems_;
  3516. mclp.onScrollItems77_ = async function (evt) {
  3517. if (myw > 1e9) myw = 9;
  3518. let tid = ++myw;
  3519.  
  3520. await new Promise(requestAnimationFrame);
  3521.  
  3522. if (tid !== myw) {
  3523. return;
  3524. }
  3525.  
  3526. const cnt = this;
  3527.  
  3528. await Promise.resolve();
  3529. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  3530. await Promise.resolve().then(() => {
  3531. this.ytRendererBehavior.onScroll(evt);
  3532. }).then(() => {
  3533. if (this.canScrollToBottom_()) {
  3534. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  3535. if (hasUserJustInteracted) {
  3536. // only when there is an user action
  3537. this.setAtBottom();
  3538. return 1;
  3539. }
  3540. } else {
  3541. // no message inserting
  3542. this.setAtBottom();
  3543. return 1;
  3544. }
  3545. }).then((r) => {
  3546.  
  3547. if (this.activeItems_.length) {
  3548.  
  3549. if (this.canScrollToBottom_()) {
  3550. this.flushActiveItems_();
  3551. return 1 && r;
  3552. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  3553. // delayed due to user action
  3554. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  3555. return 0;
  3556. }
  3557. }
  3558. }).then((r) => {
  3559. if (r) {
  3560. // ensure setAtBottom is correctly set
  3561. this.setAtBottom();
  3562. }
  3563. });
  3564. } else {
  3565. cnt.onScrollItems66_(evt);
  3566. }
  3567.  
  3568. await Promise.resolve();
  3569.  
  3570. }
  3571.  
  3572. mclp.onScrollItems_ = function (evt) {
  3573.  
  3574. const cnt = this;
  3575. cnt.__intermediate_delay__ = new Promise(resolve => {
  3576. cnt.onScrollItems77_(evt).then(() => {
  3577. resolve();
  3578. });
  3579. });
  3580. }
  3581. console.log("onScrollItems_", "OK");
  3582. } else {
  3583. console.log("onScrollItems_", "NG");
  3584. }
  3585.  
  3586. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  3587.  
  3588. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  3589. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  3590.  
  3591. mclp.handleLiveChatActions77_ = async function (arr) {
  3592. if (typeof (arr || 0).length !== 'number') {
  3593. this.handleLiveChatActions66_(arr);
  3594. return;
  3595. }
  3596. if (mzt > 1e9) mzt = 9;
  3597. let tid = ++mzt;
  3598.  
  3599. if (zarr === null) zarr = arr;
  3600. else Array.prototype.push.apply(zarr, arr);
  3601. arr = null;
  3602.  
  3603. await new Promise(requestAnimationFrame);
  3604.  
  3605. if (tid !== mzt || zarr === null) {
  3606. return;
  3607. }
  3608.  
  3609. const carr = zarr;
  3610. zarr = null;
  3611.  
  3612. await Promise.resolve();
  3613. this.handleLiveChatActions66_(carr);
  3614. await Promise.resolve();
  3615.  
  3616. }
  3617.  
  3618. mclp.handleLiveChatActions_ = function (arr) {
  3619.  
  3620. const cnt = this;
  3621. cnt.__intermediate_delay__ = new Promise(resolve => {
  3622. cnt.handleLiveChatActions77_(arr).then(() => {
  3623. resolve();
  3624. });
  3625. });
  3626. }
  3627. console.log("handleLiveChatActions_", "OK");
  3628. } else {
  3629. console.log("handleLiveChatActions_", "NG");
  3630. }
  3631.  
  3632. mclp.hasUserJustInteracted11_ = () => {
  3633. const t = dateNow();
  3634. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  3635. }
  3636.  
  3637. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  3638.  
  3639. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  3640.  
  3641. mclp.canScrollToBottom_ = function () {
  3642. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  3643. }
  3644.  
  3645. console.log("canScrollToBottom_", "OK");
  3646. } else {
  3647. console.log("canScrollToBottom_", "NG");
  3648. }
  3649.  
  3650. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  3651.  
  3652. mclp.isSmoothScrollEnabled_ = function () {
  3653. return false;
  3654. }
  3655.  
  3656. mclp.maybeResizeScrollContainer_ = function () {
  3657. //
  3658. }
  3659.  
  3660. mclp.refreshOffsetContainerHeight_ = function () {
  3661. //
  3662. }
  3663.  
  3664. mclp.smoothScroll_ = function () {
  3665. //
  3666. }
  3667.  
  3668. mclp.resetSmoothScroll_ = function () {
  3669. //
  3670. }
  3671. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  3672. } else {
  3673. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  3674. }
  3675.  
  3676. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  3677.  
  3678. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  3679. mclp.handleAddChatItemAction_ = function (a) {
  3680. try {
  3681. if (a && typeof a === 'object' && !('length' in a)) {
  3682. fixLiveChatItem(a.item, null);
  3683. console.assert(arguments[0] === a);
  3684. }
  3685. } catch (e) { console.warn(e) }
  3686. return this.handleAddChatItemAction66_.apply(this, arguments);
  3687. }
  3688.  
  3689. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  3690. } else {
  3691.  
  3692. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  3693. }
  3694.  
  3695.  
  3696. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  3697.  
  3698. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  3699. mclp.handleReplaceChatItemAction_ = function (a) {
  3700. try {
  3701. if (a && typeof a === 'object' && !('length' in a)) {
  3702. fixLiveChatItem(a.replacementItem, null);
  3703. console.assert(arguments[0] === a);
  3704. }
  3705. } catch (e) { console.warn(e) }
  3706. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  3707. }
  3708.  
  3709. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  3710. } else {
  3711.  
  3712. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  3713. }
  3714.  
  3715. console.log("[End]");
  3716. console.groupEnd();
  3717.  
  3718. }).catch(console.warn);
  3719.  
  3720.  
  3721. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  3722.  
  3723. let yd = (this.__dataHost || (this.inst || 0).__dataHost || 0).__data;
  3724.  
  3725. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  3726.  
  3727. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  3728. let v = `${attrValue}`;
  3729. // conside a ticker is 101px width
  3730. // 1% = 1.01px
  3731. // 0.2% = 0.202px
  3732.  
  3733.  
  3734. const ratio1 = (yd.ratio * 100);
  3735. if (ratio1 > -1) { // avoid NaN
  3736.  
  3737. // countdownDurationMs
  3738. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  3739. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  3740. // 150000 - 1% <1% = 1.5s>
  3741. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  3742. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  3743.  
  3744. // 99px * 5% = 4.95px
  3745.  
  3746. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  3747.  
  3748.  
  3749. // 1% Duration
  3750.  
  3751. let ratio2 = ratio1;
  3752.  
  3753. const ydd = yd.data;
  3754. if (ydd) {
  3755.  
  3756. const d1 = ydd.durationSec;
  3757. const d2 = ydd.fullDurationSec;
  3758.  
  3759. // @ step timing [min. 0.2%]
  3760. let numOfSteps = 500;
  3761. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  3762. if (d2 > 400) numOfSteps = 500; // 0.2%
  3763. else if (d2 > 200) numOfSteps = 200; // 0.5%
  3764. else if (d2 > 100) numOfSteps = 100; // 1%
  3765. else if (d2 > 50) numOfSteps = 50; // 2%
  3766. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  3767. else numOfSteps = 20;
  3768. }
  3769. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  3770. if (numOfSteps < 5) numOfSteps = 5;
  3771.  
  3772. const rd = numOfSteps / 100.0;
  3773.  
  3774. ratio2 = Math.round(ratio2 * rd) / rd;
  3775.  
  3776. // ratio2 = Math.round(ratio2 * 5) / 5;
  3777. ratio2 = ratio2.toFixed(1);
  3778. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  3779.  
  3780. if (yd.__style_last__ === v) return;
  3781. yd.__style_last__ = v;
  3782. // do not consider any delay here.
  3783. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  3784.  
  3785. }
  3786. }
  3787.  
  3788. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  3789.  
  3790.  
  3791. } else {
  3792. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  3793. }
  3794.  
  3795. };
  3796.  
  3797.  
  3798. const fpTicker = (renderer) => {
  3799. const cnt = renderer.inst || renderer;
  3800. assertor(() => typeof (cnt || 0).is === 'string');
  3801. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  3802. const container = (cnt.$ || 0).container;
  3803. if (container) {
  3804. assertor(() => (container || 0).nodeType === 1);
  3805. assertor(() => typeof container.setAttribute === 'function');
  3806. container.setAttribute = tickerContainerSetAttribute;
  3807. } else {
  3808. console.warn(`"container" does not exist in ${cnt.is}`);
  3809. }
  3810. };
  3811.  
  3812.  
  3813. const tags = ["yt-live-chat-ticker-paid-message-item-renderer", "yt-live-chat-ticker-paid-sticker-item-renderer",
  3814. "yt-live-chat-ticker-renderer", "yt-live-chat-ticker-sponsor-item-renderer"];
  3815.  
  3816.  
  3817. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  3818.  
  3819. mightFirstCheckOnYtInit();
  3820. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  3821. console.log("[Begin]");
  3822.  
  3823. // << if ENABLE_VIDEO_PROGRESS_STATE_FIX >>
  3824. let isMainVideoOngoing = null;
  3825. let mainVideoLastProgress = null;
  3826. // << end >>
  3827.  
  3828. for (const tag of tags) {
  3829. const dummy = document.createElement(tag);
  3830.  
  3831. const cProto = getProto(dummy);
  3832. if (!cProto || !cProto.attached) {
  3833. console.warn(`proto.attached for ${tag} is unavailable.`);
  3834. continue;
  3835. }
  3836.  
  3837. cProto.attached77 = cProto.attached;
  3838.  
  3839. cProto.attached = function () {
  3840. fpTicker(this.hostElement || this);
  3841. return this.attached77();
  3842. }
  3843.  
  3844. for (const elm of document.getElementsByTagName(tag)) {
  3845. if ((elm || elm.inst).isAttached === true) {
  3846. fpTicker(elm);
  3847. }
  3848. }
  3849.  
  3850.  
  3851. let rafHackState = 0;
  3852.  
  3853. let isTimingFunctionHackable = false;
  3854.  
  3855. let urt = 0;
  3856.  
  3857. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  3858.  
  3859. // console.log('startCountdown', typeof cProto.startCountdown)
  3860. // console.log('updateTimeout', typeof cProto.updateTimeout)
  3861. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  3862.  
  3863. isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  3864.  
  3865. } else {
  3866. console.log(`Skip Timing Function Modification for ${tag}`);
  3867. continue;
  3868. }
  3869.  
  3870.  
  3871. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  3872.  
  3873. // cancelable - this.rafId < isAnimationPausedChanged >
  3874. rafHackState = 1;
  3875.  
  3876. if (isTimingFunctionHackable) {
  3877. rafHackState = 2;
  3878.  
  3879. } else {
  3880. rafHackState = 4;
  3881. }
  3882.  
  3883. }
  3884.  
  3885. const isCSSPropertySupported = () => {
  3886.  
  3887. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return;
  3888. const documentElement = document.documentElement;
  3889. if (!documentElement) {
  3890. console.warn('document.documentElement is not found');
  3891. return false;
  3892. }
  3893. if (`${window.getComputedStyle(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  3894. return false;
  3895. }
  3896. return true;
  3897.  
  3898. };
  3899.  
  3900. const doAnimator = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  3901.  
  3902. const doRAFHack = rafHackState === 2;
  3903.  
  3904. cProto._throwOut = function () {
  3905. this._r782 = 1;
  3906. Promise.resolve().then(() => {
  3907. this.detached();
  3908. this.data = null;
  3909. this.countdownMs = 0;
  3910. this.lastCountdownTimeMs = null;
  3911. if (this.__dataClientsReady === true) this.__dataClientsReady = false;
  3912. if (this.__dataEnabled === true) this.__dataEnabled = false;
  3913. if (this.__dataReady === true) this.__dataReady = false;
  3914. const hm = this.hostElement || this;
  3915. if (hm.parentNode) hm.remove();
  3916. if (hm.firstChild) hm.textContent = '';
  3917. }).catch(e => {
  3918. console.warn(e);
  3919. });
  3920. };
  3921.  
  3922. // cProto._checkTickerBackgroundChanged = doAnimator ? function () {
  3923. // if (runTickerClassName === 'run-ticker') {
  3924. // const container = (this.$ || 0).container || 0;
  3925. // if (!container) return;
  3926. // container.classList.add('run-ticker-test');
  3927. // const evaluated = `${window.getComputedStyle(container).background}`;
  3928. // container.classList.remove('run-ticker-test');
  3929. // if (evaluated.indexOf('0.') < 4) {
  3930. // // not fulfilling
  3931. // // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3932. // runTickerClassName = 'run-ticker-forced';
  3933. // console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3934. // "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3935. // "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3936. // );
  3937. // console.warn(`%cWarning:\n\tYou might have added a userscript or extension that hacks ticker background too.\n\tYouTube Super Fast Chat will override it for you.`, 'color: #bada55');
  3938. // console.groupEnd();
  3939. // }
  3940. // }
  3941. // } : null;
  3942.  
  3943. cProto._makeAnimator = doAnimator ? function () {
  3944. if (this._r782) return;
  3945. // if (!this.isAttached) return;
  3946. if (!this._runnerAE) {
  3947. const aElement = (this.$ || 0).container;
  3948. if (!aElement) return console.warn("this.$.container is undefined");
  3949. const da = this.data;
  3950. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  3951. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  3952. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  3953. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  3954.  
  3955. // if (!this.__tickerBackgroundInitialChecked__) {
  3956. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  3957. // console.log('__tickerBackgroundInitialChecked__')
  3958. // this._checkTickerBackgroundChanged();
  3959. // }
  3960.  
  3961. aElement.style.setProperty('--ticker-c1', c1);
  3962. aElement.style.setProperty('--ticker-c2', c2);
  3963. aElement.classList.add(runTickerClassName);
  3964. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  3965. // this._aeStartV = this.countdownMs;
  3966. // this._aeStartT = this.countdownDurationMs;
  3967. if (!(p >= 0 && p <= 100)) {
  3968. console.warn('incorrect time ratio', p);
  3969. } else {
  3970. /*
  3971. const u0 = p.toFixed(4) + '%';
  3972. this._runnerAE = animate.call(aElement,
  3973. [
  3974. { '--ticker-rtime': u0 },
  3975. { '--ticker-rtime': '0%' }
  3976. ]
  3977. ,
  3978. {
  3979. fill: "forwards",
  3980. duration: this.countdownMs,
  3981. easing: "linear"
  3982. }
  3983. );
  3984. */
  3985.  
  3986. let timingFn = 'linear';
  3987.  
  3988. const totalDuration = this.countdownDurationMs;
  3989.  
  3990. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  3991.  
  3992. // @ step timing [min. 0.2%]
  3993. let stepInterval = 0.2; // unit: %
  3994. if (totalDuration > 400000) stepInterval = 0.2;
  3995. else if (totalDuration > 200000) stepInterval = 0.5;
  3996. else if (totalDuration > 100000) stepInterval = 1;
  3997. else if (totalDuration > 50000) stepInterval = 2;
  3998. else if (totalDuration > 25000) stepInterval = 5;
  3999. else stepInterval = 5;
  4000.  
  4001. let numOfSteps = Math.round(100 / stepInterval);
  4002.  
  4003. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4004. if (numOfSteps < 5) numOfSteps = 5;
  4005.  
  4006. timingFn = `steps(${numOfSteps}, end)`;
  4007.  
  4008. }
  4009.  
  4010.  
  4011.  
  4012. this._runnerAE = animate.call(aElement,
  4013. [
  4014. { '--ticker-rtime': '100%' },
  4015. { '--ticker-rtime': '0%' }
  4016. ]
  4017. ,
  4018. {
  4019. fill: "forwards",
  4020. duration: totalDuration,
  4021. easing: timingFn
  4022. }
  4023. );
  4024.  
  4025. this._runnerAE.onfinish = () => {
  4026. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  4027. this._aeFinished();
  4028. }
  4029. }
  4030.  
  4031. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  4032. if (bq >= 0 && bq <= totalDuration) {
  4033.  
  4034. this._runnerAE.currentTime = bq
  4035. } else {
  4036. console.warn('Error on setting _runnerAE.currentTime!');
  4037. }
  4038.  
  4039.  
  4040. aeConstructor = this._runnerAE.constructor; // constructor is from iframe
  4041. return this._runnerAE;
  4042. }
  4043. } else {
  4044. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  4045. // assume just time update
  4046. const ae = this._runnerAE;
  4047. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  4048. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  4049. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  4050. if (!(p >= 0 && p <= 100)) {
  4051. console.warn('incorrect time ratio', p);
  4052. } else {
  4053. // let u0 = p.toFixed(4) + '%'
  4054. /*
  4055. ae.effect.setKeyframes([
  4056. { '--ticker-rtime': u0 },
  4057. { '--ticker-rtime': '0%' }
  4058. ]);
  4059. ae.effect.updateTiming({ duration: this.countdownMs });
  4060. */
  4061. // ae.currentTime = 0;
  4062.  
  4063.  
  4064.  
  4065. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  4066. if (bq >= 0 && bq <= this.countdownDurationMs) {
  4067.  
  4068. this._runnerAE.currentTime = bq
  4069. } else {
  4070. console.warn('Error on setting _runnerAE.currentTime!');
  4071. }
  4072.  
  4073.  
  4074. ae.play();
  4075. return ae;
  4076. }
  4077. }
  4078. } : null;
  4079.  
  4080. cProto._aeFinished = doAnimator ? function () {
  4081.  
  4082. if (this._r782) return;
  4083.  
  4084. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4085. this._throwOut();
  4086. return;
  4087. }
  4088.  
  4089. if (doAnimator) {
  4090. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4091.  
  4092. let lc = window.performance.now();
  4093. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4094. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4095. this.lastCountdownTimeMs = lc;
  4096. if (this.countdownMs > 10) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs); // just warning.
  4097.  
  4098. this.countdownMs = 0;
  4099. this.lastCountdownTimeMs = null;
  4100.  
  4101. if (this.isAttached) {
  4102. if (Date.now() - windowShownAt < 80) {
  4103. // no animation if the video page is switched from background to foreground
  4104. this.hostElement.style.display = 'none';
  4105. } else {
  4106. "auto" === this.hostElement.style.width && this.setContainerWidth();
  4107. this.slideDown();
  4108. }
  4109. }
  4110.  
  4111.  
  4112. } else {
  4113. console.warn('unexpected issue')
  4114. }
  4115. } : null;
  4116.  
  4117.  
  4118. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  4119.  
  4120. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  4121. urt++;
  4122. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  4123. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  4124. cProto.handlePauseReplay = function () {
  4125. if (this.isAttached) {
  4126.  
  4127. if (pairForPauseResumeM === 0) {
  4128. pairForPauseResume++;
  4129. if (pairForPauseResume > 1e9) pairForPauseResume = pairForPauseResume % 1e4;
  4130. }
  4131. // console.log('handlePauseReplay');
  4132. // console.log('handlePauseReplay', pairForPauseResume);
  4133. const r = this.handlePauseReplay66.apply(this, arguments);
  4134. isMainVideoOngoing = false;
  4135. return r;
  4136. }
  4137. };
  4138. } else {
  4139. console.log('Error for setting cProto.handlePauseReplay', tag)
  4140. }
  4141.  
  4142. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handlePauseReplay.length === 0) {
  4143. urt++;
  4144. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  4145. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  4146. cProto.handleResumeReplay = function () {
  4147. if (this.isAttached) {
  4148.  
  4149. if (pairForPauseResumeM === 0) {
  4150. pairForPauseResume++;
  4151. if (pairForPauseResume > 1e9) pairForPauseResume = pairForPauseResume % 1e4;
  4152. }
  4153. // console.log('handleResumeReplay');
  4154. // console.log('handleResumeReplay', pairForPauseResume);
  4155. const r = this.handleResumeReplay66.apply(this, arguments);
  4156. isMainVideoOngoing = true;
  4157. return r;
  4158.  
  4159. }
  4160. };
  4161. } else {
  4162. console.log('Error for setting cProto.handleResumeReplay', tag)
  4163. }
  4164.  
  4165. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  4166. urt++;
  4167. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  4168. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  4169. cProto.handleReplayProgress = function (a) {
  4170. if (this.isAttached) {
  4171. const p = mainVideoLastProgress;
  4172. mainVideoLastProgress = a;
  4173. if (isMainVideoOngoing === false) { // ignore isMainVideoOngoing === null ?
  4174. const d = a - p;
  4175. if (d > 0 && d < 0.28) isMainVideoOngoing = true; // timeupdate
  4176. // 0.28 is due to
  4177. // - most browsers will fire the timeupdate event between 4 to 60 times per second
  4178. // - i.e. timeupdate roughly every 15-250 milliseconds
  4179. }
  4180. let promiseResult = null;
  4181. if (this.isAnimationPaused) {
  4182. // unstable state for isMainVideoOngoing; delay required
  4183. // all the tickers' handleReplayProgress are executed in the same microtask
  4184. // execute after result returned
  4185. const lz1 = pairForPauseResume;
  4186. Promise.resolve().then(() => {
  4187. return promiseResult
  4188. }).then(() => {
  4189.  
  4190.  
  4191. if (isMainVideoOngoing === true && this.isAnimationPaused) {
  4192. const lz2 = pairForPauseResume;
  4193. // console.log( 10044000, lz1, lz2 , mainVideoLastProgress - a, isMainVideoOngoing )
  4194. if (lz1 === lz2 && mainVideoLastProgress !== null && mainVideoLastProgress - a >= -1e-5) this.isAnimationPaused = false; // trigger isAnimationPausedChanged
  4195. }
  4196.  
  4197. });
  4198. }
  4199.  
  4200. const lq1 = pairForPauseResume;
  4201. promiseResult = Promise.resolve().then(() => {
  4202. const lq2 = pairForPauseResume;
  4203.  
  4204. if (lq1 === lq2) {
  4205. this.handleReplayProgress66(a);
  4206. }
  4207.  
  4208.  
  4209. })
  4210.  
  4211. }
  4212. };
  4213. } else {
  4214. console.log('Error for setting cProto.handleReplayProgress', tag)
  4215. }
  4216.  
  4217. }
  4218.  
  4219. const ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED = ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX && urt === 3;
  4220.  
  4221. const doTimerFnModification = (doRAFHack || doAnimator);
  4222.  
  4223. let windowShownAt = 0;
  4224. if (doTimerFnModification) {
  4225.  
  4226. window.addEventListener('visibilitychange', () => {
  4227. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  4228. else windowShownAt = 0;
  4229. }, false);
  4230.  
  4231. }
  4232.  
  4233. cProto.startCountdown = doTimerFnModification ? function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4234.  
  4235. // a.durationSec [s] => countdownMs [ms]
  4236. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4237. // lastCountdownTimeMs => raf ongoing
  4238. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4239.  
  4240. if (this._r782) return;
  4241.  
  4242. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4243. this._throwOut();
  4244. return;
  4245. }
  4246.  
  4247. if (doAnimator) {
  4248. b = void 0 === b ? 0 : b;
  4249. if (void 0 !== a) {
  4250. this.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  4251. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs; // constant throughout the animation
  4252. if (!(this.lastCountdownTimeMs || this.isAnimationPaused)) {
  4253. this.lastCountdownTimeMs = performance.now()
  4254. this.rafId = 1
  4255. if (this._runnerAE) console.warn('Error in .startCountdown; this._runnerAE already created.')
  4256. this.detlaSincePausedSecs = 0;
  4257. const ae = this._makeAnimator();
  4258. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4259.  
  4260. // console.log(539, isMainVideoOngoing)
  4261. if (this.isAnimationPaused === void 0 && ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED && isMainVideoOngoing === false && mainVideoLastProgress !== null) {
  4262. // << This is mainly for [PlayBack Replay] backwards >>
  4263. // fix the case when the main video is paused but due to seeking the tickers are added
  4264. // play first then pause immediately to allow the visual effect of initial state
  4265. // don't forget to set the "playerProgressSec"
  4266. // otherwise when it resumes from paused state, the detlaSincePausedSecs will be huge
  4267. this.playerProgressSec = mainVideoLastProgress; // save the progress first
  4268. this.isAnimationPaused = true; // trigger isAnimationPausedChanged
  4269. this.detlaSincePausedSecs = 0;
  4270. this._forceNoDetlaSincePausedSecs783 = 1; // reset this.detlaSincePausedSecs = 0 when resumed
  4271. }
  4272. }
  4273. }
  4274. } else {
  4275. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4276. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4277. b = void 0 === b ? 0 : b;
  4278. void 0 !== a && (this.countdownMs = 1E3 * a,
  4279. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs,
  4280. this.ratio = 1,
  4281. this.lastCountdownTimeMs || this.isAnimationPaused || (this.lastCountdownTimeMs = performance.now(),
  4282. this.rafId = rafHub.request(this.boundUpdateTimeout37_)))
  4283. }
  4284.  
  4285. } : cProto.startCountdown;
  4286.  
  4287. cProto.updateTimeout = doTimerFnModification ? function (a) {
  4288.  
  4289. if (this._r782) return;
  4290.  
  4291. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4292. this._throwOut();
  4293. return;
  4294. }
  4295.  
  4296. if (doAnimator) {
  4297. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4298. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4299. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4300. if (this.isAttached && this.countdownMs) {
  4301. this.lastCountdownTimeMs = a
  4302. const ae = this._makeAnimator(); // request raf
  4303. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4304. } else {
  4305. (this.lastCountdownTimeMs = null,
  4306. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4307. this.slideDown()));
  4308. }
  4309. } else {
  4310. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4311. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4312. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4313. this.ratio = this.countdownMs / this.countdownDurationMs;
  4314. this.isAttached && this.countdownMs ? (this.lastCountdownTimeMs = a,
  4315. this.rafId = rafHub.request(this.boundUpdateTimeout37_)) : (this.lastCountdownTimeMs = null,
  4316. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4317. this.slideDown()))
  4318. }
  4319.  
  4320. } : cProto.updateTimeout;
  4321.  
  4322. // let ez = 0;
  4323. cProto.isAnimationPausedChanged = doTimerFnModification ? function (a, b) {
  4324.  
  4325. if (this._r782) return;
  4326.  
  4327. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4328. this._throwOut();
  4329. return;
  4330. }
  4331. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  4332. this._forceNoDetlaSincePausedSecs783 = 0;
  4333.  
  4334. Promise.resolve().then(() => {
  4335.  
  4336. if (doAnimator) {
  4337.  
  4338. const playState = (this._runnerAE || 0).playState;
  4339. if (a && playState === 'running') {
  4340.  
  4341. } else if (!a && playState !== 'running' && b) {
  4342.  
  4343. } else {
  4344. return;
  4345. }
  4346. }
  4347.  
  4348. // if (Math.abs(this.detlaSincePausedSecs) < 0.01) this.detlaSincePausedSecs = 0;
  4349. if (doAnimator) {
  4350. const pu = () => { // running -> pause
  4351. this._runnerAE.pause()
  4352. let lc = window.performance.now();
  4353. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4354. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4355. this.lastCountdownTimeMs = lc;
  4356. };
  4357. const wa = () => { // pause -> running
  4358. if (forceNoDetlaSincePausedSecs783) this.detlaSincePausedSecs = 0;
  4359. a = this.detlaSincePausedSecs ? (this.lastCountdownTimeMs || 0) + 1000 * this.detlaSincePausedSecs : (this.lastCountdownTimeMs || 0);
  4360. this.detlaSincePausedSecs = 0;
  4361. this.updateTimeout(a);
  4362. this.lastCountdownTimeMs = window.performance.now();
  4363. };
  4364. a ? (this._runnerAE && pu()) : (!a && b && wa());
  4365. } else {
  4366. // ez++;
  4367. // if(ez> 1e9) ez=9;
  4368. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4369. a ? rafHub.cancel(this.rafId) : !a && b && (a = this.lastCountdownTimeMs || 0,
  4370. this.detlaSincePausedSecs && (a = (this.lastCountdownTimeMs || 0) + 1E3 * this.detlaSincePausedSecs,
  4371. this.detlaSincePausedSecs = 0),
  4372. this.boundUpdateTimeout37_(a),
  4373. this.lastCountdownTimeMs = window.performance.now())
  4374. }
  4375.  
  4376. }).catch(e => {
  4377. console.log(e);
  4378. });
  4379.  
  4380.  
  4381.  
  4382. } : cProto.isAnimationPausedChanged;
  4383.  
  4384.  
  4385. if (doAnimator) {
  4386.  
  4387. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.81.31'));
  4388.  
  4389. let dummyValueForStyleReturn = null;
  4390.  
  4391. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  4392. cProto.computeContainerStyle = function (a, b) {
  4393.  
  4394. if (this._r782) return;
  4395.  
  4396. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4397. this._throwOut();
  4398. return;
  4399. }
  4400.  
  4401. const fullDurationSec = a ? a.fullDurationSec : 0;
  4402. if (fullDurationSec > 0 && typeof b === 'number') {
  4403.  
  4404. // usually zero
  4405.  
  4406. // let currentDuationSrc = b * fullDurationSec; // a.durationSec
  4407.  
  4408. // console.log(231, fullDurationSec, b, currentDuationSrc, a.durationSec);
  4409.  
  4410. /*
  4411. if (a.mdsz && typeof a.mdst) return a.mdst;
  4412. a.mdsz = 1;
  4413.  
  4414.  
  4415.  
  4416. let c1 = this.colorFromDecimal(a.startBackgroundColor);
  4417. let c2 = this.colorFromDecimal(a.endBackgroundColor);
  4418.  
  4419. let ratio = currentDuationSrc / fullDurationSec;
  4420.  
  4421. let m = (ratio * 100).toFixed(1);
  4422.  
  4423.  
  4424. let s = `--background:linear-gradient(90deg, ${c1},${c1} ${m}%,${c2} ${m}%,${c2});`
  4425. let ro = {
  4426. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4427. "implementsGoogStringTypedString": true
  4428. };
  4429.  
  4430. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4431.  
  4432. a.mdst = s;
  4433.  
  4434. return ro;
  4435. */
  4436. }
  4437.  
  4438.  
  4439.  
  4440. // return this.computeContainerStyle66.apply(this, arguments);
  4441.  
  4442. if (dummyValueForStyleReturn === null) {
  4443.  
  4444. let s = `--nx:82;`
  4445. let ro = {
  4446. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4447. "implementsGoogStringTypedString": true
  4448. };
  4449.  
  4450. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4451.  
  4452.  
  4453. dummyValueForStyleReturn = ro;
  4454.  
  4455.  
  4456. }
  4457.  
  4458.  
  4459. return dummyValueForStyleReturn;
  4460.  
  4461.  
  4462. }
  4463.  
  4464. }
  4465.  
  4466. if (doTimerFnModification === true) hasTimerModified = true;
  4467.  
  4468. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  4469. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  4470. }
  4471.  
  4472. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  4473. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  4474. }
  4475.  
  4476. }
  4477. console.log("[End]");
  4478. console.groupEnd();
  4479.  
  4480.  
  4481. }).catch(console.warn);
  4482.  
  4483. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  4484.  
  4485. mightFirstCheckOnYtInit();
  4486. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  4487. console.log("[Begin]");
  4488. (() => {
  4489.  
  4490. const tag = "yt-live-chat-ticker-renderer"
  4491. const dummy = document.createElement(tag);
  4492.  
  4493. const cProto = getProto(dummy);
  4494. if (!cProto || !cProto.attached) {
  4495. console.warn(`proto.attached for ${tag} is unavailable.`);
  4496. return;
  4497. }
  4498.  
  4499. if (RAF_FIX_keepScrollClamped) {
  4500.  
  4501. // to be improved
  4502.  
  4503. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  4504.  
  4505. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  4506. cProto.keepScrollClamped = function () {
  4507. this._bound_keepScrollClamped = this._bound_keepScrollClamped || this.keepScrollClamped.bind(this);
  4508. this.scrollClampRaf = requestAnimationFrame(this._bound_keepScrollClamped);
  4509. this.maybeClampScroll()
  4510. }
  4511.  
  4512. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  4513. } else {
  4514.  
  4515. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  4516. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  4517. }
  4518.  
  4519. }
  4520.  
  4521.  
  4522. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function' && fnIntegrity(cProto.startScrolling) === '1.44.32' && fnIntegrity(cProto.scrollIncrementally) === '1.82.43') {
  4523. // to be replaced by animator
  4524.  
  4525. cProto.startScrolling = function (a) {
  4526. this.scrollStopHandle && this.cancelAsync(this.scrollStopHandle);
  4527. this.asyncHandle && cancelAnimationFrame(this.asyncHandle);
  4528. this.lastFrameTimestamp = this.scrollStartTime = performance.now();
  4529. this.scrollRatePixelsPerSecond = a;
  4530. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  4531. this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally)
  4532. };
  4533.  
  4534. cProto.scrollIncrementally = function (a) {
  4535. var b = a - (this.lastFrameTimestamp || 0);
  4536. this.$.items.scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  4537. this.maybeClampScroll();
  4538. this.updateArrows();
  4539. this.lastFrameTimestamp = a;
  4540. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  4541. 0 < this.$.items.scrollLeft || this.scrollRatePixelsPerSecond && 0 < this.scrollRatePixelsPerSecond ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  4542. };
  4543.  
  4544. console.log('RAF_FIX: scrollIncrementally', tag, "OK")
  4545. } else {
  4546. assertor(() => fnIntegrity(cProto.startScrolling, '1.44.32'));
  4547. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.82.43'));
  4548. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  4549. }
  4550.  
  4551.  
  4552. })();
  4553.  
  4554. console.log("[End]");
  4555.  
  4556. console.groupEnd();
  4557.  
  4558. }).catch(console.warn);
  4559.  
  4560.  
  4561. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  4562.  
  4563.  
  4564. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  4565.  
  4566. mightFirstCheckOnYtInit();
  4567. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  4568. console.log("[Begin]");
  4569. (() => {
  4570.  
  4571. const tag = "yt-live-chat-message-input-renderer"
  4572. const dummy = document.createElement(tag);
  4573.  
  4574. const cProto = getProto(dummy);
  4575. if (!cProto || !cProto.attached) {
  4576. console.warn(`proto.attached for ${tag} is unavailable.`);
  4577. return;
  4578. }
  4579.  
  4580. let doHack = false;
  4581. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  4582.  
  4583. // not cancellable
  4584.  
  4585.  
  4586. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  4587.  
  4588. }
  4589.  
  4590. if (doHack) {
  4591.  
  4592. cProto.handleTimeout = function (a) {
  4593. console.log('cProto.handleTimeout', tag)
  4594. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  4595. this.timeoutDurationMs = this.timeoutMs = a;
  4596. this.countdownRatio = 1;
  4597. 0 === this.lastTimeoutTimeMs && rafHub.request(this.boundUpdateTimeout38_)
  4598. };
  4599. cProto.updateTimeout = function (a) {
  4600. console.log('cProto.updateTimeout', tag)
  4601. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  4602. this.lastTimeoutTimeMs && (this.timeoutMs = Math.max(0, this.timeoutMs - (a - this.lastTimeoutTimeMs)),
  4603. this.countdownRatio = this.timeoutMs / this.timeoutDurationMs);
  4604. this.isAttached && this.timeoutMs ? (this.lastTimeoutTimeMs = a,
  4605. rafHub.request(this.boundUpdateTimeout38_)) : this.lastTimeoutTimeMs = 0
  4606. };
  4607.  
  4608. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  4609. } else {
  4610.  
  4611. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  4612. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  4613.  
  4614. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  4615. }
  4616.  
  4617. })();
  4618.  
  4619. console.log("[End]");
  4620.  
  4621. console.groupEnd();
  4622.  
  4623.  
  4624. })
  4625.  
  4626.  
  4627. }
  4628.  
  4629. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  4630.  
  4631.  
  4632. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  4633.  
  4634. mightFirstCheckOnYtInit();
  4635. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  4636. console.log("[Begin]");
  4637. (() => {
  4638.  
  4639. const tag = "yt-emoji-picker-renderer"
  4640. const dummy = document.createElement(tag);
  4641.  
  4642. const cProto = getProto(dummy);
  4643. if (!cProto || !cProto.attached) {
  4644. console.warn(`proto.attached for ${tag} is unavailable.`);
  4645. return;
  4646. }
  4647.  
  4648. let doHack = false;
  4649. if (typeof cProto.animateScroll_ === 'function') {
  4650.  
  4651. // not cancellable
  4652. console.log('animateScroll_', typeof cProto.animateScroll_)
  4653.  
  4654. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  4655.  
  4656. }
  4657.  
  4658. if (doHack) {
  4659.  
  4660. const querySelector = HTMLElement.prototype.querySelector;
  4661. const U = (element) => ({
  4662. querySelector: (selector) => querySelector.call(element, selector)
  4663. });
  4664.  
  4665. cProto.animateScroll_ = function (a) {
  4666. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  4667. if (!this.boundAnimateScroll39_) this.boundAnimateScroll39_ = this.animateScroll_.bind(this);
  4668. this.lastAnimationTime_ || (this.lastAnimationTime_ = a);
  4669. a -= this.lastAnimationTime_;
  4670. 200 > a ? (U(this.hostElement).querySelector("#categories").scrollTop = this.animationStart_ + (this.animationEnd_ - this.animationStart_) * a / 200,
  4671. rafHub.request(this.boundAnimateScroll39_)) : (null != this.animationEnd_ && (U(this.hostElement).querySelector("#categories").scrollTop = this.animationEnd_),
  4672. this.animationEnd_ = this.animationStart_ = null,
  4673. this.lastAnimationTime_ = 0);
  4674. this.updateButtons_()
  4675. }
  4676.  
  4677. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  4678. } else {
  4679.  
  4680. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  4681. }
  4682.  
  4683. })();
  4684.  
  4685. console.log("[End]");
  4686.  
  4687. console.groupEnd();
  4688. });
  4689. }
  4690.  
  4691. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  4692.  
  4693.  
  4694. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  4695.  
  4696. mightFirstCheckOnYtInit();
  4697. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  4698. console.log("[Begin]");
  4699. (() => {
  4700.  
  4701. const tag = "yt-live-chat-docked-message"
  4702. const dummy = document.createElement(tag);
  4703.  
  4704. const cProto = getProto(dummy);
  4705. if (!cProto || !cProto.attached) {
  4706. console.warn(`proto.attached for ${tag} is unavailable.`);
  4707. return;
  4708. }
  4709.  
  4710. let doHack = false;
  4711. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  4712.  
  4713. // cancelable - this.intersectRAF <detached>
  4714. // yt-live-chat-docked-message
  4715. // boundCheckIntersections <-> checkIntersections
  4716. // onDockableMessagesChanged
  4717. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  4718.  
  4719. console.log('detached', typeof cProto.detached)
  4720. console.log('checkIntersections', typeof cProto.checkIntersections)
  4721. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  4722.  
  4723. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  4724.  
  4725. }
  4726.  
  4727. if (doHack) {
  4728.  
  4729. cProto.checkIntersections = function () {
  4730. // console.log('cProto.checkIntersections', tag)
  4731. if (this.dockableMessages.length) {
  4732. this.intersectRAF = rafHub.request(this.boundCheckIntersections);
  4733. let a = this.dockableMessages[0]
  4734. , b = this.hostElement.getBoundingClientRect();
  4735. a = a.getBoundingClientRect();
  4736. let c = a.top - b.top
  4737. , d = 8 >= c;
  4738. c = 8 >= c - this.hostElement.clientHeight;
  4739. if (d) {
  4740. let e;
  4741. for (; d;) {
  4742. e = this.dockableMessages.shift();
  4743. d = this.dockableMessages[0];
  4744. if (!d)
  4745. break;
  4746. d = d.getBoundingClientRect();
  4747. c = d.top - b.top;
  4748. let f = 8 >= c;
  4749. if (8 >= c - a.height)
  4750. if (f)
  4751. a = d;
  4752. else
  4753. return;
  4754. d = f
  4755. }
  4756. this.dock(e)
  4757. } else
  4758. c && this.dockedItem && this.clear()
  4759. } else
  4760. this.intersectRAF = 0
  4761. }
  4762.  
  4763. cProto.onDockableMessagesChanged = function () {
  4764. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  4765. this.dockableMessages.length && !this.intersectRAF && (this.intersectRAF = rafHub.request(this.boundCheckIntersections))
  4766. }
  4767.  
  4768. cProto.detached = function () {
  4769. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  4770. }
  4771.  
  4772. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  4773. } else {
  4774.  
  4775. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  4776. }
  4777.  
  4778. })();
  4779.  
  4780. console.log("[End]");
  4781.  
  4782. console.groupEnd();
  4783.  
  4784. }).catch(console.warn);
  4785.  
  4786. }
  4787.  
  4788. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  4789.  
  4790.  
  4791. customElements.whenDefined("yt-img-shadow").then(() => {
  4792.  
  4793. mightFirstCheckOnYtInit();
  4794. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  4795. console.log("[Begin]");
  4796. (() => {
  4797.  
  4798. const tag = "yt-img-shadow"
  4799. const dummy = document.createElement(tag);
  4800.  
  4801. const cProto = getProto(dummy);
  4802. if (!cProto || !cProto.attached) {
  4803. console.warn(`proto.attached for ${tag} is unavailable.`);
  4804. return;
  4805. }
  4806.  
  4807. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  4808.  
  4809. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  4810. cProto.thumbnailChanged_ = function (a) {
  4811.  
  4812. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  4813. if (!this.oldThumbnail_ && !this.thumbnail) return;
  4814.  
  4815. return this.thumbnailChanged66_.apply(this, arguments)
  4816.  
  4817. }
  4818. console.log("cProto.thumbnailChanged_ - OK");
  4819.  
  4820. } else {
  4821. console.log("cProto.thumbnailChanged_ - NG");
  4822.  
  4823. }
  4824. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  4825.  
  4826. cProto.setSrc66_ = cProto.setSrc_;
  4827. cProto.setSrc_ = function (a) {
  4828. if ((((this || 0).$ || 0).img || 0).src === a) return;
  4829. return this.setSrc66_.apply(this, arguments)
  4830. }
  4831.  
  4832. console.log("cProto.setSrc_ - OK");
  4833. } else {
  4834.  
  4835. console.log("cProto.setSrc_ - NG");
  4836. }
  4837.  
  4838. })();
  4839.  
  4840. console.log("[End]");
  4841.  
  4842. console.groupEnd();
  4843.  
  4844. }).catch(console.warn);
  4845.  
  4846. }
  4847.  
  4848. if (FIX_THUMBNAIL_DATACHANGED) {
  4849.  
  4850.  
  4851.  
  4852. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  4853.  
  4854. mightFirstCheckOnYtInit();
  4855. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  4856. console.log("[Begin]");
  4857. (() => {
  4858.  
  4859. const tag = "yt-live-chat-author-badge-renderer"
  4860. const dummy = document.createElement(tag);
  4861.  
  4862. const cProto = getProto(dummy);
  4863. if (!cProto || !cProto.attached) {
  4864. console.warn(`proto.attached for ${tag} is unavailable.`);
  4865. return;
  4866. }
  4867.  
  4868.  
  4869. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && fnIntegrity(cProto.dataChanged) === '1.159.97') {
  4870.  
  4871.  
  4872.  
  4873. cProto.dataChanged86 = cProto.dataChanged;
  4874. cProto.dataChanged = function (a) {
  4875.  
  4876. /*
  4877.  
  4878. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  4879. b.removeChild(b.firstChild);
  4880. if (a)
  4881. if (a.icon) {
  4882. var c = document.createElement("yt-icon");
  4883. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  4884. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  4885. b.appendChild(c)
  4886. } else if (a.customThumbnail) {
  4887. c = document.createElement("img");
  4888. var d;
  4889. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  4890. b.appendChild(c),
  4891. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  4892. }
  4893.  
  4894. */
  4895.  
  4896. const image = ((this || 0).$ || 0).image
  4897. if (image && a && image.firstElementChild) {
  4898. let exisiting = image.firstElementChild;
  4899. if (exisiting === image.lastElementChild) {
  4900.  
  4901.  
  4902. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  4903.  
  4904. let c = exisiting;
  4905. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  4906. if (c.icon !== "yt-sys-icons:shield-filled") c.icon = "yt-sys-icons:shield-filled";
  4907. if (c.defaultToFilled !== true) c.defaultToFilled = true;
  4908. } else {
  4909. let p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  4910. if (c.icon !== p) c.icon = p;
  4911. if (c.defaultToFilled !== false) c.defaultToFilled = false;
  4912. }
  4913. return;
  4914.  
  4915.  
  4916. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  4917.  
  4918. let c = exisiting;
  4919. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  4920.  
  4921. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  4922. return;
  4923. }
  4924. /*
  4925.  
  4926. var d;
  4927. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  4928.  
  4929.  
  4930. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  4931. */
  4932. }
  4933.  
  4934.  
  4935. }
  4936. }
  4937. return this.dataChanged86.apply(this, arguments)
  4938.  
  4939. }
  4940. console.log("cProto.dataChanged - OK");
  4941.  
  4942. } else {
  4943. assertor(() => fnIntegrity(cProto.dataChanged, '1.159.97'));
  4944. console.log("cProto.dataChanged - NG");
  4945.  
  4946. }
  4947.  
  4948. })();
  4949.  
  4950. console.log("[End]");
  4951.  
  4952. console.groupEnd();
  4953.  
  4954. }).catch(console.warn);
  4955.  
  4956.  
  4957. }
  4958.  
  4959.  
  4960. if (FIX_TOOLTIP_DISPLAY) {
  4961.  
  4962.  
  4963. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  4964.  
  4965. mightFirstCheckOnYtInit();
  4966. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  4967. console.log("[Begin]");
  4968. (() => {
  4969.  
  4970. const tag = "tp-yt-paper-tooltip"
  4971. const dummy = document.createElement(tag);
  4972.  
  4973. const cProto = getProto(dummy);
  4974. if (!cProto || !cProto.attached) {
  4975. console.warn(`proto.attached for ${tag} is unavailable.`);
  4976. return;
  4977. }
  4978.  
  4979. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  4980.  
  4981. cProto._readyClients43 = cProto._readyClients;
  4982. cProto._readyClients = function () {
  4983. let r = cProto._readyClients43.apply(this, arguments);
  4984. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  4985. return r;
  4986. }
  4987.  
  4988. console.log("_readyClients - OK");
  4989.  
  4990. } else {
  4991. console.log("_readyClients - NG");
  4992.  
  4993. }
  4994.  
  4995.  
  4996. })();
  4997.  
  4998. console.log("[End]");
  4999.  
  5000. console.groupEnd();
  5001.  
  5002. }).catch(console.warn);
  5003.  
  5004.  
  5005.  
  5006. }
  5007.  
  5008.  
  5009.  
  5010. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  5011.  
  5012.  
  5013. const hookDocumentMouseDownSetupFn = () => {
  5014.  
  5015.  
  5016.  
  5017. let muzTimestamp = 0;
  5018. let nszDropdown = null;
  5019.  
  5020.  
  5021.  
  5022. const handlerObject = {
  5023.  
  5024. // mdHandler282 : function (evt) {
  5025. // // console.log(evt, 1, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5026. // if (!evt || !evt.isTrusted) return;
  5027. // muzTimestamp = 0;
  5028. // nszDropdown = null;
  5029.  
  5030. // const hostElement = this.hostElement || this;
  5031. // if (!evt || !evt.isTrusted || !hostElement.hasAttribute('menu-visible')) return;
  5032. // if (!hostElement.contains(evt.target)) return;
  5033. // let targetDropDown = null;
  5034. // for(const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')){
  5035. // if(dropdown && dropdown.positionTarget && hostElement.contains( dropdown.positionTarget)){
  5036. // targetDropDown = dropdown;
  5037. // }
  5038. // }
  5039. // if ((nszDropdown = targetDropDown)) {
  5040. // muzTimestamp = Date.now();
  5041. // evt.stopImmediatePropagation();
  5042. // evt.stopPropagation();
  5043. // }
  5044.  
  5045. // },
  5046.  
  5047.  
  5048. muHandler282: function (evt) {
  5049. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5050. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5051. const dropdown = nszDropdown;
  5052. muzTimestamp = 0;
  5053. nszDropdown = null;
  5054.  
  5055. const kurMPC = kRef(currentMenuPivotWR) || 0;
  5056. const hostElement = kurMPC.hostElement || kurMPC;
  5057. if (!hostElement.hasAttribute('menu-visible')) return;
  5058. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  5059. muzTimestamp = Date.now();
  5060. evt.stopImmediatePropagation();
  5061. evt.stopPropagation();
  5062. Promise.resolve(dropdown).then((dropdown) => {
  5063. dropdown.cancel();
  5064. });
  5065. // document.body.click();
  5066. }
  5067.  
  5068. },
  5069.  
  5070. mlHandler282: function (evt) {
  5071. muzTimestamp = 0;
  5072. nszDropdown = null;
  5073. },
  5074.  
  5075. ckHandler282: function (evt) {
  5076. // console.log(evt, 3, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5077.  
  5078. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5079. if (Date.now() - muzTimestamp < 40) {
  5080. muzTimestamp = Date.now();
  5081. evt.stopImmediatePropagation();
  5082. evt.stopPropagation();
  5083. }
  5084.  
  5085. },
  5086.  
  5087. tapHandler282: function (evt) {
  5088. // console.log(evt, 2, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5089.  
  5090. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5091. if (Date.now() - muzTimestamp < 40) {
  5092. muzTimestamp = Date.now();
  5093. evt.stopImmediatePropagation();
  5094. evt.stopPropagation();
  5095. }
  5096.  
  5097. },
  5098.  
  5099.  
  5100. handleEvent(evt) {
  5101.  
  5102.  
  5103. if (evt) {
  5104. const kurMPC = kRef(currentMenuPivotWR) || 0;
  5105. const cnt = kurMPC.inst || kurMPC;
  5106. const hostElement = cnt.hostElement || cnt;
  5107. if (!cnt || cnt.isAttached !== true || hostElement.isConnected !== true) return;
  5108. switch (evt.type) {
  5109. // case 'mousedown':
  5110. // return this.mdHandler282.call(kurMPC, evt);
  5111. case 'mouseup':
  5112. return this.muHandler282(evt);
  5113. case 'mouseleave':
  5114. return this.mlHandler282(evt);
  5115. case 'tap':
  5116. return this.tapHandler282(evt);
  5117. case 'click':
  5118. return this.ckHandler282(evt);
  5119. }
  5120. }
  5121.  
  5122. }
  5123.  
  5124.  
  5125.  
  5126. }
  5127.  
  5128. document.addEventListener('mousedown', function (evt) {
  5129.  
  5130. if (!evt || !evt.isTrusted || !evt.target) return;
  5131. muzTimestamp = 0;
  5132. nszDropdown = null;
  5133.  
  5134. /** @type {HTMLElement | null} */
  5135. const kurMP = kRef(currentMenuPivotWR);
  5136. if (!kurMP) return;
  5137. const kurMPC = kurMP.closest('[menu-visible]') || 0;
  5138.  
  5139. if (!kurMPC.isClickableChatRow111 || !kurMPC.isClickableChatRow111() || !kurMPC.contains(evt.target)) return;
  5140.  
  5141. let targetDropDown = null;
  5142. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  5143. if (dropdown && dropdown.positionTarget === kurMP) {
  5144. targetDropDown = dropdown;
  5145. }
  5146. }
  5147.  
  5148. if ((nszDropdown = targetDropDown)) {
  5149. muzTimestamp = Date.now();
  5150. evt.stopImmediatePropagation();
  5151. evt.stopPropagation();
  5152. currentMenuPivotWR = mWeakRef(kurMPC);
  5153.  
  5154. const listenOpts = { capture: true, passive: false, once: true };
  5155.  
  5156. // remove unexcecuted eventHandler
  5157. document.removeEventListener('mouseup', handlerObject, listenOpts);
  5158. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  5159. document.removeEventListener('tap', handlerObject, listenOpts);
  5160. document.removeEventListener('click', handlerObject, listenOpts);
  5161.  
  5162. // inject one time eventHandler to by pass events
  5163. document.addEventListener('mouseup', handlerObject, listenOpts);
  5164. document.addEventListener('mouseleave', handlerObject, listenOpts);
  5165. document.addEventListener('tap', handlerObject, listenOpts);
  5166. document.addEventListener('click', handlerObject, listenOpts);
  5167.  
  5168. }
  5169.  
  5170. }, true);
  5171.  
  5172. }
  5173.  
  5174.  
  5175.  
  5176. customElements.whenDefined('yt-live-chat-text-message-renderer').then(() => {
  5177.  
  5178.  
  5179. mightFirstCheckOnYtInit();
  5180. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-message-renderer hacks");
  5181. console.log("[Begin]");
  5182. (() => {
  5183.  
  5184. const tag = "yt-live-chat-text-message-renderer"
  5185. const dummy = document.createElement(tag);
  5186.  
  5187. const cProto = getProto(dummy);
  5188. if (!cProto || !cProto.attached) {
  5189. console.warn(`proto.attached for ${tag} is unavailable.`);
  5190. return;
  5191. }
  5192.  
  5193.  
  5194. cProto.isClickableChatRow111 = function () {
  5195. return (
  5196. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  5197. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  5198. ); // follow .onItemTap(a)
  5199. }
  5200.  
  5201.  
  5202.  
  5203. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  5204.  
  5205. if (toHookDocumentMouseDown) {
  5206.  
  5207. hookDocumentMouseDownSetupFn();
  5208.  
  5209.  
  5210. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  5211.  
  5212.  
  5213.  
  5214. } else {
  5215.  
  5216. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent NG");
  5217.  
  5218. }
  5219.  
  5220.  
  5221. })();
  5222.  
  5223. console.log("[End]");
  5224.  
  5225. console.groupEnd();
  5226.  
  5227. }).catch(console.warn);
  5228.  
  5229. }
  5230.  
  5231.  
  5232. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  5233.  
  5234. mightFirstCheckOnYtInit();
  5235. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  5236. console.log("[Begin]");
  5237. (() => {
  5238.  
  5239. const tag = "tp-yt-iron-dropdown";
  5240. const dummy = document.createElement(tag);
  5241.  
  5242. const cProto = getProto(dummy);
  5243. if (!cProto || !cProto.attached) {
  5244. console.warn(`proto.attached for ${tag} is unavailable.`);
  5245. return;
  5246. }
  5247.  
  5248.  
  5249. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  5250. cProto.__deraf_hn__ = function (sId, fn) {
  5251. const rhKey = `_rafHandler_${sId}`;
  5252. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  5253. if (m.has(fn)) return m.get(fn);
  5254. const resFn = () => {
  5255. this.__rafs[sId] = null;
  5256. fn.call(this)
  5257. };
  5258. m.set(fn, resFn);
  5259. m.set(resFn, resFn);
  5260. return resFn;
  5261. };
  5262. cProto.__deraf34 = cProto.__deraf;
  5263. cProto.__deraf = function (a, b) { // sId, fn
  5264. let c = this.__rafs;
  5265. null !== c[a] && cancelAnimationFrame(c[a]);
  5266. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  5267. };
  5268. console.log("USE_VANILLA_DEREF - OK");
  5269. } else {
  5270. console.log("USE_VANILLA_DEREF - NG");
  5271. }
  5272.  
  5273. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  5274. cProto.__deraf66 = cProto.__deraf;
  5275. cProto.__deraf = function (sId, fn) {
  5276. if (this.__byPassRAF__) {
  5277. Promise.resolve().then(() => {
  5278. fn.call(this);
  5279. });
  5280. }
  5281. let r = this.__deraf66.apply(this, arguments);
  5282. return r;
  5283. }
  5284. console.log("FIX_DROPDOWN_DERAF - OK");
  5285. } else {
  5286. console.log("FIX_DROPDOWN_DERAF - NG");
  5287. }
  5288.  
  5289.  
  5290. if (FIX_MENU_REOPEN_RENDER_PERFORMANCE && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  5291.  
  5292. let lastClose = null;
  5293. let lastOpen = null;
  5294. let cid = 0;
  5295.  
  5296. cProto.__mtChanged__ = function (b) {
  5297.  
  5298. Promise.resolve().then(() => {
  5299. this._applyFocus();
  5300. }).then(() => {
  5301. b ? this._renderOpened() : this._renderClosed();
  5302. }).catch(console.warn);
  5303.  
  5304. };
  5305.  
  5306. const __moChanged__ = () => {
  5307. if (!cid) return;
  5308. // console.log(553, !!lastOpen, !!lastClose);
  5309. cid = 0;
  5310. if (lastOpen && !lastClose && lastOpen.isAttached) {
  5311. lastOpen.__mtChanged__(1)
  5312. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  5313. lastClose.__mtChanged__(0);
  5314. }
  5315. lastOpen = null;
  5316. lastClose = null;
  5317. };
  5318.  
  5319.  
  5320. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  5321. cProto._openedChanged66 = cProto._openedChanged;
  5322. cProto._openedChanged = function () {
  5323. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  5324. this.__byPassRAF__ = true;
  5325. let r = this._openedChanged66.apply(this, arguments);
  5326. this.__byPassRAF__ = false;
  5327. return r;
  5328. }
  5329. }
  5330.  
  5331. const pSetGet = (key, pdThis, pdBase) => {
  5332. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  5333. return {
  5334. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  5335. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  5336. };
  5337. };
  5338.  
  5339. cProto.__modifiedMenuPropsFn__ = function () {
  5340. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  5341. const pdBase = Object.getOwnPropertyDescriptors(this)
  5342.  
  5343. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  5344. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  5345. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  5346.  
  5347. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  5348. console.warn('there is setter/getter for autoFitOnAttach');
  5349. return;
  5350. }
  5351. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  5352. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  5353. return;
  5354. }
  5355. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  5356. console.warn('there is NO setter-getter for allowOutsideScroll');
  5357. return;
  5358. }
  5359.  
  5360. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  5361.  
  5362. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  5363.  
  5364. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  5365.  
  5366. Object.defineProperties(this, {
  5367. autoFitOnAttach: {
  5368. get() {
  5369. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  5370. return autoFitOnAttach;
  5371. },
  5372. set(nv) {
  5373. autoFitOnAttach = nv;
  5374. return true;
  5375. },
  5376. enumerable: true,
  5377. configurable: true
  5378. }, expandSizingTargetForScrollbars: {
  5379. get() {
  5380. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  5381. return expandSizingTargetForScrollbars;
  5382. },
  5383. set(nv) {
  5384. expandSizingTargetForScrollbars = nv;
  5385. return true;
  5386. },
  5387. enumerable: true,
  5388. configurable: true
  5389. }, allowOutsideScroll: {
  5390. get() {
  5391. if (this._modifiedMenuPropOn062__) return true;
  5392. return allowOutsideScroll;
  5393. },
  5394. set(nv) {
  5395. allowOutsideScroll = nv;
  5396. this.__AllowOutsideScrollPD__.set.call(this, nv);
  5397. return true;
  5398. },
  5399. enumerable: true,
  5400. configurable: true
  5401. }
  5402. })
  5403. };
  5404.  
  5405. /*
  5406. // ***** position() to be changed. *****
  5407. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  5408.  
  5409. overflow: visible !important;
  5410. min-width: max-content !important;
  5411. max-width: max-content !important;
  5412. max-height: max-content !important;
  5413. min-height: max-content !important;
  5414. white-space: nowrap;
  5415. }
  5416.  
  5417. */
  5418. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  5419.  
  5420. let m34 = 0;
  5421. cProto.__refitByPosition__ = function () {
  5422. m34++;
  5423. if (m34 <= 0) m34 = 0;
  5424. if (m34 !== 1) return;
  5425. const hostElement = this.hostElement || this;
  5426. if (document.visibilityState === 'visible') {
  5427. const sizingTarget = this.sizingTarget;
  5428. if (!sizingTarget) {
  5429. m34 = 0;
  5430. return;
  5431. }
  5432.  
  5433. let useVisibilityCollapse = true;
  5434. if (HTMLElement.prototype.querySelector.call(sizingTarget, 'yt-icon:empty')) {
  5435. useVisibilityCollapse = false;
  5436. }
  5437.  
  5438. if (useVisibilityCollapse) {
  5439. hostElement.style.visibility = 'collapse';
  5440. sizingTarget.style.visibility = 'collapse';
  5441. } else {
  5442. hostElement.setAttribute('rNgzQ', '');
  5443. sizingTarget.setAttribute('rNgzQ', '');
  5444. }
  5445.  
  5446. const gn = () => {
  5447.  
  5448. if (useVisibilityCollapse) {
  5449. hostElement.style.visibility = '';
  5450. sizingTarget.style.visibility = '';
  5451. } else {
  5452. hostElement.removeAttribute('rNgzQ');
  5453. sizingTarget.removeAttribute('rNgzQ');
  5454. }
  5455. }
  5456.  
  5457. const an = async () => {
  5458. while (m34 >= 1) {
  5459. await renderReadyPn(sizingTarget);
  5460. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  5461. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  5462. }
  5463. m34--;
  5464. }
  5465. m34 = 0;
  5466. Promise.resolve().then(gn);
  5467. }
  5468. an();
  5469.  
  5470.  
  5471. } else {
  5472. m34 = 0;
  5473. }
  5474. }
  5475. cProto.position34 = cProto.position
  5476. cProto.position = function () {
  5477. if (this._positionInitialize_) {
  5478. this._positionInitialize_ = 0;
  5479. this.__refitByPosition__();
  5480. }
  5481. let r = cProto.position34.apply(this, arguments);
  5482. return r;
  5483. }
  5484. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  5485.  
  5486. } else {
  5487.  
  5488. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  5489.  
  5490. }
  5491.  
  5492.  
  5493.  
  5494. cProto.__openedChanged = function () {
  5495. this._positionInitialize_ = 1;
  5496. // this.removeAttribute('horizontal-align')
  5497. // this.removeAttribute('vertical-align')
  5498. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  5499. this.__menuTypeCheck__ = true;
  5500. if (CHAT_MENU_SCROLL_UNLOCKING) {
  5501. this._modifiedMenuPropOn062__ = false;
  5502. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  5503. // this.autoFitOnAttach = true;
  5504. // this.expandSizingTargetForScrollbars = true;
  5505. // this.allowOutsideScroll = true;
  5506. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  5507. this.__modifiedMenuPropsFn__();
  5508. // this.constrain= function(){}
  5509. // this.position= function(){}
  5510.  
  5511. // this.autoFitOnAttach = true;
  5512. // this.expandSizingTargetForScrollbars = true;
  5513. // this.allowOutsideScroll = true;
  5514. }
  5515. }
  5516. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  5517. let newValue = null;
  5518. const positionTarget = this.positionTarget;
  5519. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  5520. if (this._modifiedMenuPropOn062__ === false) {
  5521. newValue = true;
  5522. }
  5523. } else if (this._modifiedMenuPropOn062__ === true) {
  5524. newValue = false;
  5525. }
  5526. if (newValue !== null) {
  5527. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  5528. this._modifiedMenuPropOn062__ = newValue;
  5529. const afterAllowOutsideScroll = this.allowOutsideScroll;
  5530. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  5531. }
  5532. }
  5533.  
  5534. if (this.opened) {
  5535.  
  5536. Promise.resolve().then(() => {
  5537.  
  5538. this._prepareRenderOpened();
  5539. }).then(() => {
  5540. this._manager.addOverlay(this);
  5541. if (this._manager._overlays.length === 1) {
  5542. lastOpen = this;
  5543. lastClose = null;
  5544. } else {
  5545. return 1;
  5546. }
  5547. // if (cid) {
  5548. // clearTimeout(cid);
  5549. // cid = -1;
  5550. // this.__moChanged__();
  5551. // cid = 0;
  5552. // } else {
  5553. // cid = -1;
  5554. // this.__moChanged__();
  5555. // cid = 0;
  5556. // }
  5557. // cid = cid > 0 ? clearTimeout(cid) : 0;
  5558. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  5559. // cid = cid || setTimeout(__moChanged__, delay1);
  5560. cid = cid || requestAnimationFrame(__moChanged__);
  5561. }).then((r) => {
  5562.  
  5563. if (r) this.__mtChanged__(1);
  5564. }).catch(console.warn);
  5565.  
  5566. } else {
  5567. Promise.resolve().then(() => {
  5568. this._manager.removeOverlay(this);
  5569. if (this._manager._overlays.length === 0) {
  5570. lastClose = this;
  5571. lastOpen = null;
  5572. } else {
  5573. return 1;
  5574. }
  5575. // cid = cid > 0 ? clearTimeout(cid) : 0;
  5576. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  5577. // cid = cid || setTimeout(__moChanged__, delay1);
  5578. cid = cid || requestAnimationFrame(__moChanged__);
  5579. }).then((r) => {
  5580. if (r) this.__mtChanged__(0);
  5581. }).catch(console.warn);
  5582.  
  5583. }
  5584.  
  5585. }
  5586. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANCE - OK");
  5587.  
  5588. } else {
  5589.  
  5590. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  5591. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC - NG");
  5592.  
  5593. }
  5594.  
  5595.  
  5596. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  5597.  
  5598. cProto.__openedChanged82 = cProto.__openedChanged;
  5599.  
  5600.  
  5601. cProto.__openedChanged = function () {
  5602.  
  5603. // currentMenuPivotWR = null;
  5604. // console.log(1480, '__openedChanged.A', this.positionTarget)
  5605.  
  5606.  
  5607.  
  5608. // if (this.opened && this.positionTarget) {
  5609.  
  5610. // const positionTarget = this.positionTarget;
  5611. // console.log(1480, '__openedChanged.B', positionTarget)
  5612. // currentMenuPivotWR = mWeakRef(positionTarget);
  5613.  
  5614. // }
  5615.  
  5616. const positionTarget = this.positionTarget;
  5617. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  5618. return this.__openedChanged82.apply(this, arguments);
  5619. }
  5620. }
  5621.  
  5622.  
  5623. // if(FIX_MENU_CAPTURE_SCROLL && typeof cProto.__onCaptureScroll === 'function' && !cProto.__onCaptureScroll66){
  5624.  
  5625. // cProto.__onCaptureScroll66 = cProto.__onCaptureScroll;
  5626.  
  5627. // cProto.__onCaptureScroll = function(a){
  5628.  
  5629. // const q = true;
  5630. // if(this.scrollAction === 'lock' && q && this.opened){
  5631.  
  5632. // // console.log(9107, this.scrollAction, this.__isAnimating, this.opened, a); // lock; __isAnimating = false
  5633. // async function af() {
  5634. // this.__isAnimating && this._finishRenderOpened();
  5635. // if (!this.opened) return;
  5636. // this.__restoreScrollPosition();
  5637. // await new Promise(r => requestAnimationFrame(r));
  5638. // if (!this.opened) return;
  5639. // this.opened && this.__isAnimating && this._finishRenderOpened();
  5640. // if (!this.opened) return;
  5641. // this.__restoreScrollPosition();
  5642. // await new Promise(r => requestAnimationFrame(r));
  5643. // if (!this.opened) return;
  5644. // this.opened && this.__isAnimating && this._finishRenderOpened();
  5645. // if (!this.opened) return;
  5646. // this.opened && !this.__isAnimating && this.refit();
  5647. // }
  5648. // Promise.resolve().then(af);
  5649.  
  5650. // return cProto.__onCaptureScroll66.apply(this, arguments);
  5651. // }else{
  5652.  
  5653. // // console.log(9102, this.scrollAction, this.__isAnimating, this.opened, a); // lock
  5654.  
  5655. // return cProto.__onCaptureScroll66.apply(this, arguments);
  5656. // }
  5657. // }
  5658. // console.log("FIX_MENU_CAPTURE_SCROLL - OK");
  5659. // }else{
  5660. // console.log("FIX_MENU_CAPTURE_SCROLL - NG");
  5661.  
  5662. // }
  5663.  
  5664.  
  5665. })();
  5666.  
  5667. console.log("[End]");
  5668.  
  5669. console.groupEnd();
  5670.  
  5671. }).catch(console.warn);
  5672.  
  5673.  
  5674.  
  5675.  
  5676. }
  5677.  
  5678. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  5679.  
  5680.  
  5681.  
  5682.  
  5683.  
  5684. });
  5685.  
  5686. })({ IntersectionObserver });