YouTube 超快聊天

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

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

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