YouTube 超快聊天

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

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

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