YouTube 超快聊天

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

当前为 2023-10-07 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址