YouTube 超快聊天

YouTube直播聊天的終極性能提升

目前為 2023-08-26 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.51.1
  4. // @license MIT
  5. // @name:ja YouTube スーパーファーストチャット
  6. // @name:zh-TW YouTube 超快聊天
  7. // @name:zh-CN YouTube 超快聊天
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/super-fast-chat.png
  9. // @namespace UserScript
  10. // @match https://www.youtube.com/live_chat*
  11. // @match https://www.youtube.com/live_chat_replay*
  12. // @author CY Fung
  13. // @run-at document-start
  14. // @grant none
  15. // @unwrap
  16. // @allFrames true
  17. // @inject-into page
  18. //
  19. // @compatible firefox Violentmonkey
  20. // @compatible firefox Tampermonkey
  21. // @compatible firefox FireMonkey
  22. // @compatible chrome Violentmonkey
  23. // @compatible chrome Tampermonkey
  24. // @compatible opera Violentmonkey
  25. // @compatible opera Tampermonkey
  26. // @compatible safari Stay
  27. // @compatible edge Violentmonkey
  28. // @compatible edge Tampermonkey
  29. // @compatible brave Violentmonkey
  30. // @compatible brave Tampermonkey
  31. //
  32. // @description Ultimate Performance Boost for YouTube Live Chats
  33. // @description:ja YouTubeのライブチャットの究極のパフォーマンスブースト
  34. // @description:zh-TW YouTube直播聊天的終極性能提升
  35. // @description:zh-CN YouTube直播聊天的终极性能提升
  36. //
  37. // ==/UserScript==
  38.  
  39. ((__CONTEXT__) => {
  40. 'use strict';
  41.  
  42. const ENABLE_REDUCED_MAXITEMS_FOR_FLUSH = true; // TRUE to enable trimming down to MAX_ITEMS_FOR_FULL_FLUSH (25) messages when there are too many unrendered messages
  43. const MAX_ITEMS_FOR_TOTAL_DISPLAY = 90; // By default, 250 latest messages will be displayed, but displaying MAX_ITEMS_FOR_TOTAL_DISPLAY (90) messages is already sufficient.
  44. const MAX_ITEMS_FOR_FULL_FLUSH = 25; // If there are too many new (stacked) messages not yet rendered, clean all and flush MAX_ITEMS_FOR_FULL_FLUSH (25) latest messages then incrementally added back to MAX_ITEMS_FOR_TOTAL_DISPLAY (90) messages
  45.  
  46. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages
  47. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  48. const USE_WILL_CHANGE_CONTROLLER = false; // FALSE for the majority
  49. const ENABLE_DELAYED_CHAT_OCCURRENCE_PREFERRED = true; // In Chrome, the rendering of new chat messages could be too fast for no smooth transform. 80ms delay of displaying new messages should be sufficient for element rendering.
  50. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  51.  
  52. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  53. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  54. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  55. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  56.  
  57. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  58. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  59.  
  60. // Replace requestAnimationFrame timers with custom implementation
  61. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  62. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  63. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  64. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  65.  
  66. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  67. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  68.  
  69. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  70. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  71.  
  72. // Data Manipulation for Participants (Participant List)
  73. // << 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 !== 'yt-live-chat-ticker-renderer') {
  4680. if (is.startsWith('yt-live-chat-ticker-')) return;
  4681. if (!is.endsWith('-renderer')) return;
  4682. }
  4683.  
  4684. } else {
  4685. if ((p.nodeName || '').includes('BUTTON')) return;
  4686. }
  4687.  
  4688. }
  4689. };
  4690.  
  4691. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  4692.  
  4693. } else {
  4694. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  4695. }
  4696.  
  4697.  
  4698. })();
  4699.  
  4700. console.log("[End]");
  4701.  
  4702. console.groupEnd();
  4703.  
  4704. }).catch(console.warn);
  4705.  
  4706.  
  4707. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  4708.  
  4709.  
  4710. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  4711.  
  4712. mightFirstCheckOnYtInit();
  4713. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  4714. console.log("[Begin]");
  4715. (() => {
  4716.  
  4717. const tag = "yt-live-chat-message-input-renderer"
  4718. const dummy = document.createElement(tag);
  4719.  
  4720. const cProto = getProto(dummy);
  4721. if (!cProto || !cProto.attached) {
  4722. console.warn(`proto.attached for ${tag} is unavailable.`);
  4723. return;
  4724. }
  4725.  
  4726. let doHack = false;
  4727. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  4728.  
  4729. // not cancellable
  4730.  
  4731.  
  4732. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  4733.  
  4734. }
  4735.  
  4736. if (doHack) {
  4737.  
  4738. cProto.handleTimeout = function (a) {
  4739. console.log('cProto.handleTimeout', tag)
  4740. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  4741. this.timeoutDurationMs = this.timeoutMs = a;
  4742. this.countdownRatio = 1;
  4743. 0 === this.lastTimeoutTimeMs && rafHub.request(this.boundUpdateTimeout38_)
  4744. };
  4745. cProto.updateTimeout = function (a) {
  4746. console.log('cProto.updateTimeout', tag)
  4747. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  4748. this.lastTimeoutTimeMs && (this.timeoutMs = Math.max(0, this.timeoutMs - (a - this.lastTimeoutTimeMs)),
  4749. this.countdownRatio = this.timeoutMs / this.timeoutDurationMs);
  4750. this.isAttached && this.timeoutMs ? (this.lastTimeoutTimeMs = a,
  4751. rafHub.request(this.boundUpdateTimeout38_)) : this.lastTimeoutTimeMs = 0
  4752. };
  4753.  
  4754. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  4755. } else {
  4756.  
  4757. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  4758. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  4759.  
  4760. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  4761. }
  4762.  
  4763. })();
  4764.  
  4765. console.log("[End]");
  4766.  
  4767. console.groupEnd();
  4768.  
  4769.  
  4770. })
  4771.  
  4772.  
  4773. }
  4774.  
  4775. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  4776.  
  4777.  
  4778. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  4779.  
  4780. mightFirstCheckOnYtInit();
  4781. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  4782. console.log("[Begin]");
  4783. (() => {
  4784.  
  4785. const tag = "yt-emoji-picker-renderer"
  4786. const dummy = document.createElement(tag);
  4787.  
  4788. const cProto = getProto(dummy);
  4789. if (!cProto || !cProto.attached) {
  4790. console.warn(`proto.attached for ${tag} is unavailable.`);
  4791. return;
  4792. }
  4793.  
  4794. let doHack = false;
  4795. if (typeof cProto.animateScroll_ === 'function') {
  4796.  
  4797. // not cancellable
  4798. console.log('animateScroll_', typeof cProto.animateScroll_)
  4799.  
  4800. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  4801.  
  4802. }
  4803.  
  4804. if (doHack) {
  4805.  
  4806. const querySelector = HTMLElement.prototype.querySelector;
  4807. const U = (element) => ({
  4808. querySelector: (selector) => querySelector.call(element, selector)
  4809. });
  4810.  
  4811. cProto.animateScroll_ = function (a) {
  4812. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  4813. if (!this.boundAnimateScroll39_) this.boundAnimateScroll39_ = this.animateScroll_.bind(this);
  4814. this.lastAnimationTime_ || (this.lastAnimationTime_ = a);
  4815. a -= this.lastAnimationTime_;
  4816. 200 > a ? (U(this.hostElement).querySelector("#categories").scrollTop = this.animationStart_ + (this.animationEnd_ - this.animationStart_) * a / 200,
  4817. rafHub.request(this.boundAnimateScroll39_)) : (null != this.animationEnd_ && (U(this.hostElement).querySelector("#categories").scrollTop = this.animationEnd_),
  4818. this.animationEnd_ = this.animationStart_ = null,
  4819. this.lastAnimationTime_ = 0);
  4820. this.updateButtons_()
  4821. }
  4822.  
  4823. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  4824. } else {
  4825.  
  4826. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  4827. }
  4828.  
  4829. })();
  4830.  
  4831. console.log("[End]");
  4832.  
  4833. console.groupEnd();
  4834. });
  4835. }
  4836.  
  4837. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  4838.  
  4839.  
  4840. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  4841.  
  4842. mightFirstCheckOnYtInit();
  4843. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  4844. console.log("[Begin]");
  4845. (() => {
  4846.  
  4847. const tag = "yt-live-chat-docked-message"
  4848. const dummy = document.createElement(tag);
  4849.  
  4850. const cProto = getProto(dummy);
  4851. if (!cProto || !cProto.attached) {
  4852. console.warn(`proto.attached for ${tag} is unavailable.`);
  4853. return;
  4854. }
  4855.  
  4856. let doHack = false;
  4857. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  4858.  
  4859. // cancelable - this.intersectRAF <detached>
  4860. // yt-live-chat-docked-message
  4861. // boundCheckIntersections <-> checkIntersections
  4862. // onDockableMessagesChanged
  4863. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  4864.  
  4865. console.log('detached', typeof cProto.detached)
  4866. console.log('checkIntersections', typeof cProto.checkIntersections)
  4867. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  4868.  
  4869. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  4870.  
  4871. }
  4872.  
  4873. if (doHack) {
  4874.  
  4875. cProto.checkIntersections = function () {
  4876. // console.log('cProto.checkIntersections', tag)
  4877. if (this.dockableMessages.length) {
  4878. this.intersectRAF = rafHub.request(this.boundCheckIntersections);
  4879. let a = this.dockableMessages[0]
  4880. , b = this.hostElement.getBoundingClientRect();
  4881. a = a.getBoundingClientRect();
  4882. let c = a.top - b.top
  4883. , d = 8 >= c;
  4884. c = 8 >= c - this.hostElement.clientHeight;
  4885. if (d) {
  4886. let e;
  4887. for (; d;) {
  4888. e = this.dockableMessages.shift();
  4889. d = this.dockableMessages[0];
  4890. if (!d)
  4891. break;
  4892. d = d.getBoundingClientRect();
  4893. c = d.top - b.top;
  4894. let f = 8 >= c;
  4895. if (8 >= c - a.height)
  4896. if (f)
  4897. a = d;
  4898. else
  4899. return;
  4900. d = f
  4901. }
  4902. this.dock(e)
  4903. } else
  4904. c && this.dockedItem && this.clear()
  4905. } else
  4906. this.intersectRAF = 0
  4907. }
  4908.  
  4909. cProto.onDockableMessagesChanged = function () {
  4910. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  4911. this.dockableMessages.length && !this.intersectRAF && (this.intersectRAF = rafHub.request(this.boundCheckIntersections))
  4912. }
  4913.  
  4914. cProto.detached = function () {
  4915. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  4916. }
  4917.  
  4918. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  4919. } else {
  4920.  
  4921. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  4922. }
  4923.  
  4924. })();
  4925.  
  4926. console.log("[End]");
  4927.  
  4928. console.groupEnd();
  4929.  
  4930. }).catch(console.warn);
  4931.  
  4932. }
  4933.  
  4934. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  4935.  
  4936.  
  4937. customElements.whenDefined("yt-img-shadow").then(() => {
  4938.  
  4939. mightFirstCheckOnYtInit();
  4940. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  4941. console.log("[Begin]");
  4942. (() => {
  4943.  
  4944. const tag = "yt-img-shadow"
  4945. const dummy = document.createElement(tag);
  4946.  
  4947. const cProto = getProto(dummy);
  4948. if (!cProto || !cProto.attached) {
  4949. console.warn(`proto.attached for ${tag} is unavailable.`);
  4950. return;
  4951. }
  4952.  
  4953. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  4954.  
  4955. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  4956. cProto.thumbnailChanged_ = function (a) {
  4957.  
  4958. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  4959. if (!this.oldThumbnail_ && !this.thumbnail) return;
  4960.  
  4961. return this.thumbnailChanged66_.apply(this, arguments)
  4962.  
  4963. }
  4964. console.log("cProto.thumbnailChanged_ - OK");
  4965.  
  4966. } else {
  4967. console.log("cProto.thumbnailChanged_ - NG");
  4968.  
  4969. }
  4970. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  4971.  
  4972. cProto.setSrc66_ = cProto.setSrc_;
  4973. cProto.setSrc_ = function (a) {
  4974. if ((((this || 0).$ || 0).img || 0).src === a) return;
  4975. return this.setSrc66_.apply(this, arguments)
  4976. }
  4977.  
  4978. console.log("cProto.setSrc_ - OK");
  4979. } else {
  4980.  
  4981. console.log("cProto.setSrc_ - NG");
  4982. }
  4983.  
  4984. })();
  4985.  
  4986. console.log("[End]");
  4987.  
  4988. console.groupEnd();
  4989.  
  4990. }).catch(console.warn);
  4991.  
  4992. }
  4993.  
  4994. if (FIX_THUMBNAIL_DATACHANGED) {
  4995.  
  4996.  
  4997.  
  4998. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  4999.  
  5000. mightFirstCheckOnYtInit();
  5001. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  5002. console.log("[Begin]");
  5003. (() => {
  5004.  
  5005. const tag = "yt-live-chat-author-badge-renderer"
  5006. const dummy = document.createElement(tag);
  5007.  
  5008. const cProto = getProto(dummy);
  5009. if (!cProto || !cProto.attached) {
  5010. console.warn(`proto.attached for ${tag} is unavailable.`);
  5011. return;
  5012. }
  5013.  
  5014.  
  5015. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && fnIntegrity(cProto.dataChanged) === '1.159.97') {
  5016.  
  5017.  
  5018.  
  5019. cProto.dataChanged86 = cProto.dataChanged;
  5020. cProto.dataChanged = function (a) {
  5021.  
  5022. /*
  5023.  
  5024. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  5025. b.removeChild(b.firstChild);
  5026. if (a)
  5027. if (a.icon) {
  5028. var c = document.createElement("yt-icon");
  5029. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  5030. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  5031. b.appendChild(c)
  5032. } else if (a.customThumbnail) {
  5033. c = document.createElement("img");
  5034. var d;
  5035. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  5036. b.appendChild(c),
  5037. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  5038. }
  5039.  
  5040. */
  5041.  
  5042. const image = ((this || 0).$ || 0).image
  5043. if (image && a && image.firstElementChild) {
  5044. let exisiting = image.firstElementChild;
  5045. if (exisiting === image.lastElementChild) {
  5046.  
  5047.  
  5048. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  5049.  
  5050. let c = exisiting;
  5051. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  5052. if (c.icon !== "yt-sys-icons:shield-filled") c.icon = "yt-sys-icons:shield-filled";
  5053. if (c.defaultToFilled !== true) c.defaultToFilled = true;
  5054. } else {
  5055. let p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  5056. if (c.icon !== p) c.icon = p;
  5057. if (c.defaultToFilled !== false) c.defaultToFilled = false;
  5058. }
  5059. return;
  5060.  
  5061.  
  5062. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  5063.  
  5064. let c = exisiting;
  5065. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  5066.  
  5067. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  5068. return;
  5069. }
  5070. /*
  5071.  
  5072. var d;
  5073. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  5074.  
  5075.  
  5076. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  5077. */
  5078. }
  5079.  
  5080.  
  5081. }
  5082. }
  5083. return this.dataChanged86.apply(this, arguments)
  5084.  
  5085. }
  5086. console.log("cProto.dataChanged - OK");
  5087.  
  5088. } else {
  5089. assertor(() => fnIntegrity(cProto.dataChanged, '1.159.97'));
  5090. console.log("cProto.dataChanged - NG");
  5091.  
  5092. }
  5093.  
  5094. })();
  5095.  
  5096. console.log("[End]");
  5097.  
  5098. console.groupEnd();
  5099.  
  5100. }).catch(console.warn);
  5101.  
  5102.  
  5103. }
  5104.  
  5105.  
  5106. if (FIX_TOOLTIP_DISPLAY) {
  5107.  
  5108.  
  5109. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  5110.  
  5111. mightFirstCheckOnYtInit();
  5112. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  5113. console.log("[Begin]");
  5114. (() => {
  5115.  
  5116. const tag = "tp-yt-paper-tooltip"
  5117. const dummy = document.createElement(tag);
  5118.  
  5119. const cProto = getProto(dummy);
  5120. if (!cProto || !cProto.attached) {
  5121. console.warn(`proto.attached for ${tag} is unavailable.`);
  5122. return;
  5123. }
  5124.  
  5125. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  5126.  
  5127. cProto._readyClients43 = cProto._readyClients;
  5128. cProto._readyClients = function () {
  5129. let r = cProto._readyClients43.apply(this, arguments);
  5130. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  5131. return r;
  5132. }
  5133.  
  5134. console.log("_readyClients - OK");
  5135.  
  5136. } else {
  5137. console.log("_readyClients - NG");
  5138.  
  5139. }
  5140.  
  5141.  
  5142. })();
  5143.  
  5144. console.log("[End]");
  5145.  
  5146. console.groupEnd();
  5147.  
  5148. }).catch(console.warn);
  5149.  
  5150.  
  5151.  
  5152. }
  5153.  
  5154.  
  5155.  
  5156. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  5157.  
  5158.  
  5159. const hookDocumentMouseDownSetupFn = () => {
  5160.  
  5161.  
  5162.  
  5163. let muzTimestamp = 0;
  5164. let nszDropdown = null;
  5165.  
  5166.  
  5167.  
  5168. const handlerObject = {
  5169.  
  5170. // mdHandler282 : function (evt) {
  5171. // // console.log(evt, 1, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5172. // if (!evt || !evt.isTrusted) return;
  5173. // muzTimestamp = 0;
  5174. // nszDropdown = null;
  5175.  
  5176. // const hostElement = this.hostElement || this;
  5177. // if (!evt || !evt.isTrusted || !hostElement.hasAttribute('menu-visible')) return;
  5178. // if (!hostElement.contains(evt.target)) return;
  5179. // let targetDropDown = null;
  5180. // for(const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')){
  5181. // if(dropdown && dropdown.positionTarget && hostElement.contains( dropdown.positionTarget)){
  5182. // targetDropDown = dropdown;
  5183. // }
  5184. // }
  5185. // if ((nszDropdown = targetDropDown)) {
  5186. // muzTimestamp = Date.now();
  5187. // evt.stopImmediatePropagation();
  5188. // evt.stopPropagation();
  5189. // }
  5190.  
  5191. // },
  5192.  
  5193.  
  5194. muHandler282: function (evt) {
  5195. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5196. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5197. const dropdown = nszDropdown;
  5198. muzTimestamp = 0;
  5199. nszDropdown = null;
  5200.  
  5201. const kurMPC = kRef(currentMenuPivotWR) || 0;
  5202. const hostElement = kurMPC.hostElement || kurMPC;
  5203. if (!hostElement.hasAttribute('menu-visible')) return;
  5204. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  5205. muzTimestamp = Date.now();
  5206. evt.stopImmediatePropagation();
  5207. evt.stopPropagation();
  5208. Promise.resolve(dropdown).then((dropdown) => {
  5209. dropdown.cancel();
  5210. });
  5211. // document.body.click();
  5212. }
  5213.  
  5214. },
  5215.  
  5216. mlHandler282: function (evt) {
  5217. muzTimestamp = 0;
  5218. nszDropdown = null;
  5219. },
  5220.  
  5221. ckHandler282: function (evt) {
  5222. // console.log(evt, 3, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5223.  
  5224. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5225. if (Date.now() - muzTimestamp < 40) {
  5226. muzTimestamp = Date.now();
  5227. evt.stopImmediatePropagation();
  5228. evt.stopPropagation();
  5229. }
  5230.  
  5231. },
  5232.  
  5233. tapHandler282: function (evt) {
  5234. // console.log(evt, 2, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  5235.  
  5236. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  5237. if (Date.now() - muzTimestamp < 40) {
  5238. muzTimestamp = Date.now();
  5239. evt.stopImmediatePropagation();
  5240. evt.stopPropagation();
  5241. }
  5242.  
  5243. },
  5244.  
  5245.  
  5246. handleEvent(evt) {
  5247.  
  5248.  
  5249. if (evt) {
  5250. const kurMPC = kRef(currentMenuPivotWR) || 0;
  5251. const cnt = kurMPC.inst || kurMPC;
  5252. const hostElement = cnt.hostElement || cnt;
  5253. if (!cnt || cnt.isAttached !== true || hostElement.isConnected !== true) return;
  5254. switch (evt.type) {
  5255. // case 'mousedown':
  5256. // return this.mdHandler282.call(kurMPC, evt);
  5257. case 'mouseup':
  5258. return this.muHandler282(evt);
  5259. case 'mouseleave':
  5260. return this.mlHandler282(evt);
  5261. case 'tap':
  5262. return this.tapHandler282(evt);
  5263. case 'click':
  5264. return this.ckHandler282(evt);
  5265. }
  5266. }
  5267.  
  5268. }
  5269.  
  5270.  
  5271.  
  5272. }
  5273.  
  5274. document.addEventListener('mousedown', function (evt) {
  5275.  
  5276. if (!evt || !evt.isTrusted || !evt.target) return;
  5277. muzTimestamp = 0;
  5278. nszDropdown = null;
  5279.  
  5280. /** @type {HTMLElement | null} */
  5281. const kurMP = kRef(currentMenuPivotWR);
  5282. if (!kurMP) return;
  5283. const kurMPC = kurMP.closest('[menu-visible]') || 0;
  5284.  
  5285. if (!kurMPC.isClickableChatRow111 || !kurMPC.isClickableChatRow111() || !kurMPC.contains(evt.target)) return;
  5286.  
  5287. let targetDropDown = null;
  5288. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  5289. if (dropdown && dropdown.positionTarget === kurMP) {
  5290. targetDropDown = dropdown;
  5291. }
  5292. }
  5293.  
  5294. if ((nszDropdown = targetDropDown)) {
  5295. muzTimestamp = Date.now();
  5296. evt.stopImmediatePropagation();
  5297. evt.stopPropagation();
  5298. currentMenuPivotWR = mWeakRef(kurMPC);
  5299.  
  5300. const listenOpts = { capture: true, passive: false, once: true };
  5301.  
  5302. // remove unexcecuted eventHandler
  5303. document.removeEventListener('mouseup', handlerObject, listenOpts);
  5304. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  5305. document.removeEventListener('tap', handlerObject, listenOpts);
  5306. document.removeEventListener('click', handlerObject, listenOpts);
  5307.  
  5308. // inject one time eventHandler to by pass events
  5309. document.addEventListener('mouseup', handlerObject, listenOpts);
  5310. document.addEventListener('mouseleave', handlerObject, listenOpts);
  5311. document.addEventListener('tap', handlerObject, listenOpts);
  5312. document.addEventListener('click', handlerObject, listenOpts);
  5313.  
  5314. }
  5315.  
  5316. }, true);
  5317.  
  5318. }
  5319.  
  5320.  
  5321. customElements.whenDefined('yt-live-chat-text-message-renderer').then(() => {
  5322.  
  5323.  
  5324. mightFirstCheckOnYtInit();
  5325. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-message-renderer hacks");
  5326. console.log("[Begin]");
  5327. (() => {
  5328.  
  5329. const tag = "yt-live-chat-text-message-renderer"
  5330. const dummy = document.createElement(tag);
  5331.  
  5332. const cProto = getProto(dummy);
  5333. if (!cProto || !cProto.attached) {
  5334. console.warn(`proto.attached for ${tag} is unavailable.`);
  5335. return;
  5336. }
  5337.  
  5338. /*
  5339.  
  5340.  
  5341.  
  5342. remarks:
  5343.  
  5344. const w=new Set();
  5345. setInterval(()=>{
  5346. for(const a of document.getElementsByTagName('*')) if(a.shouldSupportWholeItemClick) w.add(a.is||'');
  5347. console.log([...w.keys()]);
  5348. },800);
  5349.  
  5350.  
  5351. [
  5352. "yt-live-chat-ticker-sponsor-item-renderer",
  5353. "yt-live-chat-banner-header-renderer",
  5354. "yt-live-chat-text-message-renderer",
  5355. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  5356. "ytd-sponsorships-live-chat-header-renderer",
  5357. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer"
  5358. ]
  5359.  
  5360. */
  5361.  
  5362. cProto.isClickableChatRow111 = function () {
  5363. return (
  5364. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  5365. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  5366. ); // follow .onItemTap(a)
  5367. }
  5368.  
  5369.  
  5370.  
  5371. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  5372.  
  5373. if (toHookDocumentMouseDown) {
  5374.  
  5375. hookDocumentMouseDownSetupFn();
  5376.  
  5377.  
  5378. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  5379.  
  5380.  
  5381.  
  5382. } else {
  5383.  
  5384. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent NG");
  5385.  
  5386. }
  5387.  
  5388.  
  5389.  
  5390.  
  5391. })();
  5392.  
  5393. console.log("[End]");
  5394.  
  5395. console.groupEnd();
  5396.  
  5397. }).catch(console.warn);
  5398.  
  5399.  
  5400. }
  5401.  
  5402.  
  5403. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  5404.  
  5405. document.addEventListener('mousedown', function (evt) {
  5406.  
  5407. const maxloopDOMTreeElements = 4;
  5408. const maxloopYtCompontents = 4;
  5409. let j1 = 0;
  5410. let j2 = 0;
  5411. let target = (evt || 0).target || 0;
  5412. if (!target) return;
  5413.  
  5414.  
  5415. while (target instanceof HTMLElement) {
  5416. if (++j1 > maxloopDOMTreeElements) break;
  5417. if (typeof (target.is || (target.inst || 0).is || null) === 'string') break;
  5418. target = nodeParent(target);
  5419. }
  5420. const components = [];
  5421. while (target instanceof HTMLElement) {
  5422. if (++j2 > maxloopYtCompontents) break;
  5423. if (typeof (target.is || (target.inst || 0).is || null) === 'string') {
  5424. components.push(target);
  5425. }
  5426. if (typeof (target.inst || target).showContextMenu === 'function') break;
  5427. target = target.parentComponent || (target.inst || 0).parentComponent || null;
  5428. }
  5429. if (!(target instanceof HTMLElement)) return;
  5430. const targetCnt = target.inst || target;
  5431. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  5432. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  5433. return;
  5434. }
  5435.  
  5436. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  5437. if (!endpoint) return;
  5438. if (targetCnt.opened || !targetCnt.isAttached) return;
  5439.  
  5440. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  5441. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  5442. }
  5443.  
  5444. let doPreRequest = false;
  5445. if (components.length >= 2 && components[0].id === 'menu-button' && (target.$ || 0)['menu-button'] === components[0]) {
  5446. doPreRequest = true;
  5447. } else if (components.length === 1 && components[0] === target) {
  5448. doPreRequest = true;
  5449. } else if (components.length >= 2 && components[0].id === 'author-photo' && (target.$ || 0)['author-photo'] === components[0]) {
  5450. doPreRequest = true;
  5451. }
  5452. if (doPreRequest === false) {
  5453. console.log('doPreRequest = fasle on showContextMenu', components);
  5454. return;
  5455. }
  5456.  
  5457. if (targetCnt.__getCachedEndpointData__(endpoint)) return;
  5458.  
  5459. if (!targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  5460. console.log('preRequest on showContextMenu aborted due to stacked network request');
  5461. return;
  5462. }
  5463.  
  5464.  
  5465. const onSuccess = (a) => {
  5466. /*
  5467.  
  5468. dQ() && (a = a.response);
  5469. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  5470. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  5471.  
  5472. */
  5473.  
  5474. a = a.response || a;
  5475.  
  5476. if (!a) {
  5477. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  5478. return;
  5479. }
  5480.  
  5481. let z = null;
  5482. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  5483.  
  5484. if (z) {
  5485. a = z;
  5486. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  5487. }
  5488.  
  5489. };
  5490. const onFailure = (a) => {
  5491.  
  5492. /*
  5493.  
  5494. if (a instanceof Error || a instanceof Object || a instanceof String)
  5495. var b = a;
  5496. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  5497.  
  5498. */
  5499.  
  5500. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  5501. // console.log('onFailure', a)
  5502.  
  5503. };
  5504.  
  5505. if (doPreRequest) {
  5506.  
  5507. let propertyCounter = 0;
  5508. let p1unlock = null;
  5509. const p1 = new Promise(r => {
  5510. p1unlock = r;
  5511. });
  5512. const p1Timeout = 800;
  5513. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  5514.  
  5515. try {
  5516.  
  5517. const onSuccessHelperFn = function () {
  5518. p1unlock && p1unlock();
  5519. p1unlock = null;
  5520. if (propertyCounter !== 5) {
  5521. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  5522. return;
  5523. }
  5524. if (this[proxyKey] !== targetCnt) {
  5525. console.log('Error in prerequest for showContextMenu.this');
  5526. return;
  5527. }
  5528. onSuccess(...arguments);
  5529. };
  5530. const onFailureHelperFn = function () {
  5531. p1unlock && p1unlock();
  5532. p1unlock = null;
  5533. if (propertyCounter !== 5) {
  5534. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  5535. return;
  5536. }
  5537. if (this[proxyKey] !== targetCnt) {
  5538. console.log('Error in prerequest for showContextMenu.this');
  5539. return;
  5540. }
  5541. onFailure(...arguments);
  5542.  
  5543. }
  5544. const fakeTargetCnt = new Proxy({
  5545. __showContextMenu_forceNativeRequest__: 1,
  5546. __showContextMenu_sync_mode_request__: 1,
  5547. get handleGetContextMenuResponse_() {
  5548. propertyCounter += 2;
  5549. return onSuccessHelperFn;
  5550. },
  5551. get handleGetContextMenuError() {
  5552. propertyCounter += 3;
  5553. return onFailureHelperFn;
  5554. }
  5555. }, {
  5556. get(_, key, receiver) {
  5557. if (key in _) return _[key];
  5558. if (key === proxyKey) return targetCnt;
  5559.  
  5560. let giveNative = false;
  5561. if (key in targetCnt) {
  5562. if (key === 'data') giveNative = true;
  5563. else if (typeof targetCnt[key] === 'function') giveNative = true;
  5564. }
  5565. if (giveNative) return targetCnt[key];
  5566. }
  5567. });
  5568.  
  5569. const fakeEvent = (() => {
  5570. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  5571. const nf = function () { }
  5572. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  5573.  
  5574. return {
  5575. type: 'tap',
  5576. eventPhase: 0,
  5577. isTrusted: false,
  5578. __composed: true,
  5579. bubbles, cancelable, cancelBubble, timeStamp,
  5580. target, srcElement, defaultPrevented, currentTarget, composed,
  5581. stopPropagation, stopImmediatePropagation, preventDefault
  5582. };
  5583. })(evt);
  5584. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  5585.  
  5586.  
  5587. } catch (e) {
  5588. console.warn(e);
  5589. propertyCounter = 7;
  5590.  
  5591. }
  5592. if (propertyCounter !== 5) {
  5593. console.log('Error in prerequest for showContextMenu', propertyCounter);
  5594. return;
  5595. }
  5596. targetCnt.__showContextMenu_assign_lock__(p1);
  5597. setTimeout(() => {
  5598. p1unlock && p1unlock();
  5599. p1unlock = null;
  5600. }, p1Timeout);
  5601. }
  5602.  
  5603.  
  5604.  
  5605.  
  5606.  
  5607.  
  5608. }, true);
  5609.  
  5610.  
  5611. }
  5612.  
  5613.  
  5614.  
  5615. /*
  5616.  
  5617. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  5618.  
  5619. */
  5620.  
  5621. let pTags = [];
  5622. const sTags = [
  5623. "yt-live-chat-ticker-sponsor-item-renderer",
  5624. "yt-live-chat-banner-header-renderer",
  5625. "yt-live-chat-text-message-renderer",
  5626. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  5627. "ytd-sponsorships-live-chat-header-renderer",
  5628. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer"
  5629. ];
  5630.  
  5631. for (const tag of sTags) {
  5632. pTags.push(customElements.whenDefined(tag));
  5633. }
  5634.  
  5635.  
  5636. Promise.all(pTags).then(() => {
  5637.  
  5638.  
  5639. mightFirstCheckOnYtInit();
  5640. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  5641. console.log("[Begin]");
  5642.  
  5643. for (const tag of sTags) {
  5644.  
  5645.  
  5646.  
  5647. (() => {
  5648.  
  5649. const dummy = document.createElement(tag);
  5650.  
  5651. const cProto = getProto(dummy);
  5652. if (!cProto || !cProto.attached) {
  5653. console.warn(`proto.attached for ${tag} is unavailable.`);
  5654. return;
  5655. }
  5656.  
  5657.  
  5658.  
  5659.  
  5660. 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) {
  5661.  
  5662. cProto.showContextMenu37_ = cProto.showContextMenu_;
  5663. cProto.showContextMenu37 = cProto.showContextMenu;
  5664.  
  5665. function deepCopy(obj, skipKeys) {
  5666. skipKeys = skipKeys || [];
  5667. if (!obj || typeof obj !== 'object') return obj;
  5668. if (Array.isArray(obj)) {
  5669. return obj.map(item => deepCopy(item, skipKeys));
  5670. }
  5671. const copy = {};
  5672. for (let key in obj) {
  5673. if (!skipKeys.includes(key)) {
  5674. copy[key] = deepCopy(obj[key], skipKeys);
  5675. }
  5676. }
  5677. return copy;
  5678. }
  5679.  
  5680. /*
  5681. const wm37 = new WeakMap();
  5682. cProto.__showContextMenu_forceNativeRequest__ = 0;
  5683. cProto.__cacheResolvedEndpointData__ = (endpoint, a, doDeepCopy) => {
  5684. if (a) {
  5685. if (doDeepCopy) a = deepCopy(a);
  5686. wm37.set(endpoint, a);
  5687. } else {
  5688. wm37.remove(endpoint);
  5689. }
  5690. }
  5691. cProto.__showContextMenuNetworkRequestMutex__ = null;
  5692. cProto.__showContextMenuNetworkRequestMutexResolve__ = null;
  5693. cProto.showContextMenu = function (a) {
  5694. if(this.__showContextMenu_forceNativeRequest__){
  5695. return this.showContextMenu37(a);
  5696. }
  5697. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5698. if (!endpoint) {
  5699. return this.showContextMenu37(a);
  5700. }
  5701. this.__showContextMenuNetworkRequestMutex__ = (this.__showContextMenuNetworkRequestMutex__ || Promise.resolve())
  5702. .then(()=>new Promise(lockResolve=>{
  5703.  
  5704. if (endpoint !== (this.data || 0).contextMenuEndpoint || 0){
  5705. lockResolve();
  5706. return;
  5707. }
  5708.  
  5709. if (endpoint) {
  5710. let resolvedEndpoint = wm37.get(endpoint);
  5711. if (resolvedEndpoint) {
  5712. resolvedEndpoint = deepCopy(resolvedEndpoint);
  5713. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  5714. Promise.resolve(resolvedEndpoint).then(() => {
  5715. this.showContextMenu37_(resolvedEndpoint);
  5716. });
  5717. lockResolve();
  5718. return;
  5719. //this.showContextMenu37_(JSON.parse(JSON.stringify(a)));
  5720. //return;
  5721. }
  5722.  
  5723. this.__showContextMenuNetworkRequestMutexResolve__ = new Promise(resolve=>{
  5724. this.__showContextMenuNetworkRequestMutexResolve__ = resolve;
  5725.  
  5726. }).then((a)=>{
  5727.  
  5728. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5729. if (endpoint) {
  5730. const f = this.__cacheResolvedEndpointData__
  5731. if (typeof f === 'function') f(endpoint, a, true);
  5732. }
  5733. this.showContextMenu37_(a);
  5734. lockResolve();
  5735.  
  5736. }).catch(console.warn)
  5737.  
  5738. }else{
  5739.  
  5740. this.__showContextMenuNetworkRequestMutexResolve__ = null;
  5741. this.showContextMenu37(a);
  5742. lockResolve();
  5743. }
  5744.  
  5745.  
  5746.  
  5747.  
  5748. })).catch(console.warn);
  5749. }
  5750.  
  5751. cProto.showContextMenu_ = function (a) {
  5752.  
  5753. let resolve = this.__showContextMenuNetworkRequestMutexResolve__;
  5754. this.__showContextMenuNetworkRequestMutexResolve__= null;
  5755.  
  5756. if (resolve) {
  5757. resolve(a);
  5758. } else {
  5759. return this.showContextMenu37_(a);
  5760. }
  5761.  
  5762. }
  5763. */
  5764.  
  5765.  
  5766. const wm37 = new WeakMap();
  5767. cProto.__showContextMenu_forceNativeRequest__ = 0;
  5768. cProto.__cacheResolvedEndpointData__ = (endpoint, a, doDeepCopy) => {
  5769. if (a) {
  5770. if (doDeepCopy) a = deepCopy(a);
  5771. wm37.set(endpoint, a);
  5772. } else {
  5773. wm37.remove(endpoint);
  5774. }
  5775. }
  5776. cProto.__getCachedEndpointData__ = function (endpoint) {
  5777. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  5778. if (endpoint) return wm37.get(endpoint);
  5779. return null;
  5780. }
  5781. cProto.__showCachedContextMenu__ = function (resolvedEndpoint) { // non-null
  5782.  
  5783. resolvedEndpoint = deepCopy(resolvedEndpoint);
  5784. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  5785. Promise.resolve(resolvedEndpoint).then(() => {
  5786. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  5787. this.showContextMenu_(resolvedEndpoint);
  5788. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  5789. });
  5790.  
  5791.  
  5792.  
  5793. }
  5794. cProto.showContextMenu = function (a) {
  5795. if (!this.__showContextMenu_forceNativeRequest__) {
  5796. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5797. if (endpoint) {
  5798. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  5799. if (resolvedEndpoint) {
  5800. this.__showCachedContextMenu__(resolvedEndpoint);
  5801. return;
  5802. }
  5803. }
  5804. }
  5805. return this.showContextMenu37(a);
  5806. }
  5807.  
  5808. cProto.showContextMenu_ = function (a) {
  5809. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  5810. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5811. if (endpoint) {
  5812. const f = this.__cacheResolvedEndpointData__;
  5813. if (typeof f === 'function') f(endpoint, a, true);
  5814. }
  5815. }
  5816. return this.showContextMenu37_(a);
  5817. }
  5818.  
  5819.  
  5820.  
  5821.  
  5822. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  5823.  
  5824.  
  5825.  
  5826. } else {
  5827.  
  5828. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  5829.  
  5830. }
  5831.  
  5832.  
  5833.  
  5834. 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) {
  5835.  
  5836.  
  5837. cProto.showContextMenu48 = cProto.showContextMenu;
  5838.  
  5839.  
  5840. cProto.showContextMenu = function (a) {
  5841.  
  5842. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5843. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  5844.  
  5845. const parentComponent = this.parentComponent;
  5846. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  5847. parentComponent.allowScroll = false;
  5848. }
  5849. }
  5850.  
  5851. return this.showContextMenu48.apply(this, arguments);
  5852.  
  5853. }
  5854.  
  5855.  
  5856.  
  5857. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  5858.  
  5859.  
  5860.  
  5861. } else {
  5862.  
  5863. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  5864.  
  5865. }
  5866.  
  5867.  
  5868.  
  5869.  
  5870.  
  5871. 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) {
  5872.  
  5873. cProto.showContextMenu47_ = cProto.showContextMenu_;
  5874. cProto.showContextMenu47 = cProto.showContextMenu;
  5875.  
  5876. const mutex = new Mutex();
  5877. let __showContextMenu_mutex_unlock__ = null;
  5878. cProto.__showContextMenu_mutex_unlock_isEmpty__ = () => {
  5879. return __showContextMenu_mutex_unlock__ === null;
  5880. }
  5881. cProto.__showContextMenu_assign_lock__ = function (p) {
  5882.  
  5883.  
  5884. mutex.lockWith(unlock => {
  5885. p.then(unlock);
  5886. });
  5887.  
  5888. }
  5889. let lastShowMenuTarget = null;
  5890. cProto.showContextMenu = function (a) {
  5891. lastShowMenuTarget = this;
  5892.  
  5893. if (this.__showContextMenu_sync_mode_request__) {
  5894.  
  5895. return this.showContextMenu47(a);
  5896. } else {
  5897.  
  5898.  
  5899. mutex.lockWith(unlock => {
  5900. if (lastShowMenuTarget !== this) {
  5901. unlock();
  5902. return;
  5903. }
  5904.  
  5905. setTimeout(unlock, 800); // in case network failure
  5906. __showContextMenu_mutex_unlock__ = unlock;
  5907. try {
  5908. this.showContextMenu47(a);
  5909. } catch (e) {
  5910. console.warn(e);
  5911. unlock(); // in case function script error
  5912. }
  5913.  
  5914. });
  5915.  
  5916. }
  5917.  
  5918.  
  5919. }
  5920.  
  5921.  
  5922. cProto.showContextMenu_ = function (a) {
  5923.  
  5924. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  5925. __showContextMenu_mutex_unlock__();
  5926. __showContextMenu_mutex_unlock__ = null;
  5927. }
  5928. return this.showContextMenu47_(a);
  5929.  
  5930. }
  5931.  
  5932. /*
  5933. const wm37 = new WeakMap();
  5934. cProto.__showContextMenu_forceNativeRequest__ = 0;
  5935. cProto.__cacheResolvedEndpointData__ = (endpoint, a, doDeepCopy) => {
  5936. if (a) {
  5937. if (doDeepCopy) a = deepCopy(a);
  5938. wm37.set(endpoint, a);
  5939. } else {
  5940. wm37.remove(endpoint);
  5941. }
  5942. }
  5943. cProto.__showContextMenuNetworkRequestMutex__ = null;
  5944. cProto.__showContextMenuNetworkRequestMutexResolve__ = null;
  5945. cProto.showContextMenu = function (a) {
  5946. if(this.__showContextMenu_forceNativeRequest__){
  5947. return this.showContextMenu37(a);
  5948. }
  5949. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5950. if (!endpoint) {
  5951. return this.showContextMenu37(a);
  5952. }
  5953. this.__showContextMenuNetworkRequestMutex__ = (this.__showContextMenuNetworkRequestMutex__ || Promise.resolve())
  5954. .then(()=>new Promise(lockResolve=>{
  5955.  
  5956. if (endpoint !== (this.data || 0).contextMenuEndpoint || 0){
  5957. lockResolve();
  5958. return;
  5959. }
  5960.  
  5961. if (endpoint) {
  5962. let resolvedEndpoint = wm37.get(endpoint);
  5963. if (resolvedEndpoint) {
  5964. resolvedEndpoint = deepCopy(resolvedEndpoint);
  5965. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  5966. Promise.resolve(resolvedEndpoint).then(() => {
  5967. this.showContextMenu37_(resolvedEndpoint);
  5968. });
  5969. lockResolve();
  5970. return;
  5971. //this.showContextMenu37_(JSON.parse(JSON.stringify(a)));
  5972. //return;
  5973. }
  5974.  
  5975. this.__showContextMenuNetworkRequestMutexResolve__ = new Promise(resolve=>{
  5976. this.__showContextMenuNetworkRequestMutexResolve__ = resolve;
  5977.  
  5978. }).then((a)=>{
  5979.  
  5980. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  5981. if (endpoint) {
  5982. const f = this.__cacheResolvedEndpointData__
  5983. if (typeof f === 'function') f(endpoint, a, true);
  5984. }
  5985. this.showContextMenu37_(a);
  5986. lockResolve();
  5987.  
  5988. }).catch(console.warn)
  5989.  
  5990. }else{
  5991.  
  5992. this.__showContextMenuNetworkRequestMutexResolve__ = null;
  5993. this.showContextMenu37(a);
  5994. lockResolve();
  5995. }
  5996.  
  5997.  
  5998.  
  5999.  
  6000. })).catch(console.warn);
  6001. }
  6002.  
  6003. cProto.showContextMenu_ = function (a) {
  6004.  
  6005. let resolve = this.__showContextMenuNetworkRequestMutexResolve__;
  6006. this.__showContextMenuNetworkRequestMutexResolve__= null;
  6007.  
  6008. if (resolve) {
  6009. resolve(a);
  6010. } else {
  6011. return this.showContextMenu37_(a);
  6012. }
  6013.  
  6014. }
  6015. */
  6016.  
  6017.  
  6018.  
  6019.  
  6020. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  6021.  
  6022.  
  6023.  
  6024. } else {
  6025.  
  6026. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  6027.  
  6028. }
  6029.  
  6030.  
  6031.  
  6032.  
  6033. })();
  6034.  
  6035. }
  6036.  
  6037.  
  6038.  
  6039. console.log("[End]");
  6040.  
  6041. console.groupEnd();
  6042.  
  6043. }).catch(console.warn);
  6044.  
  6045.  
  6046.  
  6047. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  6048.  
  6049. mightFirstCheckOnYtInit();
  6050. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  6051. console.log("[Begin]");
  6052. (() => {
  6053.  
  6054. const tag = "tp-yt-iron-dropdown";
  6055. const dummy = document.createElement(tag);
  6056.  
  6057. const cProto = getProto(dummy);
  6058. if (!cProto || !cProto.attached) {
  6059. console.warn(`proto.attached for ${tag} is unavailable.`);
  6060. return;
  6061. }
  6062.  
  6063.  
  6064. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  6065. cProto.__deraf_hn__ = function (sId, fn) {
  6066. const rhKey = `_rafHandler_${sId}`;
  6067. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  6068. if (m.has(fn)) return m.get(fn);
  6069. const resFn = () => {
  6070. this.__rafs[sId] = null;
  6071. fn.call(this)
  6072. };
  6073. m.set(fn, resFn);
  6074. m.set(resFn, resFn);
  6075. return resFn;
  6076. };
  6077. cProto.__deraf34 = cProto.__deraf;
  6078. cProto.__deraf = function (a, b) { // sId, fn
  6079. let c = this.__rafs;
  6080. null !== c[a] && cancelAnimationFrame(c[a]);
  6081. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  6082. };
  6083. console.log("USE_VANILLA_DEREF - OK");
  6084. } else {
  6085. console.log("USE_VANILLA_DEREF - NG");
  6086. }
  6087.  
  6088. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  6089. cProto.__deraf66 = cProto.__deraf;
  6090. cProto.__deraf = function (sId, fn) {
  6091. if (this.__byPassRAF__) {
  6092. Promise.resolve().then(() => {
  6093. fn.call(this);
  6094. });
  6095. }
  6096. let r = this.__deraf66.apply(this, arguments);
  6097. return r;
  6098. }
  6099. console.log("FIX_DROPDOWN_DERAF - OK");
  6100. } else {
  6101. console.log("FIX_DROPDOWN_DERAF - NG");
  6102. }
  6103.  
  6104.  
  6105. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  6106.  
  6107. let lastClose = null;
  6108. let lastOpen = null;
  6109. let cid = 0;
  6110.  
  6111. cProto.__mtChanged__ = function (b) {
  6112.  
  6113. Promise.resolve().then(() => {
  6114. this._applyFocus();
  6115. }).then(() => {
  6116. b ? this._renderOpened() : this._renderClosed();
  6117. }).catch(console.warn);
  6118.  
  6119. };
  6120.  
  6121. const __moChanged__ = () => {
  6122. if (!cid) return;
  6123. // console.log(553, !!lastOpen, !!lastClose);
  6124. cid = 0;
  6125. if (lastOpen && !lastClose && lastOpen.isAttached) {
  6126. lastOpen.__mtChanged__(1)
  6127. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  6128. lastClose.__mtChanged__(0);
  6129. }
  6130. lastOpen = null;
  6131. lastClose = null;
  6132. };
  6133.  
  6134.  
  6135. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  6136. cProto._openedChanged66 = cProto._openedChanged;
  6137. cProto._openedChanged = function () {
  6138. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  6139. this.__byPassRAF__ = true;
  6140. let r = this._openedChanged66.apply(this, arguments);
  6141. this.__byPassRAF__ = false;
  6142. return r;
  6143. }
  6144. }
  6145.  
  6146. const pSetGet = (key, pdThis, pdBase) => {
  6147. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  6148. return {
  6149. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  6150. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  6151. };
  6152. };
  6153.  
  6154. cProto.__modifiedMenuPropsFn__ = function () {
  6155. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  6156. const pdBase = Object.getOwnPropertyDescriptors(this)
  6157.  
  6158. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  6159. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  6160. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  6161.  
  6162. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  6163. console.warn('there is setter/getter for autoFitOnAttach');
  6164. return;
  6165. }
  6166. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  6167. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  6168. return;
  6169. }
  6170. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  6171. console.warn('there is NO setter-getter for allowOutsideScroll');
  6172. return;
  6173. }
  6174.  
  6175. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  6176.  
  6177. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  6178.  
  6179. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  6180.  
  6181. Object.defineProperties(this, {
  6182. autoFitOnAttach: {
  6183. get() {
  6184. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  6185. return autoFitOnAttach;
  6186. },
  6187. set(nv) {
  6188. autoFitOnAttach = nv;
  6189. return true;
  6190. },
  6191. enumerable: true,
  6192. configurable: true
  6193. }, expandSizingTargetForScrollbars: {
  6194. get() {
  6195. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  6196. return expandSizingTargetForScrollbars;
  6197. },
  6198. set(nv) {
  6199. expandSizingTargetForScrollbars = nv;
  6200. return true;
  6201. },
  6202. enumerable: true,
  6203. configurable: true
  6204. }, allowOutsideScroll: {
  6205. get() {
  6206. if (this._modifiedMenuPropOn062__) return true;
  6207. return allowOutsideScroll;
  6208. },
  6209. set(nv) {
  6210. allowOutsideScroll = nv;
  6211. this.__AllowOutsideScrollPD__.set.call(this, nv);
  6212. return true;
  6213. },
  6214. enumerable: true,
  6215. configurable: true
  6216. }
  6217. })
  6218. };
  6219.  
  6220. /*
  6221. // ***** position() to be changed. *****
  6222. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  6223.  
  6224. overflow: visible !important;
  6225. min-width: max-content !important;
  6226. max-width: max-content !important;
  6227. max-height: max-content !important;
  6228. min-height: max-content !important;
  6229. white-space: nowrap;
  6230. }
  6231.  
  6232. */
  6233. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  6234.  
  6235. let m34 = 0;
  6236. cProto.__refitByPosition__ = function () {
  6237. m34++;
  6238. if (m34 <= 0) m34 = 0;
  6239. if (m34 !== 1) return;
  6240. const hostElement = this.hostElement || this;
  6241. if (document.visibilityState === 'visible') {
  6242. const sizingTarget = this.sizingTarget;
  6243. if (!sizingTarget) {
  6244. m34 = 0;
  6245. return;
  6246. }
  6247.  
  6248. let useVisibilityCollapse = true;
  6249. if (HTMLElement.prototype.querySelector.call(sizingTarget, 'yt-icon:empty')) {
  6250. useVisibilityCollapse = false;
  6251. }
  6252.  
  6253. if (useVisibilityCollapse) {
  6254. hostElement.style.visibility = 'collapse';
  6255. sizingTarget.style.visibility = 'collapse';
  6256. } else {
  6257. hostElement.setAttribute('rNgzQ', '');
  6258. sizingTarget.setAttribute('rNgzQ', '');
  6259. }
  6260.  
  6261. const gn = () => {
  6262.  
  6263. if (useVisibilityCollapse) {
  6264. hostElement.style.visibility = '';
  6265. sizingTarget.style.visibility = '';
  6266. } else {
  6267. hostElement.removeAttribute('rNgzQ');
  6268. sizingTarget.removeAttribute('rNgzQ');
  6269. }
  6270. }
  6271.  
  6272. const an = async () => {
  6273. while (m34 >= 1) {
  6274. await renderReadyPn(sizingTarget);
  6275. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  6276. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  6277. }
  6278. m34--;
  6279. }
  6280. m34 = 0;
  6281. Promise.resolve().then(gn);
  6282. }
  6283. setTimeout(an, 4); // wait those resizing function calls
  6284.  
  6285.  
  6286. } else {
  6287. m34 = 0;
  6288. }
  6289. }
  6290. cProto.position34 = cProto.position
  6291. cProto.position = function () {
  6292. if (this._positionInitialize_) {
  6293. this._positionInitialize_ = 0;
  6294. this.__refitByPosition__();
  6295. }
  6296. let r = cProto.position34.apply(this, arguments);
  6297. return r;
  6298. }
  6299. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  6300.  
  6301. } else {
  6302.  
  6303. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  6304.  
  6305. }
  6306.  
  6307.  
  6308.  
  6309. cProto.__openedChanged = function () {
  6310. this._positionInitialize_ = 1;
  6311. // this.removeAttribute('horizontal-align')
  6312. // this.removeAttribute('vertical-align')
  6313. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  6314. this.__menuTypeCheck__ = true;
  6315. if (CHAT_MENU_SCROLL_UNLOCKING) {
  6316. this._modifiedMenuPropOn062__ = false;
  6317. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  6318. // this.autoFitOnAttach = true;
  6319. // this.expandSizingTargetForScrollbars = true;
  6320. // this.allowOutsideScroll = true;
  6321. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  6322. this.__modifiedMenuPropsFn__();
  6323. // this.constrain= function(){}
  6324. // this.position= function(){}
  6325.  
  6326. // this.autoFitOnAttach = true;
  6327. // this.expandSizingTargetForScrollbars = true;
  6328. // this.allowOutsideScroll = true;
  6329. }
  6330. }
  6331. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  6332. let newValue = null;
  6333. const positionTarget = this.positionTarget;
  6334. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  6335. if (this._modifiedMenuPropOn062__ === false) {
  6336. newValue = true;
  6337. }
  6338. } else if (this._modifiedMenuPropOn062__ === true) {
  6339. newValue = false;
  6340. }
  6341. if (newValue !== null) {
  6342. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  6343. this._modifiedMenuPropOn062__ = newValue;
  6344. const afterAllowOutsideScroll = this.allowOutsideScroll;
  6345. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  6346. }
  6347. }
  6348.  
  6349. if (this.opened) {
  6350.  
  6351. Promise.resolve().then(() => {
  6352.  
  6353. this._prepareRenderOpened();
  6354. }).then(() => {
  6355. this._manager.addOverlay(this);
  6356. if (this._manager._overlays.length === 1) {
  6357. lastOpen = this;
  6358. lastClose = null;
  6359. } else {
  6360. return 1;
  6361. }
  6362. // if (cid) {
  6363. // clearTimeout(cid);
  6364. // cid = -1;
  6365. // this.__moChanged__();
  6366. // cid = 0;
  6367. // } else {
  6368. // cid = -1;
  6369. // this.__moChanged__();
  6370. // cid = 0;
  6371. // }
  6372. // cid = cid > 0 ? clearTimeout(cid) : 0;
  6373. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  6374. // cid = cid || setTimeout(__moChanged__, delay1);
  6375. cid = cid || requestAnimationFrame(__moChanged__);
  6376. }).then((r) => {
  6377.  
  6378. if (r) this.__mtChanged__(1);
  6379. }).catch(console.warn);
  6380.  
  6381. } else {
  6382. Promise.resolve().then(() => {
  6383. this._manager.removeOverlay(this);
  6384. if (this._manager._overlays.length === 0) {
  6385. lastClose = this;
  6386. lastOpen = null;
  6387. } else {
  6388. return 1;
  6389. }
  6390. // cid = cid > 0 ? clearTimeout(cid) : 0;
  6391. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  6392. // cid = cid || setTimeout(__moChanged__, delay1);
  6393. cid = cid || requestAnimationFrame(__moChanged__);
  6394. }).then((r) => {
  6395. if (r) this.__mtChanged__(0);
  6396. }).catch(console.warn);
  6397.  
  6398. }
  6399.  
  6400. }
  6401. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  6402.  
  6403. } else {
  6404.  
  6405. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  6406. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  6407.  
  6408. }
  6409.  
  6410.  
  6411. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  6412.  
  6413. cProto.__openedChanged82 = cProto.__openedChanged;
  6414.  
  6415.  
  6416. cProto.__openedChanged = function () {
  6417.  
  6418. // currentMenuPivotWR = null;
  6419. // console.log(1480, '__openedChanged.A', this.positionTarget)
  6420.  
  6421.  
  6422.  
  6423. // if (this.opened && this.positionTarget) {
  6424.  
  6425. // const positionTarget = this.positionTarget;
  6426. // console.log(1480, '__openedChanged.B', positionTarget)
  6427. // currentMenuPivotWR = mWeakRef(positionTarget);
  6428.  
  6429. // }
  6430.  
  6431. const positionTarget = this.positionTarget;
  6432. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  6433. return this.__openedChanged82.apply(this, arguments);
  6434. }
  6435. }
  6436.  
  6437.  
  6438. // if(FIX_MENU_CAPTURE_SCROLL && typeof cProto.__onCaptureScroll === 'function' && !cProto.__onCaptureScroll66){
  6439.  
  6440. // cProto.__onCaptureScroll66 = cProto.__onCaptureScroll;
  6441.  
  6442. // cProto.__onCaptureScroll = function(a){
  6443.  
  6444. // const q = true;
  6445. // if(this.scrollAction === 'lock' && q && this.opened){
  6446.  
  6447. // // console.log(9107, this.scrollAction, this.__isAnimating, this.opened, a); // lock; __isAnimating = false
  6448. // async function af() {
  6449. // this.__isAnimating && this._finishRenderOpened();
  6450. // if (!this.opened) return;
  6451. // this.__restoreScrollPosition();
  6452. // await new Promise(r => requestAnimationFrame(r));
  6453. // if (!this.opened) return;
  6454. // this.opened && this.__isAnimating && this._finishRenderOpened();
  6455. // if (!this.opened) return;
  6456. // this.__restoreScrollPosition();
  6457. // await new Promise(r => requestAnimationFrame(r));
  6458. // if (!this.opened) return;
  6459. // this.opened && this.__isAnimating && this._finishRenderOpened();
  6460. // if (!this.opened) return;
  6461. // this.opened && !this.__isAnimating && this.refit();
  6462. // }
  6463. // Promise.resolve().then(af);
  6464.  
  6465. // return cProto.__onCaptureScroll66.apply(this, arguments);
  6466. // }else{
  6467.  
  6468. // // console.log(9102, this.scrollAction, this.__isAnimating, this.opened, a); // lock
  6469.  
  6470. // return cProto.__onCaptureScroll66.apply(this, arguments);
  6471. // }
  6472. // }
  6473. // console.log("FIX_MENU_CAPTURE_SCROLL - OK");
  6474. // }else{
  6475. // console.log("FIX_MENU_CAPTURE_SCROLL - NG");
  6476.  
  6477. // }
  6478.  
  6479.  
  6480. })();
  6481.  
  6482. console.log("[End]");
  6483.  
  6484. console.groupEnd();
  6485.  
  6486. }).catch(console.warn);
  6487.  
  6488.  
  6489. if (LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY) {
  6490.  
  6491.  
  6492. customElements.whenDefined("yt-live-chat-renderer").then(() => {
  6493.  
  6494. mightFirstCheckOnYtInit();
  6495. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  6496. console.log("[Begin]");
  6497. (() => {
  6498.  
  6499. const tag = "yt-live-chat-renderer"
  6500. const dummy = document.createElement(tag);
  6501.  
  6502. const cProto = getProto(dummy);
  6503. if (!cProto || !cProto.attached) {
  6504. console.warn(`proto.attached for ${tag} is unavailable.`);
  6505. return;
  6506. }
  6507.  
  6508.  
  6509. if (typeof cProto._flushProperties === 'function' && !cProto._flushProperties22 && cProto._flushProperties.length === 0) {
  6510.  
  6511. cProto.flushPendingCount = 0;
  6512. cProto._flushProperties22 = cProto._flushProperties;
  6513.  
  6514. cProto._flushProperties = function () {
  6515. if (foregroundPromiseForLiveChatFlush) return;
  6516. this.flushPendingCount++;
  6517. const tid = this.flushPendingCount;
  6518. getForegroundPromiseForLiveChatFlush().then(() => {
  6519. if (tid !== this.flushPendingCount) return;
  6520. // console.log('_flushProperties22', Date.now())
  6521. this._flushProperties22();
  6522. });
  6523. };
  6524.  
  6525.  
  6526. console.log("cProto._flushProperties - OK");
  6527.  
  6528. } else {
  6529. console.log("cProto._flushProperties - NG");
  6530.  
  6531. }
  6532.  
  6533. })();
  6534.  
  6535. console.log("[End]");
  6536.  
  6537. console.groupEnd();
  6538.  
  6539. }).catch(console.warn);
  6540.  
  6541.  
  6542. }
  6543.  
  6544.  
  6545.  
  6546.  
  6547.  
  6548.  
  6549. /*
  6550.  
  6551.  
  6552.  
  6553.  
  6554.  
  6555. var FU = function() {
  6556. var a = this;
  6557. this.nextHandle_ = 1;
  6558. this.clients_ = {};
  6559. this.JSC$10323_callbacks_ = {};
  6560. this.unsubscribeAsyncHandles_ = {};
  6561. this.subscribe = vl(function(b, c, d) {
  6562. var e = Geb(b);
  6563. if (e in a.clients_)
  6564. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  6565. else {
  6566. a: {
  6567. var h = Geb(b), l;
  6568. for (l in a.unsubscribeAsyncHandles_) {
  6569. var m = a.clients_[l];
  6570. if (m instanceof KO) {
  6571. delete a.clients_[l];
  6572. delete a.JSC$10323_callbacks_[l];
  6573. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  6574. delete a.unsubscribeAsyncHandles_[l];
  6575. i6a(m);
  6576. m.objectId_ = new FQa(h);
  6577. m.register();
  6578. d = m;
  6579. break a
  6580. }
  6581. }
  6582. d.objectSource = b.invalidationId.objectSource;
  6583. d.objectId = h;
  6584. if (b = b.webAuthConfigurationData)
  6585. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  6586. b.pageId && (d.pageId = b.pageId);
  6587. d = new KO(d,a.handleInvalidationData_.bind(a));
  6588. d.register()
  6589. }
  6590. a.clients_[e] = d;
  6591. a.JSC$10323_callbacks_[e] = {}
  6592. }
  6593. d = a.nextHandle_++;
  6594. a.JSC$10323_callbacks_[e][d] = c;
  6595. return d
  6596. })
  6597. };
  6598. FU.prototype.unsubscribe = function(a, b) {
  6599. var c = Geb(a);
  6600. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  6601. !this.JSC$10323_callbacks_[c].length)) {
  6602. var d = this.clients_[c];
  6603. b = Jq.run(function() {
  6604. ei(d);
  6605. delete this.clients_[c];
  6606. delete this.unsubscribeAsyncHandles_[c]
  6607. }
  6608. .bind(this));
  6609. this.unsubscribeAsyncHandles_[c] = b
  6610. }
  6611. }
  6612. ;
  6613.  
  6614.  
  6615. */
  6616.  
  6617.  
  6618.  
  6619.  
  6620. const onManagerFound = (dummyManager) => {
  6621. if (!dummyManager || typeof dummyManager !== 'object') return;
  6622.  
  6623. const mgrProto = dummyManager.constructor.prototype;
  6624.  
  6625. let keyCallbackStore = '';
  6626. for (const [key, v] of Object.entries(dummyManager)) {
  6627. if (key.includes('_callbacks_')) keyCallbackStore = key;
  6628. }
  6629.  
  6630. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  6631.  
  6632. if (mgrProto.unsubscribe16) return;
  6633.  
  6634. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  6635.  
  6636. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  6637. console.log("[Begin]");
  6638.  
  6639.  
  6640. // const isEmptyObject = (a) => Object.keys(a).length === 0;
  6641. const isEmptyObject = (obj) => {
  6642. for (let key in obj) {
  6643. if (obj.hasOwnProperty(key)) return false;
  6644. }
  6645. return true;
  6646. }
  6647.  
  6648. const idMapper = new Map();
  6649.  
  6650. const convertId = function (objectId) {
  6651. if (!objectId || typeof objectId !== 'string') return null;
  6652.  
  6653. let result = idMapper.get(objectId)
  6654. if (result) return result;
  6655. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  6656. idMapper.set(objectId, result)
  6657. return result;
  6658. }
  6659.  
  6660.  
  6661. const rafHandleHolder = [];
  6662.  
  6663. let pzw = 0;
  6664. let lza = 0;
  6665. const genRAF = () => {
  6666.  
  6667. pzw = requestAnimationFrame(() => {
  6668. pzw = 0;
  6669. if (rafHandleHolder.length === 1) {
  6670. const f = rafHandleHolder[0];
  6671. rafHandleHolder.length = 0;
  6672. f();
  6673. } else if (rafHandleHolder.length > 1) {
  6674. let arr = rafHandleHolder.slice(0)
  6675. rafHandleHolder.length = 0;
  6676. for (const fn of arr) fn();
  6677. }
  6678. });
  6679. };
  6680.  
  6681.  
  6682. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  6683.  
  6684. const checkIntegrityForSubscribe = (mgr) => {
  6685. if (mgr
  6686. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  6687. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  6688.  
  6689. const ns = new Set(Object.keys(mgr));
  6690. const ms = new Set(Object.keys(mgr.constructor.prototype));
  6691.  
  6692. if (ns.size >= 6 && ms.size >= 4) {
  6693. // including 'subscribe18'
  6694. // 'unsubscribe16', 'subscribe19'
  6695.  
  6696. let r = 0;
  6697. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  6698. r += ns.has(k) ? 1 : 0;
  6699. }
  6700. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  6701. r += ms.has(k) ? 1 : 0;
  6702. }
  6703. if (r === 10) {
  6704. const isObject = (c) => (c || 0).constructor === Object;
  6705.  
  6706. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  6707.  
  6708. return true;
  6709. }
  6710.  
  6711.  
  6712. }
  6713.  
  6714. }
  6715.  
  6716.  
  6717. }
  6718. return false;
  6719. }
  6720.  
  6721. mgrProto.subscribe19 = function (o, f, opts) {
  6722.  
  6723. const ct_clients_ = this.clients_ || 0;
  6724. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  6725.  
  6726. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  6727.  
  6728. let objectId = ((o || 0).invalidationId || 0).objectId;
  6729. if (!objectId) return this.subscribe18.apply(this, arguments);
  6730. objectId = convertId(objectId);
  6731.  
  6732. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  6733.  
  6734. if (ct_clients_[objectId]) {
  6735. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  6736. }
  6737.  
  6738. return this.subscribe18.apply(this, arguments);
  6739. }
  6740.  
  6741. mgrProto.unsubscribe = function (o, d) {
  6742. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  6743. this.subscribe18 = this.subscribe;
  6744. this.subscribe = this.subscribe19;
  6745. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  6746. }
  6747. const ct_clients_ = this.clients_;
  6748. const ct_handles_ = this.unsubscribeAsyncHandles_;
  6749. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  6750.  
  6751. let objectId = ((o || 0).invalidationId || 0).objectId;
  6752. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  6753.  
  6754. objectId = convertId(objectId);
  6755.  
  6756.  
  6757. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  6758.  
  6759. const callbacks = this[keyCallbackStore] || 0;
  6760. const callbackObj = callbacks[objectId] || 0;
  6761.  
  6762.  
  6763. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  6764. const w = ct_clients_[objectId];
  6765. --lza;
  6766. if (lza < -1e9) lza = -1;
  6767. const qta = lza;
  6768. rafHandleHolder.push(() => {
  6769. if (qta === ct_handles_[objectId]) {
  6770. try {
  6771. w && "function" === typeof w.dispose && w.dispose();
  6772. delete ct_clients_[objectId];
  6773. delete ct_handles_[objectId];
  6774. } catch (e) {
  6775. console.warn(e);
  6776. }
  6777. }
  6778. });
  6779. ct_handles_[objectId] = qta;
  6780. if (pzw === 0) genRAF();
  6781. }
  6782. }
  6783.  
  6784.  
  6785. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  6786.  
  6787. } else {
  6788.  
  6789. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  6790. }
  6791.  
  6792. console.log("[End]");
  6793.  
  6794. console.groupEnd();
  6795.  
  6796. }
  6797.  
  6798.  
  6799.  
  6800. /*
  6801.  
  6802.  
  6803. a.prototype.async = function(e, h) {
  6804. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  6805. }
  6806. ;
  6807. a.prototype.cancelAsync = function(e) {
  6808. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  6809. }
  6810.  
  6811. */
  6812.  
  6813.  
  6814.  
  6815. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  6816.  
  6817. let __dummyManager__ = null;
  6818.  
  6819. mightFirstCheckOnYtInit();
  6820. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  6821. console.log("[Begin]");
  6822. (() => {
  6823.  
  6824. const tag = "yt-invalidation-continuation"
  6825. const dummy = document.createElement(tag);
  6826.  
  6827. const cProto = getProto(dummy);
  6828. if (!cProto || !cProto.attached) {
  6829. console.warn(`proto.attached for ${tag} is unavailable.`);
  6830. return;
  6831. }
  6832.  
  6833. const dummyManager = (dummy.inst || dummy).manager_ || 0;
  6834. __dummyManager__ = dummyManager;
  6835.  
  6836. 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) {
  6837.  
  6838.  
  6839. const rafHub = new RAFHub();
  6840.  
  6841. rafHub.keepRAF = true;
  6842. cProto.async71 = cProto.async;
  6843. cProto.cancelAsync71 = cProto.cancelAsync;
  6844.  
  6845. // mostly for subscription timeoutMs 10000ms
  6846. let mcw = 1; // 1, 3, 5, ...
  6847. let arr = new Map();
  6848.  
  6849. let __asyncInited__ = 0;
  6850. let __timeoutStartId__ = null;
  6851. const __asyncInit__ = () => {
  6852.  
  6853. if (__asyncInited__) return;
  6854. __asyncInited__ = 1;
  6855.  
  6856. __timeoutStartId__ = setTimeout(() => { });
  6857. mcw = __timeoutStartId__ * 2 + 1;
  6858.  
  6859. setInterval(() => {
  6860.  
  6861. if (!arr.length) return;
  6862.  
  6863. const p = Date.now();
  6864. let deleteKeys = [];
  6865. arr.forEach((entry, key) => {
  6866.  
  6867.  
  6868. if (entry.cid === -1) {
  6869. entry.cid = -2;
  6870. } else if (entry.cid === -2) {
  6871.  
  6872. let offset = p - entry.add
  6873. if (offset < 0) offset = 0;
  6874. let delay2 = entry.delay - offset;
  6875. if (delay2 < 0) delay2 = 0;
  6876. entry.cid = setTimeout(entry.q(), delay2);
  6877. entry.q = null;
  6878.  
  6879. } else if (entry.add + entry.delay < p) {
  6880. deleteKeys.push(key);
  6881.  
  6882. }
  6883.  
  6884. })
  6885.  
  6886. for (const key of deleteKeys) arr.delete(key);
  6887.  
  6888. }, 2000)
  6889.  
  6890. }
  6891.  
  6892.  
  6893.  
  6894.  
  6895. cProto.async = function (e, h) {
  6896.  
  6897. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  6898.  
  6899. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  6900.  
  6901. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  6902.  
  6903.  
  6904. if (!this.__asyncInited__) {
  6905. this.__asyncInited__ = 1;
  6906. __asyncInit__();
  6907. }
  6908. mcw += 2; // 2K+3, 2K+4, ...
  6909. if (mcw > 1e9) mcw = mcw % 1e4;
  6910. const cid = mcw;
  6911. const q = () => {
  6912. return () => {
  6913. console.log('async h > 8000');
  6914. e.call(this);
  6915. }
  6916. }
  6917. // setTimeout(q, delay)
  6918. arr.set(cid, {
  6919. cid: -1, // -1 -> -2 -> cid
  6920. add: Date.now(),
  6921. q,
  6922. delay: h
  6923. });
  6924. // console.log('cid-async', cid)
  6925. return cid;
  6926.  
  6927. }
  6928.  
  6929.  
  6930. cProto.cancelAsync = function (e) {
  6931.  
  6932. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  6933.  
  6934. // console.log('cid-unasync', e)
  6935.  
  6936. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  6937.  
  6938. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  6939.  
  6940. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  6941.  
  6942. if (!arr.has(e)) return; // duplciated cancel
  6943.  
  6944. const entry = arr.get(e);
  6945. if (entry.cid < 0) {
  6946. entry.cid = 0;
  6947. arr.delete(e);
  6948. } else {
  6949. clearTimeout(entry.cid); // cid >= 1
  6950. entry.cid = 0;
  6951. arr.delete(e);
  6952. }
  6953.  
  6954. } else {
  6955.  
  6956. return this.cancelAsync71(e);
  6957.  
  6958. }
  6959.  
  6960. }
  6961.  
  6962. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  6963.  
  6964. } else {
  6965. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  6966.  
  6967. }
  6968.  
  6969. })();
  6970.  
  6971. console.log("[End]");
  6972.  
  6973. console.groupEnd();
  6974.  
  6975.  
  6976.  
  6977. onManagerFound(__dummyManager__);
  6978.  
  6979. }).catch(console.warn);
  6980.  
  6981.  
  6982.  
  6983.  
  6984. if (DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION) {
  6985.  
  6986.  
  6987.  
  6988. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  6989.  
  6990.  
  6991. mightFirstCheckOnYtInit();
  6992. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  6993. console.log("[Begin]");
  6994. (() => {
  6995.  
  6996. const tag = "yt-live-interactivity-component-background"
  6997. const dummy = document.createElement(tag);
  6998.  
  6999. const cProto = getProto(dummy);
  7000. if (!cProto || !cProto.attached) {
  7001. console.warn(`proto.attached for ${tag} is unavailable.`);
  7002. return;
  7003. }
  7004.  
  7005.  
  7006. if (DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  7007.  
  7008. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  7009. cProto.maybeLoadAnimationBackground = function () {
  7010. if (this.useAnimationBackground === true) this.useAnimationBackground = false;
  7011. }
  7012.  
  7013. console.log("DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION - OK");
  7014.  
  7015. } else {
  7016. console.log("DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION - NG");
  7017.  
  7018. }
  7019.  
  7020. })();
  7021.  
  7022. console.log("[End]");
  7023.  
  7024. console.groupEnd();
  7025.  
  7026.  
  7027. }).catch(console.warn);
  7028.  
  7029. }
  7030.  
  7031.  
  7032. }
  7033.  
  7034.  
  7035.  
  7036.  
  7037. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  7038.  
  7039. const fixJsonParse = () => {
  7040.  
  7041.  
  7042.  
  7043. if (jsonParseFix && typeof JSON.parse === 'function' && !JSON.parse68) {
  7044.  
  7045. let { _parse, _JSON } = jsonParseFix;
  7046.  
  7047.  
  7048. let error = 0;
  7049. try {
  7050. _parse.apply(JSON, ["{}"])
  7051. _JSON = JSON;
  7052. } catch (e) {
  7053. error = 1;
  7054. }
  7055. if (error === 1) {
  7056.  
  7057. try {
  7058. _parse.apply(_JSON, ["{}"])
  7059. } catch (e) {
  7060. error = 2;
  7061. }
  7062. if (error === 2) {
  7063. return;
  7064. }
  7065. }
  7066.  
  7067.  
  7068. JSON.parse68 = JSON.parse;
  7069.  
  7070. JSON.parse = function parse(a, b) {
  7071. const stack = (new Error()).stack;
  7072. if (stack.includes('.readyStateChangeHandler_')) return _parse.apply(_JSON, arguments);
  7073. return this.parse68(...arguments);
  7074. };
  7075.  
  7076. JSON.parse.toString = function () {
  7077. return JSON.parse68.toString();
  7078. };
  7079.  
  7080. jsonParseFix = null;
  7081.  
  7082. }
  7083.  
  7084. }
  7085.  
  7086. if (DE_JSONPRUNE_FOR_readyStateChangeHandler_) {
  7087. promiseForCustomYtElementsReady.then(fixJsonParse);
  7088. fixJsonParse();
  7089. }
  7090.  
  7091. });
  7092.  
  7093.  
  7094.  
  7095. })({ IntersectionObserver });