YouTube 超快聊天

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

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

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