YouTube 超快聊天

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

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

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