YouTube 超快聊天

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

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

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

QingJ © 2025

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