YouTube 超快聊天

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

目前为 2023-08-29 提交的版本,查看 最新版本

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