YouTube 超快聊天

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

目前为 2023-09-08 提交的版本。查看 最新版本

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