YouTube 超快聊天

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

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

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