YouTube 超快聊天

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

目前为 2023-08-28 提交的版本。查看 最新版本

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