YouTube 超快聊天

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

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

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