YouTube 超快聊天

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

目前为 2023-08-22 提交的版本。查看 最新版本

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