YouTube 超快聊天

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

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

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