YouTube 超快聊天

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

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

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