YouTube 超快聊天

YouTube直播聊天的終極性能提升

目前為 2024-02-23 提交的版本,檢視 最新版本

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

QingJ © 2025

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