YouTube 超快聊天

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

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

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