YouTube 超快聊天

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

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

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.51.0
  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. // << if DO_PARTICIPANT_LIST_HACKS >>
  74. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  75. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  76. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  77. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  78. // << end >>
  79.  
  80. // show more button
  81. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  82.  
  83. // faster stampDomArray_ for participants list creation
  84. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  85. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  86.  
  87. // reuse yt components
  88. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  89.  
  90. // images <Group#I01>
  91. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  92. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  93. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  94.  
  95. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  96. // << if DO_LINK_PREFETCH >>
  97. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  98. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  99. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  100. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  101. // << end >>
  102.  
  103. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  104. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  105. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  106.  
  107. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  108. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  109.  
  110. const ATTEMPT_ANIMATED_TICKER_BACKGROUND = 'steps' // false OR '' for disabled, 'linear', 'steps' for easing-function
  111. // << if ATTEMPT_ANIMATED_TICKER_BACKGROUND >>
  112. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  113. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  114. // [limiting 500 max steps] is recommended for "confortable visual change"
  115. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  116. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  117. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  118. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  119. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  120. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  121. // << end >>
  122.  
  123. const FIX_TOOLTIP_DISPLAY = true;
  124. const USE_VANILLA_DEREF = true;
  125. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  126.  
  127.  
  128. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  129. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = true; // pause auto scroll faster when the context menu is about to show
  130. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  131.  
  132. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  133. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  134. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  135. // const FIX_MENU_CAPTURE_SCROLL = true;
  136. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  137.  
  138. const RAF_FIX_keepScrollClamped = true;
  139. const RAF_FIX_scrollIncrementally = true;
  140.  
  141. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  142. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  143.  
  144. const DE_JSONPRUNE_FOR_readyStateChangeHandler_ = 1; // jsonPrune for Ad-Blocking is not applicable to live_chat streaming
  145. // << end >>
  146.  
  147. const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = true;
  148.  
  149. const CHANGE_DATA_FLUSH_ASYNC = true;
  150. const CHANGE_MANAGER_UNSUBSCRIBE = true;
  151.  
  152. const DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION = true;
  153.  
  154. const CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED = true;
  155.  
  156. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  157. /*
  158.  
  159. ### Time Approach
  160.  
  161. // all below values can make the time interval > 250ms
  162. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  163. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  164. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  165. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  166. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  167. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  168.  
  169. ### Pixel Check
  170. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  171. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  172. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  173.  
  174. ### Example - totalDuration = 280000
  175. totalDuration 280000
  176. stepInterval 0.5
  177. numOfSteps = Math.round(100 / stepInterval) = 200
  178. time interval = 280000 / 200 = 1400ms <acceptable>
  179.  
  180. ### Example - totalDuration = 18000
  181. totalDuration 18000
  182. stepInterval 5
  183. numOfSteps = Math.round(100 / stepInterval) = 20
  184. time interval = 18000 / 20 = 900ms <acceptable>
  185.  
  186. ### Example - totalDuration = 5000
  187. totalDuration 5000
  188. stepInterval 5
  189. numOfSteps = Math.round(100 / stepInterval) = 20
  190. time interval = 5000 / 20 = 250ms <threshold value>
  191.  
  192. ### Example - totalDuration = 3600
  193. totalDuration 3600
  194. stepInterval 5
  195. numOfSteps = Math.round(100 / stepInterval) = 20
  196. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  197.  
  198. */
  199.  
  200. // =======================================================================================================
  201.  
  202. // AUTOMAICALLY DETERMINED
  203. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  204. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  205. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  206. let runTickerClassName = 'run-ticker';
  207.  
  208. const dummyImgURL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  209. /*
  210. WebP: data:image/webp;base64,UklGRjAB
  211. PNG: data:image/png;base64,iVBORw0KGg==
  212. JPEG: data:image/jpeg;base64,/9j/4AA=
  213. GIF: data:image/gif;base64,R0lGODlhAQABAIA=
  214. BMP: data:image/bmp;base64,Qk1oAAAA
  215. SVG: data:image/svg+xml;base64,PHN2Zy8+Cg==
  216.  
  217. WebP: data:image/webp;base64,AAAAAAA=
  218. PNG: data:image/png;base64,AAAAAAA=
  219. JPEG: data:image/jpeg;base64,AAAAAAA=
  220. GIF: data:image/gif;base64,AAAAAAA=
  221. BMP: data:image/bmp;base64,AAAAAAA=
  222.  
  223. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  224.  
  225.  
  226. */
  227.  
  228. // image sizing code
  229. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  230.  
  231.  
  232. // function KC(a, b, c, d) {
  233. // d = void 0 === d ? "width" : d;
  234. // if (!a || !a.length)
  235. // return null;
  236. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  237. // var e = window.devicePixelRatio;
  238. // 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"));
  239. // HC = e
  240. // } else
  241. // HC || (HC = window.devicePixelRatio);
  242. // e = HC;
  243. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  244. // if (z("kevlar_tuner_min_thumbnail_quality"))
  245. // return a[0].url || null;
  246. // e = a.length;
  247. // if (z("kevlar_tuner_max_thumbnail_quality"))
  248. // return a[e - 1].url || null;
  249. // if (c)
  250. // for (var h = 0; h < e; h++)
  251. // if (0 <= a[h].url.indexOf(c))
  252. // return a[h].url || null;
  253. // for (c = 0; c < e; c++)
  254. // if (a[c][d] >= b)
  255. // return a[c].url || null;
  256. // for (b = e - 1; 0 < b; b--)
  257. // if (a[b][d])
  258. // return a[b].url || null;
  259. // return a[0].url || null
  260. // }
  261.  
  262. const { IntersectionObserver } = __CONTEXT__;
  263.  
  264. /** @type {globalThis.PromiseConstructor} */
  265. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  266.  
  267. let jsonParseFix = null;
  268.  
  269. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  270. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  271.  
  272. // necessity of cssText3_smooth_transform_position to be checked.
  273. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  274.  
  275. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  276. position: static !important;
  277. }
  278.  
  279. `: '';
  280.  
  281. // fallback if dummy style fn fails
  282. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  283.  
  284. /* optional */
  285. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  286. height: auto !important;
  287. min-height: unset !important;
  288. }
  289.  
  290. #items.style-scope.yt-live-chat-item-list-renderer {
  291. transform: translateY(0px) !important;
  292. }
  293.  
  294. /* optional */
  295.  
  296. `: '';
  297.  
  298. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  299.  
  300. /* ------------------------------------------------------------------------------------------------------------- */
  301.  
  302. 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 {
  303. contain: layout style;
  304. }
  305.  
  306. #items.style-scope.yt-live-chat-item-list-renderer {
  307. contain: layout paint style;
  308. }
  309.  
  310. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  311. contain: style;
  312. }
  313.  
  314. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  315. contain: size style;
  316. }
  317.  
  318. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  319. contain: size layout paint style;
  320. }
  321.  
  322. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  323. contain: layout paint style;
  324. }
  325.  
  326. 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 {
  327. contain: layout style;
  328. }
  329.  
  330. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  331. contain: layout paint style;
  332. }
  333.  
  334. /* ------------------------------------------------------------------------------------------------------------- */
  335.  
  336. ` : '';
  337.  
  338. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  339.  
  340. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  341. top: 4px;
  342. transition-property: top;
  343. bottom: unset;
  344. }
  345.  
  346. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  347. top: -42px;
  348. }
  349.  
  350. `: '';
  351.  
  352. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  353.  
  354. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  355. contain: layout style;
  356. }
  357.  
  358. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  359. overflow: visible;
  360. }
  361.  
  362. `: '';
  363.  
  364. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  365.  
  366. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  367. --yt-live-chat-action-panel-top-border: none;
  368. }
  369.  
  370. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  371. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  372. }
  373.  
  374. html #panel-pages.yt-live-chat-renderer {
  375. border-top: 0;
  376. border-bottom: 0;
  377. }
  378.  
  379. `: '';
  380.  
  381. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  382.  
  383. img,
  384. yt-img-shadow[height][width],
  385. yt-img-shadow {
  386. content-visibility: visible !important;
  387. }
  388.  
  389. ` : '';
  390.  
  391. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  392.  
  393. /* remove YouTube constant will-change */
  394. /* constant value will slow down the performance; default auto */
  395.  
  396. /* www-player.css */
  397. html .ytp-contextmenu,
  398. html .ytp-settings-menu {
  399. will-change: unset;
  400. }
  401.  
  402. /* frequently matched elements */
  403. html .fill.yt-interaction,
  404. html .stroke.yt-interaction,
  405. html .yt-spec-touch-feedback-shape__fill,
  406. html .yt-spec-touch-feedback-shape__stroke {
  407. will-change: unset;
  408. }
  409.  
  410. /* live_chat_polymer.js */
  411. /*
  412. html .toggle-button.tp-yt-paper-toggle-button,
  413. html #primaryProgress.tp-yt-paper-progress,
  414. html #secondaryProgress.tp-yt-paper-progress,
  415. html #onRadio.tp-yt-paper-radio-button,
  416. html .fill.yt-interaction,
  417. html .stroke.yt-interaction,
  418. html .yt-spec-touch-feedback-shape__fill,
  419. html .yt-spec-touch-feedback-shape__stroke {
  420. will-change: unset;
  421. }
  422. */
  423.  
  424. /* desktop_polymer_enable_wil_icons.js */
  425. /* html .fill.yt-interaction,
  426. html .stroke.yt-interaction, */
  427. html tp-yt-app-header::before,
  428. html tp-yt-iron-list,
  429. html #items.tp-yt-iron-list > *,
  430. html #onRadio.tp-yt-paper-radio-button,
  431. html .toggle-button.tp-yt-paper-toggle-button,
  432. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  433. html #items.ytd-post-multi-image-renderer,
  434. html #items.ytd-horizontal-card-list-renderer,
  435. html #items.yt-horizontal-list-renderer,
  436. html #left-arrow.yt-horizontal-list-renderer,
  437. html #right-arrow.yt-horizontal-list-renderer,
  438. html #items.ytd-video-description-infocards-section-renderer,
  439. html #items.ytd-video-description-music-section-renderer,
  440. html #chips.ytd-feed-filter-chip-bar-renderer,
  441. html #chips.yt-chip-cloud-renderer,
  442. html #items.ytd-merch-shelf-renderer,
  443. html #items.ytd-product-details-image-carousel-renderer,
  444. html ytd-video-preview,
  445. html #player-container.ytd-video-preview,
  446. html #primaryProgress.tp-yt-paper-progress,
  447. html #secondaryProgress.tp-yt-paper-progress,
  448. html ytd-miniplayer[enabled] /* ,
  449. html .yt-spec-touch-feedback-shape__fill,
  450. html .yt-spec-touch-feedback-shape__stroke */ {
  451. will-change: unset;
  452. }
  453.  
  454. /* other */
  455. .ytp-videowall-still-info-content[class],
  456. .ytp-suggestion-image[class] {
  457. will-change: unset !important;
  458. }
  459.  
  460. ` : '';
  461.  
  462. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  463. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  464.  
  465. elzm-fonts {
  466. visibility: collapse;
  467. position: fixed;
  468. top: -10px;
  469. left: -10px;
  470. font-size: 10pt;
  471. line-height: 100%;
  472. width: 100px;
  473. height: 100px;
  474. transform: scale(0.1);
  475. transform: scale(0.01);
  476. transform: scale(0.001);
  477. transform-origin: 0 0;
  478. contain: strict;
  479. display: block;
  480.  
  481. pointer-events: none !important;
  482. user-select: none !important;
  483. }
  484.  
  485. elzm-fonts[id]#elzm-fonts-yk75g {
  486. user-select: none !important;
  487. pointer-events: none !important;
  488. }
  489.  
  490. elzm-font {
  491. visibility: collapse;
  492. position: absolute;
  493. line-height: 100%;
  494. width: 100px;
  495. height: 100px;
  496. contain: strict;
  497. display: block;
  498.  
  499. user-select: none !important;
  500. pointer-events: none !important;
  501. }
  502.  
  503. elzm-font::before {
  504. visibility: collapse;
  505. position: absolute;
  506. line-height: 100%;
  507. width: 100px;
  508. height: 100px;
  509. contain: strict;
  510. display: block;
  511.  
  512. 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';
  513.  
  514. user-select: none !important;
  515. pointer-events: none !important;
  516. }
  517.  
  518. `: '';
  519.  
  520. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  521. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  522. -webkit-backdrop-filter: none;
  523. backdrop-filter: none;
  524. }
  525. `: '';
  526.  
  527. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  528.  
  529. @keyframes blinker-miuzp {
  530. 0%, 60%, 100% {
  531. opacity: 1;
  532. }
  533. 30% {
  534. opacity: 0.6;
  535. }
  536. }
  537.  
  538. yt-icon-button#show-more.has-new-messages-miuzp {
  539. animation: blinker-miuzp 1.74s linear infinite;
  540. }
  541.  
  542. `: '';
  543.  
  544.  
  545. const addCss = () => `
  546.  
  547. @property --ticker-rtime {
  548. syntax: "<percentage>";
  549. inherits: false;
  550. initial-value: 0%;
  551. }
  552.  
  553. /*
  554. .run-ticker {
  555. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  556. }
  557.  
  558. .run-ticker-test {
  559. background: #00000001;
  560. }
  561.  
  562. .run-ticker-forced,
  563. yt-live-chat-ticker-renderer #items > * > #container.run-ticker-forced,
  564. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker-forced[class]
  565. {
  566. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2)) !important;
  567. }
  568. */
  569.  
  570. .run-ticker {
  571. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  572. }
  573.  
  574. .run-ticker,
  575. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  576. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  577. {
  578. background: var(--ticker-bg) !important;
  579. }
  580.  
  581. yt-live-chat-ticker-dummy777-item-renderer {
  582. background: #00000001;
  583. }
  584.  
  585. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  586. position: fixed !important;
  587. top: -1000px !important;
  588. left: -1000px !important;
  589. font-size: 1px !important;
  590. color: transparent !important;
  591. pointer-events: none !important;
  592. z-index: -1 !important;
  593. contain: strict !important;
  594. box-sizing: border-box !important;
  595. pointer-events: none !important;
  596. user-select: none !important;
  597. max-width: 1px !important;
  598. max-height: 1px !important;
  599. overflow: hidden !important;
  600. visibility: collapse !important;
  601. display: none !important;
  602. }
  603.  
  604. yt-live-chat-ticker-dummy777-item-renderer #container {
  605. background: inherit;
  606. }
  607.  
  608.  
  609. ${cssText8_fonts_pre_render}
  610.  
  611. ${cssText9_no_backdrop_filter_when_menu_shown}
  612.  
  613. @supports (contain: layout paint style) {
  614.  
  615. ${cssText5}
  616.  
  617. }
  618.  
  619. @supports (color: var(--general)) {
  620.  
  621. html {
  622. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  623. }
  624.  
  625. ${cssText3_smooth_transform_position}
  626.  
  627. ${cssText7c_will_change_unset}
  628.  
  629. ${cssText7b_content_visibility_unset}
  630.  
  631. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  632. overflow-y: scroll;
  633. padding-right: 0;
  634. }
  635.  
  636. ${cssText4_smooth_transform_forced_props}
  637.  
  638. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  639. pointer-events: none !important;
  640. }
  641.  
  642. #continuations, #continuations * {
  643. contain: strict;
  644. position: fixed;
  645. top: 2px;
  646. height: 1px;
  647. width: 2px;
  648. height: 1px;
  649. visibility: collapse;
  650. }
  651.  
  652. ${cssText6b_show_more_button}
  653.  
  654. ${cssText6d_input_panel_border}
  655.  
  656. ${cssText6c_input_panel_overflow}
  657.  
  658. }
  659.  
  660.  
  661. @supports (overflow-anchor: auto) {
  662.  
  663. .no-anchor * {
  664. overflow-anchor: none;
  665. }
  666. .no-anchor > item-anchor {
  667. overflow-anchor: auto;
  668. }
  669.  
  670. item-anchor {
  671.  
  672. height:1px;
  673. width: 100%;
  674. transform: scaleY(0.00001);
  675. transform-origin:0 0;
  676. contain: strict;
  677. opacity:0;
  678. display:flex;
  679. position:relative;
  680. flex-shrink:0;
  681. flex-grow:0;
  682. margin-bottom:0;
  683. overflow:hidden;
  684. box-sizing:border-box;
  685. visibility: visible;
  686. content-visibility: visible;
  687. contain-intrinsic-size: auto 1px;
  688. pointer-events:none !important;
  689.  
  690. }
  691.  
  692. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  693. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  694. }
  695.  
  696. html item-anchor {
  697.  
  698. height: 1px;
  699. width: 1px;
  700. top: auto;
  701. left: auto;
  702. right: auto;
  703. bottom: auto;
  704. transform: translateY(-1px);
  705. position: absolute;
  706. z-index: -1;
  707.  
  708. }
  709.  
  710. }
  711.  
  712. @supports (color: var(--pre-rendering)) {
  713.  
  714. @keyframes dontRenderAnimation {
  715. 0% {
  716. background-position-x: 3px;
  717. }
  718. 100% {
  719. background-position-x: 4px;
  720. }
  721. }
  722.  
  723. .dont-render[class] {
  724. /* visibility: collapse !important; */
  725. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://greasyfork.org/scripts/469878/discussions/197267 */
  726.  
  727. transform: scale(0.01) !important;
  728. transform: scale(0.00001) !important;
  729. transform: scale(0.0000001) !important;
  730. transform-origin: 0 0 !important;
  731. z-index: -1 !important;
  732. contain: strict !important;
  733. box-sizing: border-box !important;
  734.  
  735. height: 1px !important;
  736. height: 0.1px !important;
  737. height: 0.01px !important;
  738. height: 0.0001px !important;
  739. height: 0.000001px !important;
  740.  
  741. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  742.  
  743. pointer-events: none !important;
  744. user-select: none !important;
  745.  
  746. }
  747.  
  748. #sk35z {
  749. display: block !important;
  750.  
  751. visibility: collapse !important;
  752.  
  753. transform: scale(0.01) !important;
  754. transform: scale(0.00001) !important;
  755. transform: scale(0.0000001) !important;
  756. transform-origin: 0 0 !important;
  757. z-index: -1 !important;
  758. contain: strict !important;
  759. box-sizing: border-box !important;
  760.  
  761. height: 1px !important;
  762. height: 0.1px !important;
  763. height: 0.01px !important;
  764. height: 0.0001px !important;
  765. height: 0.000001px !important;
  766.  
  767. position: absolute !important;
  768. top: -1000px !important;
  769. left: -1000px !important;
  770.  
  771. }
  772.  
  773. }
  774.  
  775. [rNgzQ] {
  776. opacity: 0.1 !important;
  777. opacity: 0.01 !important;
  778. opacity: 0.001 !important;
  779. opacity: 0.0001 !important;
  780. opacity: 0.00001 !important;
  781. opacity: 0.00000001 !important;
  782.  
  783. pointer-events: none !important;
  784. }
  785.  
  786. ${cssText10_show_more_blinker}
  787.  
  788. `;
  789.  
  790.  
  791. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  792.  
  793. // Create a unique key for the script and check if it is already running
  794. const hkey_script = 'mchbwnoasqph';
  795. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  796. win[hkey_script] = true;
  797.  
  798. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  799.  
  800. let te4 = setTimeout(() => { }); // dummy; skip timerId only;
  801. if (te4 < 3) {
  802. setTimeout(() => { });
  803. setTimeout(() => { });
  804. }
  805.  
  806. }
  807.  
  808. class Mutex {
  809.  
  810. constructor() {
  811. this.p = Promise.resolve()
  812. }
  813.  
  814. /**
  815. * @param {(lockResolve: () => void)} f
  816. */
  817. lockWith(f) {
  818. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  819. }
  820.  
  821. }
  822.  
  823. function dr(s) {
  824. // reserved for future use
  825. return s;
  826. // return window.deWeakJS ? window.deWeakJS(s) : s;
  827. }
  828.  
  829. const getProto = (element) => {
  830. if (element) {
  831. const cnt = element.inst || element;
  832. return cnt.constructor.prototype || null;
  833. }
  834. return null;
  835. }
  836.  
  837. const assertor = (f) => f() || console.assert(false, f + "");
  838.  
  839. const fnIntegrity = (f, d) => {
  840. if (!f || typeof f !== 'function') {
  841. console.warn('f is not a function', f);
  842. return;
  843. }
  844. let p = f + "", s = 0, j = -1, w = 0;
  845. for (let i = 0, l = p.length; i < l; i++) {
  846. const t = p[i];
  847. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  848. if (j < i - 1) w++;
  849. j = i;
  850. } else {
  851. s++;
  852. }
  853. }
  854. let itz = `${f.length}.${s}.${w}`;
  855. if (!d) {
  856. return itz;
  857. } else {
  858. return itz === d;
  859. }
  860. }
  861.  
  862.  
  863. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  864.  
  865. let ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE = false;
  866. const isContainSupport = CSS.supports('contain', 'layout paint style');
  867. if (!isContainSupport) {
  868. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  869. } else {
  870. ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE = true;
  871. }
  872.  
  873. let ENABLE_OVERFLOW_ANCHOR_CAPABLE = false;
  874. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  875. if (!isOverflowAnchorSupport) {
  876. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  877. } else {
  878. ENABLE_OVERFLOW_ANCHOR_CAPABLE = true;
  879. }
  880.  
  881. 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.
  882.  
  883. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && ENABLE_OVERFLOW_ANCHOR_CAPABLE && ENABLE_NO_SMOOTH_TRANSFORM;
  884. const ENABLE_DELAYED_CHAT_OCCURRENCE = ENABLE_DELAYED_CHAT_OCCURRENCE_PREFERRED && ENABLE_DELAYED_CHAT_OCCURRENCE_CAPABLE && ENABLE_OVERFLOW_ANCHOR && ENABLE_NO_SMOOTH_TRANSFORM && NOT_FIREFOX;
  885.  
  886. let hasTimerModified = null;
  887. const DO_CHECK_TICKER_BACKGROUND_OVERRIDED = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND || ENABLE_RAF_HACK_TICKERS;
  888.  
  889. const fxOperator = (proto, propertyName) => {
  890. let propertyDescriptorGetter = null;
  891. try {
  892. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  893. } catch (e) { }
  894. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  895. try {
  896.  
  897. return propertyDescriptorGetter.call(dr(e));
  898. } catch (e) { }
  899. return e[propertyName];
  900. } : (e) => e[propertyName];
  901. };
  902.  
  903. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  904. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  905. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  906. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  907. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  908.  
  909. const groupCollapsed = (text1, text2) => {
  910.  
  911. console.groupCollapsed(`%c${text1}%c${text2}`,
  912. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  913. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  914. );
  915. }
  916.  
  917.  
  918. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  919. const onRegistryReady = (callback) => {
  920. if (typeof customElements === 'undefined') {
  921. if (!('__CE_registry' in document)) {
  922. // https://github.com/webcomponents/polyfills/
  923. Object.defineProperty(document, '__CE_registry', {
  924. get() {
  925. // return undefined
  926. },
  927. set(nv) {
  928. if (typeof nv == 'object') {
  929. delete this.__CE_registry;
  930. this.__CE_registry = nv;
  931. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  932. }
  933. return true;
  934. },
  935. enumerable: false,
  936. configurable: true
  937. })
  938. }
  939. let eventHandler = (evt) => {
  940. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  941. const f = callback;
  942. callback = null;
  943. eventHandler = null;
  944. f();
  945. };
  946. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  947. } else {
  948. callback();
  949. }
  950. };
  951.  
  952. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  953.  
  954. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  955.  
  956. return new Promise(resolve => {
  957.  
  958. let ro = new ResizeObserver(entries => {
  959. if (entries && entries.length >= 1) {
  960. resolve();
  961. ro.disconnect();
  962. ro = null;
  963. }
  964. });
  965. ro.observe(sizingTarget);
  966.  
  967.  
  968.  
  969. });
  970.  
  971. } : (sizingTarget) => {
  972.  
  973.  
  974. return new Promise(resolve => {
  975.  
  976. let io = new IntersectionObserver(entries => {
  977. if (entries && entries.length >= 1) {
  978. resolve();
  979. io.disconnect();
  980. io = null;
  981. }
  982. });
  983. io.observe(sizingTarget);
  984.  
  985.  
  986.  
  987. });
  988.  
  989. };
  990.  
  991. /* globals WeakRef:false */
  992.  
  993. /** @type {(o: Object | null) => WeakRef | null} */
  994. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  995.  
  996. /** @type {(wr: Object | null) => Object | null} */
  997. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  998.  
  999. const { addCssManaged } = (() => {
  1000.  
  1001. const addFontPreRendering = () => {
  1002.  
  1003. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  1004.  
  1005. let efsContainer = document.createElement('elzm-fonts');
  1006. efsContainer.id = 'elzm-fonts-yk75g'
  1007.  
  1008. const arr = [];
  1009. let p = document.createElement('elzm-font');
  1010. arr.push(p);
  1011.  
  1012. if (ENABLE_FONT_PRE_RENDERING & 1) {
  1013. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1014.  
  1015. p = document.createElement('elzm-font');
  1016. p.style.fontWeight = size;
  1017. arr.push(p);
  1018. }
  1019. }
  1020.  
  1021. if (ENABLE_FONT_PRE_RENDERING & 2) {
  1022. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1023.  
  1024. p = document.createElement('elzm-font');
  1025. p.style.fontFamily = 'Roboto';
  1026. p.style.fontWeight = size;
  1027. arr.push(p);
  1028. }
  1029. }
  1030.  
  1031. if (ENABLE_FONT_PRE_RENDERING & 4) {
  1032. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1033.  
  1034. p = document.createElement('elzm-font');
  1035. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  1036. p.style.fontWeight = size;
  1037. arr.push(p);
  1038. }
  1039. }
  1040.  
  1041.  
  1042. if (ENABLE_FONT_PRE_RENDERING & 8) {
  1043. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1044.  
  1045. p = document.createElement('elzm-font');
  1046. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  1047. p.style.fontWeight = size;
  1048. arr.push(p);
  1049. }
  1050. }
  1051.  
  1052.  
  1053. if (ENABLE_FONT_PRE_RENDERING & 16) {
  1054. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1055.  
  1056. p = document.createElement('elzm-font');
  1057. p.style.fontFamily = 'sans-serif';
  1058. p.style.fontWeight = size;
  1059. arr.push(p);
  1060. }
  1061. }
  1062.  
  1063. console.log('number of elzm-font elements', arr.length);
  1064.  
  1065. HTMLElement.prototype.append.apply(efsContainer, arr);
  1066.  
  1067. (document.body || document.documentElement).appendChild(efsContainer);
  1068.  
  1069.  
  1070. console.log('elzm-font elements have been added to the page for rendering.');
  1071.  
  1072. console.groupEnd();
  1073.  
  1074. }
  1075.  
  1076. let isCssAdded = false;
  1077.  
  1078. function addCssElement() {
  1079. let s = document.createElement('style');
  1080. s.id = 'ewRvC';
  1081. return s;
  1082. }
  1083.  
  1084. const addCssManaged = () => {
  1085. if (!isCssAdded && document.documentElement && document.head) {
  1086. isCssAdded = true;
  1087. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  1088. if (ENABLE_FONT_PRE_RENDERING) {
  1089. Promise.resolve().then(addFontPreRendering)
  1090. }
  1091. }
  1092. }
  1093.  
  1094. return { addCssManaged };
  1095. })();
  1096.  
  1097.  
  1098. const { setupStyle } = (() => {
  1099.  
  1100. const sp7 = Symbol();
  1101.  
  1102. const proxyHelperFn = (dummy) => ({
  1103.  
  1104. get(target, prop) {
  1105. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  1106. },
  1107. set(target, prop, value) {
  1108. if (!(prop in dummy)) {
  1109. target[prop] = value;
  1110. }
  1111. return true;
  1112. },
  1113. has(target, prop) {
  1114. return (prop in target);
  1115. },
  1116. deleteProperty(target, prop) {
  1117. return true;
  1118. },
  1119. ownKeys(target) {
  1120. return Object.keys(target);
  1121. },
  1122. defineProperty(target, key, descriptor) {
  1123. return Object.defineProperty(target, key, descriptor);
  1124. },
  1125. getOwnPropertyDescriptor(target, key) {
  1126. return Object.getOwnPropertyDescriptor(target, key);
  1127. },
  1128.  
  1129. });
  1130.  
  1131. const setupStyle = (m1, m2) => {
  1132. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  1133.  
  1134. const dummy1v = {
  1135. transform: '',
  1136. height: '',
  1137. minHeight: '',
  1138. paddingBottom: '',
  1139. paddingTop: ''
  1140. };
  1141.  
  1142. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  1143. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  1144. dummy1v[k] = dummyStyleFn(k);
  1145. }
  1146.  
  1147. const dummy1p = proxyHelperFn(dummy1v);
  1148. const sp1v = new Proxy(m1.style, dummy1p);
  1149. const sp2v = new Proxy(m2.style, dummy1p);
  1150. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  1151. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  1152. m1.removeAttribute("style");
  1153. m2.removeAttribute("style");
  1154.  
  1155. }
  1156.  
  1157. return { setupStyle };
  1158.  
  1159. })();
  1160.  
  1161.  
  1162.  
  1163. function setThumbnails(config) {
  1164.  
  1165. const { baseObject, thumbnails, flag0, imageLinks } = config;
  1166.  
  1167. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  1168.  
  1169.  
  1170. if (thumbnails && thumbnails.length > 0) {
  1171. if (flag0 > 0 && thumbnails.length > 1) {
  1172. let pSize = 0;
  1173. let newThumbnails = [];
  1174. for (const thumbnail of thumbnails) {
  1175. if (!thumbnail || !thumbnail.url) continue;
  1176. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  1177. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  1178. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  1179. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  1180. newThumbnails.push(thumbnail);
  1181. if (imageLinks) imageLinks.add(thumbnail.url);
  1182. }
  1183. if (squarePhoto && condSize && leastSizeFulfilled) {
  1184. pSize = thumbnail.width;
  1185. }
  1186. }
  1187. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  1188. baseObject.thumbnails = newThumbnails;
  1189. } else {
  1190. newThumbnails.length = 0;
  1191. }
  1192. newThumbnails = null;
  1193. } else {
  1194. for (const thumbnail of thumbnails) {
  1195. if (thumbnail && thumbnail.url) {
  1196. if (imageLinks) imageLinks.add(thumbnail.url);
  1197. }
  1198. }
  1199. }
  1200. }
  1201.  
  1202. }
  1203. }
  1204.  
  1205. function fixLiveChatItem(item, imageLinks) {
  1206. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  1207. if (liveChatTextMessageRenderer) {
  1208. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  1209. if (messageRuns && messageRuns.length > 0) {
  1210. for (const run of messageRuns) {
  1211. const emojiImage = (((run || 0).emoji || 0).image || 0);
  1212. setThumbnails({
  1213. baseObject: emojiImage,
  1214. thumbnails: emojiImage.thumbnails,
  1215. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  1216. imageLinks
  1217. });
  1218. }
  1219. }
  1220. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  1221. setThumbnails({
  1222. baseObject: authorPhoto,
  1223. thumbnails: authorPhoto.thumbnails,
  1224. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  1225. imageLinks
  1226. });
  1227. }
  1228. }
  1229.  
  1230.  
  1231. const flagsFnOnInterval = (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS) ? (() => {
  1232.  
  1233. const flags = () => {
  1234. try {
  1235. return ytcfg.data_.EXPERIMENT_FLAGS;
  1236. } catch (e) { }
  1237. return null;
  1238. };
  1239.  
  1240. const flagsForced = () => {
  1241. try {
  1242. return ytcfg.data_.EXPERIMENTS_FORCED_FLAGS;
  1243. } catch (e) { }
  1244. return null;
  1245. };
  1246.  
  1247. const flagsFn = (EXPERIMENT_FLAGS) => {
  1248.  
  1249. if (!EXPERIMENT_FLAGS) return;
  1250.  
  1251. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1252. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1253. EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true;
  1254. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1255. }
  1256. }
  1257.  
  1258. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1259. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1260. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1261. }
  1262.  
  1263. };
  1264.  
  1265. const uf = (EXPERIMENT_FLAGS) => {
  1266. if (EXPERIMENT_FLAGS === undefined) EXPERIMENT_FLAGS = flags();
  1267. if (EXPERIMENT_FLAGS) {
  1268. flagsFn(EXPERIMENT_FLAGS);
  1269. flagsFn(flagsForced());
  1270. }
  1271. }
  1272.  
  1273. uf();
  1274.  
  1275. const flagsFnOnInterval = (setInterval, clearInterval) => {
  1276.  
  1277. uf();
  1278. let cidFlags = 0;
  1279. let kd = 0;
  1280. new Promise(flagResolve => {
  1281.  
  1282. const flagTimer = () => {
  1283. const EXPERIMENT_FLAGS = flags();
  1284. if (!EXPERIMENT_FLAGS) return;
  1285. uf(EXPERIMENT_FLAGS);
  1286. if (kd > 0) return;
  1287. kd = 1;
  1288. const delay1000 = new Promise(resolve => setTimeout(resolve, 1000));
  1289. const moDeferred = new Promise(resolve => {
  1290. let mo = new MutationObserver(() => {
  1291. if (mo) {
  1292. mo.disconnect();
  1293. mo.takeRecords();
  1294. mo = null;
  1295. resolve();
  1296. }
  1297. });
  1298. mo.observe(document, { subtree: true, childList: true });
  1299. });
  1300. Promise.race([delay1000, moDeferred]).then(flagResolve);
  1301. };
  1302.  
  1303. uf();
  1304. cidFlags = setInterval(flagTimer, 1);
  1305. }).then(() => {
  1306. if (cidFlags > 0) clearInterval(cidFlags);
  1307. cidFlags = 0;
  1308. uf();
  1309. });
  1310.  
  1311. }
  1312.  
  1313. return flagsFnOnInterval;
  1314.  
  1315. })() : null;
  1316.  
  1317. let kptPF = null;
  1318. const emojiPrefetched = new Set();
  1319. const authorPhotoPrefetched = new Set();
  1320.  
  1321. function linker(link, rel, href, _as) {
  1322. return new Promise(resolve => {
  1323. if (!link) link = document.createElement('link');
  1324. link.rel = rel;
  1325. if (_as) link.setAttribute('as', _as);
  1326. link.onload = function () {
  1327. resolve({
  1328. link: this,
  1329. success: true
  1330. })
  1331. this.remove();
  1332. };
  1333. link.onerror = function () {
  1334. resolve({
  1335. link: this,
  1336. success: false
  1337. });
  1338. this.remove();
  1339. };
  1340. link.href = href;
  1341. document.head.appendChild(link);
  1342. link = null;
  1343. });
  1344. }
  1345.  
  1346.  
  1347.  
  1348. const cleanContext = async (win) => {
  1349. const waitFn = requestAnimationFrame; // shall have been binded to window
  1350. try {
  1351. let mx = 16; // MAX TRIAL
  1352. const frameId = 'vanillajs-iframe-v1';
  1353. /** @type {HTMLIFrameElement | null} */
  1354. let frame = document.getElementById(frameId);
  1355. let removeIframeFn = null;
  1356. if (!frame) {
  1357. frame = document.createElement('iframe');
  1358. frame.id = 'vanillajs-iframe-v1';
  1359. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  1360. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  1361. n.appendChild(frame);
  1362. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  1363. const root = document.documentElement;
  1364. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  1365. removeIframeFn = (setTimeout) => {
  1366. const removeIframeOnDocumentReady = (e) => {
  1367. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1368. win = null;
  1369. setTimeout(() => {
  1370. n.remove();
  1371. n = null;
  1372. }, 200);
  1373. }
  1374. if (document.readyState !== 'loading') {
  1375. removeIframeOnDocumentReady();
  1376. } else {
  1377. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1378. }
  1379. }
  1380. }
  1381. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  1382. const fc = frame.contentWindow;
  1383. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  1384. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval } = fc;
  1385. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval };
  1386. for (let k in res) res[k] = res[k].bind(win); // necessary
  1387. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  1388. res.animate = HTMLElement.prototype.animate;
  1389. jsonParseFix = {
  1390. _JSON: fc.JSON, _parse: fc.JSON.parse
  1391. }
  1392. return res;
  1393. } catch (e) {
  1394. console.warn(e);
  1395. return null;
  1396. }
  1397. };
  1398.  
  1399. cleanContext(win).then(__CONTEXT__ => {
  1400. if (!__CONTEXT__) return null;
  1401.  
  1402. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate } = __CONTEXT__;
  1403.  
  1404.  
  1405.  
  1406. let foregroundPromiseForLiveChatFlush = null;
  1407.  
  1408. const getForegroundPromiseForLiveChatFlush = () => {
  1409. if (document.visibilityState === 'visible') return Promise.resolve();
  1410. else {
  1411. return (foregroundPromiseForLiveChatFlush = (foregroundPromiseForLiveChatFlush || new Promise(resolve => {
  1412. requestAnimationFrame(() => {
  1413. foregroundPromiseForLiveChatFlush = null;
  1414. resolve();
  1415. });
  1416. })));
  1417. }
  1418. }
  1419.  
  1420. let aeConstructor = null;
  1421.  
  1422. // << if ENABLE_VIDEO_PROGRESS_STATE_FIX >>
  1423. let pairForPauseResume = 0; // each increasion = number of ticker
  1424. let pairForPauseResumeM = 0;
  1425. // << end >>
  1426.  
  1427. // << __openedChanged82 >>
  1428. let currentMenuPivotWR = null;
  1429.  
  1430. // << if DO_PARTICIPANT_LIST_HACKS >>
  1431. const beforeParticipantsMap = new WeakMap();
  1432. // << end >>
  1433.  
  1434.  
  1435.  
  1436. // << if onRegistryReadyForDOMOperations >>
  1437.  
  1438. let dt0 = Date.now() - 2000;
  1439. const dateNow = () => Date.now() - dt0;
  1440. // let lastScroll = 0;
  1441. // let lastLShow = 0;
  1442. let lastWheel = 0;
  1443. let lastMouseDown = 0;
  1444. let lastMouseUp = 0;
  1445. let currentMouseDown = false;
  1446. let lastTouchDown = 0;
  1447. let lastTouchUp = 0;
  1448. let currentTouchDown = false;
  1449. let lastUserInteraction = 0;
  1450.  
  1451. let scrollChatFn = null;
  1452.  
  1453. let skipDontRender = true; // true first; false by flushActiveItems_
  1454. let allowDontRender = null;
  1455.  
  1456. // ---- #items mutation ----
  1457. let sk35zResolveFn = null;
  1458. let firstList = true;
  1459.  
  1460. // << end >>
  1461.  
  1462. class RAFHub {
  1463. constructor() {
  1464. /** @type {number} */
  1465. this.startAt = 8170;
  1466. /** @type {number} */
  1467. this.counter = 0;
  1468. /** @type {number} */
  1469. this.rid = 0;
  1470. /** @type {Map<number, FrameRequestCallback>} */
  1471. this.funcs = new Map();
  1472. const funcs = this.funcs;
  1473. /** @type {FrameRequestCallback} */
  1474. this.bCallback = this.mCallback.bind(this);
  1475. this.pClear = () => funcs.clear();
  1476. this.keepRAF = false;
  1477. }
  1478. /** @param {DOMHighResTimeStamp} highResTime */
  1479. mCallback(highResTime) {
  1480. this.rid = 0;
  1481. Promise.resolve().then(this.pClear);
  1482. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  1483. }
  1484. /** @param {FrameRequestCallback} f */
  1485. request(f) {
  1486. if (this.counter > 1e9) this.counter = 9;
  1487. let cid = this.startAt + (++this.counter);
  1488. this.funcs.set(cid, f);
  1489. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  1490. return cid;
  1491. }
  1492. /** @param {number} cid */
  1493. cancel(cid) {
  1494. cid = +cid;
  1495. if (cid > 0) {
  1496. if (cid <= this.startAt) {
  1497. return cancelAnimationFrame(cid);
  1498. }
  1499. if (this.rid > 0) {
  1500. this.funcs.delete(cid);
  1501. if (this.funcs.size === 0 && !this.keepRAF) {
  1502. cancelAnimationFrame(this.rid);
  1503. this.rid = 0;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509.  
  1510. function basePrefetching() {
  1511.  
  1512. new Promise(resolve => {
  1513.  
  1514. if (document.readyState !== 'loading') {
  1515. resolve();
  1516. } else {
  1517. win.addEventListener("DOMContentLoaded", resolve, false);
  1518. }
  1519.  
  1520. }).then(() => {
  1521. const hostL1 = [
  1522. 'https://www.youtube.com', 'https://googlevideo.com',
  1523. 'https://googleapis.com', 'https://accounts.youtube.com',
  1524. 'https://www.gstatic.com', 'https://ggpht.com',
  1525. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  1526. ];
  1527.  
  1528. const hostL2 = [
  1529. 'https://youtube.com',
  1530. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  1531. ];
  1532.  
  1533. let link = null;
  1534.  
  1535. function kn() {
  1536.  
  1537. link = document.createElement('link');
  1538. if (link.relList && link.relList.supports) {
  1539. 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)
  1540. } else {
  1541. kptPF = 0;
  1542. }
  1543.  
  1544. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  1545. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  1546. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  1547. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  1548. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  1549. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  1550. console.groupEnd();
  1551.  
  1552. }
  1553.  
  1554. for (const h of hostL1) {
  1555.  
  1556. if (kptPF === null) kn();
  1557. if (ENABLE_BASE_PREFETCHING) {
  1558. // if (kptPF & 1) {
  1559. // linker(link, 'dns-prefetch', h);
  1560. // link = null;
  1561. // }
  1562. if (kptPF & 2) {
  1563. linker(link, 'preconnect', h);
  1564. link = null;
  1565. }
  1566. }
  1567. }
  1568.  
  1569. for (const h of hostL2) {
  1570. if (kptPF === null) kn();
  1571. if (ENABLE_BASE_PREFETCHING) {
  1572. if (kptPF & 1) {
  1573. linker(link, 'dns-prefetch', h);
  1574. link = null;
  1575. }
  1576. }
  1577. }
  1578.  
  1579. })
  1580.  
  1581.  
  1582. }
  1583.  
  1584. if (flagsFnOnInterval) flagsFnOnInterval(setInterval, clearInterval);
  1585.  
  1586. if (DO_LINK_PREFETCH) basePrefetching();
  1587.  
  1588. const { notifyPath7081 } = (() => {
  1589. // DO_PARTICIPANT_LIST_HACKS
  1590.  
  1591. const mutexParticipants = new Mutex();
  1592.  
  1593. let uvid = 0;
  1594. let r95dm = 0;
  1595. let c95dm = -1;
  1596.  
  1597. const foundMap = (base, content) => {
  1598. /*
  1599. let lastSearch = 0;
  1600. let founds = base.map(baseEntry => {
  1601. let search = content.indexOf(baseEntry, lastSearch);
  1602. if (search < 0) return false;
  1603. lastSearch = search + 1;
  1604. return true;
  1605. });
  1606. return founds;
  1607. */
  1608. const contentSet = new Set(content);
  1609. return base.map(baseEntry => contentSet.has(baseEntry));
  1610.  
  1611. }
  1612.  
  1613.  
  1614.  
  1615. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  1616.  
  1617. const handler1 = {
  1618. get(target, prop, receiver) {
  1619. if (prop === 'object') {
  1620. return participants; // avoid memory leakage
  1621. }
  1622. if (prop === 'type') {
  1623. return 'splice';
  1624. }
  1625. return target[prop];
  1626. }
  1627. };
  1628. const releaser = () => {
  1629. participants = null;
  1630. }
  1631.  
  1632. let foundsForAfter = foundMap(idsAfter, idsBefore);
  1633. let foundsForBefore = foundMap(idsBefore, idsAfter);
  1634.  
  1635. let indexSplices = [];
  1636. let contentUpdates = [];
  1637. for (let i = 0, j = 0; i < foundsForBefore.length || j < foundsForAfter.length;) {
  1638. if (beforeParticipants[i] === participants[j]) {
  1639. i++; j++;
  1640. } else if (idsBefore[i] === idsAfter[j]) {
  1641. // content changed
  1642. contentUpdates.push({ indexI: i, indexJ: j })
  1643. i++; j++;
  1644. } else {
  1645. let addedCount = 0;
  1646. for (let q = j; q < foundsForAfter.length; q++) {
  1647. if (foundsForAfter[q] === false) addedCount++;
  1648. else break;
  1649. }
  1650. let removedCount = 0;
  1651. for (let q = i; q < foundsForBefore.length; q++) {
  1652. if (foundsForBefore[q] === false) removedCount++;
  1653. else break;
  1654. }
  1655. if (!addedCount && !removedCount) {
  1656. throw 'ERROR(0xFF32): spliceIndicesFunc';
  1657. }
  1658. indexSplices.push(new Proxy({
  1659. index: j,
  1660. addedCount: addedCount,
  1661. removed: removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  1662. }, handler1));
  1663. i += removedCount;
  1664. j += addedCount;
  1665. }
  1666. }
  1667. foundsForBefore = null;
  1668. foundsForAfter = null;
  1669. idsBefore = null;
  1670. idsAfter = null;
  1671. beforeParticipants = null;
  1672. return { indexSplices, contentUpdates, releaser };
  1673.  
  1674. }
  1675.  
  1676. /*
  1677.  
  1678. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  1679.  
  1680. VM63631:1 Error
  1681. at customElements.get.notifyPath (<anonymous>:1:122)
  1682. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  1683. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  1684. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  1685. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  1686. at ju (live_chat_polymer.js:1674:217)
  1687. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  1688. at b._flushProperties (live_chat_polymer.js:1597:200)
  1689. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  1690. at a.notifyPath (live_chat_polymer.js:1741:182)
  1691.  
  1692. */
  1693.  
  1694. function convertToIds(participants) {
  1695. return participants.map(participant => {
  1696. if (!participant || typeof participant !== 'object') {
  1697. console.warn('Error(0xFA41): convertToIds', participant);
  1698. return participant; // just in case
  1699. }
  1700. let keys = Object.keys(participant);
  1701. // liveChatTextMessageRenderer
  1702. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  1703. // liveChatPaidMessageRenderer
  1704. /*
  1705.  
  1706. 'yt-live-chat-participant-renderer' utilizes the following:
  1707. authorName.simpleText: string
  1708. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  1709. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  1710. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  1711. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  1712.  
  1713. */
  1714. if (keys.length !== 1) {
  1715. console.warn('Error(0xFA42): convertToIds', participant);
  1716. return participant; // just in case
  1717. }
  1718. let key = keys[0];
  1719. let renderer = (participant[key] || 0);
  1720. let authorName = (renderer.authorName || 0);
  1721. let text = `${authorName.simpleText || authorName.text}`
  1722. let res = participant; // fallback if it is not a vaild entry
  1723. if (typeof text !== 'string') {
  1724. console.warn('Error(0xFA53): convertToIds', participant);
  1725. } else {
  1726. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  1727. if (text.length > 1) res = text;
  1728. }
  1729. return res;
  1730. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  1731. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  1732. });
  1733. }
  1734.  
  1735. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  1736. // just update when content is changed.
  1737. if (p1.authorName !== p2.authorName) return true;
  1738. if (p1.authorPhoto !== p2.authorPhoto) return true;
  1739. if (p1.authorBadges !== p2.authorBadges) return true;
  1740. return false;
  1741. } : (p1, p2) => {
  1742. // keep integrity all the time.
  1743. return p1 !== p2; // always true
  1744. }
  1745.  
  1746. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  1747.  
  1748. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  1749. if (path !== "participantsManager.participants") {
  1750. return this.__notifyPath5036__.apply(this, arguments);
  1751. }
  1752. if (c95dm === r95dm) return;
  1753. } else {
  1754. const stack = new Error().stack;
  1755. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  1756. return this.__notifyPath5036__.apply(this, arguments);
  1757. }
  1758. }
  1759.  
  1760. if (uvid > 1e8) uvid = uvid % 100;
  1761. let tid = ++uvid;
  1762.  
  1763. const cnt = this; // "yt-live-chat-participant-list-renderer"
  1764. mutexParticipants.lockWith(lockResolve => {
  1765.  
  1766. const participants00 = cnt.participantsManager.participants;
  1767.  
  1768. if (tid !== uvid || typeof (participants00 || 0).splice !== 'function') {
  1769. lockResolve();
  1770. return;
  1771. }
  1772.  
  1773. let doUpdate = false;
  1774.  
  1775. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  1776.  
  1777. if (!participants00.r94dm) {
  1778. participants00.r94dm = 1;
  1779. if (++r95dm > 1e9) r95dm = 9;
  1780. participants00.push = function () {
  1781. if (++r95dm > 1e9) r95dm = 9;
  1782. return Array.prototype.push.apply(this, arguments);
  1783. }
  1784. participants00.pop = function () {
  1785. if (++r95dm > 1e9) r95dm = 9;
  1786. return Array.prototype.pop.apply(this, arguments);
  1787. }
  1788. participants00.shift = function () {
  1789. if (++r95dm > 1e9) r95dm = 9;
  1790. return Array.prototype.shift.apply(this, arguments);
  1791. }
  1792. participants00.unshift = function () {
  1793. if (++r95dm > 1e9) r95dm = 9;
  1794. return Array.prototype.unshift.apply(this, arguments);
  1795. }
  1796. participants00.splice = function () {
  1797. if (++r95dm > 1e9) r95dm = 9;
  1798. return Array.prototype.splice.apply(this, arguments);
  1799. }
  1800. participants00.sort = function () {
  1801. if (++r95dm > 1e9) r95dm = 9;
  1802. return Array.prototype.sort.apply(this, arguments);
  1803. }
  1804. participants00.reverse = function () {
  1805. if (++r95dm > 1e9) r95dm = 9;
  1806. return Array.prototype.reverse.apply(this, arguments);
  1807. }
  1808. }
  1809.  
  1810. if (c95dm !== r95dm) {
  1811. c95dm = r95dm;
  1812. doUpdate = true;
  1813. }
  1814.  
  1815. } else {
  1816. doUpdate = true;
  1817. }
  1818.  
  1819. if (!doUpdate) {
  1820. lockResolve();
  1821. return;
  1822. }
  1823.  
  1824. const participants = participants00.slice(0);
  1825. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  1826. beforeParticipantsMap.set(cnt, participants);
  1827.  
  1828. const resPromise = (async () => {
  1829.  
  1830. if (beforeParticipants.length === 0) {
  1831. // not error
  1832. return 0;
  1833. }
  1834.  
  1835. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  1836.  
  1837. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  1838. if (beforeParticipants.length !== countOfElements) {
  1839. // there is somewrong for the cache. - sometimes happen
  1840. return 0;
  1841. }
  1842.  
  1843. const idsBefore = convertToIds(beforeParticipants);
  1844. const idsAfter = convertToIds(participants);
  1845.  
  1846. let { indexSplices, contentUpdates, releaser } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  1847.  
  1848. let res = 1; // default 1 for no update
  1849.  
  1850. if (indexSplices.length >= 1) {
  1851.  
  1852.  
  1853. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  1854. // let p1 = indexSplices[0].removed;
  1855. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  1856.  
  1857. /* folllow
  1858. a.notifyPath(c + ".splices", d);
  1859. a.notifyPath(c + ".length", b.length);
  1860. */
  1861. // stampDomArraySplices_
  1862.  
  1863.  
  1864. await new Promise(resolve => {
  1865. cnt.resolveForDOMRendering781 = resolve;
  1866.  
  1867. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  1868. indexSplices
  1869. });
  1870. indexSplices = null;
  1871. releaser();
  1872. releaser = null;
  1873. cnt.__notifyPath5036__("participantsManager.participants.length",
  1874. participants.length
  1875. );
  1876.  
  1877. });
  1878.  
  1879. await Promise.resolve(0); // play safe for the change of 'length'
  1880. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  1881.  
  1882. let wrongSize = participants.length !== countOfElements
  1883. if (wrongSize) {
  1884. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  1885. return 0;
  1886. }
  1887.  
  1888. res = 2 | 4;
  1889.  
  1890. } else {
  1891.  
  1892. indexSplices = null;
  1893. releaser();
  1894. releaser = null;
  1895.  
  1896. if (participants.length !== countOfElements) {
  1897. // other unhandled cases
  1898. return 0;
  1899. }
  1900.  
  1901. }
  1902.  
  1903. // participants.length === countOfElements before contentUpdates
  1904. if (contentUpdates.length >= 1) {
  1905. for (const contentUpdate of contentUpdates) {
  1906. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  1907. if (isChanged) {
  1908. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  1909. res |= 4 | 8;
  1910. }
  1911. }
  1912. }
  1913. contentUpdates = null;
  1914.  
  1915. return res;
  1916.  
  1917.  
  1918. })();
  1919.  
  1920.  
  1921. resPromise.then(resValue => {
  1922.  
  1923. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  1924. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  1925. if (resValue === 0) {
  1926. new Promise(resolve => {
  1927. cnt.resolveForDOMRendering781 = resolve;
  1928. isLogRequired && console.log("Full Refresh begins");
  1929. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  1930. }).then(() => {
  1931. isLogRequired && console.log("Full Refresh ends");
  1932. console.groupEnd();
  1933. }).then(lockResolve);
  1934. return;
  1935. }
  1936.  
  1937. const delayLockResolve = (resValue & 4) === 4;
  1938.  
  1939. if (delayLockResolve) {
  1940. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  1941. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  1942. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  1943. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  1944. isLogRequired && console.groupEnd();
  1945. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  1946. // mutex lock with requestAnimationFrame can also disable participants update in background
  1947. requestAnimationFrame(lockResolve);
  1948. } else {
  1949. lockResolve();
  1950. }
  1951.  
  1952. });
  1953.  
  1954. });
  1955.  
  1956. }
  1957.  
  1958. return { notifyPath7081 };
  1959.  
  1960. })();
  1961.  
  1962.  
  1963. const onRegistryReadyForDataManipulation = () => {
  1964.  
  1965. function dummy5035(a, b, c) { }
  1966. function dummy411(a, b, c) { }
  1967.  
  1968. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  1969.  
  1970. if (!DO_PARTICIPANT_LIST_HACKS) return;
  1971.  
  1972. const tag = "yt-live-chat-participant-list-renderer";
  1973. const cProto = getProto(document.createElement(tag));
  1974. if (!cProto || typeof cProto.attached !== 'function') {
  1975. // for _registered, proto.attached shall exist when the element is defined.
  1976. // for controller extraction, attached shall exist when instance creates.
  1977. console.warn(`proto.attached for ${tag} is unavailable.`);
  1978. return;
  1979. }
  1980.  
  1981.  
  1982. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  1983.  
  1984. 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'];
  1985. const fgs = {};
  1986. for (const key of fgsArr) fgs[key] = undefined;
  1987.  
  1988. try {
  1989. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  1990. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  1991. } catch (e) { }
  1992. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  1993.  
  1994. const canDoReplacement = (() => {
  1995. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  1996. console.warn('YouTube Live Chat Tamer is running.');
  1997. return;
  1998. }
  1999.  
  2000. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  2001. console.warn('YouTube Live Chat Tamer is running.');
  2002. return;
  2003. }
  2004.  
  2005. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  2006. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  2007.  
  2008. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  2009. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  2010. return;
  2011. }
  2012.  
  2013. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  2014. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  2015. return;
  2016. }
  2017.  
  2018. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  2019. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  2020. return;
  2021. }
  2022. return true;
  2023. })();
  2024.  
  2025. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  2026.  
  2027. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  2028. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  2029. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  2030. const s = fiRSCB.split('.');
  2031. if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  2032. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  2033. } else {
  2034. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - Failed`);
  2035. }
  2036. } else {
  2037. console.log("flushRenderStamperComponentBindings_ - not found");
  2038. }
  2039. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  2040.  
  2041. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  2042. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  2043. cProto.flushRenderStamperComponentBindings_ = function () {
  2044. // console.log('flushRenderStamperComponentBindings_')
  2045. this.flushRenderStamperComponentBindings66_();
  2046. if (this.resolveForDOMRendering781) {
  2047. this.resolveForDOMRendering781();
  2048. this.resolveForDOMRendering781 = null;
  2049. }
  2050. };
  2051. }
  2052.  
  2053. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  2054. const container = ((this || 0).$ || 0).participants;
  2055. if (!container) return 0;
  2056. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  2057. }
  2058.  
  2059. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  2060.  
  2061. cProto.__attached412__ = cProto.attached;
  2062. const fpPList = function (hostElement) {
  2063. const cnt = hostElement.inst || hostElement;
  2064. if (beforeParticipantsMap.has(cnt)) return;
  2065. hostElement.classList.add('n9fJ3');
  2066.  
  2067. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  2068. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  2069. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  2070. return;
  2071. }
  2072.  
  2073. groupCollapsed("Participant List attached", "");
  2074. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  2075. // console.log(123, 'appendChild');
  2076. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  2077. // }
  2078.  
  2079. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  2080. // console.log(123, 'insertBefore');
  2081. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  2082. // }
  2083.  
  2084. cnt.__notifyPath5036__ = cnt.notifyPath
  2085. const participants = ((cnt.participantsManager || 0).participants || 0);
  2086. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  2087. console.log(`initial number of participants: ${participants.length}`);
  2088. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  2089. beforeParticipantsMap.set(cnt, newParticipants);
  2090. cnt.notifyPath = notifyPath7081;
  2091. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  2092. console.groupEnd();
  2093. }
  2094. cProto.attached = function () {
  2095. fpPList(this.hostElement || this);
  2096. this.__attached412__.apply(this, arguments);
  2097. };
  2098.  
  2099.  
  2100. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  2101.  
  2102. /** @type {boolean | (()=>boolean)} */
  2103. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  2104. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  2105.  
  2106. let lastMessageDate = 0;
  2107. cProto.stampDomArray66_ = cProto.stampDomArray_;
  2108.  
  2109. cProto.stampDomArray_ = function (...args) {
  2110. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  2111. if (typeof toUseMaintainStableList === 'function') {
  2112. toUseMaintainStableList = toUseMaintainStableList();
  2113. }
  2114. args[5] = toUseMaintainStableList;
  2115. let currentDate = Date.now();
  2116. if (currentDate - lastMessageDate > 440) {
  2117. lastMessageDate = currentDate;
  2118. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  2119. }
  2120. }
  2121. return this.stampDomArray66_.apply(this, args);
  2122. }
  2123.  
  2124. cProto.stampDomArray_.nIegT = 1;
  2125.  
  2126. }
  2127. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  2128. } else {
  2129. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  2130. }
  2131.  
  2132. console.groupEnd();
  2133.  
  2134. if (onPageElements.length >= 1) {
  2135. for (const s of onPageElements) {
  2136. if ((s.inst || s).isAttached === true) {
  2137. fpPList(s);
  2138. }
  2139. }
  2140. }
  2141.  
  2142. }).catch(console.warn);
  2143.  
  2144. };
  2145.  
  2146. if (DO_PARTICIPANT_LIST_HACKS) {
  2147. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  2148. }
  2149.  
  2150.  
  2151.  
  2152. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  2153.  
  2154.  
  2155.  
  2156.  
  2157. const bnForDelayChatOccurrence = () => {
  2158.  
  2159. document.addEventListener('animationstart', (evt) => {
  2160.  
  2161. if (evt.animationName === 'dontRenderAnimation') {
  2162. evt.target.classList.remove('dont-render');
  2163. if (scrollChatFn) scrollChatFn();
  2164. }
  2165.  
  2166. }, true);
  2167.  
  2168. const f = (elm) => {
  2169. if (elm && elm.nodeType === 1) {
  2170. if (!skipDontRender && allowDontRender === true) {
  2171. // innerTextFixFn();
  2172. elm.classList.add('dont-render');
  2173. }
  2174. }
  2175. }
  2176.  
  2177. Node.prototype.__appendChild931__ = function (a) {
  2178. a = dr(a);
  2179. if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  2180. if (a && a.nodeType === 1) f(a);
  2181. else if (a instanceof DocumentFragment) {
  2182. for (let n = a.firstChild; n; n = n.nextSibling) {
  2183. f(n);
  2184. }
  2185. }
  2186. }
  2187. }
  2188.  
  2189. Node.prototype.__appendChild932__ = function () {
  2190. this.__appendChild931__.apply(this, arguments);
  2191. return Node.prototype.appendChild.apply(this, arguments);
  2192. }
  2193.  
  2194.  
  2195. };
  2196.  
  2197. const watchUserCSS = () => {
  2198.  
  2199. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  2200.  
  2201. const getElemFromWR = (nr) => {
  2202. const n = kRef(nr);
  2203. if (n && n.isConnected) return n;
  2204. return null;
  2205. }
  2206.  
  2207. const clearContentVisibilitySizing = () => {
  2208. Promise.resolve().then(() => {
  2209.  
  2210. const e = document.querySelector('#show-more[disabled]');
  2211. let btnShowMoreWR = e ? mWeakRef(e) : null;
  2212.  
  2213. let lastVisibleItemWR = null;
  2214. for (const elm of document.querySelectorAll('[wSr93]')) {
  2215. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  2216. elm.setAttribute('wSr93', '');
  2217. // custom CSS property --wsr94 not working when attribute wSr93 removed
  2218. }
  2219. requestAnimationFrame(() => {
  2220. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  2221. if (btnShowMore) btnShowMore.click();
  2222. else {
  2223. // would not work if switch it frequently
  2224. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  2225. if (lastVisibleItem) {
  2226.  
  2227. Promise.resolve()
  2228. .then(() => lastVisibleItem.scrollIntoView())
  2229. .then(() => lastVisibleItem.scrollIntoView(false))
  2230. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  2231. .catch(e => { }) // break the chain when method not callable
  2232.  
  2233. }
  2234. }
  2235. });
  2236.  
  2237. });
  2238.  
  2239. }
  2240.  
  2241. const mutObserver = new MutationObserver((mutations) => {
  2242. for (const mutation of mutations) {
  2243. if ((mutation.addedNodes || 0).length >= 1) {
  2244. for (const addedNode of mutation.addedNodes) {
  2245. if (addedNode.nodeName === 'STYLE') {
  2246. clearContentVisibilitySizing();
  2247. return;
  2248. }
  2249. }
  2250. }
  2251. if ((mutation.removedNodes || 0).length >= 1) {
  2252. for (const removedNode of mutation.removedNodes) {
  2253. if (removedNode.nodeName === 'STYLE') {
  2254. clearContentVisibilitySizing();
  2255. return;
  2256. }
  2257. }
  2258. }
  2259. }
  2260. });
  2261.  
  2262. mutObserver.observe(document.documentElement, {
  2263. childList: true,
  2264. subtree: false
  2265. });
  2266. mutObserver.observe(document.head, {
  2267. childList: true,
  2268. subtree: false
  2269. });
  2270. mutObserver.observe(document.body, {
  2271. childList: true,
  2272. subtree: false
  2273. });
  2274.  
  2275. }
  2276.  
  2277.  
  2278. class WillChangeController {
  2279. constructor(itemScroller, willChangeValue) {
  2280. this.element = itemScroller;
  2281. this.counter = 0;
  2282. this.active = false;
  2283. this.willChangeValue = willChangeValue;
  2284. }
  2285.  
  2286. beforeOper() {
  2287. if (!this.active) {
  2288. this.active = true;
  2289. this.element.style.willChange = this.willChangeValue;
  2290. }
  2291. this.counter++;
  2292. }
  2293.  
  2294. afterOper() {
  2295. const c = this.counter;
  2296. requestAnimationFrame(() => {
  2297. if (c === this.counter) {
  2298. this.active = false;
  2299. this.element.style.willChange = '';
  2300. }
  2301. });
  2302. }
  2303.  
  2304. release() {
  2305. const element = this.element;
  2306. this.element = null;
  2307. this.counter = 1e16;
  2308. this.active = false;
  2309. try {
  2310. element.style.willChange = '';
  2311. } catch (e) { }
  2312. }
  2313.  
  2314. }
  2315.  
  2316.  
  2317. const skzData = (skz) => skz.data = {
  2318. "message": {
  2319. "runs": [
  2320. {
  2321. "text": "em2o"
  2322. },
  2323. {
  2324. "emoji": {
  2325. "emojiId": "cm35z",
  2326. "shortcuts": [
  2327. ":_s:",
  2328. ":s:"
  2329. ],
  2330. "searchTerms": [
  2331. "_s",
  2332. "s"
  2333. ],
  2334. "image": {
  2335. "thumbnails": [
  2336. {
  2337. "url": dummyImgURL,
  2338. "width": 48,
  2339. "height": 48
  2340. }
  2341. ],
  2342. "accessibility": {
  2343. "accessibilityData": {
  2344. "label": "s"
  2345. }
  2346. }
  2347. },
  2348. "isCustomEmoji": true
  2349. }
  2350. },
  2351. {
  2352. "text": "ji"
  2353. }
  2354. ]
  2355. },
  2356. "authorName": {
  2357. "simpleText": "N"
  2358. },
  2359. "authorPhoto": {
  2360. "thumbnails": [
  2361. {
  2362. "url": dummyImgURL,
  2363. "width": 64,
  2364. "height": 64
  2365. }
  2366. ]
  2367. },
  2368. "contextMenuEndpoint": {
  2369. "commandMetadata": {
  2370. "webCommandMetadata": {
  2371. "ignoreNavigation": true
  2372. }
  2373. },
  2374. "liveChatItemContextMenuEndpoint": {
  2375. "params": "123=="
  2376. }
  2377. },
  2378. "id": "sk35z",
  2379. "timestampUsec": "1232302352350000",
  2380. "authorBadges": [
  2381. {
  2382. "liveChatAuthorBadgeRenderer": {
  2383. "customThumbnail": {
  2384. "thumbnails": [
  2385. {
  2386. "url": dummyImgURL,
  2387. "width": 16,
  2388. "height": 16
  2389. },
  2390. {
  2391. "url": dummyImgURL,
  2392. "width": 32,
  2393. "height": 32
  2394. }
  2395. ]
  2396. },
  2397. "tooltip": "T",
  2398. "accessibility": {
  2399. "accessibilityData": {
  2400. "label": "E"
  2401. }
  2402. }
  2403. }
  2404. }
  2405. ],
  2406. "authorExternalChannelId": "A",
  2407. "contextMenuAccessibility": {
  2408. "accessibilityData": {
  2409. "label": "E"
  2410. }
  2411. },
  2412. "timestampText": {
  2413. "simpleText": "0:43"
  2414. }
  2415. };
  2416.  
  2417.  
  2418.  
  2419. const { lcRendererElm, visObserver } = (() => {
  2420.  
  2421.  
  2422.  
  2423. let lcRendererWR = null;
  2424.  
  2425. const lcRendererElm = () => {
  2426. let lcRenderer = kRef(lcRendererWR);
  2427. if (!lcRenderer || !lcRenderer.isConnected) {
  2428. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  2429. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  2430. }
  2431. return lcRenderer;
  2432. };
  2433.  
  2434.  
  2435. let hasFirstShowMore = false;
  2436.  
  2437. const visObserverFn = (entry) => {
  2438.  
  2439. const target = entry.target;
  2440. if (!target) return;
  2441. // if(target.classList.contains('dont-render')) return;
  2442. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  2443. // const h = entry.boundingClientRect.height;
  2444. /*
  2445. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  2446. // e.g. under fullscreen. the element created but not rendered.
  2447. target.setAttribute('wSr93', '');
  2448. return;
  2449. }
  2450. */
  2451. if (isVisible) {
  2452. // target.style.setProperty('--wsr94', h + 'px');
  2453. target.setAttribute('wSr93', 'visible');
  2454. if (nNextElem(target) === null) {
  2455.  
  2456. // firstVisibleItemDetected = true;
  2457. /*
  2458. if (dateNow() - lastScroll < 80) {
  2459. lastLShow = 0;
  2460. lastScroll = 0;
  2461. Promise.resolve().then(clickShowMore);
  2462. } else {
  2463. lastLShow = dateNow();
  2464. }
  2465. */
  2466. // lastLShow = dateNow();
  2467. } else if (!hasFirstShowMore) { // should more than one item being visible
  2468. // implement inside visObserver to ensure there is sufficient delay
  2469. hasFirstShowMore = true;
  2470. requestAnimationFrame(() => {
  2471. // foreground page
  2472. // page visibly ready -> load the latest comments at initial loading
  2473. const lcRenderer = lcRendererElm();
  2474. if (lcRenderer) {
  2475. (lcRenderer.inst || lcRenderer).scrollToBottom_();
  2476. }
  2477. });
  2478. }
  2479. }
  2480. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  2481.  
  2482. // target.style.setProperty('--wsr94', h + 'px');
  2483. target.setAttribute('wSr93', 'hidden');
  2484. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  2485.  
  2486. }
  2487.  
  2488.  
  2489.  
  2490. const visObserver = new IntersectionObserver((entries) => {
  2491.  
  2492. for (const entry of entries) {
  2493.  
  2494. Promise.resolve(entry).then(visObserverFn);
  2495.  
  2496. }
  2497.  
  2498. }, {
  2499. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  2500. rootMargin: "0px",
  2501. threshold: [0.05, 0.95],
  2502. });
  2503.  
  2504.  
  2505. return { lcRendererElm, visObserver }
  2506.  
  2507.  
  2508. })();
  2509.  
  2510. const { setupMutObserver } = (() => {
  2511.  
  2512. const mutFn = (items) => {
  2513. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  2514. if (node.hasAttribute('wSr93')) break;
  2515. node.setAttribute('wSr93', '');
  2516. visObserver.observe(node);
  2517. }
  2518. }
  2519.  
  2520. const mutObserver = new MutationObserver((mutations) => {
  2521. const items = (mutations[0] || 0).target;
  2522. if (!items) return;
  2523. if (sk35zResolveFn) {
  2524. sk35zResolveFn();
  2525. sk35zResolveFn = null;
  2526. }
  2527. mutFn(items);
  2528. });
  2529.  
  2530. const setupMutObserver = (m2) => {
  2531. scrollChatFn = null;
  2532. mutObserver.disconnect();
  2533. mutObserver.takeRecords();
  2534. if (m2) {
  2535. ENABLE_DELAYED_CHAT_OCCURRENCE && bnForDelayChatOccurrence();
  2536. if (typeof m2.__appendChild932__ === 'function') {
  2537. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  2538. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  2539. }
  2540. mutObserver.observe(m2, {
  2541. childList: true,
  2542. subtree: false
  2543. });
  2544. mutFn(m2);
  2545.  
  2546. const isFirstList = firstList;
  2547. firstList = false;
  2548.  
  2549. if (ENABLE_OVERFLOW_ANCHOR) {
  2550.  
  2551. let items = m2;
  2552. let addedAnchor = false;
  2553. if (items) {
  2554. if (items.nextElementSibling === null) {
  2555. items.classList.add('no-anchor');
  2556. addedAnchor = true;
  2557. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  2558. }
  2559. }
  2560.  
  2561.  
  2562.  
  2563. if (addedAnchor) {
  2564. nodeParent(m2).classList.add('no-anchor'); // required
  2565. }
  2566.  
  2567. }
  2568.  
  2569. // let div = document.createElement('div');
  2570. // div.id = 'qwcc';
  2571. // HTMLElement.prototype.appendChild.call(document.querySelector('yt-live-chat-item-list-renderer'), div )
  2572. // bufferRegion =div;
  2573.  
  2574. // buffObserver.takeRecords();
  2575. // buffObserver.disconnect();
  2576. // buffObserver.observe(div, {
  2577. // childList: true,
  2578. // subtree: false
  2579. // })
  2580.  
  2581. if (ENABLE_DELAYED_CHAT_OCCURRENCE && isFirstList) {
  2582.  
  2583. promiseForCustomYtElementsReady.then(() => {
  2584.  
  2585. customElements.whenDefined('yt-live-chat-text-message-renderer').then(() => {
  2586.  
  2587.  
  2588.  
  2589.  
  2590. setTimeout(() => {
  2591.  
  2592. /** @type {HTMLTemplateElement} */
  2593. let skz = document.createElement('yt-live-chat-text-message-renderer');
  2594.  
  2595. let cz1 = null;
  2596.  
  2597. if (skz && 'data' in skz && 'attached' in skz) {
  2598.  
  2599. const deferredZy1 = new Promise(resolve => {
  2600.  
  2601. skz.attached = function () {
  2602. cz1 = HTMLElement.prototype.querySelector.call(skz, '#message img') !== null;
  2603. resolve(skz.textContent);
  2604. }
  2605. skz.detached = function () {
  2606.  
  2607. }
  2608.  
  2609. });
  2610. skz.id = 'sk35z';
  2611. skzData(skz);
  2612.  
  2613.  
  2614. sk35zResolveFn = null;
  2615. const deferredMutation = new Promise(resolve => {
  2616. sk35zResolveFn = resolve;
  2617. HTMLElement.prototype.appendChild.call(m2, skz);
  2618. });
  2619.  
  2620. Promise.all([deferredZy1, deferredMutation]).then(async (res) => {
  2621. const [zy1, _] = res;
  2622. function fn() {
  2623. const zy2 = skz.textContent;
  2624. const cz2 = HTMLElement.prototype.querySelector.call(skz, '#message img') !== null;
  2625. if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  2626. allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  2627. }
  2628. if (allowDontRender === false) {
  2629.  
  2630. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2631. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2632. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2633. );
  2634.  
  2635. 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');
  2636.  
  2637. console.groupEnd();
  2638. } else if (allowDontRender === true) {
  2639. return true;
  2640. }
  2641. }
  2642. await new Promise(r => setTimeout(r, 1));
  2643. if (fn()) {
  2644. await new Promise(r => requestAnimationFrame(r));
  2645. if (fn()) {
  2646. skz.remove();
  2647. skz.textContent = '';
  2648. console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2649. }
  2650. }
  2651. });
  2652.  
  2653. }
  2654.  
  2655. }, 1);
  2656.  
  2657. }).catch(console.warn);
  2658.  
  2659. })
  2660.  
  2661. }
  2662.  
  2663.  
  2664. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  2665.  
  2666. (() => {
  2667.  
  2668. const tag = 'yt-iframed-player-events-relay'
  2669. const dummy = document.createElement(tag);
  2670.  
  2671. const cProto = getProto(dummy);
  2672. if (!cProto || !cProto.handlePostMessage_) {
  2673. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  2674. return;
  2675. }
  2676.  
  2677. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_) {
  2678.  
  2679. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  2680.  
  2681. cProto.handlePostMessage_ = function (a) {
  2682.  
  2683. const da = (a || 0).data || 0;
  2684. if (typeof da === 'object') {
  2685.  
  2686. // console.log('handlePostMessage_', da)
  2687. const qc = da['yt-player-state-change'];
  2688. if (qc === 3) { // pause
  2689. pairForPauseResume++;
  2690. pairForPauseResumeM++;
  2691. } else if (qc === 1) { // pause
  2692. pairForPauseResume++;
  2693. pairForPauseResumeM++;
  2694. } else if (qc === 2) {
  2695. pairForPauseResume++;
  2696. pairForPauseResumeM++;
  2697. }
  2698. if (pairForPauseResume > 1e9) pairForPauseResume = pairForPauseResume % 1e4;
  2699. if (pairForPauseResumeM > 1e9) pairForPauseResumeM = pairForPauseResumeM % 1e4;
  2700. return this.handlePostMessage66_(a);
  2701.  
  2702. }
  2703.  
  2704.  
  2705. }
  2706.  
  2707. }
  2708.  
  2709.  
  2710. })();
  2711.  
  2712. }
  2713.  
  2714. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  2715. setTimeout(() => {
  2716. if (!hasTimerModified) return;
  2717. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  2718. if (!tickerRenderer) return;
  2719.  
  2720. const items = (tickerRenderer.$ || 0).items || 0;
  2721. if (!items) return;
  2722. const template = document.createElement('template');
  2723. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  2724. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  2725. dimmed="" [dummy777]>
  2726. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  2727. style="--background:linear-gradient(90deg, rgba(1,2,3,1),rgba(1,2,3,1) 7%,rgba(4,0,0,1) 7%,rgba(4,0,0,1));">
  2728. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  2729. <yt-img-shadow777 id="author-photo" height="24" width="24"
  2730. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  2731. style="background-color: transparent;" loaded=""><img id="img"
  2732. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  2733. src="${dummyImgURL}"></yt-img-shadow777>
  2734.  
  2735. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  2736. </div>
  2737. </div>
  2738. </yt-live-chat-ticker-dummy777-item-renderer>`;
  2739. const dummy777 = template.content.firstElementChild;
  2740. items.appendChild(dummy777);
  2741. Promise.resolve(dummy777).then((dummy777) => {
  2742. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  2743. if (container.isConnected === true) {
  2744.  
  2745. const evaluated = `${window.getComputedStyle(container).background}`;
  2746.  
  2747. container = null;
  2748. dummy777.remove();
  2749. dummy777.textContent = '';
  2750. dummy777 = null;
  2751.  
  2752. if (evaluated.indexOf('0.') < 4) {
  2753.  
  2754. // not fulfilling
  2755. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  2756.  
  2757. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2758. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2759. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2760. );
  2761. console.warn(`%cWarning:\n\tYou might have added a userscript or extension that also modifies the ticker background.\n\tYouTube Super Fast Chat is taking over.`, 'color: #bada55');
  2762. console.groupEnd();
  2763.  
  2764. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  2765.  
  2766. } else {
  2767.  
  2768. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2769. }
  2770. }
  2771. });
  2772.  
  2773. }, 800);
  2774. }
  2775.  
  2776. }
  2777. }
  2778.  
  2779. return { setupMutObserver };
  2780.  
  2781.  
  2782.  
  2783. })();
  2784.  
  2785. const setupEvents = () => {
  2786.  
  2787.  
  2788. let scrollCount = 0;
  2789.  
  2790. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  2791.  
  2792.  
  2793. const delayFlushActiveItemsAfterUserActionK_ = () => {
  2794.  
  2795. const lcRenderer = lcRendererElm();
  2796. if (lcRenderer) {
  2797. const cnt = (lcRenderer.inst || lcRenderer);
  2798. if (!cnt.hasUserJustInteracted11_) return;
  2799. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  2800. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  2801. }
  2802. }
  2803.  
  2804. }
  2805.  
  2806. document.addEventListener('scroll', (evt) => {
  2807. if (!evt || !evt.isTrusted) return;
  2808. // lastScroll = dateNow();
  2809. if (++scrollCount > 1e9) scrollCount = 9;
  2810. }, passiveCapture); // support contain => support passive
  2811.  
  2812. let lastScrollCount = -1;
  2813. document.addEventListener('wheel', (evt) => {
  2814. if (!evt || !evt.isTrusted) return;
  2815. if (lastScrollCount === scrollCount) return;
  2816. lastScrollCount = scrollCount;
  2817. lastWheel = dateNow();
  2818. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2819. }, passiveCapture); // support contain => support passive
  2820.  
  2821. document.addEventListener('mousedown', (evt) => {
  2822. if (!evt || !evt.isTrusted) return;
  2823. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2824. lastMouseDown = dateNow();
  2825. currentMouseDown = true;
  2826. lastUserInteraction = lastMouseDown;
  2827. }, passiveCapture);
  2828.  
  2829. document.addEventListener('pointerdown', (evt) => {
  2830. if (!evt || !evt.isTrusted) return;
  2831. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2832. lastMouseDown = dateNow();
  2833. currentMouseDown = true;
  2834. lastUserInteraction = lastMouseDown;
  2835. }, passiveCapture);
  2836.  
  2837. document.addEventListener('click', (evt) => {
  2838. if (!evt || !evt.isTrusted) return;
  2839. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2840. lastMouseDown = lastMouseUp = dateNow();
  2841. currentMouseDown = false;
  2842. lastUserInteraction = lastMouseDown;
  2843. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2844. }, passiveCapture);
  2845.  
  2846. document.addEventListener('tap', (evt) => {
  2847. if (!evt || !evt.isTrusted) return;
  2848. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  2849. lastMouseDown = lastMouseUp = dateNow();
  2850. currentMouseDown = false;
  2851. lastUserInteraction = lastMouseDown;
  2852. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2853. }, passiveCapture);
  2854.  
  2855.  
  2856. document.addEventListener('mouseup', (evt) => {
  2857. if (!evt || !evt.isTrusted) return;
  2858. if (currentMouseDown) {
  2859. lastMouseUp = dateNow();
  2860. currentMouseDown = false;
  2861. lastUserInteraction = lastMouseUp;
  2862. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2863. }
  2864. }, passiveCapture);
  2865.  
  2866.  
  2867. document.addEventListener('pointerup', (evt) => {
  2868. if (!evt || !evt.isTrusted) return;
  2869. if (currentMouseDown) {
  2870. lastMouseUp = dateNow();
  2871. currentMouseDown = false;
  2872. lastUserInteraction = lastMouseUp;
  2873. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2874. }
  2875. }, passiveCapture);
  2876.  
  2877. document.addEventListener('touchstart', (evt) => {
  2878. if (!evt || !evt.isTrusted) return;
  2879. lastTouchDown = dateNow();
  2880. currentTouchDown = true;
  2881. lastUserInteraction = lastTouchDown;
  2882. }, passiveCapture);
  2883.  
  2884. document.addEventListener('touchmove', (evt) => {
  2885. if (!evt || !evt.isTrusted) return;
  2886. lastTouchDown = dateNow();
  2887. currentTouchDown = true;
  2888. lastUserInteraction = lastTouchDown;
  2889. }, passiveCapture);
  2890.  
  2891. document.addEventListener('touchend', (evt) => {
  2892. if (!evt || !evt.isTrusted) return;
  2893. if (currentTouchDown) {
  2894. lastTouchUp = dateNow();
  2895. currentTouchDown = false;
  2896. lastUserInteraction = lastTouchUp;
  2897. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2898. }
  2899. }, passiveCapture);
  2900.  
  2901. document.addEventListener('touchcancel', (evt) => {
  2902. if (!evt || !evt.isTrusted) return;
  2903. if (currentTouchDown) {
  2904. lastTouchUp = dateNow();
  2905. currentTouchDown = false;
  2906. lastUserInteraction = lastTouchUp;
  2907. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  2908. }
  2909. }, passiveCapture);
  2910.  
  2911.  
  2912. }
  2913.  
  2914.  
  2915. const onRegistryReadyForDOMOperations = () => {
  2916.  
  2917. let firstCheckedOnYtInit = false;
  2918.  
  2919. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  2920.  
  2921. const mightFirstCheckOnYtInit = () => {
  2922. if (firstCheckedOnYtInit) return;
  2923. firstCheckedOnYtInit = true;
  2924.  
  2925. if (!document.body || !document.head) return;
  2926. if (!assertorURL()) return;
  2927.  
  2928. addCssManaged();
  2929.  
  2930. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  2931. if (efsContainer && efsContainer.parentNode !== document.body) {
  2932. document.body.appendChild(efsContainer);
  2933. }
  2934.  
  2935. };
  2936.  
  2937. if (!assertorURL()) return;
  2938. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  2939.  
  2940. if (document.documentElement && document.head) {
  2941. addCssManaged();
  2942. }
  2943. // console.log(document.body===null)
  2944.  
  2945. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  2946.  
  2947. const tag = "yt-live-chat-item-list-renderer"
  2948. const dummy = document.createElement(tag);
  2949.  
  2950. const cProto = getProto(dummy);
  2951. if (!cProto || !cProto.attached) {
  2952. console.warn(`proto.attached for ${tag} is unavailable.`);
  2953. return;
  2954. }
  2955.  
  2956. mightFirstCheckOnYtInit();
  2957. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  2958. console.log("[Begin]");
  2959.  
  2960. const mclp = cProto;
  2961. try {
  2962. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  2963. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  2964. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  2965. assertor(() => typeof mclp.setAtBottom === 'function');
  2966. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  2967. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  2968. } catch (e) { }
  2969.  
  2970.  
  2971. try {
  2972. assertor(() => typeof mclp.attached === 'function');
  2973. assertor(() => typeof mclp.detached === 'function');
  2974. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  2975. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  2976. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  2977. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  2978. assertor(() => typeof mclp.smoothScroll_ === 'function');
  2979. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  2980. } catch (e) { }
  2981.  
  2982. mclp.__intermediate_delay__ = null;
  2983.  
  2984. let mzk = 0;
  2985. let myk = 0;
  2986. let mlf = 0;
  2987. let myw = 0;
  2988. let mzt = 0;
  2989. let zarr = null;
  2990. let mlg = 0;
  2991.  
  2992. if ((mclp.clearList || 0).length === 0) {
  2993. assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  2994. mclp.clearList66 = mclp.clearList;
  2995. mclp.clearList = function () {
  2996. mzk++;
  2997. myk++;
  2998. mlf++;
  2999. myw++;
  3000. mzt++;
  3001. mlg++;
  3002. zarr = null;
  3003. this.__intermediate_delay__ = null;
  3004. this.clearList66();
  3005. };
  3006. console.log("clearList", "OK");
  3007. } else {
  3008. console.log("clearList", "NG");
  3009. }
  3010.  
  3011.  
  3012. let onListRendererAttachedDone = false;
  3013.  
  3014. function setList(itemOffset, items) {
  3015.  
  3016. const isFirstTime = onListRendererAttachedDone === false;
  3017.  
  3018. if (isFirstTime) {
  3019. onListRendererAttachedDone = true;
  3020. Promise.resolve().then(watchUserCSS);
  3021. addCssManaged();
  3022. setupEvents();
  3023. }
  3024.  
  3025. setupStyle(itemOffset, items);
  3026.  
  3027. setupMutObserver(items);
  3028. }
  3029.  
  3030. mclp.attached419 = async function () {
  3031.  
  3032. if (!this.isAttached) return;
  3033.  
  3034. let maxTrial = 16;
  3035. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  3036. if (--maxTrial < 0 || !this.isAttached) return;
  3037. await new Promise(requestAnimationFrame);
  3038. }
  3039.  
  3040. if (this.isAttached !== true) return;
  3041.  
  3042. if (!this.$) {
  3043. console.warn("!this.$");
  3044. return;
  3045. }
  3046. if (!this.$) return;
  3047. /** @type {HTMLElement | null} */
  3048. const itemScroller = this.$['item-scroller'];
  3049. /** @type {HTMLElement | null} */
  3050. const itemOffset = this.$['item-offset'];
  3051. /** @type {HTMLElement | null} */
  3052. const items = this.$['items'];
  3053.  
  3054. if (!itemScroller || !itemOffset || !items) {
  3055. console.warn("items.parentNode !== itemOffset");
  3056. return;
  3057. }
  3058.  
  3059. if (nodeParent(items) !== itemOffset) {
  3060.  
  3061. console.warn("items.parentNode !== itemOffset");
  3062. return;
  3063. }
  3064.  
  3065.  
  3066. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  3067.  
  3068. console.warn("id incorrect");
  3069. return;
  3070. }
  3071.  
  3072. 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')
  3073.  
  3074. if (!isTargetItems) {
  3075. console.warn("!isTargetItems");
  3076. return;
  3077. }
  3078.  
  3079. setList(itemOffset, items);
  3080.  
  3081. }
  3082.  
  3083. mclp.attached331 = mclp.attached;
  3084. mclp.attached = function () {
  3085. this.attached419 && this.attached419();
  3086. return this.attached331();
  3087. }
  3088.  
  3089. mclp.detached331 = mclp.detached;
  3090.  
  3091. mclp.detached = function () {
  3092. setupMutObserver();
  3093. return this.detached331();
  3094. }
  3095.  
  3096. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  3097. for (const t29 of t29s) {
  3098. if ((t29.inst || t29).isAttached === true) {
  3099. t29.attached419();
  3100. }
  3101. }
  3102.  
  3103. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  3104.  
  3105. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  3106. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  3107.  
  3108. /** @type {Map<number, any>} */
  3109. const aMap = new Map();
  3110. let count = 6150;
  3111. mclp.async66 = mclp.async;
  3112. mclp.async = function (e, f) {
  3113. // ensure the previous operation is done
  3114. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  3115. const hasF = arguments.length === 2;
  3116. const stack = new Error().stack;
  3117. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  3118. if (count > 1e9) count = 6159;
  3119. const resId = ++count;
  3120. aMap.set(resId, e);
  3121. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  3122. const rp = aMap.get(resId);
  3123. if (typeof rp !== 'function') {
  3124. return;
  3125. }
  3126. let cancelCall = false;
  3127. if (isFlushAsync) {
  3128. if (rk < 0) {
  3129. cancelCall = true;
  3130. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  3131. cancelCall = true;
  3132. }
  3133. }
  3134. if (cancelCall) {
  3135. aMap.delete(resId);
  3136. } else {
  3137. const asyncEn = function () {
  3138. aMap.delete(resId);
  3139. return rp.apply(this, arguments);
  3140. };
  3141. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  3142. }
  3143. });
  3144.  
  3145. return resId;
  3146. }
  3147.  
  3148. mclp.cancelAsync66 = mclp.cancelAsync;
  3149. mclp.cancelAsync = function (resId) {
  3150. if (resId <= 6150) {
  3151. this.cancelAsync66(resId);
  3152. } else if (aMap.has(resId)) {
  3153. const rp = aMap.get(resId);
  3154. aMap.delete(resId);
  3155. if (typeof rp !== 'function') {
  3156. this.cancelAsync66(rp);
  3157. }
  3158. }
  3159. }
  3160.  
  3161. console.log("async", "OK");
  3162. } else {
  3163. console.log("async", "NG");
  3164. }
  3165.  
  3166.  
  3167. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  3168.  
  3169. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  3170. mclp.showNewItems66_ = mclp.showNewItems_;
  3171.  
  3172. mclp.showNewItems77_ = async function () {
  3173. if (myk > 1e9) myk = 9;
  3174. let tid = ++myk;
  3175.  
  3176. await new Promise(requestAnimationFrame);
  3177.  
  3178. if (tid !== myk) {
  3179. return;
  3180. }
  3181.  
  3182. const cnt = this;
  3183.  
  3184. await Promise.resolve();
  3185. cnt.showNewItems66_();
  3186.  
  3187. await Promise.resolve();
  3188.  
  3189. }
  3190.  
  3191. mclp.showNewItems_ = function () {
  3192.  
  3193. const cnt = this;
  3194. cnt.__intermediate_delay__ = new Promise(resolve => {
  3195. cnt.showNewItems77_().then(() => {
  3196. resolve();
  3197. });
  3198. });
  3199. }
  3200.  
  3201. console.log("showNewItems_", "OK");
  3202. } else {
  3203. console.log("showNewItems_", "NG");
  3204. }
  3205.  
  3206.  
  3207. if ((mclp.flushActiveItems_ || 0).length === 0) {
  3208.  
  3209. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.137.81'));
  3210.  
  3211. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  3212.  
  3213. let contensWillChangeController = null;
  3214.  
  3215. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  3216.  
  3217. mclp.flushActiveItems78_ = async function (tid) {
  3218. try {
  3219. if (tid !== mlf) return;
  3220. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3221. let logger = false;
  3222. const cnt = this;
  3223. let immd = cnt.__intermediate_delay__;
  3224. await new Promise(requestAnimationFrame);
  3225.  
  3226. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3227. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  3228.  
  3229. mlf++;
  3230. if (mlg > 1e9) mlg = 9;
  3231. ++mlg;
  3232.  
  3233. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  3234. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  3235. let changeMaxItemsToDisplay = false;
  3236. const activeItemsLen = this.activeItems_.length;
  3237. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  3238. logger = true;
  3239.  
  3240. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  3241.  
  3242. logger && console.log('[Begin]')
  3243.  
  3244. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  3245. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  3246. console.log('reduce maxitems');
  3247. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3248. // as all the rendered chats are already "outdated"
  3249. // all old chats shall remove and reduced number of few chats will be rendered
  3250. // then restore to the original number
  3251. changeMaxItemsToDisplay = true;
  3252. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  3253. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  3254. }
  3255. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  3256. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3257.  
  3258. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3259. } else {
  3260. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  3261.  
  3262. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3263. }
  3264. }
  3265. // it is found that it will render all stacked chats after switching back from background
  3266. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  3267. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  3268.  
  3269.  
  3270. const items = (cnt.$ || 0).items;
  3271.  
  3272. if (USE_WILL_CHANGE_CONTROLLER) {
  3273. if (contensWillChangeController && contensWillChangeController.element !== items) {
  3274. contensWillChangeController.release();
  3275. contensWillChangeController = null;
  3276. }
  3277. if (!contensWillChangeController) contensWillChangeController = new WillChangeController(items, 'contents');
  3278. }
  3279. const wcController = contensWillChangeController;
  3280. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  3281. wcController && wcController.beforeOper();
  3282. await Promise.resolve();
  3283. const acItems = cnt.activeItems_;
  3284. const len1 = acItems.length;
  3285. if (!len1) console.warn('cnt.activeItems_.length = 0');
  3286. let waitFor = [];
  3287.  
  3288.  
  3289. /** @type {Set<string>} */
  3290. const imageLinks = new Set();
  3291.  
  3292. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  3293. for (const item of acItems) {
  3294. fixLiveChatItem(item, imageLinks);
  3295. }
  3296. }
  3297. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  3298. if (emojiPrefetched.size > PREFETCH_LIMITED_SIZE_EMOJI) emojiPrefetched.clear();
  3299. if (authorPhotoPrefetched.size > PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO) authorPhotoPrefetched.clear();
  3300.  
  3301. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  3302. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  3303. // preload performs the high priority fetching.
  3304. // prefetch delays the chat display if the video resoruce is demanding.
  3305.  
  3306. if (rel) {
  3307.  
  3308. imageLinks.forEach(imageLink => {
  3309. let d = false;
  3310. const isEmoji = imageLink.includes('/emoji/');
  3311. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  3312. if (!pretechedSet.has(imageLink)) {
  3313. pretechedSet.add(imageLink);
  3314. d = true;
  3315. }
  3316. if (d) {
  3317. waitFor.push(linker(null, rel, imageLink, 'image'));
  3318.  
  3319. }
  3320. })
  3321.  
  3322. }
  3323.  
  3324. }
  3325.  
  3326. skipDontRender = ((cnt.visibleItems || 0).length || 0) === 0;
  3327. // console.log('ss1', Date.now())
  3328. if (waitFor.length > 0) {
  3329. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  3330. }
  3331. waitFor.length = 0;
  3332. waitFor = null;
  3333. // console.log('ss2', Date.now())
  3334. cnt.flushActiveItems66_();
  3335. skipDontRender = ((cnt.visibleItems || 0).length || 0) === 0;
  3336. const len2 = cnt.activeItems_.length;
  3337. const bAsync = len1 !== len2;
  3338. await Promise.resolve();
  3339. if (wcController) {
  3340. if (bAsync) {
  3341. cnt.async(() => {
  3342. wcController.afterOper();
  3343. });
  3344. } else {
  3345. wcController.afterOper();
  3346. }
  3347. }
  3348. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3349. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  3350.  
  3351. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  3352. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3353. } else if (changeMaxItemsToDisplay) {
  3354.  
  3355. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  3356. maxItemsToDisplay: this.data.maxItemsToDisplay,
  3357. reducedMaxItemsToDisplay,
  3358. originalMaxItemsToDisplay: tmpMaxItemsCount
  3359. });
  3360. }
  3361. logger && console.log('[End]')
  3362.  
  3363. logger && console.groupEnd();
  3364.  
  3365. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  3366.  
  3367.  
  3368. const ff = () => {
  3369.  
  3370. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3371. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3372. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  3373. cnt.scrollToBottom_();
  3374.  
  3375. Promise.resolve().then(() => {
  3376.  
  3377. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3378. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  3379. });
  3380.  
  3381.  
  3382. }
  3383. }
  3384.  
  3385. ff();
  3386.  
  3387.  
  3388. Promise.resolve().then(ff);
  3389.  
  3390. // requestAnimationFrame(ff);
  3391. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  3392.  
  3393. const knt = cnt;
  3394. if (!scrollChatFn) {
  3395. const cnt = knt;
  3396. const f = () => {
  3397. const itemScroller = cnt.itemScroller;
  3398. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  3399. if (!cnt.atBottom) {
  3400. cnt.scrollToBottom_();
  3401. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  3402. itemScroller.scrollTop = itemScroller.scrollHeight;
  3403. }
  3404. };
  3405. scrollChatFn = () => Promise.resolve().then(f).then(f);
  3406. }
  3407.  
  3408. if (!ENABLE_DELAYED_CHAT_OCCURRENCE) scrollChatFn();
  3409. }
  3410.  
  3411. return 1;
  3412.  
  3413.  
  3414. } catch (e) {
  3415. console.warn(e);
  3416. }
  3417. }
  3418.  
  3419. mclp.flushActiveItems77_ = function () {
  3420.  
  3421. return new Promise(resResolve => {
  3422. try {
  3423. const cnt = this;
  3424. if (mlf > 1e9) mlf = 9;
  3425. let tid = ++mlf;
  3426. const hostElement = cnt.hostElement || cnt;
  3427. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  3428. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  3429.  
  3430. // 4 times to maxItems to avoid frequent trimming.
  3431. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  3432.  
  3433. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3434. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  3435. if (cnt.canScrollToBottom_()) {
  3436. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  3437. .then(() => cnt.flushActiveItems78_(tid)) // async function
  3438. .then((asyncResult) => {
  3439. resResolve(asyncResult); // either undefined or 1
  3440. resResolve = null;
  3441. }).catch((e) => {
  3442. console.warn(e);
  3443. if (resResolve) resResolve();
  3444. });
  3445. } else {
  3446. resResolve(2);
  3447. resResolve = null;
  3448. }
  3449. } catch (e) {
  3450. console.warn(e);
  3451. if (resResolve) resResolve();
  3452. }
  3453.  
  3454.  
  3455. });
  3456.  
  3457. }
  3458.  
  3459. mclp.flushActiveItems_ = function () {
  3460. const cnt = this;
  3461.  
  3462. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  3463.  
  3464. if (cnt.activeItems_.length === 0) {
  3465. cnt.__intermediate_delay__ = null;
  3466. return;
  3467. }
  3468.  
  3469. const cntData = ((cnt || 0).data || 0);
  3470. if (cntData.maxItemsToDisplay944 === undefined) {
  3471. cntData.maxItemsToDisplay944 = null;
  3472. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  3473. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  3474. }
  3475.  
  3476. // ignore previous __intermediate_delay__ and create a new one
  3477. cnt.__intermediate_delay__ = new Promise(resolve => {
  3478. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  3479. if (rt === 1) {
  3480. resolve(1); // success, scroll to bottom
  3481. if (hasMoreMessageState === 1) {
  3482. hasMoreMessageState = 0;
  3483. const showMore = (cnt.$ || 0)['show-more'];
  3484. if (showMore) {
  3485. showMore.classList.remove('has-new-messages-miuzp');
  3486. }
  3487. }
  3488. }
  3489. else if (rt === 2) {
  3490. resolve(2); // success, trim
  3491. if (hasMoreMessageState === 0) {
  3492. hasMoreMessageState = 1;
  3493. const showMore = cnt.$['show-more'];
  3494. if (showMore) {
  3495. showMore.classList.add('has-new-messages-miuzp');
  3496. }
  3497. }
  3498. }
  3499. else resolve(-1); // skip
  3500. }).catch(e => {
  3501. console.warn(e);
  3502. });
  3503. });
  3504.  
  3505. }
  3506. console.log("flushActiveItems_", "OK");
  3507. } else {
  3508. console.log("flushActiveItems_", "NG");
  3509. }
  3510.  
  3511. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  3512. try {
  3513. if (mlg > 1e9) mlg = 9;
  3514. const tid = ++mlg;
  3515. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  3516. const runCond = () => this.canScrollToBottom_();
  3517. if (!keepTrialCond()) return;
  3518. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  3519. await new Promise(r => setTimeout(r, 80));
  3520. if (!keepTrialCond()) return;
  3521. if (runCond()) return this.flushActiveItems_() | 1;
  3522. await new Promise(requestAnimationFrame);
  3523. if (runCond()) return this.flushActiveItems_() | 1;
  3524. } catch (e) {
  3525. console.warn(e);
  3526. }
  3527. }
  3528.  
  3529. if ((mclp.atBottomChanged_ || 0).length === 1) {
  3530. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  3531. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.75.39'));
  3532.  
  3533. const querySelector = HTMLElement.prototype.querySelector;
  3534. const U = (element) => ({
  3535. querySelector: (selector) => querySelector.call(element, selector)
  3536. });
  3537.  
  3538. let qid = 0;
  3539. mclp.atBottomChanged_ = function (a) {
  3540. let tid = ++qid;
  3541. let b = this;
  3542. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  3543. if (tid !== qid) return;
  3544. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  3545. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  3546. this.hideShowMoreAsync_ = null,
  3547. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  3548. }
  3549.  
  3550. console.log("atBottomChanged_", "OK");
  3551. } else {
  3552. console.log("atBottomChanged_", "NG");
  3553. }
  3554.  
  3555. if ((mclp.onScrollItems_ || 0).length === 1) {
  3556.  
  3557. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  3558. mclp.onScrollItems66_ = mclp.onScrollItems_;
  3559. mclp.onScrollItems77_ = async function (evt) {
  3560. if (myw > 1e9) myw = 9;
  3561. let tid = ++myw;
  3562.  
  3563. await new Promise(requestAnimationFrame);
  3564.  
  3565. if (tid !== myw) {
  3566. return;
  3567. }
  3568.  
  3569. const cnt = this;
  3570.  
  3571. await Promise.resolve();
  3572. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  3573. await Promise.resolve().then(() => {
  3574. this.ytRendererBehavior.onScroll(evt);
  3575. }).then(() => {
  3576. if (this.canScrollToBottom_()) {
  3577. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  3578. if (hasUserJustInteracted) {
  3579. // only when there is an user action
  3580. this.setAtBottom();
  3581. return 1;
  3582. }
  3583. } else {
  3584. // no message inserting
  3585. this.setAtBottom();
  3586. return 1;
  3587. }
  3588. }).then((r) => {
  3589.  
  3590. if (this.activeItems_.length) {
  3591.  
  3592. if (this.canScrollToBottom_()) {
  3593. this.flushActiveItems_();
  3594. return 1 && r;
  3595. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  3596. // delayed due to user action
  3597. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  3598. return 0;
  3599. }
  3600. }
  3601. }).then((r) => {
  3602. if (r) {
  3603. // ensure setAtBottom is correctly set
  3604. this.setAtBottom();
  3605. }
  3606. });
  3607. } else {
  3608. cnt.onScrollItems66_(evt);
  3609. }
  3610.  
  3611. await Promise.resolve();
  3612.  
  3613. }
  3614.  
  3615. mclp.onScrollItems_ = function (evt) {
  3616.  
  3617. const cnt = this;
  3618. cnt.__intermediate_delay__ = new Promise(resolve => {
  3619. cnt.onScrollItems77_(evt).then(() => {
  3620. resolve();
  3621. });
  3622. });
  3623. }
  3624. console.log("onScrollItems_", "OK");
  3625. } else {
  3626. console.log("onScrollItems_", "NG");
  3627. }
  3628.  
  3629. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  3630.  
  3631. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  3632. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  3633.  
  3634. mclp.handleLiveChatActions77_ = async function (arr) {
  3635. if (typeof (arr || 0).length !== 'number') {
  3636. this.handleLiveChatActions66_(arr);
  3637. return;
  3638. }
  3639. if (mzt > 1e9) mzt = 9;
  3640. let tid = ++mzt;
  3641.  
  3642. if (zarr === null) zarr = arr;
  3643. else Array.prototype.push.apply(zarr, arr);
  3644. arr = null;
  3645.  
  3646. await new Promise(requestAnimationFrame);
  3647.  
  3648. if (tid !== mzt || zarr === null) {
  3649. return;
  3650. }
  3651.  
  3652. const carr = zarr;
  3653. zarr = null;
  3654.  
  3655. await Promise.resolve();
  3656. this.handleLiveChatActions66_(carr);
  3657. await Promise.resolve();
  3658.  
  3659. }
  3660.  
  3661. mclp.handleLiveChatActions_ = function (arr) {
  3662.  
  3663. const cnt = this;
  3664. cnt.__intermediate_delay__ = new Promise(resolve => {
  3665. cnt.handleLiveChatActions77_(arr).then(() => {
  3666. resolve();
  3667. });
  3668. });
  3669. }
  3670. console.log("handleLiveChatActions_", "OK");
  3671. } else {
  3672. console.log("handleLiveChatActions_", "NG");
  3673. }
  3674.  
  3675. mclp.hasUserJustInteracted11_ = () => {
  3676. const t = dateNow();
  3677. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  3678. }
  3679.  
  3680. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  3681.  
  3682. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  3683.  
  3684. mclp.canScrollToBottom_ = function () {
  3685. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  3686. }
  3687.  
  3688. console.log("canScrollToBottom_", "OK");
  3689. } else {
  3690. console.log("canScrollToBottom_", "NG");
  3691. }
  3692.  
  3693. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  3694.  
  3695. mclp.isSmoothScrollEnabled_ = function () {
  3696. return false;
  3697. }
  3698.  
  3699. mclp.maybeResizeScrollContainer_ = function () {
  3700. //
  3701. }
  3702.  
  3703. mclp.refreshOffsetContainerHeight_ = function () {
  3704. //
  3705. }
  3706.  
  3707. mclp.smoothScroll_ = function () {
  3708. //
  3709. }
  3710.  
  3711. mclp.resetSmoothScroll_ = function () {
  3712. //
  3713. }
  3714. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  3715. } else {
  3716. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  3717. }
  3718.  
  3719. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  3720.  
  3721. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  3722. mclp.handleAddChatItemAction_ = function (a) {
  3723. try {
  3724. if (a && typeof a === 'object' && !('length' in a)) {
  3725. fixLiveChatItem(a.item, null);
  3726. console.assert(arguments[0] === a);
  3727. }
  3728. } catch (e) { console.warn(e) }
  3729. return this.handleAddChatItemAction66_.apply(this, arguments);
  3730. }
  3731.  
  3732. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  3733. } else {
  3734.  
  3735. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  3736. }
  3737.  
  3738.  
  3739. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  3740.  
  3741. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  3742. mclp.handleReplaceChatItemAction_ = function (a) {
  3743. try {
  3744. if (a && typeof a === 'object' && !('length' in a)) {
  3745. fixLiveChatItem(a.replacementItem, null);
  3746. console.assert(arguments[0] === a);
  3747. }
  3748. } catch (e) { console.warn(e) }
  3749. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  3750. }
  3751.  
  3752. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  3753. } else {
  3754.  
  3755. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  3756. }
  3757.  
  3758. console.log("[End]");
  3759. console.groupEnd();
  3760.  
  3761. }).catch(console.warn);
  3762.  
  3763.  
  3764. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  3765.  
  3766. let yd = (this.__dataHost || (this.inst || 0).__dataHost || 0).__data;
  3767.  
  3768. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  3769.  
  3770. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  3771. let v = `${attrValue}`;
  3772. // conside a ticker is 101px width
  3773. // 1% = 1.01px
  3774. // 0.2% = 0.202px
  3775.  
  3776.  
  3777. const ratio1 = (yd.ratio * 100);
  3778. if (ratio1 > -1) { // avoid NaN
  3779.  
  3780. // countdownDurationMs
  3781. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  3782. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  3783. // 150000 - 1% <1% = 1.5s>
  3784. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  3785. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  3786.  
  3787. // 99px * 5% = 4.95px
  3788.  
  3789. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  3790.  
  3791.  
  3792. // 1% Duration
  3793.  
  3794. let ratio2 = ratio1;
  3795.  
  3796. const ydd = yd.data;
  3797. if (ydd) {
  3798.  
  3799. const d1 = ydd.durationSec;
  3800. const d2 = ydd.fullDurationSec;
  3801.  
  3802. // @ step timing [min. 0.2%]
  3803. let numOfSteps = 500;
  3804. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  3805. if (d2 > 400) numOfSteps = 500; // 0.2%
  3806. else if (d2 > 200) numOfSteps = 200; // 0.5%
  3807. else if (d2 > 100) numOfSteps = 100; // 1%
  3808. else if (d2 > 50) numOfSteps = 50; // 2%
  3809. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  3810. else numOfSteps = 20;
  3811. }
  3812. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  3813. if (numOfSteps < 5) numOfSteps = 5;
  3814.  
  3815. const rd = numOfSteps / 100.0;
  3816.  
  3817. ratio2 = Math.round(ratio2 * rd) / rd;
  3818.  
  3819. // ratio2 = Math.round(ratio2 * 5) / 5;
  3820. ratio2 = ratio2.toFixed(1);
  3821. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  3822.  
  3823. if (yd.__style_last__ === v) return;
  3824. yd.__style_last__ = v;
  3825. // do not consider any delay here.
  3826. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  3827.  
  3828. }
  3829. }
  3830.  
  3831. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  3832.  
  3833.  
  3834. } else {
  3835. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  3836. }
  3837.  
  3838. };
  3839.  
  3840.  
  3841. const fpTicker = (renderer) => {
  3842. const cnt = renderer.inst || renderer;
  3843. assertor(() => typeof (cnt || 0).is === 'string');
  3844. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  3845. const container = (cnt.$ || 0).container;
  3846. if (container) {
  3847. assertor(() => (container || 0).nodeType === 1);
  3848. assertor(() => typeof container.setAttribute === 'function');
  3849. container.setAttribute = tickerContainerSetAttribute;
  3850. } else {
  3851. console.warn(`"container" does not exist in ${cnt.is}`);
  3852. }
  3853. };
  3854.  
  3855.  
  3856. const tags = ["yt-live-chat-ticker-paid-message-item-renderer", "yt-live-chat-ticker-paid-sticker-item-renderer",
  3857. "yt-live-chat-ticker-renderer", "yt-live-chat-ticker-sponsor-item-renderer"];
  3858.  
  3859.  
  3860. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  3861.  
  3862. mightFirstCheckOnYtInit();
  3863. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  3864. console.log("[Begin]");
  3865.  
  3866. // << if ENABLE_VIDEO_PROGRESS_STATE_FIX >>
  3867. let isMainVideoOngoing = null;
  3868. let mainVideoLastProgress = null;
  3869. // << end >>
  3870.  
  3871. for (const tag of tags) {
  3872. const dummy = document.createElement(tag);
  3873.  
  3874. const cProto = getProto(dummy);
  3875. if (!cProto || !cProto.attached) {
  3876. console.warn(`proto.attached for ${tag} is unavailable.`);
  3877. continue;
  3878. }
  3879.  
  3880. cProto.attached77 = cProto.attached;
  3881.  
  3882. cProto.attached = function () {
  3883. fpTicker(this.hostElement || this);
  3884. return this.attached77();
  3885. }
  3886.  
  3887. for (const elm of document.getElementsByTagName(tag)) {
  3888. if ((elm || elm.inst).isAttached === true) {
  3889. fpTicker(elm);
  3890. }
  3891. }
  3892.  
  3893.  
  3894. let rafHackState = 0;
  3895.  
  3896. let isTimingFunctionHackable = false;
  3897.  
  3898. let urt = 0;
  3899.  
  3900. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  3901.  
  3902. // console.log('startCountdown', typeof cProto.startCountdown)
  3903. // console.log('updateTimeout', typeof cProto.updateTimeout)
  3904. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  3905.  
  3906. isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  3907.  
  3908. } else {
  3909. console.log(`Skip Timing Function Modification for ${tag}`);
  3910. continue;
  3911. }
  3912.  
  3913.  
  3914. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  3915.  
  3916. // cancelable - this.rafId < isAnimationPausedChanged >
  3917. rafHackState = 1;
  3918.  
  3919. if (isTimingFunctionHackable) {
  3920. rafHackState = 2;
  3921.  
  3922. } else {
  3923. rafHackState = 4;
  3924. }
  3925.  
  3926. }
  3927.  
  3928. const isCSSPropertySupported = () => {
  3929.  
  3930. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return;
  3931. const documentElement = document.documentElement;
  3932. if (!documentElement) {
  3933. console.warn('document.documentElement is not found');
  3934. return false;
  3935. }
  3936. if (`${window.getComputedStyle(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  3937. return false;
  3938. }
  3939. return true;
  3940.  
  3941. };
  3942.  
  3943. const doAnimator = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  3944.  
  3945. const doRAFHack = rafHackState === 2;
  3946.  
  3947. cProto._throwOut = function () {
  3948. this._r782 = 1;
  3949. Promise.resolve().then(() => {
  3950. if (typeof this.requestRemoval === 'function') {
  3951. const id = (this.data || 0).id;
  3952. if (!id) this.data = { id: 1 };
  3953. try {
  3954. this.requestRemoval();
  3955. } catch (e) { }
  3956. }
  3957. this.detached();
  3958. this.data = null;
  3959. this.countdownMs = 0;
  3960. this.lastCountdownTimeMs = null;
  3961. if (this.__dataClientsReady === true) this.__dataClientsReady = false;
  3962. if (this.__dataEnabled === true) this.__dataEnabled = false;
  3963. if (this.__dataReady === true) this.__dataReady = false;
  3964. const hm = this.hostElement || this;
  3965. if (hm.parentNode) hm.remove();
  3966. if (hm.firstChild) hm.textContent = '';
  3967. }).catch(e => {
  3968. console.warn(e);
  3969. });
  3970. };
  3971.  
  3972. // cProto._checkTickerBackgroundChanged = doAnimator ? function () {
  3973. // if (runTickerClassName === 'run-ticker') {
  3974. // const container = (this.$ || 0).container || 0;
  3975. // if (!container) return;
  3976. // container.classList.add('run-ticker-test');
  3977. // const evaluated = `${window.getComputedStyle(container).background}`;
  3978. // container.classList.remove('run-ticker-test');
  3979. // if (evaluated.indexOf('0.') < 4) {
  3980. // // not fulfilling
  3981. // // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3982. // runTickerClassName = 'run-ticker-forced';
  3983. // console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3984. // "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3985. // "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3986. // );
  3987. // 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');
  3988. // console.groupEnd();
  3989. // }
  3990. // }
  3991. // } : null;
  3992.  
  3993. cProto._makeAnimator = doAnimator ? function () {
  3994. if (this._r782) return;
  3995. // if (!this.isAttached) return;
  3996. if (!this._runnerAE) {
  3997. const aElement = (this.$ || 0).container;
  3998. if (!aElement) return console.warn("this.$.container is undefined");
  3999. const da = this.data;
  4000. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  4001. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  4002. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  4003. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  4004.  
  4005. // if (!this.__tickerBackgroundInitialChecked__) {
  4006. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  4007. // console.log('__tickerBackgroundInitialChecked__')
  4008. // this._checkTickerBackgroundChanged();
  4009. // }
  4010.  
  4011. aElement.style.setProperty('--ticker-c1', c1);
  4012. aElement.style.setProperty('--ticker-c2', c2);
  4013. aElement.classList.add(runTickerClassName);
  4014. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  4015. // this._aeStartV = this.countdownMs;
  4016. // this._aeStartT = this.countdownDurationMs;
  4017. if (!(p >= 0 && p <= 100)) {
  4018. console.warn('incorrect time ratio', p);
  4019. } else {
  4020. /*
  4021. const u0 = p.toFixed(4) + '%';
  4022. this._runnerAE = animate.call(aElement,
  4023. [
  4024. { '--ticker-rtime': u0 },
  4025. { '--ticker-rtime': '0%' }
  4026. ]
  4027. ,
  4028. {
  4029. fill: "forwards",
  4030. duration: this.countdownMs,
  4031. easing: "linear"
  4032. }
  4033. );
  4034. */
  4035.  
  4036. let timingFn = 'linear';
  4037.  
  4038. const totalDuration = this.countdownDurationMs;
  4039.  
  4040. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  4041.  
  4042. // @ step timing [min. 0.2%]
  4043. let stepInterval = 0.2; // unit: %
  4044. if (totalDuration > 400000) stepInterval = 0.2;
  4045. else if (totalDuration > 200000) stepInterval = 0.5;
  4046. else if (totalDuration > 100000) stepInterval = 1;
  4047. else if (totalDuration > 50000) stepInterval = 2;
  4048. else if (totalDuration > 25000) stepInterval = 5;
  4049. else stepInterval = 5;
  4050.  
  4051. let numOfSteps = Math.round(100 / stepInterval);
  4052.  
  4053. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4054. if (numOfSteps < 5) numOfSteps = 5;
  4055.  
  4056. timingFn = `steps(${numOfSteps}, end)`;
  4057.  
  4058. }
  4059.  
  4060.  
  4061. const ae = animate.call(aElement,
  4062. [
  4063. { '--ticker-rtime': '100%' },
  4064. { '--ticker-rtime': '0%' }
  4065. ]
  4066. ,
  4067. {
  4068. fill: "forwards",
  4069. duration: totalDuration,
  4070. easing: timingFn
  4071. }
  4072. );
  4073.  
  4074. this._runnerAE = ae;
  4075.  
  4076. ae.onfinish = () => {
  4077. this.onfinish = null;
  4078. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  4079. this._aeFinished();
  4080. }
  4081. }
  4082.  
  4083. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  4084.  
  4085. if (bq >= 0 && bq <= totalDuration) {
  4086.  
  4087. if (bq > totalDuration - 1) {
  4088. ae.currentTime = bq;
  4089. // setTimeout(() => {
  4090. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  4091. // }, 1);
  4092. } else {
  4093. ae.currentTime = bq;
  4094. }
  4095. } else {
  4096. console.warn('Error on setting _runnerAE.currentTime!');
  4097. }
  4098.  
  4099.  
  4100. aeConstructor = ae.constructor; // constructor is from iframe
  4101. return ae;
  4102. }
  4103. } else {
  4104. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  4105. // assume just time update
  4106. const ae = this._runnerAE;
  4107. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  4108. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  4109. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  4110. if (!(p >= 0 && p <= 100)) {
  4111. console.warn('incorrect time ratio', p);
  4112. } else {
  4113. // let u0 = p.toFixed(4) + '%'
  4114. /*
  4115. ae.effect.setKeyframes([
  4116. { '--ticker-rtime': u0 },
  4117. { '--ticker-rtime': '0%' }
  4118. ]);
  4119. ae.effect.updateTiming({ duration: this.countdownMs });
  4120. */
  4121. // ae.currentTime = 0;
  4122.  
  4123.  
  4124.  
  4125. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  4126. if (bq >= 0 && bq <= this.countdownDurationMs) {
  4127.  
  4128. this._runnerAE.currentTime = bq
  4129. } else {
  4130. console.warn('Error on setting _runnerAE.currentTime!');
  4131. }
  4132.  
  4133.  
  4134. ae.play();
  4135. return ae;
  4136. }
  4137. }
  4138. } : null;
  4139.  
  4140. cProto._aeFinished = doAnimator ? function () {
  4141.  
  4142. if (this._r782) return;
  4143.  
  4144. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4145. this._throwOut();
  4146. return;
  4147. }
  4148.  
  4149. if (doAnimator) {
  4150. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4151.  
  4152. let lc = window.performance.now();
  4153. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4154. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4155. this.lastCountdownTimeMs = lc;
  4156. if (this.countdownMs > 10) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs); // just warning.
  4157.  
  4158. this.countdownMs = 0;
  4159. this.lastCountdownTimeMs = null;
  4160.  
  4161. if (this.isAttached) {
  4162. let fastRemoved = false;
  4163. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  4164. // no animation if the video page is switched from background to foreground
  4165. // this.hostElement.style.display = 'none';
  4166. const id = (this.data || 0).id || 0;
  4167. if (!id) this.data = { id: 1 }
  4168. try {
  4169. this.requestRemoval();
  4170. fastRemoved = true;
  4171. } catch (e) {
  4172.  
  4173. }
  4174. }
  4175.  
  4176. if (!fastRemoved) {
  4177. "auto" === this.hostElement.style.width && this.setContainerWidth();
  4178. this.slideDown();
  4179. }
  4180. }
  4181.  
  4182.  
  4183. } else {
  4184. console.warn('unexpected issue')
  4185. }
  4186. } : null;
  4187.  
  4188.  
  4189. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  4190.  
  4191. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  4192. urt++;
  4193. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  4194. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  4195. cProto.handlePauseReplay = function () {
  4196. if (this.isAttached) {
  4197.  
  4198. if (pairForPauseResumeM === 0) {
  4199. pairForPauseResume++;
  4200. if (pairForPauseResume > 1e9) pairForPauseResume = pairForPauseResume % 1e4;
  4201. }
  4202. // console.log('handlePauseReplay');
  4203. // console.log('handlePauseReplay', pairForPauseResume);
  4204. const r = this.handlePauseReplay66.apply(this, arguments);
  4205. isMainVideoOngoing = false;
  4206. return r;
  4207. }
  4208. };
  4209. } else {
  4210. console.log('Error for setting cProto.handlePauseReplay', tag)
  4211. }
  4212.  
  4213. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handlePauseReplay.length === 0) {
  4214. urt++;
  4215. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  4216. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  4217. cProto.handleResumeReplay = function () {
  4218. if (this.isAttached) {
  4219.  
  4220. if (pairForPauseResumeM === 0) {
  4221. pairForPauseResume++;
  4222. if (pairForPauseResume > 1e9) pairForPauseResume = pairForPauseResume % 1e4;
  4223. }
  4224. // console.log('handleResumeReplay');
  4225. // console.log('handleResumeReplay', pairForPauseResume);
  4226. const r = this.handleResumeReplay66.apply(this, arguments);
  4227. isMainVideoOngoing = true;
  4228. return r;
  4229.  
  4230. }
  4231. };
  4232. } else {
  4233. console.log('Error for setting cProto.handleResumeReplay', tag)
  4234. }
  4235.  
  4236. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  4237. urt++;
  4238. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  4239. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  4240. cProto.handleReplayProgress = function (a) {
  4241. if (this.isAttached) {
  4242. const p = mainVideoLastProgress;
  4243. mainVideoLastProgress = a;
  4244. if (isMainVideoOngoing === false) { // ignore isMainVideoOngoing === null ?
  4245. const d = a - p;
  4246. if (d > 0 && d < 0.28) isMainVideoOngoing = true; // timeupdate
  4247. // 0.28 is due to
  4248. // - most browsers will fire the timeupdate event between 4 to 60 times per second
  4249. // - i.e. timeupdate roughly every 15-250 milliseconds
  4250. }
  4251. let promiseResult = null;
  4252. if (this.isAnimationPaused) {
  4253. // unstable state for isMainVideoOngoing; delay required
  4254. // all the tickers' handleReplayProgress are executed in the same microtask
  4255. // execute after result returned
  4256. const lz1 = pairForPauseResume;
  4257. Promise.resolve().then(() => {
  4258. return promiseResult
  4259. }).then(() => {
  4260.  
  4261.  
  4262. if (isMainVideoOngoing === true && this.isAnimationPaused) {
  4263. const lz2 = pairForPauseResume;
  4264. // console.log( 10044000, lz1, lz2 , mainVideoLastProgress - a, isMainVideoOngoing )
  4265. if (lz1 === lz2 && mainVideoLastProgress !== null && mainVideoLastProgress - a >= -1e-5) this.isAnimationPaused = false; // trigger isAnimationPausedChanged
  4266. }
  4267.  
  4268. });
  4269. }
  4270.  
  4271. const lq1 = pairForPauseResume;
  4272. promiseResult = Promise.resolve().then(() => {
  4273. const lq2 = pairForPauseResume;
  4274.  
  4275. if (lq1 === lq2) {
  4276. this.handleReplayProgress66(a);
  4277. }
  4278.  
  4279.  
  4280. })
  4281.  
  4282. }
  4283. };
  4284. } else {
  4285. console.log('Error for setting cProto.handleReplayProgress', tag)
  4286. }
  4287.  
  4288. }
  4289.  
  4290. const ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED = ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX && urt === 3;
  4291.  
  4292. const doTimerFnModification = (doRAFHack || doAnimator);
  4293.  
  4294. let windowShownAt = 0;
  4295. if (doTimerFnModification) {
  4296.  
  4297. window.addEventListener('visibilitychange', () => {
  4298. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  4299. else windowShownAt = 0;
  4300. }, false);
  4301.  
  4302. }
  4303.  
  4304. cProto.startCountdown = doTimerFnModification ? function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4305.  
  4306. // a.durationSec [s] => countdownMs [ms]
  4307. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4308. // lastCountdownTimeMs => raf ongoing
  4309. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4310.  
  4311. if (this._r782) return;
  4312.  
  4313. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4314. this._throwOut();
  4315. return;
  4316. }
  4317.  
  4318. if (doAnimator) {
  4319. b = void 0 === b ? 0 : b;
  4320. if (void 0 !== a) {
  4321. this.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  4322. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs; // constant throughout the animation
  4323. if (!(this.lastCountdownTimeMs || this.isAnimationPaused)) {
  4324. this.lastCountdownTimeMs = performance.now()
  4325. this.rafId = 1
  4326. if (this._runnerAE) console.warn('Error in .startCountdown; this._runnerAE already created.')
  4327. this.detlaSincePausedSecs = 0;
  4328. const ae = this._makeAnimator();
  4329. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4330.  
  4331. // console.log(539, isMainVideoOngoing)
  4332. if (this.isAnimationPaused === void 0 && ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED && isMainVideoOngoing === false && mainVideoLastProgress !== null) {
  4333. // << This is mainly for [PlayBack Replay] backwards >>
  4334. // fix the case when the main video is paused but due to seeking the tickers are added
  4335. // play first then pause immediately to allow the visual effect of initial state
  4336. // don't forget to set the "playerProgressSec"
  4337. // otherwise when it resumes from paused state, the detlaSincePausedSecs will be huge
  4338. this.playerProgressSec = mainVideoLastProgress; // save the progress first
  4339. this.isAnimationPaused = true; // trigger isAnimationPausedChanged
  4340. this.detlaSincePausedSecs = 0;
  4341. this._forceNoDetlaSincePausedSecs783 = 1; // reset this.detlaSincePausedSecs = 0 when resumed
  4342. }
  4343. }
  4344. }
  4345. } else {
  4346. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4347. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4348. b = void 0 === b ? 0 : b;
  4349. void 0 !== a && (this.countdownMs = 1E3 * a,
  4350. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs,
  4351. this.ratio = 1,
  4352. this.lastCountdownTimeMs || this.isAnimationPaused || (this.lastCountdownTimeMs = performance.now(),
  4353. this.rafId = rafHub.request(this.boundUpdateTimeout37_)))
  4354. }
  4355.  
  4356. } : cProto.startCountdown;
  4357.  
  4358. cProto.updateTimeout = doTimerFnModification ? function (a) {
  4359.  
  4360. if (this._r782) return;
  4361.  
  4362. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4363. this._throwOut();
  4364. return;
  4365. }
  4366.  
  4367. if (doAnimator) {
  4368. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4369. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4370. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4371. if (this.isAttached && this.countdownMs) {
  4372. this.lastCountdownTimeMs = a
  4373. const ae = this._makeAnimator(); // request raf
  4374. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4375. } else {
  4376. (this.lastCountdownTimeMs = null,
  4377. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4378. this.slideDown()));
  4379. }
  4380. } else {
  4381. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4382. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4383. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4384. this.ratio = this.countdownMs / this.countdownDurationMs;
  4385. this.isAttached && this.countdownMs ? (this.lastCountdownTimeMs = a,
  4386. this.rafId = rafHub.request(this.boundUpdateTimeout37_)) : (this.lastCountdownTimeMs = null,
  4387. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4388. this.slideDown()))
  4389. }
  4390.  
  4391. } : cProto.updateTimeout;
  4392.  
  4393. // let ez = 0;
  4394. cProto.isAnimationPausedChanged = doTimerFnModification ? function (a, b) {
  4395.  
  4396. if (this._r782) return;
  4397.  
  4398. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4399. this._throwOut();
  4400. return;
  4401. }
  4402. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  4403. this._forceNoDetlaSincePausedSecs783 = 0;
  4404.  
  4405. Promise.resolve().then(() => {
  4406.  
  4407. if (doAnimator) {
  4408.  
  4409. const playState = (this._runnerAE || 0).playState;
  4410. if (a && playState === 'running') {
  4411.  
  4412. } else if (!a && playState !== 'running' && b) {
  4413.  
  4414. } else {
  4415. return;
  4416. }
  4417. }
  4418.  
  4419. // if (Math.abs(this.detlaSincePausedSecs) < 0.01) this.detlaSincePausedSecs = 0;
  4420. if (doAnimator) {
  4421. const pu = () => { // running -> pause
  4422. this._runnerAE.pause()
  4423. let lc = window.performance.now();
  4424. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4425. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4426. this.lastCountdownTimeMs = lc;
  4427. };
  4428. const wa = () => { // pause -> running
  4429. if (forceNoDetlaSincePausedSecs783) this.detlaSincePausedSecs = 0;
  4430. a = this.detlaSincePausedSecs ? (this.lastCountdownTimeMs || 0) + 1000 * this.detlaSincePausedSecs : (this.lastCountdownTimeMs || 0);
  4431. this.detlaSincePausedSecs = 0;
  4432. this.updateTimeout(a);
  4433. this.lastCountdownTimeMs = window.performance.now();
  4434. };
  4435. a ? (this._runnerAE && pu()) : (!a && b && wa());
  4436. } else {
  4437. // ez++;
  4438. // if(ez> 1e9) ez=9;
  4439. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4440. a ? rafHub.cancel(this.rafId) : !a && b && (a = this.lastCountdownTimeMs || 0,
  4441. this.detlaSincePausedSecs && (a = (this.lastCountdownTimeMs || 0) + 1E3 * this.detlaSincePausedSecs,
  4442. this.detlaSincePausedSecs = 0),
  4443. this.boundUpdateTimeout37_(a),
  4444. this.lastCountdownTimeMs = window.performance.now())
  4445. }
  4446.  
  4447. }).catch(e => {
  4448. console.log(e);
  4449. });
  4450.  
  4451.  
  4452.  
  4453. } : cProto.isAnimationPausedChanged;
  4454.  
  4455.  
  4456. if (doAnimator) {
  4457.  
  4458. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.81.31'));
  4459.  
  4460. let dummyValueForStyleReturn = null;
  4461.  
  4462. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  4463. cProto.computeContainerStyle = function (a, b) {
  4464.  
  4465. if (this._r782) return;
  4466.  
  4467. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4468. this._throwOut();
  4469. return;
  4470. }
  4471.  
  4472. const fullDurationSec = a ? a.fullDurationSec : 0;
  4473. if (fullDurationSec > 0 && typeof b === 'number') {
  4474.  
  4475. // usually zero
  4476.  
  4477. // let currentDuationSrc = b * fullDurationSec; // a.durationSec
  4478.  
  4479. // console.log(231, fullDurationSec, b, currentDuationSrc, a.durationSec);
  4480.  
  4481. /*
  4482. if (a.mdsz && typeof a.mdst) return a.mdst;
  4483. a.mdsz = 1;
  4484.  
  4485.  
  4486.  
  4487. let c1 = this.colorFromDecimal(a.startBackgroundColor);
  4488. let c2 = this.colorFromDecimal(a.endBackgroundColor);
  4489.  
  4490. let ratio = currentDuationSrc / fullDurationSec;
  4491.  
  4492. let m = (ratio * 100).toFixed(1);
  4493.  
  4494.  
  4495. let s = `--background:linear-gradient(90deg, ${c1},${c1} ${m}%,${c2} ${m}%,${c2});`
  4496. let ro = {
  4497. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4498. "implementsGoogStringTypedString": true
  4499. };
  4500.  
  4501. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4502.  
  4503. a.mdst = s;
  4504.  
  4505. return ro;
  4506. */
  4507. }
  4508.  
  4509.  
  4510.  
  4511. // return this.computeContainerStyle66.apply(this, arguments);
  4512.  
  4513. if (dummyValueForStyleReturn === null) {
  4514.  
  4515. let s = `--nx:82;`
  4516. let ro = {
  4517. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4518. "implementsGoogStringTypedString": true
  4519. };
  4520.  
  4521. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4522.  
  4523.  
  4524. dummyValueForStyleReturn = ro;
  4525.  
  4526.  
  4527. }
  4528.  
  4529.  
  4530. return dummyValueForStyleReturn;
  4531.  
  4532.  
  4533. }
  4534.  
  4535. }
  4536.  
  4537. if (doTimerFnModification === true) hasTimerModified = true;
  4538.  
  4539. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  4540. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  4541. }
  4542.  
  4543. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  4544. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  4545. }
  4546.  
  4547. }
  4548. console.log("[End]");
  4549. console.groupEnd();
  4550.  
  4551.  
  4552. }).catch(console.warn);
  4553.  
  4554. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  4555.  
  4556. mightFirstCheckOnYtInit();
  4557. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  4558. console.log("[Begin]");
  4559. (() => {
  4560.  
  4561. const tag = "yt-live-chat-ticker-renderer"
  4562. const dummy = document.createElement(tag);
  4563.  
  4564. const cProto = getProto(dummy);
  4565. if (!cProto || !cProto.attached) {
  4566. console.warn(`proto.attached for ${tag} is unavailable.`);
  4567. return;
  4568. }
  4569.  
  4570. if (RAF_FIX_keepScrollClamped) {
  4571.  
  4572. // to be improved
  4573.  
  4574. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  4575.  
  4576. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  4577. cProto.keepScrollClamped = function () {
  4578. this._bound_keepScrollClamped = this._bound_keepScrollClamped || this.keepScrollClamped.bind(this);
  4579. this.scrollClampRaf = requestAnimationFrame(this._bound_keepScrollClamped);
  4580. this.maybeClampScroll()
  4581. }
  4582.  
  4583. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  4584. } else {
  4585.  
  4586. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  4587. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  4588. }
  4589.  
  4590. }
  4591.  
  4592.  
  4593. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function' && fnIntegrity(cProto.startScrolling) === '1.44.32' && fnIntegrity(cProto.scrollIncrementally) === '1.82.43') {
  4594. // to be replaced by animator
  4595.  
  4596. cProto.startScrolling = function (a) {
  4597. this.scrollStopHandle && this.cancelAsync(this.scrollStopHandle);
  4598. this.asyncHandle && cancelAnimationFrame(this.asyncHandle);
  4599. this.lastFrameTimestamp = this.scrollStartTime = performance.now();
  4600. this.scrollRatePixelsPerSecond = a;
  4601. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  4602. this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally)
  4603. };
  4604.  
  4605. cProto.scrollIncrementally = function (a) {
  4606. var b = a - (this.lastFrameTimestamp || 0);
  4607. this.$.items.scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  4608. this.maybeClampScroll();
  4609. this.updateArrows();
  4610. this.lastFrameTimestamp = a;
  4611. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  4612. 0 < this.$.items.scrollLeft || this.scrollRatePixelsPerSecond && 0 < this.scrollRatePixelsPerSecond ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  4613. };
  4614.  
  4615. console.log('RAF_FIX: scrollIncrementally', tag, "OK")
  4616. } else {
  4617. assertor(() => fnIntegrity(cProto.startScrolling, '1.44.32'));
  4618. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.82.43'));
  4619. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  4620. }
  4621.  
  4622.  
  4623. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  4624.  
  4625. cProto.attached37 = cProto.attached;
  4626. cProto.detached37 = cProto.detached;
  4627.  
  4628. let naohzId = 0;
  4629. cProto.__naohzId__ = 0;
  4630. cProto.attached = function () {
  4631. Promise.resolve().then(() => {
  4632.  
  4633. const hostElement = this.hostElement || this;
  4634. if (!(hostElement instanceof HTMLElement)) return;
  4635. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  4636. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  4637. // or #chat-messages
  4638. if (!ironPage) return;
  4639. this.__naohzId__ = ++naohzId;
  4640. ironPage.setAttribute('naohz', `${+this.__naohzId__}`);
  4641.  
  4642. ironPage.removeEventListener('click', this.messageBoxClickHandlerForFade, {capture: false, passive: true});
  4643. ironPage.addEventListener('click', this.messageBoxClickHandlerForFade, {capture: false, passive: true});
  4644.  
  4645. });
  4646. return this.attached37.apply(this, arguments);
  4647. };
  4648. cProto.detached = function () {
  4649. Promise.resolve().then(() => {
  4650.  
  4651. const ironPage = document.querySelector(`iron-pages[naohz="${+this.__naohzId__}"]`);
  4652. if (!ironPage) return;
  4653.  
  4654. ironPage.removeEventListener('click', this.messageBoxClickHandlerForFade, {capture: false, passive: true});
  4655.  
  4656. });
  4657. return this.detached37.apply(this, arguments);
  4658. };
  4659.  
  4660. const clickFade = (p)=>{
  4661.  
  4662. let u = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  4663. if (u) u.click();
  4664. };
  4665. cProto.messageBoxClickHandlerForFade = async (evt) => {
  4666.  
  4667. const target = (evt || 0).target || 0;
  4668. evt = null;
  4669. if (!target) return;
  4670.  
  4671. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  4672. const is = p.is;
  4673. if (typeof is === 'string' && is) {
  4674.  
  4675. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  4676. Promise.resolve(p).then(clickFade);
  4677. return;
  4678. }
  4679. if (is.startsWith('yt-live-chat-ticker-')) return;
  4680. if (!is.endsWith('-renderer')) return;
  4681.  
  4682. } else {
  4683. if ((p.nodeName || '').includes('BUTTON')) return;
  4684. }
  4685.  
  4686. }
  4687. };
  4688.  
  4689. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  4690.  
  4691. } else {
  4692. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  4693. }
  4694.  
  4695.  
  4696. })();
  4697.  
  4698. console.log("[End]");
  4699.  
  4700. console.groupEnd();
  4701.  
  4702. }).catch(console.warn);
  4703.  
  4704.  
  4705. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  4706.  
  4707.  
  4708. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  4709.  
  4710. mightFirstCheckOnYtInit();
  4711. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  4712. console.log("[Begin]");
  4713. (() => {
  4714.  
  4715. const tag = "yt-live-chat-message-input-renderer"
  4716. const dummy = document.createElement(tag);
  4717.  
  4718. const cProto = getProto(dummy);
  4719. if (!cProto || !cProto.attached) {
  4720. console.warn(`proto.attached for ${tag} is unavailable.`);
  4721. return;
  4722. }
  4723.  
  4724. let doHack = false;
  4725. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  4726.  
  4727. // not cancellable
  4728.  
  4729.  
  4730. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  4731.  
  4732. }
  4733.  
  4734. if (doHack) {
  4735.  
  4736. cProto.handleTimeout = function (a) {
  4737. console.log('cProto.handleTimeout', tag)
  4738. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  4739. this.timeoutDurationMs = this.timeoutMs = a;
  4740. this.countdownRatio = 1;
  4741. 0 === this.lastTimeoutTimeMs && rafHub.request(this.boundUpdateTimeout38_)
  4742. };
  4743. cProto.updateTimeout = function (a) {
  4744. console.log('cProto.updateTimeout', tag)
  4745. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  4746. this.lastTimeoutTimeMs && (this.timeoutMs = Math.max(0, this.timeoutMs - (a - this.lastTimeoutTimeMs)),
  4747. this.countdownRatio = this.timeoutMs / this.timeoutDurationMs);
  4748. this.isAttached && this.timeoutMs ? (this.lastTimeoutTimeMs = a,
  4749. rafHub.request(this.boundUpdateTimeout38_)) : this.lastTimeoutTimeMs = 0
  4750. };
  4751.  
  4752. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  4753. } else {
  4754.  
  4755. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  4756. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  4757.  
  4758. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  4759. }
  4760.  
  4761. })();
  4762.  
  4763. console.log("[End]");
  4764.  
  4765. console.groupEnd();
  4766.  
  4767.  
  4768. })
  4769.  
  4770.  
  4771. }
  4772.  
  4773. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  4774.  
  4775.  
  4776. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  4777.  
  4778. mightFirstCheckOnYtInit();
  4779. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  4780. console.log("[Begin]");
  4781. (() => {
  4782.  
  4783. const tag = "yt-emoji-picker-renderer"
  4784. const dummy = document.createElement(tag);
  4785.  
  4786. const cProto = getProto(dummy);
  4787. if (!cProto || !cProto.attached) {
  4788. console.warn(`proto.attached for ${tag} is unavailable.`);
  4789. return;
  4790. }
  4791.  
  4792. let doHack = false;
  4793. if (typeof cProto.animateScroll_ === 'function') {
  4794.  
  4795. // not cancellable
  4796. console.log('animateScroll_', typeof cProto.animateScroll_)
  4797.  
  4798. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  4799.  
  4800. }
  4801.  
  4802. if (doHack) {
  4803.  
  4804. const querySelector = HTMLElement.prototype.querySelector;
  4805. const U = (element) => ({
  4806. querySelector: (selector) => querySelector.call(element, selector)
  4807. });
  4808.  
  4809. cProto.animateScroll_ = function (a) {
  4810. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  4811. if (!this.boundAnimateScroll39_) this.boundAnimateScroll39_ = this.animateScroll_.bind(this);
  4812. this.lastAnimationTime_ || (this.lastAnimationTime_ = a);
  4813. a -= this.lastAnimationTime_;
  4814. 200 > a ? (U(this.hostElement).querySelector("#categories").scrollTop = this.animationStart_ + (this.animationEnd_ - this.animationStart_) * a / 200,
  4815. rafHub.request(this.boundAnimateScroll39_)) : (null != this.animationEnd_ && (U(this.hostElement).querySelector("#categories").scrollTop = this.animationEnd_),
  4816. this.animationEnd_ = this.animationStart_ = null,
  4817. this.lastAnimationTime_ = 0);
  4818. this.updateButtons_()
  4819. }
  4820.  
  4821. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  4822. } else {
  4823.  
  4824. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  4825. }
  4826.  
  4827. })();
  4828.  
  4829. console.log("[End]");
  4830.  
  4831. console.groupEnd();
  4832. });
  4833. }
  4834.  
  4835. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  4836.  
  4837.  
  4838. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  4839.  
  4840. mightFirstCheckOnYtInit();
  4841. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  4842. console.log("[Begin]");
  4843. (() => {
  4844.  
  4845. const tag = "yt-live-chat-docked-message"
  4846. const dummy = document.createElement(tag);
  4847.  
  4848. const cProto = getProto(dummy);
  4849. if (!cProto || !cProto.attached) {
  4850. console.warn(`proto.attached for ${tag} is unavailable.`);
  4851. return;
  4852. }
  4853.  
  4854. let doHack = false;
  4855. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  4856.  
  4857. // cancelable - this.intersectRAF <detached>
  4858. // yt-live-chat-docked-message
  4859. // boundCheckIntersections <-> checkIntersections
  4860. // onDockableMessagesChanged
  4861. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  4862.  
  4863. console.log('detached', typeof cProto.detached)
  4864. console.log('checkIntersections', typeof cProto.checkIntersections)
  4865. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  4866.  
  4867. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  4868.  
  4869. }
  4870.  
  4871. if (doHack) {
  4872.  
  4873. cProto.checkIntersections = function () {
  4874. // console.log('cProto.checkIntersections', tag)
  4875. if (this.dockableMessages.length) {
  4876. this.intersectRAF = rafHub.request(this.boundCheckIntersections);
  4877. let a = this.dockableMessages[0]
  4878. , b = this.hostElement.getBoundingClientRect();
  4879. a = a.getBoundingClientRect();
  4880. let c = a.top - b.top
  4881. , d = 8 >= c;
  4882. c = 8 >= c - this.hostElement.clientHeight;
  4883. if (d) {
  4884. let e;
  4885. for (; d;) {
  4886. e = this.dockableMessages.shift();
  4887. d = this.dockableMessages[0];
  4888. if (!d)
  4889. break;
  4890. d = d.getBoundingClientRect();
  4891. c = d.top - b.top;
  4892. let f = 8 >= c;
  4893. if (8 >= c - a.height)
  4894. if (f)
  4895. a = d;
  4896. else
  4897. return;
  4898. d = f
  4899. }
  4900. this.dock(e)
  4901. } else
  4902. c && this.dockedItem && this.clear()
  4903. } else
  4904. this.intersectRAF = 0
  4905. }
  4906.  
  4907. cProto.onDockableMessagesChanged = function () {
  4908. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  4909. this.dockableMessages.length && !this.intersectRAF && (this.intersectRAF = rafHub.request(this.boundCheckIntersections))
  4910. }
  4911.  
  4912. cProto.detached = function () {
  4913. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  4914. }
  4915.  
  4916. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  4917. } else {
  4918.  
  4919. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  4920. }
  4921.  
  4922. })();
  4923.  
  4924. console.log("[End]");
  4925.  
  4926. console.groupEnd();
  4927.  
  4928. }).catch(console.warn);
  4929.  
  4930. }
  4931.  
  4932. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  4933.  
  4934.  
  4935. customElements.whenDefined("yt-img-shadow").then(() => {
  4936.  
  4937. mightFirstCheckOnYtInit();
  4938. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  4939. console.log("[Begin]");
  4940. (() => {
  4941.  
  4942. const tag = "yt-img-shadow"
  4943. const dummy = document.createElement(tag);
  4944.  
  4945. const cProto = getProto(dummy);
  4946. if (!cProto || !cProto.attached) {
  4947. console.warn(`proto.attached for ${tag} is unavailable.`);
  4948. return;
  4949. }
  4950.  
  4951. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  4952.  
  4953. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  4954. cProto.thumbnailChanged_ = function (a) {
  4955.  
  4956. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  4957. if (!this.oldThumbnail_ && !this.thumbnail) return;
  4958.  
  4959. return this.thumbnailChanged66_.apply(this, arguments)
  4960.  
  4961. }
  4962. console.log("cProto.thumbnailChanged_ - OK");
  4963.  
  4964. } else {
  4965. console.log("cProto.thumbnailChanged_ - NG");
  4966.  
  4967. }
  4968. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  4969.  
  4970. cProto.setSrc66_ = cProto.setSrc_;
  4971. cProto.setSrc_ = function (a) {
  4972. if ((((this || 0).$ || 0).img || 0).src === a) return;
  4973. return this.setSrc66_.apply(this, arguments)
  4974. }
  4975.  
  4976. console.log("cProto.setSrc_ - OK");
  4977. } else {
  4978.  
  4979. console.log("cProto.setSrc_ - NG");
  4980. }
  4981.  
  4982. })();
  4983.  
  4984. console.log("[End]");
  4985.  
  4986. console.groupEnd();
  4987.  
  4988. }).catch(console.warn);
  4989.  
  4990. }
  4991.  
  4992. if (FIX_THUMBNAIL_DATACHANGED) {
  4993.  
  4994.  
  4995.  
  4996. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  4997.  
  4998. mightFirstCheckOnYtInit();
  4999. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  5000. console.log("[Begin]");
  5001. (() => {
  5002.  
  5003. const tag = "yt-live-chat-author-badge-renderer"
  5004. const dummy = document.createElement(tag);
  5005.  
  5006. const cProto = getProto(dummy);
  5007. if (!cProto || !cProto.attached) {
  5008. console.warn(`proto.attached for ${tag} is unavailable.`);
  5009. return;
  5010. }
  5011.  
  5012.  
  5013. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && fnIntegrity(cProto.dataChanged) === '1.159.97') {
  5014.  
  5015.  
  5016.  
  5017. cProto.dataChanged86 = cProto.dataChanged;
  5018. cProto.dataChanged = function (a) {
  5019.  
  5020. /*
  5021.  
  5022. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  5023. b.removeChild(b.firstChild);
  5024. if (a)
  5025. if (a.icon) {
  5026. var c = document.createElement("yt-icon");
  5027. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  5028. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  5029. b.appendChild(c)
  5030. } else if (a.customThumbnail) {
  5031. c = document.createElement("img");
  5032. var d;
  5033. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  5034. b.appendChild(c),
  5035. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  5036. }
  5037.  
  5038. */
  5039.  
  5040. const image = ((this || 0).$ || 0).image
  5041. if (image && a && image.firstElementChild) {
  5042. let exisiting = image.firstElementChild;
  5043. if (exisiting === image.lastElementChild) {
  5044.  
  5045.  
  5046. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  5047.  
  5048. let c = exisiting;
  5049. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  5050. if (c.icon !== "yt-sys-icons:shield-filled") c.icon = "yt-sys-icons:shield-filled";
  5051. if (c.defaultToFilled !== true) c.defaultToFilled = true;
  5052. } else {
  5053. let p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  5054. if (c.icon !== p) c.icon = p;
  5055. if (c.defaultToFilled !== false) c.defaultToFilled = false;
  5056. }
  5057. return;
  5058.  
  5059.  
  5060. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  5061.  
  5062. let c = exisiting;
  5063. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  5064.  
  5065. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  5066. return;
  5067. }
  5068. /*
  5069.  
  5070. var d;
  5071. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  5072.  
  5073.  
  5074. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  5075. */
  5076. }
  5077.  
  5078.  
  5079. }
  5080. }
  5081. return this.dataChanged86.apply(this, arguments)
  5082.  
  5083. }
  5084. console.log("cProto.dataChanged - OK");
  5085.  
  5086. } else {
  5087. assertor(() => fnIntegrity(cProto.dataChanged, '1.159.97'));
  5088. console.log("cProto.dataChanged - NG");
  5089.  
  5090. }
  5091.  
  5092. })();
  5093.  
  5094. console.log("[End]");
  5095.  
  5096. console.groupEnd();
  5097.  
  5098. }).catch(console.warn);
  5099.  
  5100.  
  5101. }
  5102.  
  5103.  
  5104. if (FIX_TOOLTIP_DISPLAY) {
  5105.  
  5106.  
  5107. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  5108.  
  5109. mightFirstCheckOnYtInit();
  5110. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  5111. console.log("[Begin]");
  5112. (() => {
  5113.  
  5114. const tag = "tp-yt-paper-tooltip"
  5115. const dummy = document.createElement(tag);
  5116.  
  5117. const cProto = getProto(dummy);
  5118. if (!cProto || !cProto.attached) {
  5119. console.warn(`proto.attached for ${tag} is unavailable.`);
  5120. return;
  5121. }
  5122.  
  5123. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  5124.  
  5125. cProto._readyClients43 = cProto._readyClients;
  5126. cProto._readyClients = function () {
  5127. let r = cProto._readyClients43.apply(this, arguments);
  5128. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  5129. return r;
  5130. }
  5131.  
  5132. console.log("_readyClients - OK");
  5133.  
  5134. } else {
  5135. console.log("_readyClients - NG");
  5136.  
  5137. }
  5138.  
  5139.  
  5140. })();
  5141.  
  5142. console.log("[End]");
  5143.  
  5144. console.groupEnd();
  5145.  
  5146. }).catch(console.warn);
  5147.  
  5148.  
  5149.  
  5150. }
  5151.  
  5152.  
  5153.  
  5154. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  5155.  
  5156.  
  5157. const hookDocumentMouseDownSetupFn = () => {
  5158.  
  5159.  
  5160.  
  5161. let muzTimestamp = 0;
  5162. let nszDropdown = null;
  5163.  
  5164.  
  5165.  
  5166. const handlerObject = {
  5167.  
  5168. // mdHandler282 : function (evt) {
  5169. // // console.log(evt, 1, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5170. // if (!evt || !evt.isTrusted) return;
  5171. // muzTimestamp = 0;
  5172. // nszDropdown = null;
  5173.  
  5174. // const hostElement = this.hostElement || this;
  5175. // if (!evt || !evt.isTrusted || !hostElement.hasAttribute('menu-visible')) return;
  5176. // if (!hostElement.contains(evt.target)) return;
  5177. // let targetDropDown = null;
  5178. // for(const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')){
  5179. // if(dropdown && dropdown.positionTarget && hostElement.contains( dropdown.positionTarget)){
  5180. // targetDropDown = dropdown;
  5181. // }
  5182. // }
  5183. // if ((nszDropdown = targetDropDown)) {
  5184. // muzTimestamp = Date.now();
  5185. // evt.stopImmediatePropagation();
  5186. // evt.stopPropagation();
  5187. // }
  5188.  
  5189. // },
  5190.  
  5191.  
  5192. muHandler282: function (evt) {
  5193. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5194. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5195. const dropdown = nszDropdown;
  5196. muzTimestamp = 0;
  5197. nszDropdown = null;
  5198.  
  5199. const kurMPC = kRef(currentMenuPivotWR) || 0;
  5200. const hostElement = kurMPC.hostElement || kurMPC;
  5201. if (!hostElement.hasAttribute('menu-visible')) return;
  5202. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  5203. muzTimestamp = Date.now();
  5204. evt.stopImmediatePropagation();
  5205. evt.stopPropagation();
  5206. Promise.resolve(dropdown).then((dropdown) => {
  5207. dropdown.cancel();
  5208. });
  5209. // document.body.click();
  5210. }
  5211.  
  5212. },
  5213.  
  5214. mlHandler282: function (evt) {
  5215. muzTimestamp = 0;
  5216. nszDropdown = null;
  5217. },
  5218.  
  5219. ckHandler282: function (evt) {
  5220. // console.log(evt, 3, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5221.  
  5222. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5223. if (Date.now() - muzTimestamp < 40) {
  5224. muzTimestamp = Date.now();
  5225. evt.stopImmediatePropagation();
  5226. evt.stopPropagation();
  5227. }
  5228.  
  5229. },
  5230.  
  5231. tapHandler282: function (evt) {
  5232. // console.log(evt, 2, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5233.  
  5234. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5235. if (Date.now() - muzTimestamp < 40) {
  5236. muzTimestamp = Date.now();
  5237. evt.stopImmediatePropagation();
  5238. evt.stopPropagation();
  5239. }
  5240.  
  5241. },
  5242.  
  5243.  
  5244. handleEvent(evt) {
  5245.  
  5246.  
  5247. if (evt) {
  5248. const kurMPC = kRef(currentMenuPivotWR) || 0;
  5249. const cnt = kurMPC.inst || kurMPC;
  5250. const hostElement = cnt.hostElement || cnt;
  5251. if (!cnt || cnt.isAttached !== true || hostElement.isConnected !== true) return;
  5252. switch (evt.type) {
  5253. // case 'mousedown':
  5254. // return this.mdHandler282.call(kurMPC, evt);
  5255. case 'mouseup':
  5256. return this.muHandler282(evt);
  5257. case 'mouseleave':
  5258. return this.mlHandler282(evt);
  5259. case 'tap':
  5260. return this.tapHandler282(evt);
  5261. case 'click':
  5262. return this.ckHandler282(evt);
  5263. }
  5264. }
  5265.  
  5266. }
  5267.  
  5268.  
  5269.  
  5270. }
  5271.  
  5272. document.addEventListener('mousedown', function (evt) {
  5273.  
  5274. if (!evt || !evt.isTrusted || !evt.target) return;
  5275. muzTimestamp = 0;
  5276. nszDropdown = null;
  5277.  
  5278. /** @type {HTMLElement | null} */
  5279. const kurMP = kRef(currentMenuPivotWR);
  5280. if (!kurMP) return;
  5281. const kurMPC = kurMP.closest('[menu-visible]') || 0;
  5282.  
  5283. if (!kurMPC.isClickableChatRow111 || !kurMPC.isClickableChatRow111() || !kurMPC.contains(evt.target)) return;
  5284.  
  5285. let targetDropDown = null;
  5286. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  5287. if (dropdown && dropdown.positionTarget === kurMP) {
  5288. targetDropDown = dropdown;
  5289. }
  5290. }
  5291.  
  5292. if ((nszDropdown = targetDropDown)) {
  5293. muzTimestamp = Date.now();
  5294. evt.stopImmediatePropagation();
  5295. evt.stopPropagation();
  5296. currentMenuPivotWR = mWeakRef(kurMPC);
  5297.  
  5298. const listenOpts = { capture: true, passive: false, once: true };
  5299.  
  5300. // remove unexcecuted eventHandler
  5301. document.removeEventListener('mouseup', handlerObject, listenOpts);
  5302. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  5303. document.removeEventListener('tap', handlerObject, listenOpts);
  5304. document.removeEventListener('click', handlerObject, listenOpts);
  5305.  
  5306. // inject one time eventHandler to by pass events
  5307. document.addEventListener('mouseup', handlerObject, listenOpts);
  5308. document.addEventListener('mouseleave', handlerObject, listenOpts);
  5309. document.addEventListener('tap', handlerObject, listenOpts);
  5310. document.addEventListener('click', handlerObject, listenOpts);
  5311.  
  5312. }
  5313.  
  5314. }, true);
  5315.  
  5316. }
  5317.  
  5318.  
  5319. customElements.whenDefined('yt-live-chat-text-message-renderer').then(() => {
  5320.  
  5321.  
  5322. mightFirstCheckOnYtInit();
  5323. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-message-renderer hacks");
  5324. console.log("[Begin]");
  5325. (() => {
  5326.  
  5327. const tag = "yt-live-chat-text-message-renderer"
  5328. const dummy = document.createElement(tag);
  5329.  
  5330. const cProto = getProto(dummy);
  5331. if (!cProto || !cProto.attached) {
  5332. console.warn(`proto.attached for ${tag} is unavailable.`);
  5333. return;
  5334. }
  5335.  
  5336. /*
  5337.  
  5338.  
  5339.  
  5340. remarks:
  5341.  
  5342. const w=new Set();
  5343. setInterval(()=>{
  5344. for(const a of document.getElementsByTagName('*')) if(a.shouldSupportWholeItemClick) w.add(a.is||'');
  5345. console.log([...w.keys()]);
  5346. },800);
  5347.  
  5348.  
  5349. [
  5350. "yt-live-chat-ticker-sponsor-item-renderer",
  5351. "yt-live-chat-banner-header-renderer",
  5352. "yt-live-chat-text-message-renderer",
  5353. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  5354. "ytd-sponsorships-live-chat-header-renderer",
  5355. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer"
  5356. ]
  5357.  
  5358. */
  5359.  
  5360. cProto.isClickableChatRow111 = function () {
  5361. return (
  5362. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  5363. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  5364. ); // follow .onItemTap(a)
  5365. }
  5366.  
  5367.  
  5368.  
  5369. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  5370.  
  5371. if (toHookDocumentMouseDown) {
  5372.  
  5373. hookDocumentMouseDownSetupFn();
  5374.  
  5375.  
  5376. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  5377.  
  5378.  
  5379.  
  5380. } else {
  5381.  
  5382. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent NG");
  5383.  
  5384. }
  5385.  
  5386.  
  5387.  
  5388.  
  5389. })();
  5390.  
  5391. console.log("[End]");
  5392.  
  5393. console.groupEnd();
  5394.  
  5395. }).catch(console.warn);
  5396.  
  5397.  
  5398. }
  5399.  
  5400.  
  5401. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  5402.  
  5403. document.addEventListener('mousedown', function (evt) {
  5404.  
  5405. const maxloopDOMTreeElements = 4;
  5406. const maxloopYtCompontents = 4;
  5407. let j1 = 0;
  5408. let j2 = 0;
  5409. let target = (evt || 0).target || 0;
  5410. if (!target) return;
  5411.  
  5412.  
  5413. while (target instanceof HTMLElement) {
  5414. if (++j1 > maxloopDOMTreeElements) break;
  5415. if (typeof (target.is || (target.inst || 0).is || null) === 'string') break;
  5416. target = nodeParent(target);
  5417. }
  5418. const components = [];
  5419. while (target instanceof HTMLElement) {
  5420. if (++j2 > maxloopYtCompontents) break;
  5421. if (typeof (target.is || (target.inst || 0).is || null) === 'string') {
  5422. components.push(target);
  5423. }
  5424. if (typeof (target.inst || target).showContextMenu === 'function') break;
  5425. target = target.parentComponent || (target.inst || 0).parentComponent || null;
  5426. }
  5427. if (!(target instanceof HTMLElement)) return;
  5428. const targetCnt = target.inst || target;
  5429. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  5430. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  5431. return;
  5432. }
  5433.  
  5434. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  5435. if (!endpoint) return;
  5436. if (targetCnt.opened || !targetCnt.isAttached) return;
  5437.  
  5438. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  5439. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  5440. }
  5441.  
  5442. let doPreRequest = false;
  5443. if (components.length >= 2 && components[0].id === 'menu-button' && (target.$ || 0)['menu-button'] === components[0]) {
  5444. doPreRequest = true;
  5445. } else if (components.length === 1 && components[0] === target) {
  5446. doPreRequest = true;
  5447. } else if (components.length >= 2 && components[0].id === 'author-photo' && (target.$ || 0)['author-photo'] === components[0]) {
  5448. doPreRequest = true;
  5449. }
  5450. if (doPreRequest === false) {
  5451. console.log('doPreRequest = fasle on showContextMenu', components);
  5452. return;
  5453. }
  5454.  
  5455. if (targetCnt.__getCachedEndpointData__(endpoint)) return;
  5456.  
  5457. if (!targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  5458. console.log('preRequest on showContextMenu aborted due to stacked network request');
  5459. return;
  5460. }
  5461.  
  5462.  
  5463. const onSuccess = (a) => {
  5464. /*
  5465.  
  5466. dQ() && (a = a.response);
  5467. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  5468. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  5469.  
  5470. */
  5471.  
  5472. a = a.response || a;
  5473.  
  5474. if (!a) {
  5475. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  5476. return;
  5477. }
  5478.  
  5479. let z = null;
  5480. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  5481.  
  5482. if (z) {
  5483. a = z;
  5484. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  5485. }
  5486.  
  5487. };
  5488. const onFailure = (a) => {
  5489.  
  5490. /*
  5491.  
  5492. if (a instanceof Error || a instanceof Object || a instanceof String)
  5493. var b = a;
  5494. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  5495.  
  5496. */
  5497.  
  5498. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  5499. // console.log('onFailure', a)
  5500.  
  5501. };
  5502.  
  5503. if (doPreRequest) {
  5504.  
  5505. let propertyCounter = 0;
  5506. let p1unlock = null;
  5507. const p1 = new Promise(r => {
  5508. p1unlock = r;
  5509. });
  5510. const p1Timeout = 800;
  5511. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  5512.  
  5513. try {
  5514.  
  5515. const onSuccessHelperFn = function () {
  5516. p1unlock && p1unlock();
  5517. p1unlock = null;
  5518. if (propertyCounter !== 5) {
  5519. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  5520. return;
  5521. }
  5522. if (this[proxyKey] !== targetCnt) {
  5523. console.log('Error in prerequest for showContextMenu.this');
  5524. return;
  5525. }
  5526. onSuccess(...arguments);
  5527. };
  5528. const onFailureHelperFn = function () {
  5529. p1unlock && p1unlock();
  5530. p1unlock = null;
  5531. if (propertyCounter !== 5) {
  5532. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  5533. return;
  5534. }
  5535. if (this[proxyKey] !== targetCnt) {
  5536. console.log('Error in prerequest for showContextMenu.this');
  5537. return;
  5538. }
  5539. onFailure(...arguments);
  5540.  
  5541. }
  5542. const fakeTargetCnt = new Proxy({
  5543. __showContextMenu_forceNativeRequest__: 1,
  5544. __showContextMenu_sync_mode_request__: 1,
  5545. get handleGetContextMenuResponse_() {
  5546. propertyCounter += 2;
  5547. return onSuccessHelperFn;
  5548. },
  5549. get handleGetContextMenuError() {
  5550. propertyCounter += 3;
  5551. return onFailureHelperFn;
  5552. }
  5553. }, {
  5554. get(_, key, receiver) {
  5555. if (key in _) return _[key];
  5556. if (key === proxyKey) return targetCnt;
  5557.  
  5558. let giveNative = false;
  5559. if (key in targetCnt) {
  5560. if (key === 'data') giveNative = true;
  5561. else if (typeof targetCnt[key] === 'function') giveNative = true;
  5562. }
  5563. if (giveNative) return targetCnt[key];
  5564. }
  5565. });
  5566.  
  5567. const fakeEvent = (() => {
  5568. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  5569. const nf = function () { }
  5570. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  5571.  
  5572. return {
  5573. type: 'tap',
  5574. eventPhase: 0,
  5575. isTrusted: false,
  5576. __composed: true,
  5577. bubbles, cancelable, cancelBubble, timeStamp,
  5578. target, srcElement, defaultPrevented, currentTarget, composed,
  5579. stopPropagation, stopImmediatePropagation, preventDefault
  5580. };
  5581. })(evt);
  5582. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  5583.  
  5584.  
  5585. } catch (e) {
  5586. console.warn(e);
  5587. propertyCounter = 7;
  5588.  
  5589. }
  5590. if (propertyCounter !== 5) {
  5591. console.log('Error in prerequest for showContextMenu', propertyCounter);
  5592. return;
  5593. }
  5594. targetCnt.__showContextMenu_assign_lock__(p1);
  5595. setTimeout(() => {
  5596. p1unlock && p1unlock();
  5597. p1unlock = null;
  5598. }, p1Timeout);
  5599. }
  5600.  
  5601.  
  5602.  
  5603.  
  5604.  
  5605.  
  5606. }, true);
  5607.  
  5608.  
  5609. }
  5610.  
  5611.  
  5612.  
  5613. /*
  5614.  
  5615. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  5616.  
  5617. */
  5618.  
  5619. let pTags = [];
  5620. const sTags = [
  5621. "yt-live-chat-ticker-sponsor-item-renderer",
  5622. "yt-live-chat-banner-header-renderer",
  5623. "yt-live-chat-text-message-renderer",
  5624. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  5625. "ytd-sponsorships-live-chat-header-renderer",
  5626. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer"
  5627. ];
  5628.  
  5629. for (const tag of sTags) {
  5630. pTags.push(customElements.whenDefined(tag));
  5631. }
  5632.  
  5633.  
  5634. Promise.all(pTags).then(() => {
  5635.  
  5636.  
  5637. mightFirstCheckOnYtInit();
  5638. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  5639. console.log("[Begin]");
  5640.  
  5641. for (const tag of sTags) {
  5642.  
  5643.  
  5644.  
  5645. (() => {
  5646.  
  5647. const dummy = document.createElement(tag);
  5648.  
  5649. const cProto = getProto(dummy);
  5650. if (!cProto || !cProto.attached) {
  5651. console.warn(`proto.attached for ${tag} is unavailable.`);
  5652. return;
  5653. }
  5654.  
  5655.  
  5656.  
  5657.  
  5658. if (CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN && typeof cProto.showContextMenu === 'function' && typeof cProto.showContextMenu_ === 'function' && !cProto.showContextMenu37 && !cProto.showContextMenu37_ && cProto.showContextMenu.length === 1 && cProto.showContextMenu_.length === 1) {
  5659.  
  5660. cProto.showContextMenu37_ = cProto.showContextMenu_;
  5661. cProto.showContextMenu37 = cProto.showContextMenu;
  5662.  
  5663. function deepCopy(obj, skipKeys) {
  5664. skipKeys = skipKeys || [];
  5665. if (!obj || typeof obj !== 'object') return obj;
  5666. if (Array.isArray(obj)) {
  5667. return obj.map(item => deepCopy(item, skipKeys));
  5668. }
  5669. const copy = {};
  5670. for (let key in obj) {
  5671. if (!skipKeys.includes(key)) {
  5672. copy[key] = deepCopy(obj[key], skipKeys);
  5673. }
  5674. }
  5675. return copy;
  5676. }
  5677.  
  5678. /*
  5679. const wm37 = new WeakMap();
  5680. cProto.__showContextMenu_forceNativeRequest__ = 0;
  5681. cProto.__cacheResolvedEndpointData__ = (endpoint, a, doDeepCopy) => {
  5682. if (a) {
  5683. if (doDeepCopy) a = deepCopy(a);
  5684. wm37.set(endpoint, a);
  5685. } else {
  5686. wm37.remove(endpoint);
  5687. }
  5688. }
  5689. cProto.__showContextMenuNetworkRequestMutex__ = null;
  5690. cProto.__showContextMenuNetworkRequestMutexResolve__ = null;
  5691. cProto.showContextMenu = function (a) {
  5692. if(this.__showContextMenu_forceNativeRequest__){
  5693. return this.showContextMenu37(a);
  5694. }
  5695. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5696. if (!endpoint) {
  5697. return this.showContextMenu37(a);
  5698. }
  5699. this.__showContextMenuNetworkRequestMutex__ = (this.__showContextMenuNetworkRequestMutex__ || Promise.resolve())
  5700. .then(()=>new Promise(lockResolve=>{
  5701.  
  5702. if (endpoint !== (this.data || 0).contextMenuEndpoint || 0){
  5703. lockResolve();
  5704. return;
  5705. }
  5706.  
  5707. if (endpoint) {
  5708. let resolvedEndpoint = wm37.get(endpoint);
  5709. if (resolvedEndpoint) {
  5710. resolvedEndpoint = deepCopy(resolvedEndpoint);
  5711. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  5712. Promise.resolve(resolvedEndpoint).then(() => {
  5713. this.showContextMenu37_(resolvedEndpoint);
  5714. });
  5715. lockResolve();
  5716. return;
  5717. //this.showContextMenu37_(JSON.parse(JSON.stringify(a)));
  5718. //return;
  5719. }
  5720.  
  5721. this.__showContextMenuNetworkRequestMutexResolve__ = new Promise(resolve=>{
  5722. this.__showContextMenuNetworkRequestMutexResolve__ = resolve;
  5723.  
  5724. }).then((a)=>{
  5725.  
  5726. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5727. if (endpoint) {
  5728. const f = this.__cacheResolvedEndpointData__
  5729. if (typeof f === 'function') f(endpoint, a, true);
  5730. }
  5731. this.showContextMenu37_(a);
  5732. lockResolve();
  5733.  
  5734. }).catch(console.warn)
  5735.  
  5736. }else{
  5737.  
  5738. this.__showContextMenuNetworkRequestMutexResolve__ = null;
  5739. this.showContextMenu37(a);
  5740. lockResolve();
  5741. }
  5742.  
  5743.  
  5744.  
  5745.  
  5746. })).catch(console.warn);
  5747. }
  5748.  
  5749. cProto.showContextMenu_ = function (a) {
  5750.  
  5751. let resolve = this.__showContextMenuNetworkRequestMutexResolve__;
  5752. this.__showContextMenuNetworkRequestMutexResolve__= null;
  5753.  
  5754. if (resolve) {
  5755. resolve(a);
  5756. } else {
  5757. return this.showContextMenu37_(a);
  5758. }
  5759.  
  5760. }
  5761. */
  5762.  
  5763.  
  5764. const wm37 = new WeakMap();
  5765. cProto.__showContextMenu_forceNativeRequest__ = 0;
  5766. cProto.__cacheResolvedEndpointData__ = (endpoint, a, doDeepCopy) => {
  5767. if (a) {
  5768. if (doDeepCopy) a = deepCopy(a);
  5769. wm37.set(endpoint, a);
  5770. } else {
  5771. wm37.remove(endpoint);
  5772. }
  5773. }
  5774. cProto.__getCachedEndpointData__ = function (endpoint) {
  5775. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  5776. if (endpoint) return wm37.get(endpoint);
  5777. return null;
  5778. }
  5779. cProto.__showCachedContextMenu__ = function (resolvedEndpoint) { // non-null
  5780.  
  5781. resolvedEndpoint = deepCopy(resolvedEndpoint);
  5782. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  5783. Promise.resolve(resolvedEndpoint).then(() => {
  5784. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  5785. this.showContextMenu_(resolvedEndpoint);
  5786. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  5787. });
  5788.  
  5789.  
  5790.  
  5791. }
  5792. cProto.showContextMenu = function (a) {
  5793. if (!this.__showContextMenu_forceNativeRequest__) {
  5794. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5795. if (endpoint) {
  5796. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  5797. if (resolvedEndpoint) {
  5798. this.__showCachedContextMenu__(resolvedEndpoint);
  5799. return;
  5800. }
  5801. }
  5802. }
  5803. return this.showContextMenu37(a);
  5804. }
  5805.  
  5806. cProto.showContextMenu_ = function (a) {
  5807. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  5808. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5809. if (endpoint) {
  5810. const f = this.__cacheResolvedEndpointData__;
  5811. if (typeof f === 'function') f(endpoint, a, true);
  5812. }
  5813. }
  5814. return this.showContextMenu37_(a);
  5815. }
  5816.  
  5817.  
  5818.  
  5819.  
  5820. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  5821.  
  5822.  
  5823.  
  5824. } else {
  5825.  
  5826. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  5827.  
  5828. }
  5829.  
  5830.  
  5831.  
  5832. if (ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU && typeof cProto.showContextMenu === 'function' && typeof cProto.showContextMenu_ === 'function' && !cProto.showContextMenu48 && !cProto.showContextMenu48_ && cProto.showContextMenu.length === 1 && cProto.showContextMenu_.length === 1) {
  5833.  
  5834.  
  5835. cProto.showContextMenu48 = cProto.showContextMenu;
  5836.  
  5837.  
  5838. cProto.showContextMenu = function (a) {
  5839.  
  5840. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5841. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  5842.  
  5843. const parentComponent = this.parentComponent;
  5844. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  5845. parentComponent.allowScroll = false;
  5846. }
  5847. }
  5848.  
  5849. return this.showContextMenu48.apply(this, arguments);
  5850.  
  5851. }
  5852.  
  5853.  
  5854.  
  5855. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  5856.  
  5857.  
  5858.  
  5859. } else {
  5860.  
  5861. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  5862.  
  5863. }
  5864.  
  5865.  
  5866.  
  5867.  
  5868.  
  5869. if (ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU && typeof cProto.showContextMenu === 'function' && typeof cProto.showContextMenu_ === 'function' && !cProto.showContextMenu47 && !cProto.showContextMenu47_ && cProto.showContextMenu.length === 1 && cProto.showContextMenu_.length === 1) {
  5870.  
  5871. cProto.showContextMenu47_ = cProto.showContextMenu_;
  5872. cProto.showContextMenu47 = cProto.showContextMenu;
  5873.  
  5874. const mutex = new Mutex();
  5875. let __showContextMenu_mutex_unlock__ = null;
  5876. cProto.__showContextMenu_mutex_unlock_isEmpty__ = () => {
  5877. return __showContextMenu_mutex_unlock__ === null;
  5878. }
  5879. cProto.__showContextMenu_assign_lock__ = function (p) {
  5880.  
  5881.  
  5882. mutex.lockWith(unlock => {
  5883. p.then(unlock);
  5884. });
  5885.  
  5886. }
  5887. let lastShowMenuTarget = null;
  5888. cProto.showContextMenu = function (a) {
  5889. lastShowMenuTarget = this;
  5890.  
  5891. if (this.__showContextMenu_sync_mode_request__) {
  5892.  
  5893. return this.showContextMenu47(a);
  5894. } else {
  5895.  
  5896.  
  5897. mutex.lockWith(unlock => {
  5898. if (lastShowMenuTarget !== this) {
  5899. unlock();
  5900. return;
  5901. }
  5902.  
  5903. setTimeout(unlock, 800); // in case network failure
  5904. __showContextMenu_mutex_unlock__ = unlock;
  5905. try {
  5906. this.showContextMenu47(a);
  5907. } catch (e) {
  5908. console.warn(e);
  5909. unlock(); // in case function script error
  5910. }
  5911.  
  5912. });
  5913.  
  5914. }
  5915.  
  5916.  
  5917. }
  5918.  
  5919.  
  5920. cProto.showContextMenu_ = function (a) {
  5921.  
  5922. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  5923. __showContextMenu_mutex_unlock__();
  5924. __showContextMenu_mutex_unlock__ = null;
  5925. }
  5926. return this.showContextMenu47_(a);
  5927.  
  5928. }
  5929.  
  5930. /*
  5931. const wm37 = new WeakMap();
  5932. cProto.__showContextMenu_forceNativeRequest__ = 0;
  5933. cProto.__cacheResolvedEndpointData__ = (endpoint, a, doDeepCopy) => {
  5934. if (a) {
  5935. if (doDeepCopy) a = deepCopy(a);
  5936. wm37.set(endpoint, a);
  5937. } else {
  5938. wm37.remove(endpoint);
  5939. }
  5940. }
  5941. cProto.__showContextMenuNetworkRequestMutex__ = null;
  5942. cProto.__showContextMenuNetworkRequestMutexResolve__ = null;
  5943. cProto.showContextMenu = function (a) {
  5944. if(this.__showContextMenu_forceNativeRequest__){
  5945. return this.showContextMenu37(a);
  5946. }
  5947. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5948. if (!endpoint) {
  5949. return this.showContextMenu37(a);
  5950. }
  5951. this.__showContextMenuNetworkRequestMutex__ = (this.__showContextMenuNetworkRequestMutex__ || Promise.resolve())
  5952. .then(()=>new Promise(lockResolve=>{
  5953.  
  5954. if (endpoint !== (this.data || 0).contextMenuEndpoint || 0){
  5955. lockResolve();
  5956. return;
  5957. }
  5958.  
  5959. if (endpoint) {
  5960. let resolvedEndpoint = wm37.get(endpoint);
  5961. if (resolvedEndpoint) {
  5962. resolvedEndpoint = deepCopy(resolvedEndpoint);
  5963. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  5964. Promise.resolve(resolvedEndpoint).then(() => {
  5965. this.showContextMenu37_(resolvedEndpoint);
  5966. });
  5967. lockResolve();
  5968. return;
  5969. //this.showContextMenu37_(JSON.parse(JSON.stringify(a)));
  5970. //return;
  5971. }
  5972.  
  5973. this.__showContextMenuNetworkRequestMutexResolve__ = new Promise(resolve=>{
  5974. this.__showContextMenuNetworkRequestMutexResolve__ = resolve;
  5975.  
  5976. }).then((a)=>{
  5977.  
  5978. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5979. if (endpoint) {
  5980. const f = this.__cacheResolvedEndpointData__
  5981. if (typeof f === 'function') f(endpoint, a, true);
  5982. }
  5983. this.showContextMenu37_(a);
  5984. lockResolve();
  5985.  
  5986. }).catch(console.warn)
  5987.  
  5988. }else{
  5989.  
  5990. this.__showContextMenuNetworkRequestMutexResolve__ = null;
  5991. this.showContextMenu37(a);
  5992. lockResolve();
  5993. }
  5994.  
  5995.  
  5996.  
  5997.  
  5998. })).catch(console.warn);
  5999. }
  6000.  
  6001. cProto.showContextMenu_ = function (a) {
  6002.  
  6003. let resolve = this.__showContextMenuNetworkRequestMutexResolve__;
  6004. this.__showContextMenuNetworkRequestMutexResolve__= null;
  6005.  
  6006. if (resolve) {
  6007. resolve(a);
  6008. } else {
  6009. return this.showContextMenu37_(a);
  6010. }
  6011.  
  6012. }
  6013. */
  6014.  
  6015.  
  6016.  
  6017.  
  6018. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  6019.  
  6020.  
  6021.  
  6022. } else {
  6023.  
  6024. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  6025.  
  6026. }
  6027.  
  6028.  
  6029.  
  6030.  
  6031. })();
  6032.  
  6033. }
  6034.  
  6035.  
  6036.  
  6037. console.log("[End]");
  6038.  
  6039. console.groupEnd();
  6040.  
  6041. }).catch(console.warn);
  6042.  
  6043.  
  6044.  
  6045. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  6046.  
  6047. mightFirstCheckOnYtInit();
  6048. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  6049. console.log("[Begin]");
  6050. (() => {
  6051.  
  6052. const tag = "tp-yt-iron-dropdown";
  6053. const dummy = document.createElement(tag);
  6054.  
  6055. const cProto = getProto(dummy);
  6056. if (!cProto || !cProto.attached) {
  6057. console.warn(`proto.attached for ${tag} is unavailable.`);
  6058. return;
  6059. }
  6060.  
  6061.  
  6062. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  6063. cProto.__deraf_hn__ = function (sId, fn) {
  6064. const rhKey = `_rafHandler_${sId}`;
  6065. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  6066. if (m.has(fn)) return m.get(fn);
  6067. const resFn = () => {
  6068. this.__rafs[sId] = null;
  6069. fn.call(this)
  6070. };
  6071. m.set(fn, resFn);
  6072. m.set(resFn, resFn);
  6073. return resFn;
  6074. };
  6075. cProto.__deraf34 = cProto.__deraf;
  6076. cProto.__deraf = function (a, b) { // sId, fn
  6077. let c = this.__rafs;
  6078. null !== c[a] && cancelAnimationFrame(c[a]);
  6079. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  6080. };
  6081. console.log("USE_VANILLA_DEREF - OK");
  6082. } else {
  6083. console.log("USE_VANILLA_DEREF - NG");
  6084. }
  6085.  
  6086. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  6087. cProto.__deraf66 = cProto.__deraf;
  6088. cProto.__deraf = function (sId, fn) {
  6089. if (this.__byPassRAF__) {
  6090. Promise.resolve().then(() => {
  6091. fn.call(this);
  6092. });
  6093. }
  6094. let r = this.__deraf66.apply(this, arguments);
  6095. return r;
  6096. }
  6097. console.log("FIX_DROPDOWN_DERAF - OK");
  6098. } else {
  6099. console.log("FIX_DROPDOWN_DERAF - NG");
  6100. }
  6101.  
  6102.  
  6103. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  6104.  
  6105. let lastClose = null;
  6106. let lastOpen = null;
  6107. let cid = 0;
  6108.  
  6109. cProto.__mtChanged__ = function (b) {
  6110.  
  6111. Promise.resolve().then(() => {
  6112. this._applyFocus();
  6113. }).then(() => {
  6114. b ? this._renderOpened() : this._renderClosed();
  6115. }).catch(console.warn);
  6116.  
  6117. };
  6118.  
  6119. const __moChanged__ = () => {
  6120. if (!cid) return;
  6121. // console.log(553, !!lastOpen, !!lastClose);
  6122. cid = 0;
  6123. if (lastOpen && !lastClose && lastOpen.isAttached) {
  6124. lastOpen.__mtChanged__(1)
  6125. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  6126. lastClose.__mtChanged__(0);
  6127. }
  6128. lastOpen = null;
  6129. lastClose = null;
  6130. };
  6131.  
  6132.  
  6133. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  6134. cProto._openedChanged66 = cProto._openedChanged;
  6135. cProto._openedChanged = function () {
  6136. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  6137. this.__byPassRAF__ = true;
  6138. let r = this._openedChanged66.apply(this, arguments);
  6139. this.__byPassRAF__ = false;
  6140. return r;
  6141. }
  6142. }
  6143.  
  6144. const pSetGet = (key, pdThis, pdBase) => {
  6145. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  6146. return {
  6147. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  6148. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  6149. };
  6150. };
  6151.  
  6152. cProto.__modifiedMenuPropsFn__ = function () {
  6153. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  6154. const pdBase = Object.getOwnPropertyDescriptors(this)
  6155.  
  6156. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  6157. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  6158. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  6159.  
  6160. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  6161. console.warn('there is setter/getter for autoFitOnAttach');
  6162. return;
  6163. }
  6164. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  6165. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  6166. return;
  6167. }
  6168. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  6169. console.warn('there is NO setter-getter for allowOutsideScroll');
  6170. return;
  6171. }
  6172.  
  6173. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  6174.  
  6175. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  6176.  
  6177. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  6178.  
  6179. Object.defineProperties(this, {
  6180. autoFitOnAttach: {
  6181. get() {
  6182. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  6183. return autoFitOnAttach;
  6184. },
  6185. set(nv) {
  6186. autoFitOnAttach = nv;
  6187. return true;
  6188. },
  6189. enumerable: true,
  6190. configurable: true
  6191. }, expandSizingTargetForScrollbars: {
  6192. get() {
  6193. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  6194. return expandSizingTargetForScrollbars;
  6195. },
  6196. set(nv) {
  6197. expandSizingTargetForScrollbars = nv;
  6198. return true;
  6199. },
  6200. enumerable: true,
  6201. configurable: true
  6202. }, allowOutsideScroll: {
  6203. get() {
  6204. if (this._modifiedMenuPropOn062__) return true;
  6205. return allowOutsideScroll;
  6206. },
  6207. set(nv) {
  6208. allowOutsideScroll = nv;
  6209. this.__AllowOutsideScrollPD__.set.call(this, nv);
  6210. return true;
  6211. },
  6212. enumerable: true,
  6213. configurable: true
  6214. }
  6215. })
  6216. };
  6217.  
  6218. /*
  6219. // ***** position() to be changed. *****
  6220. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  6221.  
  6222. overflow: visible !important;
  6223. min-width: max-content !important;
  6224. max-width: max-content !important;
  6225. max-height: max-content !important;
  6226. min-height: max-content !important;
  6227. white-space: nowrap;
  6228. }
  6229.  
  6230. */
  6231. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  6232.  
  6233. let m34 = 0;
  6234. cProto.__refitByPosition__ = function () {
  6235. m34++;
  6236. if (m34 <= 0) m34 = 0;
  6237. if (m34 !== 1) return;
  6238. const hostElement = this.hostElement || this;
  6239. if (document.visibilityState === 'visible') {
  6240. const sizingTarget = this.sizingTarget;
  6241. if (!sizingTarget) {
  6242. m34 = 0;
  6243. return;
  6244. }
  6245.  
  6246. let useVisibilityCollapse = true;
  6247. if (HTMLElement.prototype.querySelector.call(sizingTarget, 'yt-icon:empty')) {
  6248. useVisibilityCollapse = false;
  6249. }
  6250.  
  6251. if (useVisibilityCollapse) {
  6252. hostElement.style.visibility = 'collapse';
  6253. sizingTarget.style.visibility = 'collapse';
  6254. } else {
  6255. hostElement.setAttribute('rNgzQ', '');
  6256. sizingTarget.setAttribute('rNgzQ', '');
  6257. }
  6258.  
  6259. const gn = () => {
  6260.  
  6261. if (useVisibilityCollapse) {
  6262. hostElement.style.visibility = '';
  6263. sizingTarget.style.visibility = '';
  6264. } else {
  6265. hostElement.removeAttribute('rNgzQ');
  6266. sizingTarget.removeAttribute('rNgzQ');
  6267. }
  6268. }
  6269.  
  6270. const an = async () => {
  6271. while (m34 >= 1) {
  6272. await renderReadyPn(sizingTarget);
  6273. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  6274. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  6275. }
  6276. m34--;
  6277. }
  6278. m34 = 0;
  6279. Promise.resolve().then(gn);
  6280. }
  6281. setTimeout(an, 4); // wait those resizing function calls
  6282.  
  6283.  
  6284. } else {
  6285. m34 = 0;
  6286. }
  6287. }
  6288. cProto.position34 = cProto.position
  6289. cProto.position = function () {
  6290. if (this._positionInitialize_) {
  6291. this._positionInitialize_ = 0;
  6292. this.__refitByPosition__();
  6293. }
  6294. let r = cProto.position34.apply(this, arguments);
  6295. return r;
  6296. }
  6297. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  6298.  
  6299. } else {
  6300.  
  6301. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  6302.  
  6303. }
  6304.  
  6305.  
  6306.  
  6307. cProto.__openedChanged = function () {
  6308. this._positionInitialize_ = 1;
  6309. // this.removeAttribute('horizontal-align')
  6310. // this.removeAttribute('vertical-align')
  6311. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  6312. this.__menuTypeCheck__ = true;
  6313. if (CHAT_MENU_SCROLL_UNLOCKING) {
  6314. this._modifiedMenuPropOn062__ = false;
  6315. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  6316. // this.autoFitOnAttach = true;
  6317. // this.expandSizingTargetForScrollbars = true;
  6318. // this.allowOutsideScroll = true;
  6319. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  6320. this.__modifiedMenuPropsFn__();
  6321. // this.constrain= function(){}
  6322. // this.position= function(){}
  6323.  
  6324. // this.autoFitOnAttach = true;
  6325. // this.expandSizingTargetForScrollbars = true;
  6326. // this.allowOutsideScroll = true;
  6327. }
  6328. }
  6329. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  6330. let newValue = null;
  6331. const positionTarget = this.positionTarget;
  6332. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  6333. if (this._modifiedMenuPropOn062__ === false) {
  6334. newValue = true;
  6335. }
  6336. } else if (this._modifiedMenuPropOn062__ === true) {
  6337. newValue = false;
  6338. }
  6339. if (newValue !== null) {
  6340. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  6341. this._modifiedMenuPropOn062__ = newValue;
  6342. const afterAllowOutsideScroll = this.allowOutsideScroll;
  6343. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  6344. }
  6345. }
  6346.  
  6347. if (this.opened) {
  6348.  
  6349. Promise.resolve().then(() => {
  6350.  
  6351. this._prepareRenderOpened();
  6352. }).then(() => {
  6353. this._manager.addOverlay(this);
  6354. if (this._manager._overlays.length === 1) {
  6355. lastOpen = this;
  6356. lastClose = null;
  6357. } else {
  6358. return 1;
  6359. }
  6360. // if (cid) {
  6361. // clearTimeout(cid);
  6362. // cid = -1;
  6363. // this.__moChanged__();
  6364. // cid = 0;
  6365. // } else {
  6366. // cid = -1;
  6367. // this.__moChanged__();
  6368. // cid = 0;
  6369. // }
  6370. // cid = cid > 0 ? clearTimeout(cid) : 0;
  6371. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  6372. // cid = cid || setTimeout(__moChanged__, delay1);
  6373. cid = cid || requestAnimationFrame(__moChanged__);
  6374. }).then((r) => {
  6375.  
  6376. if (r) this.__mtChanged__(1);
  6377. }).catch(console.warn);
  6378.  
  6379. } else {
  6380. Promise.resolve().then(() => {
  6381. this._manager.removeOverlay(this);
  6382. if (this._manager._overlays.length === 0) {
  6383. lastClose = this;
  6384. lastOpen = null;
  6385. } else {
  6386. return 1;
  6387. }
  6388. // cid = cid > 0 ? clearTimeout(cid) : 0;
  6389. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  6390. // cid = cid || setTimeout(__moChanged__, delay1);
  6391. cid = cid || requestAnimationFrame(__moChanged__);
  6392. }).then((r) => {
  6393. if (r) this.__mtChanged__(0);
  6394. }).catch(console.warn);
  6395.  
  6396. }
  6397.  
  6398. }
  6399. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  6400.  
  6401. } else {
  6402.  
  6403. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  6404. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  6405.  
  6406. }
  6407.  
  6408.  
  6409. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  6410.  
  6411. cProto.__openedChanged82 = cProto.__openedChanged;
  6412.  
  6413.  
  6414. cProto.__openedChanged = function () {
  6415.  
  6416. // currentMenuPivotWR = null;
  6417. // console.log(1480, '__openedChanged.A', this.positionTarget)
  6418.  
  6419.  
  6420.  
  6421. // if (this.opened && this.positionTarget) {
  6422.  
  6423. // const positionTarget = this.positionTarget;
  6424. // console.log(1480, '__openedChanged.B', positionTarget)
  6425. // currentMenuPivotWR = mWeakRef(positionTarget);
  6426.  
  6427. // }
  6428.  
  6429. const positionTarget = this.positionTarget;
  6430. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  6431. return this.__openedChanged82.apply(this, arguments);
  6432. }
  6433. }
  6434.  
  6435.  
  6436. // if(FIX_MENU_CAPTURE_SCROLL && typeof cProto.__onCaptureScroll === 'function' && !cProto.__onCaptureScroll66){
  6437.  
  6438. // cProto.__onCaptureScroll66 = cProto.__onCaptureScroll;
  6439.  
  6440. // cProto.__onCaptureScroll = function(a){
  6441.  
  6442. // const q = true;
  6443. // if(this.scrollAction === 'lock' && q && this.opened){
  6444.  
  6445. // // console.log(9107, this.scrollAction, this.__isAnimating, this.opened, a); // lock; __isAnimating = false
  6446. // async function af() {
  6447. // this.__isAnimating && this._finishRenderOpened();
  6448. // if (!this.opened) return;
  6449. // this.__restoreScrollPosition();
  6450. // await new Promise(r => requestAnimationFrame(r));
  6451. // if (!this.opened) return;
  6452. // this.opened && this.__isAnimating && this._finishRenderOpened();
  6453. // if (!this.opened) return;
  6454. // this.__restoreScrollPosition();
  6455. // await new Promise(r => requestAnimationFrame(r));
  6456. // if (!this.opened) return;
  6457. // this.opened && this.__isAnimating && this._finishRenderOpened();
  6458. // if (!this.opened) return;
  6459. // this.opened && !this.__isAnimating && this.refit();
  6460. // }
  6461. // Promise.resolve().then(af);
  6462.  
  6463. // return cProto.__onCaptureScroll66.apply(this, arguments);
  6464. // }else{
  6465.  
  6466. // // console.log(9102, this.scrollAction, this.__isAnimating, this.opened, a); // lock
  6467.  
  6468. // return cProto.__onCaptureScroll66.apply(this, arguments);
  6469. // }
  6470. // }
  6471. // console.log("FIX_MENU_CAPTURE_SCROLL - OK");
  6472. // }else{
  6473. // console.log("FIX_MENU_CAPTURE_SCROLL - NG");
  6474.  
  6475. // }
  6476.  
  6477.  
  6478. })();
  6479.  
  6480. console.log("[End]");
  6481.  
  6482. console.groupEnd();
  6483.  
  6484. }).catch(console.warn);
  6485.  
  6486.  
  6487. if (LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY) {
  6488.  
  6489.  
  6490. customElements.whenDefined("yt-live-chat-renderer").then(() => {
  6491.  
  6492. mightFirstCheckOnYtInit();
  6493. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  6494. console.log("[Begin]");
  6495. (() => {
  6496.  
  6497. const tag = "yt-live-chat-renderer"
  6498. const dummy = document.createElement(tag);
  6499.  
  6500. const cProto = getProto(dummy);
  6501. if (!cProto || !cProto.attached) {
  6502. console.warn(`proto.attached for ${tag} is unavailable.`);
  6503. return;
  6504. }
  6505.  
  6506.  
  6507. if (typeof cProto._flushProperties === 'function' && !cProto._flushProperties22 && cProto._flushProperties.length === 0) {
  6508.  
  6509. cProto.flushPendingCount = 0;
  6510. cProto._flushProperties22 = cProto._flushProperties;
  6511.  
  6512. cProto._flushProperties = function () {
  6513. if (foregroundPromiseForLiveChatFlush) return;
  6514. this.flushPendingCount++;
  6515. const tid = this.flushPendingCount;
  6516. getForegroundPromiseForLiveChatFlush().then(() => {
  6517. if (tid !== this.flushPendingCount) return;
  6518. // console.log('_flushProperties22', Date.now())
  6519. this._flushProperties22();
  6520. });
  6521. };
  6522.  
  6523.  
  6524. console.log("cProto._flushProperties - OK");
  6525.  
  6526. } else {
  6527. console.log("cProto._flushProperties - NG");
  6528.  
  6529. }
  6530.  
  6531. })();
  6532.  
  6533. console.log("[End]");
  6534.  
  6535. console.groupEnd();
  6536.  
  6537. }).catch(console.warn);
  6538.  
  6539.  
  6540. }
  6541.  
  6542.  
  6543.  
  6544.  
  6545.  
  6546.  
  6547. /*
  6548.  
  6549.  
  6550.  
  6551.  
  6552.  
  6553. var FU = function() {
  6554. var a = this;
  6555. this.nextHandle_ = 1;
  6556. this.clients_ = {};
  6557. this.JSC$10323_callbacks_ = {};
  6558. this.unsubscribeAsyncHandles_ = {};
  6559. this.subscribe = vl(function(b, c, d) {
  6560. var e = Geb(b);
  6561. if (e in a.clients_)
  6562. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  6563. else {
  6564. a: {
  6565. var h = Geb(b), l;
  6566. for (l in a.unsubscribeAsyncHandles_) {
  6567. var m = a.clients_[l];
  6568. if (m instanceof KO) {
  6569. delete a.clients_[l];
  6570. delete a.JSC$10323_callbacks_[l];
  6571. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  6572. delete a.unsubscribeAsyncHandles_[l];
  6573. i6a(m);
  6574. m.objectId_ = new FQa(h);
  6575. m.register();
  6576. d = m;
  6577. break a
  6578. }
  6579. }
  6580. d.objectSource = b.invalidationId.objectSource;
  6581. d.objectId = h;
  6582. if (b = b.webAuthConfigurationData)
  6583. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  6584. b.pageId && (d.pageId = b.pageId);
  6585. d = new KO(d,a.handleInvalidationData_.bind(a));
  6586. d.register()
  6587. }
  6588. a.clients_[e] = d;
  6589. a.JSC$10323_callbacks_[e] = {}
  6590. }
  6591. d = a.nextHandle_++;
  6592. a.JSC$10323_callbacks_[e][d] = c;
  6593. return d
  6594. })
  6595. };
  6596. FU.prototype.unsubscribe = function(a, b) {
  6597. var c = Geb(a);
  6598. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  6599. !this.JSC$10323_callbacks_[c].length)) {
  6600. var d = this.clients_[c];
  6601. b = Jq.run(function() {
  6602. ei(d);
  6603. delete this.clients_[c];
  6604. delete this.unsubscribeAsyncHandles_[c]
  6605. }
  6606. .bind(this));
  6607. this.unsubscribeAsyncHandles_[c] = b
  6608. }
  6609. }
  6610. ;
  6611.  
  6612.  
  6613. */
  6614.  
  6615.  
  6616.  
  6617.  
  6618. const onManagerFound = (dummyManager) => {
  6619. if (!dummyManager || typeof dummyManager !== 'object') return;
  6620.  
  6621. const mgrProto = dummyManager.constructor.prototype;
  6622.  
  6623. let keyCallbackStore = '';
  6624. for (const [key, v] of Object.entries(dummyManager)) {
  6625. if (key.includes('_callbacks_')) keyCallbackStore = key;
  6626. }
  6627.  
  6628. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  6629.  
  6630. if (mgrProto.unsubscribe16) return;
  6631.  
  6632. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  6633.  
  6634. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  6635. console.log("[Begin]");
  6636.  
  6637.  
  6638. // const isEmptyObject = (a) => Object.keys(a).length === 0;
  6639. const isEmptyObject = (obj) => {
  6640. for (let key in obj) {
  6641. if (obj.hasOwnProperty(key)) return false;
  6642. }
  6643. return true;
  6644. }
  6645.  
  6646. const idMapper = new Map();
  6647.  
  6648. const convertId = function (objectId) {
  6649. if (!objectId || typeof objectId !== 'string') return null;
  6650.  
  6651. let result = idMapper.get(objectId)
  6652. if (result) return result;
  6653. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  6654. idMapper.set(objectId, result)
  6655. return result;
  6656. }
  6657.  
  6658.  
  6659. const rafHandleHolder = [];
  6660.  
  6661. let pzw = 0;
  6662. let lza = 0;
  6663. const genRAF = () => {
  6664.  
  6665. pzw = requestAnimationFrame(() => {
  6666. pzw = 0;
  6667. if (rafHandleHolder.length === 1) {
  6668. const f = rafHandleHolder[0];
  6669. rafHandleHolder.length = 0;
  6670. f();
  6671. } else if (rafHandleHolder.length > 1) {
  6672. let arr = rafHandleHolder.slice(0)
  6673. rafHandleHolder.length = 0;
  6674. for (const fn of arr) fn();
  6675. }
  6676. });
  6677. };
  6678.  
  6679.  
  6680. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  6681.  
  6682. const checkIntegrityForSubscribe = (mgr) => {
  6683. if (mgr
  6684. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  6685. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  6686.  
  6687. const ns = new Set(Object.keys(mgr));
  6688. const ms = new Set(Object.keys(mgr.constructor.prototype));
  6689.  
  6690. if (ns.size >= 6 && ms.size >= 4) {
  6691. // including 'subscribe18'
  6692. // 'unsubscribe16', 'subscribe19'
  6693.  
  6694. let r = 0;
  6695. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  6696. r += ns.has(k) ? 1 : 0;
  6697. }
  6698. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  6699. r += ms.has(k) ? 1 : 0;
  6700. }
  6701. if (r === 10) {
  6702. const isObject = (c) => (c || 0).constructor === Object;
  6703.  
  6704. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  6705.  
  6706. return true;
  6707. }
  6708.  
  6709.  
  6710. }
  6711.  
  6712. }
  6713.  
  6714.  
  6715. }
  6716. return false;
  6717. }
  6718.  
  6719. mgrProto.subscribe19 = function (o, f, opts) {
  6720.  
  6721. const ct_clients_ = this.clients_ || 0;
  6722. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  6723.  
  6724. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  6725.  
  6726. let objectId = ((o || 0).invalidationId || 0).objectId;
  6727. if (!objectId) return this.subscribe18.apply(this, arguments);
  6728. objectId = convertId(objectId);
  6729.  
  6730. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  6731.  
  6732. if (ct_clients_[objectId]) {
  6733. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  6734. }
  6735.  
  6736. return this.subscribe18.apply(this, arguments);
  6737. }
  6738.  
  6739. mgrProto.unsubscribe = function (o, d) {
  6740. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  6741. this.subscribe18 = this.subscribe;
  6742. this.subscribe = this.subscribe19;
  6743. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  6744. }
  6745. const ct_clients_ = this.clients_;
  6746. const ct_handles_ = this.unsubscribeAsyncHandles_;
  6747. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  6748.  
  6749. let objectId = ((o || 0).invalidationId || 0).objectId;
  6750. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  6751.  
  6752. objectId = convertId(objectId);
  6753.  
  6754.  
  6755. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  6756.  
  6757. const callbacks = this[keyCallbackStore] || 0;
  6758. const callbackObj = callbacks[objectId] || 0;
  6759.  
  6760.  
  6761. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  6762. const w = ct_clients_[objectId];
  6763. --lza;
  6764. if (lza < -1e9) lza = -1;
  6765. const qta = lza;
  6766. rafHandleHolder.push(() => {
  6767. if (qta === ct_handles_[objectId]) {
  6768. try {
  6769. w && "function" === typeof w.dispose && w.dispose();
  6770. delete ct_clients_[objectId];
  6771. delete ct_handles_[objectId];
  6772. } catch (e) {
  6773. console.warn(e);
  6774. }
  6775. }
  6776. });
  6777. ct_handles_[objectId] = qta;
  6778. if (pzw === 0) genRAF();
  6779. }
  6780. }
  6781.  
  6782.  
  6783. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  6784.  
  6785. } else {
  6786.  
  6787. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  6788. }
  6789.  
  6790. console.log("[End]");
  6791.  
  6792. console.groupEnd();
  6793.  
  6794. }
  6795.  
  6796.  
  6797.  
  6798. /*
  6799.  
  6800.  
  6801. a.prototype.async = function(e, h) {
  6802. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  6803. }
  6804. ;
  6805. a.prototype.cancelAsync = function(e) {
  6806. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  6807. }
  6808.  
  6809. */
  6810.  
  6811.  
  6812.  
  6813. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  6814.  
  6815. let __dummyManager__ = null;
  6816.  
  6817. mightFirstCheckOnYtInit();
  6818. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  6819. console.log("[Begin]");
  6820. (() => {
  6821.  
  6822. const tag = "yt-invalidation-continuation"
  6823. const dummy = document.createElement(tag);
  6824.  
  6825. const cProto = getProto(dummy);
  6826. if (!cProto || !cProto.attached) {
  6827. console.warn(`proto.attached for ${tag} is unavailable.`);
  6828. return;
  6829. }
  6830.  
  6831. const dummyManager = (dummy.inst || dummy).manager_ || 0;
  6832. __dummyManager__ = dummyManager;
  6833.  
  6834. if (CHANGE_DATA_FLUSH_ASYNC && typeof cProto.async === 'function' && !cProto.async71 && cProto.async.length === 2 && typeof cProto.cancelAsync === 'function' && !cProto.cancelAsync71 && cProto.cancelAsync.length === 1) {
  6835.  
  6836.  
  6837. const rafHub = new RAFHub();
  6838.  
  6839. rafHub.keepRAF = true;
  6840. cProto.async71 = cProto.async;
  6841. cProto.cancelAsync71 = cProto.cancelAsync;
  6842.  
  6843. // mostly for subscription timeoutMs 10000ms
  6844. let mcw = 1; // 1, 3, 5, ...
  6845. let arr = new Map();
  6846.  
  6847. let __asyncInited__ = 0;
  6848. let __timeoutStartId__ = null;
  6849. const __asyncInit__ = () => {
  6850.  
  6851. if (__asyncInited__) return;
  6852. __asyncInited__ = 1;
  6853.  
  6854. __timeoutStartId__ = setTimeout(() => { });
  6855. mcw = __timeoutStartId__ * 2 + 1;
  6856.  
  6857. setInterval(() => {
  6858.  
  6859. if (!arr.length) return;
  6860.  
  6861. const p = Date.now();
  6862. let deleteKeys = [];
  6863. arr.forEach((entry, key) => {
  6864.  
  6865.  
  6866. if (entry.cid === -1) {
  6867. entry.cid = -2;
  6868. } else if (entry.cid === -2) {
  6869.  
  6870. let offset = p - entry.add
  6871. if (offset < 0) offset = 0;
  6872. let delay2 = entry.delay - offset;
  6873. if (delay2 < 0) delay2 = 0;
  6874. entry.cid = setTimeout(entry.q(), delay2);
  6875. entry.q = null;
  6876.  
  6877. } else if (entry.add + entry.delay < p) {
  6878. deleteKeys.push(key);
  6879.  
  6880. }
  6881.  
  6882. })
  6883.  
  6884. for (const key of deleteKeys) arr.delete(key);
  6885.  
  6886. }, 2000)
  6887.  
  6888. }
  6889.  
  6890.  
  6891.  
  6892.  
  6893. cProto.async = function (e, h) {
  6894.  
  6895. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  6896.  
  6897. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  6898.  
  6899. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  6900.  
  6901.  
  6902. if (!this.__asyncInited__) {
  6903. this.__asyncInited__ = 1;
  6904. __asyncInit__();
  6905. }
  6906. mcw += 2; // 2K+3, 2K+4, ...
  6907. if (mcw > 1e9) mcw = mcw % 1e4;
  6908. const cid = mcw;
  6909. const q = () => {
  6910. return () => {
  6911. console.log('async h > 8000');
  6912. e.call(this);
  6913. }
  6914. }
  6915. // setTimeout(q, delay)
  6916. arr.set(cid, {
  6917. cid: -1, // -1 -> -2 -> cid
  6918. add: Date.now(),
  6919. q,
  6920. delay: h
  6921. });
  6922. // console.log('cid-async', cid)
  6923. return cid;
  6924.  
  6925. }
  6926.  
  6927.  
  6928. cProto.cancelAsync = function (e) {
  6929.  
  6930. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  6931.  
  6932. // console.log('cid-unasync', e)
  6933.  
  6934. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  6935.  
  6936. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  6937.  
  6938. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  6939.  
  6940. if (!arr.has(e)) return; // duplciated cancel
  6941.  
  6942. const entry = arr.get(e);
  6943. if (entry.cid < 0) {
  6944. entry.cid = 0;
  6945. arr.delete(e);
  6946. } else {
  6947. clearTimeout(entry.cid); // cid >= 1
  6948. entry.cid = 0;
  6949. arr.delete(e);
  6950. }
  6951.  
  6952. } else {
  6953.  
  6954. return this.cancelAsync71(e);
  6955.  
  6956. }
  6957.  
  6958. }
  6959.  
  6960. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  6961.  
  6962. } else {
  6963. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  6964.  
  6965. }
  6966.  
  6967. })();
  6968.  
  6969. console.log("[End]");
  6970.  
  6971. console.groupEnd();
  6972.  
  6973.  
  6974.  
  6975. onManagerFound(__dummyManager__);
  6976.  
  6977. }).catch(console.warn);
  6978.  
  6979.  
  6980.  
  6981.  
  6982. if (DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION) {
  6983.  
  6984.  
  6985.  
  6986. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  6987.  
  6988.  
  6989. mightFirstCheckOnYtInit();
  6990. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  6991. console.log("[Begin]");
  6992. (() => {
  6993.  
  6994. const tag = "yt-live-interactivity-component-background"
  6995. const dummy = document.createElement(tag);
  6996.  
  6997. const cProto = getProto(dummy);
  6998. if (!cProto || !cProto.attached) {
  6999. console.warn(`proto.attached for ${tag} is unavailable.`);
  7000. return;
  7001. }
  7002.  
  7003.  
  7004. if (DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  7005.  
  7006. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  7007. cProto.maybeLoadAnimationBackground = function () {
  7008. if (this.useAnimationBackground === true) this.useAnimationBackground = false;
  7009. }
  7010.  
  7011. console.log("DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION - OK");
  7012.  
  7013. } else {
  7014. console.log("DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION - NG");
  7015.  
  7016. }
  7017.  
  7018. })();
  7019.  
  7020. console.log("[End]");
  7021.  
  7022. console.groupEnd();
  7023.  
  7024.  
  7025. }).catch(console.warn);
  7026.  
  7027. }
  7028.  
  7029.  
  7030. }
  7031.  
  7032.  
  7033.  
  7034.  
  7035. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  7036.  
  7037. const fixJsonParse = () => {
  7038.  
  7039.  
  7040.  
  7041. if (jsonParseFix && typeof JSON.parse === 'function' && !JSON.parse68) {
  7042.  
  7043. let { _parse, _JSON } = jsonParseFix;
  7044.  
  7045.  
  7046. let error = 0;
  7047. try {
  7048. _parse.apply(JSON, ["{}"])
  7049. _JSON = JSON;
  7050. } catch (e) {
  7051. error = 1;
  7052. }
  7053. if (error === 1) {
  7054.  
  7055. try {
  7056. _parse.apply(_JSON, ["{}"])
  7057. } catch (e) {
  7058. error = 2;
  7059. }
  7060. if (error === 2) {
  7061. return;
  7062. }
  7063. }
  7064.  
  7065.  
  7066. JSON.parse68 = JSON.parse;
  7067.  
  7068. JSON.parse = function parse(a, b) {
  7069. const stack = (new Error()).stack;
  7070. if (stack.includes('.readyStateChangeHandler_')) return _parse.apply(_JSON, arguments);
  7071. return this.parse68(...arguments);
  7072. };
  7073.  
  7074. JSON.parse.toString = function () {
  7075. return JSON.parse68.toString();
  7076. };
  7077.  
  7078. jsonParseFix = null;
  7079.  
  7080. }
  7081.  
  7082. }
  7083.  
  7084. if (DE_JSONPRUNE_FOR_readyStateChangeHandler_) {
  7085. promiseForCustomYtElementsReady.then(fixJsonParse);
  7086. fixJsonParse();
  7087. }
  7088.  
  7089. });
  7090.  
  7091.  
  7092.  
  7093. })({ IntersectionObserver });