YouTube 超快聊天

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

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

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