YouTube 超快聊天

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

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

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.66.6
  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. /** @type {WeakMapConstructor} */
  44. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  45.  
  46. // *********** DON'T REPORT NOT WORKING DUE TO THE CHANGED SETTINGS ********************
  47. // 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
  48.  
  49. 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
  50. 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)
  51. 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)
  52.  
  53. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages <<< DON'T CHANGE >>>
  54. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  55. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  56.  
  57. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  58. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  59. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  60. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  61.  
  62. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  63. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  64.  
  65. // Replace requestAnimationFrame timers with custom implementation
  66. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  67. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  68. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  69. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  70.  
  71. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  72. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  73.  
  74. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  75. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  76.  
  77. // Data Manipulation for Participants (Participant List)
  78. // << if DO_PARTICIPANT_LIST_HACKS >>
  79. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  80. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  81. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  82. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  83. // << end >>
  84.  
  85. // show more button
  86. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  87.  
  88. // faster stampDomArray_ for participants list creation
  89. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  90. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  91.  
  92. // reuse yt components
  93. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  94.  
  95. // ShadyDom Free is buggy
  96. const DISABLE_FLAGS_SHADYDOM_FREE = true;
  97.  
  98. // images <Group#I01>
  99. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  100. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  101. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  102.  
  103. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  104. // << if DO_LINK_PREFETCH >>
  105. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  106. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  107. const SKIP_PRELOAD_EMOJI = true;
  108. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  109. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  110. // << end >>
  111.  
  112. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  113. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  114. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  115.  
  116. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  117. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  118.  
  119. const ATTEMPT_ANIMATED_TICKER_BACKGROUND = ''; // false OR '' for disabled, 'linear', 'steps' for easing-function
  120. // <<<< ATTEMPT_ANIMATED_TICKER_BACKGROUND to be reviewed with memory leakage issues >>>>
  121. // << if ATTEMPT_ANIMATED_TICKER_BACKGROUND >>
  122. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  123. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  124. // [limiting 500 max steps] is recommended for "confortable visual change"
  125. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  126. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  127. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  128. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  129. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  130. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  131. 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
  132. // << end >>
  133.  
  134. const FIX_TOOLTIP_DISPLAY = true; // changed in 2024.05.02
  135. const USE_VANILLA_DEREF = true;
  136. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  137.  
  138.  
  139. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  140. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = false; // pause auto scroll faster when the context menu is about to show
  141. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  142.  
  143. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  144. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  145. const NO_ITEM_TAP_FOR_NON_STATIONARY_TAP = true; // dont open the menu (e.g. text message) if cursor is moved or long press
  146. const TAP_ACTION_DURATION = 280; // exceeding 280ms would not consider as a tap action
  147. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  148. // const FIX_MENU_CAPTURE_SCROLL = true;
  149. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  150.  
  151. const RAF_FIX_keepScrollClamped = true;
  152. const RAF_FIX_scrollIncrementally = 2; // 0: no action; 1: basic fix; 2: also fix scroll position
  153.  
  154. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  155. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  156.  
  157. const CHECK_JSONPRUNE = true; // This is a bug in Brave
  158. // << end >>
  159.  
  160. // const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = false;
  161.  
  162. const CHANGE_DATA_FLUSH_ASYNC = false;
  163. // CHANGE_DATA_FLUSH_ASYNC is disabled due to bug report: https://greasyfork.org/scripts/469878/discussions/199479
  164. // to be further investigated
  165.  
  166. const CHANGE_MANAGER_UNSUBSCRIBE = true;
  167.  
  168. const INTERACTIVITY_BACKGROUND_ANIMATION = 1; // mostly for pinned message
  169. // 0 = default Yt animation background [= no fix];
  170. // 1 = disable default animation background [= keep special animation];
  171. // 2 = disable all animation backgrounds [= no animation backbround]
  172.  
  173. const CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED = true;
  174.  
  175. const MAX_TOOLTIP_NO_WRAP_WIDTH = '72vw'; // '' for disable; accept values like '60px', '25vw'
  176.  
  177.  
  178.  
  179. // (Dec 2024: AMEND_TICKER_handleLiveChatAction to be removed)
  180. const AMEND_TICKER_handleLiveChatAction = false; // to fix ticker duplication and unresponsively fast ticker generation
  181. // AMEND_TICKER_handleLiveChatAction to be fixed (2024.05.21)
  182.  
  183. // (Dec 2024: AMEND_TICKER_handleLiveChatAction_v3 to be removed)
  184. const AMEND_TICKER_handleLiveChatAction_v3 = true; // responsiveness fix (Major Feature)
  185.  
  186. const USE_ADVANCED_TICKING = true; // added in Dec 2024 v0.66.0; need to ensure it would not affect the function if ticker design changed. to be reviewed
  187. const END_ANIMATING_TICKERS = true; // added in Dec 2024 v0.66.5; see pressure test like https://www.youtube.com/watch?v=CQaUs-vNgXo
  188.  
  189.  
  190.  
  191. const ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION = true;
  192. const ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME = true;
  193. const FIX_BATCH_TICKER_ORDER = true;
  194.  
  195. const DISABLE_Translation_By_Google = true;
  196.  
  197. const FASTER_ICON_RENDERING = true;
  198.  
  199. const DELAY_FOCUSEDCHANGED = true;
  200.  
  201. const skipErrorForhandleAddChatItemAction_ = true; // currently depends on ENABLE_NO_SMOOTH_TRANSFORM
  202. const fixChildrenIssue801 = true; // if __children801__ is set [fix polymer controller method extration for `.set()`]
  203.  
  204. const SUPPRESS_refreshOffsetContainerHeight_ = true; // added in FEB 2024; true for default layout options; no effect if ENABLE_NO_SMOOTH_TRANSFORM is false
  205.  
  206. const NO_FILTER_DROPDOWN_BORDER = true; // added in 2024.03.02
  207.  
  208. const FIX_ANIMATION_TICKER_TEXT_POSITION = true; // CSS fix; experimental; added in 2024.04.07
  209. const FIX_AUTHOR_CHIP_BADGE_POSITION = true;
  210.  
  211. const FIX_ToggleRenderPolymerControllerExtractionBug = false; // to be reviewed
  212.  
  213. const REACTION_ANIMATION_PANEL_CSS_FIX = true;
  214.  
  215. // -------------------------------
  216.  
  217.  
  218. const FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP = true; // To fix Memory Leakage in yt-live-chat-ticker-...-item-renderer
  219. const FIX_MEMORY_LEAKAGE_TICKER_STATSBAR = true; // To fix Memory Leakage in updateStatsBarAndMaybeShowAnimation
  220. const FIX_MEMORY_LEAKAGE_TICKER_TIMER = true; // To fix Memory Leakage in setContainerWidth, slideDown, collapse // Dec 2024 fix in advance tickering
  221. const FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth = true; // To fix Memory Leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth()
  222.  
  223. // leakage in ytd-sponsorships-live-chat-gift-purchase-announcement-renderer - to be confirmed
  224.  
  225. // <<<<< FOR MEMORY LEAKAGE >>>>
  226. const DEBUG_wmList = false;
  227. let DEBUG_wmList_started = false;
  228. // const FLAG_001 = true;
  229. const FLAG_001a = false;
  230. const FLAG_001b = false;
  231. const FLAG_001c = false;
  232. const FLAG_001d = false;
  233. const FLAG_001e = false;
  234. const FLAG_001f = false;
  235. // const FLAG_001g = true;
  236.  
  237.  
  238.  
  239. /**
  240. *
  241. *
  242. *
  243. *
  244. *
  245. rendererStamperObserver_: function(a, b, c) {
  246. if (c.path == a) {
  247. if (c.value === void 0 && !this.hasDataPath_[a])
  248. return;
  249. this.hasDataPath_[a] = c.value !== void 0
  250. }
  251. this.rendererStamperApplyChangeRecord_(a, b, c)
  252. },
  253.  
  254.  
  255. addStampDomObserverFns_: function() {
  256. for (var a in this.stampDom) {
  257. var b = this.stampDom[a];
  258. b.id ? (this[SQa(b.id)] = this.rendererStamperObserver_.bind(this, a, b.id),
  259. this.hasDataPath_[a] = !1) : Er(new Dn("Bad rendererstamper config",this.is + ":" + a))
  260. }
  261. },
  262. *
  263. *
  264. *
  265. *
  266. *
  267. */
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. // <<<<< FOR MEMORY LEAKAGE >>>>
  275.  
  276. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  277. /*
  278.  
  279. ### Time Approach
  280.  
  281. // all below values can make the time interval > 250ms
  282. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  283. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  284. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  285. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  286. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  287. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  288.  
  289. ### Pixel Check
  290. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  291. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  292. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  293.  
  294. ### Example - totalDuration = 280000
  295. totalDuration 280000
  296. stepInterval 0.5
  297. numOfSteps = Math.round(100 / stepInterval) = 200
  298. time interval = 280000 / 200 = 1400ms <acceptable>
  299.  
  300. ### Example - totalDuration = 18000
  301. totalDuration 18000
  302. stepInterval 5
  303. numOfSteps = Math.round(100 / stepInterval) = 20
  304. time interval = 18000 / 20 = 900ms <acceptable>
  305.  
  306. ### Example - totalDuration = 5000
  307. totalDuration 5000
  308. stepInterval 5
  309. numOfSteps = Math.round(100 / stepInterval) = 20
  310. time interval = 5000 / 20 = 250ms <threshold value>
  311.  
  312. ### Example - totalDuration = 3600
  313. totalDuration 3600
  314. stepInterval 5
  315. numOfSteps = Math.round(100 / stepInterval) = 20
  316. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  317.  
  318. */
  319.  
  320. // =======================================================================================================
  321.  
  322. // AUTOMAICALLY DETERMINED
  323. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  324. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  325. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  326. let runTickerClassName = 'run-ticker';
  327.  
  328. const dummyImgURL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  329. /*
  330. WebP: data:image/webp;base64,UklGRjAB
  331. PNG: data:image/png;base64,iVBORw0KGg==
  332. JPEG: data:image/jpeg;base64,/9j/4AA=
  333. GIF: data:image/gif;base64,R0lGODlhAQABAIA=
  334. BMP: data:image/bmp;base64,Qk1oAAAA
  335. SVG: data:image/svg+xml;base64,PHN2Zy8+Cg==
  336.  
  337. WebP: data:image/webp;base64,AAAAAAA=
  338. PNG: data:image/png;base64,AAAAAAA=
  339. JPEG: data:image/jpeg;base64,AAAAAAA=
  340. GIF: data:image/gif;base64,AAAAAAA=
  341. BMP: data:image/bmp;base64,AAAAAAA=
  342.  
  343. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  344.  
  345.  
  346. */
  347.  
  348. // image sizing code
  349. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  350.  
  351.  
  352. // function KC(a, b, c, d) {
  353. // d = void 0 === d ? "width" : d;
  354. // if (!a || !a.length)
  355. // return null;
  356. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  357. // var e = window.devicePixelRatio;
  358. // 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"));
  359. // HC = e
  360. // } else
  361. // HC || (HC = window.devicePixelRatio);
  362. // e = HC;
  363. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  364. // if (z("kevlar_tuner_min_thumbnail_quality"))
  365. // return a[0].url || null;
  366. // e = a.length;
  367. // if (z("kevlar_tuner_max_thumbnail_quality"))
  368. // return a[e - 1].url || null;
  369. // if (c)
  370. // for (var h = 0; h < e; h++)
  371. // if (0 <= a[h].url.indexOf(c))
  372. // return a[h].url || null;
  373. // for (c = 0; c < e; c++)
  374. // if (a[c][d] >= b)
  375. // return a[c].url || null;
  376. // for (b = e - 1; 0 < b; b--)
  377. // if (a[b][d])
  378. // return a[b].url || null;
  379. // return a[0].url || null
  380. // }
  381.  
  382. const { IntersectionObserver } = __CONTEXT__;
  383. let _x69;
  384. try {
  385. _x69 = document.createAttributeNS("http://www.w3.org/2000/svg", "nil").addEventListener;
  386. } catch (e) { }
  387. const pureAddEventListener = _x69;
  388. if (!pureAddEventListener) return console.warn("pureAddEventListener cannot be obtained.");
  389.  
  390. /** @type {globalThis.PromiseConstructor} */
  391. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  392.  
  393. // let jsonParseFix = null;
  394.  
  395. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  396. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  397.  
  398. // necessity of cssText3_smooth_transform_position to be checked.
  399. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  400.  
  401. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  402. position: static !important;
  403. }
  404.  
  405. `: '';
  406.  
  407. // fallback if dummy style fn fails
  408. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  409.  
  410. /* optional */
  411. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  412. height: auto !important;
  413. min-height: unset !important;
  414. }
  415.  
  416. #items.style-scope.yt-live-chat-item-list-renderer {
  417. transform: translateY(0px) !important;
  418. }
  419.  
  420. /* optional */
  421.  
  422. `: '';
  423.  
  424. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  425.  
  426. /* ------------------------------------------------------------------------------------------------------------- */
  427.  
  428. 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 {
  429. contain: layout style;
  430. }
  431.  
  432. #items.style-scope.yt-live-chat-item-list-renderer {
  433. contain: layout paint style;
  434. }
  435.  
  436. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  437. contain: style;
  438. }
  439.  
  440. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  441. contain: size style;
  442. }
  443.  
  444. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  445. contain: size layout paint style;
  446. }
  447.  
  448. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  449. contain: layout paint style;
  450. }
  451.  
  452. 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 {
  453. contain: layout style;
  454. }
  455.  
  456. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  457. contain: layout paint style;
  458. }
  459.  
  460. /* ------------------------------------------------------------------------------------------------------------- */
  461.  
  462. ` : '';
  463.  
  464. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  465.  
  466. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  467. top: 4px;
  468. transition-property: top;
  469. bottom: unset;
  470. }
  471.  
  472. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  473. top: -42px;
  474. }
  475.  
  476. `: '';
  477.  
  478. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  479.  
  480. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  481. contain: layout style;
  482. }
  483.  
  484. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  485. overflow: visible;
  486. }
  487.  
  488. `: '';
  489.  
  490. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  491.  
  492. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  493. --yt-live-chat-action-panel-top-border: none;
  494. }
  495.  
  496. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  497. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  498. }
  499.  
  500. html #panel-pages.yt-live-chat-renderer {
  501. border-top: 0;
  502. border-bottom: 0;
  503. }
  504.  
  505. `: '';
  506.  
  507. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  508.  
  509. img,
  510. yt-img-shadow[height][width],
  511. yt-img-shadow {
  512. content-visibility: visible !important;
  513. }
  514.  
  515. ` : '';
  516.  
  517. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  518.  
  519. /* remove YouTube constant will-change */
  520. /* constant value will slow down the performance; default auto */
  521.  
  522. /* www-player.css */
  523. html .ytp-contextmenu,
  524. html .ytp-settings-menu {
  525. will-change: unset;
  526. }
  527.  
  528. /* frequently matched elements */
  529. html .fill.yt-interaction,
  530. html .stroke.yt-interaction,
  531. html .yt-spec-touch-feedback-shape__fill,
  532. html .yt-spec-touch-feedback-shape__stroke {
  533. will-change: unset;
  534. }
  535.  
  536. /* live_chat_polymer.js */
  537. /*
  538. html .toggle-button.tp-yt-paper-toggle-button,
  539. html #primaryProgress.tp-yt-paper-progress,
  540. html #secondaryProgress.tp-yt-paper-progress,
  541. html #onRadio.tp-yt-paper-radio-button,
  542. html .fill.yt-interaction,
  543. html .stroke.yt-interaction,
  544. html .yt-spec-touch-feedback-shape__fill,
  545. html .yt-spec-touch-feedback-shape__stroke {
  546. will-change: unset;
  547. }
  548. */
  549.  
  550. /* desktop_polymer_enable_wil_icons.js */
  551. /* html .fill.yt-interaction,
  552. html .stroke.yt-interaction, */
  553. html tp-yt-app-header::before,
  554. html tp-yt-iron-list,
  555. html #items.tp-yt-iron-list > *,
  556. html #onRadio.tp-yt-paper-radio-button,
  557. html .toggle-button.tp-yt-paper-toggle-button,
  558. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  559. html #items.ytd-post-multi-image-renderer,
  560. html #items.ytd-horizontal-card-list-renderer,
  561. html #items.yt-horizontal-list-renderer,
  562. html #left-arrow.yt-horizontal-list-renderer,
  563. html #right-arrow.yt-horizontal-list-renderer,
  564. html #items.ytd-video-description-infocards-section-renderer,
  565. html #items.ytd-video-description-music-section-renderer,
  566. html #chips.ytd-feed-filter-chip-bar-renderer,
  567. html #chips.yt-chip-cloud-renderer,
  568. html #items.ytd-merch-shelf-renderer,
  569. html #items.ytd-product-details-image-carousel-renderer,
  570. html ytd-video-preview,
  571. html #player-container.ytd-video-preview,
  572. html #primaryProgress.tp-yt-paper-progress,
  573. html #secondaryProgress.tp-yt-paper-progress,
  574. html ytd-miniplayer[enabled] /* ,
  575. html .yt-spec-touch-feedback-shape__fill,
  576. html .yt-spec-touch-feedback-shape__stroke */ {
  577. will-change: unset;
  578. }
  579.  
  580. /* other */
  581. .ytp-videowall-still-info-content[class],
  582. .ytp-suggestion-image[class] {
  583. will-change: unset !important;
  584. }
  585.  
  586. ` : '';
  587.  
  588. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  589. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  590.  
  591. elzm-fonts {
  592. visibility: collapse;
  593. position: fixed;
  594. top: -10px;
  595. left: -10px;
  596. font-size: 10pt;
  597. line-height: 100%;
  598. width: 100px;
  599. height: 100px;
  600. transform: scale(0.1);
  601. transform: scale(0.01);
  602. transform: scale(0.001);
  603. transform-origin: 0 0;
  604. contain: strict;
  605. display: block;
  606.  
  607. pointer-events: none !important;
  608. user-select: none !important;
  609. }
  610.  
  611. elzm-fonts[id]#elzm-fonts-yk75g {
  612. user-select: none !important;
  613. pointer-events: none !important;
  614. }
  615.  
  616. elzm-font {
  617. visibility: collapse;
  618. position: absolute;
  619. line-height: 100%;
  620. width: 100px;
  621. height: 100px;
  622. contain: strict;
  623. display: block;
  624.  
  625. user-select: none !important;
  626. pointer-events: none !important;
  627. }
  628.  
  629. elzm-font::before {
  630. visibility: collapse;
  631. position: absolute;
  632. line-height: 100%;
  633. width: 100px;
  634. height: 100px;
  635. contain: strict;
  636. display: block;
  637.  
  638. 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';
  639.  
  640. user-select: none !important;
  641. pointer-events: none !important;
  642. }
  643.  
  644. `: '';
  645.  
  646. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  647. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  648. -webkit-backdrop-filter: none;
  649. backdrop-filter: none;
  650. }
  651. `: '';
  652.  
  653. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  654.  
  655. @keyframes blinker-miuzp {
  656. 0%, 60%, 100% {
  657. opacity: 1;
  658. }
  659. 30% {
  660. opacity: 0.6;
  661. }
  662. }
  663.  
  664. yt-icon-button#show-more.has-new-messages-miuzp {
  665. animation: blinker-miuzp 1.74s linear infinite;
  666. }
  667.  
  668. `: '';
  669.  
  670. const cssText11_entire_message_clickable = FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK ? `
  671.  
  672. yt-live-chat-paid-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  673. pointer-events: none !important;
  674. }
  675.  
  676. yt-live-chat-membership-item-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  677. pointer-events: none !important;
  678. }
  679.  
  680. yt-live-chat-paid-sticker-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  681. pointer-events: none !important;
  682. }
  683.  
  684. yt-live-chat-text-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  685. pointer-events: none !important; /* TO_BE_REVIEWED */
  686. }
  687.  
  688. yt-live-chat-auto-mod-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  689. pointer-events: none !important;
  690. }
  691.  
  692. `: '';
  693.  
  694. const cssText12_nowrap_tooltip = MAX_TOOLTIP_NO_WRAP_WIDTH && typeof MAX_TOOLTIP_NO_WRAP_WIDTH === 'string' ? `
  695.  
  696.  
  697. tp-yt-paper-tooltip[role="tooltip"] {
  698. box-sizing: content-box !important;
  699. margin: 0px !important;
  700. padding: 0px !important;
  701. contain: none !important;
  702. }
  703.  
  704. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"] {
  705. box-sizing: content-box !important;
  706. display: inline-block;
  707. contain: none !important;
  708. }
  709.  
  710.  
  711. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"]{
  712. max-width: ${MAX_TOOLTIP_NO_WRAP_WIDTH};
  713. width: max-content;
  714. text-overflow: ellipsis;
  715. overflow: hidden;
  716. white-space: nowrap;
  717. }
  718.  
  719.  
  720. `: '';
  721.  
  722.  
  723. const cssText13_no_text_select_when_menu_visible = `
  724. [menu-visible] {
  725. --sfc47-text-select: none;
  726. }
  727. [menu-visible] #header[id][class],
  728. [menu-visible] #content[id][class],
  729. [menu-visible] #header[id][class] *,
  730. [menu-visible] #content[id][class] * {
  731. user-select: var(--sfc47-text-select) !important;
  732. }
  733. [menu-visible] #menu {
  734. --sfc47-text-select: inherit;
  735. }
  736. `;
  737.  
  738. const cssText14_NO_FILTER_DROPDOWN_BORDER = NO_FILTER_DROPDOWN_BORDER ? `
  739. yt-live-chat-header-renderer.yt-live-chat-renderer #label.yt-dropdown-menu::before {
  740. border:0;
  741. }
  742. ` : '';
  743.  
  744. const cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION = FIX_ANIMATION_TICKER_TEXT_POSITION ? `
  745. .style-scope.yt-live-chat-ticker-renderer #animation-container[id][class] {
  746. position: relative;
  747. display: grid;
  748. grid-auto-columns: 1fr;
  749. grid-auto-rows: 1fr;
  750. grid-template-columns: repeat(1, 1fr);
  751. gap: 7px;
  752. padding-bottom: 0;
  753. margin-bottom: 0;
  754. padding-top: 0;
  755. align-self: flex-start;
  756. flex-wrap: nowrap;
  757. margin-top: 1px;
  758. }
  759.  
  760. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class] {
  761. margin-top: 0px;
  762. margin-bottom: 0px;
  763. flex-direction: row;
  764. flex-wrap: nowrap;
  765. align-items: center;
  766. justify-content: flex-start;
  767. }
  768.  
  769. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class]:first-child::after {
  770. content: '補';
  771. visibility: collapse;
  772. display: inline-block;
  773. position: relative;
  774. width: 0;
  775. line-height: 22px;
  776. }
  777.  
  778. ` : '';
  779.  
  780. const cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION = FIX_AUTHOR_CHIP_BADGE_POSITION ? `
  781. #card #author-name-chip > yt-live-chat-author-chip[single-line] {
  782. flex-wrap: nowrap;
  783. white-space: nowrap;
  784. display: inline-flex;
  785. flex-direction: row;
  786. text-wrap: nowrap;
  787. flex-shrink: 0;
  788. align-items: center;
  789. }
  790.  
  791. #card #author-name-chip {
  792. display: inline-flex;
  793. flex-direction: row;
  794. align-items: flex-start;
  795. }
  796. `: '';
  797.  
  798.  
  799. // Example: https://www.youtube.com/watch?v=Xfytz-igsuc
  800. const cssText17_FIX_overwidth_banner_message = `
  801. yt-live-chat-banner-manager#live-chat-banner.style-scope.yt-live-chat-item-list-renderer {
  802. max-width: 100%;
  803. box-sizing: border-box;
  804. }
  805. `;
  806.  
  807.  
  808. const cssText18_REACTION_ANIMATION_PANEL_CSS_FIX = REACTION_ANIMATION_PANEL_CSS_FIX ? `
  809. #reaction-control-panel-overlay[class] {
  810. contain: strict;
  811. margin: 0;
  812. padding: 0;
  813. border: 0;
  814. box-sizing: border-box;
  815. will-change: initial;
  816. }
  817. #reaction-control-panel-overlay[class] *[class] {
  818. will-change: initial;
  819. }
  820. `: '';
  821.  
  822. const cssText19_FOR_ADVANCED_TICKING = `
  823. ticker-bg-overlay {
  824. display: block;
  825. position: absolute;
  826. z-index: -1;
  827. box-sizing: border-box;
  828. border: 0;
  829. padding: 0;
  830. margin: 0;
  831. width: 200%;
  832. top: 0;
  833. bottom: 0;
  834. left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  835. contain: strict;
  836. }
  837. ticker-bg-overlay-end {
  838. position: absolute;
  839. right: 0px;
  840. top: 50%;
  841. display: block;
  842. width: 1px;
  843. height: 1px;
  844. opacity: 0;
  845. pointer-events: none;
  846. box-sizing: border-box;
  847. border: 0;
  848. padding: 0;
  849. margin: 0;
  850. contain: strict;
  851. }
  852.  
  853. ticker-bg-overlay-end2 {
  854.  
  855. all:unset;
  856. position: fixed;
  857. display: block;
  858. margin-left: -0.5px;
  859. top: 8px;
  860. left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  861.  
  862. width: 1px;
  863. height: 1px;
  864. opacity: 0;
  865. pointer-events: none;
  866. box-sizing: border-box;
  867. border: 0;
  868. padding: 0;
  869. margin: 0;
  870. contain: strict;
  871. z-index: -1;
  872. visibility: collapse;
  873.  
  874. }
  875.  
  876. .ticker-no-transition-time, .ticker-no-transition-time [id] {
  877. transition-duration: 0s !important;
  878. }
  879.  
  880. yt-live-chat-ticker-creator-goal-view-model ~ yt-live-chat-ticker-creator-goal-view-model {
  881. transition-duration: 0s !important;
  882. /* transition: initial !important; */
  883. }
  884.  
  885. yt-live-chat-ticker-paid-message-item-renderer ~ yt-live-chat-ticker-paid-message-item-renderer {
  886. transition-duration: 0s !important;
  887. /* transition: initial !important; */
  888. }
  889.  
  890. yt-live-chat-ticker-paid-sticker-item-renderer ~ yt-live-chat-ticker-paid-sticker-item-renderer {
  891. transition-duration: 0s !important;
  892. /* transition: initial !important; */
  893. }
  894.  
  895. yt-live-chat-ticker-sponsor-item-renderer ~ yt-live-chat-ticker-sponsor-item-renderer {
  896. transition-duration: 0s !important;
  897. /* transition: initial !important; */
  898. }
  899.  
  900.  
  901. /*
  902.  
  903.  
  904. ey.style.position = 'absolute';
  905. ey.style.right = '0px';
  906. ey.style.top = '50%';
  907. ey.style.display='block';
  908. ey.style.width='1px';
  909. ey.style.height='1px';
  910. ey.style.opacity = '0';
  911.  
  912. em.style.display = 'block';
  913. em.style.position = 'absolute';
  914. em.style.boxSizing = 'border-box';
  915. em.style.width = '200%';
  916. em.style.top = '0';
  917. em.style.bottom = '0';
  918. // em.style.height = '100%';
  919.  
  920.  
  921. // em.style.left = '-50%';
  922. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  923.  
  924. */
  925.  
  926. `;
  927.  
  928. const addCss = () => `
  929.  
  930. @property --ticker-rtime {
  931. syntax: "<percentage>";
  932. inherits: false;
  933. initial-value: 0%;
  934. }
  935.  
  936. /*
  937. .run-ticker {
  938. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  939. }
  940.  
  941. .run-ticker-test {
  942. background: #00000001;
  943. }
  944.  
  945. .run-ticker-forced,
  946. yt-live-chat-ticker-renderer #items > * > #container.run-ticker-forced,
  947. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker-forced[class]
  948. {
  949. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2)) !important;
  950. }
  951. */
  952.  
  953. .run-ticker {
  954. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  955. }
  956.  
  957. .run-ticker,
  958. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  959. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  960. {
  961. background: var(--ticker-bg) !important;
  962. }
  963.  
  964. yt-live-chat-ticker-dummy777-item-renderer {
  965. background: #00000001;
  966. }
  967.  
  968. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  969. position: fixed !important;
  970. top: -1000px !important;
  971. left: -1000px !important;
  972. font-size: 1px !important;
  973. color: transparent !important;
  974. pointer-events: none !important;
  975. z-index: -1 !important;
  976. contain: strict !important;
  977. box-sizing: border-box !important;
  978. pointer-events: none !important;
  979. user-select: none !important;
  980. max-width: 1px !important;
  981. max-height: 1px !important;
  982. overflow: hidden !important;
  983. visibility: collapse !important;
  984. display: none !important;
  985. }
  986.  
  987. yt-live-chat-ticker-dummy777-item-renderer #container {
  988. background: inherit;
  989. }
  990.  
  991.  
  992. ${cssText8_fonts_pre_render}
  993.  
  994. ${cssText9_no_backdrop_filter_when_menu_shown}
  995.  
  996. @supports (contain: layout paint style) {
  997.  
  998. ${cssText5}
  999.  
  1000. }
  1001.  
  1002. @supports (color: var(--general)) {
  1003.  
  1004. html {
  1005. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  1006. }
  1007.  
  1008. ${cssText3_smooth_transform_position}
  1009.  
  1010. ${cssText7c_will_change_unset}
  1011.  
  1012. ${cssText7b_content_visibility_unset}
  1013.  
  1014. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  1015. overflow-y: scroll;
  1016. padding-right: 0;
  1017. }
  1018.  
  1019. ${cssText4_smooth_transform_forced_props}
  1020.  
  1021. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  1022. pointer-events: none !important;
  1023. }
  1024.  
  1025. #continuations, #continuations * {
  1026. contain: strict;
  1027. position: fixed;
  1028. top: 2px;
  1029. height: 1px;
  1030. width: 2px;
  1031. height: 1px;
  1032. visibility: collapse;
  1033. }
  1034.  
  1035. ${cssText6b_show_more_button}
  1036.  
  1037. ${cssText6d_input_panel_border}
  1038.  
  1039. ${cssText6c_input_panel_overflow}
  1040.  
  1041. }
  1042.  
  1043.  
  1044. @supports (overflow-anchor: auto) {
  1045.  
  1046. .no-anchor * {
  1047. overflow-anchor: none;
  1048. }
  1049. .no-anchor > item-anchor {
  1050. overflow-anchor: auto;
  1051. }
  1052.  
  1053. item-anchor {
  1054.  
  1055. height:1px;
  1056. width: 100%;
  1057. transform: scaleY(0.00001);
  1058. transform-origin:0 0;
  1059. contain: strict;
  1060. opacity:0;
  1061. display:flex;
  1062. position:relative;
  1063. flex-shrink:0;
  1064. flex-grow:0;
  1065. margin-bottom:0;
  1066. overflow:hidden;
  1067. box-sizing:border-box;
  1068. visibility: visible;
  1069. content-visibility: visible;
  1070. contain-intrinsic-size: auto 1px;
  1071. pointer-events:none !important;
  1072.  
  1073. }
  1074.  
  1075. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  1076. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  1077. }
  1078.  
  1079. html item-anchor {
  1080.  
  1081. height: 1px;
  1082. width: 1px;
  1083. top: auto;
  1084. left: auto;
  1085. right: auto;
  1086. bottom: auto;
  1087. transform: translateY(-1px);
  1088. position: absolute;
  1089. z-index: -1;
  1090.  
  1091. }
  1092.  
  1093. }
  1094.  
  1095. @supports (color: var(--pre-rendering)) {
  1096.  
  1097. @keyframes dontRenderAnimation {
  1098. 0% {
  1099. background-position-x: 3px;
  1100. }
  1101. 100% {
  1102. background-position-x: 4px;
  1103. }
  1104. }
  1105.  
  1106. .dont-render[class] {
  1107. /* visibility: collapse !important; */
  1108. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://greasyfork.org/scripts/469878/discussions/197267 */
  1109.  
  1110. transform: scale(0.01) !important;
  1111. transform: scale(0.00001) !important;
  1112. transform: scale(0.0000001) !important;
  1113. transform-origin: 0 0 !important;
  1114. z-index: -1 !important;
  1115. contain: strict !important;
  1116. box-sizing: border-box !important;
  1117.  
  1118. height: 1px !important;
  1119. height: 0.1px !important;
  1120. height: 0.01px !important;
  1121. height: 0.0001px !important;
  1122. height: 0.000001px !important;
  1123.  
  1124. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  1125.  
  1126. pointer-events: none !important;
  1127. user-select: none !important;
  1128.  
  1129. }
  1130.  
  1131. #sk35z {
  1132. display: block !important;
  1133.  
  1134. visibility: collapse !important;
  1135.  
  1136. transform: scale(0.01) !important;
  1137. transform: scale(0.00001) !important;
  1138. transform: scale(0.0000001) !important;
  1139. transform-origin: 0 0 !important;
  1140. z-index: -1 !important;
  1141. contain: strict !important;
  1142. box-sizing: border-box !important;
  1143.  
  1144. height: 1px !important;
  1145. height: 0.1px !important;
  1146. height: 0.01px !important;
  1147. height: 0.0001px !important;
  1148. height: 0.000001px !important;
  1149.  
  1150. position: absolute !important;
  1151. top: -1000px !important;
  1152. left: -1000px !important;
  1153.  
  1154. }
  1155.  
  1156. }
  1157.  
  1158. [rNgzQ] {
  1159. opacity: 0 !important;
  1160. pointer-events: none !important;
  1161. }
  1162.  
  1163.  
  1164. ${cssText10_show_more_blinker}
  1165.  
  1166. ${cssText11_entire_message_clickable}
  1167.  
  1168. ${cssText12_nowrap_tooltip}
  1169.  
  1170. ${cssText13_no_text_select_when_menu_visible}
  1171.  
  1172. ${cssText14_NO_FILTER_DROPDOWN_BORDER}
  1173.  
  1174. ${cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION}
  1175.  
  1176. ${cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION}
  1177.  
  1178. ${cssText17_FIX_overwidth_banner_message}
  1179.  
  1180. ${cssText18_REACTION_ANIMATION_PANEL_CSS_FIX}
  1181.  
  1182. ${cssText19_FOR_ADVANCED_TICKING}
  1183.  
  1184. `;
  1185.  
  1186.  
  1187. const konsole = {
  1188. nil: Symbol(),
  1189. logs: [],
  1190. style: '',
  1191. log(...args) {
  1192. konsole.logs.push({
  1193. type: 'log',
  1194. msg: [konsole.tag || konsole.nil, ...args, konsole.style || konsole.nil].filter(e => e !== konsole.nil)
  1195. });
  1196. },
  1197. setTag(tag) {
  1198. konsole.tag = tag;
  1199. },
  1200. setStyle(style) {
  1201. konsole.style = style;
  1202. },
  1203. groupCollapsed(...args) {
  1204.  
  1205. konsole.logs.push({
  1206. type: 'groupCollapsed',
  1207. msg: [...args].filter(e => e !== konsole.nil)
  1208. });
  1209. },
  1210. groupEnd() {
  1211.  
  1212. konsole.logs.push({
  1213. type: 'groupEnd'
  1214. })
  1215. },
  1216. print() {
  1217. const copy = konsole.logs.slice(0);
  1218. konsole.logs.length = 0;
  1219. for (const { type, msg } of copy) {
  1220. if (type === 'log') {
  1221. console.log(...msg)
  1222. } else if (type === 'groupCollapsed') {
  1223.  
  1224. console.groupCollapsed(...msg)
  1225. } else if (type === 'groupEnd') {
  1226. console.groupEnd();
  1227. }
  1228.  
  1229. }
  1230.  
  1231. }
  1232. };
  1233.  
  1234. /*
  1235. konsole.groupCollapsedX = (text1, text2) => {
  1236.  
  1237. if(!text2){
  1238.  
  1239. konsole.groupCollapsed(`%c${text1}`,
  1240. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;"
  1241. );
  1242. }else{
  1243.  
  1244. konsole.groupCollapsed(`%c${text1}%c${text2}`,
  1245. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1246. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1247. );
  1248. }
  1249. }
  1250.  
  1251. konsole.groupCollapsedX('YouTube Super Fast Chat');
  1252.  
  1253. setTimeout(()=>{
  1254.  
  1255. konsole.setTag('[[Fonts Pre-Rendering]]');
  1256. konsole.log(123);
  1257. konsole.log('wsd',332, 'ssa');
  1258. konsole.setTag('');
  1259. }, 100);
  1260.  
  1261. setTimeout(()=>{
  1262.  
  1263. konsole.setTag('[[Fonts Pre-Rendering 2]]');
  1264. konsole.log(123);
  1265. konsole.log('wsd',332, 'ssa');
  1266. konsole.setTag('');
  1267. }, 300);
  1268.  
  1269. setTimeout(()=>{
  1270.  
  1271. konsole.groupEnd();
  1272. konsole.print();
  1273. }, 1000);
  1274.  
  1275. */
  1276.  
  1277. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  1278.  
  1279. // Create a unique key for the script and check if it is already running
  1280. const hkey_script = 'mchbwnoasqph';
  1281. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  1282. win[hkey_script] = true;
  1283.  
  1284. let unexpectedErr = "";
  1285.  
  1286. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  1287.  
  1288. let te4 = setTimeout(() => { }); // dummy; skip timerId only;
  1289. if (te4 < 3) {
  1290. setTimeout(() => { });
  1291. setTimeout(() => { });
  1292. }
  1293.  
  1294. }
  1295.  
  1296. const firstKey = (obj) => {
  1297. for (const key in obj) {
  1298. if (obj.hasOwnProperty(key)) return key;
  1299. }
  1300. return null;
  1301. }
  1302.  
  1303. const firstObjectKey = (obj) => {
  1304. for (const key in obj) {
  1305. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1306. }
  1307. return null;
  1308. }
  1309.  
  1310. /**
  1311. * Takes in a __SORTED__ array and inserts the provided value into
  1312. * the correct, sorted, position.
  1313. * > https://github.com/bhowell2/binary-insert-js/
  1314. * @param array the sorted array where the provided value needs to be inserted (in order)
  1315. * @param insertValue value to be added to the array
  1316. * @param comparator function that helps determine where to insert the value (
  1317. */
  1318. function binaryInsert(array, insertValue, comparator) {
  1319. let left = 0;
  1320. let right = array.length;
  1321.  
  1322. let z;
  1323. // Directly return if array is empty or the insertValue should be at the end
  1324. if (right === 0 || (z = comparator(array[right - 1], insertValue)) <= 0) {
  1325. array.push(insertValue);
  1326. return array;
  1327. }
  1328.  
  1329. // Check if the insertValue should be at the beginning
  1330. if ((right === 1 ? z : comparator(array[0], insertValue)) >= 0) {
  1331. array.unshift(insertValue);
  1332. return array;
  1333. }
  1334. ++left; --right;
  1335.  
  1336. // Main binary search loop to find the insertion position
  1337. while (left < right) {
  1338. const mid = Math.floor((right + left) / 2);
  1339. const compared = comparator(array[mid], insertValue);
  1340. if (compared < 0) {
  1341. left = mid + 1;
  1342. } else if (compared > 0) {
  1343. right = mid;
  1344. } else {
  1345. // If equal, insert at the mid position
  1346. left = right = mid;
  1347. break;
  1348. }
  1349. }
  1350.  
  1351. // Insertion is always at the right position due to the nature of the binary search
  1352. array.splice(right, 0, insertValue);
  1353. return array;
  1354. }
  1355.  
  1356.  
  1357.  
  1358.  
  1359. class LimitedSizeSet extends Set {
  1360. constructor(n) {
  1361. super();
  1362. this.limit = n;
  1363. }
  1364.  
  1365. add(key) {
  1366. if (!super.has(key)) {
  1367. super.add(key);
  1368. let n = super.size - this.limit;
  1369. if (n > 0) {
  1370. const iterator = super.values();
  1371. do {
  1372. const firstKey = iterator.next().value; // Get the first (oldest) key
  1373. super.delete(firstKey); // Delete the oldest key
  1374. } while (--n > 0)
  1375. }
  1376. }
  1377. }
  1378.  
  1379. removeAdd(key) {
  1380. super.delete(key);
  1381. this.add(key);
  1382. }
  1383.  
  1384. }
  1385.  
  1386.  
  1387. class LimitedSizeMap extends Map {
  1388. constructor(n) {
  1389. super();
  1390. this.limit = n;
  1391. }
  1392.  
  1393. set(key, val) {
  1394. if (!super.has(key)) {
  1395. super.set(key, val);
  1396. let n = super.size - this.limit;
  1397. if (n > 0) {
  1398. const iterator = super.keys();
  1399. do {
  1400. const firstKey = iterator.next().value; // Get the first (oldest) key
  1401. super.delete(firstKey); // Delete the oldest key
  1402. } while (--n > 0)
  1403. }
  1404. }
  1405. }
  1406.  
  1407. removeSet(key, val) {
  1408. super.delete(key);
  1409. this.set(key, val);
  1410. }
  1411.  
  1412. }
  1413.  
  1414. // function removeElementFromArray(arr, index) {
  1415. // if (index >= 0 && index < arr.length) {
  1416. // arr.splice(index, 1);
  1417. // }
  1418. // }
  1419.  
  1420. // function getRandomInt(a, b) {
  1421. // // Ensure that 'a' and 'b' are integers
  1422. // a = Math.ceil(a);
  1423. // b = Math.floor(b);
  1424.  
  1425. // // Generate a random integer in the range [a, b]
  1426. // return Math.floor(Math.random() * (b - a + 1)) + a;
  1427. // }
  1428.  
  1429. function deepCopy(obj, skipKeys) {
  1430. skipKeys = skipKeys || [];
  1431. if (!obj || typeof obj !== 'object') return obj;
  1432. if (Array.isArray(obj)) {
  1433. return obj.map(item => deepCopy(item, skipKeys));
  1434. }
  1435. const copy = {};
  1436. for (let key in obj) {
  1437. if (!skipKeys.includes(key)) {
  1438. copy[key] = deepCopy(obj[key], skipKeys);
  1439. }
  1440. }
  1441. return copy;
  1442. }
  1443.  
  1444. class Mutex {
  1445.  
  1446. constructor() {
  1447. this.p = Promise.resolve()
  1448. }
  1449.  
  1450. /**
  1451. * @param {(lockResolve: () => void)} f
  1452. */
  1453. lockWith(f) {
  1454. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  1455. }
  1456.  
  1457. }
  1458.  
  1459. const PromiseExternal = ((resolve_, reject_) => {
  1460. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  1461. return class PromiseExternal extends Promise {
  1462. constructor(cb = h) {
  1463. super(cb);
  1464. if (cb === h) {
  1465. /** @type {(value: any) => void} */
  1466. this.resolve = resolve_;
  1467. /** @type {(reason?: any) => void} */
  1468. this.reject = reject_;
  1469. }
  1470. }
  1471. };
  1472. })();
  1473.  
  1474.  
  1475. const createPipeline = () => {
  1476. let pipelineMutex = Promise.resolve();
  1477. const pipelineExecution = fn => {
  1478. return new Promise((resolve, reject) => {
  1479. pipelineMutex = pipelineMutex.then(async () => {
  1480. let res;
  1481. try {
  1482. res = await fn();
  1483. } catch (e) {
  1484. console.log('error_F1', e);
  1485. reject(e);
  1486. }
  1487. resolve(res);
  1488. }).catch(console.warn);
  1489. });
  1490. };
  1491. return pipelineExecution;
  1492. };
  1493.  
  1494. const tickerPE = createPipeline();
  1495.  
  1496. /** @type {typeof PromiseExternal.prototype | null} */
  1497. let relayPromise = null;
  1498.  
  1499.  
  1500. /** @type {typeof PromiseExternal.prototype | null} */
  1501. let onPlayStateChangePromise = null;
  1502.  
  1503.  
  1504.  
  1505.  
  1506. const valAssign = (elm, attr, val) => {
  1507. if (typeof val === 'number') val = val.toFixed(3);
  1508. if (!(Math.abs(elm.style.getPropertyValue(attr) - val) < 1e-5)) {
  1509. elm.style.setProperty(attr, val);
  1510. return true;
  1511. }
  1512. return false;
  1513. };
  1514.  
  1515. let playEventsStack = Promise.resolve();
  1516.  
  1517.  
  1518. let playerProgressChangedArg1 = null;
  1519. let playerProgressChangedArg2 = null;
  1520. let playerProgressChangedArg3 = null;
  1521.  
  1522. let dntElementWeak = null;
  1523.  
  1524.  
  1525. let timestampUnderLiveMode = false;
  1526.  
  1527. const updateTickerCurrentTime = () => {
  1528.  
  1529. if(resistanceUpdateDebugMode){
  1530. console.log('updateTickerCurrentTime')
  1531.  
  1532. if(!dntElementWeak || !kRef(dntElementWeak)) dntElementWeak = mWeakRef(document.querySelector('yt-live-chat-ticker-renderer'));
  1533. timestampUnderLiveMode = true;
  1534. }
  1535.  
  1536. const dntElement = kRef(dntElementWeak);
  1537. const v = timestampUnderLiveMode ? (Date.now() / 1000 - timeOriginDT / 1000) : playerProgressChangedArg1;
  1538. if (dntElement instanceof HTMLElement && v >= 0) {
  1539. valAssign(dntElement, '--ticker-current-time', v);
  1540. }
  1541. }
  1542.  
  1543. // ================== FOR USE_ADVANCED_TICKING ================
  1544.  
  1545. const timeOriginDT = +new Date(performance.timeOrigin);
  1546. let startResistanceUpdaterStarted = false;
  1547.  
  1548. const RESISTANCE_UPDATE_OPT = 3;
  1549. let resistanceUpdateLast = 0;
  1550. let resistanceUpdateBusy = false;
  1551. let resistanceUpdateRetry = false;
  1552. const resistanceUpdateDebugMode = false;
  1553. const allBackgroundOverLays = document.getElementsByTagName('ticker-bg-overlay');
  1554. const rgFlag = {};
  1555. const resistanceUpdateFn = (b) => {
  1556. if(b !== rgFlag && resistanceUpdateRetry === false) return;
  1557. if (!resistanceUpdateDebugMode && allBackgroundOverLays.length === 0) return;
  1558. resistanceUpdateBusy = false;
  1559. const t = Date.now();
  1560. const d = t - resistanceUpdateLast;
  1561. if (d > 375) {
  1562. resistanceUpdateLast = t;
  1563. resistanceUpdateRetry = false;
  1564. updateTickerCurrentTime();
  1565. } else if (typeof requestIdleCallback === 'function') {
  1566. resistanceUpdateRetry = true;
  1567. requestIdleCallback(resistanceUpdateFn);
  1568. } else {
  1569. resistanceUpdateRetry = true;
  1570. setTimeout(resistanceUpdateFn, d + 17);
  1571. }
  1572. }
  1573. const resistanceUpdateFn_ = ()=>{
  1574. if (!resistanceUpdateBusy) {
  1575. resistanceUpdateBusy = true;
  1576. resistanceUpdateRetry = false;
  1577. Promise.resolve(rgFlag).then(resistanceUpdateFn);
  1578. }
  1579. }
  1580. const startResistanceUpdater = () => {
  1581.  
  1582. if (startResistanceUpdaterStarted) return;
  1583. startResistanceUpdaterStarted = true;
  1584.  
  1585.  
  1586. if (RESISTANCE_UPDATE_OPT & 1)
  1587. document.addEventListener('yt-action', () => {
  1588. resistanceUpdateFn_();
  1589. }, true)
  1590.  
  1591. if (RESISTANCE_UPDATE_OPT & 2)
  1592. new MutationObserver(() => {
  1593. resistanceUpdateFn_();
  1594. }).observe(document, {
  1595. subtree: true, childList: true, attributes: true
  1596. });
  1597. resistanceUpdateFn_();
  1598. }
  1599.  
  1600. if(resistanceUpdateDebugMode) startResistanceUpdater();
  1601.  
  1602.  
  1603. function dr(s) {
  1604. // reserved for future use
  1605. return s;
  1606. // return window.deWeakJS ? window.deWeakJS(s) : s;
  1607. }
  1608.  
  1609. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1610. const indr = o => insp(o).$ || o.$ || 0;
  1611.  
  1612. const getProto = (element) => {
  1613. if (element) {
  1614. const cnt = insp(element);
  1615. return cnt.constructor.prototype || null;
  1616. }
  1617. return null;
  1618. }
  1619.  
  1620. const assertor = (f) => f() || console.assert(false, f + "");
  1621.  
  1622. const fnIntegrity = (f, d) => {
  1623.  
  1624.  
  1625. if (!f || typeof f !== 'function') {
  1626. console.warn('f is not a function', f);
  1627. return;
  1628. }
  1629. // return; // M44
  1630. let p = `${f}`, s = 0, j = -1, w = 0;
  1631. // return; // M44
  1632. for (let i = 0, l = p.length; i < l; i++) {
  1633. const t = p[i];
  1634. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1635. if (j < i - 1) w++;
  1636. j = i;
  1637. } else {
  1638. s++;
  1639. }
  1640. }
  1641. // if(p.length > 44 && p.length < 50){
  1642.  
  1643. // (window.skam|| (window.skam=[])).push(p);
  1644. // return false;
  1645. // }
  1646.  
  1647. // if(p.length > 405 && p.length < 415 ){ //350 450
  1648.  
  1649.  
  1650. // //  [353, 411, 411, 411]
  1651.  
  1652. // // if(p.length >= 350 && p.length<=450){
  1653.  
  1654. // // (window.skam|| (window.skam=[])).push(p.length);
  1655. // // }
  1656. // (window.skam|| (window.skam=[])).push(p);
  1657. // return false;
  1658. // }
  1659.  
  1660. // if(p.length < 50) return true; else return false;
  1661. // return; // M44
  1662. let itz = `${f.length}.${s}.${w}`;
  1663. if (!d) {
  1664. return itz;
  1665. } else if (itz !== d) {
  1666. console.warn('fnIntegrity=false', itz);
  1667. return false;
  1668. } else {
  1669. return true;
  1670. }
  1671. }
  1672.  
  1673.  
  1674. const px2cm = (px) => px * window.devicePixelRatio * 0.026458333;
  1675. const px2mm = (px) => px * window.devicePixelRatio * 0.26458333;
  1676.  
  1677.  
  1678. ; (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS || DISABLE_FLAGS_SHADYDOM_FREE) && (() => {
  1679.  
  1680. const _config_ = () => {
  1681. try {
  1682. return ytcfg.data_;
  1683. } catch (e) { }
  1684. return null;
  1685. };
  1686.  
  1687. const flagsFn = (EXPERIMENT_FLAGS) => {
  1688.  
  1689. // console.log(700)
  1690.  
  1691. if (!EXPERIMENT_FLAGS) return;
  1692.  
  1693. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1694. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1695. // EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true; // timestamp toggle issue
  1696. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1697. // console.log(701)
  1698. }
  1699. }
  1700.  
  1701. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1702. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1703. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1704. // console.log(702);
  1705. }
  1706.  
  1707. if (DISABLE_FLAGS_SHADYDOM_FREE) {
  1708. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_node_methods = false;
  1709. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_query_methods = false;
  1710. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_readonly_properties_batch_one = false;
  1711. EXPERIMENT_FLAGS.enable_shadydom_free_parent_node = false;
  1712. EXPERIMENT_FLAGS.enable_shadydom_free_children = false;
  1713. EXPERIMENT_FLAGS.enable_shadydom_free_last_child = false;
  1714. }
  1715.  
  1716. // EXPERIMENT_FLAGS.enable_button_behavior_reuse = false;
  1717.  
  1718. };
  1719.  
  1720. const uf = (config_) => {
  1721. config_ = config_ || _config_();
  1722. if (config_) {
  1723. const { EXPERIMENT_FLAGS, EXPERIMENTS_FORCED_FLAGS } = config_;
  1724. if (EXPERIMENT_FLAGS) {
  1725. flagsFn(EXPERIMENT_FLAGS);
  1726. if (EXPERIMENTS_FORCED_FLAGS) flagsFn(EXPERIMENTS_FORCED_FLAGS);
  1727. }
  1728. }
  1729. }
  1730.  
  1731. window._ytConfigHacks.add((config_) => {
  1732. uf(config_);
  1733. });
  1734.  
  1735. uf();
  1736.  
  1737. })();
  1738.  
  1739. if (DISABLE_Translation_By_Google) {
  1740.  
  1741. let mo = new MutationObserver(() => {
  1742.  
  1743. if (!mo) return;
  1744. let h = document.head;
  1745. if (!h) return;
  1746. mo.disconnect();
  1747. mo.takeRecords();
  1748. mo = null;
  1749.  
  1750. let meta = document.createElement('meta');
  1751. meta.setAttribute('name', 'google');
  1752. meta.setAttribute('content', 'notranslate');
  1753. h.appendChild(meta);
  1754.  
  1755.  
  1756. });
  1757. mo.observe(document, { subtree: true, childList: true });
  1758. }
  1759.  
  1760.  
  1761. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  1762.  
  1763. const isContainSupport = CSS.supports('contain', 'layout paint style');
  1764. if (!isContainSupport) {
  1765. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  1766. }
  1767.  
  1768. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  1769. if (!isOverflowAnchorSupport) {
  1770. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  1771. }
  1772.  
  1773. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && isOverflowAnchorSupport && ENABLE_NO_SMOOTH_TRANSFORM;
  1774.  
  1775. let hasTimerModified = null;
  1776. const DO_CHECK_TICKER_BACKGROUND_OVERRIDED = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND || ENABLE_RAF_HACK_TICKERS;
  1777.  
  1778. const fxOperator = (proto, propertyName) => {
  1779. let propertyDescriptorGetter = null;
  1780. try {
  1781. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  1782. } catch (e) { }
  1783. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  1784. try {
  1785.  
  1786. return propertyDescriptorGetter.call(dr(e));
  1787. } catch (e) { }
  1788. return e[propertyName];
  1789. } : (e) => e[propertyName];
  1790. };
  1791.  
  1792. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  1793. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  1794. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  1795. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  1796. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  1797.  
  1798. const groupCollapsed = (text1, text2) => {
  1799.  
  1800. console.groupCollapsed(`%c${text1}%c${text2}`,
  1801. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1802. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1803. );
  1804. }
  1805.  
  1806. // const microNow = () => performance.now() + (performance.timeOrigin || performance.timing.navigationStart);
  1807.  
  1808.  
  1809. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1810. const onRegistryReady = (callback) => {
  1811. if (typeof customElements === 'undefined') {
  1812. if (!('__CE_registry' in document)) {
  1813. // https://github.com/webcomponents/polyfills/
  1814. Object.defineProperty(document, '__CE_registry', {
  1815. get() {
  1816. // return undefined
  1817. },
  1818. set(nv) {
  1819. if (typeof nv == 'object') {
  1820. delete this.__CE_registry;
  1821. this.__CE_registry = nv;
  1822. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1823. }
  1824. return true;
  1825. },
  1826. enumerable: false,
  1827. configurable: true
  1828. })
  1829. }
  1830. let eventHandler = (evt) => {
  1831. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1832. const f = callback;
  1833. callback = null;
  1834. eventHandler = null;
  1835. f();
  1836. };
  1837. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1838. } else {
  1839. callback();
  1840. }
  1841. };
  1842.  
  1843. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  1844.  
  1845. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  1846.  
  1847. return new Promise(resolve => {
  1848.  
  1849. let ro = new ResizeObserver(entries => {
  1850. if (entries && entries.length >= 1) {
  1851. resolve();
  1852. ro.disconnect();
  1853. ro = null;
  1854. }
  1855. });
  1856. ro.observe(sizingTarget);
  1857.  
  1858.  
  1859.  
  1860. });
  1861.  
  1862. } : (sizingTarget) => {
  1863.  
  1864.  
  1865. return new Promise(resolve => {
  1866.  
  1867. let io = new IntersectionObserver(entries => {
  1868. if (entries && entries.length >= 1) {
  1869. resolve();
  1870. io.disconnect();
  1871. io = null;
  1872. }
  1873. });
  1874. io.observe(sizingTarget);
  1875.  
  1876.  
  1877.  
  1878. });
  1879.  
  1880. };
  1881.  
  1882. /* globals WeakRef:false */
  1883.  
  1884. /** @type {(o: Object | null) => WeakRef | null} */
  1885. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1886.  
  1887. /** @type {(wr: Object | null) => Object | null} */
  1888. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1889.  
  1890. const getLCRDummy = () => {
  1891. // direct createElement or createComponent_ will make the emoji rendering crashed. reason TBC
  1892.  
  1893. return Promise.all([customElements.whenDefined('yt-live-chat-app'), customElements.whenDefined('yt-live-chat-renderer')]).then(async () => {
  1894.  
  1895. const tag = "yt-live-chat-renderer"
  1896. let dummy = document.querySelector(tag);
  1897. if (!dummy) {
  1898.  
  1899. let mo = null;
  1900.  
  1901. const ytLiveChatApp = document.querySelector('yt-live-chat-app') || document.createElement('yt-live-chat-app');
  1902.  
  1903. const lcaProto = getProto(ytLiveChatApp);
  1904.  
  1905. dummy = await new Promise(resolve => {
  1906.  
  1907. if (typeof lcaProto.createComponent_ === 'function' && !lcaProto.createComponent99_) {
  1908.  
  1909. lcaProto.createComponent99_ = lcaProto.createComponent_;
  1910. lcaProto.createComponent98_ = function (a, b, c) {
  1911. // (3) ['yt-live-chat-renderer', {…}, true]
  1912. const r = this.createComponent99_.apply(this, arguments);
  1913. if (a === 'yt-live-chat-renderer') {
  1914. resolve(r);
  1915. }
  1916. return r;
  1917. };
  1918. lcaProto.createComponent_ = lcaProto.createComponent98_;
  1919.  
  1920. } else {
  1921.  
  1922. mo = new MutationObserver(() => {
  1923. const t = document.querySelector(tag);
  1924. if (t) {
  1925. resolve(t);
  1926. }
  1927. });
  1928. mo.observe(document, { subtree: true, childList: true })
  1929. }
  1930.  
  1931. });
  1932.  
  1933. if (mo) {
  1934. mo.disconnect();
  1935. mo.takeRecords();
  1936. mo = null;
  1937. }
  1938.  
  1939. if (lcaProto.createComponent99_ && lcaProto.createComponent_ && lcaProto.createComponent98_ === lcaProto.createComponent_) {
  1940. lcaProto.createComponent_ = lcaProto.createComponent99_;
  1941. lcaProto.createComponent99_ = null;
  1942. lcaProto.createComponent98_ = null;
  1943. }
  1944.  
  1945. }
  1946. return dummy;
  1947.  
  1948. });
  1949. }
  1950.  
  1951. const { addCssManaged } = (() => {
  1952.  
  1953. const addFontPreRendering = () => {
  1954.  
  1955. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  1956.  
  1957. let efsContainer = document.createElement('elzm-fonts');
  1958. efsContainer.id = 'elzm-fonts-yk75g'
  1959.  
  1960. const arr = [];
  1961. let p = document.createElement('elzm-font');
  1962. arr.push(p);
  1963.  
  1964. if (ENABLE_FONT_PRE_RENDERING & 1) {
  1965. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1966.  
  1967. p = document.createElement('elzm-font');
  1968. p.style.fontWeight = size;
  1969. arr.push(p);
  1970. }
  1971. }
  1972.  
  1973. if (ENABLE_FONT_PRE_RENDERING & 2) {
  1974. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1975.  
  1976. p = document.createElement('elzm-font');
  1977. p.style.fontFamily = 'Roboto';
  1978. p.style.fontWeight = size;
  1979. arr.push(p);
  1980. }
  1981. }
  1982.  
  1983. if (ENABLE_FONT_PRE_RENDERING & 4) {
  1984. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1985.  
  1986. p = document.createElement('elzm-font');
  1987. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  1988. p.style.fontWeight = size;
  1989. arr.push(p);
  1990. }
  1991. }
  1992.  
  1993.  
  1994. if (ENABLE_FONT_PRE_RENDERING & 8) {
  1995. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1996.  
  1997. p = document.createElement('elzm-font');
  1998. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  1999. p.style.fontWeight = size;
  2000. arr.push(p);
  2001. }
  2002. }
  2003.  
  2004.  
  2005. if (ENABLE_FONT_PRE_RENDERING & 16) {
  2006. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2007.  
  2008. p = document.createElement('elzm-font');
  2009. p.style.fontFamily = 'sans-serif';
  2010. p.style.fontWeight = size;
  2011. arr.push(p);
  2012. }
  2013. }
  2014.  
  2015. console.log('number of elzm-font elements', arr.length);
  2016.  
  2017. HTMLElement.prototype.append.apply(efsContainer, arr);
  2018.  
  2019. (document.body || document.documentElement).appendChild(efsContainer);
  2020.  
  2021.  
  2022. console.log('elzm-font elements have been added to the page for rendering.');
  2023.  
  2024. console.groupEnd();
  2025.  
  2026. }
  2027.  
  2028. let isCssAdded = false;
  2029.  
  2030. function addCssElement() {
  2031. let s = document.createElement('style');
  2032. s.id = 'ewRvC';
  2033. return s;
  2034. }
  2035.  
  2036. const addCssManaged = () => {
  2037. if (!isCssAdded && document.documentElement && document.head) {
  2038. isCssAdded = true;
  2039. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  2040. if (ENABLE_FONT_PRE_RENDERING) {
  2041. Promise.resolve().then(addFontPreRendering)
  2042. }
  2043. }
  2044. }
  2045.  
  2046. return { addCssManaged };
  2047. })();
  2048.  
  2049.  
  2050. const { setupStyle } = (() => {
  2051.  
  2052. const sp7 = Symbol();
  2053.  
  2054. const proxyHelperFn = (dummy) => ({
  2055.  
  2056. get(target, prop) {
  2057. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  2058. },
  2059. set(target, prop, value) {
  2060. if (!(prop in dummy)) {
  2061. target[prop] = value;
  2062. }
  2063. return true;
  2064. },
  2065. has(target, prop) {
  2066. return (prop in target);
  2067. },
  2068. deleteProperty(target, prop) {
  2069. return true;
  2070. },
  2071. ownKeys(target) {
  2072. return Object.keys(target);
  2073. },
  2074. defineProperty(target, key, descriptor) {
  2075. return Object.defineProperty(target, key, descriptor);
  2076. },
  2077. getOwnPropertyDescriptor(target, key) {
  2078. return Object.getOwnPropertyDescriptor(target, key);
  2079. },
  2080.  
  2081. });
  2082.  
  2083. const setupStyle = (m1, m2) => {
  2084. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  2085.  
  2086. const dummy1v = {
  2087. transform: '',
  2088. height: '',
  2089. minHeight: '',
  2090. paddingBottom: '',
  2091. paddingTop: ''
  2092. };
  2093.  
  2094. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  2095. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  2096. dummy1v[k] = dummyStyleFn(k);
  2097. }
  2098.  
  2099. const dummy1p = proxyHelperFn(dummy1v);
  2100. const sp1v = new Proxy(m1.style, dummy1p);
  2101. const sp2v = new Proxy(m2.style, dummy1p);
  2102. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  2103. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  2104. m1.removeAttribute("style");
  2105. m2.removeAttribute("style");
  2106.  
  2107. }
  2108.  
  2109. return { setupStyle };
  2110.  
  2111. })();
  2112.  
  2113.  
  2114.  
  2115. function setThumbnails(config) {
  2116.  
  2117. const { baseObject, thumbnails, flag0, imageLinks } = config;
  2118.  
  2119. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  2120.  
  2121.  
  2122. if (thumbnails && thumbnails.length > 0) {
  2123. if (flag0 > 0 && thumbnails.length > 1) {
  2124. let pSize = 0;
  2125. let newThumbnails = [];
  2126. for (const thumbnail of thumbnails) {
  2127. if (!thumbnail || !thumbnail.url) continue;
  2128. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  2129. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  2130. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  2131. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  2132. newThumbnails.push(thumbnail);
  2133. if (imageLinks) imageLinks.add(thumbnail.url);
  2134. }
  2135. if (squarePhoto && condSize && leastSizeFulfilled) {
  2136. pSize = thumbnail.width;
  2137. }
  2138. }
  2139. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  2140. baseObject.thumbnails = newThumbnails;
  2141. } else {
  2142. newThumbnails.length = 0;
  2143. }
  2144. newThumbnails = null;
  2145. } else {
  2146. for (const thumbnail of thumbnails) {
  2147. if (thumbnail && thumbnail.url) {
  2148. if (imageLinks) imageLinks.add(thumbnail.url);
  2149. }
  2150. }
  2151. }
  2152. }
  2153.  
  2154. }
  2155. }
  2156.  
  2157. function fixLiveChatItem(item, imageLinks) {
  2158. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  2159. if (liveChatTextMessageRenderer) {
  2160. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  2161. if (messageRuns && messageRuns.length > 0) {
  2162. for (const run of messageRuns) {
  2163. const emojiImage = (((run || 0).emoji || 0).image || 0);
  2164. setThumbnails({
  2165. baseObject: emojiImage,
  2166. thumbnails: emojiImage.thumbnails,
  2167. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  2168. imageLinks
  2169. });
  2170. }
  2171. }
  2172. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  2173. setThumbnails({
  2174. baseObject: authorPhoto,
  2175. thumbnails: authorPhoto.thumbnails,
  2176. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  2177. imageLinks
  2178. });
  2179. }
  2180. }
  2181.  
  2182.  
  2183.  
  2184. let kptPF = null;
  2185. const emojiPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_EMOJI);
  2186. const authorPhotoPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO);
  2187.  
  2188. function linker(link, rel, href, _as) {
  2189. return new Promise(resolve => {
  2190. if (!link) link = document.createElement('link');
  2191. link.rel = rel;
  2192. if (_as) link.setAttribute('as', _as);
  2193. link.onload = function () {
  2194. resolve({
  2195. link: this,
  2196. success: true
  2197. })
  2198. this.remove();
  2199. };
  2200. link.onerror = function () {
  2201. resolve({
  2202. link: this,
  2203. success: false
  2204. });
  2205. this.remove();
  2206. };
  2207. link.href = href;
  2208. document.head.appendChild(link);
  2209. link = null;
  2210. });
  2211. }
  2212.  
  2213.  
  2214.  
  2215. const cleanContext = async (win) => {
  2216. const waitFn = requestAnimationFrame; // shall have been binded to window
  2217. try {
  2218. let mx = 16; // MAX TRIAL
  2219. const frameId = 'vanillajs-iframe-v1';
  2220. /** @type {HTMLIFrameElement | null} */
  2221. let frame = document.getElementById(frameId);
  2222. let removeIframeFn = null;
  2223. if (!frame) {
  2224. frame = document.createElement('iframe');
  2225. frame.id = frameId;
  2226. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2227. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2228. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2229. n.appendChild(frame);
  2230. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2231. const root = document.documentElement;
  2232. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2233. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2234.  
  2235. removeIframeFn = (setTimeout) => {
  2236. const removeIframeOnDocumentReady = (e) => {
  2237. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2238. e = n;
  2239. n = win = removeIframeFn = 0;
  2240. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2241. }
  2242. if (!setTimeout || document.readyState !== 'loading') {
  2243. removeIframeOnDocumentReady();
  2244. } else {
  2245. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2246. }
  2247. }
  2248. }
  2249. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2250. const fc = frame.contentWindow;
  2251. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2252. try {
  2253. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle } = fc;
  2254. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle };
  2255. for (let k in res) res[k] = res[k].bind(win); // necessary
  2256. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2257.  
  2258. /** @type {HTMLElement} */
  2259. const HTMLElementProto = fc.HTMLElement.prototype;
  2260. /** @type {EventTarget} */
  2261. const EventTargetProto = fc.EventTarget.prototype;
  2262. // jsonParseFix = {
  2263. // _JSON: fc.JSON, _parse: fc.JSON.parse
  2264. // }
  2265. return {
  2266. ...res,
  2267. animate: HTMLElementProto.animate,
  2268. addEventListener: EventTargetProto.addEventListener,
  2269. removeEventListener: EventTargetProto.removeEventListener
  2270. };
  2271. } catch (e) {
  2272. if (removeIframeFn) removeIframeFn();
  2273. return null;
  2274. }
  2275. } catch (e) {
  2276. console.warn(e);
  2277. return null;
  2278. }
  2279. };
  2280.  
  2281.  
  2282. let xoIcjPr = null;
  2283. window.addEventListener('message', (evt) => {
  2284. if ((evt || 0).data === 'xoIcj' && xoIcjPr !== null) xoIcjPr.resolve();
  2285. });
  2286. const timelineResolve = async () => {
  2287. if (xoIcjPr !== null) {
  2288. await xoIcjPr.then();
  2289. return;
  2290. }
  2291. xoIcjPr = new PromiseExternal();
  2292. window.postMessage('xoIcj');
  2293. await xoIcjPr.then();
  2294. xoIcjPr = null;
  2295. }
  2296.  
  2297. cleanContext(win).then(__CONTEXT__ => {
  2298. if (!__CONTEXT__) return null;
  2299.  
  2300. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, getComputedStyle, addEventListener, removeEventListener } = __CONTEXT__;
  2301.  
  2302. const wmComputedStyle = new WeakMap();
  2303. const getComputedStyleCached = (elem) => {
  2304. let cs = wmComputedStyle.get(elem);
  2305. if (!cs) {
  2306. cs = getComputedStyle(elem);
  2307. wmComputedStyle.set(elem, cs);
  2308. }
  2309. return cs;
  2310. }
  2311.  
  2312.  
  2313. const isGPUAccelerationAvailable = (() => {
  2314. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  2315. try {
  2316. const canvas = document.createElement('canvas');
  2317. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  2318. } catch (e) {
  2319. return false;
  2320. }
  2321. })();
  2322.  
  2323. const foregroundPromiseFn_noGPU = (() => {
  2324.  
  2325. if (isGPUAccelerationAvailable) return null;
  2326.  
  2327. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  2328. if (!pd || typeof pd.get !== 'function') return null;
  2329. const pdGet = pd.get;
  2330.  
  2331. let pr = null;
  2332.  
  2333. let hState = pdGet.call(document) === 'hidden';
  2334. // let cid = 0;
  2335. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  2336. const newHState = pdGet.call(document) === 'hidden';
  2337. if (hState !== newHState) {
  2338. // if (cid > 0) cid = clearInterval(cid);
  2339. hState = newHState;
  2340. if (!hState && pr) pr = pr.resolve();
  2341. }
  2342. });
  2343.  
  2344. // cid = setInterval(() => {
  2345. // const newHState = document.visibilityState === 'hidden';
  2346. // if (hState !== newHState) {
  2347. // hState = newHState;
  2348. // if (!hState && pr) pr = pr.resolve();
  2349. // }
  2350. // }, 100);
  2351.  
  2352.  
  2353. return (() => {
  2354. if (pr) return pr;
  2355. const w = ((!hState && setTimeout(() => {
  2356. if (!hState && pr === w) pr = pr.resolve();
  2357. })), (pr = new PromiseExternal()));
  2358. return w;
  2359. });
  2360.  
  2361. })();
  2362.  
  2363. // window.foregroundPromiseFn_noGPU = foregroundPromiseFn_noGPU;
  2364.  
  2365. let rafPromise = null;
  2366. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2367. requestAnimationFrame(hRes => {
  2368. rafPromise = null;
  2369. resolve(hRes);
  2370. });
  2371. }));
  2372. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  2373.  
  2374. const iAFP = foregroundPromiseFn_noGPU ? foregroundPromiseFn_noGPU : typeof IntersectionObserver === 'undefined' ? getRafPromise : (() => {
  2375.  
  2376. const ioWM = new WeakMap();
  2377. const ek = Symbol();
  2378. /** @type {IntersectionObserverCallback} */
  2379. const ioCb = (entries, observer) => {
  2380. /** @type {PromiseExternal} */
  2381. const pr = observer[ek];
  2382. const resolve = pr.resolve;
  2383. let target;
  2384. if (resolve && (target = ((entries ? entries[0] : 0) || 0).target) instanceof Element) {
  2385. pr.resolve = null;
  2386. observer.unobserve(target);
  2387. resolve();
  2388. }
  2389. };
  2390. /**
  2391. *
  2392. * @param {Element} elm
  2393. * @returns {Promise<void>}
  2394. */
  2395. const iAFP = (elm) => {
  2396. let io = ioWM.get(elm);
  2397. if (!io) {
  2398. io = new IntersectionObserver(ioCb);
  2399. ioWM.set(elm, io); // strong reference
  2400. }
  2401. let pr = io[ek];
  2402. if (!pr) {
  2403. pr = io[ek] = new PromiseExternal();
  2404. io.observe(elm);
  2405. }
  2406. return pr;
  2407. }
  2408.  
  2409. return iAFP;
  2410.  
  2411. })();
  2412.  
  2413. let playerState = null;
  2414. let _playerState = null;
  2415. let lastPlayerProgress = null;
  2416. let relayCount = 0;
  2417. let playerEventsByIframeRelay = false;
  2418. let isPlayProgressTriggered = false;
  2419. let waitForInitialDataCompletion = 0;
  2420.  
  2421.  
  2422.  
  2423. let aeConstructor = null;
  2424.  
  2425. // << __openedChanged82 >>
  2426. let currentMenuPivotWR = null;
  2427.  
  2428. // << if DO_PARTICIPANT_LIST_HACKS >>
  2429. const beforeParticipantsMap = new WeakMap();
  2430. // << end >>
  2431.  
  2432.  
  2433.  
  2434. // << if onRegistryReadyForDOMOperations >>
  2435.  
  2436. let dt0 = Date.now() - 2000;
  2437. const dateNow = () => Date.now() - dt0;
  2438. // let lastScroll = 0;
  2439. // let lastLShow = 0;
  2440. let lastWheel = 0;
  2441. let lastMouseDown = 0;
  2442. let lastMouseUp = 0;
  2443. let currentMouseDown = false;
  2444. let lastTouchDown = 0;
  2445. let lastTouchUp = 0;
  2446. let currentTouchDown = false;
  2447. let lastUserInteraction = 0;
  2448.  
  2449. let scrollChatFn = null;
  2450.  
  2451. let skipDontRender = true; // true first; false by flushActiveItems_
  2452. let allowDontRender = null;
  2453.  
  2454. // ---- #items mutation ----
  2455. let sk35zResolveFn = null;
  2456. let firstList = true;
  2457.  
  2458. // << end >>
  2459.  
  2460. class RAFHub {
  2461. constructor() {
  2462. /** @type {number} */
  2463. this.startAt = 8170;
  2464. /** @type {number} */
  2465. this.counter = 0;
  2466. /** @type {number} */
  2467. this.rid = 0;
  2468. /** @type {Map<number, FrameRequestCallback>} */
  2469. this.funcs = new Map();
  2470. const funcs = this.funcs;
  2471. /** @type {FrameRequestCallback} */
  2472. this.bCallback = this.mCallback.bind(this);
  2473. this.pClear = () => funcs.clear();
  2474. this.keepRAF = false;
  2475. }
  2476. /** @param {DOMHighResTimeStamp} highResTime */
  2477. mCallback(highResTime) {
  2478. this.rid = 0;
  2479. Promise.resolve().then(this.pClear);
  2480. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2481. }
  2482. /** @param {FrameRequestCallback} f */
  2483. request(f) {
  2484. if (this.counter > 1e9) this.counter = 9;
  2485. let cid = this.startAt + (++this.counter);
  2486. this.funcs.set(cid, f);
  2487. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  2488. return cid;
  2489. }
  2490. /** @param {number} cid */
  2491. cancel(cid) {
  2492. cid = +cid;
  2493. if (cid > 0) {
  2494. if (cid <= this.startAt) {
  2495. return cancelAnimationFrame(cid);
  2496. }
  2497. if (this.rid > 0) {
  2498. this.funcs.delete(cid);
  2499. if (this.funcs.size === 0 && !this.keepRAF) {
  2500. cancelAnimationFrame(this.rid);
  2501. this.rid = 0;
  2502. }
  2503. }
  2504. }
  2505. }
  2506. }
  2507.  
  2508. function basePrefetching() {
  2509.  
  2510. new Promise(resolve => {
  2511.  
  2512. if (document.readyState !== 'loading') {
  2513. resolve();
  2514. } else {
  2515. win.addEventListener("DOMContentLoaded", resolve, false);
  2516. }
  2517.  
  2518. }).then(() => {
  2519. const hostL1 = [
  2520. 'https://www.youtube.com', 'https://googlevideo.com',
  2521. 'https://googleapis.com', 'https://accounts.youtube.com',
  2522. 'https://www.gstatic.com', 'https://ggpht.com',
  2523. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  2524. ];
  2525.  
  2526. const hostL2 = [
  2527. 'https://youtube.com',
  2528. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  2529. ];
  2530.  
  2531. let link = null;
  2532.  
  2533. function kn() {
  2534.  
  2535. link = document.createElement('link');
  2536. if (link.relList && link.relList.supports) {
  2537. 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)
  2538. } else {
  2539. kptPF = 0;
  2540. }
  2541.  
  2542. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  2543. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  2544. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  2545. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  2546. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  2547. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  2548. console.groupEnd();
  2549.  
  2550. }
  2551.  
  2552. for (const h of hostL1) {
  2553.  
  2554. if (kptPF === null) kn();
  2555. if (ENABLE_BASE_PREFETCHING) {
  2556. // if (kptPF & 1) {
  2557. // linker(link, 'dns-prefetch', h);
  2558. // link = null;
  2559. // }
  2560. if (kptPF & 2) {
  2561. linker(link, 'preconnect', h);
  2562. link = null;
  2563. }
  2564. }
  2565. }
  2566.  
  2567. for (const h of hostL2) {
  2568. if (kptPF === null) kn();
  2569. if (ENABLE_BASE_PREFETCHING) {
  2570. if (kptPF & 1) {
  2571. linker(link, 'dns-prefetch', h);
  2572. link = null;
  2573. }
  2574. }
  2575. }
  2576.  
  2577. })
  2578.  
  2579.  
  2580. }
  2581.  
  2582. if (DO_LINK_PREFETCH) basePrefetching();
  2583.  
  2584. const { notifyPath7081 } = (() => {
  2585. // DO_PARTICIPANT_LIST_HACKS
  2586.  
  2587. const mutexParticipants = new Mutex();
  2588.  
  2589. let uvid = 0;
  2590. let r95dm = 0;
  2591. let c95dm = -1;
  2592.  
  2593. const foundMap = (base, content) => {
  2594. /*
  2595. let lastSearch = 0;
  2596. let founds = base.map(baseEntry => {
  2597. let search = content.indexOf(baseEntry, lastSearch);
  2598. if (search < 0) return false;
  2599. lastSearch = search + 1;
  2600. return true;
  2601. });
  2602. return founds;
  2603. */
  2604. const contentSet = new Set(content);
  2605. return base.map(baseEntry => contentSet.has(baseEntry));
  2606.  
  2607. }
  2608.  
  2609.  
  2610.  
  2611. let participantsForSpliceWR = null;
  2612.  
  2613. class IndexSpliceEntry {
  2614. /**
  2615. *
  2616. * @param {number} _index
  2617. * @param {number} _addedCount
  2618. * @param {any[]} _removed
  2619. */
  2620. constructor(_index, _addedCount, _removed) {
  2621. this.index = _index;
  2622. this.addedCount = _addedCount;
  2623. this.removed = _removed;
  2624. }
  2625. get __proxy312__() {
  2626. return 1
  2627. }
  2628. get type() {
  2629. return 'splice'
  2630. }
  2631. get object() {
  2632. return kRef(participantsForSpliceWR); // avoid memory leakage
  2633. }
  2634. }
  2635.  
  2636. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  2637.  
  2638. let foundsForAfter = foundMap(idsAfter, idsBefore);
  2639. let foundsForBefore = foundMap(idsBefore, idsAfter);
  2640.  
  2641. const nAfter = foundsForAfter.length;
  2642. const nBefore = foundsForBefore.length;
  2643.  
  2644. const indexSplices = [];
  2645. const contentUpdates = [];
  2646. participantsForSpliceWR = null;
  2647. for (let i = 0, j = 0; i < nBefore || j < nAfter;) {
  2648. if (beforeParticipants[i] === participants[j]) {
  2649. i++; j++;
  2650. } else if (idsBefore[i] === idsAfter[j]) {
  2651. // content changed
  2652. contentUpdates.push({ indexI: i, indexJ: j })
  2653. i++; j++;
  2654. } else {
  2655. let addedCount = 0;
  2656. for (let q = j; q < nAfter; q++) {
  2657. if (foundsForAfter[q] === false) addedCount++;
  2658. else break;
  2659. }
  2660. let removedCount = 0;
  2661. for (let q = i; q < nBefore; q++) {
  2662. if (foundsForBefore[q] === false) removedCount++;
  2663. else break;
  2664. }
  2665. if (!addedCount && !removedCount) {
  2666. throw 'ERROR(0xFF32): spliceIndicesFunc';
  2667. }
  2668. const entry = new IndexSpliceEntry(
  2669. j,
  2670. addedCount,
  2671. removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  2672. );
  2673. indexSplices.push(entry);
  2674. i += removedCount;
  2675. j += addedCount;
  2676. }
  2677. }
  2678. foundsForBefore = null;
  2679. foundsForAfter = null;
  2680. idsBefore = null;
  2681. idsAfter = null;
  2682. beforeParticipants = null;
  2683. participantsForSpliceWR = indexSplices.length > 0 ? mWeakRef(participants) : null;
  2684. participants = null;
  2685. return { indexSplices, contentUpdates };
  2686.  
  2687. }
  2688.  
  2689. /*
  2690.  
  2691. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  2692.  
  2693. VM63631:1 Error
  2694. at customElements.get.notifyPath (<anonymous>:1:122)
  2695. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  2696. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  2697. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  2698. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  2699. at ju (live_chat_polymer.js:1674:217)
  2700. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  2701. at b._flushProperties (live_chat_polymer.js:1597:200)
  2702. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  2703. at a.notifyPath (live_chat_polymer.js:1741:182)
  2704.  
  2705. */
  2706.  
  2707. function convertToIds(participants) {
  2708. return participants.map(participant => {
  2709. if (!participant || typeof participant !== 'object') {
  2710. console.warn('Error(0xFA41): convertToIds', participant);
  2711. return participant; // just in case
  2712. }
  2713. let keys = Object.keys(participant);
  2714. // liveChatTextMessageRenderer
  2715. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  2716. // liveChatPaidMessageRenderer
  2717. /*
  2718.  
  2719. 'yt-live-chat-participant-renderer' utilizes the following:
  2720. authorName.simpleText: string
  2721. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  2722. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  2723. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  2724. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  2725.  
  2726. */
  2727. if (keys.length !== 1) {
  2728. console.warn('Error(0xFA42): convertToIds', participant);
  2729. return participant; // just in case
  2730. }
  2731. let key = keys[0];
  2732. let renderer = (participant[key] || 0);
  2733. let authorName = (renderer.authorName || 0);
  2734. let text = `${authorName.simpleText || authorName.text}`
  2735. let res = participant; // fallback if it is not a vaild entry
  2736. if (typeof text !== 'string') {
  2737. console.warn('Error(0xFA53): convertToIds', participant);
  2738. } else {
  2739. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  2740. if (text.length > 1) res = text;
  2741. }
  2742. return res;
  2743. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  2744. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  2745. });
  2746. }
  2747.  
  2748. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  2749. // just update when content is changed.
  2750. if (p1.authorName !== p2.authorName) return true;
  2751. if (p1.authorPhoto !== p2.authorPhoto) return true;
  2752. if (p1.authorBadges !== p2.authorBadges) return true;
  2753. return false;
  2754. } : (p1, p2) => {
  2755. // keep integrity all the time.
  2756. return p1 !== p2; // always true
  2757. }
  2758.  
  2759. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  2760.  
  2761. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2762. if (path !== "participantsManager.participants") {
  2763. return this.__notifyPath5036__.apply(this, arguments);
  2764. }
  2765. if (c95dm === r95dm) return;
  2766. } else {
  2767. const stack = new Error().stack;
  2768. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  2769. return this.__notifyPath5036__.apply(this, arguments);
  2770. }
  2771. }
  2772.  
  2773. if (uvid > 1e8) uvid = uvid % 100;
  2774. let tid = ++uvid;
  2775.  
  2776.  
  2777. // const cnt = this; // "yt-live-chat-participant-list-renderer"
  2778.  
  2779. const wNode = mWeakRef(this);
  2780.  
  2781. mutexParticipants.lockWith(lockResolve => {
  2782.  
  2783. const cnt = kRef(wNode);
  2784.  
  2785. const participants00 = (((cnt || 0).participantsManager || 0).participants || 0);
  2786.  
  2787. if (tid !== uvid || !cnt || typeof (participants00 || 0).splice !== 'function') {
  2788. lockResolve();
  2789. return;
  2790. }
  2791.  
  2792. let doUpdate = false;
  2793.  
  2794. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2795.  
  2796. if (!participants00.r94dm) {
  2797. participants00.r94dm = 1;
  2798. if (++r95dm > 1e9) r95dm = 9;
  2799. participants00.push = function () {
  2800. if (++r95dm > 1e9) r95dm = 9;
  2801. return Array.prototype.push.apply(this, arguments);
  2802. }
  2803. participants00.pop = function () {
  2804. if (++r95dm > 1e9) r95dm = 9;
  2805. return Array.prototype.pop.apply(this, arguments);
  2806. }
  2807. participants00.shift = function () {
  2808. if (++r95dm > 1e9) r95dm = 9;
  2809. return Array.prototype.shift.apply(this, arguments);
  2810. }
  2811. participants00.unshift = function () {
  2812. if (++r95dm > 1e9) r95dm = 9;
  2813. return Array.prototype.unshift.apply(this, arguments);
  2814. }
  2815. participants00.splice = function () {
  2816. if (++r95dm > 1e9) r95dm = 9;
  2817. return Array.prototype.splice.apply(this, arguments);
  2818. }
  2819. participants00.sort = function () {
  2820. if (++r95dm > 1e9) r95dm = 9;
  2821. return Array.prototype.sort.apply(this, arguments);
  2822. }
  2823. participants00.reverse = function () {
  2824. if (++r95dm > 1e9) r95dm = 9;
  2825. return Array.prototype.reverse.apply(this, arguments);
  2826. }
  2827. }
  2828.  
  2829. if (c95dm !== r95dm) {
  2830. c95dm = r95dm;
  2831. doUpdate = true;
  2832. }
  2833.  
  2834. } else {
  2835. doUpdate = true;
  2836. }
  2837.  
  2838. if (!doUpdate) {
  2839. lockResolve();
  2840. return;
  2841. }
  2842.  
  2843. const participants = participants00.slice(0);
  2844. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  2845. beforeParticipantsMap.set(cnt, participants);
  2846.  
  2847. const resPromise = (async () => {
  2848.  
  2849. if (beforeParticipants.length === 0) {
  2850. // not error
  2851. return 0;
  2852. }
  2853.  
  2854. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  2855.  
  2856. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  2857. if (beforeParticipants.length !== countOfElements) {
  2858. // there is somewrong for the cache. - sometimes happen
  2859. return 0;
  2860. }
  2861.  
  2862. const idsBefore = convertToIds(beforeParticipants);
  2863. const idsAfter = convertToIds(participants);
  2864.  
  2865. let { indexSplices, contentUpdates } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  2866.  
  2867. let res = 1; // default 1 for no update
  2868.  
  2869. if (indexSplices.length >= 1) {
  2870.  
  2871.  
  2872. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  2873. // let p1 = indexSplices[0].removed;
  2874. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  2875.  
  2876. /* folllow
  2877. a.notifyPath(c + ".splices", d);
  2878. a.notifyPath(c + ".length", b.length);
  2879. */
  2880. // stampDomArraySplices_
  2881.  
  2882.  
  2883. await new Promise(resolve => {
  2884. cnt.resolveForDOMRendering781 = resolve;
  2885.  
  2886. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  2887. indexSplices
  2888. });
  2889. indexSplices = null;
  2890. participantsForSpliceWR = null;
  2891. cnt.__notifyPath5036__("participantsManager.participants.length",
  2892. participants.length
  2893. );
  2894.  
  2895. });
  2896.  
  2897. // play safe for the change of 'length'
  2898. if (typeof nextBrowserTick !== 'function') {
  2899. await Promise.resolve(0);
  2900. } else {
  2901. await new Promise(resolve => nextBrowserTick(resolve)).then();
  2902. }
  2903.  
  2904. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  2905.  
  2906. const wrongSize = participants.length !== countOfElements
  2907. if (wrongSize) {
  2908. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  2909. return 0;
  2910. }
  2911.  
  2912. res = 2 | 4;
  2913.  
  2914. } else {
  2915.  
  2916. indexSplices = null;
  2917. participantsForSpliceWR = null;
  2918.  
  2919. if (participants.length !== countOfElements) {
  2920. // other unhandled cases
  2921. return 0;
  2922. }
  2923.  
  2924. }
  2925.  
  2926. // participants.length === countOfElements before contentUpdates
  2927. if (contentUpdates.length >= 1) {
  2928. for (const contentUpdate of contentUpdates) {
  2929. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  2930. if (isChanged) {
  2931. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  2932. res |= 4 | 8;
  2933. }
  2934. }
  2935. }
  2936. contentUpdates = null;
  2937.  
  2938. return res;
  2939.  
  2940.  
  2941. })();
  2942.  
  2943.  
  2944. resPromise.then(resValue => {
  2945.  
  2946. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  2947. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  2948. if (resValue === 0) {
  2949. new Promise(resolve => {
  2950. cnt.resolveForDOMRendering781 = resolve;
  2951. isLogRequired && console.log("Full Refresh begins");
  2952. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  2953. }).then(() => {
  2954. isLogRequired && console.log("Full Refresh ends");
  2955. console.groupEnd();
  2956. }).then(lockResolve);
  2957. return;
  2958. }
  2959.  
  2960. const delayLockResolve = (resValue & 4) === 4;
  2961.  
  2962. if (delayLockResolve) {
  2963. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  2964. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  2965. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  2966. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  2967. isLogRequired && console.groupEnd();
  2968. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  2969. // mutex lock with requestAnimationFrame can also disable participants update in background
  2970. requestAnimationFrame(lockResolve);
  2971. } else {
  2972. lockResolve();
  2973. }
  2974.  
  2975. });
  2976.  
  2977. });
  2978.  
  2979. }
  2980.  
  2981. return { notifyPath7081 };
  2982.  
  2983. })();
  2984.  
  2985. const whenDefinedMultiple = async (tags) => {
  2986.  
  2987. const sTags = [...new Set(tags)];
  2988. const len = sTags.length;
  2989.  
  2990. const pTags = new Array(len);
  2991. for (let i = 0; i < len; i++) {
  2992. pTags[i] = customElements.whenDefined(sTags[i]);
  2993. }
  2994.  
  2995. await Promise.all(pTags);
  2996. pTags.length = 0;
  2997.  
  2998. return sTags;
  2999.  
  3000. }
  3001.  
  3002. const onRegistryReadyForDataManipulation = () => {
  3003.  
  3004. function dummy5035(a, b, c) { }
  3005. function dummy411(a, b, c) { }
  3006.  
  3007.  
  3008.  
  3009. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  3010.  
  3011. if (!DO_PARTICIPANT_LIST_HACKS) return;
  3012.  
  3013. const tag = "yt-live-chat-participant-list-renderer";
  3014. const cProto = getProto(document.createElement(tag));
  3015. if (!cProto || typeof cProto.attached !== 'function') {
  3016. // for _registered, proto.attached shall exist when the element is defined.
  3017. // for controller extraction, attached shall exist when instance creates.
  3018. console.warn(`proto.attached for ${tag} is unavailable.`);
  3019. return;
  3020. }
  3021.  
  3022.  
  3023. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  3024.  
  3025. 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'];
  3026. const fgs = {};
  3027. for (const key of fgsArr) fgs[key] = undefined;
  3028.  
  3029. try {
  3030. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  3031. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  3032. } catch (e) { }
  3033. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  3034.  
  3035. const canDoReplacement = (() => {
  3036. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  3037. console.warn('YouTube Live Chat Tamer is running.');
  3038. return;
  3039. }
  3040.  
  3041. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  3042. console.warn('YouTube Live Chat Tamer is running.');
  3043. return;
  3044. }
  3045.  
  3046. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  3047. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  3048.  
  3049. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  3050. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  3051. return;
  3052. }
  3053.  
  3054. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  3055. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  3056. return;
  3057. }
  3058.  
  3059. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  3060. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  3061. return;
  3062. }
  3063. return true;
  3064. })();
  3065.  
  3066. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  3067.  
  3068. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  3069. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3070. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  3071. // const s = fiRSCB.split('.');
  3072. // Feb 2024: 0.403.247 => NG
  3073. // if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  3074. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  3075. // } else {
  3076. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - NG`);
  3077. // }
  3078. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ###`);
  3079. } else {
  3080. console.log("flushRenderStamperComponentBindings_ - not found");
  3081. }
  3082. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  3083.  
  3084. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3085. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  3086. cProto.flushRenderStamperComponentBindings_ = function () {
  3087. // console.log('flushRenderStamperComponentBindings_')
  3088. this.flushRenderStamperComponentBindings66_();
  3089. if (this.resolveForDOMRendering781) {
  3090. this.resolveForDOMRendering781();
  3091. this.resolveForDOMRendering781 = null;
  3092. }
  3093. };
  3094. }
  3095.  
  3096. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  3097. const container = ((this || 0).$ || 0).participants;
  3098. if (!container) return 0;
  3099. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  3100. }
  3101.  
  3102. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  3103.  
  3104. cProto.__attached412__ = cProto.attached;
  3105. const fpPList = function (hostElement) {
  3106. const cnt = insp(hostElement);
  3107. if (beforeParticipantsMap.has(cnt)) return;
  3108. hostElement.classList.add('n9fJ3');
  3109.  
  3110. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  3111. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  3112. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  3113. return;
  3114. }
  3115.  
  3116. groupCollapsed("Participant List attached", "");
  3117. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  3118. // console.log(123, 'appendChild');
  3119. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  3120. // }
  3121.  
  3122. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  3123. // console.log(123, 'insertBefore');
  3124. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  3125. // }
  3126.  
  3127. cnt.__notifyPath5036__ = cnt.notifyPath
  3128. const participants = ((cnt.participantsManager || 0).participants || 0);
  3129. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  3130. console.log(`initial number of participants: ${participants.length}`);
  3131. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  3132. beforeParticipantsMap.set(cnt, newParticipants);
  3133. cnt.notifyPath = notifyPath7081;
  3134. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  3135. console.groupEnd();
  3136. }
  3137. cProto.attached = function () {
  3138. fpPList(this.hostElement || this);
  3139. this.__attached412__.apply(this, arguments);
  3140. };
  3141.  
  3142.  
  3143. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  3144.  
  3145. /** @type {boolean | (()=>boolean)} */
  3146. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  3147. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  3148.  
  3149. let lastMessageDate = 0;
  3150. cProto.stampDomArray66_ = cProto.stampDomArray_;
  3151.  
  3152. cProto.stampDomArray_ = function (...args) {
  3153. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  3154. if (typeof toUseMaintainStableList === 'function') {
  3155. toUseMaintainStableList = toUseMaintainStableList();
  3156. }
  3157. args[5] = toUseMaintainStableList;
  3158. let currentDate = Date.now();
  3159. if (currentDate - lastMessageDate > 440) {
  3160. lastMessageDate = currentDate;
  3161. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  3162. }
  3163. }
  3164. return this.stampDomArray66_.apply(this, args);
  3165. }
  3166.  
  3167. cProto.stampDomArray_.nIegT = 1;
  3168.  
  3169. }
  3170. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  3171. } else {
  3172. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  3173. }
  3174.  
  3175. console.groupEnd();
  3176.  
  3177. if (onPageElements.length >= 1) {
  3178. for (const s of onPageElements) {
  3179. if (insp(s).isAttached === true) {
  3180. fpPList(s);
  3181. }
  3182. }
  3183. }
  3184.  
  3185. }).catch(console.warn);
  3186.  
  3187. };
  3188.  
  3189. if (DO_PARTICIPANT_LIST_HACKS) {
  3190. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  3191. }
  3192.  
  3193.  
  3194.  
  3195. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  3196.  
  3197. const transitionEndAfterFnSimple = new WeakMap();
  3198. let prevTransitionClosing = null;
  3199.  
  3200. const fixChildrenIssue = !!fixChildrenIssue801;
  3201. if (fixChildrenIssue && typeof Object.getOwnPropertyDescriptor === 'function' && typeof Proxy !== 'undefined') {
  3202. const divProto = HTMLDivElement.prototype;
  3203. const polymerControllerSetData3 = function (c, d, e) {
  3204. return insp(this).set(c, d, e);
  3205. }
  3206. const polymerControllerSetData2 = function (c, d) {
  3207. return insp(this).set(c, d);
  3208. }
  3209. const dummyFn = function () {
  3210. console.log('dummyFn', ...arguments);
  3211. };
  3212.  
  3213. const wm44 = new Map();
  3214. function unPolymerSet(elem) {
  3215. const is = elem.is;
  3216. if (is && !elem.set) {
  3217. let rt = wm44.get(is);
  3218. if (!rt) {
  3219. rt = 1;
  3220. const cnt = insp(elem);
  3221. if (cnt !== elem && cnt && typeof cnt.set === 'function') {
  3222. const pcSet = cnt.constructor.prototype.set;
  3223. if (pcSet && typeof pcSet === 'function' && pcSet.length === 3) {
  3224. rt = polymerControllerSetData3;
  3225. } else if (pcSet && typeof pcSet === 'function' && pcSet.length === 2) {
  3226. rt = polymerControllerSetData2;
  3227. }
  3228. }
  3229. wm44.set(is, rt);
  3230. }
  3231. if (typeof rt === 'function') {
  3232. elem.set = rt;
  3233. } else {
  3234. elem.set = dummyFn;
  3235. }
  3236. }
  3237. }
  3238. if (!divProto.__children577__ && !divProto.__children578__) {
  3239.  
  3240. const dp = Object.getOwnPropertyDescriptor(Element.prototype, 'children');
  3241. const dp2 = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'children');
  3242. const dp3 = Object.getOwnPropertyDescriptor(divProto, 'children');
  3243.  
  3244. if (dp && dp.configurable === true && dp.enumerable === true && typeof dp.get === 'function' && !dp2 && !dp3) {
  3245.  
  3246. if (divProto instanceof HTMLElement && divProto instanceof Element) {
  3247.  
  3248. let m = Object.assign({}, dp);
  3249. divProto.__children577__ = dp.get;
  3250. divProto.__children578__ = function () {
  3251. if (this.__children803__) return this.__children803__;
  3252. if (this.__children801__) {
  3253. let arr = [];
  3254. for (let elem = this.firstElementChild; elem !== null; elem = elem.nextElementSibling) {
  3255. if (elem.is) {
  3256. unPolymerSet(elem);
  3257. arr.push(elem);
  3258. }
  3259. }
  3260. if (this.__children801__ === 2) this.__children803__ = arr;
  3261. return arr;
  3262. }
  3263. return 577;
  3264. };
  3265. m.get = function () {
  3266. const r = this.__children578__();
  3267. if (r !== 577) return r;
  3268. return this.__children577__();
  3269. };
  3270. Object.defineProperty(divProto, 'children', m);
  3271.  
  3272. console.log('fixChildrenIssue - set OK')
  3273.  
  3274. }
  3275. }
  3276.  
  3277. }
  3278.  
  3279.  
  3280. }
  3281.  
  3282.  
  3283. // const bnForDelayChatOccurrence = () => {
  3284.  
  3285. // document.addEventListener('animationstart', (evt) => {
  3286.  
  3287. // if (evt.animationName === 'dontRenderAnimation') {
  3288. // evt.target.classList.remove('dont-render');
  3289. // if (scrollChatFn) scrollChatFn();
  3290. // }
  3291.  
  3292. // }, true);
  3293.  
  3294. // const f = (elm) => {
  3295. // if (elm && elm.nodeType === 1) {
  3296. // if (!skipDontRender && allowDontRender === true) {
  3297. // // innerTextFixFn();
  3298. // elm.classList.add('dont-render');
  3299. // }
  3300. // }
  3301. // }
  3302.  
  3303. // Node.prototype.__appendChild931__ = function (a) {
  3304. // a = dr(a);
  3305. // if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  3306. // if (a && a.nodeType === 1) f(a);
  3307. // else if (a instanceof DocumentFragment) {
  3308. // for (let n = a.firstChild; n; n = n.nextSibling) {
  3309. // f(n);
  3310. // }
  3311. // }
  3312. // }
  3313. // }
  3314.  
  3315. // Node.prototype.__appendChild932__ = function () {
  3316. // this.__appendChild931__.apply(this, arguments);
  3317. // return Node.prototype.appendChild.apply(this, arguments);
  3318. // }
  3319.  
  3320.  
  3321. // };
  3322.  
  3323. const watchUserCSS = () => {
  3324.  
  3325. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  3326.  
  3327. const getElemFromWR = (nr) => {
  3328. const n = kRef(nr);
  3329. if (n && n.isConnected) return n;
  3330. return null;
  3331. }
  3332.  
  3333. const clearContentVisibilitySizing = () => {
  3334. Promise.resolve().then(() => {
  3335.  
  3336. const e = document.querySelector('#show-more[disabled]');
  3337. let btnShowMoreWR = e ? mWeakRef(e) : null;
  3338.  
  3339. let lastVisibleItemWR = null;
  3340. for (const elm of document.querySelectorAll('[wSr93]')) {
  3341. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  3342. elm.setAttribute('wSr93', '');
  3343. // custom CSS property --wsr94 not working when attribute wSr93 removed
  3344. }
  3345. foregroundPromiseFn().then(() => {
  3346. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  3347. if (btnShowMore) btnShowMore.click();
  3348. else {
  3349. // would not work if switch it frequently
  3350. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  3351. if (lastVisibleItem) {
  3352.  
  3353. Promise.resolve()
  3354. .then(() => lastVisibleItem.scrollIntoView())
  3355. .then(() => lastVisibleItem.scrollIntoView(false))
  3356. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  3357. .catch(e => { }) // break the chain when method not callable
  3358.  
  3359. }
  3360. }
  3361. });
  3362.  
  3363. });
  3364.  
  3365. }
  3366.  
  3367. const mutObserver = new MutationObserver((mutations) => {
  3368. for (const mutation of mutations) {
  3369. if ((mutation.addedNodes || 0).length >= 1) {
  3370. for (const addedNode of mutation.addedNodes) {
  3371. if (addedNode.nodeName === 'STYLE') {
  3372. clearContentVisibilitySizing();
  3373. return;
  3374. }
  3375. }
  3376. }
  3377. if ((mutation.removedNodes || 0).length >= 1) {
  3378. for (const removedNode of mutation.removedNodes) {
  3379. if (removedNode.nodeName === 'STYLE') {
  3380. clearContentVisibilitySizing();
  3381. return;
  3382. }
  3383. }
  3384. }
  3385. }
  3386. });
  3387.  
  3388. mutObserver.observe(document.documentElement, {
  3389. childList: true,
  3390. subtree: false
  3391. });
  3392. mutObserver.observe(document.head, {
  3393. childList: true,
  3394. subtree: false
  3395. });
  3396. mutObserver.observe(document.body, {
  3397. childList: true,
  3398. subtree: false
  3399. });
  3400.  
  3401. }
  3402.  
  3403.  
  3404. class WillChangeController {
  3405. constructor(itemScroller, willChangeValue) {
  3406. this.element = itemScroller;
  3407. this.counter = 0;
  3408. this.active = false;
  3409. this.willChangeValue = willChangeValue;
  3410. }
  3411.  
  3412. beforeOper() {
  3413. if (!this.active) {
  3414. this.active = true;
  3415. this.element.style.willChange = this.willChangeValue;
  3416. }
  3417. this.counter++;
  3418. }
  3419.  
  3420. afterOper() {
  3421. const c = this.counter;
  3422. foregroundPromiseFn().then(() => {
  3423. if (c === this.counter) {
  3424. this.active = false;
  3425. this.element.style.willChange = '';
  3426. }
  3427. });
  3428. }
  3429.  
  3430. release() {
  3431. const element = this.element;
  3432. this.element = null;
  3433. this.counter = 1e16;
  3434. this.active = false;
  3435. try {
  3436. element.style.willChange = '';
  3437. } catch (e) { }
  3438. }
  3439.  
  3440. }
  3441.  
  3442.  
  3443. const skzData = (skz) => skz.data = {
  3444. "message": {
  3445. "runs": [
  3446. {
  3447. "text": "em2o"
  3448. },
  3449. {
  3450. "emoji": {
  3451. "emojiId": "cm35z",
  3452. "shortcuts": [
  3453. ":_s:",
  3454. ":s:"
  3455. ],
  3456. "searchTerms": [
  3457. "_s",
  3458. "s"
  3459. ],
  3460. "image": {
  3461. "thumbnails": [
  3462. {
  3463. "url": dummyImgURL,
  3464. "width": 48,
  3465. "height": 48
  3466. }
  3467. ],
  3468. "accessibility": {
  3469. "accessibilityData": {
  3470. "label": "s"
  3471. }
  3472. }
  3473. },
  3474. "isCustomEmoji": true
  3475. }
  3476. },
  3477. {
  3478. "text": "ji"
  3479. }
  3480. ]
  3481. },
  3482. "authorName": {
  3483. "simpleText": "N"
  3484. },
  3485. "authorPhoto": {
  3486. "thumbnails": [
  3487. {
  3488. "url": dummyImgURL,
  3489. "width": 64,
  3490. "height": 64
  3491. }
  3492. ]
  3493. },
  3494. "contextMenuEndpoint": {
  3495. "commandMetadata": {
  3496. "webCommandMetadata": {
  3497. "ignoreNavigation": true
  3498. }
  3499. },
  3500. "liveChatItemContextMenuEndpoint": {
  3501. "params": "123=="
  3502. }
  3503. },
  3504. "id": "sk35z",
  3505. "timestampUsec": "1232302352350000",
  3506. "authorBadges": [
  3507. {
  3508. "liveChatAuthorBadgeRenderer": {
  3509. "customThumbnail": {
  3510. "thumbnails": [
  3511. {
  3512. "url": dummyImgURL,
  3513. "width": 16,
  3514. "height": 16
  3515. },
  3516. {
  3517. "url": dummyImgURL,
  3518. "width": 32,
  3519. "height": 32
  3520. }
  3521. ]
  3522. },
  3523. "tooltip": "T",
  3524. "accessibility": {
  3525. "accessibilityData": {
  3526. "label": "E"
  3527. }
  3528. }
  3529. }
  3530. }
  3531. ],
  3532. "authorExternalChannelId": "A",
  3533. "contextMenuAccessibility": {
  3534. "accessibilityData": {
  3535. "label": "E"
  3536. }
  3537. },
  3538. "timestampText": {
  3539. "simpleText": "0:43"
  3540. }
  3541. };
  3542.  
  3543.  
  3544.  
  3545. const { lcRendererElm, visObserver } = (() => {
  3546.  
  3547.  
  3548.  
  3549. let lcRendererWR = null;
  3550.  
  3551. const lcRendererElm = () => {
  3552. let lcRenderer = kRef(lcRendererWR);
  3553. if (!lcRenderer || !lcRenderer.isConnected) {
  3554. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  3555. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  3556. }
  3557. return lcRenderer;
  3558. };
  3559.  
  3560.  
  3561. let hasFirstShowMore = false;
  3562.  
  3563. const visObserverFn = (entry) => {
  3564.  
  3565. const target = entry.target;
  3566. if (!target) return;
  3567. // if(target.classList.contains('dont-render')) return;
  3568. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  3569. // const h = entry.boundingClientRect.height;
  3570. /*
  3571. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  3572. // e.g. under fullscreen. the element created but not rendered.
  3573. target.setAttribute('wSr93', '');
  3574. return;
  3575. }
  3576. */
  3577. if (isVisible) {
  3578. // target.style.setProperty('--wsr94', h + 'px');
  3579. target.setAttribute('wSr93', 'visible');
  3580. if (nNextElem(target) === null) {
  3581.  
  3582. // firstVisibleItemDetected = true;
  3583. /*
  3584. if (dateNow() - lastScroll < 80) {
  3585. lastLShow = 0;
  3586. lastScroll = 0;
  3587. Promise.resolve().then(clickShowMore);
  3588. } else {
  3589. lastLShow = dateNow();
  3590. }
  3591. */
  3592. // lastLShow = dateNow();
  3593. } else if (!hasFirstShowMore) { // should more than one item being visible
  3594. // implement inside visObserver to ensure there is sufficient delay
  3595. hasFirstShowMore = true;
  3596. foregroundPromiseFn().then(() => {
  3597. // foreground page
  3598. // page visibly ready -> load the latest comments at initial loading
  3599. const lcRenderer = lcRendererElm();
  3600. if (lcRenderer) {
  3601. if (typeof nextBrowserTick !== 'function') {
  3602. insp(lcRenderer).scrollToBottom_();
  3603. } else {
  3604. nextBrowserTick(() => {
  3605. const cnt = insp(lcRenderer);
  3606. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3607. cnt.scrollToBottom_();
  3608. });
  3609. }
  3610. }
  3611. });
  3612. }
  3613. }
  3614. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  3615.  
  3616. // target.style.setProperty('--wsr94', h + 'px');
  3617. target.setAttribute('wSr93', 'hidden');
  3618. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  3619.  
  3620. }
  3621.  
  3622.  
  3623.  
  3624. const visObserver = new IntersectionObserver((entries) => {
  3625.  
  3626. for (const entry of entries) {
  3627.  
  3628. Promise.resolve(entry).then(visObserverFn);
  3629.  
  3630. }
  3631.  
  3632. }, {
  3633. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  3634. rootMargin: "0px",
  3635. threshold: [0.05, 0.95],
  3636. });
  3637.  
  3638.  
  3639. return { lcRendererElm, visObserver }
  3640.  
  3641.  
  3642. })();
  3643.  
  3644. const { setupMutObserver } = (() => {
  3645.  
  3646. async function asyncTickerBackgroundOverridedChecker() {
  3647.  
  3648. try {
  3649. await promiseForCustomYtElementsReady.then();
  3650. await customElements.whenDefined('yt-live-chat-text-message-renderer');
  3651. await new Promise(r => setTimeout(r, 800));
  3652.  
  3653. if (!hasTimerModified) return;
  3654. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  3655. if (!tickerRenderer) return;
  3656.  
  3657. const tickerRendererDollar = indr(tickerRenderer);
  3658. const items = (tickerRendererDollar || 0).items || 0;
  3659. if (!items) return;
  3660. const template = document.createElement('template');
  3661. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  3662. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  3663. dimmed="" [dummy777]>
  3664. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  3665. 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));">
  3666. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  3667. <yt-img-shadow777 id="author-photo" height="24" width="24"
  3668. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  3669. style="background-color: transparent;" loaded=""><img id="img"
  3670. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  3671. src="${dummyImgURL}"></yt-img-shadow777>
  3672.  
  3673. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  3674. </div>
  3675. </div>
  3676. </yt-live-chat-ticker-dummy777-item-renderer>`;
  3677. const dummy777 = template.content.firstElementChild;
  3678. await Promise.resolve().then();
  3679. let res = 0;
  3680. if (items instanceof HTMLElement && items.isConnected === true) {
  3681. try {
  3682. items.appendChild(dummy777);
  3683. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  3684. if (container.isConnected === true) {
  3685. const evaluated = `${getComputedStyleCached(container).background}`;
  3686. container = null;
  3687. res = evaluated.indexOf('0.') < 4 ? 1 : 2;
  3688. }
  3689. } catch (e) { console.warn(e) }
  3690. HTMLElement.prototype.remove.call(dummy777);
  3691. }
  3692. await Promise.resolve().then();
  3693. dummy777.textContent = '';
  3694. if (res === 1) {
  3695. // not fulfilling
  3696. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3697. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3698. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3699. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3700. );
  3701. 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');
  3702. console.groupEnd();
  3703. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  3704. } else if (res === 2) {
  3705. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3706. }
  3707. } catch (e) {
  3708. console.warn(e);
  3709. }
  3710. }
  3711.  
  3712. // async function asyncDelayChatOccurrence(m2) {
  3713. // try {
  3714. // await promiseForCustomYtElementsReady.then();
  3715. // await customElements.whenDefined('yt-live-chat-text-message-renderer');
  3716. // await new Promise(r => setTimeout(r, 1));
  3717. // const dummy888 = document.createElement('yt-live-chat-text-message-renderer');
  3718. // // const template = document.createElement('template');
  3719. // // template.innerHTML = "<yt-live-chat-text-message-renderer></yt-live-chat-text-message-renderer>"
  3720. // // const dummy888 = template.content.firstElementChild;
  3721. // const skzCnt = insp(dummy888);
  3722. // if (!(skzCnt && 'data' in skzCnt && 'attached' in skzCnt)) {
  3723. // return;
  3724. // }
  3725. // if (!skzCnt.hostElement) skzCnt.hostElement = dummy888;
  3726. // /** @type {HTMLTemplateElement} */
  3727. // const skzElem = dummy888;
  3728. // let cz1 = null;
  3729. // const deferredZy1 = new Promise(resolve => {
  3730. // skzCnt.attached = function () {
  3731. // cz1 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  3732. // resolve(skzElem.textContent);
  3733. // }
  3734. // skzCnt.detached = function () {
  3735. // }
  3736. // });
  3737. // skzElem.id = 'sk35z';
  3738. // skzData(skzCnt);
  3739. // sk35zResolveFn = null;
  3740. // const deferredMutation = new Promise(resolve => {
  3741. // sk35zResolveFn = resolve;
  3742. // HTMLElement.prototype.appendChild.call(m2, skzElem);
  3743. // });
  3744. // const [zy1, _] = await Promise.all([deferredZy1, deferredMutation]);
  3745. // skzCnt.attached = function () { };
  3746. // function fn() {
  3747. // const zy2 = skzElem.textContent;
  3748. // const cz2 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  3749. // if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  3750. // allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  3751. // }
  3752. // if (allowDontRender === true) return true;
  3753. // if (allowDontRender === false) {
  3754. // console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3755. // "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3756. // "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3757. // );
  3758. // 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');
  3759. // console.groupEnd();
  3760. // }
  3761. // }
  3762. // await new Promise(r => setTimeout(r, 1));
  3763. // if (!fn()) return;
  3764. // await foregroundPromiseFn().then();
  3765. // if (!fn()) return;
  3766. // skzElem.remove();
  3767. // await Promise.resolve().then();
  3768. // skzElem.textContent = '';
  3769. // console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3770. // } catch (e) {
  3771. // console.warn(e);
  3772. // }
  3773. // }
  3774.  
  3775. const mutFn = (items) => {
  3776. let seqIndex = -1;
  3777. const elementSet = new Set();
  3778. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  3779. if (node.hasAttribute('wSr93')) {
  3780. seqIndex = parseInt(node.getAttribute('yt-chat-item-seq'), 10);
  3781. break;
  3782. }
  3783. node.setAttribute('wSr93', '');
  3784. visObserver.observe(node);
  3785. elementSet.add(node);
  3786. }
  3787. let iter = elementSet.values();
  3788. let i = seqIndex + elementSet.size;
  3789. for (let curr; curr = iter.next().value;) {
  3790. curr.setAttribute('yt-chat-item-seq', i % 60);
  3791. curr.classList.add('yt-chat-item-' + ((i % 2) ? 'odd' : 'even'));
  3792. i--;
  3793. }
  3794. iter = null;
  3795. elementSet.clear();
  3796. }
  3797.  
  3798. const mutObserver = new MutationObserver((mutations) => {
  3799. const items = (mutations[0] || 0).target;
  3800. if (!items) return;
  3801. if (sk35zResolveFn) {
  3802. sk35zResolveFn();
  3803. sk35zResolveFn = null;
  3804. }
  3805. mutFn(items);
  3806. });
  3807.  
  3808. const setupMutObserver = (m2) => {
  3809. scrollChatFn = null;
  3810. mutObserver.disconnect();
  3811. mutObserver.takeRecords();
  3812. if (m2) {
  3813. if (typeof m2.__appendChild932__ === 'function') {
  3814. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  3815. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  3816. }
  3817. mutObserver.observe(m2, {
  3818. childList: true,
  3819. subtree: false
  3820. });
  3821. mutFn(m2);
  3822.  
  3823. const isFirstList = firstList;
  3824. firstList = false;
  3825.  
  3826. if (ENABLE_OVERFLOW_ANCHOR) {
  3827.  
  3828. let items = m2;
  3829. let addedAnchor = false;
  3830. if (items) {
  3831. if (items.nextElementSibling === null) {
  3832. items.classList.add('no-anchor');
  3833. addedAnchor = true;
  3834. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  3835. }
  3836. }
  3837.  
  3838.  
  3839.  
  3840. if (addedAnchor) {
  3841. nodeParent(m2).classList.add('no-anchor'); // required
  3842. }
  3843.  
  3844. }
  3845.  
  3846.  
  3847.  
  3848. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  3849.  
  3850. (() => {
  3851.  
  3852. const tag = 'yt-iframed-player-events-relay'
  3853. const dummy = document.createElement(tag);
  3854.  
  3855. const cProto = getProto(dummy);
  3856. if (!cProto || !cProto.handlePostMessage_) {
  3857. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  3858. return;
  3859. }
  3860.  
  3861. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_ && !cProto.handlePostMessage67_ ) {
  3862.  
  3863. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  3864.  
  3865. const handlePostMessageAfterPromiseA = (da) => {
  3866.  
  3867. if (!da || typeof da !== 'object') return;
  3868.  
  3869. if ('yt-player-state-change' in da) {
  3870.  
  3871. const qc = da['yt-player-state-change'];
  3872.  
  3873.  
  3874. let isQcChanged = false;
  3875.  
  3876. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  3877. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  3878. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  3879.  
  3880.  
  3881. if ((isQcChanged) && playerState !== _playerState) {
  3882. playerEventsByIframeRelay = true;
  3883. onPlayStateChangePromise = new Promise((resolve) => {
  3884. const k = _playerState;
  3885. foregroundPromiseFn().then(() => {
  3886. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  3887. onPlayStateChangePromise = null;
  3888. resolve();
  3889. })
  3890. }).catch(console.warn);
  3891.  
  3892. }
  3893.  
  3894. } else if ('yt-player-video-progress' in da) {
  3895. const vp = da['yt-player-video-progress'];
  3896.  
  3897.  
  3898. relayCount++;
  3899. lastPlayerProgress = vp > 0 ? vp : 0;
  3900.  
  3901.  
  3902. if (relayPromise && vp > 0 && relayCount >= 2) {
  3903. if (onPlayStateChangePromise) {
  3904. onPlayStateChangePromise.then(() => {
  3905. relayPromise && relayPromise.resolve();
  3906. relayPromise = null;
  3907. })
  3908. } else {
  3909. relayPromise.resolve();
  3910. relayPromise = null;
  3911. }
  3912. }
  3913.  
  3914. }
  3915.  
  3916. };
  3917.  
  3918. cProto.handlePostMessage67_ = function (a) {
  3919.  
  3920. let da = a.data;
  3921. const wNode = mWeakRef(this);
  3922. // const wData = mWeakRef(da);
  3923.  
  3924. playEventsStack = playEventsStack.then(() => {
  3925.  
  3926. const cnt = kRef(wNode);
  3927. // const da = kRef(wData);
  3928.  
  3929. if (!cnt || !a || !da) return;
  3930. handlePostMessageAfterPromiseA(da);
  3931. da = null;
  3932.  
  3933. const r = cnt.handlePostMessage66_(a);
  3934. a = null;
  3935.  
  3936. }).catch(console.warn);
  3937.  
  3938. }
  3939.  
  3940. const handlePostMessageAfterPromiseB = (da) => {
  3941.  
  3942. const lcr = document.querySelector('yt-live-chat-renderer');
  3943. const psc = document.querySelector("yt-player-seek-continuation");
  3944. if (lcr && psc && lcr.replayBuffer_) {
  3945.  
  3946. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  3947. const daProgress = da['yt-player-video-progress'] * 1000
  3948. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  3949.  
  3950. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  3951. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  3952.  
  3953. // console.log(deepCopy( front_))
  3954. // console.log(deepCopy( back_))
  3955. // console.log(rbProgress, daProgress, )
  3956. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  3957. // no action
  3958. // console.log('ss1')
  3959. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  3960. // daProgress - 1200 < rbProgress < daProgress + 3400
  3961. // console.log('ss2')
  3962. } else {
  3963.  
  3964. lcr.previousProgressSec = 1E-5;
  3965. // lcr._setIsSeeking(!0),
  3966. lcr.replayBuffer_.clear()
  3967. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  3968. }
  3969.  
  3970. }
  3971.  
  3972.  
  3973. };
  3974.  
  3975. cProto.handlePostMessage_ = function (a) {
  3976.  
  3977. let da = (a || 0).data || 0;
  3978. const wNode = mWeakRef(this);
  3979.  
  3980. if (typeof da !== 'object') return;
  3981.  
  3982. if (waitForInitialDataCompletion === 1) return;
  3983.  
  3984. if (!isPlayProgressTriggered) {
  3985. isPlayProgressTriggered = true; // set once
  3986.  
  3987. if ('yt-player-video-progress' in da) {
  3988. waitForInitialDataCompletion = 1;
  3989.  
  3990. const wrapWith = (data) => {
  3991. const { origin } = a;
  3992. return {
  3993. origin,
  3994. data
  3995. };
  3996. }
  3997.  
  3998. this.handlePostMessage67_(wrapWith({
  3999. "yt-iframed-parent-ready": true
  4000. }));
  4001.  
  4002.  
  4003. playEventsStack = playEventsStack.then(() => {
  4004.  
  4005. const cnt = kRef(wNode);
  4006.  
  4007. if (!cnt || !a || !da) return;
  4008.  
  4009. handlePostMessageAfterPromiseB(da);
  4010. da = null;
  4011.  
  4012. waitForInitialDataCompletion = 2;
  4013.  
  4014. const r = cnt.handlePostMessage_(a); // isPlayProgressTriggered is set
  4015. a = null;
  4016.  
  4017. }).catch(console.warn);
  4018.  
  4019. return;
  4020.  
  4021. }
  4022.  
  4023. }
  4024.  
  4025. this.handlePostMessage67_(a);
  4026.  
  4027. }
  4028.  
  4029. }
  4030.  
  4031.  
  4032. })();
  4033.  
  4034. }
  4035.  
  4036. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  4037. asyncTickerBackgroundOverridedChecker();
  4038. }
  4039.  
  4040. }
  4041. }
  4042.  
  4043. return { setupMutObserver };
  4044.  
  4045.  
  4046.  
  4047. })();
  4048.  
  4049. const setupEvents = () => {
  4050.  
  4051.  
  4052. let scrollCount = 0;
  4053.  
  4054. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  4055.  
  4056.  
  4057. const delayFlushActiveItemsAfterUserActionK_ = () => {
  4058.  
  4059. const lcRenderer = lcRendererElm();
  4060. if (lcRenderer) {
  4061. const cnt = insp(lcRenderer);
  4062. if (!cnt.hasUserJustInteracted11_) return;
  4063. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  4064. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  4065. }
  4066. }
  4067.  
  4068. }
  4069.  
  4070. document.addEventListener('scroll', (evt) => {
  4071. if (!evt || !evt.isTrusted) return;
  4072. // lastScroll = dateNow();
  4073. if (++scrollCount > 1e9) scrollCount = 9;
  4074. }, passiveCapture); // support contain => support passive
  4075.  
  4076. let lastScrollCount = -1;
  4077. document.addEventListener('wheel', (evt) => {
  4078. if (!evt || !evt.isTrusted) return;
  4079. if (lastScrollCount === scrollCount) return;
  4080. lastScrollCount = scrollCount;
  4081. lastWheel = dateNow();
  4082. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4083. }, passiveCapture); // support contain => support passive
  4084.  
  4085. document.addEventListener('mousedown', (evt) => {
  4086. if (!evt || !evt.isTrusted) return;
  4087. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4088. lastMouseDown = dateNow();
  4089. currentMouseDown = true;
  4090. lastUserInteraction = lastMouseDown;
  4091. }, passiveCapture);
  4092.  
  4093. document.addEventListener('pointerdown', (evt) => {
  4094. if (!evt || !evt.isTrusted) return;
  4095. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4096. lastMouseDown = dateNow();
  4097. currentMouseDown = true;
  4098. lastUserInteraction = lastMouseDown;
  4099. }, passiveCapture);
  4100.  
  4101. document.addEventListener('click', (evt) => {
  4102. if (!evt || !evt.isTrusted) return;
  4103. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4104. lastMouseDown = lastMouseUp = dateNow();
  4105. currentMouseDown = false;
  4106. lastUserInteraction = lastMouseDown;
  4107. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4108. }, passiveCapture);
  4109.  
  4110. document.addEventListener('tap', (evt) => {
  4111. if (!evt || !evt.isTrusted) return;
  4112. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4113. lastMouseDown = lastMouseUp = dateNow();
  4114. currentMouseDown = false;
  4115. lastUserInteraction = lastMouseDown;
  4116. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4117. }, passiveCapture);
  4118.  
  4119.  
  4120. document.addEventListener('mouseup', (evt) => {
  4121. if (!evt || !evt.isTrusted) return;
  4122. if (currentMouseDown) {
  4123. lastMouseUp = dateNow();
  4124. currentMouseDown = false;
  4125. lastUserInteraction = lastMouseUp;
  4126. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4127. }
  4128. }, passiveCapture);
  4129.  
  4130.  
  4131. document.addEventListener('pointerup', (evt) => {
  4132. if (!evt || !evt.isTrusted) return;
  4133. if (currentMouseDown) {
  4134. lastMouseUp = dateNow();
  4135. currentMouseDown = false;
  4136. lastUserInteraction = lastMouseUp;
  4137. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4138. }
  4139. }, passiveCapture);
  4140.  
  4141. document.addEventListener('touchstart', (evt) => {
  4142. if (!evt || !evt.isTrusted) return;
  4143. lastTouchDown = dateNow();
  4144. currentTouchDown = true;
  4145. lastUserInteraction = lastTouchDown;
  4146. }, passiveCapture);
  4147.  
  4148. document.addEventListener('touchmove', (evt) => {
  4149. if (!evt || !evt.isTrusted) return;
  4150. lastTouchDown = dateNow();
  4151. currentTouchDown = true;
  4152. lastUserInteraction = lastTouchDown;
  4153. }, passiveCapture);
  4154.  
  4155. document.addEventListener('touchend', (evt) => {
  4156. if (!evt || !evt.isTrusted) return;
  4157. if (currentTouchDown) {
  4158. lastTouchUp = dateNow();
  4159. currentTouchDown = false;
  4160. lastUserInteraction = lastTouchUp;
  4161. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4162. }
  4163. }, passiveCapture);
  4164.  
  4165. document.addEventListener('touchcancel', (evt) => {
  4166. if (!evt || !evt.isTrusted) return;
  4167. if (currentTouchDown) {
  4168. lastTouchUp = dateNow();
  4169. currentTouchDown = false;
  4170. lastUserInteraction = lastTouchUp;
  4171. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4172. }
  4173. }, passiveCapture);
  4174.  
  4175.  
  4176. }
  4177.  
  4178. const getTimestampUsec = (itemRenderer) => {
  4179. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  4180. return itemRenderer.timestampUsec
  4181. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  4182. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  4183. if (messageRenderer) {
  4184.  
  4185. const messageRendererKey = firstObjectKey(messageRenderer);
  4186. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  4187. const messageRendererData = messageRenderer[messageRendererKey];
  4188. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  4189. return messageRendererData.timestampUsec
  4190. }
  4191. }
  4192. }
  4193. }
  4194. return null;
  4195. }
  4196.  
  4197. const onRegistryReadyForDOMOperations = () => {
  4198.  
  4199. let firstCheckedOnYtInit = false;
  4200.  
  4201. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  4202.  
  4203. const mightFirstCheckOnYtInit = () => {
  4204. if (firstCheckedOnYtInit) return;
  4205. firstCheckedOnYtInit = true;
  4206.  
  4207. if (!document.body || !document.head) return;
  4208. if (!assertorURL()) return;
  4209.  
  4210. addCssManaged();
  4211.  
  4212. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  4213. if (efsContainer && efsContainer.parentNode !== document.body) {
  4214. document.body.appendChild(efsContainer);
  4215. }
  4216.  
  4217. };
  4218.  
  4219. if (!assertorURL()) return;
  4220. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  4221.  
  4222.  
  4223. const { weakWrap } = (() => {
  4224.  
  4225.  
  4226. // const tickerFuncProps = new Set([
  4227. // 'animateShowStats', 'animateHideStats', // updateStatsBarAndMaybeShowAnimationRevised
  4228. // 'collapse', // slideDownNoSelfLeakage
  4229. // 'requestRemoval', // collapseNoSelfLeakage
  4230. // 'setContainerWidth', 'get', 'set', // deletedChangedNoSelfLeakage
  4231. // 'computeAriaLabel', //dataChanged
  4232. // 'startCountdown', // dataChanged [in case]
  4233. // ]);
  4234.  
  4235. // const tickerTags = new Set([
  4236. // "yt-live-chat-ticker-renderer",
  4237. // "yt-live-chat-ticker-paid-message-item-renderer",
  4238. // "yt-live-chat-ticker-paid-sticker-item-renderer",
  4239. // "yt-live-chat-ticker-sponsor-item-renderer"
  4240. // ]);
  4241.  
  4242. // const emptySet = new Set();
  4243.  
  4244.  
  4245.  
  4246. // const tickerFuncPropsFn = (cnt) => {
  4247.  
  4248. // const is = `${cnt.is}`;
  4249.  
  4250. // if (tickerTags.has(is)) {
  4251. // let flg = 0;
  4252. // if (cnt.get && cnt.set) flg |= 1;
  4253. // if (cnt.setContainerWidth && cnt.collapse && cnt.requestRemoval) flg |= 2;
  4254. // if (cnt.animateShowStats && cnt.animateHideStats) flg |= 4;
  4255. // if (cnt.startCountdown) flg |= 8;
  4256. // console.log(`DEBUG flag_6877 = ${flg}`, is);
  4257. // // DEBUG flag_6877 = 15 yt-live-chat-ticker-paid-message-item-renderer
  4258. // // DEBUG flag_6877 = 11 yt-live-chat-ticker-sponsor-item-renderer
  4259. // return tickerFuncProps;
  4260. // }
  4261.  
  4262. // return emptySet;
  4263.  
  4264.  
  4265. // }
  4266.  
  4267.  
  4268. // const smb = Symbol();
  4269. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  4270. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  4271. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  4272.  
  4273.  
  4274.  
  4275.  
  4276. const thisConversionFn = (thisArg) => {
  4277. if (!thisArg) return null;
  4278. const kThis = thisArg[vmb];
  4279. if (kThis) {
  4280. const ref = kThis.ref;
  4281. return (ref ? kRef(ref) : null) || null;
  4282. }
  4283. return thisArg;
  4284. }
  4285. const pFnHandler2 = {
  4286. get(target, prop) {
  4287. if (prop === vmc) return target;
  4288. return Reflect.get(target, prop);
  4289. },
  4290. apply(target, thisArg, argumentsList) {
  4291. thisArg = thisConversionFn(thisArg);
  4292. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  4293. }
  4294. }
  4295. const proxySelfHandler = {
  4296. get(target, prop) {
  4297. if(prop === vmb) return target;
  4298. const ref = target.ref;
  4299. const cnt = kRef(ref);
  4300. if (!cnt) return;
  4301. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  4302. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  4303. return cnt[prop][vmd];
  4304. }
  4305. return cnt[prop];
  4306. },
  4307. set(target, prop, value) {
  4308. const cnt = kRef(target.ref);
  4309. if (!cnt) return true;
  4310. if(value && (value[vmc] || value[vmb])){
  4311. cnt[prop] = value[vmc] || thisConversionFn(value);
  4312. return true;
  4313. }
  4314. cnt[prop] = value;
  4315. return true;
  4316. }
  4317. };
  4318. const weakWrap = (thisArg) => {
  4319. thisArg = thisConversionFn(thisArg);
  4320. if (!thisArg) {
  4321. console.error('thisArg is not found');
  4322. return null;
  4323. }
  4324. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  4325. }
  4326.  
  4327.  
  4328.  
  4329.  
  4330.  
  4331.  
  4332. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  4333. window.getComputedStyle533 = window.getComputedStyle;
  4334. window.getComputedStyle = function (a, ...args) {
  4335. a = thisConversionFn(a);
  4336. if (a) {
  4337. return getComputedStyle533(a, ...args);
  4338. }
  4339. return null;
  4340. }
  4341. }
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349. // const fnProxySelf = function (...args) {
  4350. // const cnt = kRef(this.ref);
  4351. // if (cnt) {
  4352. // return cnt[this.prop](...args); // might throw error
  4353. // }
  4354. // }
  4355. // const proxySelfHandler = {
  4356. // get(target, prop) {
  4357. // const ref = target.ref;
  4358. // const cnt = kRef(ref);
  4359. // if (!cnt) return;
  4360. // if (prop === 'dtz06') return 1;
  4361. // if (typeof cnt[prop] === 'function') {
  4362. // if (!target.funcs.has(prop)) {
  4363. // console.warn(`proxy get to function | prop: ${prop} | is: ${cnt.is}`);
  4364. // }
  4365. // if (!target[`$$${prop}$$`]) target[`$$${prop}$$`] = fnProxySelf.bind({ prop, ref });
  4366. // return target[`$$${prop}$$`];
  4367. // }
  4368. // return cnt[prop];
  4369. // },
  4370. // set(target, prop, value) {
  4371. // const cnt = kRef(target.ref);
  4372. // if (!cnt) return true;
  4373. // if (typeof value === 'function') {
  4374. // console.warn(`proxy set to function | prop: ${prop} | is: ${cnt.is}`);
  4375. // cnt[prop] = value;
  4376. // return true;
  4377. // }
  4378. // cnt[prop] = value;
  4379. // return true;
  4380. // }
  4381. // };
  4382.  
  4383. // return { tickerFuncPropsFn, proxySelfHandler }
  4384.  
  4385. return {weakWrap}
  4386. })();
  4387.  
  4388.  
  4389.  
  4390. if (document.documentElement && document.head) {
  4391. addCssManaged();
  4392. }
  4393. // console.log(document.body===null)
  4394.  
  4395. const preprocessChatLiveActionsMap = new WeakSet();
  4396.  
  4397. const toLAObj=(aItem)=>{
  4398.  
  4399. if (!aItem || typeof aItem !== 'object') return false;
  4400. const key = firstObjectKey(aItem); // addLiveChatTickerItemAction
  4401. if (!key) return false;
  4402. let obj = aItem[key];
  4403. if (!obj || typeof obj !== 'object') return false;
  4404.  
  4405. if (typeof (obj.item || 0) == 'object' && firstObjectKey(obj) === 'item') {
  4406. obj = obj.item;
  4407. const key = firstObjectKey(obj);
  4408. if (key) {
  4409. obj = obj[key];
  4410. }
  4411. }
  4412.  
  4413. return obj;
  4414.  
  4415. };
  4416.  
  4417. const preprocessChatLiveActions = (arr) =>{
  4418.  
  4419. if(!arr || !arr.length) return arr;
  4420.  
  4421. if(preprocessChatLiveActionsMap.has(arr)) return arr;
  4422. preprocessChatLiveActionsMap.add(arr);
  4423.  
  4424. const ct = Date.now();
  4425.  
  4426. // console.log('preprocessChatLiveActions', arr)
  4427.  
  4428.  
  4429. const mapper = new Map();
  4430.  
  4431. // without delaying. get the time of request
  4432. // (both streaming and replay, but replay relys on progress update so background operation is suppressed)
  4433. for (let j = 0, l = arr.length; j < l; j++) {
  4434. const aItem = arr[j];
  4435.  
  4436. const obj = toLAObj(aItem);
  4437. if(obj === false) continue;
  4438. if (obj.id && !obj.__timestampActionRequest__) {
  4439. // for all item entries
  4440. obj.__timestampActionRequest__ = ct;
  4441. }
  4442.  
  4443. if (obj.id && obj.__timestampActionRequest__ > 0 && obj.durationSec > 0 && obj.fullDurationSec) {
  4444.  
  4445. // console.log(948700, obj , obj.id, (obj.fullDurationSec - obj.durationSec) * 1000)
  4446. const m = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  4447. // obj.__orderTime__ = m;
  4448. mapper.set(aItem, m);
  4449.  
  4450.  
  4451. }
  4452.  
  4453. }
  4454.  
  4455. if (mapper.size > 1) {
  4456.  
  4457. const idxices = [];
  4458.  
  4459. // sort ticker
  4460. let mArr1 = arr.filter((aItem,idx) => {
  4461.  
  4462. if (mapper.has(aItem)) {
  4463. idxices.push(idx);
  4464. return true;
  4465. }
  4466. return false;
  4467.  
  4468. });
  4469.  
  4470.  
  4471. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  4472. return mapper.get(a) - mapper.get(b);
  4473. // low index = oldest = smallest timestamp
  4474. });
  4475.  
  4476.  
  4477.  
  4478. // console.log(948701, arr.slice(0));
  4479. for(let j = 0, l=mArr1.length;j <l;j++){
  4480.  
  4481. const idx = idxices[j];
  4482. // arr[idx] = mArr1[j]
  4483. arr[idx] = mArr2[j];
  4484.  
  4485. // const obj1 = toObj(mArr1[j]);
  4486. // const obj2 = toObj(mArr2[j]);
  4487.  
  4488. // console.log(948705, idx, obj1 , obj1.id, (obj1.fullDurationSec - obj1.durationSec) * 1000, obj1.__orderTime__)
  4489.  
  4490. // console.log(948706, idx, obj2 , obj2.id, (obj2.fullDurationSec - obj2.durationSec) * 1000, obj2.__orderTime__)
  4491.  
  4492. }
  4493.  
  4494. // console.log(948702, arr.slice(0));
  4495. // console.log(948701, arr);
  4496. // arr = arr.map(aItem => {
  4497. // const idx = mArr1.indexOf(aItem);
  4498. // if (idx < 0) return aItem;
  4499. // return mArr2[idx];
  4500. // });
  4501. // console.log(948702, arr);
  4502.  
  4503. // mostly in order, but some not in order
  4504.  
  4505.  
  4506. // eg
  4507.  
  4508. /*
  4509.  
  4510.  
  4511. 948711 68 '1734488590715474'
  4512. 948711 69 '1734488590909853'
  4513. 948711 70 '1734488594763719'
  4514. 948711 71 '1734488602334615' <
  4515. 948711 72 '1734488602267214' <
  4516. 948711 73 '1734488602751771'
  4517. */
  4518.  
  4519. // arr.filter(aItem=>{
  4520.  
  4521. // const p = toObj(aItem);
  4522. // if(p.timestampUsec) return true;
  4523.  
  4524. // }).forEach((aItem,idx)=>{
  4525.  
  4526. // const p = toObj(aItem);
  4527. // console.log(948711, idx, p.timestampUsec);
  4528. // })
  4529.  
  4530. // return arr;
  4531.  
  4532. }
  4533.  
  4534.  
  4535. {
  4536.  
  4537.  
  4538. const mapper = new Map();
  4539.  
  4540.  
  4541. const idxices = [];
  4542.  
  4543. let mArr1 = arr.filter((aItem,idx) => {
  4544.  
  4545. const timestampUsec = +toLAObj(aItem).timestampUsec; // +false.x = NaN
  4546. if(timestampUsec > 0){
  4547. idxices.push(idx);
  4548. mapper.set(aItem, timestampUsec)
  4549. return true;
  4550. }
  4551. return false;
  4552. });
  4553.  
  4554. if(mapper.size > 1){
  4555.  
  4556.  
  4557. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  4558. return mapper.get(a) - mapper.get(b);
  4559. // low index = oldest = smallest timestamp
  4560. });
  4561. // console.log(948701, arr.slice(0));
  4562. for(let j = 0, l=mArr1.length;j <l;j++){
  4563. const idx = idxices[j];
  4564. arr[idx] = mArr2[j];
  4565. // const obj1 = toObj(mArr1[j]);
  4566. // const obj2 = toObj(mArr2[j]);
  4567. // console.log(948711, idx, obj1 === obj2, obj1, obj1.timestampUsec);
  4568. // console.log(948712, idx, obj1 === obj2, obj2, obj2.timestampUsec);
  4569. }
  4570.  
  4571. }
  4572.  
  4573. }
  4574.  
  4575.  
  4576. return arr;
  4577.  
  4578.  
  4579. }
  4580.  
  4581. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  4582. getLCRDummy().then(async (lcrDummy) => {
  4583.  
  4584. const tag = "yt-live-chat-renderer"
  4585. const dummy = lcrDummy;
  4586.  
  4587. const cProto = getProto(dummy);
  4588. if (!cProto || !cProto.attached) {
  4589. console.warn(`proto.attached for ${tag} is unavailable.`);
  4590. return;
  4591. }
  4592.  
  4593. mightFirstCheckOnYtInit();
  4594. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  4595. console.log("[Begin]");
  4596.  
  4597.  
  4598.  
  4599.  
  4600.  
  4601.  
  4602. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  4603.  
  4604. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  4605.  
  4606. const pop078 = function () {
  4607. const r = this.pop78();
  4608.  
  4609. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  4610. for (const action of r.actions) {
  4611.  
  4612. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  4613. if (itemActionKey) {
  4614.  
  4615. const itemAction = action[itemActionKey];
  4616. const item = (itemAction || 0).item;
  4617. if (typeof item === 'object') {
  4618.  
  4619. const rendererKey = firstObjectKey(item);
  4620. if (rendererKey) {
  4621. const renderer = item[rendererKey];
  4622. if (renderer && typeof renderer === 'object') {
  4623. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  4624. renderer.__progressAt__ = playerProgressChangedArg1;
  4625.  
  4626. // console.log(48117006)
  4627. }
  4628.  
  4629. }
  4630.  
  4631. }
  4632. }
  4633. }
  4634. }
  4635. return r;
  4636. }
  4637.  
  4638. const replayQueueProxyHandler = {
  4639. get(target, prop, receiver) {
  4640. if (prop === 'qe3') return 1;
  4641. const v = target[prop];
  4642. if (prop === 'front_') {
  4643. if (v && typeof v.length === 'number') {
  4644. if (!v.pop78) {
  4645. v.pop78 = v.pop;
  4646. v.pop = pop078;
  4647. }
  4648. }
  4649. }
  4650. return v;
  4651. }
  4652. };
  4653.  
  4654. cProto.playerProgressChanged_ = function (a, b, c) {
  4655. // console.log(48117005)
  4656. playerProgressChangedArg1 = a;
  4657. playerProgressChangedArg2 = b;
  4658. playerProgressChangedArg3 = c;
  4659. const replayBuffer_ = this.replayBuffer_;
  4660. if (replayBuffer_) {
  4661. const replayQueue = replayBuffer_.replayQueue
  4662. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  4663. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, replayQueueProxyHandler);
  4664. }
  4665. }
  4666. Promise.resolve().then(updateTickerCurrentTime);
  4667. return this.playerProgressChanged32_.apply(this, arguments);
  4668. };
  4669.  
  4670. }
  4671.  
  4672. console.log("[End]");
  4673. console.groupEnd();
  4674.  
  4675.  
  4676. });
  4677.  
  4678. }
  4679.  
  4680.  
  4681.  
  4682. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  4683.  
  4684.  
  4685. const tag = "yt-live-chat-item-list-renderer"
  4686. const dummy = document.createElement(tag);
  4687.  
  4688. const cProto = getProto(dummy);
  4689. if (!cProto || !cProto.attached) {
  4690. console.warn(`proto.attached for ${tag} is unavailable.`);
  4691. return;
  4692. }
  4693.  
  4694. mightFirstCheckOnYtInit();
  4695. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  4696. console.log("[Begin]");
  4697.  
  4698. const mclp = cProto;
  4699. const _flag0281_ = window._flag0281_ || mclp._flag0281_;
  4700.  
  4701. try {
  4702. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  4703. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  4704. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  4705. assertor(() => typeof mclp.setAtBottom === 'function');
  4706. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  4707. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  4708. } catch (e) { }
  4709.  
  4710.  
  4711. try {
  4712. assertor(() => typeof mclp.attached === 'function');
  4713. assertor(() => typeof mclp.detached === 'function');
  4714. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  4715. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  4716. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  4717. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  4718. assertor(() => typeof mclp.smoothScroll_ === 'function');
  4719. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  4720. } catch (e) { }
  4721.  
  4722. mclp.__intermediate_delay__ = null;
  4723.  
  4724. let myk = 0;
  4725. let mlf = 0;
  4726. let myw = 0;
  4727. let mzt = 0;
  4728. let zarr = null;
  4729. let mlg = 0;
  4730.  
  4731. if ((_flag0281_ & 0x2000) == 0) {
  4732.  
  4733. if ((mclp.clearList || 0).length === 0) {
  4734. (_flag0281_ & 0x2) == 0 && assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  4735. mclp.clearList66 = mclp.clearList;
  4736. mclp.clearList = function () {
  4737. myk++;
  4738. mlf++;
  4739. myw++;
  4740. mzt++;
  4741. mlg++;
  4742. zarr = null;
  4743. this.__intermediate_delay__ = null;
  4744. this.clearList66();
  4745. };
  4746. console.log("clearList", "OK");
  4747. } else {
  4748. console.log("clearList", "NG");
  4749. }
  4750.  
  4751. }
  4752.  
  4753.  
  4754.  
  4755. let onListRendererAttachedDone = false;
  4756.  
  4757. function setList(itemOffset, items) {
  4758.  
  4759. const isFirstTime = onListRendererAttachedDone === false;
  4760.  
  4761. if (isFirstTime) {
  4762. onListRendererAttachedDone = true;
  4763. Promise.resolve().then(watchUserCSS);
  4764. addCssManaged();
  4765. setupEvents();
  4766. }
  4767.  
  4768. setupStyle(itemOffset, items);
  4769.  
  4770. setupMutObserver(items);
  4771. }
  4772.  
  4773. mclp.attached419 = async function () {
  4774.  
  4775. if (!this.isAttached) return;
  4776.  
  4777. let maxTrial = 16;
  4778. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  4779. if (--maxTrial < 0 || !this.isAttached) return;
  4780. await iAFP(this.hostElement).then();
  4781. // await new Promise(requestAnimationFrame);
  4782. }
  4783.  
  4784. if (this.isAttached !== true) return;
  4785.  
  4786. if (!this.$) {
  4787. console.warn("!this.$");
  4788. return;
  4789. }
  4790. if (!this.$) return;
  4791. /** @type {HTMLElement | null} */
  4792. const itemScroller = this.$['item-scroller'];
  4793. /** @type {HTMLElement | null} */
  4794. const itemOffset = this.$['item-offset'];
  4795. /** @type {HTMLElement | null} */
  4796. const items = this.$['items'];
  4797.  
  4798. if (!itemScroller || !itemOffset || !items) {
  4799. console.warn("items.parentNode !== itemOffset");
  4800. return;
  4801. }
  4802.  
  4803. if (nodeParent(items) !== itemOffset) {
  4804.  
  4805. console.warn("items.parentNode !== itemOffset");
  4806. return;
  4807. }
  4808.  
  4809.  
  4810. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  4811.  
  4812. console.warn("id incorrect");
  4813. return;
  4814. }
  4815.  
  4816. 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')
  4817.  
  4818. if (!isTargetItems) {
  4819. console.warn("!isTargetItems");
  4820. return;
  4821. }
  4822.  
  4823. setList(itemOffset, items);
  4824.  
  4825. }
  4826.  
  4827. mclp.attached331 = mclp.attached;
  4828. mclp.attached = function () {
  4829. this.attached419 && this.attached419();
  4830. return this.attached331();
  4831. }
  4832.  
  4833. mclp.detached331 = mclp.detached;
  4834.  
  4835. mclp.detached = function () {
  4836. setupMutObserver();
  4837. return this.detached331();
  4838. }
  4839.  
  4840. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  4841. for (const t29 of t29s) {
  4842. if (insp(t29).isAttached === true) {
  4843. t29.attached419();
  4844. }
  4845. }
  4846.  
  4847. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  4848.  
  4849. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  4850. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  4851.  
  4852. /** @type {Map<number, any>} */
  4853. const aMap = new Map();
  4854. let count = 6150;
  4855. mclp.async66 = mclp.async;
  4856. mclp.async = function (e, f) {
  4857. // ensure the previous operation is done
  4858. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  4859. const hasF = arguments.length === 2;
  4860. const stack = new Error().stack;
  4861. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  4862. if (count > 1e9) count = 6159;
  4863. const resId = ++count;
  4864. aMap.set(resId, e);
  4865. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  4866. const rp = aMap.get(resId);
  4867. if (typeof rp !== 'function') {
  4868. return;
  4869. }
  4870. let cancelCall = false;
  4871. if (isFlushAsync) {
  4872. if (rk < 0) {
  4873. cancelCall = true;
  4874. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  4875. cancelCall = true;
  4876. }
  4877. }
  4878. if (cancelCall) {
  4879. aMap.delete(resId);
  4880. } else {
  4881. const asyncEn = function () {
  4882. aMap.delete(resId);
  4883. return rp.apply(this, arguments);
  4884. };
  4885. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  4886. }
  4887. });
  4888.  
  4889. return resId;
  4890. }
  4891.  
  4892. mclp.cancelAsync66 = mclp.cancelAsync;
  4893. mclp.cancelAsync = function (resId) {
  4894. if (resId <= 6150) {
  4895. this.cancelAsync66(resId);
  4896. } else if (aMap.has(resId)) {
  4897. const rp = aMap.get(resId);
  4898. aMap.delete(resId);
  4899. if (typeof rp !== 'function') {
  4900. this.cancelAsync66(rp);
  4901. }
  4902. }
  4903. }
  4904.  
  4905. console.log("async", "OK");
  4906. } else {
  4907. console.log("async", "NG");
  4908. }
  4909.  
  4910.  
  4911. if ((_flag0281_ & 0x2) == 0) {
  4912. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  4913.  
  4914. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  4915. mclp.showNewItems66_ = mclp.showNewItems_;
  4916.  
  4917. mclp.showNewItems77_ = async function () {
  4918. if (myk > 1e9) myk = 9;
  4919. let tid = ++myk;
  4920.  
  4921. await iAFP(this.hostElement).then();
  4922. // await new Promise(requestAnimationFrame);
  4923.  
  4924. if (tid !== myk) {
  4925. return;
  4926. }
  4927.  
  4928. const cnt = this;
  4929.  
  4930. await Promise.resolve();
  4931. cnt.showNewItems66_();
  4932.  
  4933. await Promise.resolve();
  4934.  
  4935. }
  4936.  
  4937. mclp.showNewItems_ = function () {
  4938.  
  4939. const cnt = this;
  4940. cnt.__intermediate_delay__ = new Promise(resolve => {
  4941. cnt.showNewItems77_().then(() => {
  4942. resolve();
  4943. });
  4944. });
  4945. }
  4946.  
  4947. console.log("showNewItems_", "OK");
  4948. } else {
  4949. console.log("showNewItems_", "NG");
  4950. }
  4951.  
  4952. }
  4953.  
  4954. if ((_flag0281_ & 0x2000) == 0) {
  4955. if ((mclp.flushActiveItems_ || 0).length === 0) {
  4956.  
  4957. if ((_flag0281_ & 0x2) == 0) {
  4958.  
  4959. const sfi = fnIntegrity(mclp.flushActiveItems_);
  4960. if (sfi === '0.156.86') {
  4961. // https://www.youtube.com/s/desktop/f61c8d85/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4962.  
  4963. // added "refreshOffsetContainerHeight_"
  4964.  
  4965. // f.flushActiveItems_ = function() {
  4966. // var a = this;
  4967. // if (0 < this.activeItems_.length)
  4968. // if (this.canScrollToBottom_()) {
  4969. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  4970. // b && this.splice("visibleItems", 0, b);
  4971. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  4972. // this.preinsertHeight_ = this.items.clientHeight;
  4973. // this.activeItems_.unshift("visibleItems");
  4974. // try {
  4975. // this.push.apply(this, this.activeItems_)
  4976. // } catch (c) {
  4977. // fm(c)
  4978. // }
  4979. // this.activeItems_ = [];
  4980. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && Mw(function() {
  4981. // a.showNewItems_()
  4982. // }) : Mw(function() {
  4983. // a.refreshOffsetContainerHeight_();
  4984. // a.maybeScrollToBottom_()
  4985. // })
  4986. // } else
  4987. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  4988. // }
  4989. // ;
  4990.  
  4991. } else if (sfi === '0.150.84') {
  4992. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4993. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  4994. // b && this.splice("visibleItems", 0, b);
  4995. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  4996. // this.preinsertHeight_ = this.items.clientHeight;
  4997. // this.activeItems_.unshift("visibleItems");
  4998. // try {
  4999. // this.push.apply(this, this.activeItems_)
  5000. // } catch (c) {
  5001. // nm(c)
  5002. // }
  5003. // this.activeItems_ = [];
  5004. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && zQ(function() {
  5005. // a.showNewItems_()
  5006. // }) : zQ(function() {
  5007. // a.maybeScrollToBottom_()
  5008. // })
  5009. } else if (sfi === '0.137.81' || sfi === '0.138.81') {
  5010. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  5011. } else {
  5012. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.150.84'));
  5013. }
  5014. }
  5015.  
  5016. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  5017.  
  5018. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  5019.  
  5020.  
  5021. const preloadFn = (acItems) => {
  5022. let waitFor = [];
  5023. /** @type {Set<string>} */
  5024. const imageLinks = new Set();
  5025.  
  5026. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  5027. for (const item of acItems) {
  5028. fixLiveChatItem(item, imageLinks);
  5029. }
  5030. }
  5031. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  5032.  
  5033. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  5034. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  5035. // preload performs the high priority fetching.
  5036. // prefetch delays the chat display if the video resoruce is demanding.
  5037.  
  5038. if (rel) {
  5039.  
  5040. imageLinks.forEach(imageLink => {
  5041. let d = false;
  5042. if (SKIP_PRELOAD_EMOJI && imageLink.includes('.ggpht.com/')) return;
  5043. const isEmoji = imageLink.includes('/emoji/');
  5044. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  5045. if (!pretechedSet.has(imageLink)) {
  5046. pretechedSet.add(imageLink);
  5047. d = true;
  5048. }
  5049. if (d) {
  5050. waitFor.push(linker(null, rel, imageLink, 'image'));
  5051.  
  5052. }
  5053. })
  5054.  
  5055. }
  5056.  
  5057. }
  5058.  
  5059. return async () => {
  5060. if (waitFor.length > 0) {
  5061. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  5062. }
  5063. waitFor.length = 0;
  5064. waitFor = null;
  5065. };
  5066.  
  5067. };
  5068.  
  5069. mclp.flushActiveItems78_ = async function (tid) {
  5070. try {
  5071.  
  5072. if (tid !== mlf) return;
  5073. if ((this._flag0281_ & 0x4) == 0x4) {
  5074. const cnt = this;
  5075.  
  5076. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5077. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  5078.  
  5079. mlf++;
  5080. if (mlg > 1e9) mlg = 9;
  5081. ++mlg;
  5082. const acItems = cnt.activeItems_;
  5083. if (acItems.length < MAX_ITEMS_FOR_FULL_FLUSH) {
  5084. const pn = preloadFn(acItems);
  5085. await pn();
  5086. }
  5087. cnt.flushActiveItems66_();
  5088.  
  5089. return 1;
  5090.  
  5091. }
  5092. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  5093. let logger = false;
  5094. const cnt = this;
  5095. let immd = cnt.__intermediate_delay__;
  5096. await iAFP(this.hostElement).then();
  5097. // await new Promise(requestAnimationFrame);
  5098.  
  5099. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5100. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  5101.  
  5102. mlf++;
  5103. if (mlg > 1e9) mlg = 9;
  5104. ++mlg;
  5105.  
  5106. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  5107. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  5108. let changeMaxItemsToDisplay = false;
  5109. const activeItemsLen = this.activeItems_.length;
  5110. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  5111. logger = true;
  5112.  
  5113. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  5114.  
  5115. logger && console.log('[Begin]')
  5116.  
  5117. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  5118. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  5119. console.log('reduce maxitems');
  5120. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  5121. // as all the rendered chats are already "outdated"
  5122. // all old chats shall remove and reduced number of few chats will be rendered
  5123. // then restore to the original number
  5124. changeMaxItemsToDisplay = true;
  5125. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  5126. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  5127. }
  5128. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  5129. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  5130.  
  5131. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  5132. } else {
  5133. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  5134.  
  5135. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  5136. }
  5137. }
  5138. // it is found that it will render all stacked chats after switching back from background
  5139. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  5140. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  5141.  
  5142. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  5143. await Promise.resolve();
  5144. const acItems = cnt.activeItems_;
  5145. const len1 = acItems.length;
  5146. if (!len1) console.warn('cnt.activeItems_.length = 0');
  5147.  
  5148. const pn = preloadFn(acItems);
  5149. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  5150. skipDontRender = noVisibleItem1;
  5151. await pn();
  5152. // console.log('ss2', Date.now())
  5153. cnt.flushActiveItems66_();
  5154. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  5155. skipDontRender = noVisibleItem2;
  5156. await Promise.resolve();
  5157. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  5158. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  5159.  
  5160. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  5161. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  5162. } else if (changeMaxItemsToDisplay) {
  5163.  
  5164. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  5165. maxItemsToDisplay: this.data.maxItemsToDisplay,
  5166. reducedMaxItemsToDisplay,
  5167. originalMaxItemsToDisplay: tmpMaxItemsCount
  5168. });
  5169. }
  5170. logger && console.log('[End]');
  5171.  
  5172. logger && console.groupEnd();
  5173.  
  5174. if (noVisibleItem1 && !noVisibleItem2) {
  5175. // fix possible no auto scroll issue.
  5176. !((cnt.__notRequired__ || 0) & 256) && setTimeout(() => cnt.setAtBottom(), 1);
  5177. }
  5178.  
  5179. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  5180.  
  5181.  
  5182. const ff = () => {
  5183.  
  5184. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5185. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5186. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  5187.  
  5188. if (typeof nextBrowserTick !== 'function') {
  5189. cnt.scrollToBottom_();
  5190. Promise.resolve().then(() => {
  5191. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5192. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  5193. });
  5194. } else {
  5195. nextBrowserTick(() => {
  5196. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5197. cnt.scrollToBottom_();
  5198. });
  5199. }
  5200.  
  5201. }
  5202. }
  5203.  
  5204. ff();
  5205.  
  5206.  
  5207. Promise.resolve().then(ff);
  5208.  
  5209. // requestAnimationFrame(ff);
  5210. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  5211.  
  5212. const knt = cnt;
  5213. if (!scrollChatFn) {
  5214. const cnt = knt;
  5215. const f = () => {
  5216. const itemScroller = cnt.itemScroller;
  5217. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  5218. if (!cnt.atBottom) {
  5219. cnt.scrollToBottom_();
  5220. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  5221. itemScroller.scrollTop = itemScroller.scrollHeight;
  5222. }
  5223. };
  5224. if (typeof nextBrowserTick !== 'function') {
  5225. scrollChatFn = () => Promise.resolve().then(f).then(f);
  5226. } else {
  5227. scrollChatFn = () => nextBrowserTick(f);
  5228. }
  5229. }
  5230.  
  5231. scrollChatFn();
  5232. }
  5233.  
  5234. return 1;
  5235.  
  5236.  
  5237. } catch (e) {
  5238. console.warn(e);
  5239. }
  5240. }
  5241.  
  5242. mclp.flushActiveItems77_ = function () {
  5243.  
  5244. return new Promise(resResolve => {
  5245. try {
  5246. const cnt = this;
  5247. if (mlf > 1e9) mlf = 9;
  5248. let tid = ++mlf;
  5249. const hostElement = cnt.hostElement || cnt;
  5250. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  5251. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  5252.  
  5253. // 4 times to maxItems to avoid frequent trimming.
  5254. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  5255.  
  5256. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  5257. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  5258. if (cnt.canScrollToBottom_()) {
  5259. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  5260. .then(() => cnt.flushActiveItems78_(tid)) // async function
  5261. .then((asyncResult) => {
  5262. resResolve(asyncResult); // either undefined or 1
  5263. resResolve = null;
  5264. }).catch((e) => {
  5265. console.warn(e);
  5266. if (resResolve) resResolve();
  5267. });
  5268. } else {
  5269. resResolve(2);
  5270. resResolve = null;
  5271. }
  5272. } catch (e) {
  5273. console.warn(e);
  5274. if (resResolve) resResolve();
  5275. }
  5276.  
  5277.  
  5278. });
  5279.  
  5280. }
  5281.  
  5282. mclp.flushActiveItems_ = function () {
  5283. const cnt = this;
  5284.  
  5285. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  5286.  
  5287. if (cnt.activeItems_.length === 0) {
  5288. cnt.__intermediate_delay__ = null;
  5289. return;
  5290. }
  5291.  
  5292. const cntData = ((cnt || 0).data || 0);
  5293. if (cntData.maxItemsToDisplay944 === undefined) {
  5294. cntData.maxItemsToDisplay944 = null;
  5295. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  5296. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  5297. }
  5298.  
  5299. // ignore previous __intermediate_delay__ and create a new one
  5300. cnt.__intermediate_delay__ = new Promise(resolve => {
  5301. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  5302. if (rt === 1) {
  5303. resolve(1); // success, scroll to bottom
  5304. if (hasMoreMessageState === 1) {
  5305. hasMoreMessageState = 0;
  5306. const showMore = (cnt.$ || 0)['show-more'];
  5307. if (showMore) {
  5308. showMore.classList.remove('has-new-messages-miuzp');
  5309. }
  5310. }
  5311. }
  5312. else if (rt === 2) {
  5313. resolve(2); // success, trim
  5314. if (hasMoreMessageState === 0) {
  5315. hasMoreMessageState = 1;
  5316. const showMore = cnt.$['show-more'];
  5317. if (showMore) {
  5318. showMore.classList.add('has-new-messages-miuzp');
  5319. }
  5320. }
  5321. }
  5322. else resolve(-1); // skip
  5323. }).catch(e => {
  5324. console.warn(e);
  5325. });
  5326. });
  5327.  
  5328. }
  5329. console.log("flushActiveItems_", "OK");
  5330. } else {
  5331. console.log("flushActiveItems_", "NG");
  5332. }
  5333. }
  5334.  
  5335. if ((_flag0281_ & 0x40) == 0) {
  5336.  
  5337. if (ENABLE_NO_SMOOTH_TRANSFORM && SUPPRESS_refreshOffsetContainerHeight_ && typeof mclp.refreshOffsetContainerHeight_ === 'function' && !mclp.refreshOffsetContainerHeight26_ && mclp.refreshOffsetContainerHeight_.length === 0) {
  5338. assertor(() => fnIntegrity(mclp.refreshOffsetContainerHeight_, '0.31.21'));
  5339. mclp.refreshOffsetContainerHeight26_ = mclp.refreshOffsetContainerHeight_;
  5340. mclp.refreshOffsetContainerHeight_ = function () {
  5341. // var a = this.itemScroller.clientHeight;
  5342. // this.itemOffset.style.height = this.items.clientHeight + "px";
  5343. // this.bottomAlignMessages && (this.itemOffset.style.minHeight = a + "px")
  5344. }
  5345. console.log("refreshOffsetContainerHeight_", "OK");
  5346. } else {
  5347. console.log("refreshOffsetContainerHeight_", "NG");
  5348. }
  5349.  
  5350. }
  5351.  
  5352. if ((_flag0281_ & 0x80) == 0) {
  5353. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  5354. try {
  5355. if (mlg > 1e9) mlg = 9;
  5356. const tid = ++mlg;
  5357. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  5358. const runCond = () => this.canScrollToBottom_();
  5359. if (!keepTrialCond()) return;
  5360. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  5361. await new Promise(r => setTimeout(r, 80));
  5362. if (!keepTrialCond()) return;
  5363. if (runCond()) return this.flushActiveItems_() | 1;
  5364. await iAFP(this.hostElement).then();
  5365. // await new Promise(requestAnimationFrame);
  5366. if (runCond()) return this.flushActiveItems_() | 1;
  5367. } catch (e) {
  5368. console.warn(e);
  5369. }
  5370. }
  5371. }
  5372.  
  5373. if ((_flag0281_ & 0x40) == 0 ) {
  5374.  
  5375. if( (mclp.atBottomChanged_ || 0).length === 0) {
  5376. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  5377.  
  5378.  
  5379.  
  5380.  
  5381.  
  5382. const sfi = fnIntegrity(mclp.atBottomChanged_);
  5383.  
  5384. if(sfi === '0.75.37'){
  5385. // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  5386.  
  5387.  
  5388. // Dec 2024.
  5389.  
  5390. /**
  5391. *
  5392. *
  5393. f.atBottomChanged_ = function() {
  5394. var a = this;
  5395. this.atBottom ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = Zu(function() {
  5396. R(a.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5397. }, 200)) : (this.hideShowMoreAsync_ && $u(this.hideShowMoreAsync_),
  5398. this.hideShowMoreAsync_ = null,
  5399. R(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5400. }
  5401. *
  5402. */
  5403.  
  5404. } else {
  5405. assertor(() => fnIntegrity(mclp.atBottomChanged_, '0.75.37'));
  5406. }
  5407.  
  5408.  
  5409. const querySelector = HTMLElement.prototype.querySelector;
  5410. const U = (element) => ({
  5411. querySelector: (selector) => querySelector.call(element, selector)
  5412. });
  5413.  
  5414. let qid = 0;
  5415. mclp.__updateButtonVisibility371__ = function (button) {
  5416. Promise.resolve(this).then((cnt) => {
  5417. button.style.visibility = cnt.__buttonVisibility371__;
  5418. });
  5419. }
  5420. const fixButtonOnClick = function (cnt, button) {
  5421. button.addEventListener('click', (evt) => {
  5422. evt.stopImmediatePropagation();
  5423. evt.stopPropagation();
  5424. evt.preventDefault();
  5425. Promise.resolve(cnt).then((cnt) => {
  5426. cnt.scrollToBottom_();
  5427. });
  5428. }, true);
  5429. // button.addEventListener('pointerup', (evt)=>{
  5430. // evt.stopImmediatePropagation();
  5431. // evt.stopPropagation();
  5432. // }, true);
  5433. // button.addEventListener('mouseup', (evt)=>{
  5434. // evt.stopImmediatePropagation();
  5435. // evt.stopPropagation();
  5436. // }, true);
  5437. }
  5438. mclp.atBottomChanged_ = function () {
  5439. let a = this.atBottom;
  5440. const button = (this.$ || 0)['show-more'];
  5441. if (button) {
  5442. // primary execution
  5443. if (a) {
  5444. if (this.__buttonVisibility371__ !== "hidden") {
  5445. this.__buttonVisibility371__ = "hidden";
  5446. if (!this.hideShowMoreAsync_) {
  5447. const tid = ++qid;
  5448. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  5449. if (tid !== qid) {
  5450. return;
  5451. }
  5452. this.__updateButtonVisibility371__(button);
  5453. });
  5454. }
  5455. }
  5456. } else {
  5457. if (this.__buttonVisibility371__ !== "visible") {
  5458. this.__buttonVisibility371__ = "visible";
  5459. if (this.hideShowMoreAsync_) {
  5460. qid++;
  5461. }
  5462. this.hideShowMoreAsync_ = null;
  5463. if (!button.__fix_onclick__) {
  5464. button.__fix_onclick__ = true;
  5465. fixButtonOnClick(this, button);
  5466. }
  5467. this.__updateButtonVisibility371__(button);
  5468. }
  5469. }
  5470. } else {
  5471. // fallback
  5472. let tid = ++qid;
  5473. let b = this;
  5474. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  5475. if (tid !== qid) return;
  5476. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5477. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  5478. this.hideShowMoreAsync_ = null,
  5479. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5480. }
  5481. }
  5482.  
  5483. console.log("atBottomChanged_", "OK");
  5484.  
  5485. } else if ((mclp.atBottomChanged_ || 0).length === 1) {
  5486. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  5487.  
  5488. const sfi = fnIntegrity(mclp.atBottomChanged_);
  5489. if (sfi === '1.73.37') {
  5490. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  5491.  
  5492. /**
  5493. *
  5494. *
  5495. *
  5496. f.atBottomChanged_ = function(a) {
  5497. var b = this;
  5498. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = zQ(function() {
  5499. T(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5500. }, 200)) : (this.hideShowMoreAsync_ && AQ(this.hideShowMoreAsync_),
  5501. this.hideShowMoreAsync_ = null,
  5502. T(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5503. };
  5504.  
  5505. *
  5506. *
  5507. */
  5508.  
  5509.  
  5510. } else if (sfi === '1.75.39') {
  5511. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  5512. } else {
  5513. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.73.37'));
  5514. }
  5515.  
  5516. const querySelector = HTMLElement.prototype.querySelector;
  5517. const U = (element) => ({
  5518. querySelector: (selector) => querySelector.call(element, selector)
  5519. });
  5520.  
  5521. let qid = 0;
  5522. mclp.__updateButtonVisibility371__ = function (button) {
  5523. Promise.resolve(this).then((cnt) => {
  5524. button.style.visibility = cnt.__buttonVisibility371__;
  5525. });
  5526. }
  5527. const fixButtonOnClick = function (cnt, button) {
  5528. button.addEventListener('click', (evt) => {
  5529. evt.stopImmediatePropagation();
  5530. evt.stopPropagation();
  5531. evt.preventDefault();
  5532. Promise.resolve(cnt).then((cnt) => {
  5533. cnt.scrollToBottom_();
  5534. });
  5535. }, true);
  5536. // button.addEventListener('pointerup', (evt)=>{
  5537. // evt.stopImmediatePropagation();
  5538. // evt.stopPropagation();
  5539. // }, true);
  5540. // button.addEventListener('mouseup', (evt)=>{
  5541. // evt.stopImmediatePropagation();
  5542. // evt.stopPropagation();
  5543. // }, true);
  5544. }
  5545. mclp.atBottomChanged_ = function (a) {
  5546. const button = (this.$ || 0)['show-more'];
  5547. if (button) {
  5548. // primary execution
  5549. if (a) {
  5550. if (this.__buttonVisibility371__ !== "hidden") {
  5551. this.__buttonVisibility371__ = "hidden";
  5552. if (!this.hideShowMoreAsync_) {
  5553. const tid = ++qid;
  5554. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  5555. if (tid !== qid) {
  5556. return;
  5557. }
  5558. this.__updateButtonVisibility371__(button);
  5559. });
  5560. }
  5561. }
  5562. } else {
  5563. if (this.__buttonVisibility371__ !== "visible") {
  5564. this.__buttonVisibility371__ = "visible";
  5565. if (this.hideShowMoreAsync_) {
  5566. qid++;
  5567. }
  5568. this.hideShowMoreAsync_ = null;
  5569. if (!button.__fix_onclick__) {
  5570. button.__fix_onclick__ = true;
  5571. fixButtonOnClick(this, button);
  5572. }
  5573. this.__updateButtonVisibility371__(button);
  5574. }
  5575. }
  5576. } else {
  5577. // fallback
  5578. let tid = ++qid;
  5579. let b = this;
  5580. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  5581. if (tid !== qid) return;
  5582. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5583. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  5584. this.hideShowMoreAsync_ = null,
  5585. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5586. }
  5587. }
  5588.  
  5589. console.log("atBottomChanged_", "OK");
  5590. } else {
  5591. console.log("atBottomChanged_", "NG");
  5592. }
  5593. }
  5594.  
  5595.  
  5596. if ((_flag0281_ & 0x2) == 0) {
  5597. if ((mclp.onScrollItems_ || 0).length === 1) {
  5598.  
  5599. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  5600. mclp.onScrollItems66_ = mclp.onScrollItems_;
  5601. mclp.onScrollItems77_ = async function (evt) {
  5602. if (myw > 1e9) myw = 9;
  5603. let tid = ++myw;
  5604.  
  5605. await iAFP(this.hostElement).then();
  5606. // await new Promise(requestAnimationFrame);
  5607.  
  5608. if (tid !== myw) {
  5609. return;
  5610. }
  5611.  
  5612. const cnt = this;
  5613.  
  5614. await Promise.resolve();
  5615. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  5616. const onScrollItemsBasicOnly_ = !!((cnt.__notRequired__ || 0) & 512);
  5617. await Promise.resolve().then(() => {
  5618. this.ytRendererBehavior.onScroll(evt);
  5619. }).then(() => {
  5620. if (onScrollItemsBasicOnly_) return;
  5621. if (this.canScrollToBottom_()) {
  5622. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  5623. if (hasUserJustInteracted) {
  5624. // only when there is an user action
  5625. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  5626. return 1;
  5627. }
  5628. } else {
  5629. // no message inserting
  5630. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  5631. return 1;
  5632. }
  5633. }).then((r) => {
  5634.  
  5635. if (onScrollItemsBasicOnly_) return;
  5636. if (this.activeItems_.length) {
  5637.  
  5638. if (this.canScrollToBottom_()) {
  5639. this.flushActiveItems_();
  5640. return 1 && r;
  5641. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  5642. // delayed due to user action
  5643. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  5644. return 0;
  5645. }
  5646. }
  5647. }).then((r) => {
  5648. if (onScrollItemsBasicOnly_) return;
  5649. if (r) {
  5650. // ensure setAtBottom is correctly set
  5651. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  5652. }
  5653. });
  5654. } else {
  5655. cnt.onScrollItems66_(evt);
  5656. }
  5657.  
  5658. await Promise.resolve();
  5659.  
  5660. }
  5661.  
  5662. mclp.onScrollItems_ = function (evt) {
  5663.  
  5664. const cnt = this;
  5665. cnt.__intermediate_delay__ = new Promise(resolve => {
  5666. cnt.onScrollItems77_(evt).then(() => {
  5667. resolve();
  5668. });
  5669. });
  5670. }
  5671. console.log("onScrollItems_", "OK");
  5672. } else {
  5673. console.log("onScrollItems_", "NG");
  5674. }
  5675. }
  5676.  
  5677. if ((_flag0281_ & 0x2) == 0) {
  5678. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  5679.  
  5680. const sfi = fnIntegrity(mclp.handleLiveChatActions_);
  5681. if (sfi === '1.39.20') {
  5682. // TBC
  5683. } else if (sfi === '1.31.17') {
  5684. // original
  5685. } else {
  5686. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  5687. }
  5688.  
  5689. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  5690.  
  5691. mclp.handleLiveChatActions77_ = async function (arr) {
  5692. if (typeof (arr || 0).length !== 'number') {
  5693. this.handleLiveChatActions66_(arr);
  5694. return;
  5695. }
  5696. if (mzt > 1e9) mzt = 9;
  5697. let tid = ++mzt;
  5698.  
  5699. if (zarr === null) zarr = arr;
  5700. else Array.prototype.push.apply(zarr, arr);
  5701. arr = null;
  5702.  
  5703. await iAFP(this.hostElement).then();
  5704. // await new Promise(requestAnimationFrame);
  5705.  
  5706. if (tid !== mzt || zarr === null) {
  5707. return;
  5708. }
  5709.  
  5710. const carr = zarr;
  5711. zarr = null;
  5712.  
  5713. await Promise.resolve();
  5714. this.handleLiveChatActions66_(carr);
  5715. await Promise.resolve();
  5716.  
  5717. }
  5718.  
  5719. mclp.handleLiveChatActions_ = function (arr) {
  5720.  
  5721.  
  5722. preprocessChatLiveActions(arr);
  5723.  
  5724.  
  5725.  
  5726. // console.log(1929, cnt.activeItems_)
  5727. // console.log(9487, arr);
  5728.  
  5729. const cnt = this;
  5730. cnt.__intermediate_delay__ = new Promise(resolve => {
  5731. cnt.handleLiveChatActions77_(arr).then(() => {
  5732. resolve();
  5733. });
  5734. });
  5735.  
  5736. resistanceUpdateFn_();
  5737. }
  5738. console.log("handleLiveChatActions_", "OK");
  5739. } else {
  5740. console.log("handleLiveChatActions_", "NG");
  5741. }
  5742. }
  5743.  
  5744. mclp.hasUserJustInteracted11_ = () => {
  5745. const t = dateNow();
  5746. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  5747. }
  5748.  
  5749. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  5750.  
  5751. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  5752.  
  5753. mclp.canScrollToBottom_ = function () {
  5754. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  5755. }
  5756.  
  5757. console.log("canScrollToBottom_", "OK");
  5758. } else {
  5759. console.log("canScrollToBottom_", "NG");
  5760. }
  5761.  
  5762. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  5763.  
  5764. mclp.isSmoothScrollEnabled_ = function () {
  5765. return false;
  5766. }
  5767.  
  5768. mclp.maybeResizeScrollContainer_ = function () {
  5769. //
  5770. }
  5771.  
  5772. mclp.refreshOffsetContainerHeight_ = function () {
  5773. //
  5774. }
  5775.  
  5776. mclp.smoothScroll_ = function () {
  5777. //
  5778. }
  5779.  
  5780. mclp.resetSmoothScroll_ = function () {
  5781. //
  5782. }
  5783. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  5784. } else {
  5785. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  5786. }
  5787.  
  5788. if ((_flag0281_ & 0x8) == 0) {
  5789.  
  5790.  
  5791. if (typeof mclp.forEachItem_ === 'function' && !mclp.forEachItem66_ && skipErrorForhandleAddChatItemAction_ && mclp.forEachItem_.length === 1) {
  5792.  
  5793. mclp.forEachItem66_ = mclp.forEachItem_;
  5794. mclp.forEachItem_ = function (a) {
  5795.  
  5796. if ((this._flag0281_ & 0x8) == 0x8) return this.forEachItem66_(a);
  5797.  
  5798. // ƒ (a){this.visibleItems.forEach(a.bind(this,"visibleItems"));this.activeItems_.forEach(a.bind(this,"activeItems_"))}
  5799.  
  5800. try {
  5801.  
  5802. let items801 = false;
  5803. if (typeof a === 'function') {
  5804. const items = this.items;
  5805. if (items instanceof HTMLDivElement) {
  5806. const ev = this.visibleItems;
  5807. const ea = this.activeItems_;
  5808. if (ev && ea && ev.length >= 0 && ea.length >= 0) {
  5809. items801 = items;
  5810. }
  5811. }
  5812. }
  5813.  
  5814. if (items801) {
  5815. items801.__children801__ = 1;
  5816. const res = this.forEachItem66_(a);
  5817. items801.__children801__ = 0;
  5818. return res;
  5819. }
  5820.  
  5821. } catch (e) { }
  5822. return this.forEachItem66_(a);
  5823.  
  5824.  
  5825. // this.visibleItems.forEach((val, idx, arr)=>{
  5826. // a.call(this, 'visibleItems', val, idx, arr);
  5827. // });
  5828.  
  5829. // this.activeItems_.forEach((val, idx, arr)=>{
  5830. // a.call(this, 'activeItems_', val, idx, arr);
  5831. // });
  5832.  
  5833.  
  5834.  
  5835. }
  5836.  
  5837.  
  5838. }
  5839.  
  5840. }
  5841.  
  5842. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  5843.  
  5844. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  5845. mclp.handleAddChatItemAction_ = function (a) {
  5846. try {
  5847. if (a && typeof a === 'object' && !('length' in a)) {
  5848. fixLiveChatItem(a.item, null);
  5849. console.assert(arguments[0] === a);
  5850. }
  5851. } catch (e) { console.warn(e) }
  5852. let res;
  5853. if (skipErrorForhandleAddChatItemAction_) { // YouTube Native Engine Issue
  5854. try {
  5855. res = this.handleAddChatItemAction66_.apply(this, arguments);
  5856. } catch (e) {
  5857. if (e && (e.message || '').includes('.querySelector(')) {
  5858. console.log("skipErrorForhandleAddChatItemAction_", e.message);
  5859. } else {
  5860. throw e;
  5861. }
  5862. }
  5863. } else {
  5864. res = this.handleAddChatItemAction66_.apply(this, arguments);
  5865. }
  5866. return res;
  5867. }
  5868.  
  5869. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  5870. } else {
  5871.  
  5872. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  5873. }
  5874.  
  5875.  
  5876. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  5877.  
  5878. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  5879. mclp.handleReplaceChatItemAction_ = function (a) {
  5880. try {
  5881. if (a && typeof a === 'object' && !('length' in a)) {
  5882. fixLiveChatItem(a.replacementItem, null);
  5883. console.assert(arguments[0] === a);
  5884. }
  5885. } catch (e) { console.warn(e) }
  5886. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  5887. }
  5888.  
  5889. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  5890. } else {
  5891.  
  5892. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  5893. }
  5894.  
  5895. console.log("[End]");
  5896. console.groupEnd();
  5897.  
  5898. }).catch(console.warn);
  5899.  
  5900.  
  5901. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  5902.  
  5903. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  5904.  
  5905. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  5906.  
  5907. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  5908. let v = `${attrValue}`;
  5909. // conside a ticker is 101px width
  5910. // 1% = 1.01px
  5911. // 0.2% = 0.202px
  5912.  
  5913.  
  5914. const ratio1 = (yd.ratio * 100);
  5915. if (ratio1 > -1) { // avoid NaN
  5916.  
  5917. // countdownDurationMs
  5918. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  5919. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  5920. // 150000 - 1% <1% = 1.5s>
  5921. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  5922. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  5923.  
  5924. // 99px * 5% = 4.95px
  5925.  
  5926. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  5927.  
  5928.  
  5929. // 1% Duration
  5930.  
  5931. let ratio2 = ratio1;
  5932.  
  5933. const ydd = yd.data;
  5934. if (ydd) {
  5935.  
  5936. const d1 = ydd.durationSec;
  5937. const d2 = ydd.fullDurationSec;
  5938.  
  5939. // @ step timing [min. 0.2%]
  5940. let numOfSteps = 500;
  5941. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  5942. if (d2 > 400) numOfSteps = 500; // 0.2%
  5943. else if (d2 > 200) numOfSteps = 200; // 0.5%
  5944. else if (d2 > 100) numOfSteps = 100; // 1%
  5945. else if (d2 > 50) numOfSteps = 50; // 2%
  5946. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  5947. else numOfSteps = 20;
  5948. }
  5949. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  5950. if (numOfSteps < 5) numOfSteps = 5;
  5951.  
  5952. const rd = numOfSteps / 100.0;
  5953.  
  5954. ratio2 = Math.round(ratio2 * rd) / rd;
  5955.  
  5956. // ratio2 = Math.round(ratio2 * 5) / 5;
  5957. ratio2 = ratio2.toFixed(1);
  5958. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  5959.  
  5960. if (yd.__style_last__ === v) return;
  5961. yd.__style_last__ = v;
  5962. // do not consider any delay here.
  5963. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  5964.  
  5965. }
  5966. }
  5967.  
  5968. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  5969.  
  5970.  
  5971. } else {
  5972. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  5973. }
  5974.  
  5975. };
  5976.  
  5977.  
  5978. const fpTicker = (renderer) => {
  5979. if (FLAG_001a) return;
  5980. const cnt = insp(renderer);
  5981. assertor(() => typeof (cnt || 0).is === 'string');
  5982. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  5983. const container = (cnt.$ || 0).container;
  5984. if (container) {
  5985. assertor(() => (container || 0).nodeType === 1);
  5986. assertor(() => typeof container.setAttribute === 'function');
  5987. container.setAttribute = tickerContainerSetAttribute;
  5988. } else {
  5989. console.warn(`"container" does not exist in ${cnt.is}`);
  5990. }
  5991. };
  5992.  
  5993.  
  5994. const tags = [
  5995. "yt-live-chat-ticker-renderer",
  5996. "yt-live-chat-ticker-paid-message-item-renderer",
  5997. "yt-live-chat-ticker-paid-sticker-item-renderer",
  5998. "yt-live-chat-ticker-sponsor-item-renderer"
  5999. ];
  6000.  
  6001. const tagsItemRenderer = [
  6002. "yt-live-chat-ticker-renderer",
  6003. "yt-live-chat-ticker-paid-message-item-renderer",
  6004. "yt-live-chat-ticker-paid-sticker-item-renderer",
  6005. "yt-live-chat-ticker-sponsor-item-renderer"
  6006. ];
  6007.  
  6008. const wmList = new Set;
  6009. if (DEBUG_wmList) {
  6010.  
  6011. setInterval(() => {
  6012. let q = document.querySelector('#label-text');
  6013. if(!q) return;
  6014. const size = new Set([...wmList].filter(e => e?.deref()?.isConnected === false).map(e => e?.deref())).size;
  6015. q.textContent = `${48833}, ${DEBUG_wmList_started}, ${size}`;
  6016.  
  6017. // console.log(48833, )
  6018. }, 100);
  6019. }
  6020.  
  6021.  
  6022. /*
  6023. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  6024. const dProto = {
  6025. detachedForTickerInit: function () {
  6026. try {
  6027. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  6028. // this.behaviorActionMap = 0;
  6029. // this.isVisibilityRoot = 0;
  6030. } catch (e) { }
  6031. return this.detached582MemoryLeak();
  6032. },
  6033. attachedForTickerInit: function () {
  6034. wmList.add(new WeakRef(this))
  6035. // fpTicker(this.hostElement || this);
  6036. return this.attached77();
  6037. },
  6038. }
  6039. for (const tag of tagsItemRenderer) { // ##tag##
  6040. const dummy = document.createElement(tag);
  6041. const cProto = getProto(dummy);
  6042. if (!cProto || !cProto.attached) {
  6043. console.warn(`proto.attached for ${tag} is unavailable.`);
  6044. continue;
  6045. }
  6046. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  6047. cProto.detached582MemoryLeak = cProto.detached;
  6048. cProto.detached = cProto.detachedForTickerInit;
  6049. }
  6050. cProto.attached77 = cProto.attached;
  6051. cProto.attached = dProto.attachedForTickerInit;
  6052. }
  6053. });
  6054. */
  6055.  
  6056.  
  6057. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  6058.  
  6059. if (FLAG_001b) return;
  6060. mightFirstCheckOnYtInit();
  6061. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  6062. console.log("[Begin]");
  6063.  
  6064. let dummyValueForStyleReturn = null;
  6065.  
  6066. const genDummyValueForStyleReturn = () => {
  6067. let s = `--nx:82;`
  6068. let ro = {
  6069. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  6070. "implementsGoogStringTypedString": true
  6071. };
  6072. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  6073. return ro;
  6074. }
  6075.  
  6076. let isCSSPropertySupported_ = null;
  6077. const isCSSPropertySupported = () => {
  6078.  
  6079. // @property --ticker-rtime
  6080.  
  6081. if (typeof isCSSPropertySupported_ === 'boolean') return isCSSPropertySupported_;
  6082. isCSSPropertySupported_ = false;
  6083.  
  6084. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return false;
  6085. const documentElement = document.documentElement;
  6086. if (!documentElement) {
  6087. console.warn('document.documentElement is not found');
  6088. return false;
  6089. }
  6090. if (`${getComputedStyleCached(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  6091. return false;
  6092. }
  6093.  
  6094. const ae = animate.call(documentElement,
  6095. [
  6096. { '--ticker-rtime': '70%' },
  6097. { '--ticker-rtime': '30%' }
  6098. ],
  6099. {
  6100. fill: "forwards",
  6101. duration: 1000 * 40,
  6102. easing: 'linear'
  6103. }
  6104. );
  6105.  
  6106. let animatedValue = getComputedStyleCached(document.documentElement).getPropertyValue('--ticker-rtime');
  6107. ae.finish();
  6108. if (`${animatedValue}`.length !== 3) return false;
  6109.  
  6110. isCSSPropertySupported_ = true;
  6111. return true;
  6112.  
  6113. };
  6114.  
  6115. let tickerAttachmentId = 0;
  6116.  
  6117. let windowShownAt = -1;
  6118. const setupEventForWindowShownAt = () => {
  6119. window.addEventListener('visibilitychange', () => {
  6120. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  6121. else windowShownAt = 0;
  6122. }, false);
  6123. }
  6124.  
  6125. const __requestRemoval__ = function (cnt) {
  6126. if (cnt.hostElement && typeof cnt.requestRemoval === 'function') {
  6127. try {
  6128. const id = (cnt.data || 0).id;
  6129. if (!id) cnt.data = { id: 1 };
  6130. } catch (e) { }
  6131. try {
  6132. cnt.requestRemoval();
  6133. return true;
  6134. } catch (e) { }
  6135. }
  6136. return false;
  6137. }
  6138.  
  6139. const widthIORes = new WeakMap();
  6140. const widthIO = new IntersectionObserver((mutations) => {
  6141. for (const mutation of mutations) {
  6142. const elm = mutation.target;
  6143. widthIO.unobserve(elm);
  6144. const {promise, values} =widthIORes.get(elm) || {};
  6145. if(promise && values){
  6146.  
  6147.  
  6148. widthIORes.delete(elm);
  6149. values.width= mutation.boundingClientRect.width;
  6150. promise.resolve(values);
  6151. }
  6152. }
  6153. });
  6154. const widthReq = (elm)=>{
  6155.  
  6156. {
  6157.  
  6158. const {promise, values} =widthIORes.get(elm) || {};
  6159. if(promise) return promise;
  6160. }
  6161. const promise = new PromiseExternal();
  6162. widthIORes.set(elm, {promise, values: {}});
  6163. widthIO.unobserve(elm);
  6164. widthIO.observe(elm);
  6165.  
  6166. return promise;
  6167.  
  6168. }
  6169.  
  6170.  
  6171.  
  6172. const dProto = {
  6173.  
  6174.  
  6175. /**
  6176. *
  6177.  
  6178. f.updateStatsBarAndMaybeShowAnimation = function(a, b, c) {
  6179. var d = this;
  6180. a || c();
  6181. a && this.statsBar && this.username && this.textContent && (this.isMouseOver ? (b(),
  6182. c()) : (a = this.animateShowStats(),
  6183. this.data.animationOrigin && this.data.trackingParams && aB().stateChanged(this.data.trackingParams, {
  6184. animationEventData: {
  6185. origin: this.data.animationOrigin
  6186. }
  6187. }),
  6188. a.finished.then(function() {
  6189. var e;
  6190. setTimeout(function() {
  6191. b();
  6192. c();
  6193. if (!d.isMouseOver) {
  6194. var g, k;
  6195. d.animateHideStats(((g = d.data) == null ? void 0 : g.dynamicStateData.stateSlideDurationMs) || 0, ((k = d.data) == null ? void 0 : k.dynamicStateData.stateUpdateDelayAfterMs) || 0)
  6196. }
  6197. }, ((e = d.data) == null ? void 0 : e.dynamicStateData.stateUpdateDelayBeforeMs) || 0)
  6198. })))
  6199. }
  6200.  
  6201. *
  6202. */
  6203.  
  6204.  
  6205.  
  6206. /**
  6207. *
  6208. *
  6209.  
  6210. f.animateShowStats = function() {
  6211. var a = this.textContent.animate({
  6212. transform: "translateY(-30px)"
  6213. }, {
  6214. duration: this.data.dynamicStateData.stateSlideDurationMs,
  6215. fill: "forwards"
  6216. });
  6217. this.username.animate({
  6218. opacity: 0
  6219. }, {
  6220. duration: 500,
  6221. fill: "forwards"
  6222. });
  6223. this.statsBar.animate({
  6224. opacity: 1
  6225. }, {
  6226. duration: 500,
  6227. fill: "forwards"
  6228. });
  6229. return a
  6230. }
  6231. ;
  6232. f.animateHideStats = function(a, b) {
  6233. this.textContent.animate({
  6234. transform: "translateY(0)"
  6235. }, {
  6236. duration: a,
  6237. fill: "forwards",
  6238. delay: b
  6239. });
  6240. this.username.animate({
  6241. opacity: 1
  6242. }, {
  6243. duration: 300,
  6244. fill: "forwards",
  6245. delay: b
  6246. });
  6247. this.statsBar.animate({
  6248. opacity: 0
  6249. }, {
  6250. duration: 300,
  6251. fill: "forwards",
  6252. delay: b
  6253. })
  6254. }
  6255. *
  6256. */
  6257. updateStatsBarAndMaybeShowAnimationRevised: function (a, b, c) {
  6258. // prevent memory leakage due to d.data was asked in a.finished.then
  6259. try{
  6260. // console.log('updateStatsBarAndMaybeShowAnimation called', this.is)
  6261. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6262. return this.updateStatsBarAndMaybeShowAnimation38.call(this.__proxySelf0__, a, b, c);
  6263. }catch(e){
  6264. console.log('updateStatsBarAndMaybeShowAnimationRevised ERROR');
  6265. console.error(e);
  6266. }
  6267. },
  6268.  
  6269. detachedForMemoryLeakage: function () {
  6270.  
  6271. try{
  6272. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  6273. // this.behaviorActionMap = 0;
  6274. // this.isVisibilityRoot = 0;
  6275. }catch(e){}
  6276. return this.detached582MemoryLeak();
  6277. },
  6278.  
  6279. detachedForTickerInit: function () {
  6280.  
  6281. Promise.resolve(this).then((cnt) => {
  6282. if (cnt.isAttached) return;
  6283. cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false && __requestRemoval__(cnt);
  6284. cnt.rafId > 1 && rafHub.cancel(cnt.rafId);
  6285. }).catch(console.warn);
  6286.  
  6287. let r;
  6288. try {
  6289. r = this.detached77();
  6290. } catch (e) {
  6291. console.warn(e);
  6292. }
  6293. this.__ticker_attachmentId__ = 0;
  6294. return r;
  6295. },
  6296.  
  6297. attachedForTickerInit: function () {
  6298. if (tickerAttachmentId > 1e9) tickerAttachmentId = 9;
  6299. this.__ticker_attachmentId__ = ++tickerAttachmentId;
  6300.  
  6301. DEBUG_wmList && wmList.add(new WeakRef(this))
  6302. if (DEBUG_wmList && !DEBUG_wmList_started) {
  6303. console.log('!!!!!!!!!!!!! DEBUG_wmList_started !!!!!!!!!')
  6304. DEBUG_wmList_started = 1;
  6305. }
  6306.  
  6307. fpTicker(this.hostElement || this);
  6308. return this.attached77();
  6309.  
  6310. },
  6311.  
  6312.  
  6313. // doAnimator
  6314.  
  6315. _makeAnimator: function () {
  6316. if (this._r782) return;
  6317. // if (!this.isAttached) return;
  6318. if (!this._runnerAE) {
  6319. /** @type {HTMLElement | null} */
  6320. const aElement = (this.$ || 0).container;
  6321. if (!aElement) return console.warn("this.$.container is undefined");
  6322. const da = this.data;
  6323. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  6324. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  6325. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  6326. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  6327.  
  6328. // if (!this.__tickerBackgroundInitialChecked__) {
  6329. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  6330. // console.log('__tickerBackgroundInitialChecked__')
  6331. // this._checkTickerBackgroundChanged();
  6332. // }
  6333.  
  6334. aElement.style.setProperty('--ticker-c1', c1);
  6335. aElement.style.setProperty('--ticker-c2', c2);
  6336. aElement.classList.add(runTickerClassName);
  6337. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  6338. // this._aeStartV = this.countdownMs;
  6339. // this._aeStartT = this.countdownDurationMs;
  6340. if (!(p >= 0 && p <= 100)) {
  6341. console.warn('incorrect time ratio', p);
  6342. } else {
  6343. /*
  6344. const u0 = p.toFixed(4) + '%';
  6345. this._runnerAE = animate.call(aElement,
  6346. [
  6347. { '--ticker-rtime': u0 },
  6348. { '--ticker-rtime': '0%' }
  6349. ]
  6350. ,
  6351. {
  6352. fill: "forwards",
  6353. duration: this.countdownMs,
  6354. easing: "linear"
  6355. }
  6356. );
  6357. */
  6358.  
  6359. let timingFn = 'linear';
  6360.  
  6361. const totalDuration = this.countdownDurationMs;
  6362.  
  6363. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  6364.  
  6365. // @ step timing [min. 0.2%]
  6366. let stepInterval = 0.2; // unit: %
  6367. if (totalDuration > 400000) stepInterval = 0.2;
  6368. else if (totalDuration > 200000) stepInterval = 0.5;
  6369. else if (totalDuration > 100000) stepInterval = 1;
  6370. else if (totalDuration > 50000) stepInterval = 2;
  6371. else if (totalDuration > 25000) stepInterval = 5;
  6372. else stepInterval = 5;
  6373.  
  6374. let numOfSteps = Math.round(100 / stepInterval);
  6375.  
  6376. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  6377. if (numOfSteps < 5) numOfSteps = 5;
  6378.  
  6379. timingFn = `steps(${numOfSteps}, end)`;
  6380.  
  6381. }
  6382.  
  6383.  
  6384. /** @type {Animation} */
  6385. const ae = animate.call(aElement,
  6386. [
  6387. { '--ticker-rtime': '100%' },
  6388. { '--ticker-rtime': '0%' }
  6389. ]
  6390. ,
  6391. {
  6392. fill: "forwards",
  6393. duration: totalDuration,
  6394. easing: timingFn
  6395. }
  6396. );
  6397.  
  6398. this._runnerAE = ae;
  6399.  
  6400. ae.onfinish = (event) => {
  6401. this.onfinish = null;
  6402. if (this._runnerAE !== ae) return;
  6403. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  6404. this._aeFinished(event);
  6405. }
  6406. }
  6407.  
  6408. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  6409.  
  6410. if (bq >= 0 && bq <= totalDuration) {
  6411.  
  6412. if (bq > totalDuration - 1) {
  6413. ae.currentTime = bq;
  6414. // setTimeout(() => {
  6415. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  6416. // }, 1);
  6417. } else {
  6418. ae.currentTime = bq;
  6419. }
  6420. } else {
  6421. console.warn('Error on setting _runnerAE.currentTime!');
  6422. }
  6423.  
  6424.  
  6425. aeConstructor = ae.constructor; // constructor is from iframe
  6426. return ae;
  6427. }
  6428. } else {
  6429. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  6430. // assume just time update
  6431. const ae = this._runnerAE;
  6432. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  6433. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  6434. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  6435. if (!(p >= 0 && p <= 100)) {
  6436. console.warn('incorrect time ratio', p);
  6437. } else {
  6438. // let u0 = p.toFixed(4) + '%'
  6439. /*
  6440. ae.effect.setKeyframes([
  6441. { '--ticker-rtime': u0 },
  6442. { '--ticker-rtime': '0%' }
  6443. ]);
  6444. ae.effect.updateTiming({ duration: this.countdownMs });
  6445. */
  6446. // ae.currentTime = 0;
  6447.  
  6448.  
  6449.  
  6450. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  6451. if (bq >= 0 && bq <= this.countdownDurationMs) {
  6452.  
  6453. this._runnerAE.currentTime = bq
  6454. } else {
  6455. console.warn('Error on setting _runnerAE.currentTime!');
  6456. }
  6457.  
  6458.  
  6459. ae.play();
  6460. return ae;
  6461. }
  6462. }
  6463. },
  6464.  
  6465. _aeFinished: function (event) {
  6466.  
  6467. if (this._r782) return;
  6468.  
  6469. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  6470. this._throwOut();
  6471. return;
  6472. }
  6473.  
  6474. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  6475.  
  6476. let lc = window.performance.now();
  6477. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  6478. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  6479. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  6480. if (this.countdownMs > 76) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs, this, event); // just warning.
  6481.  
  6482. this.countdownMs = 0;
  6483. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null;
  6484.  
  6485. if (this.isAttached) {
  6486. let fastRemoved = false;
  6487. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  6488. // no animation if the video page is switched from background to foreground
  6489. // this.hostElement.style.display = 'none';
  6490.  
  6491. fastRemoved = __requestRemoval__(this);
  6492. }
  6493.  
  6494. if (!fastRemoved) {
  6495. "auto" === this.hostElement.style.width && this.setContainerWidth();
  6496. this.slideDown();
  6497. }
  6498. }
  6499.  
  6500.  
  6501.  
  6502. },
  6503.  
  6504.  
  6505. /** @type {()} */
  6506. _throwOut: function () {
  6507. this._r782 = 1;
  6508. Promise.resolve(this).then((cnt) => {
  6509. __requestRemoval__(cnt);
  6510. cnt.detached();
  6511. if (cnt.__dataClientsReady === true) cnt.__dataClientsReady = false;
  6512. if (cnt.__dataEnabled === true) cnt.__dataEnabled = false;
  6513. if (cnt.__dataReady === true) cnt.__dataReady = false;
  6514. cnt.data = null;
  6515. cnt.countdownMs = 0;
  6516. cnt.lastCountdownTimeMs = null;
  6517. const hm = cnt.hostElement || cnt;
  6518. if (hm.parentNode) hm.remove();
  6519. for (let t; t = hm.firstChild;) t.remove();
  6520. }).catch(e => {
  6521. console.warn(e);
  6522. });
  6523. },
  6524.  
  6525.  
  6526. // doTimerFnModification
  6527.  
  6528.  
  6529. /** @type {(a, b)} */
  6530. startCountdownForTimerFnModA: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  6531. try {
  6532.  
  6533. const cnt = kRef(this);
  6534. if (!cnt) return;
  6535. if (!cnt.hostElement) return;
  6536.  
  6537. const attachementId = cnt.__ticker_attachmentId__;
  6538. if(!attachementId) return;
  6539.  
  6540. // a.durationSec [s] => countdownMs [ms]
  6541. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  6542. // lastCountdownTimeMs => raf ongoing
  6543. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  6544.  
  6545. if (cnt._r782) return;
  6546.  
  6547. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6548. cnt._throwOut();
  6549. return;
  6550. }
  6551.  
  6552. // TimerFnModA
  6553.  
  6554. b = void 0 === b ? 0 : b;
  6555. if (void 0 !== a) {
  6556.  
  6557. cnt.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  6558. cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs; // constant throughout the animation
  6559. if (!(cnt.lastCountdownTimeMs || cnt.isAnimationPaused)) {
  6560. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now()
  6561. cnt.rafId = 1
  6562. if (cnt._runnerAE) console.warn('Error in .startCountdown; cnt._runnerAE already created.')
  6563. cnt.detlaSincePausedSecs = 0;
  6564. const ae = cnt._makeAnimator();
  6565. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  6566.  
  6567. // if (playerProgressChangedArg1 === null) {
  6568. // console.log('startCountdownForTimerFnModA', cnt.data)
  6569. // }
  6570.  
  6571. if (isPlayProgressTriggered && cnt.isAnimationPaused !== true && cnt.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__) {
  6572.  
  6573.  
  6574.  
  6575.  
  6576. cnt.playerProgressSec = lastPlayerProgress > 0 ? lastPlayerProgress : 0; // save the progress first
  6577. cnt.isAnimationPaused = true; // trigger isAnimationPausedChanged
  6578. cnt.detlaSincePausedSecs = 0;
  6579. cnt._forceNoDetlaSincePausedSecs783 = 1; // reset cnt.detlaSincePausedSecs = 0 when resumed
  6580.  
  6581. relayPromise = relayPromise || new PromiseExternal();
  6582.  
  6583. relayPromise.then(() => {
  6584.  
  6585. const cnt = kRef(this);
  6586. if (!cnt) return;
  6587. if (!cnt.hostElement) return;
  6588.  
  6589. if (cnt && attachementId !== cnt.__ticker_attachmentId__) return;
  6590. if (cnt.isAttached === true && cnt.countdownDurationMs > 0 && cnt.isAnimationPaused === true && cnt.isReplayPaused !== true) {
  6591. cnt.isAnimationPaused = false;
  6592. }
  6593. });
  6594.  
  6595.  
  6596. }
  6597.  
  6598.  
  6599.  
  6600. }
  6601. }
  6602.  
  6603. } catch (e) {
  6604. console.warn(e);
  6605. }
  6606.  
  6607. },
  6608.  
  6609.  
  6610.  
  6611. /** @type {(a, b)} */
  6612. startCountdownForTimerFnModT: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  6613.  
  6614. try {
  6615. const cnt = kRef(this);
  6616. if (!cnt) return;
  6617. if (!cnt.hostElement) return;
  6618.  
  6619. const attachementId = cnt.__ticker_attachmentId__;
  6620. if(!attachementId) return;
  6621.  
  6622. // a.durationSec [s] => countdownMs [ms]
  6623. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  6624. // lastCountdownTimeMs => raf ongoing
  6625. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  6626.  
  6627. if (cnt._r782) return;
  6628.  
  6629. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6630. cnt._throwOut();
  6631. return;
  6632. }
  6633.  
  6634. // TimerFnModT
  6635.  
  6636. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  6637. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  6638. b = void 0 === b ? 0 : b;
  6639. void 0 !== a && (cnt.countdownMs = 1E3 * a,
  6640. cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs,
  6641. cnt.ratio = 1,
  6642. cnt.lastCountdownTimeMs || cnt.isAnimationPaused || (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now(),
  6643. cnt.rafId = rafHub.request(cnt.boundUpdateTimeout37_)))
  6644.  
  6645. } catch (e) {
  6646. console.warn(e);
  6647. }
  6648.  
  6649. },
  6650.  
  6651.  
  6652. /** @type {(a,)} */
  6653. updateTimeoutForTimerFnModA: function (a) {
  6654.  
  6655. try {
  6656. const cnt = kRef(this);
  6657. if (!cnt) return;
  6658. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6659.  
  6660. const attachementId = cnt.__ticker_attachmentId__;
  6661. if(!attachementId) return;
  6662.  
  6663. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  6664.  
  6665. if (cnt._r782) return;
  6666.  
  6667. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6668. cnt._throwOut();
  6669. return;
  6670. }
  6671.  
  6672. // TimerFnModA
  6673.  
  6674. if (!cnt._runnerAE) console.warn('Error in .updateTimeout; cnt._runnerAE is undefined');
  6675. if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  6676. cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  6677. }
  6678. if (cnt.countdownMs > cnt.countdownDurationMs) cnt.countdownMs = cnt.countdownDurationMs;
  6679. if (cnt.isAttached && cnt.countdownMs) {
  6680. cnt.lastCountdownTimeMs = a
  6681. const ae = cnt._makeAnimator(); // request raf
  6682. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  6683. } else {
  6684. (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  6685. cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  6686. cnt.slideDown()));
  6687. }
  6688.  
  6689. } catch (e) {
  6690. console.warn(e);
  6691. }
  6692.  
  6693.  
  6694. },
  6695.  
  6696. /** @type {(a,)} */
  6697. updateTimeoutForTimerFnModT: function (a) {
  6698.  
  6699. try {
  6700. const cnt = kRef(this);
  6701. if (!cnt) return;
  6702. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6703.  
  6704. const attachementId = cnt.__ticker_attachmentId__;
  6705. if(!attachementId) return;
  6706.  
  6707. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  6708.  
  6709. if (cnt._r782) return;
  6710.  
  6711. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6712. cnt._throwOut();
  6713. return;
  6714. }
  6715.  
  6716. // TimerFnModT
  6717.  
  6718. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  6719. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  6720. if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  6721. cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  6722. }
  6723. // console.log(703, cnt.countdownMs)
  6724. cnt.ratio = cnt.countdownMs / cnt.countdownDurationMs;
  6725. cnt.isAttached && cnt.countdownMs ? (cnt.lastCountdownTimeMs = a,
  6726. cnt.rafId = rafHub.request(cnt.boundUpdateTimeout37_)) : (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  6727. cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  6728. cnt.slideDown()))
  6729.  
  6730.  
  6731. } catch (e) {
  6732. console.warn(e);
  6733. }
  6734. },
  6735.  
  6736. /** @type {(a,b)} */
  6737. isAnimationPausedChangedForTimerFnModA: function (a, b) {
  6738.  
  6739. const cnt = kRef(this);
  6740. if (!cnt) return;
  6741. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6742.  
  6743. const attachementId = cnt.__ticker_attachmentId__;
  6744. if(!attachementId) return;
  6745.  
  6746. if (cnt._r782) return;
  6747.  
  6748. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6749. cnt._throwOut();
  6750. return;
  6751. }
  6752. let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  6753. cnt._forceNoDetlaSincePausedSecs783 = 0;
  6754.  
  6755. Promise.resolve(cnt).then((cnt) => {
  6756.  
  6757. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6758.  
  6759. if (a) {
  6760.  
  6761. if (cnt._runnerAE && cnt._runnerAE.playState === 'running') {
  6762.  
  6763. cnt._runnerAE.pause()
  6764. let lc = window.performance.now();
  6765. cnt.countdownMs = Math.max(0, cnt.countdownMs - (lc - cnt.lastCountdownTimeMs));
  6766. if (cnt.countdownMs > cnt.countdownDurationMs) cnt.countdownMs = cnt.countdownDurationMs;
  6767. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = lc;
  6768. }
  6769.  
  6770. } else if (!a && b) {
  6771.  
  6772.  
  6773. if (forceNoDetlaSincePausedSecs783) cnt.detlaSincePausedSecs = 0;
  6774. a = cnt.detlaSincePausedSecs ? (cnt.lastCountdownTimeMs || 0) + 1000 * cnt.detlaSincePausedSecs : (cnt.lastCountdownTimeMs || 0);
  6775. cnt.detlaSincePausedSecs = 0;
  6776. cnt.updateTimeout(a);
  6777. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now();
  6778.  
  6779. }
  6780.  
  6781. cnt = null;
  6782.  
  6783.  
  6784. }).catch(e => {
  6785. console.log(e);
  6786. });
  6787.  
  6788.  
  6789.  
  6790. },
  6791.  
  6792.  
  6793. /** @type {(a,b)} */
  6794. isAnimationPausedChangedForTimerFnModT: function (a, b) {
  6795.  
  6796. const cnt = kRef(this);
  6797. if (!cnt) return;
  6798. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6799.  
  6800. const attachementId = cnt.__ticker_attachmentId__;
  6801. if(!attachementId) return;
  6802.  
  6803. if (cnt._r782) return;
  6804.  
  6805. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6806. cnt._throwOut();
  6807. return;
  6808. }
  6809. // let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  6810. // cnt._forceNoDetlaSincePausedSecs783 = 0;
  6811.  
  6812. Promise.resolve(cnt).then((cnt) => {
  6813.  
  6814. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6815.  
  6816. // TimerFnModT
  6817.  
  6818. // ez++;
  6819. // if(ez> 1e9) ez=9;
  6820. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  6821. a ? rafHub.cancel(cnt.rafId) : !a && b && (a = cnt.lastCountdownTimeMs || 0,
  6822. cnt.detlaSincePausedSecs && (a = (cnt.lastCountdownTimeMs || 0) + 1E3 * cnt.detlaSincePausedSecs,
  6823. cnt.detlaSincePausedSecs = 0),
  6824. cnt.boundUpdateTimeout37_(a),
  6825. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now())
  6826.  
  6827. cnt = null;
  6828.  
  6829. }).catch(e => {
  6830. console.log(e);
  6831. });
  6832.  
  6833.  
  6834.  
  6835. },
  6836.  
  6837. setContainerWidthNoSelfLeakage: function(){
  6838. // prevent memory leakage due ot delay function
  6839. try{
  6840. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6841. return this.setContainerWidth55.call(this.__proxySelf0__);
  6842. }catch(e){
  6843. console.log('setContainerWidthNoSelfLeakage ERROR');
  6844. console.error(e);
  6845. }
  6846.  
  6847. },
  6848.  
  6849. slideDownNoSelfLeakage: function(){
  6850. // prevent memory leakage due ot delay function
  6851. try{
  6852. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6853. return this.slideDown55.call(this.__proxySelf0__);
  6854. }catch(e){
  6855. console.log('slideDownNoSelfLeakage ERROR');
  6856. console.error(e);
  6857. }
  6858. },
  6859.  
  6860. collapseNoSelfLeakage: function(){
  6861. // prevent memory leakage due ot delay function
  6862. try{
  6863. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6864. return this.collapse55.call(this.__proxySelf0__);
  6865. }catch(e){
  6866. console.log('collapseNoSelfLeakage ERROR');
  6867. console.error(e);
  6868. }
  6869. },
  6870.  
  6871. deletedChangedNoSelfLeakage: function(){
  6872. // prevent memory leakage due ot delay function
  6873. try{
  6874. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6875. return this.deletedChanged55.call(this.__proxySelf0__);
  6876. }catch(e){
  6877. console.log('deletedChangedNoSelfLeakage ERROR');
  6878. console.error(e);
  6879. }
  6880.  
  6881. },
  6882.  
  6883.  
  6884. /** @type {(a,b)} */
  6885. computeContainerStyleForAnimatorEnabled: function (a, b) {
  6886.  
  6887. if (this._r782) return;
  6888. const attachementId = this.__ticker_attachmentId__;
  6889. if(!attachementId) return;
  6890.  
  6891. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  6892. this._throwOut();
  6893. return;
  6894. }
  6895.  
  6896. return (dummyValueForStyleReturn || (dummyValueForStyleReturn = genDummyValueForStyleReturn()));
  6897.  
  6898. },
  6899.  
  6900.  
  6901.  
  6902. /** @type {()} */
  6903. handlePauseReplayForPlaybackProgressState: function () {
  6904. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  6905.  
  6906. const attachementId = this.__ticker_attachmentId__;
  6907. if(!attachementId) return;
  6908.  
  6909. const jr = mWeakRef(this);
  6910.  
  6911. if (onPlayStateChangePromise) {
  6912.  
  6913. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  6914. const tid = ++this.rtu;
  6915.  
  6916. onPlayStateChangePromise.then(() => {
  6917. const cnt = kRef(jr);
  6918. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6919. if (cnt.isAttached) {
  6920. if (tid === cnt.rtu && !onPlayStateChangePromise && typeof cnt.handlePauseReplay === 'function' && cnt.hostElement) cnt.handlePauseReplay.apply(cnt, arguments);
  6921. // this.handlePauseReplay can be undefined if it is memory cleaned
  6922. }
  6923. });
  6924.  
  6925. return;
  6926. }
  6927.  
  6928. if (playerState !== 2) return;
  6929. if (this.isAttached) {
  6930. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  6931. const tid = ++this.rtk;
  6932. const tc = relayCount;
  6933. foregroundPromiseFn().then(() => {
  6934. const cnt = kRef(jr);
  6935. if (attachementId !== cnt.__ticker_attachmentId__) return;
  6936. if (cnt.isAttached) {
  6937. if (tid === cnt.rtk && tc === relayCount && playerState === 2 && _playerState === playerState && cnt.hostElement) {
  6938. cnt.handlePauseReplay66();
  6939. }
  6940. }
  6941.  
  6942. })
  6943. }
  6944. },
  6945.  
  6946. /** @type {()} */
  6947. handleResumeReplayForPlaybackProgressState: function () {
  6948. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  6949.  
  6950. const attachementId = this.__ticker_attachmentId__;
  6951. if(!attachementId) return;
  6952.  
  6953. const jr = mWeakRef(this);
  6954. if (onPlayStateChangePromise) {
  6955.  
  6956. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  6957. const tid = ++this.rtv;
  6958.  
  6959. onPlayStateChangePromise.then(() => {
  6960. const cnt = kRef(jr);
  6961. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6962. if (tid === cnt.rtv && !onPlayStateChangePromise && typeof cnt.handleResumeReplay === 'function' && cnt.hostElement) cnt.handleResumeReplay.apply(cnt, arguments);
  6963. // this.handleResumeReplay can be undefined if it is memory cleaned
  6964. });
  6965.  
  6966. return;
  6967. }
  6968.  
  6969.  
  6970. if (playerState !== 1) return;
  6971. if (this.isAttached) {
  6972. const tc = relayCount;
  6973.  
  6974. relayPromise = relayPromise || new PromiseExternal();
  6975. relayPromise.then(() => {
  6976. const cnt = kRef(jr);
  6977. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6978. if (relayCount > tc && playerState === 1 && _playerState === playerState && cnt.hostElement) {
  6979. cnt.handleResumeReplay66();
  6980. }
  6981. });
  6982. }
  6983. },
  6984.  
  6985. /** @type {(a,)} */
  6986. handleReplayProgressForPlaybackProgressState: function (a) {
  6987. if (this.isAttached) {
  6988. const attachementId = this.__ticker_attachmentId__;
  6989. if(!attachementId) return;
  6990. const tid = ++this.rtk;
  6991. const jr = mWeakRef(kRef(this));
  6992. foregroundPromiseFn().then(() => {
  6993. const cnt = kRef(jr);
  6994. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6995. if (cnt.isAttached) {
  6996. if (tid === cnt.rtk && cnt.hostElement) {
  6997. cnt.handleReplayProgress66(a);
  6998. }
  6999. }
  7000. })
  7001. }
  7002. }
  7003.  
  7004.  
  7005. }
  7006.  
  7007.  
  7008. for (const tag of tagsItemRenderer) { // ##tag##
  7009.  
  7010.  
  7011. const dummy = document.createElement(tag);
  7012.  
  7013. const cProto = getProto(dummy);
  7014. if (!cProto || !cProto.attached) {
  7015. console.warn(`proto.attached for ${tag} is unavailable.`);
  7016. continue;
  7017. }
  7018.  
  7019. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  7020. cProto.detached582MemoryLeak = cProto.detached;
  7021. cProto.detached = dProto.detachedForMemoryLeakage;
  7022. }
  7023.  
  7024. cProto.detached77 = cProto.detached;
  7025. cProto.detached = dProto.detachedForTickerInit;
  7026.  
  7027. cProto.attached77 = cProto.attached;
  7028.  
  7029. cProto.attached = dProto.attachedForTickerInit;
  7030.  
  7031. if (FLAG_001c) continue;
  7032.  
  7033. let flgLeakageFixApplied = 0;
  7034.  
  7035. if (FIX_MEMORY_LEAKAGE_TICKER_STATSBAR && typeof cProto.updateStatsBarAndMaybeShowAnimation === 'function' && !cProto.updateStatsBarAndMaybeShowAnimation38 && cProto.updateStatsBarAndMaybeShowAnimation.length === 3) {
  7036.  
  7037. cProto.updateStatsBarAndMaybeShowAnimation38 = cProto.updateStatsBarAndMaybeShowAnimation;
  7038. cProto.updateStatsBarAndMaybeShowAnimation = dProto.updateStatsBarAndMaybeShowAnimationRevised;
  7039.  
  7040. flgLeakageFixApplied |= 2;
  7041. } else {
  7042. // the function is only in yt-live-chat-ticker-paid-message-item-renderer
  7043. }
  7044.  
  7045.  
  7046. // ------------- withTimerFn_ -------------
  7047.  
  7048. let withTimerFn_ = 0;
  7049. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  7050.  
  7051. // console.log('startCountdown', typeof cProto.startCountdown)
  7052. // console.log('updateTimeout', typeof cProto.updateTimeout)
  7053. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  7054.  
  7055. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  7056. const isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  7057. if (!isTimingFunctionHackable) console.log('isTimingFunctionHackable = false');
  7058. withTimerFn_ = isTimingFunctionHackable ? 2 : 1;
  7059. } else {
  7060. let flag = 0;
  7061. if (typeof cProto.startCountdown === 'function') flag |= 1;
  7062. if (typeof cProto.updateTimeout === 'function') flag |= 2;
  7063. if (typeof cProto.isAnimationPausedChanged === 'function') flag |= 4;
  7064.  
  7065. console.log(`Skip Timing Function Modification: ${flag} / ${1 + 2 + 4}`, ` ${tag}`);
  7066. // console.log(Object.getOwnPropertyNames(cProto))
  7067. // continue;
  7068. }
  7069. // ------------- withTimerFn_ -------------
  7070.  
  7071. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7072.  
  7073. let urt = 0;
  7074.  
  7075. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  7076.  
  7077.  
  7078. /**
  7079. *
  7080. f.handlePauseReplay = function() {
  7081. this.isAnimationPaused = !0;
  7082. this.detlaSincePausedSecs = 0
  7083. }
  7084. */
  7085.  
  7086. /**
  7087. *
  7088. f.handlePauseReplay = function() {
  7089. this.isReplayPaused = !0
  7090. }
  7091. *
  7092. */
  7093.  
  7094. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  7095. const fi = fnIntegrity(cProto.handlePauseReplay);
  7096. urt++;
  7097. if (fi === '0.8.2' || fi === '0.12.4') {
  7098. } else {
  7099. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  7100. }
  7101. } else {
  7102. if (withTimerFn_ > 0) console.log('Error for setting cProto.handlePauseReplay', tag)
  7103. }
  7104.  
  7105. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handleResumeReplay.length === 0) {
  7106. urt++;
  7107. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  7108. } else {
  7109. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleResumeReplay', tag)
  7110. }
  7111.  
  7112. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  7113. urt++;
  7114. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  7115. } else {
  7116. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleReplayProgress', tag)
  7117. }
  7118.  
  7119.  
  7120.  
  7121. }
  7122.  
  7123. 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);
  7124. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  7125.  
  7126. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  7127.  
  7128. cProto.rtk = 0;
  7129. cProto.rtu = 0;
  7130. cProto.rtv = 0;
  7131.  
  7132. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  7133. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  7134.  
  7135. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  7136. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  7137.  
  7138. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  7139. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  7140.  
  7141. }
  7142.  
  7143. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7144.  
  7145. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7146.  
  7147. if (FIX_MEMORY_LEAKAGE_TICKER_TIMER) {
  7148. if (!USE_ADVANCED_TICKING && typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth55 && cProto.setContainerWidth.length === 0) {
  7149. cProto.setContainerWidth55 = cProto.setContainerWidth;
  7150. cProto.setContainerWidth = dProto.setContainerWidthNoSelfLeakage;
  7151. flgLeakageFixApplied |= 4;
  7152. }
  7153. if (!USE_ADVANCED_TICKING && typeof cProto.slideDown === 'function' && !cProto.slideDown55 && cProto.slideDown.length === 0) {
  7154. cProto.slideDown55 = cProto.slideDown;
  7155. cProto.slideDown = dProto.slideDownNoSelfLeakage;
  7156. flgLeakageFixApplied |= 8;
  7157. }
  7158. if (!USE_ADVANCED_TICKING && typeof cProto.collapse === 'function' && !cProto.collapse55 && cProto.collapse.length === 0) {
  7159. cProto.collapse55 = cProto.collapse;
  7160. cProto.collapse = dProto.collapseNoSelfLeakage;
  7161. flgLeakageFixApplied |= 16;
  7162. }
  7163. if (typeof cProto.deletedChanged === 'function' && !cProto.deletedChanged55 && cProto.deletedChanged.length === 0) {
  7164.  
  7165. cProto.deletedChanged55 = cProto.deletedChanged;
  7166. cProto.deletedChanged = dProto.deletedChangedNoSelfLeakage;
  7167. flgLeakageFixApplied |= 32;
  7168. }
  7169.  
  7170. }
  7171.  
  7172. console.log(`FIX_MEMORY_LEAKAGE_TICKER_: ${flgLeakageFixApplied} / ${1 + 2 + 4 + 8 + 16 + 32}`, cProto.is);
  7173.  
  7174. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7175.  
  7176.  
  7177.  
  7178.  
  7179. if (withTimerFn_ > 0) {
  7180.  
  7181. const isTimingFunctionHackable = withTimerFn_ & 2;
  7182.  
  7183. let doAnimator_ = false;
  7184.  
  7185. let rafHackState = 0;
  7186. // continue;
  7187. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  7188.  
  7189. // cancelable - this.rafId < isAnimationPausedChanged >
  7190. rafHackState = 1;
  7191.  
  7192. if (isTimingFunctionHackable) {
  7193. rafHackState = 2;
  7194.  
  7195. } else {
  7196. rafHackState = 4;
  7197. }
  7198.  
  7199. }
  7200. // continue;
  7201.  
  7202. doAnimator_ = !USE_ADVANCED_TICKING && !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  7203.  
  7204.  
  7205. const doAnimator = doAnimator_;
  7206.  
  7207. cProto._throwOut = dProto._throwOut;
  7208.  
  7209. cProto._makeAnimator = doAnimator ? dProto._makeAnimator : null;
  7210.  
  7211. cProto._aeFinished = doAnimator ? dProto._aeFinished : null;
  7212.  
  7213.  
  7214. const doRAFHack = rafHackState === 2;
  7215.  
  7216.  
  7217. const doTimerFnModification = !USE_ADVANCED_TICKING && (doRAFHack || doAnimator);
  7218. // doTimerFnModification = false; // M55
  7219.  
  7220. if (doTimerFnModification) { // including memory fix leakage
  7221.  
  7222. if (doAnimator && windowShownAt < 0) {
  7223. windowShownAt = 0;
  7224. setupEventForWindowShownAt();
  7225. }
  7226.  
  7227. cProto.startCountdown = (
  7228. doAnimator ? dProto.startCountdownForTimerFnModA : dProto.startCountdownForTimerFnModT
  7229. );
  7230.  
  7231. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  7232. cProto.updateTimeout = (
  7233. doAnimator ? dProto.updateTimeoutForTimerFnModA : dProto.updateTimeoutForTimerFnModT
  7234. );
  7235.  
  7236.  
  7237. // let ez = 0;
  7238. cProto.isAnimationPausedChanged = (
  7239. doAnimator ? dProto.isAnimationPausedChangedForTimerFnModA : dProto.isAnimationPausedChangedForTimerFnModT
  7240. );
  7241.  
  7242. flgLeakageFixApplied |= 1;
  7243. }
  7244.  
  7245.  
  7246. if (doAnimator) {
  7247.  
  7248.  
  7249. const s = fnIntegrity(cProto.computeContainerStyle);
  7250.  
  7251. if (s === '2.46.29') {
  7252. // f.computeContainerStyle = function(a, b) {
  7253. // if (!a)
  7254. // return $h(kmb);
  7255. // var c = this.colorFromDecimal(a.startBackgroundColor);
  7256. // a = this.colorFromDecimal(a.endBackgroundColor);
  7257. // b = 100 * b + "%";
  7258. // return $h(lmb, c, c, b, a, b, a)
  7259. // }
  7260. } else if (s === '2.44.29' || s === '2.81.31') {
  7261.  
  7262. // var ofb = da([""])
  7263. // pfb = da("background:linear-gradient(90deg, {,{ {,{ {,{);".split("{"))
  7264.  
  7265. // f.computeContainerStyle = function(a, b) {
  7266. // if (!a)
  7267. // return pi(ofb);
  7268. // var c = this.colorFromDecimal(a.startBackgroundColor);
  7269. // a = this.colorFromDecimal(a.endBackgroundColor);
  7270. // b = 100 * b + "%";
  7271. // return pi(pfb, c, c, b, a, b, a)
  7272. // }
  7273.  
  7274. } else {
  7275. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.46.29'));
  7276. }
  7277.  
  7278. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  7279.  
  7280. cProto.computeContainerStyle = dProto.computeContainerStyleForAnimatorEnabled;
  7281.  
  7282. }
  7283.  
  7284. if (doTimerFnModification === true) hasTimerModified = true;
  7285.  
  7286.  
  7287. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  7288. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  7289. }
  7290.  
  7291.  
  7292. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  7293. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  7294. }
  7295. }
  7296.  
  7297. const canDoAdvancedTicking = 1 &&
  7298. typeof cProto.startCountdown === 'function' && !cProto.startCountdown49 && cProto.startCountdown.length === 2 &&
  7299. typeof cProto.updateTimeout === 'function' && !cProto.updateTimeout49 && cProto.updateTimeout.length === 1 &&
  7300. typeof cProto.isAnimationPausedChanged === 'function' && !cProto.isAnimationPausedChanged49 && cProto.isAnimationPausedChanged.length === 2 &&
  7301. typeof cProto.setContainerWidth === 'function' && cProto.setContainerWidth.length === 0 &&
  7302. typeof cProto.slideDown === 'function' && cProto.slideDown.length === 0 &&
  7303. CSS.supports("left","clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)");
  7304.  
  7305.  
  7306. if (USE_ADVANCED_TICKING && canDoAdvancedTicking) {
  7307. // startResistanceUpdater();
  7308. // live replay video -> 48117005 -> 48117006 keep fire. ->48117007 0 -> 48117007 {...}
  7309. // live stream video -> 48117007 0 -> 48117007 YES
  7310.  
  7311. console.log('USE_ADVANCED_TICKING')
  7312.  
  7313. const wio2 = dProto.wio2 || (dProto.wio2 = new IntersectionObserver((mutations) => {
  7314.  
  7315. for (const mutation of mutations) {
  7316. if (mutation.isIntersecting) {
  7317.  
  7318. const marker = mutation.target;
  7319. let endId = marker.id
  7320. if(!endId) continue;
  7321. let tid = endId.substring(0, endId.length -2 );
  7322. if(!tid) continue;
  7323. // let bId = `${tid}-b`;
  7324. const bgElm = document.querySelector(`#${tid}-b`);
  7325. if(!bgElm) continue;
  7326. const overlay = bgElm;
  7327.  
  7328. wio2.unobserve(marker);
  7329. marker.remove();
  7330. let p = overlay || 0;
  7331. let cn = 4;
  7332. while ((p = p.parentElement) instanceof HTMLElement) {
  7333. if (p instanceof HTMLElement) {
  7334. const cnt = insp(p);
  7335. if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1 ) {
  7336.  
  7337. cnt.__advancedTicking038__ = 2;
  7338.  
  7339. let deletionMode = false;
  7340. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7341. if (timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__timestampActionRequest__ > 0) {
  7342.  
  7343. // time choose - 0.2s for transition (slideDown sliding-down)
  7344. // 60hz = 17ms
  7345. // choose 0.28s
  7346. const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  7347. // check whether the targetFutureTime is already the past
  7348. if (targetFutureTime + 280 < Date.now()) {
  7349. // just dispose
  7350. deletionMode = true;
  7351. }
  7352. } else if (!timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__progressAt__ > 0) {
  7353.  
  7354. const targetFutureTime = (cntData.__progressAt__ + cntData.durationSec) ;
  7355. // check whether the targetFutureTime is already the past
  7356. if (targetFutureTime + 0.28 < playerProgressChangedArg1) {
  7357. // just dispose
  7358. deletionMode = true;
  7359. }
  7360.  
  7361.  
  7362. }
  7363.  
  7364.  
  7365. if (deletionMode) {
  7366. __requestRemoval__(cnt);
  7367. } else {
  7368.  
  7369. const w = cnt.hostElement.style.width;
  7370. if (w === "auto" || w === "") cnt.setContainerWidth();
  7371. cnt.slideDown();
  7372. }
  7373.  
  7374. break;
  7375. }
  7376. }
  7377. cn--;
  7378. if (!cn) {
  7379. console.log('cnt not found for ticker-bg-overlay');
  7380. break;
  7381. }
  7382. }
  7383.  
  7384.  
  7385. }
  7386. }
  7387.  
  7388. // console.log(mutations);
  7389. },{
  7390.  
  7391. rootMargin: '0px',
  7392. threshold: [1]
  7393.  
  7394. }));
  7395.  
  7396. // const wio = dProto.wio || (dProto.wio = new IntersectionObserver((mutations) => {
  7397.  
  7398. // // for (const mutation of mutations) {
  7399. // // if (mutation.isIntersecting) {
  7400. // // const marker = mutation.target;
  7401. // // const overlay = marker instanceof HTMLElement ? marker.closest('ticker-bg-overlay') : 0;
  7402. // // wio.unobserve(marker);
  7403. // // marker.remove();
  7404. // // let p = overlay || 0;
  7405. // // let cn = 4;
  7406. // // while ((p = p.parentElement) instanceof HTMLElement) {
  7407. // // if (p instanceof HTMLElement) {
  7408. // // const cnt = insp(p);
  7409. // // if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1 ) {
  7410.  
  7411. // // cnt.__advancedTicking038__ = 2;
  7412.  
  7413. // // let deletionMode = false;
  7414. // // const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7415. // // if (timestampUnderLiveMode && cntData && cntData.duration > 0 && cntData.__timestampActionRequest__ > 0) {
  7416.  
  7417. // // const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  7418. // // // check whether the targetFutureTime is already the past
  7419. // // if (targetFutureTime + 800 < Date.now()) {
  7420. // // // just dispose
  7421. // // deletionMode = true;
  7422. // // }
  7423. // // }
  7424.  
  7425. // // if (deletionMode) {
  7426. // // __requestRemoval__(cnt);
  7427. // // } else {
  7428.  
  7429. // // ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7430. // // cnt.slideDown());
  7431. // // }
  7432.  
  7433. // // break;
  7434. // // }
  7435. // // }
  7436. // // cn--;
  7437. // // if (!cn) {
  7438. // // console.log('cnt not found for ticker-bg-overlay');
  7439. // // break;
  7440. // // }
  7441. // // }
  7442. // // }
  7443. // // }
  7444. // }, {
  7445. // rootMargin: '1px',
  7446. // threshold: [0]
  7447. // }));
  7448.  
  7449. // cProto._throwOut = dProto._throwOut;
  7450.  
  7451.  
  7452. const u37fn = dProto.u37fn || (dProto.u37fn = function (cnt) {
  7453.  
  7454. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7455. if(!cntData) return;
  7456. const cntElement = cnt.hostElement;
  7457. if(!(cntElement instanceof HTMLElement)) return;
  7458.  
  7459. const duration = (cntData.fullDurationSec || cntData.durationSec || 0);
  7460.  
  7461. let ct;
  7462.  
  7463. if (cntData && duration > 0 && !('__progressAt__' in cntData)) {
  7464. ct = Date.now();
  7465. cntData.__liveTimestamp__ = (cntData.__timestampActionRequest__ || ct) / 1000 - timeOriginDT / 1000;
  7466. timestampUnderLiveMode = true;
  7467. } else if (cntData && duration > 0 && cntData.__progressAt__ > 0) {
  7468. timestampUnderLiveMode = false;
  7469. }
  7470. // console.log(48117007, cntData)
  7471.  
  7472. let tk = cntData.__progressAt__ || cntData.__liveTimestamp__;
  7473.  
  7474. if (!tk) {
  7475. console.log('time property is not found');
  7476. return;
  7477. }
  7478.  
  7479.  
  7480.  
  7481. const liveOffsetMs = ct > 0 && cntData.__timestampActionRequest__ > 0 ? ct - cntData.__timestampActionRequest__ : 0;
  7482.  
  7483. // console.log(1237, liveOffsetMs, cntData.durationSec)
  7484.  
  7485. if (liveOffsetMs > 0) {
  7486. cntData.durationSec -= Math.floor(liveOffsetMs / 1000);
  7487. if (cntData.durationSec < 0) cntData.durationSec = 0;
  7488. // console.log(1238, liveOffsetMs, cntData.durationSec)
  7489. if (!cntData.durationSec) {
  7490. try {
  7491. cnt.requestRemoval();
  7492. } catch (e) { }
  7493. return;
  7494. }
  7495. }
  7496.  
  7497.  
  7498. let offset = cntData.fullDurationSec - cntData.durationSec; // consider this is live replay video, offset can be > 0
  7499. if (offset > 0) tk -= offset;
  7500. // in livestreaming. tk can be negative as we use performance.timeOrigin for t=0s time frame
  7501.  
  7502.  
  7503.  
  7504. const existingOverlaySelector = `ticker-bg-overlay[ticker-id="${cnt.__ticker_attachmentId__}"]`;
  7505.  
  7506. if (valAssign(cntElement, '--ticker-start-time', tk) && duration > 0) {
  7507.  
  7508. // t0 ...... 1 ... fullDurationSec
  7509. // tk ...... k ... fullDurationSec-durationSec
  7510. // t0-fullDurationSec ...... 0 ... 0
  7511.  
  7512. // now - (fullDurationSec-durationSec)
  7513.  
  7514.  
  7515. // update dntElementWeak
  7516. const dnt = cnt.parentComponent;
  7517. const dntElement = dnt ? dnt.hostElement || dnt : 0;
  7518. if (dntElement) {
  7519. dntElementWeak = mWeakRef(dntElement);
  7520. resistanceUpdateBusy = false;
  7521. if (!startResistanceUpdaterStarted) startResistanceUpdater();
  7522. else updateTickerCurrentTime();
  7523. }
  7524.  
  7525. // create overlay if needed
  7526. if (!cntElement.querySelector(existingOverlaySelector)) {
  7527.  
  7528. // remove if any
  7529. const oldElement = cntElement.querySelector('ticker-bg-overlay');
  7530. if (oldElement) oldElement.remove();
  7531. // use advancedTicking, ticker enabled
  7532. cnt.__advancedTicking038__ = 1;
  7533.  
  7534. const em = document.createElement('ticker-bg-overlay');
  7535. // const ey = document.createElement('ticker-bg-overlay-end');
  7536. const wy = document.createElement('ticker-bg-overlay-end2');
  7537.  
  7538. const cr1 = cnt.colorFromDecimal(cntData.startBackgroundColor);
  7539. const cr2 = cnt.colorFromDecimal(cntData.endBackgroundColor);
  7540.  
  7541. const container = cnt.$.container;
  7542. em.setAttribute('ticker-id', `${cnt.__ticker_attachmentId__}`);
  7543.  
  7544. const tid = `ticker-${cnt.__ticker_attachmentId__}-${ Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  7545.  
  7546. em.id = `${tid}-b`;
  7547. em.style.background = `linear-gradient(90deg, ${cr1},${cr1} 50%,${cr2} 50%,${cr2})`;
  7548.  
  7549. if (!(container instanceof HTMLElement)) {
  7550. // em.insertBefore(ey, em.firstChild);
  7551. cntElement.insertBefore(em, cntElement.firstChild);
  7552. cntElement.style.borderRadius = '16px';
  7553. container.style.borderRadius = 'initial';
  7554. } else {
  7555. // em.insertBefore(ey, em.firstChild);
  7556. container.insertBefore(em, container.firstChild);
  7557. }
  7558.  
  7559. // em.style.left = '-50%';
  7560. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  7561.  
  7562. if (container instanceof HTMLElement) {
  7563.  
  7564. container.style.background = 'transparent';
  7565. container.style.backgroundColor = 'transparent';
  7566. // container.style.zIndex = '1';
  7567. }
  7568. // em.style.zIndex = '-1';
  7569. valAssign(cntElement, '--ticker-duration-time', duration)
  7570.  
  7571. valAssign(wy, '--ticker-start-time', tk);
  7572. valAssign(wy, '--ticker-duration-time', duration);
  7573. wy.id = `${tid}-e`;
  7574.  
  7575. dntElement.appendChild(wy);
  7576.  
  7577. // if (wio instanceof IntersectionObserver) {
  7578. // wio.observe(ey);
  7579. // }
  7580.  
  7581. if (wio2 instanceof IntersectionObserver) {
  7582. wio2.observe(wy);
  7583. }
  7584.  
  7585. }
  7586. }
  7587. });
  7588.  
  7589. const timeFn = (cnt)=>{
  7590.  
  7591. if (!cnt) return;
  7592. if (!cnt.hostElement) return;
  7593.  
  7594. const attachementId = cnt.__ticker_attachmentId__;
  7595. if (!attachementId) return;
  7596.  
  7597. Promise.resolve(cnt).then(u37fn);
  7598.  
  7599. }
  7600.  
  7601. cProto.startCountdown = dProto.startCountdownAdv || (dProto.startCountdownAdv = function (a, b) {
  7602.  
  7603. timeFn(kRef(this));
  7604.  
  7605. // try {
  7606. // const cnt = kRef(this);
  7607. // if (!cnt) return;
  7608. // if (!cnt.hostElement) return;
  7609.  
  7610. // const attachementId = cnt.__ticker_attachmentId__;
  7611. // if (!attachementId) return;
  7612.  
  7613. // // a.durationSec [s] => countdownMs [ms]
  7614. // // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  7615. // // lastCountdownTimeMs => raf ongoing
  7616. // // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  7617.  
  7618. // // if (cnt._r782) return;
  7619.  
  7620. // // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7621. // // cnt._throwOut();
  7622. // // return;
  7623. // // }
  7624.  
  7625. // // TimerFnModT
  7626.  
  7627. // // b = void 0 === b ? 0 : b;
  7628. // // void 0 !== a && (cnt.countdownMs = 1E3 * a,
  7629. // // cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs,
  7630. // // // cnt.ratio = 1,
  7631. // // cnt.lastCountdownTimeMs || cnt.isAnimationPaused || (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now(),
  7632. // // cnt.rafId = -1))
  7633.  
  7634. // Promise.resolve(cnt).then((cnt) => {
  7635. // u37fn(cnt);
  7636. // })
  7637.  
  7638. // } catch (e) {
  7639. // console.warn(e);
  7640. // }
  7641.  
  7642.  
  7643. });
  7644.  
  7645. cProto.updateTimeout = dProto.updateTimeoutAdv || (dProto.updateTimeoutAdv = function (a) {
  7646.  
  7647.  
  7648. // timeFn(kRef(this));
  7649.  
  7650. // try {
  7651. // const cnt = kRef(this);
  7652. // if (!cnt) return;
  7653. // if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7654.  
  7655. // const attachementId = cnt.__ticker_attachmentId__;
  7656. // if (!attachementId) return;
  7657.  
  7658. // // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  7659.  
  7660. // // if (cnt._r782) return;
  7661.  
  7662. // // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7663. // // cnt._throwOut();
  7664. // // return;
  7665. // // }
  7666.  
  7667. // // if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  7668. // // cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  7669. // // }
  7670. // // console.log(703, cnt.countdownMs)
  7671. // // cnt.ratio = cnt.countdownMs / cnt.countdownDurationMs;
  7672.  
  7673. // // u37fn(cnt);
  7674. // // cnt.isAttached && cnt.countdownMs ? (cnt.lastCountdownTimeMs = a,
  7675. // // cnt.rafId = -1) : (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  7676. // // cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7677. // // cnt.slideDown()))
  7678.  
  7679.  
  7680. // } catch (e) {
  7681. // console.warn(e);
  7682. // }
  7683.  
  7684. });
  7685.  
  7686. cProto.isAnimationPausedChanged = dProto.isAnimationPausedChangedAdv || (dProto.isAnimationPausedChangedAdv = function (a, b) {
  7687.  
  7688.  
  7689. // timeFn(kRef(this));
  7690.  
  7691. // const cnt = kRef(this);
  7692. // if (!cnt) return;
  7693. // if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7694.  
  7695. // const attachementId = cnt.__ticker_attachmentId__;
  7696. // if (!attachementId) return;
  7697.  
  7698. // if (cnt._r782) return;
  7699.  
  7700. // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7701. // cnt._throwOut();
  7702. // return;
  7703. // }
  7704. // let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  7705. // cnt._forceNoDetlaSincePausedSecs783 = 0;
  7706.  
  7707. // u37fn(cnt);
  7708. // Promise.resolve(cnt).then((cnt) => {
  7709.  
  7710. // if (attachementId !== cnt.__ticker_attachmentId__) return;
  7711.  
  7712. // // a ? 0 : !a && b && (a = cnt.lastCountdownTimeMs || 0,
  7713. // // cnt.detlaSincePausedSecs && (a = (cnt.lastCountdownTimeMs || 0) + 1E3 * cnt.detlaSincePausedSecs,
  7714. // // cnt.detlaSincePausedSecs = 0),
  7715. // // cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now())
  7716.  
  7717. // cnt = null;
  7718.  
  7719. // }).catch(e => {
  7720. // console.log(e);
  7721. // });
  7722.  
  7723.  
  7724. });
  7725.  
  7726. if (typeof cProto.slideDown === 'function' && !cProto.slideDown43 && cProto.slideDown.length === 0) {
  7727.  
  7728. cProto.slideDown43 = cProto.slideDown;
  7729. cProto.slideDown = dProto.slideDownAdv || (dProto.slideDownAdv = async function () {
  7730.  
  7731. // console.log('calling slideDown', Date.now())
  7732. if(this.__advancedTicking038__){
  7733.  
  7734. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  7735.  
  7736.  
  7737. const hostElement = this.hostElement;
  7738. const container = this.$.container;
  7739. if (hostElement instanceof HTMLElement && container instanceof HTMLElement) {
  7740. const prevTransitionClosingElm = kRef(prevTransitionClosing);
  7741. if (prevTransitionClosingElm !== hostElement) {
  7742. prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  7743. prevTransitionClosing = mWeakRef(hostElement);
  7744. }
  7745. if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  7746. const pr = new PromiseExternal();
  7747. transitionEndAfterFnSimple.set(hostElement, pr);
  7748. transitionEndAfterFnSimple.set(container, pr);
  7749. hostElement.classList.add("sliding-down");
  7750. await pr.then();
  7751. transitionEndAfterFnSimple.delete(hostElement);
  7752. transitionEndAfterFnSimple.delete(container);
  7753. if(this && this.hostElement instanceof HTMLElement){
  7754. this.collapse();
  7755. }
  7756. return;
  7757. }
  7758. }
  7759. this.slideDown43();
  7760. });
  7761. }
  7762.  
  7763.  
  7764. if (typeof cProto.collapse === 'function' && !cProto.collapse43 && cProto.collapse.length === 0) {
  7765. cProto.collapse43 = cProto.collapse;
  7766. cProto.collapse = dProto.collapseAdv || (dProto.collapseAdv = async function () {
  7767.  
  7768.  
  7769. if (this.__advancedTicking038__) {
  7770.  
  7771. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  7772.  
  7773.  
  7774. const hostElement = this.hostElement;
  7775. const container = this.$.container;
  7776. if (hostElement instanceof HTMLElement && container instanceof HTMLElement) {
  7777. const prevTransitionClosingElm = kRef(prevTransitionClosing);
  7778. if (prevTransitionClosingElm !== hostElement) {
  7779. prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  7780. prevTransitionClosing = mWeakRef(hostElement);
  7781. }
  7782. if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  7783.  
  7784. const pr = new PromiseExternal();
  7785. transitionEndAfterFnSimple.set(hostElement, pr);
  7786. transitionEndAfterFnSimple.set(container, pr);
  7787. hostElement.classList.add("collapsing");
  7788. hostElement.style.width = "0";
  7789. await pr.then();
  7790. transitionEndAfterFnSimple.delete(hostElement);
  7791. transitionEndAfterFnSimple.delete(container);
  7792. if (this && this.hostElement instanceof HTMLElement) {
  7793.  
  7794. this.requestRemoval();
  7795. }
  7796.  
  7797. return;
  7798. }
  7799.  
  7800.  
  7801. }
  7802. this.collapse43();
  7803.  
  7804.  
  7805. });
  7806. }
  7807.  
  7808. if (typeof cProto.requestRemoval === 'function' && !cProto.requestRemoval49 && cProto.requestRemoval.length === 0) {
  7809. cProto.requestRemoval49 = cProto.requestRemoval;
  7810. cProto.requestRemoval = dProto.requestRemovalAdv || (dProto.requestRemovalAdv = function () {
  7811. if (this.__advancedTicking038__) {
  7812. try {
  7813. const overlayBg = this.hostElement.querySelector('ticker-bg-overlay[id]');
  7814. if (overlayBg) {
  7815. const overlayBgId = overlayBg.id;
  7816. const tid = overlayBgId ? overlayBgId.substring(0, overlayBgId.length - 2) : '';
  7817. const endElm = tid ? document.querySelector(`#${tid}-e`) : null;
  7818. if (endElm) {
  7819. wio2.unobserve(endElm);
  7820. endElm.remove();
  7821. }
  7822. }
  7823. } catch (e) { }
  7824. this.__advancedTicking038__ = 2;
  7825. }
  7826. const hostElement = this.hostElement;
  7827. if (hostElement instanceof HTMLElement) {
  7828. try {
  7829. // hostElement.remove();
  7830. if (!hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.add('ticker-no-transition-time');
  7831. } catch (e) { }
  7832. return this.requestRemoval49();
  7833. }
  7834. });
  7835. }
  7836.  
  7837. if (typeof cProto.computeContainerStyle === 'function' && !cProto.computeContainerStyle49 && cProto.computeContainerStyle.length === 2) {
  7838. cProto.computeContainerStyle49 = cProto.computeContainerStyle;
  7839. cProto.computeContainerStyle = dProto.computeContainerStyleAdv || (dProto.computeContainerStyleAdv = function (a, b) {
  7840. if (this.__advancedTicking038__) {
  7841. return "";
  7842. }
  7843. return this.computeContainerStyle49(a, b);
  7844. });
  7845. }
  7846.  
  7847.  
  7848.  
  7849. if (typeof cProto.setRevampContainerWidth === 'function' && !cProto.setRevampContainerWidth41 && cProto.setRevampContainerWidth.length === 0) {
  7850. cProto.setRevampContainerWidth41 = cProto.setRevampContainerWidth;
  7851. cProto.setRevampContainerWidth = dProto.setRevampContainerWidthAdv || (dProto.setRevampContainerWidthAdv = async function () {
  7852.  
  7853. // not sure the reason for auto instead of pixel.
  7854. // this is a new function in Dec 2024, but not mainly adopted in the coding yet
  7855.  
  7856. /*
  7857. var a = this;
  7858. (R(this.hostElement).querySelector("#container").clientWidth || 0) === 0 ? (this.hostElement.style.overflow = "visible",
  7859. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  7860. this.ytLiveChatTickerItemBehavior.shouldAnimateIn ? (this.hostElement.style.width = "0",
  7861. Zu(function() {
  7862. a.hostElement.style.width = "auto"
  7863. }, 1)) : this.hostElement.style.width = "auto")
  7864. */
  7865.  
  7866.  
  7867.  
  7868.  
  7869. const hostElement = (this || 0).hostElement;
  7870. const container = this.$.container;
  7871.  
  7872.  
  7873. let qw = null;
  7874.  
  7875. {
  7876.  
  7877.  
  7878. let maxC = 4;
  7879.  
  7880. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  7881.  
  7882. const ed = `${hostElement.id}`
  7883. if (!p || !p.startsWith(`${ed}::`)) {
  7884.  
  7885. const w = hostElement.style.width;
  7886. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  7887.  
  7888. const res = await widthReq(container);
  7889.  
  7890. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  7891.  
  7892. } else {
  7893. qw = p.split('::');
  7894. break;
  7895. }
  7896.  
  7897. }
  7898.  
  7899. }
  7900.  
  7901. if (!qw) {
  7902.  
  7903. console.log('container width failure');
  7904. this.setRevampContainerWidth41();
  7905. return; // failure
  7906. }
  7907.  
  7908.  
  7909. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  7910. if (shouldAnimateIn) {
  7911.  
  7912.  
  7913.  
  7914. const w = hostElement.style.width;
  7915. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  7916. hostElement.classList.remove('ticker-no-transition-time');
  7917. await widthReq(container);
  7918.  
  7919. hostElement.style.width = `${qw[1]}px`;
  7920. return;
  7921.  
  7922.  
  7923. } else {
  7924. hostElement.style.width = `${qw[1]}px`;
  7925. }
  7926.  
  7927.  
  7928. // const container = this.$.container;
  7929. // if(hostElement instanceof HTMLElement && hostElement.style.width) hostElement.style.width = '';
  7930. });
  7931. }
  7932.  
  7933.  
  7934. if (typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth41 && cProto.setContainerWidth.length === 0) {
  7935. cProto.setContainerWidth41 = cProto.setContainerWidth;
  7936. cProto.setContainerWidth = dProto.setContainerWidthAdv || (dProto.setContainerWidthAdv = async function () {
  7937.  
  7938.  
  7939.  
  7940. /*
  7941.  
  7942.  
  7943. var a = this
  7944. , b = R(this.hostElement).querySelector("#container").clientWidth || 0;
  7945. b === 0 ? (this.hostElement.style.overflow = "visible",
  7946. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  7947. this.shouldAnimateIn ? (this.hostElement.style.width = "0",
  7948. Zu(function() {
  7949. a.hostElement.style.width = b + "px"
  7950. }, 1)) : this.hostElement.style.width = b + "px")
  7951.  
  7952. */
  7953.  
  7954. const hostElement = (this || 0).hostElement;
  7955. const container = this.$.container;
  7956.  
  7957. let qw = null;
  7958. {
  7959.  
  7960.  
  7961. let maxC = 4;
  7962.  
  7963. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  7964. const ed = `${hostElement.id}`
  7965. if (!p || !p.startsWith(`${ed}::`)) {
  7966. const w = hostElement.style.width;
  7967. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  7968. const res = await widthReq(container);
  7969. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  7970. } else {
  7971. qw = p.split('::');
  7972. break;
  7973. }
  7974. }
  7975.  
  7976. }
  7977.  
  7978. if(!qw){
  7979.  
  7980. console.log('container width failure');
  7981. this.setContainerWidth41();
  7982. return; // failure
  7983. }
  7984.  
  7985.  
  7986. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  7987. if (shouldAnimateIn) {
  7988.  
  7989.  
  7990.  
  7991. const w = hostElement.style.width;
  7992. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  7993. hostElement.classList.remove('ticker-no-transition-time');
  7994. await widthReq(container);
  7995.  
  7996. hostElement.style.width = `${qw[1]}px`;
  7997. return;
  7998.  
  7999.  
  8000. } else {
  8001. hostElement.style.width = `${qw[1]}px`;
  8002. }
  8003.  
  8004. });
  8005. }
  8006.  
  8007.  
  8008.  
  8009.  
  8010. }
  8011.  
  8012.  
  8013.  
  8014. }
  8015.  
  8016. const selector = tags.join(', ');
  8017. const elements = document.querySelectorAll(selector);
  8018. if (elements.length >= 1) {
  8019. for (const elm of elements) {
  8020. if (insp(elm).isAttached === true) {
  8021. fpTicker(elm);
  8022. }
  8023. }
  8024. }
  8025.  
  8026. console.log("[End]");
  8027. console.groupEnd();
  8028.  
  8029.  
  8030. }).catch(console.warn);
  8031.  
  8032. if(FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth){
  8033.  
  8034. /**
  8035. *
  8036. *
  8037. *
  8038. *
  8039. cT.prototype.dataChanged = function() {
  8040. var a = this;
  8041. this.data && (Q(this.hostElement).querySelector("#content").style.color = this.ytLiveChatTickerItemBehavior.colorFromDecimal(this.data.detailTextColor),
  8042. this.hostElement.ariaLabel = this.computeAriaLabel(this.data),
  8043. this.ytLiveChatTickerItemBehavior.startCountdown(this.data.durationSec, this.data.fullDurationSec),
  8044. qw(function() {
  8045. a.ytLiveChatTickerItemBehavior.setContainerWidth()
  8046. }))
  8047. }
  8048.  
  8049.  
  8050. znb.prototype.dataChanged = function(a) {
  8051. var b = this;
  8052. a && (a.tickerThumbnails.length > 1 && Q(this.hostElement).querySelector("#content").classList.add("multiple-thumbnails"),
  8053. this.ytLiveChatTickerItemBehavior.startCountdown(a.durationSec, a.fullDurationSec),
  8054. qw(function() {
  8055. b.ytLiveChatTickerItemBehavior.setContainerWidth()
  8056. }))
  8057. }
  8058.  
  8059. *
  8060. */
  8061.  
  8062. const dProto = {
  8063. dataChanged54500: function () {
  8064. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  8065. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  8066. try {
  8067. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8068. return this.dataChanged544.call(this.__proxySelf0__);
  8069. } catch (e) {
  8070. console.log('dataChanged54500 ERROR');
  8071. console.error(e);
  8072. }
  8073. } else {
  8074. return this.dataChanged544();
  8075. }
  8076. },
  8077. dataChanged54501: function (a) {
  8078. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  8079. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  8080. try {
  8081. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8082. return this.dataChanged544.call(this.__proxySelf0__, a);
  8083. } catch (e) {
  8084. console.log('dataChanged54501 ERROR');
  8085. console.error(e);
  8086. }
  8087. } else {
  8088. return this.dataChanged544(a);
  8089. }
  8090. },
  8091. }
  8092.  
  8093. for (const sto of [
  8094. 'yt-live-chat-ticker-sponsor-item-renderer',
  8095. 'yt-live-chat-ticker-paid-sticker-item-renderer'
  8096. ].map(tag => [tag, customElements.whenDefined(tag)])) {
  8097. const [tag, promise] = sto;
  8098. promise.then(()=>{
  8099. const dummy = document.createElement(tag);
  8100. const cProto = getProto(dummy);
  8101. if (!cProto || !cProto.attached) {
  8102. console.warn(`proto.attached for ${tag} is unavailable.`);
  8103. return;
  8104. }
  8105. if (!cProto.dataChanged || cProto.dataChanged544 || typeof cProto.dataChanged !== 'function' || !(cProto.dataChanged.length >= 0 && cProto.dataChanged.length <= 1)) return;
  8106.  
  8107. cProto.dataChanged544 = cProto.dataChanged;
  8108.  
  8109. if (cProto.dataChanged.length === 0) cProto.dataChanged = dProto.dataChanged54500;
  8110. else if (cProto.dataChanged.length === 1) cProto.dataChanged = dProto.dataChanged54501;
  8111. })
  8112. }
  8113.  
  8114. }
  8115.  
  8116. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  8117.  
  8118. if (FLAG_001d) return;
  8119.  
  8120. mightFirstCheckOnYtInit();
  8121. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  8122. console.log("[Begin]");
  8123. (() => {
  8124.  
  8125. /* pending!!
  8126.  
  8127. handleLiveChatAction
  8128.  
  8129. removeTickerItemById
  8130.  
  8131. _itemsChanged
  8132. itemsChanged
  8133.  
  8134. handleMarkChatItemAsDeletedAction
  8135. handleMarkChatItemsByAuthorAsDeletedAction
  8136. handleRemoveChatItemByAuthorAction
  8137.  
  8138.  
  8139. */
  8140.  
  8141. const tag = "yt-live-chat-ticker-renderer"
  8142. const dummy = document.createElement(tag);
  8143.  
  8144. const cProto = getProto(dummy);
  8145. if (!cProto || !cProto.attached) {
  8146. console.warn(`proto.attached for ${tag} is unavailable.`);
  8147. return;
  8148. }
  8149.  
  8150. const do_amend_ticker_handleLiveChatAction = AMEND_TICKER_handleLiveChatAction && !AMEND_TICKER_handleLiveChatAction_v3
  8151. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && cProto.handleLiveChatAction.length === 1
  8152. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && cProto.handleLiveChatActions.length === 1
  8153. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  8154. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  8155. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  8156. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  8157. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  8158. ;
  8159.  
  8160. console.log('do_amend_ticker_handleLiveChatAction', fnIntegrity(cProto.handleLiveChatAction), fnIntegrity(cProto.handleLiveChatActions))
  8161.  
  8162.  
  8163. if (do_amend_ticker_handleLiveChatAction) {
  8164.  
  8165.  
  8166. if (fnIntegrity(cProto.handleLiveChatActions) === '1.23.12') {
  8167.  
  8168. console.log(`handleLiveChatActions`, 'modified');
  8169.  
  8170. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  8171.  
  8172. cProto.handleLiveChatActions = function (a) {
  8173. /**
  8174. *
  8175. f.handleLiveChatActions = function(a) {
  8176. a.length && (a.forEach(this.handleLiveChatAction, this),
  8177. this.updateHighlightedItem(),
  8178. this.shouldAnimateIn = !0)
  8179. }
  8180. *
  8181. */
  8182. const len = a.length;
  8183. if (len) {
  8184. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  8185.  
  8186. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  8187.  
  8188. // Primarily for the initial batch, this is due to replayBuffer._back.
  8189. const entries = [];
  8190. const entriesI = [];
  8191. for (let i = 0; i < len; i++) {
  8192. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  8193. const timestampUsec = item ? parseInt(getTimestampUsec(item[firstObjectKey(item)]), 10) : 0;
  8194. if (timestampUsec > 0) {
  8195. entriesI.push(i);
  8196. binaryInsert(entries, { e: a[i], timestampUsec }, (a, b) => {
  8197. const diff = a.timestampUsec - b.timestampUsec;
  8198. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  8199. });
  8200. }
  8201. }
  8202. const mLen = entries.length;
  8203. if (mLen >= 2) {
  8204. for (let j = 0; j < mLen; j++) {
  8205. a[entriesI[j]] = entries[j].e;
  8206. }
  8207. }
  8208. entries.length = 0;
  8209. entriesI.length = 0;
  8210. }
  8211. for (const action of a) {
  8212. action.__batchId45__ = batchToken;
  8213. this.handleLiveChatAction(action);
  8214. }
  8215. }
  8216. }
  8217.  
  8218.  
  8219. }
  8220.  
  8221.  
  8222. console.log(`handleLiveChatAction`, 'modified');
  8223.  
  8224. const cacheChatActions = new LimitedSizeSet(16);
  8225.  
  8226. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  8227.  
  8228. cProto.handleLiveChatAction = function (a) {
  8229.  
  8230. const key = firstObjectKey(a);
  8231. if (!key) return;
  8232.  
  8233. const val = a[key];
  8234. let itemKey = '';
  8235. let itemId = '';
  8236. const valItem = val ? val.item : null;
  8237. if (valItem) {
  8238. itemKey = firstObjectKey(valItem);
  8239. if (itemKey) {
  8240. const itemVal = valItem[itemKey];
  8241. itemId = itemVal ? itemVal.id : '';
  8242. if (itemId) {
  8243. const cacheKey = `${key}.${itemKey}::${itemId}`;
  8244. if (key === 'addChatItemAction' && itemId) return; // no need
  8245. if (cacheChatActions.has(cacheKey)) {
  8246. console.log('handleLiveChatAction Repeated Item', cacheKey);
  8247. return;
  8248. } else {
  8249. cacheChatActions.add(cacheKey);
  8250. }
  8251. }
  8252. }
  8253. }
  8254. return this.handleLiveChatAction45(a);
  8255. };
  8256.  
  8257. console.log("AMEND_TICKER_handleLiveChatAction - OK (v2)");
  8258.  
  8259. } else if (0 && do_amend_ticker_handleLiveChatAction
  8260. && '|1.63.48|1.64.48|'.includes(`|${fnIntegrity(cProto.handleLiveChatAction)}|`)
  8261. && fnIntegrity(cProto.handleLiveChatActions) === '1.23.12'
  8262. ) {
  8263.  
  8264. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  8265.  
  8266. cProto.handleLiveChatActions = function (a) {
  8267. /**
  8268. *
  8269. f.handleLiveChatActions = function(a) {
  8270. a.length && (a.forEach(this.handleLiveChatAction, this),
  8271. this.updateHighlightedItem(),
  8272. this.shouldAnimateIn = !0)
  8273. }
  8274. *
  8275. */
  8276.  
  8277. if (a.length) {
  8278. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  8279. const len = a.length;
  8280. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  8281. // Primarily for the initial batch, this is due to replayBuffer._back.
  8282. const entries = [];
  8283. const entriesI = [];
  8284. for (let i = 0; i < len; i++) {
  8285. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  8286. if (item) {
  8287. const itemRendererKey = firstObjectKey(item);
  8288. const itemRenderer = item[itemRendererKey];
  8289. if (itemRenderer) {
  8290. let timestampUsec = getTimestampUsec(itemRenderer);
  8291. if (timestampUsec !== null) {
  8292. timestampUsec = parseInt(timestampUsec, 10);
  8293. if (timestampUsec > 0) {
  8294. entriesI.push(i);
  8295. entries.push({ e: a[i], timestampUsec })
  8296. }
  8297. }
  8298. }
  8299. }
  8300. }
  8301. const mLen = entries.length;
  8302. if (mLen >= 2) {
  8303. entries.sort((a, b) => {
  8304. const diff = a.timestampUsec - b.timestampUsec;
  8305. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  8306. });
  8307. for (let j = 0; j < mLen; j++) {
  8308. const i = entriesI[j];
  8309. a[i] = entries[j].e;
  8310. }
  8311. }
  8312. entries.length = 0;
  8313. entriesI.length = 0;
  8314. }
  8315. for (const action of a) {
  8316. action.__batchId45__ = batchToken;
  8317. this.handleLiveChatAction(action);
  8318. }
  8319. }
  8320. }
  8321.  
  8322. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  8323.  
  8324. cProto._nszlv_ = 0;
  8325. cProto._stackedLCAs_ = null;
  8326. cProto._lastAddItem_ = null;
  8327. cProto._lastAddItemInStack_ = false;
  8328. cProto.handleLiveChatAction = function (a) {
  8329.  
  8330. /**
  8331. *
  8332. *
  8333. f.handleLiveChatAction = function(a) {
  8334. var b = C(a, xO)
  8335. , c = C(a, yO)
  8336. , d = C(a, o1a)
  8337. , e = C(a, p1a);
  8338. a = C(a, A1a);
  8339. b ? this.unshift("items", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : a && this.handleRemoveChatItemByAuthorAction(a)
  8340. }
  8341. *
  8342. */
  8343.  
  8344. // return this.handleLiveChatAction45(a)
  8345. const { addChatItemAction, addLiveChatTickerItemAction, markChatItemAsDeletedAction,
  8346. removeChatItemAction, markChatItemsByAuthorAsDeletedAction, removeChatItemByAuthorAction, __batchId45__ } = a
  8347.  
  8348. if (addChatItemAction) return;
  8349. const d = Date.now();
  8350.  
  8351. if (this._stackedLCAs_ === null) this._stackedLCAs_ = [];
  8352. const stackArr = this._stackedLCAs_;
  8353. let newStackEntry = null;
  8354. if (addLiveChatTickerItemAction) {
  8355. let isDuplicated = false;
  8356.  
  8357. const newItem = addLiveChatTickerItemAction.item;
  8358. const tickerType = firstObjectKey(newItem);
  8359. if (!tickerType) return;
  8360. const tickerItem = newItem[tickerType];
  8361. const tickerId = tickerItem.id;
  8362. if (!tickerId) return;
  8363.  
  8364. if (this._lastAddItem_ && this._lastAddItem_.id === tickerId) {
  8365. let prevTickerItem = null;
  8366. if (this._lastAddItemInStack_) {
  8367. const entry = stackArr[stackArr.length - 1]; // only consider the last entry
  8368. if (entry && entry.action === 'addItem') {
  8369. prevTickerItem = entry.data; // only consider the first item;
  8370. }
  8371. } else {
  8372. prevTickerItem = this.items[0]; // only consider the first item;
  8373. }
  8374. if (prevTickerItem && prevTickerItem[tickerType]) {
  8375. if (prevTickerItem[tickerType].id === tickerId) {
  8376. isDuplicated = true;
  8377. }
  8378. }
  8379. }
  8380. if (!isDuplicated) {
  8381. this._lastAddItem_ = tickerItem;
  8382. this._lastAddItemInStack_ = true;
  8383. // console.log('newItem', newItem)
  8384.  
  8385. const item = newItem;
  8386. const key = firstObjectKey(item);
  8387. if (key) {
  8388. const itemRenderer = item[key] || 0;
  8389. if (itemRenderer.fullDurationSec > 0) {
  8390. itemRenderer.__actionAt__ = d;
  8391. }
  8392. }
  8393.  
  8394. newStackEntry = { action: 'addItem', data: newItem };
  8395.  
  8396. } else {
  8397. console.log('handleLiveChatAction Repeated Item', tickerItem.id, tickerItem); // happen in both live and playback. Reason Unknown.
  8398. return;
  8399. }
  8400.  
  8401. } else {
  8402. markChatItemAsDeletedAction && (newStackEntry = { action: 'mcItemD', data: markChatItemAsDeletedAction });
  8403. removeChatItemAction && (newStackEntry = { action: 'removeItemById', data: removeChatItemAction.targetId });
  8404. markChatItemsByAuthorAsDeletedAction && (newStackEntry = { action: 'mcItemAD', data: markChatItemsByAuthorAsDeletedAction });
  8405. removeChatItemByAuthorAction && (newStackEntry = { action: 'removeItemA', data: removeChatItemByAuthorAction })
  8406. }
  8407.  
  8408.  
  8409. if (!newStackEntry) return;
  8410. stackArr.push(newStackEntry);
  8411.  
  8412.  
  8413. this._nszlv_++;
  8414. if (this._nszlv_ > 1e9) this._nszlv_ = 9;
  8415. const tid = this._nszlv_;
  8416.  
  8417. newStackEntry.__batchId45__ = __batchId45__ || '';
  8418. newStackEntry.dateTime = Date.now();
  8419.  
  8420.  
  8421. foregroundPromiseFn().then(() => {
  8422.  
  8423. if (tid !== this._nszlv_) return;
  8424. const dateNow = Date.now(); // time difference to shift animation start time shall be considered. (pending)
  8425. const stackArr = this._stackedLCAs_.slice(0);
  8426. this._stackedLCAs_.length = 0;
  8427. this._lastAddItemInStack_ = false;
  8428. let lastDateTime = 0;
  8429. let prevBatchId = '';
  8430. const addItems = [];
  8431. // const previousShouldAnimateIn = this.shouldAnimateIn;
  8432.  
  8433. const addItemsFx = () => {
  8434.  
  8435. if (addItems.length >= 1) {
  8436. const eArr = addItems.slice(0);
  8437. addItems.length = 0;
  8438. if (ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME) {
  8439.  
  8440. const arr = []; // size of arr <= size of eArr
  8441. const d = Date.now();
  8442. for (const item of eArr) {
  8443. const key = firstObjectKey(item);
  8444. if (key) {
  8445.  
  8446.  
  8447. const itemRenderer = item[key] || 0;
  8448. const { durationSec, fullDurationSec, __actionAt__ } = itemRenderer;
  8449. if (__actionAt__ > 0 && durationSec > 0 && fullDurationSec > 0) {
  8450.  
  8451.  
  8452. const offset = d - __actionAt__;
  8453. if (offset > 0 && typeof durationSec === 'number' && typeof fullDurationSec === 'number' && fullDurationSec >= durationSec) {
  8454. const adjustedDurationSec = durationSec - Math.floor(offset / 1000);
  8455. if (adjustedDurationSec < durationSec) { // prevent NaN
  8456. // console.log('adjustedDurationSec', adjustedDurationSec);
  8457. if (adjustedDurationSec > 0) {
  8458. // console.log('offset Sec', Math.floor(offset / 1000));
  8459. itemRenderer.durationSec = adjustedDurationSec;
  8460. } else {
  8461. // if adjustedDurationSec equal 0 or invalid
  8462. continue; // skip adding
  8463. }
  8464. }
  8465.  
  8466. }
  8467.  
  8468. }
  8469.  
  8470. if (fullDurationSec > 0 && durationSec < 1) continue; // fallback check
  8471.  
  8472.  
  8473.  
  8474. }
  8475. arr.push(item)
  8476. // arr.unshift(item);
  8477. }
  8478.  
  8479.  
  8480. // console.log(arr.slice(0))
  8481. this.unshift("items", ...arr);
  8482. } else {
  8483. this.unshift("items", ...eArr);
  8484. }
  8485. }
  8486. }
  8487.  
  8488. for (const entry of stackArr) {
  8489.  
  8490. const { action, data, dateTime, __batchId45__ } = entry;
  8491.  
  8492. const finishLastAction = (
  8493. (prevBatchId !== __batchId45__ && prevBatchId)
  8494. || (dateNow - lastDateTime >= 1000 && dateNow - dateTime < 1000)
  8495. );
  8496.  
  8497. const addPrevItems = addItems.length >= 1 && (finishLastAction || action !== 'addItem');
  8498. lastDateTime = dateTime;
  8499. prevBatchId = __batchId45__;
  8500.  
  8501. if (addPrevItems) {
  8502. addItemsFx();
  8503. }
  8504.  
  8505. if (action === 'addItem') addItems.unshift(data);
  8506. else if (action === 'mcItemD') this.handleMarkChatItemAsDeletedAction(data);
  8507. else if (action === 'removeItemById') this.removeTickerItemById(data);
  8508. else if (action === 'mcItemAD') this.handleMarkChatItemsByAuthorAsDeletedAction(data);
  8509. else if (action === 'removeItemA') this.handleRemoveChatItemByAuthorAction(data);
  8510.  
  8511. }
  8512.  
  8513. addItemsFx();
  8514. })
  8515.  
  8516. }
  8517.  
  8518. console.log("AMEND_TICKER_handleLiveChatAction - OK (v1)");
  8519. } else {
  8520. console.log("AMEND_TICKER_handleLiveChatAction - NG");
  8521. }
  8522.  
  8523.  
  8524.  
  8525. const do_amend_ticker_handleLiveChatAction_v3 = AMEND_TICKER_handleLiveChatAction_v3 && !AMEND_TICKER_handleLiveChatAction
  8526. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && cProto.handleLiveChatAction.length === 1
  8527. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && cProto.handleLiveChatActions.length === 1
  8528. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  8529. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  8530. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  8531. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  8532. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  8533. ;
  8534.  
  8535. if (do_amend_ticker_handleLiveChatAction_v3) {
  8536.  
  8537. /*
  8538. f.handleLiveChatActions = function(a) {
  8539. a.length && (a.forEach(this.handleLiveChatAction, this),
  8540. this.updateHighlightedItem(),
  8541. this.shouldAnimateIn = !0)
  8542. }
  8543. */
  8544.  
  8545. /*
  8546.  
  8547. f.handleLiveChatAction = function(a) {
  8548. var b = y(a, PM)
  8549. , c = y(a, QM)
  8550. , d = y(a, OM)
  8551. , e = y(a, Yab);
  8552. a = y(a, ibb);
  8553. 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)
  8554. }
  8555. */
  8556.  
  8557. const arr00 = new Array(1);
  8558. arr00.forEach = () => { };
  8559. arr00.push = (...args) => { return 1 + args.length };
  8560. arr00.pop = () => { };
  8561. arr00.shift = () => { };
  8562. arr00.unshift = () => { };
  8563. arr00.splice = () => [];
  8564. cProto.handleLiveChatActionsArr0 = arr00;
  8565.  
  8566. cProto.handleLiveChatActions58 = cProto.handleLiveChatActions;
  8567. cProto.xGqq4mo = null;
  8568. cProto.xGqq4Flg = 0;
  8569. cProto.xGqq4moPreparePromise = null;
  8570. cProto.xGqq4f = function () {
  8571. if (this.xGqq4Flg === 2) {
  8572. this.xGqq4Flg = 0;
  8573. tickerPE(async () => { // avoid confliction with ticker generation
  8574. await this.xGqq4moPreparePromise; // just in case
  8575. const s = this.handleLiveChatActionsArr0;
  8576. try {
  8577. this.handleLiveChatActions58(s);
  8578. } catch (e) {
  8579. console.warn(e);
  8580. }
  8581. // console.log('xGqq4f done')
  8582. });
  8583.  
  8584. }
  8585. }
  8586. const liveActionQM = new WeakSet();
  8587. let liveActionsLastTickerAction = null;
  8588. const lastTickerActionM = new WeakSet();
  8589. cProto.handleLiveChatActions = function (a) {
  8590. // let promise = null;
  8591. if (a && a.length) {
  8592. /** @type {MutationObserver | null} */
  8593. let mo = this.xGqq4mo;
  8594. // console.log('xGqq4f aaaa')
  8595. const hostElement = this.hostElement;
  8596. if (hostElement instanceof HTMLElement) {
  8597. if (mo === null || (mo instanceof MutationObserver && this.xGqq4p !== hostElement.xGqq4q)) {
  8598. if (mo instanceof MutationObserver) {
  8599. mo.disconnect();
  8600. mo.takeRecords();
  8601. }
  8602. this.xGqq4mo = mo = new MutationObserver(() => {
  8603. this.xGqq4f();
  8604. })
  8605. const moid = `dm-${Date.now()}-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;;
  8606. this.xGqq4p = moid;
  8607. hostElement.xGqq4q = moid;
  8608. mo.observe(hostElement, { subtree: true, childList: true });
  8609. }
  8610. }
  8611. for (const u of a) {
  8612. u && liveActionQM.add(u)
  8613. }
  8614.  
  8615. /** @type {Promise} */
  8616. const pastPromise = this.xGqq4moPreparePromise || null;
  8617. this.xGqq4moPreparePromise = (async () => {
  8618. try {
  8619. await pastPromise; // just in case
  8620. liveActionsLastTickerAction = null;
  8621. a.forEach(this.handleLiveChatAction, this);
  8622. if (liveActionsLastTickerAction) lastTickerActionM.add(liveActionsLastTickerAction)
  8623. } catch (e) { console.warn(e); } // Promise catch can make the promise always resolved
  8624. // now tickerPE can execute
  8625. })();
  8626.  
  8627.  
  8628. // console.log('xGqq4f bbbb')
  8629. // promise = this.handleLiveChatAction_LastPromise;
  8630. // const f = () => {
  8631. // const s = this.handleLiveChatActionsArr0;
  8632. // try {
  8633. // return this.handleLiveChatActions58(s);
  8634. // } catch (e) {
  8635. // console.warn(e);
  8636. // }
  8637. // }
  8638. // if (!promise) {
  8639. // f();
  8640. // } else {
  8641. // promise.then(f);
  8642. // }
  8643. } else {
  8644. return this.handleLiveChatActions58(a);
  8645. }
  8646. }
  8647.  
  8648. // 12:17:05.748 PM
  8649. // 12:17:05.785 v {name: 'addLiveChatTickerItemAction'}
  8650. // 12:17:08.059 QM
  8651. // 12:17:08.068 v {name: 'markChatItemAsDeletedAction'}
  8652. // 12:17:09.123 OM
  8653. // 12:17:09.133 v {name: 'removeChatItemAction'}
  8654. // 12:17:11.566 Yab
  8655. // 12:17:11.574 v {name: 'markChatItemsByAuthorAsDeletedAction'}
  8656. // 12:17:14.272 ibb
  8657. // 12:17:14.282 v {name: 'removeChatItemByAuthorAction'}
  8658.  
  8659. const keyFilter = (a, keySet) => {
  8660. if (typeof (a || 0) === 'object') {
  8661. for (const k of Object.keys(a)) {
  8662. if (keySet.has(k)) {
  8663. return k;
  8664. }
  8665. }
  8666. }
  8667. return null;
  8668. }
  8669.  
  8670. cProto.lcuJB = function () {
  8671. this.ddnB8 = 1;
  8672. let res = new Set();
  8673. const pxy = new Proxy({}, {
  8674. get(target, prop) {
  8675. res.add(prop);
  8676. },
  8677. set(target, prop, value) {
  8678. return true;
  8679. }
  8680. });
  8681. this.handleLiveChatAction(pxy);
  8682. this.ddnB8 = 0;
  8683. return res.size > 0 ? res : null;
  8684. }
  8685.  
  8686. cProto.ddnB8 = 0;
  8687. cProto.handleLiveChatAction58 = cProto.handleLiveChatAction;
  8688. cProto.liveChatActionFilterKeys = null;
  8689. cProto.handleLiveChatActionTM = new LimitedSizeMap(24);
  8690. const tt0 = Date.now() - 100000;
  8691. cProto.handleLiveChatAction = function (a) {
  8692. if (this.ddnB8) return this.handleLiveChatAction58(a);
  8693. const inQM = a && liveActionQM.delete(a); // true if added from handleLiveChatActions
  8694. let keySet = this.liveChatActionFilterKeys;
  8695. if (keySet === null) {
  8696. const keys = this.lcuJB();
  8697. this.liveChatActionFilterKeys = keySet = (keys || false);
  8698. }
  8699. if (!keySet) {
  8700. if (!unexpectedErr) {
  8701. console.error(unexpectedErr = "************************ [YouTube Super Fast Chat] TickerRenderer:handleLiveChatAction keySet not found; ERR 0xF3D0 ************************");
  8702. }
  8703. return this.handleLiveChatAction58(a);
  8704. }
  8705. const key = keyFilter(a, keySet);
  8706. if (!key) {
  8707. return this.handleLiveChatAction58(a); // just by default
  8708. }
  8709.  
  8710. // ------ avoid duplicate items -------
  8711. const item = ((a[key] || 0).item || 0);
  8712. const ifk = item ? firstObjectKey(item) : null;
  8713. const rendererItem = ifk ? item[ifk] : null;
  8714. if (rendererItem && rendererItem.id) {
  8715. const id = rendererItem.id || 0;
  8716. if (typeof id === 'string') {
  8717. const map = this.handleLiveChatActionTM;
  8718. if (map) {
  8719. const mid = `${rendererItem.authorExternalChannelId}::${rendererItem.id}`;
  8720. const prevTime = map.get(mid);
  8721. const now = Date.now() - tt0;
  8722. map.removeSet(mid, now);
  8723. if (prevTime > 0 && now - prevTime < 2400) {
  8724. console.log('handleLiveChatAction Repeated Item OK', rendererItem.id, rendererItem);
  8725. return; // skip
  8726. } else if (prevTime) {
  8727. console.log('handleLiveChatAction Repeated Item NG', mid, now, prevTime, rendererItem.id, rendererItem);
  8728. }
  8729. // map.removeSet(mid, now);
  8730. }
  8731. }
  8732. }
  8733. // ------ avoid duplicate items -------
  8734.  
  8735. if (inQM) {
  8736. liveActionsLastTickerAction = a;
  8737. }
  8738. this.handleLiveChatAction_LastPromise = tickerPE(async () => {
  8739. await this.xGqq4moPreparePromise; // avoid tickerPE is called before actions under looping in handleLiveChatActions
  8740. const inLQM = lastTickerActionM.delete(a); // multiple candidates
  8741. if (inLQM) this.xGqq4Flg = 2; // 2 to 2 in case two batches are added "in the same time"
  8742. this.handleLiveChatAction58(a);
  8743. // if (inLQM) await timelineResolve(); // timing split by marco event to make tickers generation in different 16ms frame
  8744. // else await Promise.resolve();
  8745. // await Promise.resolve();
  8746. await timelineResolve(); // timing split by marco event to make tickers generation in different 16ms frame
  8747. });
  8748. }
  8749.  
  8750. }
  8751.  
  8752. if (RAF_FIX_keepScrollClamped) {
  8753.  
  8754. // to be improved
  8755.  
  8756. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  8757.  
  8758. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  8759. cProto.keepScrollClamped = function () {
  8760.  
  8761. const cnt = kRef(this);
  8762. if (!cnt) return;
  8763. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8764.  
  8765. cnt._bound_keepScrollClamped = cnt._bound_keepScrollClamped || cnt.keepScrollClamped.bind(mWeakRef(cnt));
  8766. cnt.scrollClampRaf = requestAnimationFrame(cnt._bound_keepScrollClamped);
  8767. cnt.maybeClampScroll()
  8768. }
  8769.  
  8770. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  8771. } else {
  8772.  
  8773. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  8774. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  8775. }
  8776.  
  8777. }
  8778.  
  8779.  
  8780. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function' && fnIntegrity(cProto.startScrolling) === '1.44.31' && '|1.78.45|1.82.43|1.43.31'.indexOf('|' + fnIntegrity(cProto.scrollIncrementally) + '|') >= 0) {
  8781. // to be replaced by animator
  8782.  
  8783. cProto.startScrolling = function (a) {
  8784.  
  8785. const cnt = kRef(this);
  8786. if (!cnt) return;
  8787. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8788.  
  8789. cnt.scrollStopHandle && cnt.cancelAsync(cnt.scrollStopHandle);
  8790. cnt.asyncHandle && cancelAnimationFrame(cnt.asyncHandle);
  8791. cnt.lastFrameTimestamp = cnt.scrollStartTime = performance.now();
  8792. cnt.scrollRatePixelsPerSecond = a;
  8793. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8794. cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally)
  8795. };
  8796.  
  8797. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  8798.  
  8799. /**
  8800. *
  8801. * // 2024.12.17
  8802. * // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  8803.  
  8804. f.startScrolling = function(a) {
  8805. this.scrollStopHandle && $u(this.scrollStopHandle);
  8806. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  8807. this.scrollStartTime = performance.now();
  8808. this.lastFrameTimestamp = performance.now();
  8809. this.scrollRatePixelsPerSecond = a;
  8810. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  8811. }
  8812. ;
  8813. f.scrollIncrementally = function(a) {
  8814. var b = a - (this.lastFrameTimestamp || 0);
  8815. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  8816. this.maybeClampScroll();
  8817. this.updateArrows();
  8818. this.lastFrameTimestamp = a;
  8819. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft > 0 || this.scrollRatePixelsPerSecond && this.scrollRatePixelsPerSecond > 0 ? this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this)) : this.stopScrolling()
  8820. }
  8821. ;
  8822. *
  8823. */
  8824.  
  8825. cProto.__getTickerBarQuery__ = function () {
  8826. const tickerBarQuery = this.tickerBarQuery === '#items' ? this.$.items : this.hostElement.querySelector(this.tickerBarQuery);
  8827. return tickerBarQuery;
  8828. }
  8829.  
  8830. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  8831.  
  8832. const cnt = kRef(this);
  8833. if (!cnt) return;
  8834. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8835.  
  8836. const b = a - (cnt.lastFrameTimestamp || 0);
  8837. const rate = cnt.scrollRatePixelsPerSecond
  8838. const q = b / 1E3 * (rate || 0);
  8839.  
  8840. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8841. const sl = tickerBarQuery.scrollLeft;
  8842. // console.log(rate, sl, q)
  8843. if (cnt.lastFrameTimestamp == cnt.scrollStartTime) {
  8844.  
  8845. } else if (q > -1e-5 && q < 1e-5) {
  8846.  
  8847. } else {
  8848. let cond1 = sl > 0 && rate > 0 && q > 0;
  8849. let cond2 = sl > 0 && rate < 0 && q < 0;
  8850. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  8851. if (cond1 || cond2 || cond3) {
  8852. tickerBarQuery.scrollLeft += q;
  8853. cnt.maybeClampScroll();
  8854. cnt.updateArrows();
  8855. }
  8856. }
  8857.  
  8858. cnt.lastFrameTimestamp = a;
  8859. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8860. 0 < tickerBarQuery.scrollLeft || rate && 0 < rate ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8861. } : function (a) {
  8862.  
  8863. const cnt = kRef(this);
  8864. if (!cnt) return;
  8865. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8866.  
  8867. const b = a - (cnt.lastFrameTimestamp || 0);
  8868. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8869. tickerBarQuery.scrollLeft += b / 1E3 * (cnt.scrollRatePixelsPerSecond || 0);
  8870. cnt.maybeClampScroll();
  8871. cnt.updateArrows();
  8872. cnt.lastFrameTimestamp = a;
  8873. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8874. 0 < tickerBarQuery.scrollLeft || cnt.scrollRatePixelsPerSecond && 0 < cnt.scrollRatePixelsPerSecond ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8875. };
  8876.  
  8877. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  8878. } else {
  8879. assertor(() => fnIntegrity(cProto.startScrolling, '1.44.31'));
  8880. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.78.45'));
  8881. console.log('cProto.startScrolling', cProto.startScrolling);
  8882. console.log('cProto.scrollIncrementally', cProto.scrollIncrementally);
  8883. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  8884. }
  8885.  
  8886.  
  8887. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  8888.  
  8889. cProto.attached37 = cProto.attached;
  8890. cProto.detached37 = cProto.detached;
  8891.  
  8892. let naohzId = 0;
  8893. cProto.__naohzId__ = 0;
  8894. cProto.attached = function () {
  8895. Promise.resolve(this).then((cnt) => {
  8896.  
  8897. const hostElement = cnt.hostElement || cnt;
  8898. if (!(hostElement instanceof HTMLElement)) return;
  8899. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  8900. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  8901. // or #chat-messages
  8902. if (!ironPage) return;
  8903.  
  8904. if (cnt.__naohzId__) removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8905. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  8906. cnt.__naohzId__ = ++naohzId;
  8907. ironPage.setAttribute('naohz', `${+cnt.__naohzId__}`);
  8908.  
  8909. addEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8910. cnt = null;
  8911.  
  8912. });
  8913. return this.attached37.apply(this, arguments);
  8914. };
  8915. cProto.detached = function () {
  8916. Promise.resolve(this).then((cnt) => {
  8917.  
  8918. const ironPage = document.querySelector(`iron-pages[naohz="${+cnt.__naohzId__}"]`);
  8919. if (!ironPage) return;
  8920.  
  8921. removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8922.  
  8923. cnt = null;
  8924.  
  8925. });
  8926. return this.detached37.apply(this, arguments);
  8927. };
  8928.  
  8929. const clickFade = (u) => {
  8930. u.click();
  8931. };
  8932. cProto.messageBoxClickHandlerForFade = async (evt) => {
  8933.  
  8934. const target = (evt || 0).target || 0;
  8935. if (!target) return;
  8936.  
  8937. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  8938. const is = p.is;
  8939. if (typeof is === 'string' && is) {
  8940.  
  8941. if (is === 'yt-live-chat-pinned-message-renderer') {
  8942. return;
  8943. }
  8944. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  8945. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  8946. if (fade) {
  8947. Promise.resolve(fade).then(clickFade);
  8948. evt && evt.stopPropagation();
  8949. }
  8950. return;
  8951. }
  8952. if (is !== 'yt-live-chat-ticker-renderer') {
  8953. if (is.startsWith('yt-live-chat-ticker-')) return;
  8954. if (!is.endsWith('-renderer')) return;
  8955. }
  8956.  
  8957. } else {
  8958. if ((p.nodeName || '').includes('BUTTON')) return;
  8959. }
  8960.  
  8961. }
  8962. };
  8963.  
  8964. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  8965.  
  8966. } else {
  8967. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  8968. }
  8969.  
  8970.  
  8971. })();
  8972.  
  8973. console.log("[End]");
  8974.  
  8975. console.groupEnd();
  8976.  
  8977. }).catch(console.warn);
  8978.  
  8979.  
  8980.  
  8981. if (ENABLE_RAF_HACK_INPUT_RENDERER || DELAY_FOCUSEDCHANGED) {
  8982.  
  8983. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  8984.  
  8985. mightFirstCheckOnYtInit();
  8986. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  8987. console.log("[Begin]");
  8988. (() => {
  8989.  
  8990.  
  8991.  
  8992. const tag = "yt-live-chat-message-input-renderer"
  8993. const dummy = document.createElement(tag);
  8994.  
  8995. const cProto = getProto(dummy);
  8996. if (!cProto || !cProto.attached) {
  8997. console.warn(`proto.attached for ${tag} is unavailable.`);
  8998. return;
  8999. }
  9000.  
  9001.  
  9002. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  9003.  
  9004. let doHack = false;
  9005. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  9006.  
  9007. // not cancellable
  9008.  
  9009. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  9010.  
  9011. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  9012.  
  9013. if (!doHack) console.log('doHack = false')
  9014.  
  9015. }
  9016. // doHack = false; // M55
  9017.  
  9018. if (doHack) {
  9019.  
  9020. cProto.handleTimeout = function (a) {
  9021.  
  9022. const cnt = kRef(this);
  9023. if (!cnt) return;
  9024. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9025.  
  9026. console.log('cProto.handleTimeout', tag)
  9027. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  9028. cnt.timeoutDurationMs = cnt.timeoutMs = a;
  9029. cnt.countdownRatio = 1;
  9030. 0 === cnt.lastTimeoutTimeMs && rafHub.request(cnt.boundUpdateTimeout38_)
  9031. };
  9032. cProto.updateTimeout = function (a) {
  9033.  
  9034. const cnt = kRef(this);
  9035. if (!cnt) return;
  9036. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9037.  
  9038. console.log('cProto.updateTimeout', tag)
  9039. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  9040. cnt.lastTimeoutTimeMs && (cnt.timeoutMs = Math.max(0, cnt.timeoutMs - (a - cnt.lastTimeoutTimeMs)),
  9041. cnt.countdownRatio = cnt.timeoutMs / cnt.timeoutDurationMs);
  9042. cnt.isAttached && cnt.timeoutMs ? (cnt.lastTimeoutTimeMs = a,
  9043. rafHub.request(cnt.boundUpdateTimeout38_)) : cnt.lastTimeoutTimeMs = 0
  9044. };
  9045.  
  9046. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  9047. } else {
  9048.  
  9049. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  9050. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  9051.  
  9052. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  9053. }
  9054.  
  9055.  
  9056. }
  9057.  
  9058. if (DELAY_FOCUSEDCHANGED && typeof cProto.onFocusedChanged === 'function' && cProto.onFocusedChanged.length === 1 && !cProto.onFocusedChanged372) {
  9059. cProto.onFocusedChanged372 = cProto.onFocusedChanged;
  9060. cProto.onFocusedChanged = function (a) {
  9061. Promise.resolve(this).then((cnt) => {
  9062. if (cnt.isAttached === true) cnt.onFocusedChanged372(a);
  9063. cnt = null;
  9064. }).catch(console.warn);
  9065. }
  9066. }
  9067.  
  9068. })();
  9069.  
  9070. console.log("[End]");
  9071.  
  9072. console.groupEnd();
  9073.  
  9074.  
  9075. })
  9076.  
  9077. }
  9078.  
  9079.  
  9080. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  9081.  
  9082. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  9083.  
  9084. mightFirstCheckOnYtInit();
  9085. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  9086. console.log("[Begin]");
  9087. (() => {
  9088.  
  9089. const tag = "yt-emoji-picker-renderer"
  9090. const dummy = document.createElement(tag);
  9091.  
  9092. const cProto = getProto(dummy);
  9093. if (!cProto || !cProto.attached) {
  9094. console.warn(`proto.attached for ${tag} is unavailable.`);
  9095. return;
  9096. }
  9097.  
  9098. let doHack = false;
  9099. if (typeof cProto.animateScroll_ === 'function') {
  9100.  
  9101. // not cancellable
  9102. console.log('animateScroll_', typeof cProto.animateScroll_)
  9103.  
  9104. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  9105.  
  9106. }
  9107.  
  9108. if (doHack) {
  9109.  
  9110. const querySelector = HTMLElement.prototype.querySelector;
  9111. const U = (element) => ({
  9112. querySelector: (selector) => querySelector.call(element, selector)
  9113. });
  9114.  
  9115. cProto.animateScroll_ = function (a) {
  9116.  
  9117. const cnt = kRef(this);
  9118. if (!cnt) return;
  9119. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9120.  
  9121. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  9122. if (!cnt.boundAnimateScroll39_) cnt.boundAnimateScroll39_ = cnt.animateScroll_.bind(mWeakRef(cnt));
  9123. cnt.lastAnimationTime_ || (cnt.lastAnimationTime_ = a);
  9124. a -= cnt.lastAnimationTime_;
  9125. 200 > a ? (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationStart_ + (cnt.animationEnd_ - cnt.animationStart_) * a / 200,
  9126. rafHub.request(cnt.boundAnimateScroll39_)) : (null != cnt.animationEnd_ && (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationEnd_),
  9127. cnt.animationEnd_ = cnt.animationStart_ = null,
  9128. cnt.lastAnimationTime_ = 0);
  9129. cnt.updateButtons_()
  9130. }
  9131.  
  9132. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  9133. } else {
  9134.  
  9135. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  9136. }
  9137.  
  9138. })();
  9139.  
  9140. console.log("[End]");
  9141.  
  9142. console.groupEnd();
  9143. });
  9144. }
  9145.  
  9146. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  9147.  
  9148. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  9149.  
  9150. mightFirstCheckOnYtInit();
  9151. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  9152. console.log("[Begin]");
  9153. (() => {
  9154.  
  9155. const tag = "yt-live-chat-docked-message"
  9156. const dummy = document.createElement(tag);
  9157.  
  9158. const cProto = getProto(dummy);
  9159. if (!cProto || !cProto.attached) {
  9160. console.warn(`proto.attached for ${tag} is unavailable.`);
  9161. return;
  9162. }
  9163.  
  9164. let doHack = false;
  9165. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  9166.  
  9167. // cancelable - this.intersectRAF <detached>
  9168. // yt-live-chat-docked-message
  9169. // boundCheckIntersections <-> checkIntersections
  9170. // onDockableMessagesChanged
  9171. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  9172.  
  9173. console.log('detached', typeof cProto.detached)
  9174. console.log('checkIntersections', typeof cProto.checkIntersections)
  9175. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  9176.  
  9177. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  9178.  
  9179. }
  9180.  
  9181. if (doHack) {
  9182.  
  9183. cProto.__boundCheckIntersectionsSubstitutionFn__ = function () {
  9184. const cnt = this;
  9185. if (!cnt.i5zmk && typeof cnt.boundCheckIntersections === 'function' && typeof cnt.checkIntersections === 'function') {
  9186. cnt.i5zmk = 1
  9187. cnt.boundCheckIntersections = cnt.checkIntersections.bind(mWeakRef(cnt));
  9188. }
  9189. }
  9190.  
  9191. cProto.checkIntersections = function () {
  9192.  
  9193. const cnt = kRef(this);
  9194. if (!cnt) return;
  9195. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9196.  
  9197. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  9198.  
  9199. // console.log('cProto.checkIntersections', tag)
  9200. if (cnt.dockableMessages.length) {
  9201. cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections);
  9202. let a = cnt.dockableMessages[0]
  9203. , b = cnt.hostElement.getBoundingClientRect();
  9204. a = a.getBoundingClientRect();
  9205. let c = a.top - b.top
  9206. , d = 8 >= c;
  9207. c = 8 >= c - cnt.hostElement.clientHeight;
  9208. if (d) {
  9209. let e;
  9210. for (; d;) {
  9211. e = cnt.dockableMessages.shift();
  9212. d = cnt.dockableMessages[0];
  9213. if (!d)
  9214. break;
  9215. d = d.getBoundingClientRect();
  9216. c = d.top - b.top;
  9217. let f = 8 >= c;
  9218. if (8 >= c - a.height)
  9219. if (f)
  9220. a = d;
  9221. else
  9222. return;
  9223. d = f
  9224. }
  9225. cnt.dock(e)
  9226. } else
  9227. c && cnt.dockedItem && cnt.clear()
  9228. } else
  9229. cnt.intersectRAF = 0
  9230. }
  9231.  
  9232. cProto.onDockableMessagesChanged = function () {
  9233. const cnt = this;
  9234. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  9235. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  9236. cnt.dockableMessages.length && !cnt.intersectRAF && (cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections))
  9237. }
  9238.  
  9239. cProto.detached = function () {
  9240. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  9241. }
  9242.  
  9243. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  9244. } else {
  9245.  
  9246. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  9247. }
  9248.  
  9249. })();
  9250.  
  9251. console.log("[End]");
  9252.  
  9253. console.groupEnd();
  9254.  
  9255. }).catch(console.warn);
  9256.  
  9257. }
  9258.  
  9259. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  9260.  
  9261. customElements.whenDefined("yt-img-shadow").then(() => {
  9262.  
  9263. mightFirstCheckOnYtInit();
  9264. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  9265. console.log("[Begin]");
  9266. (() => {
  9267.  
  9268. const tag = "yt-img-shadow"
  9269. const dummy = document.createElement(tag);
  9270.  
  9271. const cProto = getProto(dummy);
  9272. if (!cProto || !cProto.attached) {
  9273. console.warn(`proto.attached for ${tag} is unavailable.`);
  9274. return;
  9275. }
  9276.  
  9277. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  9278.  
  9279. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  9280. cProto.thumbnailChanged_ = function (a) {
  9281.  
  9282. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  9283. if (!this.oldThumbnail_ && !this.thumbnail) return;
  9284.  
  9285. return this.thumbnailChanged66_.apply(this, arguments)
  9286.  
  9287. }
  9288. console.log("cProto.thumbnailChanged_ - OK");
  9289.  
  9290. } else {
  9291. console.log("cProto.thumbnailChanged_ - NG");
  9292.  
  9293. }
  9294. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  9295.  
  9296. cProto.setSrc66_ = cProto.setSrc_;
  9297. cProto.setSrc_ = function (a) {
  9298. if ((((this || 0).$ || 0).img || 0).src === a) return;
  9299. return this.setSrc66_.apply(this, arguments)
  9300. }
  9301.  
  9302. console.log("cProto.setSrc_ - OK");
  9303. } else {
  9304.  
  9305. console.log("cProto.setSrc_ - NG");
  9306. }
  9307.  
  9308. })();
  9309.  
  9310. console.log("[End]");
  9311.  
  9312. console.groupEnd();
  9313.  
  9314. }).catch(console.warn);
  9315.  
  9316. }
  9317.  
  9318. if (FIX_THUMBNAIL_DATACHANGED) {
  9319.  
  9320. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  9321.  
  9322. mightFirstCheckOnYtInit();
  9323. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  9324. console.log("[Begin]");
  9325. (() => {
  9326.  
  9327. const tag = "yt-live-chat-author-badge-renderer"
  9328. const dummy = document.createElement(tag);
  9329.  
  9330. const cProto = getProto(dummy);
  9331. if (!cProto || !cProto.attached) {
  9332. console.warn(`proto.attached for ${tag} is unavailable.`);
  9333. return;
  9334. }
  9335.  
  9336. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|0.169.106|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9337.  
  9338. cProto.dataChanged86 = cProto.dataChanged;
  9339. cProto.dataChanged = function () {
  9340.  
  9341. /* 2024.12.15 */
  9342. /*
  9343. zO.prototype.dataChanged = function() {
  9344. for (var a = Ov(R(this.hostElement).querySelector("#image")); a.firstChild; )
  9345. a.removeChild(a.firstChild);
  9346. if (this.data)
  9347. if (this.data.icon) {
  9348. var b = document.createElement("yt-icon");
  9349. this.data.icon.iconType === "MODERATOR" && this.enableNewModeratorBadge ? (b.polymerController.icon = "yt-sys-icons:shield-filled",
  9350. b.polymerController.defaultToFilled = !0) : b.polymerController.icon = "live-chat-badges:" + this.data.icon.iconType.toLowerCase();
  9351. a.appendChild(b)
  9352. } else if (this.data.customThumbnail) {
  9353. b = document.createElement("img");
  9354. var c;
  9355. (c = (c = UA(this.data.customThumbnail.thumbnails, 16)) ? Yb(kc(c)) : null) ? (b.src = c,
  9356. a.appendChild(b),
  9357. b.setAttribute("alt", this.hostElement.ariaLabel || "")) : Fq(new Zn("Could not compute URL for thumbnail",this.data.customThumbnail))
  9358. }
  9359. }
  9360. */
  9361.  
  9362. const a = (this || 0).data;
  9363. const image = ((this || 0).$ || 0).image;
  9364. if (image && a && image.firstElementChild) {
  9365. const exisiting = image.firstElementChild;
  9366. if (exisiting === image.lastElementChild) {
  9367.  
  9368. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9369.  
  9370. const c = exisiting;
  9371. const t = insp(c);
  9372. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9373. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9374. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9375. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9376. } else {
  9377. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9378. if (w.icon !== p) w.icon = p;
  9379. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9380. }
  9381. return;
  9382.  
  9383.  
  9384. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9385.  
  9386. const c = exisiting;
  9387. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9388.  
  9389. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9390. return;
  9391. }
  9392. /*
  9393.  
  9394. var d;
  9395. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9396.  
  9397. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9398. */
  9399. }
  9400.  
  9401. }
  9402. }
  9403. return this.dataChanged86.apply(this, arguments)
  9404.  
  9405. }
  9406. console.log("cProto.dataChanged - OK");
  9407.  
  9408. } else if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|1.163.100|1.162.100|1.160.97|1.159.97|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9409.  
  9410. cProto.dataChanged86 = cProto.dataChanged;
  9411. cProto.dataChanged = function (a) {
  9412.  
  9413. /*
  9414.  
  9415. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  9416. b.removeChild(b.firstChild);
  9417. if (a)
  9418. if (a.icon) {
  9419. var c = document.createElement("yt-icon");
  9420. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  9421. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9422. b.appendChild(c)
  9423. } else if (a.customThumbnail) {
  9424. c = document.createElement("img");
  9425. var d;
  9426. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9427. b.appendChild(c),
  9428. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  9429. }
  9430.  
  9431. */
  9432.  
  9433.  
  9434. /* 2024.04.20 */
  9435. /*
  9436. for (var b = Tx(N(this.hostElement).querySelector("#image")); b.firstChild; )
  9437. b.removeChild(b.firstChild);
  9438. if (a)
  9439. if (a.icon) {
  9440. var c = document.createElement("yt-icon");
  9441. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.polymerController.icon = "yt-sys-icons:shield-filled",
  9442. c.polymerController.defaultToFilled = !0) : c.polymerController.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9443. b.appendChild(c)
  9444. } else if (a.customThumbnail) {
  9445. c = document.createElement("img");
  9446. var d;
  9447. (d = (d = WD(a.customThumbnail.thumbnails, 16)) ? Sb(ec(d)) : null) ? (c.src = d,
  9448. b.appendChild(c),
  9449. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : nr(new mn("Could not compute URL for thumbnail",a.customThumbnail))
  9450. }
  9451. */
  9452.  
  9453. const image = ((this || 0).$ || 0).image
  9454. if (image && a && image.firstElementChild) {
  9455. const exisiting = image.firstElementChild;
  9456. if (exisiting === image.lastElementChild) {
  9457.  
  9458. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9459.  
  9460. const c = exisiting;
  9461. const t = insp(c);
  9462. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9463. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9464. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9465. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9466. } else {
  9467. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9468. if (w.icon !== p) w.icon = p;
  9469. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9470. }
  9471. return;
  9472.  
  9473.  
  9474. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9475.  
  9476. const c = exisiting;
  9477. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9478.  
  9479. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9480. return;
  9481. }
  9482. /*
  9483.  
  9484. var d;
  9485. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9486.  
  9487. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9488. */
  9489. }
  9490.  
  9491. }
  9492. }
  9493. return this.dataChanged86.apply(this, arguments)
  9494.  
  9495. }
  9496. console.log("cProto.dataChanged - OK");
  9497.  
  9498. } else {
  9499. assertor(() => fnIntegrity(cProto.dataChanged, '0.169.106'));
  9500. console.log("cProto.dataChanged - NG");
  9501.  
  9502. }
  9503.  
  9504. })();
  9505.  
  9506. console.log("[End]");
  9507.  
  9508. console.groupEnd();
  9509.  
  9510. }).catch(console.warn);
  9511.  
  9512.  
  9513. }
  9514.  
  9515.  
  9516.  
  9517. if(USE_ADVANCED_TICKING){
  9518.  
  9519.  
  9520. customElements.whenDefined("yt-live-chat-renderer").then(() => {
  9521.  
  9522. const tag = "yt-live-chat-renderer"
  9523. const dummy = document.createElement(tag);
  9524.  
  9525.  
  9526. const cProto = getProto(dummy);
  9527.  
  9528. dummy.usePatchedLifecycles = false;
  9529. dummy.data = null;
  9530. dummy.__data = null;
  9531. Object.setPrototypeOf(dummy, Object.prototype);
  9532. if (!cProto || !cProto.attached) {
  9533. console.warn(`proto.attached for ${tag} is unavailable.`);
  9534. return;
  9535. }
  9536.  
  9537. /*
  9538. <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;
  9539. */
  9540.  
  9541. if (cProto && typeof cProto.immediatelyApplyLiveChatActions === 'function' && cProto.immediatelyApplyLiveChatActions.length === 1 && !cProto.immediatelyApplyLiveChatActions82) {
  9542. cProto.immediatelyApplyLiveChatActions82 = cProto.immediatelyApplyLiveChatActions;
  9543. cProto.immediatelyApplyLiveChatActions = function(arr){
  9544.  
  9545. try{
  9546. preprocessChatLiveActions(arr);
  9547.  
  9548. }catch(e){
  9549. console.warn(e);
  9550. }
  9551. return this.immediatelyApplyLiveChatActions82(arr);
  9552. };
  9553. }
  9554.  
  9555.  
  9556. if (cProto && typeof cProto.preprocessActions_ === 'function' && cProto.preprocessActions_.length === 1 && !cProto.preprocessActions82_) {
  9557. cProto.preprocessActions82_ = cProto.preprocessActions_;
  9558. cProto.preprocessActions_ = function(arr){
  9559. arr = this.preprocessActions82_(arr);
  9560. preprocessChatLiveActions(arr);
  9561. return arr;
  9562. };
  9563. }
  9564.  
  9565.  
  9566. });
  9567. }
  9568.  
  9569.  
  9570. if (FIX_TOOLTIP_DISPLAY) {
  9571.  
  9572. // ----------------------------------------------------------------------------------------------------
  9573.  
  9574. const checkPDGet = (pd) => {
  9575. return pd && pd.get && !pd.set && pd.enumerable && pd.configurable;
  9576. }
  9577.  
  9578. const tooltipUIWM = new WeakMap();
  9579. const tooltipInitProps = {};
  9580. const createTooltipIfRequired_ = function () {
  9581. let r;
  9582. if (tooltipUIWM.get(this) === void 0) {
  9583. const w = document.createElement;
  9584. let EU = null;
  9585. tooltipUIWM.set(this, null);
  9586. document.createElement = function () {
  9587. let r = w.apply(this, arguments);
  9588. EU = r;
  9589. return r;
  9590. };
  9591. r = this.createTooltipIfRequired14_();
  9592. document.createElement = w;
  9593. if (EU instanceof HTMLElement && EU.is) {
  9594. tooltipUIWM.set(this, EU);
  9595. EU.setAttribute('__nogc__', ''); // avoid gc process script
  9596.  
  9597. if (typeof EU.offset === 'number') tooltipInitProps['offset'] = EU.offset;
  9598. if (typeof EU.fitToVisibleBounds === 'boolean') tooltipInitProps['fitToVisibleBounds'] = EU.fitToVisibleBounds;
  9599. if (typeof EU.position === 'string') tooltipInitProps['position'] = EU.position;
  9600. if (typeof EU.for === 'string') tooltipInitProps['for'] = EU.for;
  9601.  
  9602. // this.__mcT__ = EU.outerHTML;
  9603. // EU.__dataX = JSON.stringify(EU.__data);
  9604. // EU.__dataY = Object.entries(EU);
  9605.  
  9606. // <<< FOR DEBUG >>>
  9607. // let kx;
  9608. // Object.defineProperty(EU, '_target', {
  9609. // get(){
  9610. // return kx;
  9611. // },
  9612. // set(nv){
  9613. // kx= nv;
  9614. // debugger;
  9615. // return true;
  9616. // }
  9617. // });
  9618. // <<< FOR DEBUG >>>
  9619.  
  9620. if (typeof Polymer !== 'undefined' && Polymer.__fixedGetOwnerRoot__ && Polymer.__fixedQuerySelector__) {
  9621.  
  9622. } else {
  9623. let eProto = null;
  9624. const euCnt = insp(EU);
  9625. if (checkPDGet(Object.getOwnPropertyDescriptor(euCnt.constructor.prototype || {}, 'target'))) {
  9626.  
  9627. eProto = euCnt.constructor.prototype;
  9628. } else if (checkPDGet(Object.getOwnPropertyDescriptor(EU.constructor.prototype || {}, 'target'))) {
  9629.  
  9630. eProto = EU.constructor.prototype;
  9631. }
  9632. if (eProto) {
  9633. delete eProto.target;
  9634. /*
  9635.  
  9636. get target() {
  9637. var a = Pv(this).parentNode, b = Pv(this).getOwnerRoot(), c;
  9638. this.for ? c = Pv(b).querySelector("#" + this.for) : c = a.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? b.host : a;
  9639. return c
  9640. },
  9641. */
  9642. Object.defineProperty(eProto, 'target', {
  9643. get() {
  9644. let a = this.parentNode, b = this.getRootNode();
  9645. return (this.for ? b.querySelector("#" + this.for) : a)
  9646. }
  9647. })
  9648. }
  9649. }
  9650. // setInterval(()=>EU.updatePosition(), 100)
  9651.  
  9652. } else {
  9653. tooltipUIWM.set(this, null);
  9654. }
  9655. } else {
  9656. r = this.createTooltipIfRequired14_();
  9657. }
  9658.  
  9659. const EU = tooltipUIWM.get(this);
  9660. if (EU) {
  9661. EU.remove();
  9662. if (typeof tooltipInitProps.offset === 'number') EU['offset'] = tooltipInitProps.offset;
  9663. if (typeof tooltipInitProps.fitToVisibleBounds === 'boolean') EU['fitToVisibleBounds'] = tooltipInitProps.fitToVisibleBounds;
  9664. try {
  9665. if (typeof tooltipInitProps.position === 'string') EU['position'] = tooltipInitProps.position;
  9666. if (typeof tooltipInitProps.for === 'string') EU['for'] = tooltipInitProps.for; else delete EU.for;
  9667. } catch (e) { }
  9668. }
  9669. return r;
  9670. };
  9671.  
  9672.  
  9673. // added in 2024.05.02
  9674. getLCRDummy().then(async (lcrDummy) => {
  9675.  
  9676. // console.log(8171, 99);
  9677. const tag = "yt-live-chat-renderer"
  9678. const dummy = lcrDummy;
  9679.  
  9680. const cProto = getProto(dummy);
  9681. if (!cProto || !cProto.attached) {
  9682. console.warn(`proto.attached for ${tag} is unavailable.`);
  9683. return;
  9684. }
  9685.  
  9686. /*
  9687. <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;
  9688. */
  9689.  
  9690. if (cProto && typeof cProto.createTooltipIfRequired_ === 'function' && cProto.createTooltipIfRequired_.length === 0 && !cProto.createTooltipIfRequired14_) {
  9691. cProto.createTooltipIfRequired14_ = cProto.createTooltipIfRequired_;
  9692. cProto.createTooltipIfRequired_ = createTooltipIfRequired_;
  9693. }
  9694.  
  9695. });
  9696.  
  9697. // ----------------------------------------------------------------------------------------------------
  9698.  
  9699. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  9700.  
  9701. mightFirstCheckOnYtInit();
  9702. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  9703. console.log("[Begin]");
  9704. (() => {
  9705.  
  9706. const tag = "tp-yt-paper-tooltip"
  9707. const dummy = document.createElement(tag);
  9708.  
  9709. const cProto = getProto(dummy);
  9710. if (!cProto || !cProto.attached) {
  9711. console.warn(`proto.attached for ${tag} is unavailable.`);
  9712. return;
  9713. }
  9714.  
  9715. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  9716.  
  9717. cProto._readyClients43 = cProto._readyClients;
  9718. cProto._readyClients = function () {
  9719. // console.log(1238)
  9720.  
  9721. let r = cProto._readyClients43.apply(this, arguments);
  9722. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  9723. return r;
  9724. }
  9725.  
  9726. console.log("_readyClients - OK");
  9727.  
  9728. } else {
  9729. console.log("_readyClients - NG");
  9730.  
  9731. }
  9732.  
  9733. if (typeof cProto.show === 'function' && !cProto.show17) {
  9734. cProto.show17 = cProto.show;
  9735. cProto.show = function () {
  9736.  
  9737. let r = this.show17.apply(this, arguments);
  9738. this._showing === true && Promise.resolve(this).then((cnt) => {
  9739. const tooltip = (cnt.$ || 0).tooltip;
  9740.  
  9741. if (tooltip && tooltip.firstElementChild === null) {
  9742. let text = tooltip.textContent;
  9743. if (typeof text === 'string' && text.length >= 2) {
  9744. tooltip.textContent = text.trim();
  9745. }
  9746. }
  9747. cnt = null;
  9748. }).catch(console.warn)
  9749. return r;
  9750. }
  9751.  
  9752. console.log("trim tooltip content - OK");
  9753.  
  9754. } else {
  9755. console.log("trim tooltip content - NG");
  9756.  
  9757. }
  9758.  
  9759.  
  9760. })();
  9761.  
  9762. console.log("[End]");
  9763.  
  9764. console.groupEnd();
  9765.  
  9766. }).catch(console.warn);
  9767.  
  9768. }
  9769.  
  9770.  
  9771. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  9772.  
  9773. const hookDocumentMouseDownSetupFn = () => {
  9774.  
  9775. let muzTimestamp = 0;
  9776. let nszDropdown = null;
  9777.  
  9778. const handlerObject = {
  9779.  
  9780. muHandler282: function (evt) {
  9781. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  9782. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9783. const dropdown = nszDropdown;
  9784. muzTimestamp = 0;
  9785. nszDropdown = null;
  9786.  
  9787. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9788. const hostElement = kurMPCe.hostElement || kurMPCe; // should be always hostElement === kurMPCe ?
  9789. if (!hostElement.hasAttribute('menu-visible')) return;
  9790.  
  9791. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  9792. if (chatBanner) return;
  9793.  
  9794. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  9795. muzTimestamp = Date.now();
  9796. evt.stopImmediatePropagation();
  9797. evt.stopPropagation();
  9798. Promise.resolve(dropdown).then((dropdown) => {
  9799. dropdown.cancel();
  9800. dropdown = null;
  9801. });
  9802. }
  9803.  
  9804. },
  9805.  
  9806. mlHandler282: function (evt) {
  9807. muzTimestamp = 0;
  9808. nszDropdown = null;
  9809. },
  9810.  
  9811. ckHandler282: function (evt) {
  9812. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9813. if (Date.now() - muzTimestamp < 40) {
  9814. muzTimestamp = Date.now();
  9815. evt.stopImmediatePropagation();
  9816. evt.stopPropagation();
  9817. }
  9818. },
  9819.  
  9820. tapHandler282: function (evt) {
  9821. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9822. if (Date.now() - muzTimestamp < 40) {
  9823. muzTimestamp = Date.now();
  9824. evt.stopImmediatePropagation();
  9825. evt.stopPropagation();
  9826. }
  9827. },
  9828.  
  9829. handleEvent(evt) {
  9830. if (evt) {
  9831. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9832. const kurMPCc = insp(kurMPCe);
  9833. const hostElement = kurMPCc.hostElement || kurMPCc;
  9834. if (!kurMPCc || kurMPCc.isAttached !== true || hostElement.isConnected !== true) return;
  9835. switch (evt.type) {
  9836. case 'mouseup':
  9837. return this.muHandler282(evt);
  9838. case 'mouseleave':
  9839. return this.mlHandler282(evt);
  9840. case 'tap':
  9841. return this.tapHandler282(evt);
  9842. case 'click':
  9843. return this.ckHandler282(evt);
  9844. }
  9845. }
  9846. }
  9847.  
  9848. }
  9849.  
  9850. document.addEventListener('mousedown', function (evt) {
  9851.  
  9852. if (!evt || !evt.isTrusted || !evt.target) return;
  9853.  
  9854. muzTimestamp = 0;
  9855. nszDropdown = null;
  9856.  
  9857. /** @type {HTMLElement | null} */
  9858. const kurMP = kRef(currentMenuPivotWR);
  9859. if (!kurMP) return;
  9860. const kurMPCe = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0; // element
  9861.  
  9862. if (!kurMPCe || !kurMPCe.hasAttribute('whole-message-clickable')) return;
  9863.  
  9864. const kurMPCc = insp(kurMPCe); // controller
  9865.  
  9866. if (!kurMPCc.isClickableChatRow111 || !kurMPCc.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPCe, evt.target)) return;
  9867.  
  9868. const chatBanner = HTMLElement.prototype.closest.call(kurMPCe, 'yt-live-chat-banner-renderer') || 0;
  9869. if (chatBanner) return;
  9870.  
  9871. let targetDropDown = null;
  9872. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  9873. if (dropdown && dropdown.positionTarget === kurMP) {
  9874. targetDropDown = dropdown;
  9875. }
  9876. }
  9877.  
  9878. if (!targetDropDown) return;
  9879.  
  9880. if ((nszDropdown = targetDropDown)) {
  9881. muzTimestamp = Date.now();
  9882. evt.stopImmediatePropagation();
  9883. evt.stopPropagation();
  9884. currentMenuPivotWR = mWeakRef(kurMPCe);
  9885.  
  9886. const listenOpts = { capture: true, passive: false, once: true };
  9887.  
  9888. // remove unexcecuted eventHandler
  9889. document.removeEventListener('mouseup', handlerObject, listenOpts);
  9890. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  9891. document.removeEventListener('tap', handlerObject, listenOpts);
  9892. document.removeEventListener('click', handlerObject, listenOpts);
  9893.  
  9894. // inject one time eventHandler to by pass events
  9895. document.addEventListener('mouseup', handlerObject, listenOpts);
  9896. document.addEventListener('mouseleave', handlerObject, listenOpts);
  9897. document.addEventListener('tap', handlerObject, listenOpts);
  9898. document.addEventListener('click', handlerObject, listenOpts);
  9899.  
  9900. }
  9901.  
  9902. }, true);
  9903.  
  9904. }
  9905.  
  9906.  
  9907. // yt-live-chat-paid-message-renderer ??
  9908.  
  9909. /*
  9910.  
  9911. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  9912.  
  9913.  
  9914. "yt-live-chat-ticker-paid-message-item-renderer"
  9915. "yt-live-chat-ticker-paid-sticker-item-renderer"
  9916. "yt-live-chat-paid-message-renderer"
  9917. "yt-live-chat-text-message-renderer"
  9918. "yt-live-chat-paid-sticker-renderer"
  9919.  
  9920. */
  9921.  
  9922.  
  9923. whenDefinedMultiple([
  9924.  
  9925. "yt-live-chat-paid-message-renderer",
  9926. "yt-live-chat-membership-item-renderer",
  9927. "yt-live-chat-paid-sticker-renderer",
  9928. "yt-live-chat-text-message-renderer",
  9929. "yt-live-chat-auto-mod-message-renderer",
  9930.  
  9931. /*
  9932. "yt-live-chat-ticker-paid-message-item-renderer",
  9933. "yt-live-chat-ticker-paid-sticker-item-renderer",
  9934. "yt-live-chat-paid-message-renderer",
  9935. "yt-live-chat-text-message-renderer",
  9936. "yt-live-chat-paid-sticker-renderer",
  9937.  
  9938. "yt-live-chat-ticker-sponsor-item-renderer",
  9939. "yt-live-chat-banner-header-renderer",
  9940. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  9941. "ytd-sponsorships-live-chat-header-renderer",
  9942. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  9943.  
  9944.  
  9945.  
  9946.  
  9947. "yt-live-chat-auto-mod-message-renderer",
  9948. "yt-live-chat-text-message-renderer",
  9949. "yt-live-chat-paid-message-renderer",
  9950.  
  9951. "yt-live-chat-legacy-paid-message-renderer",
  9952. "yt-live-chat-membership-item-renderer",
  9953. "yt-live-chat-paid-sticker-renderer",
  9954. "yt-live-chat-donation-announcement-renderer",
  9955. "yt-live-chat-moderation-message-renderer",
  9956. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  9957. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  9958. "yt-live-chat-viewer-engagement-message-renderer",
  9959.  
  9960. */
  9961.  
  9962.  
  9963. ]).then(sTags => {
  9964. // return; // M33
  9965.  
  9966. if (FLAG_001e) return;
  9967.  
  9968. mightFirstCheckOnYtInit();
  9969. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  9970. console.log("[Begin]");
  9971. let doMouseHook = false;
  9972.  
  9973. const dProto = {
  9974. isClickableChatRow111: function () {
  9975. return (
  9976. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  9977. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  9978. ); // follow .onItemTap(a)
  9979. }
  9980. };
  9981.  
  9982. for (const sTag of sTags) { // ##tag##
  9983.  
  9984.  
  9985. (() => {
  9986.  
  9987. const tag = sTag;
  9988. const dummy = document.createElement(tag);
  9989.  
  9990. const cProto = getProto(dummy);
  9991. if (!cProto || !cProto.attached) {
  9992. console.warn(`proto.attached for ${tag} is unavailable.`);
  9993. return;
  9994. }
  9995.  
  9996. const dCnt = insp(dummy);
  9997. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  9998.  
  9999. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  10000.  
  10001. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  10002.  
  10003. if (toHookDocumentMouseDown) {
  10004. doMouseHook = true;
  10005. }
  10006.  
  10007. console.log("shouldSupportWholeItemClick Y", tag);
  10008.  
  10009. } else {
  10010.  
  10011. console.log("shouldSupportWholeItemClick N", tag);
  10012. }
  10013.  
  10014.  
  10015. })();
  10016.  
  10017. }
  10018.  
  10019.  
  10020. if (doMouseHook) {
  10021.  
  10022. hookDocumentMouseDownSetupFn();
  10023.  
  10024. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  10025. }
  10026.  
  10027. console.log("[End]");
  10028.  
  10029. console.groupEnd();
  10030.  
  10031.  
  10032. }).catch(console.warn);
  10033.  
  10034.  
  10035. // https://www.youtube.com/watch?v=oQzFi1NO7io
  10036.  
  10037.  
  10038. }
  10039.  
  10040. if (NO_ITEM_TAP_FOR_NON_STATIONARY_TAP) {
  10041. let targetElementCntWR = null;
  10042. let _e0 = null;
  10043. document.addEventListener('mousedown', (e) => {
  10044. if (!e || !e.isTrusted) return;
  10045. let element = e.target;
  10046. for (; element instanceof HTMLElement; element = element.parentNode) {
  10047. if (element.is) break;
  10048. }
  10049. if (!element || !element.is) return;
  10050. const cnt = insp(element);
  10051. if (typeof cnt.onItemTap === 'function') {
  10052. cnt._onItemTap_isNonStationary = 0;
  10053. const cProto = getProto(element);
  10054. if (!cProto.onItemTap366 && typeof cProto.onItemTap === 'function' && cProto.onItemTap.length === 1) {
  10055. cProto.onItemTap366 = cProto.onItemTap; // note: [onItemTap] .some(function(){...})
  10056. cProto.onItemTap = function (a) {
  10057. const t = this._onItemTap_isNonStationary;
  10058. this._onItemTap_isNonStationary = 0;
  10059. if (t > Date.now()) return;
  10060. return this.onItemTap366.apply(this, arguments)
  10061. }
  10062. }
  10063. _e0 = e;
  10064. targetElementCntWR = mWeakRef(cnt);
  10065. } else {
  10066. _e0 = null;
  10067. targetElementCntWR = null;
  10068. }
  10069. }, { capture: true, passive: true });
  10070.  
  10071. document.addEventListener('mouseup', (e) => {
  10072. if (!e || !e.isTrusted) return;
  10073. const e0 = _e0;
  10074. _e0 = null;
  10075. if (!e0) return;
  10076. const cnt = kRef(targetElementCntWR);
  10077. targetElementCntWR = null;
  10078. if (!cnt) return;
  10079. if (e.timeStamp - e0.timeStamp > TAP_ACTION_DURATION) {
  10080. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10081. } else if ((window.getSelection() + "").trim().replace(/[\u2000-\u200a\u202f\u2800\u200B\u200C\u200D\uFEFF]+/g, '').length >= 1) {
  10082. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10083. } else {
  10084. const dx = e.clientX - e0.clientX;
  10085. const dy = e.clientY - e0.clientY;
  10086. const dd = Math.sqrt(dx * dx + dy * dy);
  10087. const ddmm = px2mm(dd);
  10088. if (ddmm > 1.0) {
  10089. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10090. } else {
  10091. cnt._onItemTap_isNonStationary = 0;
  10092. }
  10093. }
  10094. }, { capture: true, passive: true });
  10095.  
  10096. }
  10097.  
  10098.  
  10099. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  10100.  
  10101. let rr = null;
  10102. const p1 = new Promise(resolve => {
  10103. rr = resolve;
  10104. });
  10105.  
  10106. const p1unlock = () => {
  10107. const f = rr;
  10108. if (f) {
  10109. rr = null;
  10110. f();
  10111. }
  10112. }
  10113.  
  10114. return {
  10115. p1,
  10116. p1unlock,
  10117. assignLock: (targetCnt, timeout) => {
  10118. targetCnt.__showContextMenu_assign_lock__(p1);
  10119. if (timeout) setTimeout(p1unlock, timeout);
  10120. }
  10121. }
  10122.  
  10123. }
  10124.  
  10125. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  10126.  
  10127. document.addEventListener('mousedown', function (evt) {
  10128.  
  10129. const maxloopDOMTreeElements = 4;
  10130. const maxloopYtCompontents = 4;
  10131. let j1 = 0;
  10132. let j2 = 0;
  10133. let target = (evt || 0).target || 0;
  10134. if (!target) return;
  10135.  
  10136.  
  10137. while (target instanceof HTMLElement) {
  10138. if (++j1 > maxloopDOMTreeElements) break;
  10139. if (typeof (target.is || insp(target).is || null) === 'string') break;
  10140. target = nodeParent(target);
  10141. }
  10142. const components = [];
  10143. while (target instanceof HTMLElement) {
  10144. if (++j2 > maxloopYtCompontents) break;
  10145. const cnt = insp(target);
  10146. if (typeof (target.is || cnt.is || null) === 'string') {
  10147. components.push(target);
  10148. }
  10149. if (typeof cnt.showContextMenu === 'function') break;
  10150. target = target.parentComponent || cnt.parentComponent || null;
  10151. }
  10152. if (!(target instanceof HTMLElement)) return;
  10153. const targetCnt = insp(target);
  10154. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  10155. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  10156. return;
  10157. }
  10158.  
  10159. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  10160. if (!endpoint) return;
  10161. if (targetCnt.opened || !targetCnt.isAttached) return;
  10162.  
  10163. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  10164. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  10165. }
  10166.  
  10167. const targetDollar = indr(target);
  10168.  
  10169. let doPreRequest = false;
  10170. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  10171. doPreRequest = true;
  10172. } else if (components.length === 1 && components[0] === target) {
  10173. doPreRequest = true;
  10174. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  10175. doPreRequest = true;
  10176. }
  10177. if (doPreRequest === false) {
  10178. console.log('doPreRequest = fasle on showContextMenu', components);
  10179. return;
  10180. }
  10181.  
  10182. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  10183.  
  10184. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  10185. console.log('preRequest on showContextMenu aborted due to stacked network request');
  10186. return;
  10187. }
  10188.  
  10189.  
  10190. const onSuccess = (a) => {
  10191. /*
  10192.  
  10193. dQ() && (a = a.response);
  10194. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  10195. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  10196.  
  10197. */
  10198.  
  10199. a = a.response || a;
  10200.  
  10201. if (!a) {
  10202. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  10203. return;
  10204. }
  10205.  
  10206. let z = null;
  10207. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  10208.  
  10209. if (z) {
  10210. a = z;
  10211. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  10212. }
  10213.  
  10214. };
  10215. const onFailure = (a) => {
  10216.  
  10217. /*
  10218.  
  10219. if (a instanceof Error || a instanceof Object || a instanceof String)
  10220. var b = a;
  10221. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  10222.  
  10223. */
  10224.  
  10225. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  10226. // console.log('onFailure', a)
  10227.  
  10228. };
  10229.  
  10230. if (doPreRequest) {
  10231.  
  10232. let propertyCounter = 0;
  10233. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  10234. const p1Timeout = 800;
  10235. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  10236.  
  10237. try {
  10238.  
  10239. const onSuccessHelperFn = function () {
  10240. pm1.p1unlock();
  10241. if (propertyCounter !== 5) {
  10242. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  10243. return;
  10244. }
  10245. if (this[proxyKey] !== targetCnt) {
  10246. console.log('Error in prerequest for showContextMenu.this');
  10247. return;
  10248. }
  10249. onSuccess(...arguments);
  10250. };
  10251. const onFailureHelperFn = function () {
  10252. pm1.p1unlock();
  10253. if (propertyCounter !== 5) {
  10254. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  10255. return;
  10256. }
  10257. if (this[proxyKey] !== targetCnt) {
  10258. console.log('Error in prerequest for showContextMenu.this');
  10259. return;
  10260. }
  10261. onFailure(...arguments);
  10262.  
  10263. }
  10264. const fakeTargetCnt = new Proxy({
  10265. __showContextMenu_forceNativeRequest__: 1,
  10266. get handleGetContextMenuResponse_() {
  10267. propertyCounter += 2;
  10268. return onSuccessHelperFn;
  10269. },
  10270. get handleGetContextMenuError() {
  10271. propertyCounter += 3;
  10272. return onFailureHelperFn;
  10273. }
  10274. }, {
  10275. get(_, key, receiver) {
  10276. if (key in _) return _[key];
  10277. if (key === proxyKey) return targetCnt;
  10278.  
  10279. let giveNative = false;
  10280. if (key in targetCnt) {
  10281. if (key === 'data') giveNative = true;
  10282. else if (typeof targetCnt[key] === 'function') giveNative = true;
  10283. }
  10284. if (giveNative) return targetCnt[key];
  10285. }
  10286. });
  10287.  
  10288. const fakeEvent = (() => {
  10289. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  10290. const nf = function () { }
  10291. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  10292.  
  10293. return {
  10294. type: 'tap',
  10295. eventPhase: 0,
  10296. isTrusted: false,
  10297. __composed: true,
  10298. bubbles, cancelable, cancelBubble, timeStamp,
  10299. target, srcElement, defaultPrevented, currentTarget, composed,
  10300. stopPropagation, stopImmediatePropagation, preventDefault
  10301. };
  10302. })(evt);
  10303. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  10304.  
  10305.  
  10306. } catch (e) {
  10307. console.warn(e);
  10308. propertyCounter = 7;
  10309.  
  10310. }
  10311. if (propertyCounter !== 5) {
  10312. console.log('Error in prerequest for showContextMenu', propertyCounter);
  10313. return;
  10314. }
  10315.  
  10316. pm1.assignLock(targetCnt, p1Timeout);
  10317.  
  10318. }
  10319.  
  10320.  
  10321.  
  10322.  
  10323.  
  10324.  
  10325. }, true);
  10326.  
  10327.  
  10328. }
  10329.  
  10330.  
  10331.  
  10332. /*
  10333.  
  10334. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  10335.  
  10336. */
  10337.  
  10338. whenDefinedMultiple([
  10339. "yt-live-chat-ticker-sponsor-item-renderer",
  10340. "yt-live-chat-ticker-paid-message-item-renderer",
  10341.  
  10342. "yt-live-chat-banner-header-renderer",
  10343. "yt-live-chat-text-message-renderer",
  10344. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  10345. "ytd-sponsorships-live-chat-header-renderer",
  10346. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  10347.  
  10348. "yt-live-chat-paid-sticker-renderer",
  10349. "yt-live-chat-viewer-engagement-message-renderer",
  10350. "yt-live-chat-paid-message-renderer"
  10351.  
  10352.  
  10353.  
  10354.  
  10355. ]).then(sTags => {
  10356.  
  10357. if (FLAG_001f) return;
  10358.  
  10359. mightFirstCheckOnYtInit();
  10360. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  10361. console.log("[Begin]");
  10362.  
  10363.  
  10364. const __showContextMenu_mutex__ = new Mutex();
  10365. let __showContextMenu_mutex_unlock__ = null;
  10366. let lastShowMenuTarget = null;
  10367.  
  10368.  
  10369.  
  10370.  
  10371. const wm37 = new WeakMap();
  10372.  
  10373. const dProto = {
  10374.  
  10375.  
  10376. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  10377.  
  10378. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  10379. if (a) {
  10380. if (doDeepCopy) a = deepCopy(a);
  10381. wm37.set(endpoint, a);
  10382. } else {
  10383. wm37.remove(endpoint);
  10384. }
  10385. },
  10386. __getCachedEndpointData__: function (endpoint) {
  10387. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  10388. if (endpoint) return wm37.get(endpoint);
  10389. return null;
  10390. },
  10391. /** @type {(resolvedEndpoint: any) => void 0} */
  10392. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  10393.  
  10394. resolvedEndpoint = deepCopy(resolvedEndpoint);
  10395. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  10396. Promise.resolve(resolvedEndpoint).then((resolvedEndpoint) => {
  10397. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  10398. this.showContextMenu_(resolvedEndpoint);
  10399. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  10400. resolvedEndpoint = null;
  10401. });
  10402.  
  10403.  
  10404. },
  10405.  
  10406.  
  10407.  
  10408. showContextMenuForCacheReopen: function (a) {
  10409. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37(a);
  10410. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10411. if (!this.__showContextMenu_forceNativeRequest__) {
  10412. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10413. if (endpoint) {
  10414. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  10415. if (resolvedEndpoint) {
  10416. this.__showCachedContextMenu__(resolvedEndpoint);
  10417. a && a.stopPropagation()
  10418. return;
  10419. }
  10420. }
  10421. }
  10422. return this.showContextMenu37(a);
  10423. },
  10424.  
  10425. showContextMenuForCacheReopen_: function (a) {
  10426. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37_(a);
  10427. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10428. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  10429. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10430. if (endpoint) {
  10431. const f = this.__cacheResolvedEndpointData__;
  10432. if (typeof f === 'function') f(endpoint, a, true);
  10433. }
  10434. }
  10435. return this.showContextMenu37_(a);
  10436. },
  10437.  
  10438. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  10439.  
  10440. showContextMenuWithDisableScroll: function (a) {
  10441.  
  10442. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10443. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  10444.  
  10445. const parentComponent = this.parentComponent;
  10446. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  10447. parentComponent.contextMenuOpen = true; // computeAllowScroll_(contextMenuOpen, moderationModeEnabled): allowScroll = !(contextMenuOpen || moderationModeEnabled)
  10448. }
  10449. }
  10450.  
  10451. return this.showContextMenu48.apply(this, arguments);
  10452.  
  10453. },
  10454.  
  10455. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  10456.  
  10457. __showContextMenu_mutex_unlock_isEmpty__: () => {
  10458. return __showContextMenu_mutex_unlock__ === null;
  10459. },
  10460.  
  10461. __showContextMenu_assign_lock__: function (p) {
  10462.  
  10463. const mutex = __showContextMenu_mutex__;
  10464.  
  10465. mutex.lockWith(unlock => {
  10466. p.then(unlock);
  10467. p = null;
  10468. unlock = null;
  10469. });
  10470.  
  10471. },
  10472.  
  10473. showContextMenuWithMutex: function (a) {
  10474. if (this.__showContextMenu_forceNativeRequest__) return this.showContextMenu47(a);
  10475. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10476. lastShowMenuTarget = this;
  10477. const wNode = mWeakRef(this);
  10478.  
  10479.  
  10480. const mutex = __showContextMenu_mutex__;
  10481.  
  10482. mutex.lockWith(unlock => {
  10483. const cnt = kRef(wNode);
  10484. if (lastShowMenuTarget !== cnt || !cnt) {
  10485. unlock();
  10486. return;
  10487. }
  10488.  
  10489. setTimeout(unlock, 800); // in case network failure
  10490. __showContextMenu_mutex_unlock__ = unlock;
  10491. try {
  10492. cnt.showContextMenu47(a);
  10493. } catch (e) {
  10494. console.warn(e);
  10495. unlock(); // in case function script error
  10496. }
  10497.  
  10498. });
  10499.  
  10500.  
  10501. },
  10502.  
  10503. showContextMenuWithMutex_: function (a) {
  10504.  
  10505. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  10506. __showContextMenu_mutex_unlock__();
  10507. __showContextMenu_mutex_unlock__ = null;
  10508. }
  10509. return this.showContextMenu47_(a);
  10510.  
  10511. }
  10512.  
  10513. }
  10514.  
  10515. for (const tag of sTags) { // ##tag##
  10516.  
  10517. (() => {
  10518.  
  10519. const dummy = document.createElement(tag);
  10520.  
  10521. const cProto = getProto(dummy);
  10522. if (!cProto || !cProto.attached) {
  10523. console.warn(`proto.attached for ${tag} is unavailable.`);
  10524. return;
  10525. }
  10526.  
  10527.  
  10528. 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) {
  10529. cProto.showContextMenu37_ = cProto.showContextMenu_;
  10530. cProto.showContextMenu37 = cProto.showContextMenu;
  10531. cProto.__showContextMenu_forceNativeRequest__ = 0;
  10532. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  10533. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  10534. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  10535. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  10536. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  10537. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  10538. } else {
  10539. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  10540. }
  10541.  
  10542. 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) {
  10543. cProto.showContextMenu48 = cProto.showContextMenu;
  10544. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  10545. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10546. } else if (!ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU) {
  10547. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - N/A", tag);
  10548. } else {
  10549. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10550. }
  10551.  
  10552.  
  10553. 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) {
  10554. cProto.showContextMenu47_ = cProto.showContextMenu_;
  10555. cProto.showContextMenu47 = cProto.showContextMenu;
  10556. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  10557. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  10558. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  10559. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  10560. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10561. } else {
  10562. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10563. }
  10564.  
  10565. })();
  10566.  
  10567. }
  10568.  
  10569. console.log("[End]");
  10570.  
  10571. console.groupEnd();
  10572.  
  10573. }).catch(console.warn);
  10574.  
  10575.  
  10576.  
  10577. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  10578.  
  10579. mightFirstCheckOnYtInit();
  10580. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  10581. console.log("[Begin]");
  10582. (() => {
  10583.  
  10584. const tag = "tp-yt-iron-dropdown";
  10585. const dummy = document.createElement(tag);
  10586.  
  10587. const cProto = getProto(dummy);
  10588. if (!cProto || !cProto.attached) {
  10589. console.warn(`proto.attached for ${tag} is unavailable.`);
  10590. return;
  10591. }
  10592.  
  10593. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  10594. cProto.__deraf_hn__ = function (sId, fn) {
  10595. const rhKey = `_rafHandler_${sId}`;
  10596. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  10597. if (m.has(fn)) return m.get(fn);
  10598. const resFn = () => {
  10599. this.__rafs[sId] = null;
  10600. fn.call(this)
  10601. };
  10602. m.set(fn, resFn);
  10603. m.set(resFn, resFn);
  10604. return resFn;
  10605. };
  10606. cProto.__deraf34 = cProto.__deraf;
  10607. cProto.__deraf = function (a, b) { // sId, fn
  10608. let c = this.__rafs;
  10609. null !== c[a] && cancelAnimationFrame(c[a]);
  10610. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  10611. };
  10612. console.log("USE_VANILLA_DEREF - OK");
  10613. } else {
  10614. console.log("USE_VANILLA_DEREF - NG");
  10615. }
  10616.  
  10617. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  10618. cProto.__deraf66 = cProto.__deraf;
  10619. cProto.__deraf = function (sId, fn) {
  10620. if (this.__byPassRAF__) {
  10621. Promise.resolve(this).then((cnt) => {
  10622. fn.call(cnt);
  10623. cnt = null;
  10624. });
  10625. }
  10626. let r = this.__deraf66.apply(this, arguments);
  10627. return r;
  10628. }
  10629. console.log("FIX_DROPDOWN_DERAF - OK");
  10630. } else {
  10631. console.log("FIX_DROPDOWN_DERAF - NG");
  10632. }
  10633.  
  10634.  
  10635. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  10636.  
  10637. let lastClose = null;
  10638. let lastOpen = null;
  10639. let cid = 0;
  10640.  
  10641. cProto.__mtChanged__ = function (b) {
  10642.  
  10643. Promise.resolve(this).then((cnt) => {
  10644. cnt._applyFocus();
  10645. return cnt;
  10646. }).then((cnt) => {
  10647. b ? cnt._renderOpened() : cnt._renderClosed();
  10648. cnt = null;
  10649. }).catch(console.warn);
  10650.  
  10651. };
  10652.  
  10653. const __moChanged__ = () => {
  10654. if (!cid) return;
  10655. // console.log(553, !!lastOpen, !!lastClose);
  10656. cid = 0;
  10657. if (lastOpen && !lastClose && lastOpen.isAttached) {
  10658. lastOpen.__mtChanged__(1)
  10659. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  10660. lastClose.__mtChanged__(0);
  10661. }
  10662. lastOpen = null;
  10663. lastClose = null;
  10664. };
  10665.  
  10666.  
  10667. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  10668. cProto._openedChanged66 = cProto._openedChanged;
  10669. cProto._openedChanged = function () {
  10670. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  10671. this.__byPassRAF__ = true;
  10672. let r = this._openedChanged66.apply(this, arguments);
  10673. this.__byPassRAF__ = false;
  10674. return r;
  10675. }
  10676. }
  10677.  
  10678. const pSetGet = (key, pdThis, pdBase) => {
  10679. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  10680. return {
  10681. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  10682. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  10683. };
  10684. };
  10685.  
  10686. cProto.__modifiedMenuPropsFn__ = function () {
  10687. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  10688. const pdBase = Object.getOwnPropertyDescriptors(this)
  10689.  
  10690. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  10691. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  10692. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  10693.  
  10694. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  10695. console.warn('there is setter/getter for autoFitOnAttach');
  10696. return;
  10697. }
  10698. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  10699. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  10700. return;
  10701. }
  10702. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  10703. console.warn('there is NO setter-getter for allowOutsideScroll');
  10704. return;
  10705. }
  10706.  
  10707. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  10708.  
  10709. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  10710.  
  10711. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  10712.  
  10713. Object.defineProperties(this, {
  10714. autoFitOnAttach: {
  10715. get() {
  10716. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10717. return autoFitOnAttach;
  10718. },
  10719. set(nv) {
  10720. autoFitOnAttach = nv;
  10721. return true;
  10722. },
  10723. enumerable: true,
  10724. configurable: true
  10725. }, expandSizingTargetForScrollbars: {
  10726. get() {
  10727. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10728. return expandSizingTargetForScrollbars;
  10729. },
  10730. set(nv) {
  10731. expandSizingTargetForScrollbars = nv;
  10732. return true;
  10733. },
  10734. enumerable: true,
  10735. configurable: true
  10736. }, allowOutsideScroll: {
  10737. get() {
  10738. if (this._modifiedMenuPropOn062__) return true;
  10739. return allowOutsideScroll;
  10740. },
  10741. set(nv) {
  10742. allowOutsideScroll = nv;
  10743. this.__AllowOutsideScrollPD__.set.call(this, nv);
  10744. return true;
  10745. },
  10746. enumerable: true,
  10747. configurable: true
  10748. }
  10749. })
  10750. };
  10751.  
  10752. /*
  10753. // ***** position() to be changed. *****
  10754. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  10755.  
  10756. overflow: visible !important;
  10757. min-width: max-content !important;
  10758. max-width: max-content !important;
  10759. max-height: max-content !important;
  10760. min-height: max-content !important;
  10761. white-space: nowrap;
  10762. }
  10763.  
  10764. */
  10765. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  10766.  
  10767. let m34 = 0;
  10768. cProto.__refitByPosition__ = function () {
  10769. m34++;
  10770. if (m34 <= 0) m34 = 0;
  10771. if (m34 !== 1) return;
  10772. const hostElement = this.hostElement || this;
  10773. if (document.visibilityState === 'visible') {
  10774. const sizingTarget = this.sizingTarget;
  10775. if (!sizingTarget) {
  10776. m34 = 0;
  10777. return;
  10778. }
  10779. hostElement.setAttribute('rNgzQ', '');
  10780. sizingTarget.setAttribute('rNgzQ', '');
  10781.  
  10782. const gn = () => {
  10783. hostElement.removeAttribute('rNgzQ');
  10784. sizingTarget.removeAttribute('rNgzQ');
  10785. }
  10786.  
  10787. const an = async () => {
  10788. while (m34 >= 1) {
  10789. await renderReadyPn(sizingTarget);
  10790. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  10791. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  10792. }
  10793. m34--;
  10794. }
  10795. m34 = 0;
  10796. Promise.resolve().then(gn);
  10797. }
  10798. setTimeout(an, 4); // wait those resizing function calls
  10799.  
  10800.  
  10801. } else {
  10802. m34 = 0;
  10803. }
  10804. }
  10805. cProto.position34 = cProto.position
  10806. cProto.position = function () {
  10807. if (this._positionInitialize_) {
  10808. this._positionInitialize_ = 0;
  10809. this.__refitByPosition__();
  10810. }
  10811. let r = cProto.position34.apply(this, arguments);
  10812. return r;
  10813. }
  10814. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  10815.  
  10816. } else {
  10817.  
  10818. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  10819.  
  10820. }
  10821.  
  10822.  
  10823.  
  10824. cProto.__openedChanged = function () {
  10825. this._positionInitialize_ = 1;
  10826. // this.removeAttribute('horizontal-align')
  10827. // this.removeAttribute('vertical-align')
  10828. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  10829. this.__menuTypeCheck__ = true;
  10830. if (CHAT_MENU_SCROLL_UNLOCKING) {
  10831. this._modifiedMenuPropOn062__ = false;
  10832. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10833. // this.autoFitOnAttach = true;
  10834. // this.expandSizingTargetForScrollbars = true;
  10835. // this.allowOutsideScroll = true;
  10836. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  10837. this.__modifiedMenuPropsFn__();
  10838. // this.constrain= function(){}
  10839. // this.position= function(){}
  10840.  
  10841. // this.autoFitOnAttach = true;
  10842. // this.expandSizingTargetForScrollbars = true;
  10843. // this.allowOutsideScroll = true;
  10844. }
  10845. }
  10846. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  10847. let newValue = null;
  10848. const positionTarget = this.positionTarget;
  10849. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  10850. if (this._modifiedMenuPropOn062__ === false) {
  10851. newValue = true;
  10852. }
  10853. } else if (this._modifiedMenuPropOn062__ === true) {
  10854. newValue = false;
  10855. }
  10856. if (newValue !== null) {
  10857. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  10858. this._modifiedMenuPropOn062__ = newValue;
  10859. const afterAllowOutsideScroll = this.allowOutsideScroll;
  10860. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  10861. }
  10862. }
  10863.  
  10864. if (this.opened) {
  10865.  
  10866. Promise.resolve().then(() => {
  10867.  
  10868. this._prepareRenderOpened();
  10869. }).then(() => {
  10870. this._manager.addOverlay(this);
  10871. if (this._manager._overlays.length === 1) {
  10872. lastOpen = this;
  10873. lastClose = null;
  10874. } else {
  10875. return 1;
  10876. }
  10877. // if (cid) {
  10878. // clearTimeout(cid);
  10879. // cid = -1;
  10880. // this.__moChanged__();
  10881. // cid = 0;
  10882. // } else {
  10883. // cid = -1;
  10884. // this.__moChanged__();
  10885. // cid = 0;
  10886. // }
  10887. // cid = cid > 0 ? clearTimeout(cid) : 0;
  10888. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10889. // cid = cid || setTimeout(__moChanged__, delay1);
  10890. cid = cid || requestAnimationFrame(__moChanged__);
  10891. }).then((r) => {
  10892.  
  10893. if (r) this.__mtChanged__(1);
  10894. }).catch(console.warn);
  10895.  
  10896. } else {
  10897. Promise.resolve().then(() => {
  10898. this._manager.removeOverlay(this);
  10899. if (this._manager._overlays.length === 0) {
  10900. lastClose = this;
  10901. lastOpen = null;
  10902. } else {
  10903. return 1;
  10904. }
  10905. // cid = cid > 0 ? clearTimeout(cid) : 0;
  10906. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10907. // cid = cid || setTimeout(__moChanged__, delay1);
  10908. cid = cid || requestAnimationFrame(__moChanged__);
  10909. }).then((r) => {
  10910. if (r) this.__mtChanged__(0);
  10911. }).catch(console.warn);
  10912.  
  10913. }
  10914.  
  10915. }
  10916. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  10917.  
  10918. } else {
  10919.  
  10920. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  10921. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  10922.  
  10923. }
  10924.  
  10925.  
  10926. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  10927.  
  10928. cProto.__openedChanged82 = cProto.__openedChanged;
  10929.  
  10930.  
  10931. cProto.__openedChanged = function () {
  10932. const positionTarget = this.positionTarget;
  10933. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  10934. return this.__openedChanged82.apply(this, arguments);
  10935. }
  10936. }
  10937.  
  10938.  
  10939. })();
  10940.  
  10941. console.log("[End]");
  10942.  
  10943. console.groupEnd();
  10944.  
  10945. }).catch(console.warn);
  10946.  
  10947.  
  10948.  
  10949. FIX_ToggleRenderPolymerControllerExtractionBug && customElements.whenDefined('yt-live-chat-toggle-renderer').then(() => {
  10950.  
  10951. mightFirstCheckOnYtInit();
  10952. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-toggle-renderer hacks");
  10953. console.log("[Begin]");
  10954. (() => {
  10955.  
  10956. const tag = "yt-live-chat-toggle-renderer";
  10957. const dummy = document.createElement(tag);
  10958.  
  10959. const cProto = getProto(dummy);
  10960. if (!cProto || !cProto.attached) {
  10961. console.warn(`proto.attached for ${tag} is unavailable.`);
  10962. return;
  10963. }
  10964.  
  10965. })();
  10966.  
  10967. console.log("[End]");
  10968. console.groupEnd();
  10969.  
  10970. });
  10971.  
  10972.  
  10973.  
  10974.  
  10975. /*
  10976.  
  10977.  
  10978.  
  10979.  
  10980.  
  10981. var FU = function() {
  10982. var a = this;
  10983. this.nextHandle_ = 1;
  10984. this.clients_ = {};
  10985. this.JSC$10323_callbacks_ = {};
  10986. this.unsubscribeAsyncHandles_ = {};
  10987. this.subscribe = vl(function(b, c, d) {
  10988. var e = Geb(b);
  10989. if (e in a.clients_)
  10990. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  10991. else {
  10992. a: {
  10993. var h = Geb(b), l;
  10994. for (l in a.unsubscribeAsyncHandles_) {
  10995. var m = a.clients_[l];
  10996. if (m instanceof KO) {
  10997. delete a.clients_[l];
  10998. delete a.JSC$10323_callbacks_[l];
  10999. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  11000. delete a.unsubscribeAsyncHandles_[l];
  11001. i6a(m);
  11002. m.objectId_ = new FQa(h);
  11003. m.register();
  11004. d = m;
  11005. break a
  11006. }
  11007. }
  11008. d.objectSource = b.invalidationId.objectSource;
  11009. d.objectId = h;
  11010. if (b = b.webAuthConfigurationData)
  11011. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  11012. b.pageId && (d.pageId = b.pageId);
  11013. d = new KO(d,a.handleInvalidationData_.bind(a));
  11014. d.register()
  11015. }
  11016. a.clients_[e] = d;
  11017. a.JSC$10323_callbacks_[e] = {}
  11018. }
  11019. d = a.nextHandle_++;
  11020. a.JSC$10323_callbacks_[e][d] = c;
  11021. return d
  11022. })
  11023. };
  11024. FU.prototype.unsubscribe = function(a, b) {
  11025. var c = Geb(a);
  11026. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  11027. !this.JSC$10323_callbacks_[c].length)) {
  11028. var d = this.clients_[c];
  11029. b = Jq.run(function() {
  11030. ei(d);
  11031. delete this.clients_[c];
  11032. delete this.unsubscribeAsyncHandles_[c]
  11033. }
  11034. .bind(this));
  11035. this.unsubscribeAsyncHandles_[c] = b
  11036. }
  11037. }
  11038. ;
  11039.  
  11040.  
  11041. */
  11042.  
  11043.  
  11044. const onManagerFound = (dummyManager) => {
  11045. if (!dummyManager || typeof dummyManager !== 'object') return;
  11046.  
  11047. const mgrProto = dummyManager.constructor.prototype;
  11048.  
  11049. let keyCallbackStore = '';
  11050. for (const [key, v] of Object.entries(dummyManager)) {
  11051. if (key.includes('_callbacks_')) keyCallbackStore = key;
  11052. }
  11053.  
  11054. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  11055.  
  11056. if (mgrProto.unsubscribe16) return;
  11057.  
  11058. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  11059.  
  11060. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  11061. console.log("[Begin]");
  11062.  
  11063. const isEmptyObject = ((obj) => (firstKey(obj) === null));
  11064.  
  11065. const idMapper = new Map();
  11066.  
  11067. const convertId = function (objectId) {
  11068. if (!objectId || typeof objectId !== 'string') return null;
  11069.  
  11070. let result = idMapper.get(objectId)
  11071. if (result) return result;
  11072. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  11073. idMapper.set(objectId, result)
  11074. return result;
  11075. }
  11076.  
  11077.  
  11078. const rafHandleHolder = [];
  11079.  
  11080. let pzw = 0;
  11081. let lza = 0;
  11082. const rafHandlerFn = () => {
  11083. pzw = 0;
  11084. if (rafHandleHolder.length === 1) {
  11085. const f = rafHandleHolder[0];
  11086. rafHandleHolder.length = 0;
  11087. f();
  11088. } else if (rafHandleHolder.length > 1) {
  11089. const arr = rafHandleHolder.slice(0);
  11090. rafHandleHolder.length = 0;
  11091. for (const fn of arr) fn();
  11092. }
  11093. };
  11094.  
  11095.  
  11096. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  11097.  
  11098. const checkIntegrityForSubscribe = (mgr) => {
  11099. if (mgr
  11100. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  11101. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  11102.  
  11103. const ns = new Set(Object.keys(mgr));
  11104. const ms = new Set(Object.keys(mgr.constructor.prototype));
  11105.  
  11106. if (ns.size >= 6 && ms.size >= 4) {
  11107. // including 'subscribe18'
  11108. // 'unsubscribe16', 'subscribe19'
  11109.  
  11110. let r = 0;
  11111. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  11112. r += ns.has(k) ? 1 : 0;
  11113. }
  11114. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  11115. r += ms.has(k) ? 1 : 0;
  11116. }
  11117. if (r === 10) {
  11118. const isObject = (c) => (c || 0).constructor === Object;
  11119.  
  11120. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  11121.  
  11122. return true;
  11123. }
  11124.  
  11125.  
  11126. }
  11127.  
  11128. }
  11129.  
  11130.  
  11131. }
  11132. return false;
  11133. }
  11134.  
  11135. mgrProto.subscribe19 = function (o, f, opts) {
  11136.  
  11137. const ct_clients_ = this.clients_ || 0;
  11138. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  11139.  
  11140. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  11141.  
  11142. let objectId = ((o || 0).invalidationId || 0).objectId;
  11143. if (!objectId) return this.subscribe18.apply(this, arguments);
  11144. objectId = convertId(objectId);
  11145.  
  11146. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  11147.  
  11148. if (ct_clients_[objectId]) {
  11149. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  11150. }
  11151.  
  11152. return this.subscribe18.apply(this, arguments);
  11153. }
  11154.  
  11155. mgrProto.unsubscribe = function (o, d) {
  11156. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  11157. this.subscribe18 = this.subscribe;
  11158. this.subscribe = this.subscribe19;
  11159. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  11160. }
  11161. const ct_clients_ = this.clients_;
  11162. const ct_handles_ = this.unsubscribeAsyncHandles_;
  11163. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  11164.  
  11165. let objectId = ((o || 0).invalidationId || 0).objectId;
  11166. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  11167.  
  11168. objectId = convertId(objectId);
  11169.  
  11170.  
  11171. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  11172.  
  11173. const callbacks = this[keyCallbackStore] || 0;
  11174. const callbackObj = callbacks[objectId] || 0;
  11175.  
  11176.  
  11177. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  11178. const w = ct_clients_[objectId];
  11179. --lza;
  11180. if (lza < -1e9) lza = -1;
  11181. const qta = lza;
  11182. rafHandleHolder.push(() => {
  11183. if (qta === ct_handles_[objectId]) {
  11184. const o = {
  11185. callbacks, callbackObj,
  11186. client: ct_clients_[objectId],
  11187. handle: ct_handles_[objectId]
  11188. };
  11189. let p = 0;
  11190. try {
  11191. if (ct_clients_[objectId] === w) {
  11192. w && "function" === typeof w.dispose && w.dispose();
  11193. delete ct_clients_[objectId];
  11194. delete ct_handles_[objectId];
  11195. p = 1;
  11196. } else {
  11197. // w && "function" === typeof w.dispose && w.dispose();
  11198. // delete ct_clients_[objectId];
  11199. // delete ct_handles_[objectId];
  11200. p = 2;
  11201. }
  11202. } catch (e) {
  11203. console.warn(e);
  11204. }
  11205. console.log(`unsubscribed: ${p}`, this, o);
  11206. }
  11207. });
  11208. ct_handles_[objectId] = qta;
  11209. if (pzw === 0) {
  11210. pzw = requestAnimationFrame(rafHandlerFn);
  11211. }
  11212. }
  11213. }
  11214.  
  11215.  
  11216. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  11217.  
  11218. } else {
  11219.  
  11220. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  11221. }
  11222.  
  11223. console.log("[End]");
  11224.  
  11225. console.groupEnd();
  11226.  
  11227. }
  11228.  
  11229.  
  11230.  
  11231. /*
  11232.  
  11233.  
  11234. a.prototype.async = function(e, h) {
  11235. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  11236. }
  11237. ;
  11238. a.prototype.cancelAsync = function(e) {
  11239. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  11240. }
  11241.  
  11242. */
  11243.  
  11244.  
  11245. (FASTER_ICON_RENDERING && Promise.all(
  11246. [
  11247. customElements.whenDefined("yt-icon-shape"),
  11248. customElements.whenDefined("yt-icon")
  11249. // document.createElement('icon-shape'),
  11250. ]
  11251. )).then(() => {
  11252. let cq = 0;
  11253. let dummys = [document.createElement('yt-icon-shape'), document.createElement('yt-icon')]
  11254. for (const dummy of dummys) {
  11255. let cProto = getProto(dummy);
  11256. if (cProto && typeof cProto.shouldRenderIconShape === 'function' && !cProto.shouldRenderIconShape571 && cProto.shouldRenderIconShape.length === 1) {
  11257. assertor(() => fnIntegrity(cProto.shouldRenderIconShape, '1.70.38'));
  11258. cq++;
  11259. cProto.shouldRenderIconShape571 = cProto.shouldRenderIconShape;
  11260. cProto.shouldRenderIconShape = function (a) {
  11261. if (this.isAnimatedIcon) return this.shouldRenderIconShape571(a);
  11262. if (!this.iconType || !this.iconShapeData) return this.shouldRenderIconShape571(a);
  11263. if (!this.iconName) return this.shouldRenderIconShape571(a);
  11264. return false;
  11265. // console.log(1051, this.iconType)
  11266. // console.log(1052, this.iconShapeData)
  11267. // console.log(1053, this.isAnimatedIcon)
  11268. }
  11269. }
  11270. // if(cProto && cProto.switchTemplateAtRegistration){
  11271. // cProto.switchTemplateAtRegistration = false;
  11272. // }
  11273. }
  11274. if (cq === 1) {
  11275. console.log("modified shouldRenderIconShape - Y")
  11276. } else {
  11277. console.log("modified shouldRenderIconShape - N", cq)
  11278. }
  11279. });
  11280.  
  11281. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  11282.  
  11283. let __dummyManager__ = null;
  11284.  
  11285. mightFirstCheckOnYtInit();
  11286. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  11287. console.log("[Begin]");
  11288. (() => {
  11289.  
  11290. const tag = "yt-invalidation-continuation"
  11291. const dummy = document.createElement(tag);
  11292.  
  11293. const cProto = getProto(dummy);
  11294. if (!cProto || !cProto.attached) {
  11295. console.warn(`proto.attached for ${tag} is unavailable.`);
  11296. return;
  11297. }
  11298.  
  11299. const dummyManager = insp(dummy).manager_ || 0;
  11300. __dummyManager__ = dummyManager;
  11301.  
  11302. 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) {
  11303.  
  11304.  
  11305. const rafHub = new RAFHub();
  11306.  
  11307. rafHub.keepRAF = true;
  11308. cProto.async71 = cProto.async;
  11309. cProto.cancelAsync71 = cProto.cancelAsync;
  11310.  
  11311. // mostly for subscription timeoutMs 10000ms
  11312. let mcw = 1; // 1, 3, 5, ...
  11313. let arr = new Map();
  11314.  
  11315. let __asyncInited__ = 0;
  11316. let __timeoutStartId__ = null;
  11317. const __asyncInit__ = () => {
  11318.  
  11319. if (__asyncInited__) return;
  11320. __asyncInited__ = 1;
  11321.  
  11322. __timeoutStartId__ = setTimeout(() => { });
  11323. mcw = __timeoutStartId__ * 2 + 1;
  11324.  
  11325. setInterval(() => {
  11326.  
  11327. if (!arr.length) return;
  11328.  
  11329. const p = Date.now();
  11330. let deleteKeys = [];
  11331. arr.forEach((entry, key) => {
  11332.  
  11333.  
  11334. if (entry.cid === -1) {
  11335. entry.cid = -2;
  11336. } else if (entry.cid === -2) {
  11337.  
  11338. let offset = p - entry.add
  11339. if (offset < 0) offset = 0;
  11340. let delay2 = entry.delay - offset;
  11341. if (delay2 < 0) delay2 = 0;
  11342. entry.cid = setTimeout(entry.q(), delay2);
  11343. entry.q = null;
  11344.  
  11345. } else if (entry.add + entry.delay < p) {
  11346. deleteKeys.push(key);
  11347.  
  11348. }
  11349.  
  11350. })
  11351.  
  11352. for (const key of deleteKeys) arr.delete(key);
  11353.  
  11354. }, 2000)
  11355.  
  11356. }
  11357.  
  11358.  
  11359. cProto.async = function (e, h) {
  11360.  
  11361. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  11362.  
  11363. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  11364.  
  11365. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  11366.  
  11367.  
  11368. if (!this.__asyncInited__) {
  11369. this.__asyncInited__ = 1;
  11370. __asyncInit__();
  11371. }
  11372. mcw += 2; // 2K+3, 2K+4, ...
  11373. if (mcw > 1e9) mcw = mcw % 1e4;
  11374. const cid = mcw;
  11375. const q = () => {
  11376. return () => {
  11377. console.log('async h > 8000');
  11378. e.call(this);
  11379. }
  11380. }
  11381. // setTimeout(q, delay)
  11382. arr.set(cid, {
  11383. cid: -1, // -1 -> -2 -> cid
  11384. add: Date.now(),
  11385. q,
  11386. delay: h
  11387. });
  11388. // console.log('cid-async', cid)
  11389. return cid;
  11390.  
  11391. }
  11392.  
  11393.  
  11394. cProto.cancelAsync = function (e) {
  11395.  
  11396. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  11397.  
  11398. // console.log('cid-unasync', e)
  11399.  
  11400. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  11401.  
  11402. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  11403.  
  11404. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  11405.  
  11406. if (!arr.has(e)) return; // duplciated cancel
  11407.  
  11408. const entry = arr.get(e);
  11409. if (entry.cid < 0) {
  11410. entry.cid = 0;
  11411. arr.delete(e);
  11412. } else {
  11413. clearTimeout(entry.cid); // cid >= 1
  11414. entry.cid = 0;
  11415. arr.delete(e);
  11416. }
  11417.  
  11418. } else {
  11419.  
  11420. return this.cancelAsync71(e);
  11421.  
  11422. }
  11423.  
  11424. }
  11425.  
  11426. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  11427.  
  11428. } else if(!CHANGE_DATA_FLUSH_ASYNC){
  11429. console.log("CHANGE_DATA_FLUSH_ASYNC - N/A");
  11430. } else {
  11431. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  11432.  
  11433. }
  11434.  
  11435. })();
  11436.  
  11437. console.log("[End]");
  11438.  
  11439. console.groupEnd();
  11440.  
  11441.  
  11442.  
  11443. onManagerFound(__dummyManager__);
  11444.  
  11445. }).catch(console.warn);
  11446.  
  11447.  
  11448. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  11449.  
  11450. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  11451.  
  11452. mightFirstCheckOnYtInit();
  11453. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  11454. console.log("[Begin]");
  11455. (() => {
  11456.  
  11457. const tag = "yt-live-interactivity-component-background"
  11458. const dummy = document.createElement(tag);
  11459.  
  11460. const cProto = getProto(dummy);
  11461. if (!cProto || !cProto.attached) {
  11462. console.warn(`proto.attached for ${tag} is unavailable.`);
  11463. return;
  11464. }
  11465.  
  11466. cProto.__toStopAfterRun__ = function (hostElement) {
  11467. let mo = new MutationObserver(() => {
  11468. mo.disconnect();
  11469. mo.takeRecords();
  11470. mo = null;
  11471. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  11472. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  11473. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  11474. });
  11475. });
  11476. mo.observe(hostElement, { subtree: true, childList: true });
  11477. }
  11478.  
  11479. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  11480.  
  11481. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  11482. cProto.maybeLoadAnimationBackground = function () {
  11483. let toRun = true;
  11484. let stopAfterRun = false;
  11485. if (!this.__bypassDisableAnimationBackground__) {
  11486. let doFix = false;
  11487. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  11488. if (!this.lottieAnimation) {
  11489. doFix = true;
  11490. }
  11491. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  11492. doFix = true;
  11493. }
  11494. if (doFix) {
  11495. if (this.useAnimationBackground === true) {
  11496. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  11497. }
  11498. toRun = true;
  11499. stopAfterRun = true;
  11500. }
  11501. }
  11502. if (toRun) {
  11503. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  11504. this.__toStopAfterRun__(this.hostElement); // primary
  11505. }
  11506. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  11507. if (stopAfterRun && this.lottieAnimation) {
  11508. this.lottieAnimation.stop(); // fallback if no mutation
  11509. }
  11510. return r;
  11511. }
  11512. }
  11513.  
  11514. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - OK`);
  11515.  
  11516. } else {
  11517. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - NG`);
  11518.  
  11519. }
  11520.  
  11521. })();
  11522.  
  11523. console.log("[End]");
  11524.  
  11525. console.groupEnd();
  11526.  
  11527.  
  11528. }).catch(console.warn);
  11529.  
  11530. }
  11531.  
  11532.  
  11533. if (DELAY_FOCUSEDCHANGED) {
  11534.  
  11535. customElements.whenDefined("yt-live-chat-text-input-field-renderer").then(() => {
  11536.  
  11537.  
  11538. mightFirstCheckOnYtInit();
  11539. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-input-field-renderer hacks");
  11540. console.log("[Begin]");
  11541. (() => {
  11542.  
  11543. const tag = "yt-live-chat-text-input-field-renderer"
  11544. const dummy = document.createElement(tag);
  11545.  
  11546. const cProto = getProto(dummy);
  11547. if (!cProto || !cProto.attached) {
  11548. console.warn(`proto.attached for ${tag} is unavailable.`);
  11549. return;
  11550. }
  11551.  
  11552. if (DELAY_FOCUSEDCHANGED && typeof cProto.focusedChanged === 'function' && cProto.focusedChanged.length === 0 && !cProto.focusedChanged372) {
  11553. cProto.focusedChanged372 = cProto.focusedChanged;
  11554. cProto.focusedChanged = function () {
  11555. Promise.resolve(this).then((cnt) => {
  11556. if (cnt.isAttached === true) cnt.focusedChanged372();
  11557. });
  11558. }
  11559. }
  11560.  
  11561. })();
  11562.  
  11563. console.log("[End]");
  11564.  
  11565. console.groupEnd();
  11566.  
  11567. });
  11568.  
  11569. }
  11570.  
  11571.  
  11572. }
  11573.  
  11574.  
  11575.  
  11576.  
  11577. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  11578.  
  11579. const fixJsonParse = () => {
  11580.  
  11581. let p1 = window.onerror;
  11582.  
  11583. try {
  11584. JSON.parse("{}");
  11585. } catch (e) {
  11586. console.warn(e);
  11587. }
  11588.  
  11589. let p2 = window.onerror;
  11590.  
  11591. if (p1 !== p2) {
  11592.  
  11593.  
  11594. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  11595. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  11596. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  11597. );
  11598.  
  11599. 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");
  11600.  
  11601. console.groupEnd();
  11602.  
  11603. }
  11604.  
  11605. }
  11606.  
  11607. if (CHECK_JSONPRUNE) {
  11608. promiseForCustomYtElementsReady.then(fixJsonParse);
  11609. }
  11610.  
  11611. if(END_ANIMATING_TICKERS){
  11612.  
  11613. let lastElmW = null;
  11614.  
  11615. document.addEventListener('transitionstart', (evt) => {
  11616.  
  11617. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  11618.  
  11619. const elm = evt.target;
  11620. let act = false;
  11621. /*
  11622. switch(elm.nodeName.toLowerCase()){
  11623.  
  11624. case 'yt-live-chat-ticker-creator-goal-view-model':
  11625. case 'yt-live-chat-ticker-paid-message-item-renderer':
  11626. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  11627.  
  11628. case 'yt-live-chat-ticker-sponsor-item-renderer':
  11629. act =true;
  11630. break;
  11631.  
  11632.  
  11633. }
  11634. */
  11635. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  11636. act = true;
  11637. }
  11638. if (act) {
  11639. const lastElm = kRef(lastElmW);
  11640. if (elm !== lastElm) {
  11641.  
  11642. if (lastElm instanceof HTMLElement) {
  11643. lastElm.classList.add('ticker-no-transition-time');
  11644. }
  11645. lastElmW = mWeakRef(elm);
  11646.  
  11647. }
  11648.  
  11649.  
  11650. }
  11651. }
  11652.  
  11653. }, true);
  11654.  
  11655.  
  11656.  
  11657. document.addEventListener('transitionend', (evt) => {
  11658.  
  11659. if (evt.propertyName && !evt.pseudoElement) {
  11660.  
  11661. const elm = evt.target;
  11662. const f = transitionEndAfterFnSimple.get(elm);
  11663. if (f) {
  11664. transitionEndAfterFnSimple.delete(elm);
  11665. f.resolve(evt.propertyName);
  11666. }
  11667. }
  11668.  
  11669. }, true);
  11670.  
  11671. /*
  11672.  
  11673. document.addEventListener('transitionend', (evt) => {
  11674.  
  11675. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  11676.  
  11677. const elm = evt.target;
  11678. let act = false;
  11679. /-*
  11680. switch(elm.nodeName.toLowerCase()){
  11681.  
  11682. case 'yt-live-chat-ticker-creator-goal-view-model':
  11683. case 'yt-live-chat-ticker-paid-message-item-renderer':
  11684. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  11685.  
  11686. case 'yt-live-chat-ticker-sponsor-item-renderer':
  11687. act =true;
  11688. break;
  11689.  
  11690.  
  11691. }
  11692. *-/
  11693. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  11694. act = true;
  11695. }
  11696. if (act) {
  11697. elm.style.transitionDuration = '0s';
  11698.  
  11699. }
  11700. }
  11701.  
  11702. }, true);
  11703.  
  11704.  
  11705. document.addEventListener('transitioncancel', (evt) => {
  11706.  
  11707. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  11708.  
  11709. const elm = evt.target;
  11710. let act = false;
  11711. /-*
  11712. switch(elm.nodeName.toLowerCase()){
  11713.  
  11714. case 'yt-live-chat-ticker-creator-goal-view-model':
  11715. case 'yt-live-chat-ticker-paid-message-item-renderer':
  11716. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  11717.  
  11718. case 'yt-live-chat-ticker-sponsor-item-renderer':
  11719. act =true;
  11720. break;
  11721.  
  11722.  
  11723. }
  11724. *-/
  11725. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  11726. act = true;
  11727. }
  11728. if (act) {
  11729. elm.style.transitionDuration = '0s';
  11730.  
  11731. }
  11732. }
  11733.  
  11734. }, true);
  11735.  
  11736. */
  11737.  
  11738.  
  11739. }
  11740.  
  11741. });
  11742.  
  11743.  
  11744.  
  11745. })({ IntersectionObserver });