YouTube 超快聊天

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

当前为 2024-01-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.60.40
  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.gf.qytechs.cn/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://gf.qytechs.cn/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://gf.qytechs.cn/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. if (typeof window.nextBrowserTick !== 'function') {
  2733. insp(lcRenderer).scrollToBottom_();
  2734. } else {
  2735. nextBrowserTick(() => {
  2736. const cnt = insp(lcRenderer);
  2737. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  2738. cnt.scrollToBottom_();
  2739. });
  2740. }
  2741. }
  2742. });
  2743. }
  2744. }
  2745. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  2746.  
  2747. // target.style.setProperty('--wsr94', h + 'px');
  2748. target.setAttribute('wSr93', 'hidden');
  2749. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  2750.  
  2751. }
  2752.  
  2753.  
  2754.  
  2755. const visObserver = new IntersectionObserver((entries) => {
  2756.  
  2757. for (const entry of entries) {
  2758.  
  2759. Promise.resolve(entry).then(visObserverFn);
  2760.  
  2761. }
  2762.  
  2763. }, {
  2764. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  2765. rootMargin: "0px",
  2766. threshold: [0.05, 0.95],
  2767. });
  2768.  
  2769.  
  2770. return { lcRendererElm, visObserver }
  2771.  
  2772.  
  2773. })();
  2774.  
  2775. const { setupMutObserver } = (() => {
  2776.  
  2777. async function asyncTickerBackgroundOverridedChecker() {
  2778.  
  2779. try {
  2780. await promiseForCustomYtElementsReady.then();
  2781. await customElements.whenDefined('yt-live-chat-text-message-renderer');
  2782. await new Promise(r => setTimeout(r, 800));
  2783.  
  2784. if (!hasTimerModified) return;
  2785. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  2786. if (!tickerRenderer) return;
  2787.  
  2788. const tickerRendererDollar = indr(tickerRenderer);
  2789. const items = (tickerRendererDollar || 0).items || 0;
  2790. if (!items) return;
  2791. const template = document.createElement('template');
  2792. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  2793. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  2794. dimmed="" [dummy777]>
  2795. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  2796. 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));">
  2797. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  2798. <yt-img-shadow777 id="author-photo" height="24" width="24"
  2799. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  2800. style="background-color: transparent;" loaded=""><img id="img"
  2801. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  2802. src="${dummyImgURL}"></yt-img-shadow777>
  2803.  
  2804. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  2805. </div>
  2806. </div>
  2807. </yt-live-chat-ticker-dummy777-item-renderer>`;
  2808. const dummy777 = template.content.firstElementChild;
  2809. await Promise.resolve().then();
  2810. let res = 0;
  2811. if (items instanceof HTMLElement && items.isConnected === true) {
  2812. try {
  2813. items.appendChild(dummy777);
  2814. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  2815. if (container.isConnected === true) {
  2816. const evaluated = `${getComputedStyle(container).background}`;
  2817. container = null;
  2818. res = evaluated.indexOf('0.') < 4 ? 1 : 2;
  2819. }
  2820. } catch (e) { console.warn(e) }
  2821. HTMLElement.prototype.remove.call(dummy777);
  2822. }
  2823. await Promise.resolve().then();
  2824. dummy777.textContent = '';
  2825. if (res === 1) {
  2826. // not fulfilling
  2827. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  2828. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2829. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2830. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2831. );
  2832. 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');
  2833. console.groupEnd();
  2834. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  2835. } else if (res === 2) {
  2836. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2837. }
  2838. } catch (e) {
  2839. console.warn(e);
  2840. }
  2841. }
  2842.  
  2843. async function asyncDelayChatOccurrence(m2) {
  2844. try {
  2845. await promiseForCustomYtElementsReady.then();
  2846. await customElements.whenDefined('yt-live-chat-text-message-renderer');
  2847. await new Promise(r => setTimeout(r, 1));
  2848. const dummy888 = document.createElement('yt-live-chat-text-message-renderer');
  2849. // const template = document.createElement('template');
  2850. // template.innerHTML = "<yt-live-chat-text-message-renderer></yt-live-chat-text-message-renderer>"
  2851. // const dummy888 = template.content.firstElementChild;
  2852. const skzCnt = insp(dummy888);
  2853. if (!(skzCnt && 'data' in skzCnt && 'attached' in skzCnt)) {
  2854. return;
  2855. }
  2856. if (!skzCnt.hostElement) skzCnt.hostElement = dummy888;
  2857. /** @type {HTMLTemplateElement} */
  2858. const skzElem = dummy888;
  2859. let cz1 = null;
  2860. const deferredZy1 = new Promise(resolve => {
  2861. skzCnt.attached = function () {
  2862. cz1 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  2863. resolve(skzElem.textContent);
  2864. }
  2865. skzCnt.detached = function () {
  2866. }
  2867. });
  2868. skzElem.id = 'sk35z';
  2869. skzData(skzCnt);
  2870. sk35zResolveFn = null;
  2871. const deferredMutation = new Promise(resolve => {
  2872. sk35zResolveFn = resolve;
  2873. HTMLElement.prototype.appendChild.call(m2, skzElem);
  2874. });
  2875. const [zy1, _] = await Promise.all([deferredZy1, deferredMutation]);
  2876. skzCnt.attached = function () { };
  2877. function fn() {
  2878. const zy2 = skzElem.textContent;
  2879. const cz2 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  2880. if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  2881. allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  2882. }
  2883. if (allowDontRender === true) return true;
  2884. if (allowDontRender === false) {
  2885. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  2886. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  2887. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  2888. );
  2889. 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');
  2890. console.groupEnd();
  2891. }
  2892. }
  2893. await new Promise(r => setTimeout(r, 1));
  2894. if (!fn()) return;
  2895. await new Promise(r => requestAnimationFrame(r));
  2896. if (!fn()) return;
  2897. skzElem.remove();
  2898. await Promise.resolve().then();
  2899. skzElem.textContent = '';
  2900. console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  2901. } catch (e) {
  2902. console.warn(e);
  2903. }
  2904. }
  2905.  
  2906. const mutFn = (items) => {
  2907. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  2908. if (node.hasAttribute('wSr93')) break;
  2909. node.setAttribute('wSr93', '');
  2910. visObserver.observe(node);
  2911. }
  2912. }
  2913.  
  2914. const mutObserver = new MutationObserver((mutations) => {
  2915. const items = (mutations[0] || 0).target;
  2916. if (!items) return;
  2917. if (sk35zResolveFn) {
  2918. sk35zResolveFn();
  2919. sk35zResolveFn = null;
  2920. }
  2921. mutFn(items);
  2922. });
  2923.  
  2924. const setupMutObserver = (m2) => {
  2925. scrollChatFn = null;
  2926. mutObserver.disconnect();
  2927. mutObserver.takeRecords();
  2928. if (m2) {
  2929. ENABLE_DELAYED_CHAT_OCCURRENCE && bnForDelayChatOccurrence();
  2930. if (typeof m2.__appendChild932__ === 'function') {
  2931. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  2932. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  2933. }
  2934. mutObserver.observe(m2, {
  2935. childList: true,
  2936. subtree: false
  2937. });
  2938. mutFn(m2);
  2939.  
  2940. const isFirstList = firstList;
  2941. firstList = false;
  2942.  
  2943. if (ENABLE_OVERFLOW_ANCHOR) {
  2944.  
  2945. let items = m2;
  2946. let addedAnchor = false;
  2947. if (items) {
  2948. if (items.nextElementSibling === null) {
  2949. items.classList.add('no-anchor');
  2950. addedAnchor = true;
  2951. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  2952. }
  2953. }
  2954.  
  2955.  
  2956.  
  2957. if (addedAnchor) {
  2958. nodeParent(m2).classList.add('no-anchor'); // required
  2959. }
  2960.  
  2961. }
  2962.  
  2963. // let div = document.createElement('div');
  2964. // div.id = 'qwcc';
  2965. // HTMLElement.prototype.appendChild.call(document.querySelector('yt-live-chat-item-list-renderer'), div )
  2966. // bufferRegion =div;
  2967.  
  2968. // buffObserver.takeRecords();
  2969. // buffObserver.disconnect();
  2970. // buffObserver.observe(div, {
  2971. // childList: true,
  2972. // subtree: false
  2973. // })
  2974.  
  2975. if (ENABLE_DELAYED_CHAT_OCCURRENCE && isFirstList) {
  2976. asyncDelayChatOccurrence(m2);
  2977. }
  2978.  
  2979.  
  2980. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  2981.  
  2982. (() => {
  2983.  
  2984. const tag = 'yt-iframed-player-events-relay'
  2985. const dummy = document.createElement(tag);
  2986.  
  2987. const cProto = getProto(dummy);
  2988. if (!cProto || !cProto.handlePostMessage_) {
  2989. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  2990. return;
  2991. }
  2992.  
  2993. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_) {
  2994.  
  2995. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  2996.  
  2997. cProto.handlePostMessage67_ = function (a) {
  2998.  
  2999. const da = a.data;
  3000.  
  3001.  
  3002.  
  3003. playEventsStack = playEventsStack.then(() => {
  3004.  
  3005.  
  3006.  
  3007. if ('yt-player-state-change' in da) {
  3008.  
  3009. const qc = da['yt-player-state-change'];
  3010.  
  3011.  
  3012. let isQcChanged = false;
  3013.  
  3014. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  3015. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  3016. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  3017.  
  3018.  
  3019. if ((isQcChanged) && playerState !== _playerState) {
  3020. playerEventsByIframeRelay = true;
  3021. onPlayStateChangePromise = new Promise((resolve) => {
  3022. let k = _playerState;
  3023. foregroundPromiseFn().then(() => {
  3024. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  3025. onPlayStateChangePromise = null;
  3026. resolve();
  3027. })
  3028. }).catch(console.warn);
  3029.  
  3030. }
  3031.  
  3032. } else if ('yt-player-video-progress' in da) {
  3033. const vp = da['yt-player-video-progress'];
  3034.  
  3035.  
  3036. relayCount++;
  3037. lastPlayerProgress = vp > 0 ? vp : 0;
  3038.  
  3039.  
  3040. if (relayPromise && vp > 0 && relayCount >= 2) {
  3041. if (onPlayStateChangePromise) {
  3042. onPlayStateChangePromise.then(() => {
  3043. relayPromise && relayPromise.resolve();
  3044. relayPromise = null;
  3045. })
  3046. } else {
  3047. relayPromise.resolve();
  3048. relayPromise = null;
  3049. }
  3050. }
  3051.  
  3052.  
  3053.  
  3054. }
  3055.  
  3056.  
  3057.  
  3058.  
  3059.  
  3060.  
  3061. return this.handlePostMessage66_(a);
  3062.  
  3063.  
  3064.  
  3065. }).catch(console.warn);
  3066.  
  3067. }
  3068.  
  3069.  
  3070. cProto.handlePostMessage_ = function (a) {
  3071.  
  3072.  
  3073. const da = (a || 0).data || 0;
  3074.  
  3075. if (typeof da !== 'object') return;
  3076.  
  3077. if (waitForInitialDataCompletion === 1) return;
  3078.  
  3079. if (!isPlayProgressTriggered) {
  3080. isPlayProgressTriggered = true;
  3081.  
  3082. if ('yt-player-video-progress' in da) {
  3083. waitForInitialDataCompletion = 1;
  3084.  
  3085. const wrapWith = (data) => {
  3086. const { origin } = a;
  3087. return {
  3088. origin,
  3089. data
  3090. };
  3091. }
  3092.  
  3093. this.handlePostMessage67_(wrapWith({
  3094. "yt-iframed-parent-ready": true
  3095. }));
  3096.  
  3097.  
  3098.  
  3099. playEventsStack = playEventsStack.then(() => {
  3100.  
  3101.  
  3102.  
  3103. const lcr = document.querySelector('yt-live-chat-renderer');
  3104. const psc = document.querySelector("yt-player-seek-continuation");
  3105. if (lcr && psc && lcr.replayBuffer_) {
  3106.  
  3107.  
  3108. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  3109. const daProgress = da['yt-player-video-progress'] * 1000
  3110. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  3111.  
  3112.  
  3113. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  3114. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  3115.  
  3116.  
  3117. // console.log(deepCopy( front_))
  3118. // console.log(deepCopy( back_))
  3119. // console.log(rbProgress, daProgress, )
  3120. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  3121. // no action
  3122. // console.log('ss1')
  3123. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  3124. // daProgress - 1200 < rbProgress < daProgress + 3400
  3125. // console.log('ss2')
  3126. } else {
  3127.  
  3128. // console.log('ss3')
  3129. // lcr.replayBuffer_.replayQueue.back_.length= 0;
  3130. // lcr.replayBuffer_.replayQueue.front_.length= 0;
  3131.  
  3132. // lcr
  3133. lcr.previousProgressSec = 1E-5;
  3134. // lcr._setIsSeeking(!0),
  3135. lcr.replayBuffer_.clear()
  3136. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  3137. }
  3138.  
  3139. }
  3140.  
  3141.  
  3142. waitForInitialDataCompletion = 2;
  3143.  
  3144. this.handlePostMessage_(a);
  3145.  
  3146.  
  3147. }).catch(console.warn);
  3148.  
  3149.  
  3150.  
  3151. return;
  3152.  
  3153. }
  3154.  
  3155. }
  3156.  
  3157.  
  3158.  
  3159. this.handlePostMessage67_(a);
  3160.  
  3161.  
  3162.  
  3163. }
  3164.  
  3165. }
  3166.  
  3167.  
  3168. })();
  3169.  
  3170. }
  3171.  
  3172. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  3173. asyncTickerBackgroundOverridedChecker();
  3174. }
  3175.  
  3176. }
  3177. }
  3178.  
  3179. return { setupMutObserver };
  3180.  
  3181.  
  3182.  
  3183. })();
  3184.  
  3185. const setupEvents = () => {
  3186.  
  3187.  
  3188. let scrollCount = 0;
  3189.  
  3190. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  3191.  
  3192.  
  3193. const delayFlushActiveItemsAfterUserActionK_ = () => {
  3194.  
  3195. const lcRenderer = lcRendererElm();
  3196. if (lcRenderer) {
  3197. const cnt = insp(lcRenderer);
  3198. if (!cnt.hasUserJustInteracted11_) return;
  3199. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  3200. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  3201. }
  3202. }
  3203.  
  3204. }
  3205.  
  3206. document.addEventListener('scroll', (evt) => {
  3207. if (!evt || !evt.isTrusted) return;
  3208. // lastScroll = dateNow();
  3209. if (++scrollCount > 1e9) scrollCount = 9;
  3210. }, passiveCapture); // support contain => support passive
  3211.  
  3212. let lastScrollCount = -1;
  3213. document.addEventListener('wheel', (evt) => {
  3214. if (!evt || !evt.isTrusted) return;
  3215. if (lastScrollCount === scrollCount) return;
  3216. lastScrollCount = scrollCount;
  3217. lastWheel = dateNow();
  3218. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3219. }, passiveCapture); // support contain => support passive
  3220.  
  3221. document.addEventListener('mousedown', (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('pointerdown', (evt) => {
  3230. if (!evt || !evt.isTrusted) return;
  3231. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3232. lastMouseDown = dateNow();
  3233. currentMouseDown = true;
  3234. lastUserInteraction = lastMouseDown;
  3235. }, passiveCapture);
  3236.  
  3237. document.addEventListener('click', (evt) => {
  3238. if (!evt || !evt.isTrusted) return;
  3239. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3240. lastMouseDown = lastMouseUp = dateNow();
  3241. currentMouseDown = false;
  3242. lastUserInteraction = lastMouseDown;
  3243. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3244. }, passiveCapture);
  3245.  
  3246. document.addEventListener('tap', (evt) => {
  3247. if (!evt || !evt.isTrusted) return;
  3248. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  3249. lastMouseDown = lastMouseUp = dateNow();
  3250. currentMouseDown = false;
  3251. lastUserInteraction = lastMouseDown;
  3252. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3253. }, passiveCapture);
  3254.  
  3255.  
  3256. document.addEventListener('mouseup', (evt) => {
  3257. if (!evt || !evt.isTrusted) return;
  3258. if (currentMouseDown) {
  3259. lastMouseUp = dateNow();
  3260. currentMouseDown = false;
  3261. lastUserInteraction = lastMouseUp;
  3262. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3263. }
  3264. }, passiveCapture);
  3265.  
  3266.  
  3267. document.addEventListener('pointerup', (evt) => {
  3268. if (!evt || !evt.isTrusted) return;
  3269. if (currentMouseDown) {
  3270. lastMouseUp = dateNow();
  3271. currentMouseDown = false;
  3272. lastUserInteraction = lastMouseUp;
  3273. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3274. }
  3275. }, passiveCapture);
  3276.  
  3277. document.addEventListener('touchstart', (evt) => {
  3278. if (!evt || !evt.isTrusted) return;
  3279. lastTouchDown = dateNow();
  3280. currentTouchDown = true;
  3281. lastUserInteraction = lastTouchDown;
  3282. }, passiveCapture);
  3283.  
  3284. document.addEventListener('touchmove', (evt) => {
  3285. if (!evt || !evt.isTrusted) return;
  3286. lastTouchDown = dateNow();
  3287. currentTouchDown = true;
  3288. lastUserInteraction = lastTouchDown;
  3289. }, passiveCapture);
  3290.  
  3291. document.addEventListener('touchend', (evt) => {
  3292. if (!evt || !evt.isTrusted) return;
  3293. if (currentTouchDown) {
  3294. lastTouchUp = dateNow();
  3295. currentTouchDown = false;
  3296. lastUserInteraction = lastTouchUp;
  3297. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3298. }
  3299. }, passiveCapture);
  3300.  
  3301. document.addEventListener('touchcancel', (evt) => {
  3302. if (!evt || !evt.isTrusted) return;
  3303. if (currentTouchDown) {
  3304. lastTouchUp = dateNow();
  3305. currentTouchDown = false;
  3306. lastUserInteraction = lastTouchUp;
  3307. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  3308. }
  3309. }, passiveCapture);
  3310.  
  3311.  
  3312. }
  3313.  
  3314. const getTimestampUsec = (itemRenderer) => {
  3315. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  3316. return itemRenderer.timestampUsec
  3317. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  3318. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  3319. if (messageRenderer) {
  3320.  
  3321. const messageRendererKey = firstObjectKey(messageRenderer);
  3322. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  3323. const messageRendererData = messageRenderer[messageRendererKey];
  3324. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  3325. return messageRendererData.timestampUsec
  3326. }
  3327. }
  3328. }
  3329. }
  3330. return null;
  3331. }
  3332.  
  3333. const onRegistryReadyForDOMOperations = () => {
  3334.  
  3335. let firstCheckedOnYtInit = false;
  3336.  
  3337. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  3338.  
  3339. const mightFirstCheckOnYtInit = () => {
  3340. if (firstCheckedOnYtInit) return;
  3341. firstCheckedOnYtInit = true;
  3342.  
  3343. if (!document.body || !document.head) return;
  3344. if (!assertorURL()) return;
  3345.  
  3346. addCssManaged();
  3347.  
  3348. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  3349. if (efsContainer && efsContainer.parentNode !== document.body) {
  3350. document.body.appendChild(efsContainer);
  3351. }
  3352.  
  3353. };
  3354.  
  3355. if (!assertorURL()) return;
  3356. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  3357.  
  3358. if (document.documentElement && document.head) {
  3359. addCssManaged();
  3360. }
  3361. // console.log(document.body===null)
  3362.  
  3363. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  3364. getLCRDummy().then(async (lcrDummy) => {
  3365.  
  3366. const tag = "yt-live-chat-renderer"
  3367. const dummy = lcrDummy;
  3368.  
  3369. const cProto = getProto(dummy);
  3370. if (!cProto || !cProto.attached) {
  3371. console.warn(`proto.attached for ${tag} is unavailable.`);
  3372. return;
  3373. }
  3374.  
  3375. mightFirstCheckOnYtInit();
  3376. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  3377. console.log("[Begin]");
  3378.  
  3379.  
  3380.  
  3381.  
  3382.  
  3383.  
  3384. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  3385.  
  3386. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  3387.  
  3388. const pop078 = function () {
  3389. const r = this.pop78();
  3390.  
  3391. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  3392. for (const action of r.actions) {
  3393.  
  3394. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  3395. if (itemActionKey) {
  3396.  
  3397. const itemAction = action[itemActionKey];
  3398. const item = (itemAction || 0).item;
  3399. if (typeof item === 'object') {
  3400.  
  3401. const rendererKey = firstObjectKey(item);
  3402. if (rendererKey) {
  3403. const renderer = item[rendererKey];
  3404. if (renderer && typeof renderer === 'object') {
  3405. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  3406. renderer.__progressAt__ = playerProgressChangedArg1;
  3407. }
  3408.  
  3409. }
  3410.  
  3411. }
  3412. }
  3413. }
  3414. }
  3415. return r;
  3416. }
  3417.  
  3418. cProto.playerProgressChanged_ = function (a, b, c) {
  3419. playerProgressChangedArg1 = a;
  3420. playerProgressChangedArg2 = b;
  3421. playerProgressChangedArg3 = c;
  3422. const replayBuffer_ = this.replayBuffer_;
  3423. if (replayBuffer_) {
  3424. const replayQueue = replayBuffer_.replayQueue
  3425. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  3426.  
  3427. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, {
  3428. get(target, prop, receiver) {
  3429. if (prop === 'qe3') return 1;
  3430. const v = target[prop];
  3431. if (prop === 'front_') {
  3432. if (v && typeof v.length === 'number') {
  3433. if (!v.pop78) {
  3434. v.pop78 = v.pop;
  3435. v.pop = pop078;
  3436. }
  3437. }
  3438. }
  3439. return v;
  3440. }
  3441. });
  3442.  
  3443. }
  3444. }
  3445. return this.playerProgressChanged32_.apply(this, arguments);
  3446. };
  3447.  
  3448. }
  3449.  
  3450. // if (typeof cProto.immediatelyApplyLiveChatActions === 'function' && !cProto.immediatelyApplyLiveChatActions32) {
  3451.  
  3452. // cProto.immediatelyApplyLiveChatActions32 = cProto.immediatelyApplyLiveChatActions;
  3453.  
  3454. // cProto.immediatelyApplyLiveChatActions = function (a) {
  3455. // // if (a.length > 8) {
  3456. // // console.log(a)
  3457. // // }
  3458. // // console.log(a)
  3459. // /*
  3460. // let arr=a.slice();
  3461.  
  3462. // if(arr.length >= 2){
  3463. // arr.sort((a, b)=>{
  3464. // let ak = firstObjectKey(a);
  3465. // let bk = firstObjectKey(b);
  3466. // if(!ak||!bk) return 0;
  3467. // const ax = +a[ak]._timestampUsec57;
  3468. // const bx = +b[bk]._timestampUsec57;
  3469. // if(ax >0 && bx >0){
  3470. // const c = bx - ax ;
  3471.  
  3472. // return c > 0.1 ? -1 : c< -0.1 ? 1 : 0;
  3473. // }
  3474. // return 0;
  3475.  
  3476. // });
  3477. // console.log('sort', JSON.parse(JSON.stringify(arr)));
  3478. // }
  3479. // a=arr;
  3480. // */
  3481.  
  3482. // if (a && typeof a === 'object' && a.length >= 1) {
  3483. // const d = Date.now();
  3484. // const m = [];
  3485. // for (let i = 0, l = a.length; i < l; i++) {
  3486. // const action = a[i];
  3487. // const key = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  3488. // if (key === 'addChatItemAction' || key === 'addLiveChatTickerItemAction') {
  3489. // const itemAction = action[key] || 0;
  3490. // const item = itemAction.item || 0;
  3491. // if (item && typeof item === 'object') {
  3492. // let rendererKey = firstObjectKey(item);
  3493. // const renderer = item[rendererKey];
  3494. // let timestampUsec = getTimestampUsec(renderer);
  3495. // if (timestampUsec !== null) {
  3496. // renderer._timestampUsec57 = timestampUsec;
  3497. // }
  3498. // m.push(renderer);
  3499. // // if(timestampUsec!==null){
  3500. // // if(key==='addLiveChatTickerItemAction')console.log(renderer, rendererKey, key)
  3501. // // m.push(renderer);
  3502.  
  3503. // // }
  3504. // }
  3505. // }
  3506. // }
  3507. // if (m.length >= 1) {
  3508.  
  3509. // let lastUsec = null;
  3510. // for (let i = 0, l = m.length; i < l; i++) {
  3511. // const renderer = m[i];
  3512. // if ('_timestampUsec57' in renderer) {
  3513. // lastUsec = +renderer._timestampUsec57 / 1E3;
  3514. // renderer.__lcrTime__ = d;
  3515. // renderer.__actionAt__ = d;
  3516. // }
  3517. // }
  3518.  
  3519.  
  3520. // if (lastUsec !== null) {
  3521.  
  3522. // const refUsec = lastUsec
  3523.  
  3524. // let prevUsec = null;
  3525. // for (let i = 0, l = m.length; i < l; i++) {
  3526. // const renderer = m[i];
  3527. // if ('_timestampUsec57' in renderer) {
  3528.  
  3529. // let actualTime = +renderer._timestampUsec57 / 1E3; // ms
  3530. // let lcrTime = d - Math.round(refUsec - actualTime); // ms
  3531.  
  3532. // renderer.__lcrTime__ = lcrTime; // ms
  3533. // renderer.__actionAt__ = d;
  3534.  
  3535. // prevUsec = lcrTime
  3536. // } else {
  3537.  
  3538. // renderer._prevUsec57 = prevUsec;
  3539. // }
  3540. // }
  3541.  
  3542.  
  3543. // let nextUsec = null;
  3544. // for (let i = m.length - 1; i >= 0; i--) {
  3545. // const renderer = m[i];
  3546. // if ('_timestampUsec57' in renderer) {
  3547.  
  3548. // nextUsec = renderer.__lcrTime__
  3549. // } else {
  3550.  
  3551. // renderer._nextUsec57 = nextUsec;
  3552.  
  3553. // if (renderer._nextUsec57 > 0 && renderer._prevUsec57 > 0 && renderer._nextUsec57 > renderer._prevUsec57) {
  3554. // renderer.__lcrTime__ = (renderer._nextUsec57 + renderer._prevUsec57) / 2;
  3555. // renderer.__actionAt__ = d;
  3556. // }
  3557. // }
  3558. // }
  3559.  
  3560.  
  3561. // }
  3562.  
  3563.  
  3564. // }
  3565. // }
  3566. // return this.immediatelyApplyLiveChatActions32.apply(this, arguments)
  3567. // }
  3568.  
  3569.  
  3570. // }
  3571.  
  3572.  
  3573.  
  3574. console.log("[End]");
  3575. console.groupEnd();
  3576.  
  3577.  
  3578. });
  3579.  
  3580. }
  3581.  
  3582. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  3583.  
  3584. const tag = "yt-live-chat-item-list-renderer"
  3585. const dummy = document.createElement(tag);
  3586.  
  3587. const cProto = getProto(dummy);
  3588. if (!cProto || !cProto.attached) {
  3589. console.warn(`proto.attached for ${tag} is unavailable.`);
  3590. return;
  3591. }
  3592.  
  3593. mightFirstCheckOnYtInit();
  3594. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  3595. console.log("[Begin]");
  3596.  
  3597. const mclp = cProto;
  3598. try {
  3599. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  3600. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  3601. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  3602. assertor(() => typeof mclp.setAtBottom === 'function');
  3603. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  3604. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  3605. } catch (e) { }
  3606.  
  3607.  
  3608. try {
  3609. assertor(() => typeof mclp.attached === 'function');
  3610. assertor(() => typeof mclp.detached === 'function');
  3611. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  3612. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  3613. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  3614. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  3615. assertor(() => typeof mclp.smoothScroll_ === 'function');
  3616. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  3617. } catch (e) { }
  3618.  
  3619. mclp.__intermediate_delay__ = null;
  3620.  
  3621. let mzk = 0;
  3622. let myk = 0;
  3623. let mlf = 0;
  3624. let myw = 0;
  3625. let mzt = 0;
  3626. let zarr = null;
  3627. let mlg = 0;
  3628.  
  3629. if ((mclp.clearList || 0).length === 0) {
  3630. assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  3631. mclp.clearList66 = mclp.clearList;
  3632. mclp.clearList = function () {
  3633. mzk++;
  3634. myk++;
  3635. mlf++;
  3636. myw++;
  3637. mzt++;
  3638. mlg++;
  3639. zarr = null;
  3640. this.__intermediate_delay__ = null;
  3641. this.clearList66();
  3642. };
  3643. console.log("clearList", "OK");
  3644. } else {
  3645. console.log("clearList", "NG");
  3646. }
  3647.  
  3648.  
  3649. let onListRendererAttachedDone = false;
  3650.  
  3651. function setList(itemOffset, items) {
  3652.  
  3653. const isFirstTime = onListRendererAttachedDone === false;
  3654.  
  3655. if (isFirstTime) {
  3656. onListRendererAttachedDone = true;
  3657. Promise.resolve().then(watchUserCSS);
  3658. addCssManaged();
  3659. setupEvents();
  3660. }
  3661.  
  3662. setupStyle(itemOffset, items);
  3663.  
  3664. setupMutObserver(items);
  3665. }
  3666.  
  3667. mclp.attached419 = async function () {
  3668.  
  3669. if (!this.isAttached) return;
  3670.  
  3671. let maxTrial = 16;
  3672. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  3673. if (--maxTrial < 0 || !this.isAttached) return;
  3674. await new Promise(requestAnimationFrame);
  3675. }
  3676.  
  3677. if (this.isAttached !== true) return;
  3678.  
  3679. if (!this.$) {
  3680. console.warn("!this.$");
  3681. return;
  3682. }
  3683. if (!this.$) return;
  3684. /** @type {HTMLElement | null} */
  3685. const itemScroller = this.$['item-scroller'];
  3686. /** @type {HTMLElement | null} */
  3687. const itemOffset = this.$['item-offset'];
  3688. /** @type {HTMLElement | null} */
  3689. const items = this.$['items'];
  3690.  
  3691. if (!itemScroller || !itemOffset || !items) {
  3692. console.warn("items.parentNode !== itemOffset");
  3693. return;
  3694. }
  3695.  
  3696. if (nodeParent(items) !== itemOffset) {
  3697.  
  3698. console.warn("items.parentNode !== itemOffset");
  3699. return;
  3700. }
  3701.  
  3702.  
  3703. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  3704.  
  3705. console.warn("id incorrect");
  3706. return;
  3707. }
  3708.  
  3709. 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')
  3710.  
  3711. if (!isTargetItems) {
  3712. console.warn("!isTargetItems");
  3713. return;
  3714. }
  3715.  
  3716. setList(itemOffset, items);
  3717.  
  3718. }
  3719.  
  3720. mclp.attached331 = mclp.attached;
  3721. mclp.attached = function () {
  3722. this.attached419 && this.attached419();
  3723. return this.attached331();
  3724. }
  3725.  
  3726. mclp.detached331 = mclp.detached;
  3727.  
  3728. mclp.detached = function () {
  3729. setupMutObserver();
  3730. return this.detached331();
  3731. }
  3732.  
  3733. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  3734. for (const t29 of t29s) {
  3735. if (insp(t29).isAttached === true) {
  3736. t29.attached419();
  3737. }
  3738. }
  3739.  
  3740. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  3741.  
  3742. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  3743. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  3744.  
  3745. /** @type {Map<number, any>} */
  3746. const aMap = new Map();
  3747. let count = 6150;
  3748. mclp.async66 = mclp.async;
  3749. mclp.async = function (e, f) {
  3750. // ensure the previous operation is done
  3751. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  3752. const hasF = arguments.length === 2;
  3753. const stack = new Error().stack;
  3754. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  3755. if (count > 1e9) count = 6159;
  3756. const resId = ++count;
  3757. aMap.set(resId, e);
  3758. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  3759. const rp = aMap.get(resId);
  3760. if (typeof rp !== 'function') {
  3761. return;
  3762. }
  3763. let cancelCall = false;
  3764. if (isFlushAsync) {
  3765. if (rk < 0) {
  3766. cancelCall = true;
  3767. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  3768. cancelCall = true;
  3769. }
  3770. }
  3771. if (cancelCall) {
  3772. aMap.delete(resId);
  3773. } else {
  3774. const asyncEn = function () {
  3775. aMap.delete(resId);
  3776. return rp.apply(this, arguments);
  3777. };
  3778. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  3779. }
  3780. });
  3781.  
  3782. return resId;
  3783. }
  3784.  
  3785. mclp.cancelAsync66 = mclp.cancelAsync;
  3786. mclp.cancelAsync = function (resId) {
  3787. if (resId <= 6150) {
  3788. this.cancelAsync66(resId);
  3789. } else if (aMap.has(resId)) {
  3790. const rp = aMap.get(resId);
  3791. aMap.delete(resId);
  3792. if (typeof rp !== 'function') {
  3793. this.cancelAsync66(rp);
  3794. }
  3795. }
  3796. }
  3797.  
  3798. console.log("async", "OK");
  3799. } else {
  3800. console.log("async", "NG");
  3801. }
  3802.  
  3803.  
  3804. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  3805.  
  3806. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  3807. mclp.showNewItems66_ = mclp.showNewItems_;
  3808.  
  3809. mclp.showNewItems77_ = async function () {
  3810. if (myk > 1e9) myk = 9;
  3811. let tid = ++myk;
  3812.  
  3813. await new Promise(requestAnimationFrame);
  3814.  
  3815. if (tid !== myk) {
  3816. return;
  3817. }
  3818.  
  3819. const cnt = this;
  3820.  
  3821. await Promise.resolve();
  3822. cnt.showNewItems66_();
  3823.  
  3824. await Promise.resolve();
  3825.  
  3826. }
  3827.  
  3828. mclp.showNewItems_ = function () {
  3829.  
  3830. const cnt = this;
  3831. cnt.__intermediate_delay__ = new Promise(resolve => {
  3832. cnt.showNewItems77_().then(() => {
  3833. resolve();
  3834. });
  3835. });
  3836. }
  3837.  
  3838. console.log("showNewItems_", "OK");
  3839. } else {
  3840. console.log("showNewItems_", "NG");
  3841. }
  3842.  
  3843.  
  3844. if ((mclp.flushActiveItems_ || 0).length === 0) {
  3845.  
  3846. const sfi = fnIntegrity(mclp.flushActiveItems_);
  3847. if (sfi === '0.150.84') {
  3848. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  3849. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  3850. // b && this.splice("visibleItems", 0, b);
  3851. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  3852. // this.preinsertHeight_ = this.items.clientHeight;
  3853. // this.activeItems_.unshift("visibleItems");
  3854. // try {
  3855. // this.push.apply(this, this.activeItems_)
  3856. // } catch (c) {
  3857. // nm(c)
  3858. // }
  3859. // this.activeItems_ = [];
  3860. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && zQ(function() {
  3861. // a.showNewItems_()
  3862. // }) : zQ(function() {
  3863. // a.maybeScrollToBottom_()
  3864. // })
  3865. } else if (sfi === '0.137.81' || sfi === '0.138.81') {
  3866. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  3867. } else {
  3868. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.150.84'));
  3869. }
  3870.  
  3871. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  3872.  
  3873. let contensWillChangeController = null;
  3874.  
  3875. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  3876.  
  3877. mclp.flushActiveItems78_ = async function (tid) {
  3878. try {
  3879. if (tid !== mlf) return;
  3880. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  3881. let logger = false;
  3882. const cnt = this;
  3883. let immd = cnt.__intermediate_delay__;
  3884. await new Promise(requestAnimationFrame);
  3885.  
  3886. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3887. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  3888.  
  3889. mlf++;
  3890. if (mlg > 1e9) mlg = 9;
  3891. ++mlg;
  3892.  
  3893. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  3894. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  3895. let changeMaxItemsToDisplay = false;
  3896. const activeItemsLen = this.activeItems_.length;
  3897. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  3898. logger = true;
  3899.  
  3900. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  3901.  
  3902. logger && console.log('[Begin]')
  3903.  
  3904. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  3905. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  3906. console.log('reduce maxitems');
  3907. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  3908. // as all the rendered chats are already "outdated"
  3909. // all old chats shall remove and reduced number of few chats will be rendered
  3910. // then restore to the original number
  3911. changeMaxItemsToDisplay = true;
  3912. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  3913. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  3914. }
  3915. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  3916. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  3917.  
  3918. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3919. } else {
  3920. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  3921.  
  3922. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  3923. }
  3924. }
  3925. // it is found that it will render all stacked chats after switching back from background
  3926. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  3927. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  3928.  
  3929.  
  3930. const items = (cnt.$ || 0).items;
  3931.  
  3932. if (USE_WILL_CHANGE_CONTROLLER) {
  3933. if (contensWillChangeController && contensWillChangeController.element !== items) {
  3934. contensWillChangeController.release();
  3935. contensWillChangeController = null;
  3936. }
  3937. if (!contensWillChangeController) contensWillChangeController = new WillChangeController(items, 'contents');
  3938. }
  3939. const wcController = contensWillChangeController;
  3940. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  3941. wcController && wcController.beforeOper();
  3942. await Promise.resolve();
  3943. const acItems = cnt.activeItems_;
  3944. const len1 = acItems.length;
  3945. if (!len1) console.warn('cnt.activeItems_.length = 0');
  3946. let waitFor = [];
  3947.  
  3948.  
  3949. /** @type {Set<string>} */
  3950. const imageLinks = new Set();
  3951.  
  3952. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  3953. for (const item of acItems) {
  3954. fixLiveChatItem(item, imageLinks);
  3955. }
  3956. }
  3957. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  3958. if (emojiPrefetched.size > PREFETCH_LIMITED_SIZE_EMOJI) emojiPrefetched.clear();
  3959. if (authorPhotoPrefetched.size > PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO) authorPhotoPrefetched.clear();
  3960.  
  3961. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  3962. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  3963. // preload performs the high priority fetching.
  3964. // prefetch delays the chat display if the video resoruce is demanding.
  3965.  
  3966. if (rel) {
  3967.  
  3968. imageLinks.forEach(imageLink => {
  3969. let d = false;
  3970. const isEmoji = imageLink.includes('/emoji/');
  3971. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  3972. if (!pretechedSet.has(imageLink)) {
  3973. pretechedSet.add(imageLink);
  3974. d = true;
  3975. }
  3976. if (d) {
  3977. waitFor.push(linker(null, rel, imageLink, 'image'));
  3978.  
  3979. }
  3980. })
  3981.  
  3982. }
  3983.  
  3984. }
  3985.  
  3986. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  3987. skipDontRender = noVisibleItem1;
  3988. // console.log('ss1', Date.now())
  3989. if (waitFor.length > 0) {
  3990. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  3991. }
  3992. waitFor.length = 0;
  3993. waitFor = null;
  3994. // console.log('ss2', Date.now())
  3995. cnt.flushActiveItems66_();
  3996. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  3997. skipDontRender = noVisibleItem2;
  3998. const len2 = cnt.activeItems_.length;
  3999. const bAsync = len1 !== len2;
  4000. await Promise.resolve();
  4001. if (wcController) {
  4002. if (bAsync) {
  4003. cnt.async(() => {
  4004. wcController.afterOper();
  4005. });
  4006. } else {
  4007. wcController.afterOper();
  4008. }
  4009. }
  4010. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  4011. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  4012.  
  4013. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  4014. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  4015. } else if (changeMaxItemsToDisplay) {
  4016.  
  4017. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  4018. maxItemsToDisplay: this.data.maxItemsToDisplay,
  4019. reducedMaxItemsToDisplay,
  4020. originalMaxItemsToDisplay: tmpMaxItemsCount
  4021. });
  4022. }
  4023. logger && console.log('[End]');
  4024.  
  4025. logger && console.groupEnd();
  4026.  
  4027. if (noVisibleItem1 && !noVisibleItem2) {
  4028. // fix possible no auto scroll issue.
  4029. setTimeout(() => cnt.setAtBottom(), 1);
  4030. }
  4031.  
  4032. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  4033.  
  4034.  
  4035. const ff = () => {
  4036.  
  4037. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4038. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4039. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  4040.  
  4041. if (typeof window.nextBrowserTick !== 'function') {
  4042. cnt.scrollToBottom_();
  4043. Promise.resolve().then(() => {
  4044. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4045. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  4046. });
  4047. } else {
  4048. nextBrowserTick(() => {
  4049. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4050. cnt.scrollToBottom_();
  4051. });
  4052. }
  4053.  
  4054. }
  4055. }
  4056.  
  4057. ff();
  4058.  
  4059.  
  4060. Promise.resolve().then(ff);
  4061.  
  4062. // requestAnimationFrame(ff);
  4063. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  4064.  
  4065. const knt = cnt;
  4066. if (!scrollChatFn) {
  4067. const cnt = knt;
  4068. const f = () => {
  4069. const itemScroller = cnt.itemScroller;
  4070. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  4071. if (!cnt.atBottom) {
  4072. cnt.scrollToBottom_();
  4073. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  4074. itemScroller.scrollTop = itemScroller.scrollHeight;
  4075. }
  4076. };
  4077. if (typeof window.nextBrowserTick !== 'function') {
  4078. scrollChatFn = () => Promise.resolve().then(f).then(f);
  4079. } else {
  4080. scrollChatFn = () => nextBrowserTick(f);
  4081. }
  4082. }
  4083.  
  4084. if (!ENABLE_DELAYED_CHAT_OCCURRENCE) scrollChatFn();
  4085. }
  4086.  
  4087. return 1;
  4088.  
  4089.  
  4090. } catch (e) {
  4091. console.warn(e);
  4092. }
  4093. }
  4094.  
  4095. mclp.flushActiveItems77_ = function () {
  4096.  
  4097. return new Promise(resResolve => {
  4098. try {
  4099. const cnt = this;
  4100. if (mlf > 1e9) mlf = 9;
  4101. let tid = ++mlf;
  4102. const hostElement = cnt.hostElement || cnt;
  4103. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  4104. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  4105.  
  4106. // 4 times to maxItems to avoid frequent trimming.
  4107. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  4108.  
  4109. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  4110. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  4111. if (cnt.canScrollToBottom_()) {
  4112. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  4113. .then(() => cnt.flushActiveItems78_(tid)) // async function
  4114. .then((asyncResult) => {
  4115. resResolve(asyncResult); // either undefined or 1
  4116. resResolve = null;
  4117. }).catch((e) => {
  4118. console.warn(e);
  4119. if (resResolve) resResolve();
  4120. });
  4121. } else {
  4122. resResolve(2);
  4123. resResolve = null;
  4124. }
  4125. } catch (e) {
  4126. console.warn(e);
  4127. if (resResolve) resResolve();
  4128. }
  4129.  
  4130.  
  4131. });
  4132.  
  4133. }
  4134.  
  4135. mclp.flushActiveItems_ = function () {
  4136. const cnt = this;
  4137.  
  4138. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  4139.  
  4140. if (cnt.activeItems_.length === 0) {
  4141. cnt.__intermediate_delay__ = null;
  4142. return;
  4143. }
  4144.  
  4145. const cntData = ((cnt || 0).data || 0);
  4146. if (cntData.maxItemsToDisplay944 === undefined) {
  4147. cntData.maxItemsToDisplay944 = null;
  4148. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  4149. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  4150. }
  4151.  
  4152. // ignore previous __intermediate_delay__ and create a new one
  4153. cnt.__intermediate_delay__ = new Promise(resolve => {
  4154. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  4155. if (rt === 1) {
  4156. resolve(1); // success, scroll to bottom
  4157. if (hasMoreMessageState === 1) {
  4158. hasMoreMessageState = 0;
  4159. const showMore = (cnt.$ || 0)['show-more'];
  4160. if (showMore) {
  4161. showMore.classList.remove('has-new-messages-miuzp');
  4162. }
  4163. }
  4164. }
  4165. else if (rt === 2) {
  4166. resolve(2); // success, trim
  4167. if (hasMoreMessageState === 0) {
  4168. hasMoreMessageState = 1;
  4169. const showMore = cnt.$['show-more'];
  4170. if (showMore) {
  4171. showMore.classList.add('has-new-messages-miuzp');
  4172. }
  4173. }
  4174. }
  4175. else resolve(-1); // skip
  4176. }).catch(e => {
  4177. console.warn(e);
  4178. });
  4179. });
  4180.  
  4181. }
  4182. console.log("flushActiveItems_", "OK");
  4183. } else {
  4184. console.log("flushActiveItems_", "NG");
  4185. }
  4186.  
  4187. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  4188. try {
  4189. if (mlg > 1e9) mlg = 9;
  4190. const tid = ++mlg;
  4191. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  4192. const runCond = () => this.canScrollToBottom_();
  4193. if (!keepTrialCond()) return;
  4194. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  4195. await new Promise(r => setTimeout(r, 80));
  4196. if (!keepTrialCond()) return;
  4197. if (runCond()) return this.flushActiveItems_() | 1;
  4198. await new Promise(requestAnimationFrame);
  4199. if (runCond()) return this.flushActiveItems_() | 1;
  4200. } catch (e) {
  4201. console.warn(e);
  4202. }
  4203. }
  4204.  
  4205. if ((mclp.atBottomChanged_ || 0).length === 1) {
  4206. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  4207.  
  4208. const sfi = fnIntegrity(mclp.atBottomChanged_);
  4209. if (sfi === '1.73.37') {
  4210. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4211. } else if (sfi === '1.75.39') {
  4212. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  4213. } else {
  4214. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.73.37'));
  4215. }
  4216.  
  4217. const querySelector = HTMLElement.prototype.querySelector;
  4218. const U = (element) => ({
  4219. querySelector: (selector) => querySelector.call(element, selector)
  4220. });
  4221.  
  4222. let qid = 0;
  4223. mclp.atBottomChanged_ = function (a) {
  4224. let tid = ++qid;
  4225. let b = this;
  4226. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  4227. if (tid !== qid) return;
  4228. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  4229. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  4230. this.hideShowMoreAsync_ = null,
  4231. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  4232. }
  4233.  
  4234. console.log("atBottomChanged_", "OK");
  4235. } else {
  4236. console.log("atBottomChanged_", "NG");
  4237. }
  4238.  
  4239. if ((mclp.onScrollItems_ || 0).length === 1) {
  4240.  
  4241. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  4242. mclp.onScrollItems66_ = mclp.onScrollItems_;
  4243. mclp.onScrollItems77_ = async function (evt) {
  4244. if (myw > 1e9) myw = 9;
  4245. let tid = ++myw;
  4246.  
  4247. await new Promise(requestAnimationFrame);
  4248.  
  4249. if (tid !== myw) {
  4250. return;
  4251. }
  4252.  
  4253. const cnt = this;
  4254.  
  4255. await Promise.resolve();
  4256. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  4257. await Promise.resolve().then(() => {
  4258. this.ytRendererBehavior.onScroll(evt);
  4259. }).then(() => {
  4260. if (this.canScrollToBottom_()) {
  4261. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  4262. if (hasUserJustInteracted) {
  4263. // only when there is an user action
  4264. this.setAtBottom();
  4265. return 1;
  4266. }
  4267. } else {
  4268. // no message inserting
  4269. this.setAtBottom();
  4270. return 1;
  4271. }
  4272. }).then((r) => {
  4273.  
  4274. if (this.activeItems_.length) {
  4275.  
  4276. if (this.canScrollToBottom_()) {
  4277. this.flushActiveItems_();
  4278. return 1 && r;
  4279. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  4280. // delayed due to user action
  4281. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  4282. return 0;
  4283. }
  4284. }
  4285. }).then((r) => {
  4286. if (r) {
  4287. // ensure setAtBottom is correctly set
  4288. this.setAtBottom();
  4289. }
  4290. });
  4291. } else {
  4292. cnt.onScrollItems66_(evt);
  4293. }
  4294.  
  4295. await Promise.resolve();
  4296.  
  4297. }
  4298.  
  4299. mclp.onScrollItems_ = function (evt) {
  4300.  
  4301. const cnt = this;
  4302. cnt.__intermediate_delay__ = new Promise(resolve => {
  4303. cnt.onScrollItems77_(evt).then(() => {
  4304. resolve();
  4305. });
  4306. });
  4307. }
  4308. console.log("onScrollItems_", "OK");
  4309. } else {
  4310. console.log("onScrollItems_", "NG");
  4311. }
  4312.  
  4313. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  4314.  
  4315. const sfi = fnIntegrity(mclp.handleLiveChatActions_);
  4316. if (sfi === '1.39.20') {
  4317. // TBC
  4318. } else if (sfi === '1.31.17') {
  4319. // original
  4320. } else {
  4321. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  4322. }
  4323.  
  4324. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  4325.  
  4326. mclp.handleLiveChatActions77_ = async function (arr) {
  4327. if (typeof (arr || 0).length !== 'number') {
  4328. this.handleLiveChatActions66_(arr);
  4329. return;
  4330. }
  4331. if (mzt > 1e9) mzt = 9;
  4332. let tid = ++mzt;
  4333.  
  4334. if (zarr === null) zarr = arr;
  4335. else Array.prototype.push.apply(zarr, arr);
  4336. arr = null;
  4337.  
  4338. await new Promise(requestAnimationFrame);
  4339.  
  4340. if (tid !== mzt || zarr === null) {
  4341. return;
  4342. }
  4343.  
  4344. const carr = zarr;
  4345. zarr = null;
  4346.  
  4347. await Promise.resolve();
  4348. this.handleLiveChatActions66_(carr);
  4349. await Promise.resolve();
  4350.  
  4351. }
  4352.  
  4353. mclp.handleLiveChatActions_ = function (arr) {
  4354.  
  4355. const cnt = this;
  4356. cnt.__intermediate_delay__ = new Promise(resolve => {
  4357. cnt.handleLiveChatActions77_(arr).then(() => {
  4358. resolve();
  4359. });
  4360. });
  4361. }
  4362. console.log("handleLiveChatActions_", "OK");
  4363. } else {
  4364. console.log("handleLiveChatActions_", "NG");
  4365. }
  4366.  
  4367. mclp.hasUserJustInteracted11_ = () => {
  4368. const t = dateNow();
  4369. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  4370. }
  4371.  
  4372. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  4373.  
  4374. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  4375.  
  4376. mclp.canScrollToBottom_ = function () {
  4377. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  4378. }
  4379.  
  4380. console.log("canScrollToBottom_", "OK");
  4381. } else {
  4382. console.log("canScrollToBottom_", "NG");
  4383. }
  4384.  
  4385. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  4386.  
  4387. mclp.isSmoothScrollEnabled_ = function () {
  4388. return false;
  4389. }
  4390.  
  4391. mclp.maybeResizeScrollContainer_ = function () {
  4392. //
  4393. }
  4394.  
  4395. mclp.refreshOffsetContainerHeight_ = function () {
  4396. //
  4397. }
  4398.  
  4399. mclp.smoothScroll_ = function () {
  4400. //
  4401. }
  4402.  
  4403. mclp.resetSmoothScroll_ = function () {
  4404. //
  4405. }
  4406. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  4407. } else {
  4408. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  4409. }
  4410.  
  4411. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  4412.  
  4413. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  4414. mclp.handleAddChatItemAction_ = function (a) {
  4415. try {
  4416. if (a && typeof a === 'object' && !('length' in a)) {
  4417. fixLiveChatItem(a.item, null);
  4418. console.assert(arguments[0] === a);
  4419. }
  4420. } catch (e) { console.warn(e) }
  4421. return this.handleAddChatItemAction66_.apply(this, arguments);
  4422. }
  4423.  
  4424. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  4425. } else {
  4426.  
  4427. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  4428. }
  4429.  
  4430.  
  4431. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  4432.  
  4433. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  4434. mclp.handleReplaceChatItemAction_ = function (a) {
  4435. try {
  4436. if (a && typeof a === 'object' && !('length' in a)) {
  4437. fixLiveChatItem(a.replacementItem, null);
  4438. console.assert(arguments[0] === a);
  4439. }
  4440. } catch (e) { console.warn(e) }
  4441. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  4442. }
  4443.  
  4444. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  4445. } else {
  4446.  
  4447. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  4448. }
  4449.  
  4450. console.log("[End]");
  4451. console.groupEnd();
  4452.  
  4453. }).catch(console.warn);
  4454.  
  4455.  
  4456. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  4457.  
  4458. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  4459.  
  4460. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  4461.  
  4462. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  4463. let v = `${attrValue}`;
  4464. // conside a ticker is 101px width
  4465. // 1% = 1.01px
  4466. // 0.2% = 0.202px
  4467.  
  4468.  
  4469. const ratio1 = (yd.ratio * 100);
  4470. if (ratio1 > -1) { // avoid NaN
  4471.  
  4472. // countdownDurationMs
  4473. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  4474. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  4475. // 150000 - 1% <1% = 1.5s>
  4476. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  4477. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  4478.  
  4479. // 99px * 5% = 4.95px
  4480.  
  4481. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  4482.  
  4483.  
  4484. // 1% Duration
  4485.  
  4486. let ratio2 = ratio1;
  4487.  
  4488. const ydd = yd.data;
  4489. if (ydd) {
  4490.  
  4491. const d1 = ydd.durationSec;
  4492. const d2 = ydd.fullDurationSec;
  4493.  
  4494. // @ step timing [min. 0.2%]
  4495. let numOfSteps = 500;
  4496. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  4497. if (d2 > 400) numOfSteps = 500; // 0.2%
  4498. else if (d2 > 200) numOfSteps = 200; // 0.5%
  4499. else if (d2 > 100) numOfSteps = 100; // 1%
  4500. else if (d2 > 50) numOfSteps = 50; // 2%
  4501. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  4502. else numOfSteps = 20;
  4503. }
  4504. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4505. if (numOfSteps < 5) numOfSteps = 5;
  4506.  
  4507. const rd = numOfSteps / 100.0;
  4508.  
  4509. ratio2 = Math.round(ratio2 * rd) / rd;
  4510.  
  4511. // ratio2 = Math.round(ratio2 * 5) / 5;
  4512. ratio2 = ratio2.toFixed(1);
  4513. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  4514.  
  4515. if (yd.__style_last__ === v) return;
  4516. yd.__style_last__ = v;
  4517. // do not consider any delay here.
  4518. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  4519.  
  4520. }
  4521. }
  4522.  
  4523. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  4524.  
  4525.  
  4526. } else {
  4527. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  4528. }
  4529.  
  4530. };
  4531.  
  4532.  
  4533. const fpTicker = (renderer) => {
  4534. const cnt = insp(renderer);
  4535. assertor(() => typeof (cnt || 0).is === 'string');
  4536. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  4537. const container = (cnt.$ || 0).container;
  4538. if (container) {
  4539. assertor(() => (container || 0).nodeType === 1);
  4540. assertor(() => typeof container.setAttribute === 'function');
  4541. container.setAttribute = tickerContainerSetAttribute;
  4542. } else {
  4543. console.warn(`"container" does not exist in ${cnt.is}`);
  4544. }
  4545. };
  4546.  
  4547.  
  4548. const tags = [
  4549. "yt-live-chat-ticker-paid-message-item-renderer",
  4550. "yt-live-chat-ticker-paid-sticker-item-renderer",
  4551. "yt-live-chat-ticker-renderer",
  4552. "yt-live-chat-ticker-sponsor-item-renderer"
  4553. ];
  4554.  
  4555.  
  4556. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  4557.  
  4558. mightFirstCheckOnYtInit();
  4559. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  4560. console.log("[Begin]");
  4561.  
  4562. let dummyValueForStyleReturn = null;
  4563.  
  4564. const genDummyValueForStyleReturn = () => {
  4565. let s = `--nx:82;`
  4566. let ro = {
  4567. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  4568. "implementsGoogStringTypedString": true
  4569. };
  4570. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  4571. return ro;
  4572. }
  4573.  
  4574. let isCSSPropertySupported_ = null;
  4575. const isCSSPropertySupported = () => {
  4576.  
  4577. // @property --ticker-rtime
  4578.  
  4579. if (typeof isCSSPropertySupported_ === 'boolean') return isCSSPropertySupported_;
  4580. isCSSPropertySupported_ = false;
  4581.  
  4582. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return false;
  4583. const documentElement = document.documentElement;
  4584. if (!documentElement) {
  4585. console.warn('document.documentElement is not found');
  4586. return false;
  4587. }
  4588. if (`${getComputedStyle(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  4589. return false;
  4590. }
  4591.  
  4592. const ae = animate.call(documentElement,
  4593. [
  4594. { '--ticker-rtime': '70%' },
  4595. { '--ticker-rtime': '30%' }
  4596. ],
  4597. {
  4598. fill: "forwards",
  4599. duration: 1000 * 40,
  4600. easing: 'linear'
  4601. }
  4602. );
  4603.  
  4604. let animatedValue = getComputedStyle(document.documentElement).getPropertyValue('--ticker-rtime');
  4605. ae.finish();
  4606. if (`${animatedValue}`.length !== 3) return false;
  4607.  
  4608. isCSSPropertySupported_ = true;
  4609. return true;
  4610.  
  4611. };
  4612.  
  4613.  
  4614. let windowShownAt = -1;
  4615. const setupEventForWindowShownAt = () => {
  4616. window.addEventListener('visibilitychange', () => {
  4617. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  4618. else windowShownAt = 0;
  4619. }, false);
  4620. }
  4621.  
  4622. const dProto = {
  4623.  
  4624. attachedForTickerInit: function () {
  4625.  
  4626. fpTicker(this.hostElement || this);
  4627. return this.attached77();
  4628.  
  4629. },
  4630.  
  4631.  
  4632. // doAnimator
  4633.  
  4634. _makeAnimator: function () {
  4635. if (this._r782) return;
  4636. // if (!this.isAttached) return;
  4637. if (!this._runnerAE) {
  4638. /** @type {HTMLElement | null} */
  4639. const aElement = (this.$ || 0).container;
  4640. if (!aElement) return console.warn("this.$.container is undefined");
  4641. const da = this.data;
  4642. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  4643. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  4644. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  4645. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  4646.  
  4647. // if (!this.__tickerBackgroundInitialChecked__) {
  4648. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  4649. // console.log('__tickerBackgroundInitialChecked__')
  4650. // this._checkTickerBackgroundChanged();
  4651. // }
  4652.  
  4653. aElement.style.setProperty('--ticker-c1', c1);
  4654. aElement.style.setProperty('--ticker-c2', c2);
  4655. aElement.classList.add(runTickerClassName);
  4656. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  4657. // this._aeStartV = this.countdownMs;
  4658. // this._aeStartT = this.countdownDurationMs;
  4659. if (!(p >= 0 && p <= 100)) {
  4660. console.warn('incorrect time ratio', p);
  4661. } else {
  4662. /*
  4663. const u0 = p.toFixed(4) + '%';
  4664. this._runnerAE = animate.call(aElement,
  4665. [
  4666. { '--ticker-rtime': u0 },
  4667. { '--ticker-rtime': '0%' }
  4668. ]
  4669. ,
  4670. {
  4671. fill: "forwards",
  4672. duration: this.countdownMs,
  4673. easing: "linear"
  4674. }
  4675. );
  4676. */
  4677.  
  4678. let timingFn = 'linear';
  4679.  
  4680. const totalDuration = this.countdownDurationMs;
  4681.  
  4682. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  4683.  
  4684. // @ step timing [min. 0.2%]
  4685. let stepInterval = 0.2; // unit: %
  4686. if (totalDuration > 400000) stepInterval = 0.2;
  4687. else if (totalDuration > 200000) stepInterval = 0.5;
  4688. else if (totalDuration > 100000) stepInterval = 1;
  4689. else if (totalDuration > 50000) stepInterval = 2;
  4690. else if (totalDuration > 25000) stepInterval = 5;
  4691. else stepInterval = 5;
  4692.  
  4693. let numOfSteps = Math.round(100 / stepInterval);
  4694.  
  4695. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  4696. if (numOfSteps < 5) numOfSteps = 5;
  4697.  
  4698. timingFn = `steps(${numOfSteps}, end)`;
  4699.  
  4700. }
  4701.  
  4702.  
  4703. /** @type {Animation} */
  4704. const ae = animate.call(aElement,
  4705. [
  4706. { '--ticker-rtime': '100%' },
  4707. { '--ticker-rtime': '0%' }
  4708. ]
  4709. ,
  4710. {
  4711. fill: "forwards",
  4712. duration: totalDuration,
  4713. easing: timingFn
  4714. }
  4715. );
  4716.  
  4717. this._runnerAE = ae;
  4718.  
  4719. ae.onfinish = (event) => {
  4720. this.onfinish = null;
  4721. if (this._runnerAE !== ae) return;
  4722. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  4723. this._aeFinished(event);
  4724. }
  4725. }
  4726.  
  4727. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  4728.  
  4729. if (bq >= 0 && bq <= totalDuration) {
  4730.  
  4731. if (bq > totalDuration - 1) {
  4732. ae.currentTime = bq;
  4733. // setTimeout(() => {
  4734. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  4735. // }, 1);
  4736. } else {
  4737. ae.currentTime = bq;
  4738. }
  4739. } else {
  4740. console.warn('Error on setting _runnerAE.currentTime!');
  4741. }
  4742.  
  4743.  
  4744. aeConstructor = ae.constructor; // constructor is from iframe
  4745. return ae;
  4746. }
  4747. } else {
  4748. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  4749. // assume just time update
  4750. const ae = this._runnerAE;
  4751. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  4752. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  4753. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  4754. if (!(p >= 0 && p <= 100)) {
  4755. console.warn('incorrect time ratio', p);
  4756. } else {
  4757. // let u0 = p.toFixed(4) + '%'
  4758. /*
  4759. ae.effect.setKeyframes([
  4760. { '--ticker-rtime': u0 },
  4761. { '--ticker-rtime': '0%' }
  4762. ]);
  4763. ae.effect.updateTiming({ duration: this.countdownMs });
  4764. */
  4765. // ae.currentTime = 0;
  4766.  
  4767.  
  4768.  
  4769. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  4770. if (bq >= 0 && bq <= this.countdownDurationMs) {
  4771.  
  4772. this._runnerAE.currentTime = bq
  4773. } else {
  4774. console.warn('Error on setting _runnerAE.currentTime!');
  4775. }
  4776.  
  4777.  
  4778. ae.play();
  4779. return ae;
  4780. }
  4781. }
  4782. },
  4783.  
  4784. _aeFinished: function (event) {
  4785.  
  4786. if (this._r782) return;
  4787.  
  4788. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4789. this._throwOut();
  4790. return;
  4791. }
  4792.  
  4793. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4794.  
  4795. let lc = window.performance.now();
  4796. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  4797. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4798. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  4799. if (this.countdownMs > 76) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs, this, event); // just warning.
  4800.  
  4801. this.countdownMs = 0;
  4802. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null;
  4803.  
  4804. if (this.isAttached) {
  4805. let fastRemoved = false;
  4806. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  4807. // no animation if the video page is switched from background to foreground
  4808. // this.hostElement.style.display = 'none';
  4809. const id = (this.data || 0).id || 0;
  4810. if (!id) this.data = { id: 1 }
  4811. try {
  4812. this.requestRemoval();
  4813. fastRemoved = true;
  4814. } catch (e) {
  4815.  
  4816. }
  4817. }
  4818.  
  4819. if (!fastRemoved) {
  4820. "auto" === this.hostElement.style.width && this.setContainerWidth();
  4821. this.slideDown();
  4822. }
  4823. }
  4824.  
  4825.  
  4826.  
  4827. },
  4828.  
  4829.  
  4830. /** @type {()} */
  4831. _throwOut: function () {
  4832. this._r782 = 1;
  4833. Promise.resolve().then(() => {
  4834. if (typeof this.requestRemoval === 'function') {
  4835. const id = (this.data || 0).id;
  4836. if (!id) this.data = { id: 1 };
  4837. try {
  4838. this.requestRemoval();
  4839. } catch (e) { }
  4840. }
  4841. this.detached();
  4842. if (this.__dataClientsReady === true) this.__dataClientsReady = false;
  4843. if (this.__dataEnabled === true) this.__dataEnabled = false;
  4844. if (this.__dataReady === true) this.__dataReady = false;
  4845. this.data = null;
  4846. this.countdownMs = 0;
  4847. this.lastCountdownTimeMs = null;
  4848. const hm = this.hostElement || this;
  4849. if (hm.parentNode) hm.remove();
  4850. for (let t; t = hm.firstChild;) t.remove();
  4851. }).catch(e => {
  4852. console.warn(e);
  4853. });
  4854. },
  4855.  
  4856.  
  4857. // doTimerFnModification
  4858.  
  4859.  
  4860. /** @type {(a, b)} */
  4861. startCountdownForTimerFnModA: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4862. try {
  4863. // a.durationSec [s] => countdownMs [ms]
  4864. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4865. // lastCountdownTimeMs => raf ongoing
  4866. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4867.  
  4868. if (this._r782) return;
  4869.  
  4870. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4871. this._throwOut();
  4872. return;
  4873. }
  4874.  
  4875. // TimerFnModA
  4876.  
  4877. b = void 0 === b ? 0 : b;
  4878. if (void 0 !== a) {
  4879.  
  4880. this.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  4881. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs; // constant throughout the animation
  4882. if (!(this.lastCountdownTimeMs || this.isAnimationPaused)) {
  4883. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = performance.now()
  4884. this.rafId = 1
  4885. if (this._runnerAE) console.warn('Error in .startCountdown; this._runnerAE already created.')
  4886. this.detlaSincePausedSecs = 0;
  4887. const ae = this._makeAnimator();
  4888. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4889.  
  4890. // if (playerProgressChangedArg1 === null) {
  4891. // console.log('startCountdownForTimerFnModA', this.data)
  4892. // }
  4893.  
  4894. if (isPlayProgressTriggered && this.isAnimationPaused !== true && this.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__) {
  4895.  
  4896.  
  4897.  
  4898.  
  4899. this.playerProgressSec = lastPlayerProgress > 0 ? lastPlayerProgress : 0; // save the progress first
  4900. this.isAnimationPaused = true; // trigger isAnimationPausedChanged
  4901. this.detlaSincePausedSecs = 0;
  4902. this._forceNoDetlaSincePausedSecs783 = 1; // reset this.detlaSincePausedSecs = 0 when resumed
  4903.  
  4904. relayPromise = relayPromise || new PromiseExternal();
  4905.  
  4906. relayPromise.then(() => {
  4907. if (this.isAttached === true && this.countdownDurationMs > 0 && this.isAnimationPaused === true && this.isReplayPaused !== true) {
  4908. this.isAnimationPaused = false;
  4909. }
  4910. });
  4911.  
  4912.  
  4913. }
  4914.  
  4915.  
  4916.  
  4917. }
  4918. }
  4919.  
  4920. } catch (e) {
  4921. console.warn(e);
  4922. }
  4923.  
  4924. },
  4925.  
  4926.  
  4927.  
  4928. /** @type {(a, b)} */
  4929. startCountdownForTimerFnModT: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  4930. try {
  4931. // a.durationSec [s] => countdownMs [ms]
  4932. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  4933. // lastCountdownTimeMs => raf ongoing
  4934. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  4935.  
  4936. if (this._r782) return;
  4937.  
  4938. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4939. this._throwOut();
  4940. return;
  4941. }
  4942.  
  4943. // TimerFnModT
  4944.  
  4945. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  4946. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  4947. b = void 0 === b ? 0 : b;
  4948. void 0 !== a && (this.countdownMs = 1E3 * a,
  4949. this.countdownDurationMs = b ? 1E3 * b : this.countdownMs,
  4950. this.ratio = 1,
  4951. this.lastCountdownTimeMs || this.isAnimationPaused || (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = performance.now(),
  4952. this.rafId = rafHub.request(this.boundUpdateTimeout37_)))
  4953.  
  4954. } catch (e) {
  4955. console.warn(e);
  4956. }
  4957.  
  4958. },
  4959.  
  4960.  
  4961. /** @type {(a,)} */
  4962. updateTimeoutForTimerFnModA: function (a) {
  4963.  
  4964. try {
  4965.  
  4966. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  4967.  
  4968. if (this._r782) return;
  4969.  
  4970. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  4971. this._throwOut();
  4972. return;
  4973. }
  4974.  
  4975. // TimerFnModA
  4976.  
  4977. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  4978. if (this.lastCountdownTimeMs !== this._lastCountdownTimeMsX0) {
  4979. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  4980. }
  4981. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  4982. if (this.isAttached && this.countdownMs) {
  4983. this.lastCountdownTimeMs = a
  4984. const ae = this._makeAnimator(); // request raf
  4985. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  4986. } else {
  4987. (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null,
  4988. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  4989. this.slideDown()));
  4990. }
  4991.  
  4992. } catch (e) {
  4993. console.warn(e);
  4994. }
  4995.  
  4996.  
  4997. },
  4998.  
  4999. /** @type {(a,)} */
  5000. updateTimeoutForTimerFnModT: function (a) {
  5001.  
  5002. try {
  5003.  
  5004. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  5005.  
  5006. if (this._r782) return;
  5007.  
  5008. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5009. this._throwOut();
  5010. return;
  5011. }
  5012.  
  5013. // TimerFnModT
  5014.  
  5015. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  5016. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  5017. if (this.lastCountdownTimeMs !== this._lastCountdownTimeMsX0) {
  5018. this.countdownMs = Math.max(0, this.countdownMs - (a - (this.lastCountdownTimeMs || 0)));
  5019. }
  5020. // console.log(703, this.countdownMs)
  5021. this.ratio = this.countdownMs / this.countdownDurationMs;
  5022. this.isAttached && this.countdownMs ? (this.lastCountdownTimeMs = a,
  5023. this.rafId = rafHub.request(this.boundUpdateTimeout37_)) : (this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null,
  5024. this.isAttached && ("auto" === this.hostElement.style.width && this.setContainerWidth(),
  5025. this.slideDown()))
  5026.  
  5027.  
  5028. } catch (e) {
  5029. console.warn(e);
  5030. }
  5031. },
  5032.  
  5033. /** @type {(a,b)} */
  5034. isAnimationPausedChangedForTimerFnModA: function (a, b) {
  5035.  
  5036. if (this._r782) return;
  5037.  
  5038. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5039. this._throwOut();
  5040. return;
  5041. }
  5042. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  5043. this._forceNoDetlaSincePausedSecs783 = 0;
  5044.  
  5045. Promise.resolve().then(() => {
  5046.  
  5047. if (a) {
  5048.  
  5049. if (this._runnerAE && this._runnerAE.playState === 'running') {
  5050.  
  5051. this._runnerAE.pause()
  5052. let lc = window.performance.now();
  5053. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  5054. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  5055. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  5056. }
  5057.  
  5058. } else if (!a && b) {
  5059.  
  5060.  
  5061. if (forceNoDetlaSincePausedSecs783) this.detlaSincePausedSecs = 0;
  5062. a = this.detlaSincePausedSecs ? (this.lastCountdownTimeMs || 0) + 1000 * this.detlaSincePausedSecs : (this.lastCountdownTimeMs || 0);
  5063. this.detlaSincePausedSecs = 0;
  5064. this.updateTimeout(a);
  5065. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = window.performance.now();
  5066.  
  5067. }
  5068.  
  5069.  
  5070. }).catch(e => {
  5071. console.log(e);
  5072. });
  5073.  
  5074.  
  5075.  
  5076. },
  5077.  
  5078.  
  5079. /** @type {(a,b)} */
  5080. isAnimationPausedChangedForTimerFnModT: function (a, b) {
  5081.  
  5082. if (this._r782) return;
  5083.  
  5084. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5085. this._throwOut();
  5086. return;
  5087. }
  5088. let forceNoDetlaSincePausedSecs783 = this._forceNoDetlaSincePausedSecs783;
  5089. this._forceNoDetlaSincePausedSecs783 = 0;
  5090.  
  5091. Promise.resolve().then(() => {
  5092.  
  5093. // TimerFnModT
  5094.  
  5095. // ez++;
  5096. // if(ez> 1e9) ez=9;
  5097. if (!this.boundUpdateTimeout37_) this.boundUpdateTimeout37_ = this.updateTimeout.bind(this);
  5098. a ? rafHub.cancel(this.rafId) : !a && b && (a = this.lastCountdownTimeMs || 0,
  5099. this.detlaSincePausedSecs && (a = (this.lastCountdownTimeMs || 0) + 1E3 * this.detlaSincePausedSecs,
  5100. this.detlaSincePausedSecs = 0),
  5101. this.boundUpdateTimeout37_(a),
  5102. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = window.performance.now())
  5103.  
  5104.  
  5105. }).catch(e => {
  5106. console.log(e);
  5107. });
  5108.  
  5109.  
  5110.  
  5111. },
  5112.  
  5113.  
  5114. /** @type {(a,b)} */
  5115. computeContainerStyleForAnimatorEnabled: function (a, b) {
  5116.  
  5117. if (this._r782) return;
  5118.  
  5119. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  5120. this._throwOut();
  5121. return;
  5122. }
  5123.  
  5124. return (dummyValueForStyleReturn || (dummyValueForStyleReturn = genDummyValueForStyleReturn()));
  5125.  
  5126. },
  5127.  
  5128.  
  5129.  
  5130. /** @type {()} */
  5131. handlePauseReplayForPlaybackProgressState: function () {
  5132. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  5133.  
  5134. if (onPlayStateChangePromise) {
  5135.  
  5136. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  5137. const tid = ++this.rtu;
  5138.  
  5139. onPlayStateChangePromise.then(() => {
  5140. if (tid === this.rtu && !onPlayStateChangePromise) this.handlePauseReplay.apply(this, arguments);
  5141. });
  5142.  
  5143. return;
  5144. }
  5145.  
  5146. if (playerState !== 2) return;
  5147. if (this.isAttached) {
  5148. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  5149. const tid = ++this.rtk;
  5150. const tc = relayCount;
  5151. foregroundPromiseFn().then(() => {
  5152. if (tid === this.rtk && tc === relayCount && playerState === 2 && _playerState === playerState) {
  5153. this.handlePauseReplay66();
  5154. }
  5155.  
  5156. })
  5157. }
  5158. },
  5159.  
  5160. /** @type {()} */
  5161. handleResumeReplayForPlaybackProgressState: function () {
  5162. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  5163.  
  5164.  
  5165. if (onPlayStateChangePromise) {
  5166.  
  5167. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  5168. const tid = ++this.rtv;
  5169.  
  5170. onPlayStateChangePromise.then(() => {
  5171. if (tid === this.rtv && !onPlayStateChangePromise) this.handleResumeReplay.apply(this, arguments);
  5172. });
  5173.  
  5174. return;
  5175. }
  5176.  
  5177.  
  5178. if (playerState !== 1) return;
  5179. if (this.isAttached) {
  5180. const tc = relayCount;
  5181.  
  5182. relayPromise = relayPromise || new PromiseExternal();
  5183. relayPromise.then(() => {
  5184. if (relayCount > tc && playerState === 1 && _playerState === playerState) {
  5185. this.handleResumeReplay66();
  5186. }
  5187. });
  5188. }
  5189. },
  5190.  
  5191. /** @type {(a,)} */
  5192. handleReplayProgressForPlaybackProgressState: function (a) {
  5193. if (this.isAttached) {
  5194. const tid = ++this.rtk;
  5195. foregroundPromiseFn().then(() => {
  5196. if (tid === this.rtk) {
  5197. this.handleReplayProgress66(a);
  5198. }
  5199. })
  5200. }
  5201. }
  5202.  
  5203.  
  5204. }
  5205.  
  5206.  
  5207. for (const tag of tags) { // ##tag##
  5208. const dummy = document.createElement(tag);
  5209.  
  5210. const cProto = getProto(dummy);
  5211. if (!cProto || !cProto.attached) {
  5212. console.warn(`proto.attached for ${tag} is unavailable.`);
  5213. continue;
  5214. }
  5215.  
  5216. cProto.attached77 = cProto.attached;
  5217.  
  5218. cProto.attached = dProto.attachedForTickerInit;
  5219.  
  5220. let rafHackState = 0;
  5221.  
  5222. let isTimingFunctionHackable = false;
  5223.  
  5224. let urt = 0;
  5225.  
  5226. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  5227.  
  5228. // console.log('startCountdown', typeof cProto.startCountdown)
  5229. // console.log('updateTimeout', typeof cProto.updateTimeout)
  5230. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  5231.  
  5232. isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  5233.  
  5234. } else {
  5235. console.log(`Skip Timing Function Modification for ${tag}`);
  5236. continue;
  5237. }
  5238.  
  5239.  
  5240. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  5241.  
  5242. // cancelable - this.rafId < isAnimationPausedChanged >
  5243. rafHackState = 1;
  5244.  
  5245. if (isTimingFunctionHackable) {
  5246. rafHackState = 2;
  5247.  
  5248. } else {
  5249. rafHackState = 4;
  5250. }
  5251.  
  5252. }
  5253.  
  5254. const doAnimator = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  5255.  
  5256. const doRAFHack = rafHackState === 2;
  5257.  
  5258. cProto._throwOut = dProto._throwOut;
  5259.  
  5260. cProto._makeAnimator = doAnimator ? dProto._makeAnimator : null;
  5261.  
  5262. cProto._aeFinished = doAnimator ? dProto._aeFinished : null;
  5263.  
  5264.  
  5265. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  5266.  
  5267.  
  5268.  
  5269. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  5270. urt++;
  5271. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  5272. } else {
  5273. console.log('Error for setting cProto.handlePauseReplay', tag)
  5274. }
  5275.  
  5276. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handlePauseReplay.length === 0) {
  5277. urt++;
  5278. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  5279. } else {
  5280. console.log('Error for setting cProto.handleResumeReplay', tag)
  5281. }
  5282.  
  5283. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  5284. urt++;
  5285. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  5286. } else {
  5287. console.log('Error for setting cProto.handleReplayProgress', tag)
  5288. }
  5289.  
  5290.  
  5291.  
  5292. }
  5293.  
  5294. const ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED = ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX && urt === 3;
  5295. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  5296.  
  5297. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  5298.  
  5299. cProto.rtk = 0;
  5300. cProto.rtu = 0;
  5301. cProto.rtv = 0;
  5302.  
  5303. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  5304. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  5305.  
  5306. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  5307. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  5308.  
  5309. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  5310. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  5311.  
  5312. }
  5313.  
  5314. const doTimerFnModification = (doRAFHack || doAnimator);
  5315.  
  5316. if (doAnimator && windowShownAt < 0) {
  5317. windowShownAt = 0;
  5318. setupEventForWindowShownAt();
  5319. }
  5320.  
  5321. if (doTimerFnModification) {
  5322.  
  5323. cProto.startCountdown = (
  5324. doAnimator ? dProto.startCountdownForTimerFnModA : dProto.startCountdownForTimerFnModT
  5325. );
  5326.  
  5327. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  5328. cProto.updateTimeout = (
  5329. doAnimator ? dProto.updateTimeoutForTimerFnModA : dProto.updateTimeoutForTimerFnModT
  5330. );
  5331.  
  5332.  
  5333. // let ez = 0;
  5334. cProto.isAnimationPausedChanged = (
  5335. doAnimator ? dProto.isAnimationPausedChangedForTimerFnModA : dProto.isAnimationPausedChangedForTimerFnModT
  5336. );
  5337.  
  5338. }
  5339.  
  5340. if (doAnimator) {
  5341.  
  5342. const s = fnIntegrity(cProto.computeContainerStyle);
  5343. // 2.44.29 or 2.81.31
  5344. if (s === '2.44.29' || s === '2.81.31') {
  5345.  
  5346. // var ofb = da([""])
  5347. // pfb = da("background:linear-gradient(90deg, {,{ {,{ {,{);".split("{"))
  5348.  
  5349. // f.computeContainerStyle = function(a, b) {
  5350. // if (!a)
  5351. // return pi(ofb);
  5352. // var c = this.colorFromDecimal(a.startBackgroundColor);
  5353. // a = this.colorFromDecimal(a.endBackgroundColor);
  5354. // b = 100 * b + "%";
  5355. // return pi(pfb, c, c, b, a, b, a)
  5356. // }
  5357.  
  5358. } else {
  5359. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.44.29'));
  5360. }
  5361.  
  5362. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  5363.  
  5364. cProto.computeContainerStyle = dProto.computeContainerStyleForAnimatorEnabled;
  5365.  
  5366. }
  5367.  
  5368. if (doTimerFnModification === true) hasTimerModified = true;
  5369.  
  5370. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  5371. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  5372. }
  5373.  
  5374. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  5375. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  5376. }
  5377.  
  5378. }
  5379.  
  5380. const selector = tags.join(', ');
  5381. const elements = document.querySelectorAll(selector);
  5382. if (elements.length >= 1) {
  5383. for (const elm of elements) {
  5384. if (insp(elm).isAttached === true) {
  5385. fpTicker(elm);
  5386. }
  5387. }
  5388. }
  5389.  
  5390. console.log("[End]");
  5391. console.groupEnd();
  5392.  
  5393.  
  5394. }).catch(console.warn);
  5395.  
  5396. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  5397.  
  5398. mightFirstCheckOnYtInit();
  5399. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  5400. console.log("[Begin]");
  5401. (() => {
  5402.  
  5403. /* pending!!
  5404.  
  5405. handleLiveChatAction
  5406.  
  5407. removeTickerItemById
  5408.  
  5409. _itemsChanged
  5410. itemsChanged
  5411.  
  5412. handleMarkChatItemAsDeletedAction
  5413. handleMarkChatItemsByAuthorAsDeletedAction
  5414. handleRemoveChatItemByAuthorAction
  5415.  
  5416.  
  5417. */
  5418.  
  5419. const tag = "yt-live-chat-ticker-renderer"
  5420. const dummy = document.createElement(tag);
  5421.  
  5422. const cProto = getProto(dummy);
  5423. if (!cProto || !cProto.attached) {
  5424. console.warn(`proto.attached for ${tag} is unavailable.`);
  5425. return;
  5426. }
  5427.  
  5428. if (AMEND_TICKER_handleLiveChatAction
  5429. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && '|1.63.48|1.64.48|'.includes(`|${fnIntegrity(cProto.handleLiveChatAction)}|`)
  5430. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && fnIntegrity(cProto.handleLiveChatActions) === '1.23.12'
  5431. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  5432. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  5433. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  5434. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  5435. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  5436. ) {
  5437.  
  5438. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  5439.  
  5440. cProto.handleLiveChatActions = function (a) {
  5441. /**
  5442. *
  5443. f.handleLiveChatActions = function(a) {
  5444. a.length && (a.forEach(this.handleLiveChatAction, this),
  5445. this.updateHighlightedItem(),
  5446. this.shouldAnimateIn = !0)
  5447. }
  5448. *
  5449. */
  5450.  
  5451. if (a.length) {
  5452. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  5453. const len = a.length;
  5454. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  5455. // Primarily for the initial batch, this is due to replayBuffer._back.
  5456. const entries = [];
  5457. const entriesI = [];
  5458. for (let i = 0; i < len; i++) {
  5459. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  5460. if (item) {
  5461. const itemRendererKey = firstObjectKey(item);
  5462. const itemRenderer = item[itemRendererKey];
  5463. if (itemRenderer) {
  5464. let timestampUsec = getTimestampUsec(itemRenderer);
  5465. if (timestampUsec !== null) {
  5466. timestampUsec = parseInt(timestampUsec);
  5467. if (timestampUsec > 0) {
  5468. entriesI.push(i);
  5469. entries.push({ e: a[i], timestampUsec })
  5470. }
  5471. }
  5472. }
  5473. }
  5474. }
  5475. const mLen = entries.length;
  5476. if (mLen >= 2) {
  5477. entries.sort((a, b) => {
  5478. const diff = a.timestampUsec - b.timestampUsec;
  5479. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  5480. });
  5481. for (let j = 0; j < mLen; j++) {
  5482. const i = entriesI[j];
  5483. a[i] = entries[j].e;
  5484. }
  5485. }
  5486. entries.length = 0;
  5487. entriesI.length = 0;
  5488. }
  5489. for (const action of a) {
  5490. action.__batchId45__ = batchToken;
  5491. this.handleLiveChatAction(action);
  5492. }
  5493. }
  5494. }
  5495.  
  5496. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  5497.  
  5498.  
  5499.  
  5500. cProto._nszlv_ = 0;
  5501. cProto._stackedLCAs_ = null;
  5502. cProto._lastAddItem_ = null;
  5503. cProto._lastAddItemInStack_ = false;
  5504. cProto.handleLiveChatAction = function (a) {
  5505.  
  5506.  
  5507. /**
  5508. *
  5509. *
  5510. f.handleLiveChatAction = function(a) {
  5511. var b = C(a, xO)
  5512. , c = C(a, yO)
  5513. , d = C(a, o1a)
  5514. , e = C(a, p1a);
  5515. a = C(a, A1a);
  5516. b ? this.unshift("items", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : a && this.handleRemoveChatItemByAuthorAction(a)
  5517. }
  5518. *
  5519. */
  5520.  
  5521. // return this.handleLiveChatAction45(a)
  5522. const { addChatItemAction, addLiveChatTickerItemAction, markChatItemAsDeletedAction,
  5523. removeChatItemAction, markChatItemsByAuthorAsDeletedAction, removeChatItemByAuthorAction, __batchId45__ } = a
  5524.  
  5525. if (addChatItemAction) return;
  5526.  
  5527.  
  5528. const d = Date.now();
  5529.  
  5530.  
  5531. // console.log(Object.keys(a));
  5532.  
  5533. if (this._stackedLCAs_ === null) this._stackedLCAs_ = [];
  5534. const stackArr = this._stackedLCAs_;
  5535. let newStackEntry = null;
  5536. if (addLiveChatTickerItemAction) {
  5537. let isDuplicated = false;
  5538.  
  5539. const newItem = addLiveChatTickerItemAction.item;
  5540. const tickerType = firstObjectKey(newItem);
  5541. if (!tickerType) return;
  5542. const tickerItem = newItem[tickerType];
  5543. const tickerId = tickerItem.id;
  5544. if (!tickerId) return;
  5545.  
  5546. if (this._lastAddItem_ && this._lastAddItem_.id === tickerId) {
  5547. let prevTickerItem = null;
  5548. if (this._lastAddItemInStack_) {
  5549. const entry = stackArr[stackArr.length - 1]; // only consider the last entry
  5550. if (entry && entry.action === 'addItem') {
  5551. prevTickerItem = entry.data; // only consider the first item;
  5552. }
  5553. } else {
  5554. prevTickerItem = this.items[0]; // only consider the first item;
  5555. }
  5556. if (prevTickerItem && prevTickerItem[tickerType]) {
  5557. if (prevTickerItem[tickerType].id === tickerId) {
  5558. isDuplicated = true;
  5559. }
  5560. }
  5561. }
  5562. if (!isDuplicated) {
  5563. this._lastAddItem_ = tickerItem;
  5564. this._lastAddItemInStack_ = true;
  5565. // console.log('newItem', newItem)
  5566.  
  5567. const item = newItem;
  5568. const key = firstObjectKey(item);
  5569. if (key) {
  5570. const itemRenderer = item[key] || 0;
  5571. if (itemRenderer.fullDurationSec > 0) {
  5572. itemRenderer.__actionAt__ = d;
  5573. }
  5574. }
  5575.  
  5576.  
  5577. newStackEntry = { action: 'addItem', data: newItem };
  5578.  
  5579. } else {
  5580. console.log('handleLiveChatAction Repeated Item', tickerItem.id, tickerItem); // happen in both live and playback. Reason Unknown.
  5581. return;
  5582. }
  5583.  
  5584. } else {
  5585. markChatItemAsDeletedAction && (newStackEntry = { action: 'mcItemD', data: markChatItemAsDeletedAction });
  5586. removeChatItemAction && (newStackEntry = { action: 'removeItemById', data: removeChatItemAction.targetId });
  5587. markChatItemsByAuthorAsDeletedAction && (newStackEntry = { action: 'mcItemAD', data: markChatItemsByAuthorAsDeletedAction });
  5588. removeChatItemByAuthorAction && (newStackEntry = { action: 'removeItemA', data: removeChatItemByAuthorAction })
  5589. }
  5590.  
  5591.  
  5592. if (!newStackEntry) return;
  5593. stackArr.push(newStackEntry);
  5594.  
  5595.  
  5596. this._nszlv_++;
  5597. if (this._nszlv_ > 1e9) this._nszlv_ = 9;
  5598. const tid = this._nszlv_;
  5599.  
  5600. newStackEntry.__batchId45__ = __batchId45__ || '';
  5601. newStackEntry.dateTime = Date.now();
  5602.  
  5603.  
  5604. foregroundPromiseFn().then(() => {
  5605.  
  5606. if (tid !== this._nszlv_) return;
  5607. const dateNow = Date.now(); // time difference to shift animation start time shall be considered. (pending)
  5608. const stackArr = this._stackedLCAs_.slice(0);
  5609. this._stackedLCAs_.length = 0;
  5610. this._lastAddItemInStack_ = false;
  5611. let lastDateTime = 0;
  5612. let prevBatchId = '';
  5613. const addItems = [];
  5614. // const previousShouldAnimateIn = this.shouldAnimateIn;
  5615.  
  5616. const addItemsFx = () => {
  5617.  
  5618. if (addItems.length >= 1) {
  5619. const eArr = addItems.slice(0);
  5620. addItems.length = 0;
  5621. if (ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME) {
  5622.  
  5623. const arr = []; // size of arr <= size of eArr
  5624. const d = Date.now();
  5625. for (const item of eArr) {
  5626. const key = firstObjectKey(item);
  5627. if (key) {
  5628.  
  5629.  
  5630. const itemRenderer = item[key] || 0;
  5631. const { durationSec, fullDurationSec, __actionAt__ } = itemRenderer;
  5632. if (__actionAt__ > 0 && durationSec > 0 && fullDurationSec > 0) {
  5633.  
  5634.  
  5635. const offset = d - __actionAt__;
  5636. if (offset > 0 && typeof durationSec === 'number' && typeof fullDurationSec === 'number' && fullDurationSec >= durationSec) {
  5637. const adjustedDurationSec = durationSec - Math.floor(offset / 1000);
  5638. if (adjustedDurationSec < durationSec) { // prevent NaN
  5639. // console.log('adjustedDurationSec', adjustedDurationSec);
  5640. if (adjustedDurationSec > 0) {
  5641. // console.log('offset Sec', Math.floor(offset / 1000));
  5642. itemRenderer.durationSec = adjustedDurationSec;
  5643. } else {
  5644. // if adjustedDurationSec equal 0 or invalid
  5645. continue; // skip adding
  5646. }
  5647. }
  5648.  
  5649. }
  5650.  
  5651. }
  5652.  
  5653. if (fullDurationSec > 0 && durationSec < 1) continue; // fallback check
  5654.  
  5655.  
  5656.  
  5657. }
  5658. arr.push(item)
  5659. // arr.unshift(item);
  5660. }
  5661.  
  5662.  
  5663. // console.log(arr.slice(0))
  5664. this.unshift("items", ...arr);
  5665. } else {
  5666. this.unshift("items", ...eArr);
  5667. }
  5668. }
  5669. }
  5670.  
  5671. for (const entry of stackArr) {
  5672.  
  5673. const { action, data, dateTime, __batchId45__ } = entry;
  5674.  
  5675. const finishLastAction = (
  5676. (prevBatchId !== __batchId45__ && prevBatchId)
  5677. || (dateNow - lastDateTime >= 1000 && dateNow - dateTime < 1000)
  5678. );
  5679.  
  5680. const addPrevItems = addItems.length >= 1 && (finishLastAction || action !== 'addItem');
  5681. lastDateTime = dateTime;
  5682. prevBatchId = __batchId45__;
  5683.  
  5684. // if (dateNow - dateTime >= 1000 && this.shouldAnimateIn) this.shouldAnimateIn = false;
  5685.  
  5686.  
  5687. if (addPrevItems) {
  5688. addItemsFx();
  5689. }
  5690. // if (finishLastAction) {
  5691. // this.updateHighlightedItem();
  5692. // if (!this.shouldAnimateIn) this.shouldAnimateIn = true;
  5693. // }
  5694.  
  5695.  
  5696. if (action === 'addItem') addItems.unshift(data);
  5697. else if (action === 'mcItemD') this.handleMarkChatItemAsDeletedAction(data);
  5698. else if (action === 'removeItemById') this.removeTickerItemById(data);
  5699. else if (action === 'mcItemAD') this.handleMarkChatItemsByAuthorAsDeletedAction(data);
  5700. else if (action === 'removeItemA') this.handleRemoveChatItemByAuthorAction(data);
  5701.  
  5702. }
  5703.  
  5704.  
  5705. // if (previousShouldAnimateIn && !this.shouldAnimateIn) this.shouldAnimateIn = true;
  5706.  
  5707. addItemsFx();
  5708.  
  5709. // if (prevBatchId || dateNow - lastDateTime >= 1000) {
  5710. // this.updateHighlightedItem();
  5711. // if (!this.shouldAnimateIn) this.shouldAnimateIn = true;
  5712. // }
  5713.  
  5714. })
  5715.  
  5716. }
  5717.  
  5718. console.log("AMEND_TICKER_handleLiveChatAction - OK");
  5719. } else {
  5720. console.log("AMEND_TICKER_handleLiveChatAction - NG");
  5721. }
  5722.  
  5723. if (RAF_FIX_keepScrollClamped) {
  5724.  
  5725. // to be improved
  5726.  
  5727. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  5728.  
  5729. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  5730. cProto.keepScrollClamped = function () {
  5731. this._bound_keepScrollClamped = this._bound_keepScrollClamped || this.keepScrollClamped.bind(this);
  5732. this.scrollClampRaf = requestAnimationFrame(this._bound_keepScrollClamped);
  5733. this.maybeClampScroll()
  5734. }
  5735.  
  5736. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  5737. } else {
  5738.  
  5739. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  5740. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  5741. }
  5742.  
  5743. }
  5744.  
  5745.  
  5746. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function' && fnIntegrity(cProto.startScrolling) === '1.43.31' && fnIntegrity(cProto.scrollIncrementally) === '1.82.43') {
  5747. // to be replaced by animator
  5748.  
  5749. cProto.startScrolling = function (a) {
  5750. this.scrollStopHandle && this.cancelAsync(this.scrollStopHandle);
  5751. this.asyncHandle && cancelAnimationFrame(this.asyncHandle);
  5752. this.lastFrameTimestamp = this.scrollStartTime = performance.now();
  5753. this.scrollRatePixelsPerSecond = a;
  5754. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5755. this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally)
  5756. };
  5757.  
  5758. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  5759.  
  5760. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  5761. const b = a - (this.lastFrameTimestamp || 0);
  5762. const rate = this.scrollRatePixelsPerSecond
  5763. const q = b / 1E3 * (rate || 0);
  5764.  
  5765. const sl = this.$.items.scrollLeft;
  5766. // console.log(rate, sl, q)
  5767. if (this.lastFrameTimestamp == this.scrollStartTime) {
  5768.  
  5769. } else if (q > -1e-5 && q < 1e-5) {
  5770.  
  5771. } else {
  5772. let cond1 = sl > 0 && rate > 0 && q > 0;
  5773. let cond2 = sl > 0 && rate < 0 && q < 0;
  5774. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  5775. if (cond1 || cond2 || cond3) {
  5776. this.$.items.scrollLeft += q;
  5777. this.maybeClampScroll();
  5778. this.updateArrows();
  5779. }
  5780. }
  5781.  
  5782. this.lastFrameTimestamp = a;
  5783. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5784. 0 < this.$.items.scrollLeft || rate && 0 < rate ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  5785. } : function (a) {
  5786. const b = a - (this.lastFrameTimestamp || 0);
  5787. this.$.items.scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  5788. this.maybeClampScroll();
  5789. this.updateArrows();
  5790. this.lastFrameTimestamp = a;
  5791. this._bound_scrollIncrementally = this._bound_scrollIncrementally || this.scrollIncrementally.bind(this);
  5792. 0 < this.$.items.scrollLeft || this.scrollRatePixelsPerSecond && 0 < this.scrollRatePixelsPerSecond ? this.asyncHandle = requestAnimationFrame(this._bound_scrollIncrementally) : this.stopScrolling()
  5793. };
  5794.  
  5795. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  5796. } else {
  5797. assertor(() => fnIntegrity(cProto.startScrolling, '1.43.31'));
  5798. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.82.43'));
  5799. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  5800. }
  5801.  
  5802.  
  5803. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  5804.  
  5805. cProto.attached37 = cProto.attached;
  5806. cProto.detached37 = cProto.detached;
  5807.  
  5808. let naohzId = 0;
  5809. cProto.__naohzId__ = 0;
  5810. cProto.attached = function () {
  5811. Promise.resolve().then(() => {
  5812.  
  5813. const hostElement = this.hostElement || this;
  5814. if (!(hostElement instanceof HTMLElement)) return;
  5815. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  5816. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  5817. // or #chat-messages
  5818. if (!ironPage) return;
  5819.  
  5820. if (this.__naohzId__) removeEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5821. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  5822. this.__naohzId__ = ++naohzId;
  5823. ironPage.setAttribute('naohz', `${+this.__naohzId__}`);
  5824.  
  5825. addEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5826.  
  5827. });
  5828. return this.attached37.apply(this, arguments);
  5829. };
  5830. cProto.detached = function () {
  5831. Promise.resolve().then(() => {
  5832.  
  5833. const ironPage = document.querySelector(`iron-pages[naohz="${+this.__naohzId__}"]`);
  5834. if (!ironPage) return;
  5835.  
  5836. removeEventListener.call(ironPage, 'click', this.messageBoxClickHandlerForFade, { capture: false, passive: true });
  5837.  
  5838. });
  5839. return this.detached37.apply(this, arguments);
  5840. };
  5841.  
  5842. const clickFade = (u) => {
  5843. u.click();
  5844. };
  5845. cProto.messageBoxClickHandlerForFade = async (evt) => {
  5846.  
  5847. const target = (evt || 0).target || 0;
  5848. if (!target) return;
  5849.  
  5850. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  5851. const is = p.is;
  5852. if (typeof is === 'string' && is) {
  5853.  
  5854. if (is === 'yt-live-chat-pinned-message-renderer') {
  5855. return;
  5856. }
  5857. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  5858. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  5859. if (fade) {
  5860. Promise.resolve(fade).then(clickFade);
  5861. evt && evt.stopPropagation();
  5862. }
  5863. return;
  5864. }
  5865. if (is !== 'yt-live-chat-ticker-renderer') {
  5866. if (is.startsWith('yt-live-chat-ticker-')) return;
  5867. if (!is.endsWith('-renderer')) return;
  5868. }
  5869.  
  5870. } else {
  5871. if ((p.nodeName || '').includes('BUTTON')) return;
  5872. }
  5873.  
  5874. }
  5875. };
  5876.  
  5877. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  5878.  
  5879. } else {
  5880. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  5881. }
  5882.  
  5883.  
  5884. })();
  5885.  
  5886. console.log("[End]");
  5887.  
  5888. console.groupEnd();
  5889.  
  5890. }).catch(console.warn);
  5891.  
  5892.  
  5893.  
  5894. if (ENABLE_RAF_HACK_INPUT_RENDERER || DELAY_FOCUSEDCHANGED) {
  5895.  
  5896. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  5897.  
  5898. mightFirstCheckOnYtInit();
  5899. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  5900. console.log("[Begin]");
  5901. (() => {
  5902.  
  5903.  
  5904.  
  5905. const tag = "yt-live-chat-message-input-renderer"
  5906. const dummy = document.createElement(tag);
  5907.  
  5908. const cProto = getProto(dummy);
  5909. if (!cProto || !cProto.attached) {
  5910. console.warn(`proto.attached for ${tag} is unavailable.`);
  5911. return;
  5912. }
  5913.  
  5914.  
  5915. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  5916.  
  5917. let doHack = false;
  5918. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  5919.  
  5920. // not cancellable
  5921.  
  5922.  
  5923. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  5924.  
  5925. }
  5926.  
  5927. if (doHack) {
  5928.  
  5929. cProto.handleTimeout = function (a) {
  5930. console.log('cProto.handleTimeout', tag)
  5931. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  5932. this.timeoutDurationMs = this.timeoutMs = a;
  5933. this.countdownRatio = 1;
  5934. 0 === this.lastTimeoutTimeMs && rafHub.request(this.boundUpdateTimeout38_)
  5935. };
  5936. cProto.updateTimeout = function (a) {
  5937. console.log('cProto.updateTimeout', tag)
  5938. if (!this.boundUpdateTimeout38_) this.boundUpdateTimeout38_ = this.updateTimeout.bind(this);
  5939. this.lastTimeoutTimeMs && (this.timeoutMs = Math.max(0, this.timeoutMs - (a - this.lastTimeoutTimeMs)),
  5940. this.countdownRatio = this.timeoutMs / this.timeoutDurationMs);
  5941. this.isAttached && this.timeoutMs ? (this.lastTimeoutTimeMs = a,
  5942. rafHub.request(this.boundUpdateTimeout38_)) : this.lastTimeoutTimeMs = 0
  5943. };
  5944.  
  5945. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  5946. } else {
  5947.  
  5948. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  5949. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  5950.  
  5951. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  5952. }
  5953.  
  5954.  
  5955. }
  5956.  
  5957. if (DELAY_FOCUSEDCHANGED && typeof cProto.onFocusedChanged === 'function' && cProto.onFocusedChanged.length === 1 && !cProto.onFocusedChanged372) {
  5958. cProto.onFocusedChanged372 = cProto.onFocusedChanged;
  5959. cProto.onFocusedChanged = function (a) {
  5960. Promise.resolve().then(() => {
  5961. if (this.isAttached === true) this.onFocusedChanged372(a);
  5962. }).catch(console.warn);
  5963. }
  5964. }
  5965.  
  5966. })();
  5967.  
  5968. console.log("[End]");
  5969.  
  5970. console.groupEnd();
  5971.  
  5972.  
  5973. })
  5974.  
  5975. }
  5976.  
  5977.  
  5978. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  5979.  
  5980.  
  5981. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  5982.  
  5983. mightFirstCheckOnYtInit();
  5984. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  5985. console.log("[Begin]");
  5986. (() => {
  5987.  
  5988. const tag = "yt-emoji-picker-renderer"
  5989. const dummy = document.createElement(tag);
  5990.  
  5991. const cProto = getProto(dummy);
  5992. if (!cProto || !cProto.attached) {
  5993. console.warn(`proto.attached for ${tag} is unavailable.`);
  5994. return;
  5995. }
  5996.  
  5997. let doHack = false;
  5998. if (typeof cProto.animateScroll_ === 'function') {
  5999.  
  6000. // not cancellable
  6001. console.log('animateScroll_', typeof cProto.animateScroll_)
  6002.  
  6003. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  6004.  
  6005. }
  6006.  
  6007. if (doHack) {
  6008.  
  6009. const querySelector = HTMLElement.prototype.querySelector;
  6010. const U = (element) => ({
  6011. querySelector: (selector) => querySelector.call(element, selector)
  6012. });
  6013.  
  6014. cProto.animateScroll_ = function (a) {
  6015. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  6016. if (!this.boundAnimateScroll39_) this.boundAnimateScroll39_ = this.animateScroll_.bind(this);
  6017. this.lastAnimationTime_ || (this.lastAnimationTime_ = a);
  6018. a -= this.lastAnimationTime_;
  6019. 200 > a ? (U(this.hostElement).querySelector("#categories").scrollTop = this.animationStart_ + (this.animationEnd_ - this.animationStart_) * a / 200,
  6020. rafHub.request(this.boundAnimateScroll39_)) : (null != this.animationEnd_ && (U(this.hostElement).querySelector("#categories").scrollTop = this.animationEnd_),
  6021. this.animationEnd_ = this.animationStart_ = null,
  6022. this.lastAnimationTime_ = 0);
  6023. this.updateButtons_()
  6024. }
  6025.  
  6026. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  6027. } else {
  6028.  
  6029. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  6030. }
  6031.  
  6032. })();
  6033.  
  6034. console.log("[End]");
  6035.  
  6036. console.groupEnd();
  6037. });
  6038. }
  6039.  
  6040. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  6041.  
  6042.  
  6043. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  6044.  
  6045. mightFirstCheckOnYtInit();
  6046. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  6047. console.log("[Begin]");
  6048. (() => {
  6049.  
  6050. const tag = "yt-live-chat-docked-message"
  6051. const dummy = document.createElement(tag);
  6052.  
  6053. const cProto = getProto(dummy);
  6054. if (!cProto || !cProto.attached) {
  6055. console.warn(`proto.attached for ${tag} is unavailable.`);
  6056. return;
  6057. }
  6058.  
  6059. let doHack = false;
  6060. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  6061.  
  6062. // cancelable - this.intersectRAF <detached>
  6063. // yt-live-chat-docked-message
  6064. // boundCheckIntersections <-> checkIntersections
  6065. // onDockableMessagesChanged
  6066. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  6067.  
  6068. console.log('detached', typeof cProto.detached)
  6069. console.log('checkIntersections', typeof cProto.checkIntersections)
  6070. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  6071.  
  6072. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  6073.  
  6074. }
  6075.  
  6076. if (doHack) {
  6077.  
  6078. cProto.checkIntersections = function () {
  6079. // console.log('cProto.checkIntersections', tag)
  6080. if (this.dockableMessages.length) {
  6081. this.intersectRAF = rafHub.request(this.boundCheckIntersections);
  6082. let a = this.dockableMessages[0]
  6083. , b = this.hostElement.getBoundingClientRect();
  6084. a = a.getBoundingClientRect();
  6085. let c = a.top - b.top
  6086. , d = 8 >= c;
  6087. c = 8 >= c - this.hostElement.clientHeight;
  6088. if (d) {
  6089. let e;
  6090. for (; d;) {
  6091. e = this.dockableMessages.shift();
  6092. d = this.dockableMessages[0];
  6093. if (!d)
  6094. break;
  6095. d = d.getBoundingClientRect();
  6096. c = d.top - b.top;
  6097. let f = 8 >= c;
  6098. if (8 >= c - a.height)
  6099. if (f)
  6100. a = d;
  6101. else
  6102. return;
  6103. d = f
  6104. }
  6105. this.dock(e)
  6106. } else
  6107. c && this.dockedItem && this.clear()
  6108. } else
  6109. this.intersectRAF = 0
  6110. }
  6111.  
  6112. cProto.onDockableMessagesChanged = function () {
  6113. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  6114. this.dockableMessages.length && !this.intersectRAF && (this.intersectRAF = rafHub.request(this.boundCheckIntersections))
  6115. }
  6116.  
  6117. cProto.detached = function () {
  6118. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  6119. }
  6120.  
  6121. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  6122. } else {
  6123.  
  6124. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  6125. }
  6126.  
  6127. })();
  6128.  
  6129. console.log("[End]");
  6130.  
  6131. console.groupEnd();
  6132.  
  6133. }).catch(console.warn);
  6134.  
  6135. }
  6136.  
  6137. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  6138.  
  6139.  
  6140. customElements.whenDefined("yt-img-shadow").then(() => {
  6141.  
  6142. mightFirstCheckOnYtInit();
  6143. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  6144. console.log("[Begin]");
  6145. (() => {
  6146.  
  6147. const tag = "yt-img-shadow"
  6148. const dummy = document.createElement(tag);
  6149.  
  6150. const cProto = getProto(dummy);
  6151. if (!cProto || !cProto.attached) {
  6152. console.warn(`proto.attached for ${tag} is unavailable.`);
  6153. return;
  6154. }
  6155.  
  6156. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  6157.  
  6158. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  6159. cProto.thumbnailChanged_ = function (a) {
  6160.  
  6161. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  6162. if (!this.oldThumbnail_ && !this.thumbnail) return;
  6163.  
  6164. return this.thumbnailChanged66_.apply(this, arguments)
  6165.  
  6166. }
  6167. console.log("cProto.thumbnailChanged_ - OK");
  6168.  
  6169. } else {
  6170. console.log("cProto.thumbnailChanged_ - NG");
  6171.  
  6172. }
  6173. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  6174.  
  6175. cProto.setSrc66_ = cProto.setSrc_;
  6176. cProto.setSrc_ = function (a) {
  6177. if ((((this || 0).$ || 0).img || 0).src === a) return;
  6178. return this.setSrc66_.apply(this, arguments)
  6179. }
  6180.  
  6181. console.log("cProto.setSrc_ - OK");
  6182. } else {
  6183.  
  6184. console.log("cProto.setSrc_ - NG");
  6185. }
  6186.  
  6187. })();
  6188.  
  6189. console.log("[End]");
  6190.  
  6191. console.groupEnd();
  6192.  
  6193. }).catch(console.warn);
  6194.  
  6195. }
  6196.  
  6197. if (FIX_THUMBNAIL_DATACHANGED) {
  6198.  
  6199.  
  6200.  
  6201. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  6202.  
  6203. mightFirstCheckOnYtInit();
  6204. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  6205. console.log("[Begin]");
  6206. (() => {
  6207.  
  6208. const tag = "yt-live-chat-author-badge-renderer"
  6209. const dummy = document.createElement(tag);
  6210.  
  6211. const cProto = getProto(dummy);
  6212. if (!cProto || !cProto.attached) {
  6213. console.warn(`proto.attached for ${tag} is unavailable.`);
  6214. return;
  6215. }
  6216.  
  6217.  
  6218. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|1.160.97|1.159.97|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  6219.  
  6220.  
  6221.  
  6222. cProto.dataChanged86 = cProto.dataChanged;
  6223. cProto.dataChanged = function (a) {
  6224.  
  6225. /*
  6226.  
  6227. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  6228. b.removeChild(b.firstChild);
  6229. if (a)
  6230. if (a.icon) {
  6231. var c = document.createElement("yt-icon");
  6232. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  6233. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  6234. b.appendChild(c)
  6235. } else if (a.customThumbnail) {
  6236. c = document.createElement("img");
  6237. var d;
  6238. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  6239. b.appendChild(c),
  6240. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  6241. }
  6242.  
  6243. */
  6244.  
  6245. const image = ((this || 0).$ || 0).image
  6246. if (image && a && image.firstElementChild) {
  6247. let exisiting = image.firstElementChild;
  6248. if (exisiting === image.lastElementChild) {
  6249.  
  6250.  
  6251. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  6252.  
  6253. let c = exisiting;
  6254. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  6255. if (c.icon !== "yt-sys-icons:shield-filled") c.icon = "yt-sys-icons:shield-filled";
  6256. if (c.defaultToFilled !== true) c.defaultToFilled = true;
  6257. } else {
  6258. let p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  6259. if (c.icon !== p) c.icon = p;
  6260. if (c.defaultToFilled !== false) c.defaultToFilled = false;
  6261. }
  6262. return;
  6263.  
  6264.  
  6265. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  6266.  
  6267. let c = exisiting;
  6268. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  6269.  
  6270. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  6271. return;
  6272. }
  6273. /*
  6274.  
  6275. var d;
  6276. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  6277.  
  6278.  
  6279. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  6280. */
  6281. }
  6282.  
  6283.  
  6284. }
  6285. }
  6286. return this.dataChanged86.apply(this, arguments)
  6287.  
  6288. }
  6289. console.log("cProto.dataChanged - OK");
  6290.  
  6291. } else {
  6292. assertor(() => fnIntegrity(cProto.dataChanged, '1.160.97'));
  6293. console.log("cProto.dataChanged - NG");
  6294.  
  6295. }
  6296.  
  6297. })();
  6298.  
  6299. console.log("[End]");
  6300.  
  6301. console.groupEnd();
  6302.  
  6303. }).catch(console.warn);
  6304.  
  6305.  
  6306. }
  6307.  
  6308.  
  6309. if (FIX_TOOLTIP_DISPLAY) {
  6310.  
  6311.  
  6312. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  6313.  
  6314. mightFirstCheckOnYtInit();
  6315. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  6316. console.log("[Begin]");
  6317. (() => {
  6318.  
  6319. const tag = "tp-yt-paper-tooltip"
  6320. const dummy = document.createElement(tag);
  6321.  
  6322. const cProto = getProto(dummy);
  6323. if (!cProto || !cProto.attached) {
  6324. console.warn(`proto.attached for ${tag} is unavailable.`);
  6325. return;
  6326. }
  6327.  
  6328. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  6329.  
  6330. cProto._readyClients43 = cProto._readyClients;
  6331. cProto._readyClients = function () {
  6332. let r = cProto._readyClients43.apply(this, arguments);
  6333. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  6334. return r;
  6335. }
  6336.  
  6337. console.log("_readyClients - OK");
  6338.  
  6339. } else {
  6340. console.log("_readyClients - NG");
  6341.  
  6342. }
  6343.  
  6344. if (typeof cProto.show === 'function' && !cProto.show17) {
  6345. cProto.show17 = cProto.show;
  6346. cProto.show = function () {
  6347.  
  6348. let r = this.show17.apply(this, arguments);
  6349. this._showing === true && Promise.resolve().then(() => {
  6350. const tooltip = (this.$ || 0).tooltip;
  6351.  
  6352. if (tooltip && tooltip.firstElementChild === null) {
  6353. let text = tooltip.textContent;
  6354. if (typeof text === 'string' && text.length >= 2) {
  6355. tooltip.textContent = text.trim();
  6356. }
  6357. }
  6358. }).catch(console.warn)
  6359. return r;
  6360. }
  6361.  
  6362. console.log("trim tooltip content - OK");
  6363.  
  6364. } else {
  6365. console.log("trim tooltip content - NG");
  6366.  
  6367. }
  6368.  
  6369. /*
  6370. cProto.updatePosition61 = cProto.updatePosition;
  6371.  
  6372.  
  6373. cProto.updatePosition = function () {
  6374.  
  6375.  
  6376. if (this._target && this.offsetParent) {
  6377. var a = this.offset;
  6378. 14 != this.marginTop && 14 == this.offset && (a = this.marginTop);
  6379. var b = this.offsetParent.getBoundingClientRect()
  6380. , c = this._target.getBoundingClientRect()
  6381. , d = this.getBoundingClientRect()
  6382. , e = (c.width - d.width) / 2
  6383. , h = (c.height - d.height) / 2
  6384. , l = c.left - b.left
  6385. , m = c.top - b.top;
  6386. switch (this.position) {
  6387. case "top":
  6388. var p = l + e;
  6389. var q = m - d.height - a;
  6390. break;
  6391. case "bottom":
  6392. p = l + e;
  6393. q = m + c.height + a;
  6394. break;
  6395. case "left":
  6396. p = l - d.width - a;
  6397. q = m + h;
  6398. break;
  6399. case "right":
  6400. p = l + c.width + a,
  6401. q = m + h;
  6402. }
  6403.  
  6404. if(this.ascee) {
  6405. this.fitToVisibleBounds = false;
  6406. }
  6407. this.fitToVisibleBounds ? (b.left + p + d.width > window.innerWidth ? (this.style.right = "0px",
  6408. this.style.left = "auto") : (this.style.left = Math.max(0, p) + "px",
  6409. this.style.right = "auto"),
  6410. b.top + q + d.height > window.innerHeight ? (this.style.bottom = b.height + "px",
  6411. this.style.top = "auto") : (this.style.top = Math.max(-b.top, q) + "px",
  6412. this.style.bottom = "auto")) : (this.style.left = p + "px",
  6413. this.style.top = q + "px")
  6414. }
  6415. }
  6416.  
  6417. cProto.updateStyles61 = cProto.updateStyles;
  6418. cProto.updateStyles= function(){
  6419. if(this.ascee) return;
  6420. return this.updateStyles61.apply(this,arguments);
  6421. }
  6422. */
  6423.  
  6424.  
  6425. })();
  6426.  
  6427. console.log("[End]");
  6428.  
  6429. console.groupEnd();
  6430.  
  6431. }).catch(console.warn);
  6432.  
  6433.  
  6434.  
  6435. }
  6436.  
  6437.  
  6438.  
  6439. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  6440.  
  6441.  
  6442. const hookDocumentMouseDownSetupFn = () => {
  6443.  
  6444.  
  6445.  
  6446. let muzTimestamp = 0;
  6447. let nszDropdown = null;
  6448.  
  6449.  
  6450.  
  6451. const handlerObject = {
  6452.  
  6453. // mdHandler282 : function (evt) {
  6454. // // console.log(evt, 1, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6455. // if (!evt || !evt.isTrusted) return;
  6456. // muzTimestamp = 0;
  6457. // nszDropdown = null;
  6458.  
  6459. // const hostElement = this.hostElement || this;
  6460. // if (!evt || !evt.isTrusted || !hostElement.hasAttribute('menu-visible')) return;
  6461. // if (!hostElement.contains(evt.target)) return;
  6462. // let targetDropDown = null;
  6463. // for(const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')){
  6464. // if(dropdown && dropdown.positionTarget && hostElement.contains( dropdown.positionTarget)){
  6465. // targetDropDown = dropdown;
  6466. // }
  6467. // }
  6468. // if ((nszDropdown = targetDropDown)) {
  6469. // muzTimestamp = Date.now();
  6470. // evt.stopImmediatePropagation();
  6471. // evt.stopPropagation();
  6472. // }
  6473.  
  6474. // },
  6475.  
  6476.  
  6477. muHandler282: function (evt) {
  6478. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6479. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6480. const dropdown = nszDropdown;
  6481. muzTimestamp = 0;
  6482. nszDropdown = null;
  6483.  
  6484. const kurMPC = kRef(currentMenuPivotWR) || 0;
  6485. const hostElement = kurMPC.hostElement || kurMPC;
  6486. if (!hostElement.hasAttribute('menu-visible')) return;
  6487.  
  6488. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  6489. if (chatBanner) return;
  6490.  
  6491. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  6492.  
  6493. /*
  6494. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6495. if(parentButton) return;
  6496. */
  6497.  
  6498. muzTimestamp = Date.now();
  6499. evt.stopImmediatePropagation();
  6500. evt.stopPropagation();
  6501. Promise.resolve(dropdown).then((dropdown) => {
  6502. dropdown.cancel();
  6503. });
  6504. // document.body.click();
  6505. }
  6506.  
  6507. },
  6508.  
  6509. mlHandler282: function (evt) {
  6510. muzTimestamp = 0;
  6511. nszDropdown = null;
  6512. },
  6513.  
  6514. ckHandler282: function (evt) {
  6515. // console.log(evt, 3, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6516.  
  6517. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6518. if (Date.now() - muzTimestamp < 40) {
  6519.  
  6520. /*
  6521. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6522. if(parentButton) return;
  6523. */
  6524.  
  6525. muzTimestamp = Date.now();
  6526. evt.stopImmediatePropagation();
  6527. evt.stopPropagation();
  6528. }
  6529.  
  6530. },
  6531.  
  6532. tapHandler282: function (evt) {
  6533. // console.log(evt, 2, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  6534.  
  6535. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  6536. if (Date.now() - muzTimestamp < 40) {
  6537.  
  6538. /*
  6539. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6540. if(parentButton) return;
  6541. */
  6542.  
  6543. muzTimestamp = Date.now();
  6544. evt.stopImmediatePropagation();
  6545. evt.stopPropagation();
  6546. }
  6547.  
  6548. },
  6549.  
  6550.  
  6551. handleEvent(evt) {
  6552.  
  6553.  
  6554. if (evt) {
  6555. const kurMPC = kRef(currentMenuPivotWR) || 0;
  6556. const cnt = insp(kurMPC);
  6557. const hostElement = cnt.hostElement || cnt;
  6558. if (!cnt || cnt.isAttached !== true || hostElement.isConnected !== true) return;
  6559. switch (evt.type) {
  6560. // case 'mousedown':
  6561. // return this.mdHandler282.call(kurMPC, evt);
  6562. case 'mouseup':
  6563. return this.muHandler282(evt);
  6564. case 'mouseleave':
  6565. return this.mlHandler282(evt);
  6566. case 'tap':
  6567. return this.tapHandler282(evt);
  6568. case 'click':
  6569. return this.ckHandler282(evt);
  6570. }
  6571. }
  6572.  
  6573. }
  6574.  
  6575.  
  6576.  
  6577. }
  6578.  
  6579. document.addEventListener('mousedown', function (evt) {
  6580.  
  6581. if (!evt || !evt.isTrusted || !evt.target) return;
  6582.  
  6583.  
  6584.  
  6585. muzTimestamp = 0;
  6586. nszDropdown = null;
  6587.  
  6588. /*
  6589. const parentButton = HTMLElement.prototype.closest.call(evt.target, 'button, yt-icon, yt-icon-shape, icon-shape');
  6590. if(parentButton){
  6591. const kurMPC = HTMLElement.prototype.closest.call(parentButton, '[whole-message-clickable]') || 0;
  6592. if(kurMPC){
  6593. evt.preventDefault();
  6594. evt.stopImmediatePropagation();
  6595. evt.stopPropagation();
  6596. }
  6597. return;
  6598. }
  6599. */
  6600.  
  6601. /** @type {HTMLElement | null} */
  6602. const kurMP = kRef(currentMenuPivotWR);
  6603. if (!kurMP) return;
  6604. const kurMPC = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0;
  6605.  
  6606. if (!kurMPC || !kurMPC.hasAttribute('whole-message-clickable')) return;
  6607.  
  6608. if (!kurMPC.isClickableChatRow111 || !kurMPC.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPC, evt.target)) return;
  6609.  
  6610. const chatBanner = HTMLElement.prototype.closest.call(kurMPC, 'yt-live-chat-banner-renderer') || 0;
  6611. if (chatBanner) return;
  6612.  
  6613.  
  6614. let targetDropDown = null;
  6615. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  6616. if (dropdown && dropdown.positionTarget === kurMP) {
  6617. targetDropDown = dropdown;
  6618. }
  6619. }
  6620.  
  6621. if (!targetDropDown) return;
  6622.  
  6623.  
  6624. /*
  6625. if (parentButton) {
  6626. evt.preventDefault();
  6627. evt.stopImmediatePropagation();
  6628. evt.stopPropagation();
  6629. currentMenuPivotWR = mWeakRef(kurMPC);
  6630. return;
  6631. }
  6632. */
  6633.  
  6634. if ((nszDropdown = targetDropDown)) {
  6635. muzTimestamp = Date.now();
  6636. evt.stopImmediatePropagation();
  6637. evt.stopPropagation();
  6638. currentMenuPivotWR = mWeakRef(kurMPC);
  6639.  
  6640. const listenOpts = { capture: true, passive: false, once: true };
  6641.  
  6642. // remove unexcecuted eventHandler
  6643. document.removeEventListener('mouseup', handlerObject, listenOpts);
  6644. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  6645. document.removeEventListener('tap', handlerObject, listenOpts);
  6646. document.removeEventListener('click', handlerObject, listenOpts);
  6647.  
  6648. // inject one time eventHandler to by pass events
  6649. document.addEventListener('mouseup', handlerObject, listenOpts);
  6650. document.addEventListener('mouseleave', handlerObject, listenOpts);
  6651. document.addEventListener('tap', handlerObject, listenOpts);
  6652. document.addEventListener('click', handlerObject, listenOpts);
  6653.  
  6654. }
  6655.  
  6656. }, true);
  6657.  
  6658. }
  6659.  
  6660.  
  6661. // yt-live-chat-paid-message-renderer ??
  6662.  
  6663. /*
  6664.  
  6665. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  6666.  
  6667.  
  6668. "yt-live-chat-ticker-paid-message-item-renderer"
  6669. "yt-live-chat-ticker-paid-sticker-item-renderer"
  6670. "yt-live-chat-paid-message-renderer"
  6671. "yt-live-chat-text-message-renderer"
  6672. "yt-live-chat-paid-sticker-renderer"
  6673.  
  6674. */
  6675.  
  6676.  
  6677. whenDefinedMultiple([
  6678.  
  6679. "yt-live-chat-paid-message-renderer",
  6680. "yt-live-chat-membership-item-renderer",
  6681. "yt-live-chat-paid-sticker-renderer",
  6682. "yt-live-chat-text-message-renderer",
  6683. "yt-live-chat-auto-mod-message-renderer",
  6684.  
  6685. /*
  6686. "yt-live-chat-ticker-paid-message-item-renderer",
  6687. "yt-live-chat-ticker-paid-sticker-item-renderer",
  6688. "yt-live-chat-paid-message-renderer",
  6689. "yt-live-chat-text-message-renderer",
  6690. "yt-live-chat-paid-sticker-renderer",
  6691.  
  6692. "yt-live-chat-ticker-sponsor-item-renderer",
  6693. "yt-live-chat-banner-header-renderer",
  6694. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6695. "ytd-sponsorships-live-chat-header-renderer",
  6696. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6697.  
  6698.  
  6699.  
  6700.  
  6701. "yt-live-chat-auto-mod-message-renderer",
  6702. "yt-live-chat-text-message-renderer",
  6703. "yt-live-chat-paid-message-renderer",
  6704.  
  6705. "yt-live-chat-legacy-paid-message-renderer",
  6706. "yt-live-chat-membership-item-renderer",
  6707. "yt-live-chat-paid-sticker-renderer",
  6708. "yt-live-chat-donation-announcement-renderer",
  6709. "yt-live-chat-moderation-message-renderer",
  6710. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  6711. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  6712. "yt-live-chat-viewer-engagement-message-renderer",
  6713.  
  6714. */
  6715.  
  6716.  
  6717. ]).then(sTags => {
  6718.  
  6719.  
  6720. mightFirstCheckOnYtInit();
  6721. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  6722. console.log("[Begin]");
  6723. let doMouseHook = false;
  6724.  
  6725. const dProto = {
  6726. isClickableChatRow111: function () {
  6727. return (
  6728. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  6729. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  6730. ); // follow .onItemTap(a)
  6731. }
  6732. };
  6733.  
  6734. for (const sTag of sTags) { // ##tag##
  6735.  
  6736.  
  6737. (() => {
  6738.  
  6739. const tag = sTag;
  6740. const dummy = document.createElement(tag);
  6741.  
  6742. const cProto = getProto(dummy);
  6743. if (!cProto || !cProto.attached) {
  6744. console.warn(`proto.attached for ${tag} is unavailable.`);
  6745. return;
  6746. }
  6747.  
  6748. const dCnt = insp(dummy);
  6749. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  6750.  
  6751. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  6752.  
  6753. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  6754.  
  6755. if (toHookDocumentMouseDown) {
  6756. doMouseHook = true;
  6757. }
  6758.  
  6759. console.log("shouldSupportWholeItemClick Y", tag);
  6760.  
  6761. } else {
  6762.  
  6763. console.log("shouldSupportWholeItemClick N", tag);
  6764. }
  6765.  
  6766.  
  6767. })();
  6768.  
  6769. }
  6770.  
  6771.  
  6772. if (doMouseHook) {
  6773.  
  6774. hookDocumentMouseDownSetupFn();
  6775.  
  6776.  
  6777. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  6778. }
  6779.  
  6780. console.log("[End]");
  6781.  
  6782. console.groupEnd();
  6783.  
  6784.  
  6785. }).catch(console.warn);
  6786.  
  6787.  
  6788. // https://www.youtube.com/watch?v=oQzFi1NO7io
  6789.  
  6790.  
  6791. }
  6792.  
  6793. if (NO_ITEM_TAP_FOR_NON_STATIONARY_TAP) {
  6794. let targetElementCntWR = null;
  6795. let _e0 = null;
  6796. document.addEventListener('mousedown', (e) => {
  6797. if (!e || !e.isTrusted) return;
  6798. let element = e.target;
  6799. for (; element instanceof HTMLElement; element = element.parentNode) {
  6800. if (element.is) break;
  6801. }
  6802. if (!element || !element.is) return;
  6803. const cnt = insp(element);
  6804. if (typeof cnt.onItemTap === 'function') {
  6805. cnt._onItemTap_isNonStationary = 0;
  6806. const cProto = getProto(element);
  6807. if (!cProto.onItemTap366 && typeof cProto.onItemTap === 'function' && cProto.onItemTap.length === 1) {
  6808. cProto.onItemTap366 = cProto.onItemTap;
  6809. cProto.onItemTap = function (a) {
  6810. const t = this._onItemTap_isNonStationary;
  6811. this._onItemTap_isNonStationary = 0;
  6812. if (t > Date.now()) return;
  6813. return this.onItemTap366.apply(this, arguments)
  6814. }
  6815. }
  6816. _e0 = e;
  6817. targetElementCntWR = mWeakRef(cnt);
  6818. } else {
  6819. _e0 = null;
  6820. targetElementCntWR = null;
  6821. }
  6822. }, { capture: true, passive: true });
  6823.  
  6824. document.addEventListener('mouseup', (e) => {
  6825. if (!e || !e.isTrusted) return;
  6826. const e0 = _e0;
  6827. _e0 = null;
  6828. if (!e0) return;
  6829. const cnt = kRef(targetElementCntWR);
  6830. targetElementCntWR = null;
  6831. if (!cnt) return;
  6832. if (e.timeStamp - e0.timeStamp > TAP_ACTION_DURATION) {
  6833. cnt._onItemTap_isNonStationary = Date.now() + 40;
  6834. } else if ((window.getSelection() + "").trim().replace(/[\u2000-\u200a\u202f\u2800\u200B\u200C\u200D\uFEFF]+/g, '').length >= 1) {
  6835. cnt._onItemTap_isNonStationary = Date.now() + 40;
  6836. } else {
  6837. const dx = e.clientX - e0.clientX;
  6838. const dy = e.clientY - e0.clientY;
  6839. const dd = Math.sqrt(dx * dx + dy * dy);
  6840. const ddmm = px2mm(dd);
  6841. if (ddmm > 1.0) {
  6842. cnt._onItemTap_isNonStationary = Date.now() + 40;
  6843. } else {
  6844. cnt._onItemTap_isNonStationary = 0;
  6845. }
  6846. }
  6847. }, { capture: true, passive: true });
  6848.  
  6849. }
  6850.  
  6851.  
  6852. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  6853.  
  6854. let rr = null;
  6855. const p1 = new Promise(resolve => {
  6856. rr = resolve;
  6857. });
  6858.  
  6859. const p1unlock = () => {
  6860. const f = rr;
  6861. if (f) {
  6862. rr = null;
  6863. f();
  6864. }
  6865. }
  6866.  
  6867. return {
  6868. p1,
  6869. p1unlock,
  6870. assignLock: (targetCnt, timeout) => {
  6871. targetCnt.__showContextMenu_assign_lock__(p1);
  6872. if (timeout) setTimeout(p1unlock, timeout);
  6873. }
  6874. }
  6875.  
  6876. }
  6877.  
  6878. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  6879.  
  6880. document.addEventListener('mousedown', function (evt) {
  6881.  
  6882. const maxloopDOMTreeElements = 4;
  6883. const maxloopYtCompontents = 4;
  6884. let j1 = 0;
  6885. let j2 = 0;
  6886. let target = (evt || 0).target || 0;
  6887. if (!target) return;
  6888.  
  6889.  
  6890. while (target instanceof HTMLElement) {
  6891. if (++j1 > maxloopDOMTreeElements) break;
  6892. if (typeof (target.is || insp(target).is || null) === 'string') break;
  6893. target = nodeParent(target);
  6894. }
  6895. const components = [];
  6896. while (target instanceof HTMLElement) {
  6897. if (++j2 > maxloopYtCompontents) break;
  6898. const cnt = insp(target);
  6899. if (typeof (target.is || cnt.is || null) === 'string') {
  6900. components.push(target);
  6901. }
  6902. if (typeof cnt.showContextMenu === 'function') break;
  6903. target = target.parentComponent || cnt.parentComponent || null;
  6904. }
  6905. if (!(target instanceof HTMLElement)) return;
  6906. const targetCnt = insp(target);
  6907. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  6908. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  6909. return;
  6910. }
  6911.  
  6912. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  6913. if (!endpoint) return;
  6914. if (targetCnt.opened || !targetCnt.isAttached) return;
  6915.  
  6916. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  6917. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  6918. }
  6919.  
  6920. const targetDollar = indr(target);
  6921.  
  6922. let doPreRequest = false;
  6923. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  6924. doPreRequest = true;
  6925. } else if (components.length === 1 && components[0] === target) {
  6926. doPreRequest = true;
  6927. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  6928. doPreRequest = true;
  6929. }
  6930. if (doPreRequest === false) {
  6931. console.log('doPreRequest = fasle on showContextMenu', components);
  6932. return;
  6933. }
  6934.  
  6935. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  6936.  
  6937. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  6938. console.log('preRequest on showContextMenu aborted due to stacked network request');
  6939. return;
  6940. }
  6941.  
  6942.  
  6943. const onSuccess = (a) => {
  6944. /*
  6945.  
  6946. dQ() && (a = a.response);
  6947. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  6948. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  6949.  
  6950. */
  6951.  
  6952. a = a.response || a;
  6953.  
  6954. if (!a) {
  6955. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  6956. return;
  6957. }
  6958.  
  6959. let z = null;
  6960. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  6961.  
  6962. if (z) {
  6963. a = z;
  6964. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  6965. }
  6966.  
  6967. };
  6968. const onFailure = (a) => {
  6969.  
  6970. /*
  6971.  
  6972. if (a instanceof Error || a instanceof Object || a instanceof String)
  6973. var b = a;
  6974. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  6975.  
  6976. */
  6977.  
  6978. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  6979. // console.log('onFailure', a)
  6980.  
  6981. };
  6982.  
  6983. if (doPreRequest) {
  6984.  
  6985. let propertyCounter = 0;
  6986. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  6987. const p1Timeout = 800;
  6988. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  6989.  
  6990. try {
  6991.  
  6992. const onSuccessHelperFn = function () {
  6993. pm1.p1unlock();
  6994. if (propertyCounter !== 5) {
  6995. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  6996. return;
  6997. }
  6998. if (this[proxyKey] !== targetCnt) {
  6999. console.log('Error in prerequest for showContextMenu.this');
  7000. return;
  7001. }
  7002. onSuccess(...arguments);
  7003. };
  7004. const onFailureHelperFn = function () {
  7005. pm1.p1unlock();
  7006. if (propertyCounter !== 5) {
  7007. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  7008. return;
  7009. }
  7010. if (this[proxyKey] !== targetCnt) {
  7011. console.log('Error in prerequest for showContextMenu.this');
  7012. return;
  7013. }
  7014. onFailure(...arguments);
  7015.  
  7016. }
  7017. const fakeTargetCnt = new Proxy({
  7018. __showContextMenu_forceNativeRequest__: 1,
  7019. __showContextMenu_sync_mode_request__: 1,
  7020. get handleGetContextMenuResponse_() {
  7021. propertyCounter += 2;
  7022. return onSuccessHelperFn;
  7023. },
  7024. get handleGetContextMenuError() {
  7025. propertyCounter += 3;
  7026. return onFailureHelperFn;
  7027. }
  7028. }, {
  7029. get(_, key, receiver) {
  7030. if (key in _) return _[key];
  7031. if (key === proxyKey) return targetCnt;
  7032.  
  7033. let giveNative = false;
  7034. if (key in targetCnt) {
  7035. if (key === 'data') giveNative = true;
  7036. else if (typeof targetCnt[key] === 'function') giveNative = true;
  7037. }
  7038. if (giveNative) return targetCnt[key];
  7039. }
  7040. });
  7041.  
  7042. const fakeEvent = (() => {
  7043. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  7044. const nf = function () { }
  7045. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  7046.  
  7047. return {
  7048. type: 'tap',
  7049. eventPhase: 0,
  7050. isTrusted: false,
  7051. __composed: true,
  7052. bubbles, cancelable, cancelBubble, timeStamp,
  7053. target, srcElement, defaultPrevented, currentTarget, composed,
  7054. stopPropagation, stopImmediatePropagation, preventDefault
  7055. };
  7056. })(evt);
  7057. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  7058.  
  7059.  
  7060. } catch (e) {
  7061. console.warn(e);
  7062. propertyCounter = 7;
  7063.  
  7064. }
  7065. if (propertyCounter !== 5) {
  7066. console.log('Error in prerequest for showContextMenu', propertyCounter);
  7067. return;
  7068. }
  7069.  
  7070. pm1.assignLock(targetCnt, p1Timeout);
  7071.  
  7072. }
  7073.  
  7074.  
  7075.  
  7076.  
  7077.  
  7078.  
  7079. }, true);
  7080.  
  7081.  
  7082. }
  7083.  
  7084.  
  7085.  
  7086. /*
  7087.  
  7088. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  7089.  
  7090. */
  7091.  
  7092. whenDefinedMultiple([
  7093. "yt-live-chat-ticker-sponsor-item-renderer",
  7094. "yt-live-chat-banner-header-renderer",
  7095. "yt-live-chat-text-message-renderer",
  7096. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  7097. "ytd-sponsorships-live-chat-header-renderer",
  7098. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  7099.  
  7100. "yt-live-chat-paid-sticker-renderer",
  7101. "yt-live-chat-viewer-engagement-message-renderer",
  7102. "yt-live-chat-paid-message-renderer"
  7103.  
  7104.  
  7105.  
  7106.  
  7107. ]).then(sTags => {
  7108.  
  7109. mightFirstCheckOnYtInit();
  7110. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  7111. console.log("[Begin]");
  7112.  
  7113.  
  7114. const __showContextMenu_mutex__ = new Mutex();
  7115. let __showContextMenu_mutex_unlock__ = null;
  7116. let lastShowMenuTarget = null;
  7117.  
  7118.  
  7119.  
  7120.  
  7121. const wm37 = new WeakMap();
  7122.  
  7123. const dProto = {
  7124.  
  7125.  
  7126. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  7127.  
  7128. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  7129. if (a) {
  7130. if (doDeepCopy) a = deepCopy(a);
  7131. wm37.set(endpoint, a);
  7132. } else {
  7133. wm37.remove(endpoint);
  7134. }
  7135. },
  7136. __getCachedEndpointData__: function (endpoint) {
  7137. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  7138. if (endpoint) return wm37.get(endpoint);
  7139. return null;
  7140. },
  7141. /** @type {(resolvedEndpoint: any) => void 0} */
  7142. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  7143.  
  7144. resolvedEndpoint = deepCopy(resolvedEndpoint);
  7145. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  7146. Promise.resolve(resolvedEndpoint).then(() => {
  7147. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  7148. this.showContextMenu_(resolvedEndpoint);
  7149. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  7150. });
  7151.  
  7152.  
  7153. },
  7154.  
  7155.  
  7156.  
  7157. showContextMenuForCacheReopen: function (a) {
  7158. if (!this.__showContextMenu_forceNativeRequest__) {
  7159. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7160. if (endpoint) {
  7161. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  7162. if (resolvedEndpoint) {
  7163. this.__showCachedContextMenu__(resolvedEndpoint);
  7164. a && a.stopPropagation()
  7165. return;
  7166. }
  7167. }
  7168. }
  7169. return this.showContextMenu37(a);
  7170. },
  7171.  
  7172. showContextMenuForCacheReopen_: function (a) {
  7173. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  7174. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7175. if (endpoint) {
  7176. const f = this.__cacheResolvedEndpointData__;
  7177. if (typeof f === 'function') f(endpoint, a, true);
  7178. }
  7179. }
  7180. return this.showContextMenu37_(a);
  7181. },
  7182.  
  7183. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  7184.  
  7185. showContextMenuWithDisableScroll: function (a) {
  7186.  
  7187. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  7188. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  7189.  
  7190. const parentComponent = this.parentComponent;
  7191. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  7192. parentComponent.allowScroll = false;
  7193. }
  7194. }
  7195.  
  7196. return this.showContextMenu48.apply(this, arguments);
  7197.  
  7198. },
  7199.  
  7200. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  7201.  
  7202. __showContextMenu_mutex_unlock_isEmpty__: () => {
  7203. return __showContextMenu_mutex_unlock__ === null;
  7204. },
  7205.  
  7206. __showContextMenu_assign_lock__: function (p) {
  7207.  
  7208. const mutex = __showContextMenu_mutex__;
  7209.  
  7210. mutex.lockWith(unlock => {
  7211. p.then(unlock);
  7212. });
  7213.  
  7214. },
  7215.  
  7216. showContextMenuWithMutex: function (a) {
  7217. lastShowMenuTarget = this;
  7218.  
  7219. if (this.__showContextMenu_sync_mode_request__) {
  7220.  
  7221. return this.showContextMenu47(a);
  7222. } else {
  7223.  
  7224. const mutex = __showContextMenu_mutex__;
  7225.  
  7226. mutex.lockWith(unlock => {
  7227. if (lastShowMenuTarget !== this) {
  7228. unlock();
  7229. return;
  7230. }
  7231.  
  7232. setTimeout(unlock, 800); // in case network failure
  7233. __showContextMenu_mutex_unlock__ = unlock;
  7234. try {
  7235. this.showContextMenu47(a);
  7236. } catch (e) {
  7237. console.warn(e);
  7238. unlock(); // in case function script error
  7239. }
  7240.  
  7241. });
  7242.  
  7243. }
  7244.  
  7245.  
  7246. },
  7247.  
  7248. showContextMenuWithMutex_: function (a) {
  7249.  
  7250. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  7251. __showContextMenu_mutex_unlock__();
  7252. __showContextMenu_mutex_unlock__ = null;
  7253. }
  7254. return this.showContextMenu47_(a);
  7255.  
  7256. }
  7257.  
  7258. }
  7259.  
  7260. for (const tag of sTags) { // ##tag##
  7261.  
  7262.  
  7263.  
  7264. (() => {
  7265.  
  7266. const dummy = document.createElement(tag);
  7267.  
  7268. const cProto = getProto(dummy);
  7269. if (!cProto || !cProto.attached) {
  7270. console.warn(`proto.attached for ${tag} is unavailable.`);
  7271. return;
  7272. }
  7273.  
  7274.  
  7275.  
  7276.  
  7277. 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) {
  7278.  
  7279. cProto.showContextMenu37_ = cProto.showContextMenu_;
  7280. cProto.showContextMenu37 = cProto.showContextMenu;
  7281.  
  7282. cProto.__showContextMenu_forceNativeRequest__ = 0;
  7283. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  7284. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  7285. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  7286.  
  7287. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  7288.  
  7289. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  7290.  
  7291.  
  7292. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  7293.  
  7294.  
  7295.  
  7296. } else {
  7297.  
  7298. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  7299.  
  7300. }
  7301.  
  7302.  
  7303.  
  7304. 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) {
  7305.  
  7306.  
  7307. cProto.showContextMenu48 = cProto.showContextMenu;
  7308.  
  7309.  
  7310. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  7311.  
  7312.  
  7313.  
  7314. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  7315.  
  7316.  
  7317.  
  7318. } else {
  7319.  
  7320. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  7321.  
  7322. }
  7323.  
  7324.  
  7325.  
  7326.  
  7327.  
  7328. 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) {
  7329.  
  7330. cProto.showContextMenu47_ = cProto.showContextMenu_;
  7331. cProto.showContextMenu47 = cProto.showContextMenu;
  7332.  
  7333. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  7334. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  7335. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  7336. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  7337.  
  7338. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  7339.  
  7340.  
  7341.  
  7342. } else {
  7343.  
  7344. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  7345.  
  7346. }
  7347.  
  7348.  
  7349.  
  7350.  
  7351. })();
  7352.  
  7353. }
  7354.  
  7355.  
  7356.  
  7357. console.log("[End]");
  7358.  
  7359. console.groupEnd();
  7360.  
  7361. }).catch(console.warn);
  7362.  
  7363.  
  7364.  
  7365. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  7366.  
  7367. mightFirstCheckOnYtInit();
  7368. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  7369. console.log("[Begin]");
  7370. (() => {
  7371.  
  7372. const tag = "tp-yt-iron-dropdown";
  7373. const dummy = document.createElement(tag);
  7374.  
  7375. const cProto = getProto(dummy);
  7376. if (!cProto || !cProto.attached) {
  7377. console.warn(`proto.attached for ${tag} is unavailable.`);
  7378. return;
  7379. }
  7380.  
  7381.  
  7382. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  7383. cProto.__deraf_hn__ = function (sId, fn) {
  7384. const rhKey = `_rafHandler_${sId}`;
  7385. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  7386. if (m.has(fn)) return m.get(fn);
  7387. const resFn = () => {
  7388. this.__rafs[sId] = null;
  7389. fn.call(this)
  7390. };
  7391. m.set(fn, resFn);
  7392. m.set(resFn, resFn);
  7393. return resFn;
  7394. };
  7395. cProto.__deraf34 = cProto.__deraf;
  7396. cProto.__deraf = function (a, b) { // sId, fn
  7397. let c = this.__rafs;
  7398. null !== c[a] && cancelAnimationFrame(c[a]);
  7399. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  7400. };
  7401. console.log("USE_VANILLA_DEREF - OK");
  7402. } else {
  7403. console.log("USE_VANILLA_DEREF - NG");
  7404. }
  7405.  
  7406. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  7407. cProto.__deraf66 = cProto.__deraf;
  7408. cProto.__deraf = function (sId, fn) {
  7409. if (this.__byPassRAF__) {
  7410. Promise.resolve().then(() => {
  7411. fn.call(this);
  7412. });
  7413. }
  7414. let r = this.__deraf66.apply(this, arguments);
  7415. return r;
  7416. }
  7417. console.log("FIX_DROPDOWN_DERAF - OK");
  7418. } else {
  7419. console.log("FIX_DROPDOWN_DERAF - NG");
  7420. }
  7421.  
  7422.  
  7423. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  7424.  
  7425. let lastClose = null;
  7426. let lastOpen = null;
  7427. let cid = 0;
  7428.  
  7429. cProto.__mtChanged__ = function (b) {
  7430.  
  7431. Promise.resolve().then(() => {
  7432. this._applyFocus();
  7433. }).then(() => {
  7434. b ? this._renderOpened() : this._renderClosed();
  7435. }).catch(console.warn);
  7436.  
  7437. };
  7438.  
  7439. const __moChanged__ = () => {
  7440. if (!cid) return;
  7441. // console.log(553, !!lastOpen, !!lastClose);
  7442. cid = 0;
  7443. if (lastOpen && !lastClose && lastOpen.isAttached) {
  7444. lastOpen.__mtChanged__(1)
  7445. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  7446. lastClose.__mtChanged__(0);
  7447. }
  7448. lastOpen = null;
  7449. lastClose = null;
  7450. };
  7451.  
  7452.  
  7453. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  7454. cProto._openedChanged66 = cProto._openedChanged;
  7455. cProto._openedChanged = function () {
  7456. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  7457. this.__byPassRAF__ = true;
  7458. let r = this._openedChanged66.apply(this, arguments);
  7459. this.__byPassRAF__ = false;
  7460. return r;
  7461. }
  7462. }
  7463.  
  7464. const pSetGet = (key, pdThis, pdBase) => {
  7465. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  7466. return {
  7467. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  7468. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  7469. };
  7470. };
  7471.  
  7472. cProto.__modifiedMenuPropsFn__ = function () {
  7473. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  7474. const pdBase = Object.getOwnPropertyDescriptors(this)
  7475.  
  7476. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  7477. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  7478. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  7479.  
  7480. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  7481. console.warn('there is setter/getter for autoFitOnAttach');
  7482. return;
  7483. }
  7484. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  7485. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  7486. return;
  7487. }
  7488. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  7489. console.warn('there is NO setter-getter for allowOutsideScroll');
  7490. return;
  7491. }
  7492.  
  7493. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  7494.  
  7495. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  7496.  
  7497. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  7498.  
  7499. Object.defineProperties(this, {
  7500. autoFitOnAttach: {
  7501. get() {
  7502. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  7503. return autoFitOnAttach;
  7504. },
  7505. set(nv) {
  7506. autoFitOnAttach = nv;
  7507. return true;
  7508. },
  7509. enumerable: true,
  7510. configurable: true
  7511. }, expandSizingTargetForScrollbars: {
  7512. get() {
  7513. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  7514. return expandSizingTargetForScrollbars;
  7515. },
  7516. set(nv) {
  7517. expandSizingTargetForScrollbars = nv;
  7518. return true;
  7519. },
  7520. enumerable: true,
  7521. configurable: true
  7522. }, allowOutsideScroll: {
  7523. get() {
  7524. if (this._modifiedMenuPropOn062__) return true;
  7525. return allowOutsideScroll;
  7526. },
  7527. set(nv) {
  7528. allowOutsideScroll = nv;
  7529. this.__AllowOutsideScrollPD__.set.call(this, nv);
  7530. return true;
  7531. },
  7532. enumerable: true,
  7533. configurable: true
  7534. }
  7535. })
  7536. };
  7537.  
  7538. /*
  7539. // ***** position() to be changed. *****
  7540. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  7541.  
  7542. overflow: visible !important;
  7543. min-width: max-content !important;
  7544. max-width: max-content !important;
  7545. max-height: max-content !important;
  7546. min-height: max-content !important;
  7547. white-space: nowrap;
  7548. }
  7549.  
  7550. */
  7551. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  7552.  
  7553. let m34 = 0;
  7554. cProto.__refitByPosition__ = function () {
  7555. m34++;
  7556. if (m34 <= 0) m34 = 0;
  7557. if (m34 !== 1) return;
  7558. const hostElement = this.hostElement || this;
  7559. if (document.visibilityState === 'visible') {
  7560. const sizingTarget = this.sizingTarget;
  7561. if (!sizingTarget) {
  7562. m34 = 0;
  7563. return;
  7564. }
  7565.  
  7566. /*
  7567. let useVisibilityCollapse = true;
  7568. if (HTMLElement.prototype.querySelector.call(sizingTarget, 'yt-icon:empty')) {
  7569. useVisibilityCollapse = false;
  7570. }
  7571.  
  7572. if (useVisibilityCollapse) {
  7573. hostElement.style.visibility = 'collapse';
  7574. sizingTarget.style.visibility = 'collapse';
  7575. } else {
  7576. hostElement.setAttribute('rNgzQ', '');
  7577. sizingTarget.setAttribute('rNgzQ', '');
  7578. }
  7579. */
  7580. hostElement.setAttribute('rNgzQ', '');
  7581. sizingTarget.setAttribute('rNgzQ', '');
  7582.  
  7583. const gn = () => {
  7584. /*
  7585. if (useVisibilityCollapse) {
  7586. hostElement.style.visibility = '';
  7587. sizingTarget.style.visibility = '';
  7588. } else {
  7589. hostElement.removeAttribute('rNgzQ');
  7590. sizingTarget.removeAttribute('rNgzQ');
  7591. }
  7592. */
  7593. hostElement.removeAttribute('rNgzQ');
  7594. sizingTarget.removeAttribute('rNgzQ');
  7595. }
  7596.  
  7597. const an = async () => {
  7598. while (m34 >= 1) {
  7599. await renderReadyPn(sizingTarget);
  7600. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  7601. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  7602. }
  7603. m34--;
  7604. }
  7605. m34 = 0;
  7606. Promise.resolve().then(gn);
  7607. }
  7608. setTimeout(an, 4); // wait those resizing function calls
  7609.  
  7610.  
  7611. } else {
  7612. m34 = 0;
  7613. }
  7614. }
  7615. cProto.position34 = cProto.position
  7616. cProto.position = function () {
  7617. if (this._positionInitialize_) {
  7618. this._positionInitialize_ = 0;
  7619. this.__refitByPosition__();
  7620. }
  7621. let r = cProto.position34.apply(this, arguments);
  7622. return r;
  7623. }
  7624. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  7625.  
  7626. } else {
  7627.  
  7628. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  7629.  
  7630. }
  7631.  
  7632.  
  7633.  
  7634. cProto.__openedChanged = function () {
  7635. this._positionInitialize_ = 1;
  7636. // this.removeAttribute('horizontal-align')
  7637. // this.removeAttribute('vertical-align')
  7638. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  7639. this.__menuTypeCheck__ = true;
  7640. if (CHAT_MENU_SCROLL_UNLOCKING) {
  7641. this._modifiedMenuPropOn062__ = false;
  7642. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7643. // this.autoFitOnAttach = true;
  7644. // this.expandSizingTargetForScrollbars = true;
  7645. // this.allowOutsideScroll = true;
  7646. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  7647. this.__modifiedMenuPropsFn__();
  7648. // this.constrain= function(){}
  7649. // this.position= function(){}
  7650.  
  7651. // this.autoFitOnAttach = true;
  7652. // this.expandSizingTargetForScrollbars = true;
  7653. // this.allowOutsideScroll = true;
  7654. }
  7655. }
  7656. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  7657. let newValue = null;
  7658. const positionTarget = this.positionTarget;
  7659. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  7660. if (this._modifiedMenuPropOn062__ === false) {
  7661. newValue = true;
  7662. }
  7663. } else if (this._modifiedMenuPropOn062__ === true) {
  7664. newValue = false;
  7665. }
  7666. if (newValue !== null) {
  7667. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  7668. this._modifiedMenuPropOn062__ = newValue;
  7669. const afterAllowOutsideScroll = this.allowOutsideScroll;
  7670. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  7671. }
  7672. }
  7673.  
  7674. if (this.opened) {
  7675.  
  7676. Promise.resolve().then(() => {
  7677.  
  7678. this._prepareRenderOpened();
  7679. }).then(() => {
  7680. this._manager.addOverlay(this);
  7681. if (this._manager._overlays.length === 1) {
  7682. lastOpen = this;
  7683. lastClose = null;
  7684. } else {
  7685. return 1;
  7686. }
  7687. // if (cid) {
  7688. // clearTimeout(cid);
  7689. // cid = -1;
  7690. // this.__moChanged__();
  7691. // cid = 0;
  7692. // } else {
  7693. // cid = -1;
  7694. // this.__moChanged__();
  7695. // cid = 0;
  7696. // }
  7697. // cid = cid > 0 ? clearTimeout(cid) : 0;
  7698. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7699. // cid = cid || setTimeout(__moChanged__, delay1);
  7700. cid = cid || requestAnimationFrame(__moChanged__);
  7701. }).then((r) => {
  7702.  
  7703. if (r) this.__mtChanged__(1);
  7704. }).catch(console.warn);
  7705.  
  7706. } else {
  7707. Promise.resolve().then(() => {
  7708. this._manager.removeOverlay(this);
  7709. if (this._manager._overlays.length === 0) {
  7710. lastClose = this;
  7711. lastOpen = null;
  7712. } else {
  7713. return 1;
  7714. }
  7715. // cid = cid > 0 ? clearTimeout(cid) : 0;
  7716. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  7717. // cid = cid || setTimeout(__moChanged__, delay1);
  7718. cid = cid || requestAnimationFrame(__moChanged__);
  7719. }).then((r) => {
  7720. if (r) this.__mtChanged__(0);
  7721. }).catch(console.warn);
  7722.  
  7723. }
  7724.  
  7725. }
  7726. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  7727.  
  7728. } else {
  7729.  
  7730. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  7731. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  7732.  
  7733. }
  7734.  
  7735.  
  7736. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  7737.  
  7738. cProto.__openedChanged82 = cProto.__openedChanged;
  7739.  
  7740.  
  7741. cProto.__openedChanged = function () {
  7742.  
  7743. // currentMenuPivotWR = null;
  7744. // console.log(1480, '__openedChanged.A', this.positionTarget)
  7745.  
  7746.  
  7747.  
  7748. // if (this.opened && this.positionTarget) {
  7749.  
  7750. // const positionTarget = this.positionTarget;
  7751. // console.log(1480, '__openedChanged.B', positionTarget)
  7752. // currentMenuPivotWR = mWeakRef(positionTarget);
  7753.  
  7754. // }
  7755.  
  7756. const positionTarget = this.positionTarget;
  7757. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  7758. return this.__openedChanged82.apply(this, arguments);
  7759. }
  7760. }
  7761.  
  7762.  
  7763. // if(FIX_MENU_CAPTURE_SCROLL && typeof cProto.__onCaptureScroll === 'function' && !cProto.__onCaptureScroll66){
  7764.  
  7765. // cProto.__onCaptureScroll66 = cProto.__onCaptureScroll;
  7766.  
  7767. // cProto.__onCaptureScroll = function(a){
  7768.  
  7769. // const q = true;
  7770. // if(this.scrollAction === 'lock' && q && this.opened){
  7771.  
  7772. // // console.log(9107, this.scrollAction, this.__isAnimating, this.opened, a); // lock; __isAnimating = false
  7773. // async function af() {
  7774. // this.__isAnimating && this._finishRenderOpened();
  7775. // if (!this.opened) return;
  7776. // this.__restoreScrollPosition();
  7777. // await new Promise(r => requestAnimationFrame(r));
  7778. // if (!this.opened) return;
  7779. // this.opened && this.__isAnimating && this._finishRenderOpened();
  7780. // if (!this.opened) return;
  7781. // this.__restoreScrollPosition();
  7782. // await new Promise(r => requestAnimationFrame(r));
  7783. // if (!this.opened) return;
  7784. // this.opened && this.__isAnimating && this._finishRenderOpened();
  7785. // if (!this.opened) return;
  7786. // this.opened && !this.__isAnimating && this.refit();
  7787. // }
  7788. // Promise.resolve().then(af);
  7789.  
  7790. // return cProto.__onCaptureScroll66.apply(this, arguments);
  7791. // }else{
  7792.  
  7793. // // console.log(9102, this.scrollAction, this.__isAnimating, this.opened, a); // lock
  7794.  
  7795. // return cProto.__onCaptureScroll66.apply(this, arguments);
  7796. // }
  7797. // }
  7798. // console.log("FIX_MENU_CAPTURE_SCROLL - OK");
  7799. // }else{
  7800. // console.log("FIX_MENU_CAPTURE_SCROLL - NG");
  7801.  
  7802. // }
  7803.  
  7804.  
  7805. })();
  7806.  
  7807. console.log("[End]");
  7808.  
  7809. console.groupEnd();
  7810.  
  7811. }).catch(console.warn);
  7812.  
  7813.  
  7814.  
  7815.  
  7816.  
  7817.  
  7818.  
  7819.  
  7820. /*
  7821.  
  7822.  
  7823.  
  7824.  
  7825.  
  7826. var FU = function() {
  7827. var a = this;
  7828. this.nextHandle_ = 1;
  7829. this.clients_ = {};
  7830. this.JSC$10323_callbacks_ = {};
  7831. this.unsubscribeAsyncHandles_ = {};
  7832. this.subscribe = vl(function(b, c, d) {
  7833. var e = Geb(b);
  7834. if (e in a.clients_)
  7835. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  7836. else {
  7837. a: {
  7838. var h = Geb(b), l;
  7839. for (l in a.unsubscribeAsyncHandles_) {
  7840. var m = a.clients_[l];
  7841. if (m instanceof KO) {
  7842. delete a.clients_[l];
  7843. delete a.JSC$10323_callbacks_[l];
  7844. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  7845. delete a.unsubscribeAsyncHandles_[l];
  7846. i6a(m);
  7847. m.objectId_ = new FQa(h);
  7848. m.register();
  7849. d = m;
  7850. break a
  7851. }
  7852. }
  7853. d.objectSource = b.invalidationId.objectSource;
  7854. d.objectId = h;
  7855. if (b = b.webAuthConfigurationData)
  7856. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  7857. b.pageId && (d.pageId = b.pageId);
  7858. d = new KO(d,a.handleInvalidationData_.bind(a));
  7859. d.register()
  7860. }
  7861. a.clients_[e] = d;
  7862. a.JSC$10323_callbacks_[e] = {}
  7863. }
  7864. d = a.nextHandle_++;
  7865. a.JSC$10323_callbacks_[e][d] = c;
  7866. return d
  7867. })
  7868. };
  7869. FU.prototype.unsubscribe = function(a, b) {
  7870. var c = Geb(a);
  7871. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  7872. !this.JSC$10323_callbacks_[c].length)) {
  7873. var d = this.clients_[c];
  7874. b = Jq.run(function() {
  7875. ei(d);
  7876. delete this.clients_[c];
  7877. delete this.unsubscribeAsyncHandles_[c]
  7878. }
  7879. .bind(this));
  7880. this.unsubscribeAsyncHandles_[c] = b
  7881. }
  7882. }
  7883. ;
  7884.  
  7885.  
  7886. */
  7887.  
  7888.  
  7889.  
  7890.  
  7891. const onManagerFound = (dummyManager) => {
  7892. if (!dummyManager || typeof dummyManager !== 'object') return;
  7893.  
  7894. const mgrProto = dummyManager.constructor.prototype;
  7895.  
  7896. let keyCallbackStore = '';
  7897. for (const [key, v] of Object.entries(dummyManager)) {
  7898. if (key.includes('_callbacks_')) keyCallbackStore = key;
  7899. }
  7900.  
  7901. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  7902.  
  7903. if (mgrProto.unsubscribe16) return;
  7904.  
  7905. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  7906.  
  7907. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  7908. console.log("[Begin]");
  7909.  
  7910.  
  7911. // const isEmptyObject = (a) => Object.keys(a).length === 0;
  7912. const isEmptyObject = ((obj) => (firstKey(obj) === null));
  7913.  
  7914. const idMapper = new Map();
  7915.  
  7916. const convertId = function (objectId) {
  7917. if (!objectId || typeof objectId !== 'string') return null;
  7918.  
  7919. let result = idMapper.get(objectId)
  7920. if (result) return result;
  7921. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  7922. idMapper.set(objectId, result)
  7923. return result;
  7924. }
  7925.  
  7926.  
  7927. const rafHandleHolder = [];
  7928.  
  7929. let pzw = 0;
  7930. let lza = 0;
  7931. const rafHandlerFn = () => {
  7932. pzw = 0;
  7933. if (rafHandleHolder.length === 1) {
  7934. const f = rafHandleHolder[0];
  7935. rafHandleHolder.length = 0;
  7936. f();
  7937. } else if (rafHandleHolder.length > 1) {
  7938. const arr = rafHandleHolder.slice(0);
  7939. rafHandleHolder.length = 0;
  7940. for (const fn of arr) fn();
  7941. }
  7942. };
  7943.  
  7944.  
  7945. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  7946.  
  7947. const checkIntegrityForSubscribe = (mgr) => {
  7948. if (mgr
  7949. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  7950. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  7951.  
  7952. const ns = new Set(Object.keys(mgr));
  7953. const ms = new Set(Object.keys(mgr.constructor.prototype));
  7954.  
  7955. if (ns.size >= 6 && ms.size >= 4) {
  7956. // including 'subscribe18'
  7957. // 'unsubscribe16', 'subscribe19'
  7958.  
  7959. let r = 0;
  7960. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  7961. r += ns.has(k) ? 1 : 0;
  7962. }
  7963. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  7964. r += ms.has(k) ? 1 : 0;
  7965. }
  7966. if (r === 10) {
  7967. const isObject = (c) => (c || 0).constructor === Object;
  7968.  
  7969. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  7970.  
  7971. return true;
  7972. }
  7973.  
  7974.  
  7975. }
  7976.  
  7977. }
  7978.  
  7979.  
  7980. }
  7981. return false;
  7982. }
  7983.  
  7984. mgrProto.subscribe19 = function (o, f, opts) {
  7985.  
  7986. const ct_clients_ = this.clients_ || 0;
  7987. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  7988.  
  7989. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  7990.  
  7991. let objectId = ((o || 0).invalidationId || 0).objectId;
  7992. if (!objectId) return this.subscribe18.apply(this, arguments);
  7993. objectId = convertId(objectId);
  7994.  
  7995. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  7996.  
  7997. if (ct_clients_[objectId]) {
  7998. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  7999. }
  8000.  
  8001. return this.subscribe18.apply(this, arguments);
  8002. }
  8003.  
  8004. mgrProto.unsubscribe = function (o, d) {
  8005. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  8006. this.subscribe18 = this.subscribe;
  8007. this.subscribe = this.subscribe19;
  8008. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  8009. }
  8010. const ct_clients_ = this.clients_;
  8011. const ct_handles_ = this.unsubscribeAsyncHandles_;
  8012. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  8013.  
  8014. let objectId = ((o || 0).invalidationId || 0).objectId;
  8015. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  8016.  
  8017. objectId = convertId(objectId);
  8018.  
  8019.  
  8020. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  8021.  
  8022. const callbacks = this[keyCallbackStore] || 0;
  8023. const callbackObj = callbacks[objectId] || 0;
  8024.  
  8025.  
  8026. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  8027. const w = ct_clients_[objectId];
  8028. --lza;
  8029. if (lza < -1e9) lza = -1;
  8030. const qta = lza;
  8031. rafHandleHolder.push(() => {
  8032. if (qta === ct_handles_[objectId]) {
  8033. const o = {
  8034. callbacks, callbackObj,
  8035. client: ct_clients_[objectId],
  8036. handle: ct_handles_[objectId]
  8037. };
  8038. let p = 0;
  8039. try {
  8040. if (ct_clients_[objectId] === w) {
  8041. w && "function" === typeof w.dispose && w.dispose();
  8042. delete ct_clients_[objectId];
  8043. delete ct_handles_[objectId];
  8044. p = 1;
  8045. } else {
  8046. // w && "function" === typeof w.dispose && w.dispose();
  8047. // delete ct_clients_[objectId];
  8048. // delete ct_handles_[objectId];
  8049. p = 2;
  8050. }
  8051. } catch (e) {
  8052. console.warn(e);
  8053. }
  8054. console.log(`unsubscribed: ${p}`, this, o);
  8055. }
  8056. });
  8057. ct_handles_[objectId] = qta;
  8058. if (pzw === 0) {
  8059. pzw = requestAnimationFrame(rafHandlerFn);
  8060. }
  8061. }
  8062. }
  8063.  
  8064.  
  8065. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  8066.  
  8067. } else {
  8068.  
  8069. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  8070. }
  8071.  
  8072. console.log("[End]");
  8073.  
  8074. console.groupEnd();
  8075.  
  8076. }
  8077.  
  8078.  
  8079.  
  8080. /*
  8081.  
  8082.  
  8083. a.prototype.async = function(e, h) {
  8084. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  8085. }
  8086. ;
  8087. a.prototype.cancelAsync = function(e) {
  8088. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  8089. }
  8090.  
  8091. */
  8092.  
  8093.  
  8094. (FASTER_ICON_RENDERING && Promise.all(
  8095. [
  8096. customElements.whenDefined("yt-icon-shape"),
  8097. customElements.whenDefined("yt-icon")
  8098. // document.createElement('icon-shape'),
  8099. ]
  8100. )).then(() => {
  8101. let cq = 0;
  8102. let dummys = [document.createElement('yt-icon-shape'), document.createElement('yt-icon')]
  8103. for (const dummy of dummys) {
  8104. let cProto = getProto(dummy);
  8105. if (cProto && typeof cProto.shouldRenderIconShape === 'function' && !cProto.shouldRenderIconShape571 && cProto.shouldRenderIconShape.length === 1) {
  8106. assertor(() => fnIntegrity(cProto.shouldRenderIconShape, '1.70.38'));
  8107. cq++;
  8108. cProto.shouldRenderIconShape571 = cProto.shouldRenderIconShape;
  8109. cProto.shouldRenderIconShape = function (a) {
  8110. if (this.isAnimatedIcon) return this.shouldRenderIconShape571(a);
  8111. if (!this.iconType || !this.iconShapeData) return this.shouldRenderIconShape571(a);
  8112. if (!this.iconName) return this.shouldRenderIconShape571(a);
  8113. return false;
  8114. // console.log(1051, this.iconType)
  8115. // console.log(1052, this.iconShapeData)
  8116. // console.log(1053, this.isAnimatedIcon)
  8117. }
  8118. }
  8119. // if(cProto && cProto.switchTemplateAtRegistration){
  8120. // cProto.switchTemplateAtRegistration = false;
  8121. // }
  8122. }
  8123. if (cq === 1) {
  8124. console.log("modified shouldRenderIconShape - Y")
  8125. } else {
  8126. console.log("modified shouldRenderIconShape - N", cq)
  8127. }
  8128. });
  8129.  
  8130. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  8131.  
  8132. let __dummyManager__ = null;
  8133.  
  8134. mightFirstCheckOnYtInit();
  8135. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  8136. console.log("[Begin]");
  8137. (() => {
  8138.  
  8139. const tag = "yt-invalidation-continuation"
  8140. const dummy = document.createElement(tag);
  8141.  
  8142. const cProto = getProto(dummy);
  8143. if (!cProto || !cProto.attached) {
  8144. console.warn(`proto.attached for ${tag} is unavailable.`);
  8145. return;
  8146. }
  8147.  
  8148. const dummyManager = insp(dummy).manager_ || 0;
  8149. __dummyManager__ = dummyManager;
  8150.  
  8151. 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) {
  8152.  
  8153.  
  8154. const rafHub = new RAFHub();
  8155.  
  8156. rafHub.keepRAF = true;
  8157. cProto.async71 = cProto.async;
  8158. cProto.cancelAsync71 = cProto.cancelAsync;
  8159.  
  8160. // mostly for subscription timeoutMs 10000ms
  8161. let mcw = 1; // 1, 3, 5, ...
  8162. let arr = new Map();
  8163.  
  8164. let __asyncInited__ = 0;
  8165. let __timeoutStartId__ = null;
  8166. const __asyncInit__ = () => {
  8167.  
  8168. if (__asyncInited__) return;
  8169. __asyncInited__ = 1;
  8170.  
  8171. __timeoutStartId__ = setTimeout(() => { });
  8172. mcw = __timeoutStartId__ * 2 + 1;
  8173.  
  8174. setInterval(() => {
  8175.  
  8176. if (!arr.length) return;
  8177.  
  8178. const p = Date.now();
  8179. let deleteKeys = [];
  8180. arr.forEach((entry, key) => {
  8181.  
  8182.  
  8183. if (entry.cid === -1) {
  8184. entry.cid = -2;
  8185. } else if (entry.cid === -2) {
  8186.  
  8187. let offset = p - entry.add
  8188. if (offset < 0) offset = 0;
  8189. let delay2 = entry.delay - offset;
  8190. if (delay2 < 0) delay2 = 0;
  8191. entry.cid = setTimeout(entry.q(), delay2);
  8192. entry.q = null;
  8193.  
  8194. } else if (entry.add + entry.delay < p) {
  8195. deleteKeys.push(key);
  8196.  
  8197. }
  8198.  
  8199. })
  8200.  
  8201. for (const key of deleteKeys) arr.delete(key);
  8202.  
  8203. }, 2000)
  8204.  
  8205. }
  8206.  
  8207.  
  8208.  
  8209.  
  8210. cProto.async = function (e, h) {
  8211.  
  8212. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  8213.  
  8214. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  8215.  
  8216. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  8217.  
  8218.  
  8219. if (!this.__asyncInited__) {
  8220. this.__asyncInited__ = 1;
  8221. __asyncInit__();
  8222. }
  8223. mcw += 2; // 2K+3, 2K+4, ...
  8224. if (mcw > 1e9) mcw = mcw % 1e4;
  8225. const cid = mcw;
  8226. const q = () => {
  8227. return () => {
  8228. console.log('async h > 8000');
  8229. e.call(this);
  8230. }
  8231. }
  8232. // setTimeout(q, delay)
  8233. arr.set(cid, {
  8234. cid: -1, // -1 -> -2 -> cid
  8235. add: Date.now(),
  8236. q,
  8237. delay: h
  8238. });
  8239. // console.log('cid-async', cid)
  8240. return cid;
  8241.  
  8242. }
  8243.  
  8244.  
  8245. cProto.cancelAsync = function (e) {
  8246.  
  8247. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  8248.  
  8249. // console.log('cid-unasync', e)
  8250.  
  8251. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  8252.  
  8253. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  8254.  
  8255. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  8256.  
  8257. if (!arr.has(e)) return; // duplciated cancel
  8258.  
  8259. const entry = arr.get(e);
  8260. if (entry.cid < 0) {
  8261. entry.cid = 0;
  8262. arr.delete(e);
  8263. } else {
  8264. clearTimeout(entry.cid); // cid >= 1
  8265. entry.cid = 0;
  8266. arr.delete(e);
  8267. }
  8268.  
  8269. } else {
  8270.  
  8271. return this.cancelAsync71(e);
  8272.  
  8273. }
  8274.  
  8275. }
  8276.  
  8277. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  8278.  
  8279. } else {
  8280. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  8281.  
  8282. }
  8283.  
  8284. })();
  8285.  
  8286. console.log("[End]");
  8287.  
  8288. console.groupEnd();
  8289.  
  8290.  
  8291.  
  8292. onManagerFound(__dummyManager__);
  8293.  
  8294. }).catch(console.warn);
  8295.  
  8296.  
  8297.  
  8298.  
  8299. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  8300.  
  8301.  
  8302. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  8303.  
  8304.  
  8305. mightFirstCheckOnYtInit();
  8306. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  8307. console.log("[Begin]");
  8308. (() => {
  8309.  
  8310. const tag = "yt-live-interactivity-component-background"
  8311. const dummy = document.createElement(tag);
  8312.  
  8313. const cProto = getProto(dummy);
  8314. if (!cProto || !cProto.attached) {
  8315. console.warn(`proto.attached for ${tag} is unavailable.`);
  8316. return;
  8317. }
  8318.  
  8319.  
  8320. cProto.__toStopAfterRun__ = function (hostElement) {
  8321. let mo = new MutationObserver(() => {
  8322. mo.disconnect();
  8323. mo.takeRecords();
  8324. mo = null;
  8325. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  8326. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  8327. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  8328. });
  8329. });
  8330. mo.observe(hostElement, { subtree: true, childList: true });
  8331. }
  8332.  
  8333. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  8334.  
  8335. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  8336. cProto.maybeLoadAnimationBackground = function () {
  8337. let toRun = true;
  8338. let stopAfterRun = false;
  8339. if (!this.__bypassDisableAnimationBackground__) {
  8340. let doFix = false;
  8341. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  8342. if (!this.lottieAnimation) {
  8343. doFix = true;
  8344. }
  8345. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  8346. doFix = true;
  8347. }
  8348. if (doFix) {
  8349. if (this.useAnimationBackground === true) {
  8350. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  8351. }
  8352. toRun = true;
  8353. stopAfterRun = true;
  8354. }
  8355. }
  8356. if (toRun) {
  8357. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  8358. this.__toStopAfterRun__(this.hostElement); // primary
  8359. }
  8360. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  8361. if (stopAfterRun && this.lottieAnimation) {
  8362. this.lottieAnimation.stop(); // fallback if no mutation
  8363. }
  8364. return r;
  8365. }
  8366. }
  8367.  
  8368. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION${INTERACTIVITY_BACKGROUND_ANIMATION} - OK`);
  8369.  
  8370. } else {
  8371. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION${INTERACTIVITY_BACKGROUND_ANIMATION} - NG`);
  8372.  
  8373. }
  8374.  
  8375. })();
  8376.  
  8377. console.log("[End]");
  8378.  
  8379. console.groupEnd();
  8380.  
  8381.  
  8382. }).catch(console.warn);
  8383.  
  8384. }
  8385.  
  8386.  
  8387. if (DELAY_FOCUSEDCHANGED) {
  8388.  
  8389. customElements.whenDefined("yt-live-chat-text-input-field-renderer").then(() => {
  8390.  
  8391.  
  8392. mightFirstCheckOnYtInit();
  8393. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-input-field-renderer hacks");
  8394. console.log("[Begin]");
  8395. (() => {
  8396.  
  8397. const tag = "yt-live-chat-text-input-field-renderer"
  8398. const dummy = document.createElement(tag);
  8399.  
  8400. const cProto = getProto(dummy);
  8401. if (!cProto || !cProto.attached) {
  8402. console.warn(`proto.attached for ${tag} is unavailable.`);
  8403. return;
  8404. }
  8405.  
  8406. if (DELAY_FOCUSEDCHANGED && typeof cProto.focusedChanged === 'function' && cProto.focusedChanged.length === 0 && !cProto.focusedChanged372) {
  8407. cProto.focusedChanged372 = cProto.focusedChanged;
  8408. cProto.focusedChanged = function () {
  8409. Promise.resolve().then(() => {
  8410. if (this.isAttached === true) this.focusedChanged372();
  8411. });
  8412. }
  8413. }
  8414.  
  8415. })();
  8416.  
  8417. console.log("[End]");
  8418.  
  8419. console.groupEnd();
  8420.  
  8421. });
  8422.  
  8423. }
  8424.  
  8425.  
  8426. }
  8427.  
  8428.  
  8429.  
  8430.  
  8431. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  8432.  
  8433. const fixJsonParse = () => {
  8434.  
  8435. let p1 = window.onerror;
  8436.  
  8437. try {
  8438. JSON.parse("{}");
  8439. } catch (e) {
  8440. console.warn(e);
  8441. }
  8442.  
  8443. let p2 = window.onerror;
  8444.  
  8445. if (p1 !== p2) {
  8446.  
  8447.  
  8448. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  8449. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  8450. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  8451. );
  8452.  
  8453. console.warn("\nJSON.parse is hacked (e.g. Brave's script injection) which causes window.onerror changes on every JSON.parse call.\nPlease install https://gf.qytechs.cn/scripts/473972-youtube-js-engine-tamer to fix the issue.\n");
  8454.  
  8455. console.groupEnd();
  8456.  
  8457. }
  8458.  
  8459. }
  8460.  
  8461. if (CHECK_JSONPRUNE) {
  8462. promiseForCustomYtElementsReady.then(fixJsonParse);
  8463. }
  8464.  
  8465. });
  8466.  
  8467.  
  8468.  
  8469. })({ IntersectionObserver });

QingJ © 2025

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