YouTube 超快聊天

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

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

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

QingJ © 2025

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