YouTube 超快聊天

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

当前为 2023-08-27 提交的版本,查看 最新版本

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