YouTube 超快聊天

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

目前为 2023-12-31 提交的版本。查看 最新版本

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