YouTube 超快聊天

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

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

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