YouTube 超快聊天

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

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

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