YouTube 超快聊天

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

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

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