YouTube 超快聊天

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

当前为 2024-12-17 提交的版本,查看 最新版本

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