YouTube 超快聊天

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

当前为 2023-12-20 提交的版本,查看 最新版本

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