YouTube 超快聊天

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

当前为 2023-09-02 提交的版本,查看 最新版本

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