YouTube 超快聊天

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

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

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.66.4
  4. // @license MIT
  5. // @name:ja YouTube スーパーファーストチャット
  6. // @name:zh-TW YouTube 超快聊天
  7. // @name:zh-CN YouTube 超快聊天
  8. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/super-fast-chat.png
  9. // @namespace UserScript
  10. // @match https://www.youtube.com/live_chat*
  11. // @match https://www.youtube.com/live_chat_replay*
  12. // @author CY Fung
  13. // @run-at document-start
  14. // @grant none
  15. // @unwrap
  16. // @allFrames true
  17. // @inject-into page
  18. // @require https://update.greasyfork.org/scripts/475632/1361351/ytConfigHacks.js
  19. //
  20. // @compatible firefox Violentmonkey
  21. // @compatible firefox Tampermonkey
  22. // @compatible firefox FireMonkey
  23. // @compatible chrome Violentmonkey
  24. // @compatible chrome Tampermonkey
  25. // @compatible opera Violentmonkey
  26. // @compatible opera Tampermonkey
  27. // @compatible safari Stay
  28. // @compatible edge Violentmonkey
  29. // @compatible edge Tampermonkey
  30. // @compatible brave Violentmonkey
  31. // @compatible brave Tampermonkey
  32. //
  33. // @description Ultimate Performance Boost for YouTube Live Chats
  34. // @description:ja YouTubeのライブチャットの究極のパフォーマンスブースト
  35. // @description:zh-TW YouTube直播聊天的終極性能提升
  36. // @description:zh-CN YouTube直播聊天的终极性能提升
  37. //
  38. // ==/UserScript==
  39.  
  40. ((__CONTEXT__) => {
  41. 'use strict';
  42.  
  43. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  44.  
  45. // *********** DON'T REPORT NOT WORKING DUE TO THE CHANGED SETTINGS ********************
  46. // The settings are FIXED! You might change them to try but if the script does not work due to your change, please, don't report them as issues
  47.  
  48. const ENABLE_REDUCED_MAXITEMS_FOR_FLUSH = true; // TRUE to enable trimming down to MAX_ITEMS_FOR_FULL_FLUSH (25) messages when there are too many unrendered messages
  49. const MAX_ITEMS_FOR_TOTAL_DISPLAY = 90; // By default, 250 latest messages will be displayed, but displaying MAX_ITEMS_FOR_TOTAL_DISPLAY (90) messages is already sufficient. (not exceeding 900)
  50. const MAX_ITEMS_FOR_FULL_FLUSH = 25; // If there are too many new (stacked) messages not yet rendered, clean all and flush MAX_ITEMS_FOR_FULL_FLUSH (25) latest messages then incrementally added back to MAX_ITEMS_FOR_TOTAL_DISPLAY (90) messages. (not exceeding 900)
  51.  
  52. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages <<< DON'T CHANGE >>>
  53. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  54. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  55.  
  56. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  57. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  58. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  59. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  60.  
  61. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  62. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  63.  
  64. // Replace requestAnimationFrame timers with custom implementation
  65. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  66. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  67. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  68. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  69.  
  70. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  71. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  72.  
  73. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  74. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  75.  
  76. // Data Manipulation for Participants (Participant List)
  77. // << if DO_PARTICIPANT_LIST_HACKS >>
  78. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  79. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  80. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  81. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  82. // << end >>
  83.  
  84. // show more button
  85. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  86.  
  87. // faster stampDomArray_ for participants list creation
  88. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  89. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  90.  
  91. // reuse yt components
  92. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  93.  
  94. // ShadyDom Free is buggy
  95. const DISABLE_FLAGS_SHADYDOM_FREE = true;
  96.  
  97. // images <Group#I01>
  98. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  99. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  100. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  101.  
  102. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  103. // << if DO_LINK_PREFETCH >>
  104. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  105. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  106. const SKIP_PRELOAD_EMOJI = true;
  107. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  108. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  109. // << end >>
  110.  
  111. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  112. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  113. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  114.  
  115. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  116. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  117.  
  118. const ATTEMPT_ANIMATED_TICKER_BACKGROUND = ''; // false OR '' for disabled, 'linear', 'steps' for easing-function
  119. // <<<< ATTEMPT_ANIMATED_TICKER_BACKGROUND to be reviewed with memory leakage issues >>>>
  120. // << if ATTEMPT_ANIMATED_TICKER_BACKGROUND >>
  121. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  122. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  123. // [limiting 500 max steps] is recommended for "confortable visual change"
  124. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  125. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  126. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  127. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  128. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  129. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  130. const SKIP_VIDEO_PLAYBACK_PROGRESS_STATE_FIX_FOR_NO_TIMEFX = false; // debug use; yt-live-chat-ticker-renderer might not require ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX
  131. // << end >>
  132.  
  133. const FIX_TOOLTIP_DISPLAY = true; // changed in 2024.05.02
  134. const USE_VANILLA_DEREF = true;
  135. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  136.  
  137.  
  138. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  139. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = false; // pause auto scroll faster when the context menu is about to show
  140. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  141.  
  142. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  143. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  144. const NO_ITEM_TAP_FOR_NON_STATIONARY_TAP = true; // dont open the menu (e.g. text message) if cursor is moved or long press
  145. const TAP_ACTION_DURATION = 280; // exceeding 280ms would not consider as a tap action
  146. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  147. // const FIX_MENU_CAPTURE_SCROLL = true;
  148. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  149.  
  150. const RAF_FIX_keepScrollClamped = true;
  151. const RAF_FIX_scrollIncrementally = 2; // 0: no action; 1: basic fix; 2: also fix scroll position
  152.  
  153. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  154. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  155.  
  156. const CHECK_JSONPRUNE = true; // This is a bug in Brave
  157. // << end >>
  158.  
  159. // const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = false;
  160.  
  161. const CHANGE_DATA_FLUSH_ASYNC = false;
  162. // CHANGE_DATA_FLUSH_ASYNC is disabled due to bug report: https://greasyfork.org/scripts/469878/discussions/199479
  163. // to be further investigated
  164.  
  165. const CHANGE_MANAGER_UNSUBSCRIBE = true;
  166.  
  167. const INTERACTIVITY_BACKGROUND_ANIMATION = 1; // mostly for pinned message
  168. // 0 = default Yt animation background [= no fix];
  169. // 1 = disable default animation background [= keep special animation];
  170. // 2 = disable all animation backgrounds [= no animation backbround]
  171.  
  172. const CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED = true;
  173.  
  174. const MAX_TOOLTIP_NO_WRAP_WIDTH = '72vw'; // '' for disable; accept values like '60px', '25vw'
  175.  
  176.  
  177.  
  178. // (Dec 2024: AMEND_TICKER_handleLiveChatAction to be removed)
  179. const AMEND_TICKER_handleLiveChatAction = false; // to fix ticker duplication and unresponsively fast ticker generation
  180. // AMEND_TICKER_handleLiveChatAction to be fixed (2024.05.21)
  181.  
  182. // (Dec 2024: AMEND_TICKER_handleLiveChatAction_v3 to be removed)
  183. const AMEND_TICKER_handleLiveChatAction_v3 = true; // responsiveness fix (Major Feature)
  184.  
  185. const USE_ADVANCED_TICKING = true; // added in Dec 2024; need to ensure it would not affect the function if ticker design changed. to be reviewed
  186.  
  187.  
  188.  
  189.  
  190. const ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION = true;
  191. const ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME = true;
  192. const FIX_BATCH_TICKER_ORDER = true;
  193.  
  194. const DISABLE_Translation_By_Google = true;
  195.  
  196. const FASTER_ICON_RENDERING = true;
  197.  
  198. const DELAY_FOCUSEDCHANGED = true;
  199.  
  200. const skipErrorForhandleAddChatItemAction_ = true; // currently depends on ENABLE_NO_SMOOTH_TRANSFORM
  201. const fixChildrenIssue801 = true; // if __children801__ is set [fix polymer controller method extration for `.set()`]
  202.  
  203. const SUPPRESS_refreshOffsetContainerHeight_ = true; // added in FEB 2024; true for default layout options; no effect if ENABLE_NO_SMOOTH_TRANSFORM is false
  204.  
  205. const NO_FILTER_DROPDOWN_BORDER = true; // added in 2024.03.02
  206.  
  207. const FIX_ANIMATION_TICKER_TEXT_POSITION = true; // CSS fix; experimental; added in 2024.04.07
  208. const FIX_AUTHOR_CHIP_BADGE_POSITION = true;
  209.  
  210. const FIX_ToggleRenderPolymerControllerExtractionBug = false; // to be reviewed
  211.  
  212. const REACTION_ANIMATION_PANEL_CSS_FIX = true;
  213.  
  214. // -------------------------------
  215.  
  216.  
  217. const FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP = true; // To fix Memory Leakage in yt-live-chat-ticker-...-item-renderer
  218. const FIX_MEMORY_LEAKAGE_TICKER_STATSBAR = true; // To fix Memory Leakage in updateStatsBarAndMaybeShowAnimation
  219. const FIX_MEMORY_LEAKAGE_TICKER_TIMER = true; // To fix Memory Leakage in setContainerWidth, slideDown, collapse
  220. const FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth = true; // To fix Memory Leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth()
  221.  
  222. // leakage in ytd-sponsorships-live-chat-gift-purchase-announcement-renderer - to be confirmed
  223.  
  224. // <<<<< FOR MEMORY LEAKAGE >>>>
  225. const DEBUG_wmList = false;
  226. let DEBUG_wmList_started = false;
  227. // const FLAG_001 = true;
  228. const FLAG_001a = false;
  229. const FLAG_001b = false;
  230. const FLAG_001c = false;
  231. const FLAG_001d = false;
  232. const FLAG_001e = false;
  233. const FLAG_001f = false;
  234. // const FLAG_001g = true;
  235.  
  236.  
  237.  
  238. /**
  239. *
  240. *
  241. *
  242. *
  243. *
  244. rendererStamperObserver_: function(a, b, c) {
  245. if (c.path == a) {
  246. if (c.value === void 0 && !this.hasDataPath_[a])
  247. return;
  248. this.hasDataPath_[a] = c.value !== void 0
  249. }
  250. this.rendererStamperApplyChangeRecord_(a, b, c)
  251. },
  252.  
  253.  
  254. addStampDomObserverFns_: function() {
  255. for (var a in this.stampDom) {
  256. var b = this.stampDom[a];
  257. b.id ? (this[SQa(b.id)] = this.rendererStamperObserver_.bind(this, a, b.id),
  258. this.hasDataPath_[a] = !1) : Er(new Dn("Bad rendererstamper config",this.is + ":" + a))
  259. }
  260. },
  261. *
  262. *
  263. *
  264. *
  265. *
  266. */
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273. // <<<<< FOR MEMORY LEAKAGE >>>>
  274.  
  275. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  276. /*
  277.  
  278. ### Time Approach
  279.  
  280. // all below values can make the time interval > 250ms
  281. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  282. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  283. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  284. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  285. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  286. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  287.  
  288. ### Pixel Check
  289. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  290. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  291. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  292.  
  293. ### Example - totalDuration = 280000
  294. totalDuration 280000
  295. stepInterval 0.5
  296. numOfSteps = Math.round(100 / stepInterval) = 200
  297. time interval = 280000 / 200 = 1400ms <acceptable>
  298.  
  299. ### Example - totalDuration = 18000
  300. totalDuration 18000
  301. stepInterval 5
  302. numOfSteps = Math.round(100 / stepInterval) = 20
  303. time interval = 18000 / 20 = 900ms <acceptable>
  304.  
  305. ### Example - totalDuration = 5000
  306. totalDuration 5000
  307. stepInterval 5
  308. numOfSteps = Math.round(100 / stepInterval) = 20
  309. time interval = 5000 / 20 = 250ms <threshold value>
  310.  
  311. ### Example - totalDuration = 3600
  312. totalDuration 3600
  313. stepInterval 5
  314. numOfSteps = Math.round(100 / stepInterval) = 20
  315. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  316.  
  317. */
  318.  
  319. // =======================================================================================================
  320.  
  321. // AUTOMAICALLY DETERMINED
  322. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  323. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  324. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  325. let runTickerClassName = 'run-ticker';
  326.  
  327. const dummyImgURL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  328. /*
  329. WebP: data:image/webp;base64,UklGRjAB
  330. PNG: data:image/png;base64,iVBORw0KGg==
  331. JPEG: data:image/jpeg;base64,/9j/4AA=
  332. GIF: data:image/gif;base64,R0lGODlhAQABAIA=
  333. BMP: data:image/bmp;base64,Qk1oAAAA
  334. SVG: data:image/svg+xml;base64,PHN2Zy8+Cg==
  335.  
  336. WebP: data:image/webp;base64,AAAAAAA=
  337. PNG: data:image/png;base64,AAAAAAA=
  338. JPEG: data:image/jpeg;base64,AAAAAAA=
  339. GIF: data:image/gif;base64,AAAAAAA=
  340. BMP: data:image/bmp;base64,AAAAAAA=
  341.  
  342. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  343.  
  344.  
  345. */
  346.  
  347. // image sizing code
  348. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  349.  
  350.  
  351. // function KC(a, b, c, d) {
  352. // d = void 0 === d ? "width" : d;
  353. // if (!a || !a.length)
  354. // return null;
  355. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  356. // var e = window.devicePixelRatio;
  357. // 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"));
  358. // HC = e
  359. // } else
  360. // HC || (HC = window.devicePixelRatio);
  361. // e = HC;
  362. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  363. // if (z("kevlar_tuner_min_thumbnail_quality"))
  364. // return a[0].url || null;
  365. // e = a.length;
  366. // if (z("kevlar_tuner_max_thumbnail_quality"))
  367. // return a[e - 1].url || null;
  368. // if (c)
  369. // for (var h = 0; h < e; h++)
  370. // if (0 <= a[h].url.indexOf(c))
  371. // return a[h].url || null;
  372. // for (c = 0; c < e; c++)
  373. // if (a[c][d] >= b)
  374. // return a[c].url || null;
  375. // for (b = e - 1; 0 < b; b--)
  376. // if (a[b][d])
  377. // return a[b].url || null;
  378. // return a[0].url || null
  379. // }
  380.  
  381. const { IntersectionObserver } = __CONTEXT__;
  382. let _x69;
  383. try {
  384. _x69 = document.createAttributeNS("http://www.w3.org/2000/svg", "nil").addEventListener;
  385. } catch (e) { }
  386. const pureAddEventListener = _x69;
  387. if (!pureAddEventListener) return console.warn("pureAddEventListener cannot be obtained.");
  388.  
  389. /** @type {globalThis.PromiseConstructor} */
  390. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  391.  
  392. // let jsonParseFix = null;
  393.  
  394. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  395. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  396.  
  397. // necessity of cssText3_smooth_transform_position to be checked.
  398. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  399.  
  400. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  401. position: static !important;
  402. }
  403.  
  404. `: '';
  405.  
  406. // fallback if dummy style fn fails
  407. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  408.  
  409. /* optional */
  410. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  411. height: auto !important;
  412. min-height: unset !important;
  413. }
  414.  
  415. #items.style-scope.yt-live-chat-item-list-renderer {
  416. transform: translateY(0px) !important;
  417. }
  418.  
  419. /* optional */
  420.  
  421. `: '';
  422.  
  423. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  424.  
  425. /* ------------------------------------------------------------------------------------------------------------- */
  426.  
  427. 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 {
  428. contain: layout style;
  429. }
  430.  
  431. #items.style-scope.yt-live-chat-item-list-renderer {
  432. contain: layout paint style;
  433. }
  434.  
  435. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  436. contain: style;
  437. }
  438.  
  439. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  440. contain: size style;
  441. }
  442.  
  443. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  444. contain: size layout paint style;
  445. }
  446.  
  447. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  448. contain: layout paint style;
  449. }
  450.  
  451. 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 {
  452. contain: layout style;
  453. }
  454.  
  455. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  456. contain: layout paint style;
  457. }
  458.  
  459. /* ------------------------------------------------------------------------------------------------------------- */
  460.  
  461. ` : '';
  462.  
  463. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  464.  
  465. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  466. top: 4px;
  467. transition-property: top;
  468. bottom: unset;
  469. }
  470.  
  471. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  472. top: -42px;
  473. }
  474.  
  475. `: '';
  476.  
  477. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  478.  
  479. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  480. contain: layout style;
  481. }
  482.  
  483. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  484. overflow: visible;
  485. }
  486.  
  487. `: '';
  488.  
  489. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  490.  
  491. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  492. --yt-live-chat-action-panel-top-border: none;
  493. }
  494.  
  495. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  496. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  497. }
  498.  
  499. html #panel-pages.yt-live-chat-renderer {
  500. border-top: 0;
  501. border-bottom: 0;
  502. }
  503.  
  504. `: '';
  505.  
  506. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  507.  
  508. img,
  509. yt-img-shadow[height][width],
  510. yt-img-shadow {
  511. content-visibility: visible !important;
  512. }
  513.  
  514. ` : '';
  515.  
  516. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  517.  
  518. /* remove YouTube constant will-change */
  519. /* constant value will slow down the performance; default auto */
  520.  
  521. /* www-player.css */
  522. html .ytp-contextmenu,
  523. html .ytp-settings-menu {
  524. will-change: unset;
  525. }
  526.  
  527. /* frequently matched elements */
  528. html .fill.yt-interaction,
  529. html .stroke.yt-interaction,
  530. html .yt-spec-touch-feedback-shape__fill,
  531. html .yt-spec-touch-feedback-shape__stroke {
  532. will-change: unset;
  533. }
  534.  
  535. /* live_chat_polymer.js */
  536. /*
  537. html .toggle-button.tp-yt-paper-toggle-button,
  538. html #primaryProgress.tp-yt-paper-progress,
  539. html #secondaryProgress.tp-yt-paper-progress,
  540. html #onRadio.tp-yt-paper-radio-button,
  541. html .fill.yt-interaction,
  542. html .stroke.yt-interaction,
  543. html .yt-spec-touch-feedback-shape__fill,
  544. html .yt-spec-touch-feedback-shape__stroke {
  545. will-change: unset;
  546. }
  547. */
  548.  
  549. /* desktop_polymer_enable_wil_icons.js */
  550. /* html .fill.yt-interaction,
  551. html .stroke.yt-interaction, */
  552. html tp-yt-app-header::before,
  553. html tp-yt-iron-list,
  554. html #items.tp-yt-iron-list > *,
  555. html #onRadio.tp-yt-paper-radio-button,
  556. html .toggle-button.tp-yt-paper-toggle-button,
  557. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  558. html #items.ytd-post-multi-image-renderer,
  559. html #items.ytd-horizontal-card-list-renderer,
  560. html #items.yt-horizontal-list-renderer,
  561. html #left-arrow.yt-horizontal-list-renderer,
  562. html #right-arrow.yt-horizontal-list-renderer,
  563. html #items.ytd-video-description-infocards-section-renderer,
  564. html #items.ytd-video-description-music-section-renderer,
  565. html #chips.ytd-feed-filter-chip-bar-renderer,
  566. html #chips.yt-chip-cloud-renderer,
  567. html #items.ytd-merch-shelf-renderer,
  568. html #items.ytd-product-details-image-carousel-renderer,
  569. html ytd-video-preview,
  570. html #player-container.ytd-video-preview,
  571. html #primaryProgress.tp-yt-paper-progress,
  572. html #secondaryProgress.tp-yt-paper-progress,
  573. html ytd-miniplayer[enabled] /* ,
  574. html .yt-spec-touch-feedback-shape__fill,
  575. html .yt-spec-touch-feedback-shape__stroke */ {
  576. will-change: unset;
  577. }
  578.  
  579. /* other */
  580. .ytp-videowall-still-info-content[class],
  581. .ytp-suggestion-image[class] {
  582. will-change: unset !important;
  583. }
  584.  
  585. ` : '';
  586.  
  587. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  588. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  589.  
  590. elzm-fonts {
  591. visibility: collapse;
  592. position: fixed;
  593. top: -10px;
  594. left: -10px;
  595. font-size: 10pt;
  596. line-height: 100%;
  597. width: 100px;
  598. height: 100px;
  599. transform: scale(0.1);
  600. transform: scale(0.01);
  601. transform: scale(0.001);
  602. transform-origin: 0 0;
  603. contain: strict;
  604. display: block;
  605.  
  606. pointer-events: none !important;
  607. user-select: none !important;
  608. }
  609.  
  610. elzm-fonts[id]#elzm-fonts-yk75g {
  611. user-select: none !important;
  612. pointer-events: none !important;
  613. }
  614.  
  615. elzm-font {
  616. visibility: collapse;
  617. position: absolute;
  618. line-height: 100%;
  619. width: 100px;
  620. height: 100px;
  621. contain: strict;
  622. display: block;
  623.  
  624. user-select: none !important;
  625. pointer-events: none !important;
  626. }
  627.  
  628. elzm-font::before {
  629. visibility: collapse;
  630. position: absolute;
  631. line-height: 100%;
  632. width: 100px;
  633. height: 100px;
  634. contain: strict;
  635. display: block;
  636.  
  637. 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';
  638.  
  639. user-select: none !important;
  640. pointer-events: none !important;
  641. }
  642.  
  643. `: '';
  644.  
  645. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  646. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  647. -webkit-backdrop-filter: none;
  648. backdrop-filter: none;
  649. }
  650. `: '';
  651.  
  652. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  653.  
  654. @keyframes blinker-miuzp {
  655. 0%, 60%, 100% {
  656. opacity: 1;
  657. }
  658. 30% {
  659. opacity: 0.6;
  660. }
  661. }
  662.  
  663. yt-icon-button#show-more.has-new-messages-miuzp {
  664. animation: blinker-miuzp 1.74s linear infinite;
  665. }
  666.  
  667. `: '';
  668.  
  669. const cssText11_entire_message_clickable = FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK ? `
  670.  
  671. yt-live-chat-paid-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  672. pointer-events: none !important;
  673. }
  674.  
  675. yt-live-chat-membership-item-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  676. pointer-events: none !important;
  677. }
  678.  
  679. yt-live-chat-paid-sticker-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  680. pointer-events: none !important;
  681. }
  682.  
  683. yt-live-chat-text-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  684. pointer-events: none !important; /* TO_BE_REVIEWED */
  685. }
  686.  
  687. yt-live-chat-auto-mod-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  688. pointer-events: none !important;
  689. }
  690.  
  691. `: '';
  692.  
  693. const cssText12_nowrap_tooltip = MAX_TOOLTIP_NO_WRAP_WIDTH && typeof MAX_TOOLTIP_NO_WRAP_WIDTH === 'string' ? `
  694.  
  695.  
  696. tp-yt-paper-tooltip[role="tooltip"] {
  697. box-sizing: content-box !important;
  698. margin: 0px !important;
  699. padding: 0px !important;
  700. contain: none !important;
  701. }
  702.  
  703. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"] {
  704. box-sizing: content-box !important;
  705. display: inline-block;
  706. contain: none !important;
  707. }
  708.  
  709.  
  710. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"]{
  711. max-width: ${MAX_TOOLTIP_NO_WRAP_WIDTH};
  712. width: max-content;
  713. text-overflow: ellipsis;
  714. overflow: hidden;
  715. white-space: nowrap;
  716. }
  717.  
  718.  
  719. `: '';
  720.  
  721.  
  722. const cssText13_no_text_select_when_menu_visible = `
  723. [menu-visible] {
  724. --sfc47-text-select: none;
  725. }
  726. [menu-visible] #header[id][class],
  727. [menu-visible] #content[id][class],
  728. [menu-visible] #header[id][class] *,
  729. [menu-visible] #content[id][class] * {
  730. user-select: var(--sfc47-text-select) !important;
  731. }
  732. [menu-visible] #menu {
  733. --sfc47-text-select: inherit;
  734. }
  735. `;
  736.  
  737. const cssText14_NO_FILTER_DROPDOWN_BORDER = NO_FILTER_DROPDOWN_BORDER ? `
  738. yt-live-chat-header-renderer.yt-live-chat-renderer #label.yt-dropdown-menu::before {
  739. border:0;
  740. }
  741. ` : '';
  742.  
  743. const cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION = FIX_ANIMATION_TICKER_TEXT_POSITION ? `
  744. .style-scope.yt-live-chat-ticker-renderer #animation-container[id][class] {
  745. position: relative;
  746. display: grid;
  747. grid-auto-columns: 1fr;
  748. grid-auto-rows: 1fr;
  749. grid-template-columns: repeat(1, 1fr);
  750. gap: 7px;
  751. padding-bottom: 0;
  752. margin-bottom: 0;
  753. padding-top: 0;
  754. align-self: flex-start;
  755. flex-wrap: nowrap;
  756. margin-top: 1px;
  757. }
  758.  
  759. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class] {
  760. margin-top: 0px;
  761. margin-bottom: 0px;
  762. flex-direction: row;
  763. flex-wrap: nowrap;
  764. align-items: center;
  765. justify-content: flex-start;
  766. }
  767.  
  768. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class]:first-child::after {
  769. content: '補';
  770. visibility: collapse;
  771. display: inline-block;
  772. position: relative;
  773. width: 0;
  774. line-height: 22px;
  775. }
  776.  
  777. ` : '';
  778.  
  779. const cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION = FIX_AUTHOR_CHIP_BADGE_POSITION ? `
  780. #card #author-name-chip > yt-live-chat-author-chip[single-line] {
  781. flex-wrap: nowrap;
  782. white-space: nowrap;
  783. display: inline-flex;
  784. flex-direction: row;
  785. text-wrap: nowrap;
  786. flex-shrink: 0;
  787. align-items: center;
  788. }
  789.  
  790. #card #author-name-chip {
  791. display: inline-flex;
  792. flex-direction: row;
  793. align-items: flex-start;
  794. }
  795. `: '';
  796.  
  797.  
  798. // Example: https://www.youtube.com/watch?v=Xfytz-igsuc
  799. const cssText17_FIX_overwidth_banner_message = `
  800. yt-live-chat-banner-manager#live-chat-banner.style-scope.yt-live-chat-item-list-renderer {
  801. max-width: 100%;
  802. box-sizing: border-box;
  803. }
  804. `;
  805.  
  806.  
  807. const cssText18_REACTION_ANIMATION_PANEL_CSS_FIX = REACTION_ANIMATION_PANEL_CSS_FIX ? `
  808. #reaction-control-panel-overlay[class] {
  809. contain: strict;
  810. margin: 0;
  811. padding: 0;
  812. border: 0;
  813. box-sizing: border-box;
  814. will-change: initial;
  815. }
  816. #reaction-control-panel-overlay[class] *[class] {
  817. will-change: initial;
  818. }
  819. `: '';
  820.  
  821. const cssText19_FOR_ADVANCED_TICKING = `
  822. ticker-bg-overlay {
  823. display: block;
  824. position: absolute;
  825. z-index: -1;
  826. box-sizing: border-box;
  827. border: 0;
  828. padding: 0;
  829. margin: 0;
  830. width: 200%;
  831. top: 0;
  832. bottom: 0;
  833. left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  834. contain: strict;
  835. }
  836. ticker-bg-overlay-end {
  837. position: absolute;
  838. right: 0px;
  839. top: 50%;
  840. display: block;
  841. width: 1px;
  842. height: 1px;
  843. opacity: 0;
  844. pointer-events: none;
  845. box-sizing: border-box;
  846. border: 0;
  847. padding: 0;
  848. margin: 0;
  849. contain: strict;
  850. }
  851.  
  852. ticker-bg-overlay-end2 {
  853.  
  854. all:unset;
  855. position: fixed;
  856. display: block;
  857. margin-left: -0.5px;
  858. top: 8px;
  859. left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  860.  
  861. width: 1px;
  862. height: 1px;
  863. opacity: 0;
  864. pointer-events: none;
  865. box-sizing: border-box;
  866. border: 0;
  867. padding: 0;
  868. margin: 0;
  869. contain: strict;
  870. z-index: -1;
  871. visibility: collapse;
  872.  
  873. }
  874.  
  875. /*
  876.  
  877.  
  878. ey.style.position = 'absolute';
  879. ey.style.right = '0px';
  880. ey.style.top = '50%';
  881. ey.style.display='block';
  882. ey.style.width='1px';
  883. ey.style.height='1px';
  884. ey.style.opacity = '0';
  885.  
  886. em.style.display = 'block';
  887. em.style.position = 'absolute';
  888. em.style.boxSizing = 'border-box';
  889. em.style.width = '200%';
  890. em.style.top = '0';
  891. em.style.bottom = '0';
  892. // em.style.height = '100%';
  893.  
  894.  
  895. // em.style.left = '-50%';
  896. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  897.  
  898. */
  899.  
  900. `;
  901.  
  902. const addCss = () => `
  903.  
  904. @property --ticker-rtime {
  905. syntax: "<percentage>";
  906. inherits: false;
  907. initial-value: 0%;
  908. }
  909.  
  910. /*
  911. .run-ticker {
  912. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  913. }
  914.  
  915. .run-ticker-test {
  916. background: #00000001;
  917. }
  918.  
  919. .run-ticker-forced,
  920. yt-live-chat-ticker-renderer #items > * > #container.run-ticker-forced,
  921. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker-forced[class]
  922. {
  923. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2)) !important;
  924. }
  925. */
  926.  
  927. .run-ticker {
  928. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  929. }
  930.  
  931. .run-ticker,
  932. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  933. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  934. {
  935. background: var(--ticker-bg) !important;
  936. }
  937.  
  938. yt-live-chat-ticker-dummy777-item-renderer {
  939. background: #00000001;
  940. }
  941.  
  942. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  943. position: fixed !important;
  944. top: -1000px !important;
  945. left: -1000px !important;
  946. font-size: 1px !important;
  947. color: transparent !important;
  948. pointer-events: none !important;
  949. z-index: -1 !important;
  950. contain: strict !important;
  951. box-sizing: border-box !important;
  952. pointer-events: none !important;
  953. user-select: none !important;
  954. max-width: 1px !important;
  955. max-height: 1px !important;
  956. overflow: hidden !important;
  957. visibility: collapse !important;
  958. display: none !important;
  959. }
  960.  
  961. yt-live-chat-ticker-dummy777-item-renderer #container {
  962. background: inherit;
  963. }
  964.  
  965.  
  966. ${cssText8_fonts_pre_render}
  967.  
  968. ${cssText9_no_backdrop_filter_when_menu_shown}
  969.  
  970. @supports (contain: layout paint style) {
  971.  
  972. ${cssText5}
  973.  
  974. }
  975.  
  976. @supports (color: var(--general)) {
  977.  
  978. html {
  979. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  980. }
  981.  
  982. ${cssText3_smooth_transform_position}
  983.  
  984. ${cssText7c_will_change_unset}
  985.  
  986. ${cssText7b_content_visibility_unset}
  987.  
  988. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  989. overflow-y: scroll;
  990. padding-right: 0;
  991. }
  992.  
  993. ${cssText4_smooth_transform_forced_props}
  994.  
  995. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  996. pointer-events: none !important;
  997. }
  998.  
  999. #continuations, #continuations * {
  1000. contain: strict;
  1001. position: fixed;
  1002. top: 2px;
  1003. height: 1px;
  1004. width: 2px;
  1005. height: 1px;
  1006. visibility: collapse;
  1007. }
  1008.  
  1009. ${cssText6b_show_more_button}
  1010.  
  1011. ${cssText6d_input_panel_border}
  1012.  
  1013. ${cssText6c_input_panel_overflow}
  1014.  
  1015. }
  1016.  
  1017.  
  1018. @supports (overflow-anchor: auto) {
  1019.  
  1020. .no-anchor * {
  1021. overflow-anchor: none;
  1022. }
  1023. .no-anchor > item-anchor {
  1024. overflow-anchor: auto;
  1025. }
  1026.  
  1027. item-anchor {
  1028.  
  1029. height:1px;
  1030. width: 100%;
  1031. transform: scaleY(0.00001);
  1032. transform-origin:0 0;
  1033. contain: strict;
  1034. opacity:0;
  1035. display:flex;
  1036. position:relative;
  1037. flex-shrink:0;
  1038. flex-grow:0;
  1039. margin-bottom:0;
  1040. overflow:hidden;
  1041. box-sizing:border-box;
  1042. visibility: visible;
  1043. content-visibility: visible;
  1044. contain-intrinsic-size: auto 1px;
  1045. pointer-events:none !important;
  1046.  
  1047. }
  1048.  
  1049. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  1050. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  1051. }
  1052.  
  1053. html item-anchor {
  1054.  
  1055. height: 1px;
  1056. width: 1px;
  1057. top: auto;
  1058. left: auto;
  1059. right: auto;
  1060. bottom: auto;
  1061. transform: translateY(-1px);
  1062. position: absolute;
  1063. z-index: -1;
  1064.  
  1065. }
  1066.  
  1067. }
  1068.  
  1069. @supports (color: var(--pre-rendering)) {
  1070.  
  1071. @keyframes dontRenderAnimation {
  1072. 0% {
  1073. background-position-x: 3px;
  1074. }
  1075. 100% {
  1076. background-position-x: 4px;
  1077. }
  1078. }
  1079.  
  1080. .dont-render[class] {
  1081. /* visibility: collapse !important; */
  1082. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://greasyfork.org/scripts/469878/discussions/197267 */
  1083.  
  1084. transform: scale(0.01) !important;
  1085. transform: scale(0.00001) !important;
  1086. transform: scale(0.0000001) !important;
  1087. transform-origin: 0 0 !important;
  1088. z-index: -1 !important;
  1089. contain: strict !important;
  1090. box-sizing: border-box !important;
  1091.  
  1092. height: 1px !important;
  1093. height: 0.1px !important;
  1094. height: 0.01px !important;
  1095. height: 0.0001px !important;
  1096. height: 0.000001px !important;
  1097.  
  1098. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  1099.  
  1100. pointer-events: none !important;
  1101. user-select: none !important;
  1102.  
  1103. }
  1104.  
  1105. #sk35z {
  1106. display: block !important;
  1107.  
  1108. visibility: collapse !important;
  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. position: absolute !important;
  1125. top: -1000px !important;
  1126. left: -1000px !important;
  1127.  
  1128. }
  1129.  
  1130. }
  1131.  
  1132. [rNgzQ] {
  1133. opacity: 0 !important;
  1134. pointer-events: none !important;
  1135. }
  1136.  
  1137.  
  1138. ${cssText10_show_more_blinker}
  1139.  
  1140. ${cssText11_entire_message_clickable}
  1141.  
  1142. ${cssText12_nowrap_tooltip}
  1143.  
  1144. ${cssText13_no_text_select_when_menu_visible}
  1145.  
  1146. ${cssText14_NO_FILTER_DROPDOWN_BORDER}
  1147.  
  1148. ${cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION}
  1149.  
  1150. ${cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION}
  1151.  
  1152. ${cssText17_FIX_overwidth_banner_message}
  1153.  
  1154. ${cssText18_REACTION_ANIMATION_PANEL_CSS_FIX}
  1155.  
  1156. ${cssText19_FOR_ADVANCED_TICKING}
  1157.  
  1158. `;
  1159.  
  1160.  
  1161. const konsole = {
  1162. nil: Symbol(),
  1163. logs: [],
  1164. style: '',
  1165. log(...args) {
  1166. konsole.logs.push({
  1167. type: 'log',
  1168. msg: [konsole.tag || konsole.nil, ...args, konsole.style || konsole.nil].filter(e => e !== konsole.nil)
  1169. });
  1170. },
  1171. setTag(tag) {
  1172. konsole.tag = tag;
  1173. },
  1174. setStyle(style) {
  1175. konsole.style = style;
  1176. },
  1177. groupCollapsed(...args) {
  1178.  
  1179. konsole.logs.push({
  1180. type: 'groupCollapsed',
  1181. msg: [...args].filter(e => e !== konsole.nil)
  1182. });
  1183. },
  1184. groupEnd() {
  1185.  
  1186. konsole.logs.push({
  1187. type: 'groupEnd'
  1188. })
  1189. },
  1190. print() {
  1191. const copy = konsole.logs.slice(0);
  1192. konsole.logs.length = 0;
  1193. for (const { type, msg } of copy) {
  1194. if (type === 'log') {
  1195. console.log(...msg)
  1196. } else if (type === 'groupCollapsed') {
  1197.  
  1198. console.groupCollapsed(...msg)
  1199. } else if (type === 'groupEnd') {
  1200. console.groupEnd();
  1201. }
  1202.  
  1203. }
  1204.  
  1205. }
  1206. };
  1207.  
  1208. /*
  1209. konsole.groupCollapsedX = (text1, text2) => {
  1210.  
  1211. if(!text2){
  1212.  
  1213. konsole.groupCollapsed(`%c${text1}`,
  1214. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;"
  1215. );
  1216. }else{
  1217.  
  1218. konsole.groupCollapsed(`%c${text1}%c${text2}`,
  1219. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1220. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1221. );
  1222. }
  1223. }
  1224.  
  1225. konsole.groupCollapsedX('YouTube Super Fast Chat');
  1226.  
  1227. setTimeout(()=>{
  1228.  
  1229. konsole.setTag('[[Fonts Pre-Rendering]]');
  1230. konsole.log(123);
  1231. konsole.log('wsd',332, 'ssa');
  1232. konsole.setTag('');
  1233. }, 100);
  1234.  
  1235. setTimeout(()=>{
  1236.  
  1237. konsole.setTag('[[Fonts Pre-Rendering 2]]');
  1238. konsole.log(123);
  1239. konsole.log('wsd',332, 'ssa');
  1240. konsole.setTag('');
  1241. }, 300);
  1242.  
  1243. setTimeout(()=>{
  1244.  
  1245. konsole.groupEnd();
  1246. konsole.print();
  1247. }, 1000);
  1248.  
  1249. */
  1250.  
  1251. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  1252.  
  1253. // Create a unique key for the script and check if it is already running
  1254. const hkey_script = 'mchbwnoasqph';
  1255. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  1256. win[hkey_script] = true;
  1257.  
  1258. let unexpectedErr = "";
  1259.  
  1260. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  1261.  
  1262. let te4 = setTimeout(() => { }); // dummy; skip timerId only;
  1263. if (te4 < 3) {
  1264. setTimeout(() => { });
  1265. setTimeout(() => { });
  1266. }
  1267.  
  1268. }
  1269.  
  1270. const firstKey = (obj) => {
  1271. for (const key in obj) {
  1272. if (obj.hasOwnProperty(key)) return key;
  1273. }
  1274. return null;
  1275. }
  1276.  
  1277. const firstObjectKey = (obj) => {
  1278. for (const key in obj) {
  1279. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1280. }
  1281. return null;
  1282. }
  1283.  
  1284. /**
  1285. * Takes in a __SORTED__ array and inserts the provided value into
  1286. * the correct, sorted, position.
  1287. * > https://github.com/bhowell2/binary-insert-js/
  1288. * @param array the sorted array where the provided value needs to be inserted (in order)
  1289. * @param insertValue value to be added to the array
  1290. * @param comparator function that helps determine where to insert the value (
  1291. */
  1292. function binaryInsert(array, insertValue, comparator) {
  1293. let left = 0;
  1294. let right = array.length;
  1295.  
  1296. let z;
  1297. // Directly return if array is empty or the insertValue should be at the end
  1298. if (right === 0 || (z = comparator(array[right - 1], insertValue)) <= 0) {
  1299. array.push(insertValue);
  1300. return array;
  1301. }
  1302.  
  1303. // Check if the insertValue should be at the beginning
  1304. if ((right === 1 ? z : comparator(array[0], insertValue)) >= 0) {
  1305. array.unshift(insertValue);
  1306. return array;
  1307. }
  1308. ++left; --right;
  1309.  
  1310. // Main binary search loop to find the insertion position
  1311. while (left < right) {
  1312. const mid = Math.floor((right + left) / 2);
  1313. const compared = comparator(array[mid], insertValue);
  1314. if (compared < 0) {
  1315. left = mid + 1;
  1316. } else if (compared > 0) {
  1317. right = mid;
  1318. } else {
  1319. // If equal, insert at the mid position
  1320. left = right = mid;
  1321. break;
  1322. }
  1323. }
  1324.  
  1325. // Insertion is always at the right position due to the nature of the binary search
  1326. array.splice(right, 0, insertValue);
  1327. return array;
  1328. }
  1329.  
  1330.  
  1331.  
  1332.  
  1333. class LimitedSizeSet extends Set {
  1334. constructor(n) {
  1335. super();
  1336. this.limit = n;
  1337. }
  1338.  
  1339. add(key) {
  1340. if (!super.has(key)) {
  1341. super.add(key);
  1342. let n = super.size - this.limit;
  1343. if (n > 0) {
  1344. const iterator = super.values();
  1345. do {
  1346. const firstKey = iterator.next().value; // Get the first (oldest) key
  1347. super.delete(firstKey); // Delete the oldest key
  1348. } while (--n > 0)
  1349. }
  1350. }
  1351. }
  1352.  
  1353. removeAdd(key) {
  1354. super.delete(key);
  1355. this.add(key);
  1356. }
  1357.  
  1358. }
  1359.  
  1360.  
  1361. class LimitedSizeMap extends Map {
  1362. constructor(n) {
  1363. super();
  1364. this.limit = n;
  1365. }
  1366.  
  1367. set(key, val) {
  1368. if (!super.has(key)) {
  1369. super.set(key, val);
  1370. let n = super.size - this.limit;
  1371. if (n > 0) {
  1372. const iterator = super.keys();
  1373. do {
  1374. const firstKey = iterator.next().value; // Get the first (oldest) key
  1375. super.delete(firstKey); // Delete the oldest key
  1376. } while (--n > 0)
  1377. }
  1378. }
  1379. }
  1380.  
  1381. removeSet(key, val) {
  1382. super.delete(key);
  1383. this.set(key, val);
  1384. }
  1385.  
  1386. }
  1387.  
  1388. // function removeElementFromArray(arr, index) {
  1389. // if (index >= 0 && index < arr.length) {
  1390. // arr.splice(index, 1);
  1391. // }
  1392. // }
  1393.  
  1394. // function getRandomInt(a, b) {
  1395. // // Ensure that 'a' and 'b' are integers
  1396. // a = Math.ceil(a);
  1397. // b = Math.floor(b);
  1398.  
  1399. // // Generate a random integer in the range [a, b]
  1400. // return Math.floor(Math.random() * (b - a + 1)) + a;
  1401. // }
  1402.  
  1403. function deepCopy(obj, skipKeys) {
  1404. skipKeys = skipKeys || [];
  1405. if (!obj || typeof obj !== 'object') return obj;
  1406. if (Array.isArray(obj)) {
  1407. return obj.map(item => deepCopy(item, skipKeys));
  1408. }
  1409. const copy = {};
  1410. for (let key in obj) {
  1411. if (!skipKeys.includes(key)) {
  1412. copy[key] = deepCopy(obj[key], skipKeys);
  1413. }
  1414. }
  1415. return copy;
  1416. }
  1417.  
  1418. class Mutex {
  1419.  
  1420. constructor() {
  1421. this.p = Promise.resolve()
  1422. }
  1423.  
  1424. /**
  1425. * @param {(lockResolve: () => void)} f
  1426. */
  1427. lockWith(f) {
  1428. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  1429. }
  1430.  
  1431. }
  1432.  
  1433. const PromiseExternal = ((resolve_, reject_) => {
  1434. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  1435. return class PromiseExternal extends Promise {
  1436. constructor(cb = h) {
  1437. super(cb);
  1438. if (cb === h) {
  1439. /** @type {(value: any) => void} */
  1440. this.resolve = resolve_;
  1441. /** @type {(reason?: any) => void} */
  1442. this.reject = reject_;
  1443. }
  1444. }
  1445. };
  1446. })();
  1447.  
  1448.  
  1449. const createPipeline = () => {
  1450. let pipelineMutex = Promise.resolve();
  1451. const pipelineExecution = fn => {
  1452. return new Promise((resolve, reject) => {
  1453. pipelineMutex = pipelineMutex.then(async () => {
  1454. let res;
  1455. try {
  1456. res = await fn();
  1457. } catch (e) {
  1458. console.log('error_F1', e);
  1459. reject(e);
  1460. }
  1461. resolve(res);
  1462. }).catch(console.warn);
  1463. });
  1464. };
  1465. return pipelineExecution;
  1466. };
  1467.  
  1468. const tickerPE = createPipeline();
  1469.  
  1470. /** @type {typeof PromiseExternal.prototype | null} */
  1471. let relayPromise = null;
  1472.  
  1473.  
  1474. /** @type {typeof PromiseExternal.prototype | null} */
  1475. let onPlayStateChangePromise = null;
  1476.  
  1477.  
  1478.  
  1479.  
  1480. const valAssign = (elm, attr, val) => {
  1481. if (typeof val === 'number') val = val.toFixed(3);
  1482. if (!(Math.abs(elm.style.getPropertyValue(attr) - val) < 1e-5)) {
  1483. elm.style.setProperty(attr, val);
  1484. return true;
  1485. }
  1486. return false;
  1487. };
  1488.  
  1489. let playEventsStack = Promise.resolve();
  1490.  
  1491.  
  1492. let playerProgressChangedArg1 = null;
  1493. let playerProgressChangedArg2 = null;
  1494. let playerProgressChangedArg3 = null;
  1495.  
  1496. let dntElementWeak = null;
  1497.  
  1498.  
  1499. let timestampUnderLiveMode = false;
  1500.  
  1501. const updateTickerCurrentTime = () => {
  1502.  
  1503. if(resistanceUpdateDebugMode){
  1504. console.log('updateTickerCurrentTime')
  1505.  
  1506. if(!dntElementWeak || !kRef(dntElementWeak)) dntElementWeak = mWeakRef(document.querySelector('yt-live-chat-ticker-renderer'));
  1507. timestampUnderLiveMode = true;
  1508. }
  1509.  
  1510. const dntElement = kRef(dntElementWeak);
  1511. const v = timestampUnderLiveMode ? (Date.now() / 1000 - timeOriginDT / 1000) : playerProgressChangedArg1;
  1512. if (dntElement instanceof HTMLElement && v >= 0) {
  1513. valAssign(dntElement, '--ticker-current-time', v);
  1514. }
  1515. }
  1516.  
  1517. // ================== FOR USE_ADVANCED_TICKING ================
  1518.  
  1519. const timeOriginDT = +new Date(performance.timeOrigin);
  1520. let startResistanceUpdaterStarted = false;
  1521.  
  1522. const RESISTANCE_UPDATE_OPT = 3;
  1523. let resistanceUpdateLast = 0;
  1524. let resistanceUpdateBusy = false;
  1525. let resistanceUpdateRetry = false;
  1526. const resistanceUpdateDebugMode = false;
  1527. const allBackgroundOverLays = document.getElementsByTagName('ticker-bg-overlay');
  1528. const rgFlag = {};
  1529. const resistanceUpdateFn = (b) => {
  1530. if(b !== rgFlag && resistanceUpdateRetry === false) return;
  1531. if (!resistanceUpdateDebugMode && allBackgroundOverLays.length === 0) return;
  1532. resistanceUpdateBusy = false;
  1533. const t = Date.now();
  1534. const d = t - resistanceUpdateLast;
  1535. if (d > 375) {
  1536. resistanceUpdateLast = t;
  1537. resistanceUpdateRetry = false;
  1538. updateTickerCurrentTime();
  1539. } else if (typeof requestIdleCallback === 'function') {
  1540. resistanceUpdateRetry = true;
  1541. requestIdleCallback(resistanceUpdateFn);
  1542. } else {
  1543. resistanceUpdateRetry = true;
  1544. setTimeout(resistanceUpdateFn, d + 17);
  1545. }
  1546. }
  1547. const resistanceUpdateFn_ = ()=>{
  1548. if (!resistanceUpdateBusy) {
  1549. resistanceUpdateBusy = true;
  1550. resistanceUpdateRetry = false;
  1551. Promise.resolve(rgFlag).then(resistanceUpdateFn);
  1552. }
  1553. }
  1554. const startResistanceUpdater = () => {
  1555.  
  1556. if (startResistanceUpdaterStarted) return;
  1557. startResistanceUpdaterStarted = true;
  1558.  
  1559.  
  1560. if (RESISTANCE_UPDATE_OPT & 1)
  1561. document.addEventListener('yt-action', () => {
  1562. resistanceUpdateFn_();
  1563. }, true)
  1564.  
  1565. if (RESISTANCE_UPDATE_OPT & 2)
  1566. new MutationObserver(() => {
  1567. resistanceUpdateFn_();
  1568. }).observe(document, {
  1569. subtree: true, childList: true, attributes: true
  1570. });
  1571. resistanceUpdateFn_();
  1572. }
  1573.  
  1574. if(resistanceUpdateDebugMode) startResistanceUpdater();
  1575.  
  1576.  
  1577. function dr(s) {
  1578. // reserved for future use
  1579. return s;
  1580. // return window.deWeakJS ? window.deWeakJS(s) : s;
  1581. }
  1582.  
  1583. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1584. const indr = o => insp(o).$ || o.$ || 0;
  1585.  
  1586. const getProto = (element) => {
  1587. if (element) {
  1588. const cnt = insp(element);
  1589. return cnt.constructor.prototype || null;
  1590. }
  1591. return null;
  1592. }
  1593.  
  1594. const assertor = (f) => f() || console.assert(false, f + "");
  1595.  
  1596. const fnIntegrity = (f, d) => {
  1597.  
  1598.  
  1599. if (!f || typeof f !== 'function') {
  1600. console.warn('f is not a function', f);
  1601. return;
  1602. }
  1603. // return; // M44
  1604. let p = `${f}`, s = 0, j = -1, w = 0;
  1605. // return; // M44
  1606. for (let i = 0, l = p.length; i < l; i++) {
  1607. const t = p[i];
  1608. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1609. if (j < i - 1) w++;
  1610. j = i;
  1611. } else {
  1612. s++;
  1613. }
  1614. }
  1615. // if(p.length > 44 && p.length < 50){
  1616.  
  1617. // (window.skam|| (window.skam=[])).push(p);
  1618. // return false;
  1619. // }
  1620.  
  1621. // if(p.length > 405 && p.length < 415 ){ //350 450
  1622.  
  1623.  
  1624. // //  [353, 411, 411, 411]
  1625.  
  1626. // // if(p.length >= 350 && p.length<=450){
  1627.  
  1628. // // (window.skam|| (window.skam=[])).push(p.length);
  1629. // // }
  1630. // (window.skam|| (window.skam=[])).push(p);
  1631. // return false;
  1632. // }
  1633.  
  1634. // if(p.length < 50) return true; else return false;
  1635. // return; // M44
  1636. let itz = `${f.length}.${s}.${w}`;
  1637. if (!d) {
  1638. return itz;
  1639. } else if (itz !== d) {
  1640. console.warn('fnIntegrity=false', itz);
  1641. return false;
  1642. } else {
  1643. return true;
  1644. }
  1645. }
  1646.  
  1647.  
  1648. const px2cm = (px) => px * window.devicePixelRatio * 0.026458333;
  1649. const px2mm = (px) => px * window.devicePixelRatio * 0.26458333;
  1650.  
  1651.  
  1652. ; (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS || DISABLE_FLAGS_SHADYDOM_FREE) && (() => {
  1653.  
  1654. const _config_ = () => {
  1655. try {
  1656. return ytcfg.data_;
  1657. } catch (e) { }
  1658. return null;
  1659. };
  1660.  
  1661. const flagsFn = (EXPERIMENT_FLAGS) => {
  1662.  
  1663. // console.log(700)
  1664.  
  1665. if (!EXPERIMENT_FLAGS) return;
  1666.  
  1667. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1668. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1669. // EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true; // timestamp toggle issue
  1670. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1671. // console.log(701)
  1672. }
  1673. }
  1674.  
  1675. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1676. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1677. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1678. // console.log(702);
  1679. }
  1680.  
  1681. if (DISABLE_FLAGS_SHADYDOM_FREE) {
  1682. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_node_methods = false;
  1683. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_query_methods = false;
  1684. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_readonly_properties_batch_one = false;
  1685. EXPERIMENT_FLAGS.enable_shadydom_free_parent_node = false;
  1686. EXPERIMENT_FLAGS.enable_shadydom_free_children = false;
  1687. EXPERIMENT_FLAGS.enable_shadydom_free_last_child = false;
  1688. }
  1689.  
  1690. // EXPERIMENT_FLAGS.enable_button_behavior_reuse = false;
  1691.  
  1692. };
  1693.  
  1694. const uf = (config_) => {
  1695. config_ = config_ || _config_();
  1696. if (config_) {
  1697. const { EXPERIMENT_FLAGS, EXPERIMENTS_FORCED_FLAGS } = config_;
  1698. if (EXPERIMENT_FLAGS) {
  1699. flagsFn(EXPERIMENT_FLAGS);
  1700. if (EXPERIMENTS_FORCED_FLAGS) flagsFn(EXPERIMENTS_FORCED_FLAGS);
  1701. }
  1702. }
  1703. }
  1704.  
  1705. window._ytConfigHacks.add((config_) => {
  1706. uf(config_);
  1707. });
  1708.  
  1709. uf();
  1710.  
  1711. })();
  1712.  
  1713. if (DISABLE_Translation_By_Google) {
  1714.  
  1715. let mo = new MutationObserver(() => {
  1716.  
  1717. if (!mo) return;
  1718. let h = document.head;
  1719. if (!h) return;
  1720. mo.disconnect();
  1721. mo.takeRecords();
  1722. mo = null;
  1723.  
  1724. let meta = document.createElement('meta');
  1725. meta.setAttribute('name', 'google');
  1726. meta.setAttribute('content', 'notranslate');
  1727. h.appendChild(meta);
  1728.  
  1729.  
  1730. });
  1731. mo.observe(document, { subtree: true, childList: true });
  1732. }
  1733.  
  1734.  
  1735. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  1736.  
  1737. const isContainSupport = CSS.supports('contain', 'layout paint style');
  1738. if (!isContainSupport) {
  1739. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  1740. }
  1741.  
  1742. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  1743. if (!isOverflowAnchorSupport) {
  1744. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  1745. }
  1746.  
  1747. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && isOverflowAnchorSupport && ENABLE_NO_SMOOTH_TRANSFORM;
  1748.  
  1749. let hasTimerModified = null;
  1750. const DO_CHECK_TICKER_BACKGROUND_OVERRIDED = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND || ENABLE_RAF_HACK_TICKERS;
  1751.  
  1752. const fxOperator = (proto, propertyName) => {
  1753. let propertyDescriptorGetter = null;
  1754. try {
  1755. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  1756. } catch (e) { }
  1757. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  1758. try {
  1759.  
  1760. return propertyDescriptorGetter.call(dr(e));
  1761. } catch (e) { }
  1762. return e[propertyName];
  1763. } : (e) => e[propertyName];
  1764. };
  1765.  
  1766. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  1767. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  1768. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  1769. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  1770. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  1771.  
  1772. const groupCollapsed = (text1, text2) => {
  1773.  
  1774. console.groupCollapsed(`%c${text1}%c${text2}`,
  1775. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1776. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1777. );
  1778. }
  1779.  
  1780. // const microNow = () => performance.now() + (performance.timeOrigin || performance.timing.navigationStart);
  1781.  
  1782.  
  1783. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1784. const onRegistryReady = (callback) => {
  1785. if (typeof customElements === 'undefined') {
  1786. if (!('__CE_registry' in document)) {
  1787. // https://github.com/webcomponents/polyfills/
  1788. Object.defineProperty(document, '__CE_registry', {
  1789. get() {
  1790. // return undefined
  1791. },
  1792. set(nv) {
  1793. if (typeof nv == 'object') {
  1794. delete this.__CE_registry;
  1795. this.__CE_registry = nv;
  1796. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1797. }
  1798. return true;
  1799. },
  1800. enumerable: false,
  1801. configurable: true
  1802. })
  1803. }
  1804. let eventHandler = (evt) => {
  1805. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1806. const f = callback;
  1807. callback = null;
  1808. eventHandler = null;
  1809. f();
  1810. };
  1811. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1812. } else {
  1813. callback();
  1814. }
  1815. };
  1816.  
  1817. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  1818.  
  1819. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  1820.  
  1821. return new Promise(resolve => {
  1822.  
  1823. let ro = new ResizeObserver(entries => {
  1824. if (entries && entries.length >= 1) {
  1825. resolve();
  1826. ro.disconnect();
  1827. ro = null;
  1828. }
  1829. });
  1830. ro.observe(sizingTarget);
  1831.  
  1832.  
  1833.  
  1834. });
  1835.  
  1836. } : (sizingTarget) => {
  1837.  
  1838.  
  1839. return new Promise(resolve => {
  1840.  
  1841. let io = new IntersectionObserver(entries => {
  1842. if (entries && entries.length >= 1) {
  1843. resolve();
  1844. io.disconnect();
  1845. io = null;
  1846. }
  1847. });
  1848. io.observe(sizingTarget);
  1849.  
  1850.  
  1851.  
  1852. });
  1853.  
  1854. };
  1855.  
  1856. /* globals WeakRef:false */
  1857.  
  1858. /** @type {(o: Object | null) => WeakRef | null} */
  1859. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1860.  
  1861. /** @type {(wr: Object | null) => Object | null} */
  1862. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1863.  
  1864. const getLCRDummy = () => {
  1865. // direct createElement or createComponent_ will make the emoji rendering crashed. reason TBC
  1866.  
  1867. return Promise.all([customElements.whenDefined('yt-live-chat-app'), customElements.whenDefined('yt-live-chat-renderer')]).then(async () => {
  1868.  
  1869. const tag = "yt-live-chat-renderer"
  1870. let dummy = document.querySelector(tag);
  1871. if (!dummy) {
  1872.  
  1873. let mo = null;
  1874.  
  1875. const ytLiveChatApp = document.querySelector('yt-live-chat-app') || document.createElement('yt-live-chat-app');
  1876.  
  1877. const lcaProto = getProto(ytLiveChatApp);
  1878.  
  1879. dummy = await new Promise(resolve => {
  1880.  
  1881. if (typeof lcaProto.createComponent_ === 'function' && !lcaProto.createComponent99_) {
  1882.  
  1883. lcaProto.createComponent99_ = lcaProto.createComponent_;
  1884. lcaProto.createComponent98_ = function (a, b, c) {
  1885. // (3) ['yt-live-chat-renderer', {…}, true]
  1886. const r = this.createComponent99_.apply(this, arguments);
  1887. if (a === 'yt-live-chat-renderer') {
  1888. resolve(r);
  1889. }
  1890. return r;
  1891. };
  1892. lcaProto.createComponent_ = lcaProto.createComponent98_;
  1893.  
  1894. } else {
  1895.  
  1896. mo = new MutationObserver(() => {
  1897. const t = document.querySelector(tag);
  1898. if (t) {
  1899. resolve(t);
  1900. }
  1901. });
  1902. mo.observe(document, { subtree: true, childList: true })
  1903. }
  1904.  
  1905. });
  1906.  
  1907. if (mo) {
  1908. mo.disconnect();
  1909. mo.takeRecords();
  1910. mo = null;
  1911. }
  1912.  
  1913. if (lcaProto.createComponent99_ && lcaProto.createComponent_ && lcaProto.createComponent98_ === lcaProto.createComponent_) {
  1914. lcaProto.createComponent_ = lcaProto.createComponent99_;
  1915. lcaProto.createComponent99_ = null;
  1916. lcaProto.createComponent98_ = null;
  1917. }
  1918.  
  1919. }
  1920. return dummy;
  1921.  
  1922. });
  1923. }
  1924.  
  1925. const { addCssManaged } = (() => {
  1926.  
  1927. const addFontPreRendering = () => {
  1928.  
  1929. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  1930.  
  1931. let efsContainer = document.createElement('elzm-fonts');
  1932. efsContainer.id = 'elzm-fonts-yk75g'
  1933.  
  1934. const arr = [];
  1935. let p = document.createElement('elzm-font');
  1936. arr.push(p);
  1937.  
  1938. if (ENABLE_FONT_PRE_RENDERING & 1) {
  1939. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1940.  
  1941. p = document.createElement('elzm-font');
  1942. p.style.fontWeight = size;
  1943. arr.push(p);
  1944. }
  1945. }
  1946.  
  1947. if (ENABLE_FONT_PRE_RENDERING & 2) {
  1948. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1949.  
  1950. p = document.createElement('elzm-font');
  1951. p.style.fontFamily = 'Roboto';
  1952. p.style.fontWeight = size;
  1953. arr.push(p);
  1954. }
  1955. }
  1956.  
  1957. if (ENABLE_FONT_PRE_RENDERING & 4) {
  1958. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1959.  
  1960. p = document.createElement('elzm-font');
  1961. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  1962. p.style.fontWeight = size;
  1963. arr.push(p);
  1964. }
  1965. }
  1966.  
  1967.  
  1968. if (ENABLE_FONT_PRE_RENDERING & 8) {
  1969. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1970.  
  1971. p = document.createElement('elzm-font');
  1972. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  1973. p.style.fontWeight = size;
  1974. arr.push(p);
  1975. }
  1976. }
  1977.  
  1978.  
  1979. if (ENABLE_FONT_PRE_RENDERING & 16) {
  1980. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  1981.  
  1982. p = document.createElement('elzm-font');
  1983. p.style.fontFamily = 'sans-serif';
  1984. p.style.fontWeight = size;
  1985. arr.push(p);
  1986. }
  1987. }
  1988.  
  1989. console.log('number of elzm-font elements', arr.length);
  1990.  
  1991. HTMLElement.prototype.append.apply(efsContainer, arr);
  1992.  
  1993. (document.body || document.documentElement).appendChild(efsContainer);
  1994.  
  1995.  
  1996. console.log('elzm-font elements have been added to the page for rendering.');
  1997.  
  1998. console.groupEnd();
  1999.  
  2000. }
  2001.  
  2002. let isCssAdded = false;
  2003.  
  2004. function addCssElement() {
  2005. let s = document.createElement('style');
  2006. s.id = 'ewRvC';
  2007. return s;
  2008. }
  2009.  
  2010. const addCssManaged = () => {
  2011. if (!isCssAdded && document.documentElement && document.head) {
  2012. isCssAdded = true;
  2013. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  2014. if (ENABLE_FONT_PRE_RENDERING) {
  2015. Promise.resolve().then(addFontPreRendering)
  2016. }
  2017. }
  2018. }
  2019.  
  2020. return { addCssManaged };
  2021. })();
  2022.  
  2023.  
  2024. const { setupStyle } = (() => {
  2025.  
  2026. const sp7 = Symbol();
  2027.  
  2028. const proxyHelperFn = (dummy) => ({
  2029.  
  2030. get(target, prop) {
  2031. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  2032. },
  2033. set(target, prop, value) {
  2034. if (!(prop in dummy)) {
  2035. target[prop] = value;
  2036. }
  2037. return true;
  2038. },
  2039. has(target, prop) {
  2040. return (prop in target);
  2041. },
  2042. deleteProperty(target, prop) {
  2043. return true;
  2044. },
  2045. ownKeys(target) {
  2046. return Object.keys(target);
  2047. },
  2048. defineProperty(target, key, descriptor) {
  2049. return Object.defineProperty(target, key, descriptor);
  2050. },
  2051. getOwnPropertyDescriptor(target, key) {
  2052. return Object.getOwnPropertyDescriptor(target, key);
  2053. },
  2054.  
  2055. });
  2056.  
  2057. const setupStyle = (m1, m2) => {
  2058. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  2059.  
  2060. const dummy1v = {
  2061. transform: '',
  2062. height: '',
  2063. minHeight: '',
  2064. paddingBottom: '',
  2065. paddingTop: ''
  2066. };
  2067.  
  2068. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  2069. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  2070. dummy1v[k] = dummyStyleFn(k);
  2071. }
  2072.  
  2073. const dummy1p = proxyHelperFn(dummy1v);
  2074. const sp1v = new Proxy(m1.style, dummy1p);
  2075. const sp2v = new Proxy(m2.style, dummy1p);
  2076. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  2077. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  2078. m1.removeAttribute("style");
  2079. m2.removeAttribute("style");
  2080.  
  2081. }
  2082.  
  2083. return { setupStyle };
  2084.  
  2085. })();
  2086.  
  2087.  
  2088.  
  2089. function setThumbnails(config) {
  2090.  
  2091. const { baseObject, thumbnails, flag0, imageLinks } = config;
  2092.  
  2093. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  2094.  
  2095.  
  2096. if (thumbnails && thumbnails.length > 0) {
  2097. if (flag0 > 0 && thumbnails.length > 1) {
  2098. let pSize = 0;
  2099. let newThumbnails = [];
  2100. for (const thumbnail of thumbnails) {
  2101. if (!thumbnail || !thumbnail.url) continue;
  2102. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  2103. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  2104. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  2105. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  2106. newThumbnails.push(thumbnail);
  2107. if (imageLinks) imageLinks.add(thumbnail.url);
  2108. }
  2109. if (squarePhoto && condSize && leastSizeFulfilled) {
  2110. pSize = thumbnail.width;
  2111. }
  2112. }
  2113. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  2114. baseObject.thumbnails = newThumbnails;
  2115. } else {
  2116. newThumbnails.length = 0;
  2117. }
  2118. newThumbnails = null;
  2119. } else {
  2120. for (const thumbnail of thumbnails) {
  2121. if (thumbnail && thumbnail.url) {
  2122. if (imageLinks) imageLinks.add(thumbnail.url);
  2123. }
  2124. }
  2125. }
  2126. }
  2127.  
  2128. }
  2129. }
  2130.  
  2131. function fixLiveChatItem(item, imageLinks) {
  2132. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  2133. if (liveChatTextMessageRenderer) {
  2134. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  2135. if (messageRuns && messageRuns.length > 0) {
  2136. for (const run of messageRuns) {
  2137. const emojiImage = (((run || 0).emoji || 0).image || 0);
  2138. setThumbnails({
  2139. baseObject: emojiImage,
  2140. thumbnails: emojiImage.thumbnails,
  2141. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  2142. imageLinks
  2143. });
  2144. }
  2145. }
  2146. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  2147. setThumbnails({
  2148. baseObject: authorPhoto,
  2149. thumbnails: authorPhoto.thumbnails,
  2150. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  2151. imageLinks
  2152. });
  2153. }
  2154. }
  2155.  
  2156.  
  2157.  
  2158. let kptPF = null;
  2159. const emojiPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_EMOJI);
  2160. const authorPhotoPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO);
  2161.  
  2162. function linker(link, rel, href, _as) {
  2163. return new Promise(resolve => {
  2164. if (!link) link = document.createElement('link');
  2165. link.rel = rel;
  2166. if (_as) link.setAttribute('as', _as);
  2167. link.onload = function () {
  2168. resolve({
  2169. link: this,
  2170. success: true
  2171. })
  2172. this.remove();
  2173. };
  2174. link.onerror = function () {
  2175. resolve({
  2176. link: this,
  2177. success: false
  2178. });
  2179. this.remove();
  2180. };
  2181. link.href = href;
  2182. document.head.appendChild(link);
  2183. link = null;
  2184. });
  2185. }
  2186.  
  2187.  
  2188.  
  2189. const cleanContext = async (win) => {
  2190. const waitFn = requestAnimationFrame; // shall have been binded to window
  2191. try {
  2192. let mx = 16; // MAX TRIAL
  2193. const frameId = 'vanillajs-iframe-v1';
  2194. /** @type {HTMLIFrameElement | null} */
  2195. let frame = document.getElementById(frameId);
  2196. let removeIframeFn = null;
  2197. if (!frame) {
  2198. frame = document.createElement('iframe');
  2199. frame.id = frameId;
  2200. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2201. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2202. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2203. n.appendChild(frame);
  2204. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2205. const root = document.documentElement;
  2206. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2207. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2208.  
  2209. removeIframeFn = (setTimeout) => {
  2210. const removeIframeOnDocumentReady = (e) => {
  2211. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2212. e = n;
  2213. n = win = removeIframeFn = 0;
  2214. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2215. }
  2216. if (!setTimeout || document.readyState !== 'loading') {
  2217. removeIframeOnDocumentReady();
  2218. } else {
  2219. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2220. }
  2221. }
  2222. }
  2223. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2224. const fc = frame.contentWindow;
  2225. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2226. try {
  2227. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle } = fc;
  2228. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle };
  2229. for (let k in res) res[k] = res[k].bind(win); // necessary
  2230. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2231.  
  2232. /** @type {HTMLElement} */
  2233. const HTMLElementProto = fc.HTMLElement.prototype;
  2234. /** @type {EventTarget} */
  2235. const EventTargetProto = fc.EventTarget.prototype;
  2236. // jsonParseFix = {
  2237. // _JSON: fc.JSON, _parse: fc.JSON.parse
  2238. // }
  2239. return {
  2240. ...res,
  2241. animate: HTMLElementProto.animate,
  2242. addEventListener: EventTargetProto.addEventListener,
  2243. removeEventListener: EventTargetProto.removeEventListener
  2244. };
  2245. } catch (e) {
  2246. if (removeIframeFn) removeIframeFn();
  2247. return null;
  2248. }
  2249. } catch (e) {
  2250. console.warn(e);
  2251. return null;
  2252. }
  2253. };
  2254.  
  2255.  
  2256. let xoIcjPr = null;
  2257. window.addEventListener('message', (evt) => {
  2258. if ((evt || 0).data === 'xoIcj' && xoIcjPr !== null) xoIcjPr.resolve();
  2259. });
  2260. const timelineResolve = async () => {
  2261. if (xoIcjPr !== null) {
  2262. await xoIcjPr.then();
  2263. return;
  2264. }
  2265. xoIcjPr = new PromiseExternal();
  2266. window.postMessage('xoIcj');
  2267. await xoIcjPr.then();
  2268. xoIcjPr = null;
  2269. }
  2270.  
  2271. cleanContext(win).then(__CONTEXT__ => {
  2272. if (!__CONTEXT__) return null;
  2273.  
  2274. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, getComputedStyle, addEventListener, removeEventListener } = __CONTEXT__;
  2275.  
  2276. const wmComputedStyle = new WeakMap();
  2277. const getComputedStyleCached = (elem) => {
  2278. let cs = wmComputedStyle.get(elem);
  2279. if (!cs) {
  2280. cs = getComputedStyle(elem);
  2281. wmComputedStyle.set(elem, cs);
  2282. }
  2283. return cs;
  2284. }
  2285.  
  2286.  
  2287. const isGPUAccelerationAvailable = (() => {
  2288. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  2289. try {
  2290. const canvas = document.createElement('canvas');
  2291. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  2292. } catch (e) {
  2293. return false;
  2294. }
  2295. })();
  2296.  
  2297. const foregroundPromiseFn_noGPU = (() => {
  2298.  
  2299. if (isGPUAccelerationAvailable) return null;
  2300.  
  2301. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  2302. if (!pd || typeof pd.get !== 'function') return null;
  2303. const pdGet = pd.get;
  2304.  
  2305. let pr = null;
  2306.  
  2307. let hState = pdGet.call(document) === 'hidden';
  2308. // let cid = 0;
  2309. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  2310. const newHState = pdGet.call(document) === 'hidden';
  2311. if (hState !== newHState) {
  2312. // if (cid > 0) cid = clearInterval(cid);
  2313. hState = newHState;
  2314. if (!hState && pr) pr = pr.resolve();
  2315. }
  2316. });
  2317.  
  2318. // cid = setInterval(() => {
  2319. // const newHState = document.visibilityState === 'hidden';
  2320. // if (hState !== newHState) {
  2321. // hState = newHState;
  2322. // if (!hState && pr) pr = pr.resolve();
  2323. // }
  2324. // }, 100);
  2325.  
  2326.  
  2327. return (() => {
  2328. if (pr) return pr;
  2329. const w = ((!hState && setTimeout(() => {
  2330. if (!hState && pr === w) pr = pr.resolve();
  2331. })), (pr = new PromiseExternal()));
  2332. return w;
  2333. });
  2334.  
  2335. })();
  2336.  
  2337. // window.foregroundPromiseFn_noGPU = foregroundPromiseFn_noGPU;
  2338.  
  2339. let rafPromise = null;
  2340. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2341. requestAnimationFrame(hRes => {
  2342. rafPromise = null;
  2343. resolve(hRes);
  2344. });
  2345. }));
  2346. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  2347.  
  2348. const iAFP = foregroundPromiseFn_noGPU ? foregroundPromiseFn_noGPU : typeof IntersectionObserver === 'undefined' ? getRafPromise : (() => {
  2349.  
  2350. const ioWM = new WeakMap();
  2351. const ek = Symbol();
  2352. /** @type {IntersectionObserverCallback} */
  2353. const ioCb = (entries, observer) => {
  2354. /** @type {PromiseExternal} */
  2355. const pr = observer[ek];
  2356. const resolve = pr.resolve;
  2357. let target;
  2358. if (resolve && (target = ((entries ? entries[0] : 0) || 0).target) instanceof Element) {
  2359. pr.resolve = null;
  2360. observer.unobserve(target);
  2361. resolve();
  2362. }
  2363. };
  2364. /**
  2365. *
  2366. * @param {Element} elm
  2367. * @returns {Promise<void>}
  2368. */
  2369. const iAFP = (elm) => {
  2370. let io = ioWM.get(elm);
  2371. if (!io) {
  2372. io = new IntersectionObserver(ioCb);
  2373. ioWM.set(elm, io); // strong reference
  2374. }
  2375. let pr = io[ek];
  2376. if (!pr) {
  2377. pr = io[ek] = new PromiseExternal();
  2378. io.observe(elm);
  2379. }
  2380. return pr;
  2381. }
  2382.  
  2383. return iAFP;
  2384.  
  2385. })();
  2386.  
  2387. let playerState = null;
  2388. let _playerState = null;
  2389. let lastPlayerProgress = null;
  2390. let relayCount = 0;
  2391. let playerEventsByIframeRelay = false;
  2392. let isPlayProgressTriggered = false;
  2393. let waitForInitialDataCompletion = 0;
  2394.  
  2395.  
  2396.  
  2397. let aeConstructor = null;
  2398.  
  2399. // << __openedChanged82 >>
  2400. let currentMenuPivotWR = null;
  2401.  
  2402. // << if DO_PARTICIPANT_LIST_HACKS >>
  2403. const beforeParticipantsMap = new WeakMap();
  2404. // << end >>
  2405.  
  2406.  
  2407.  
  2408. // << if onRegistryReadyForDOMOperations >>
  2409.  
  2410. let dt0 = Date.now() - 2000;
  2411. const dateNow = () => Date.now() - dt0;
  2412. // let lastScroll = 0;
  2413. // let lastLShow = 0;
  2414. let lastWheel = 0;
  2415. let lastMouseDown = 0;
  2416. let lastMouseUp = 0;
  2417. let currentMouseDown = false;
  2418. let lastTouchDown = 0;
  2419. let lastTouchUp = 0;
  2420. let currentTouchDown = false;
  2421. let lastUserInteraction = 0;
  2422.  
  2423. let scrollChatFn = null;
  2424.  
  2425. let skipDontRender = true; // true first; false by flushActiveItems_
  2426. let allowDontRender = null;
  2427.  
  2428. // ---- #items mutation ----
  2429. let sk35zResolveFn = null;
  2430. let firstList = true;
  2431.  
  2432. // << end >>
  2433.  
  2434. class RAFHub {
  2435. constructor() {
  2436. /** @type {number} */
  2437. this.startAt = 8170;
  2438. /** @type {number} */
  2439. this.counter = 0;
  2440. /** @type {number} */
  2441. this.rid = 0;
  2442. /** @type {Map<number, FrameRequestCallback>} */
  2443. this.funcs = new Map();
  2444. const funcs = this.funcs;
  2445. /** @type {FrameRequestCallback} */
  2446. this.bCallback = this.mCallback.bind(this);
  2447. this.pClear = () => funcs.clear();
  2448. this.keepRAF = false;
  2449. }
  2450. /** @param {DOMHighResTimeStamp} highResTime */
  2451. mCallback(highResTime) {
  2452. this.rid = 0;
  2453. Promise.resolve().then(this.pClear);
  2454. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2455. }
  2456. /** @param {FrameRequestCallback} f */
  2457. request(f) {
  2458. if (this.counter > 1e9) this.counter = 9;
  2459. let cid = this.startAt + (++this.counter);
  2460. this.funcs.set(cid, f);
  2461. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  2462. return cid;
  2463. }
  2464. /** @param {number} cid */
  2465. cancel(cid) {
  2466. cid = +cid;
  2467. if (cid > 0) {
  2468. if (cid <= this.startAt) {
  2469. return cancelAnimationFrame(cid);
  2470. }
  2471. if (this.rid > 0) {
  2472. this.funcs.delete(cid);
  2473. if (this.funcs.size === 0 && !this.keepRAF) {
  2474. cancelAnimationFrame(this.rid);
  2475. this.rid = 0;
  2476. }
  2477. }
  2478. }
  2479. }
  2480. }
  2481.  
  2482. function basePrefetching() {
  2483.  
  2484. new Promise(resolve => {
  2485.  
  2486. if (document.readyState !== 'loading') {
  2487. resolve();
  2488. } else {
  2489. win.addEventListener("DOMContentLoaded", resolve, false);
  2490. }
  2491.  
  2492. }).then(() => {
  2493. const hostL1 = [
  2494. 'https://www.youtube.com', 'https://googlevideo.com',
  2495. 'https://googleapis.com', 'https://accounts.youtube.com',
  2496. 'https://www.gstatic.com', 'https://ggpht.com',
  2497. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  2498. ];
  2499.  
  2500. const hostL2 = [
  2501. 'https://youtube.com',
  2502. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  2503. ];
  2504.  
  2505. let link = null;
  2506.  
  2507. function kn() {
  2508.  
  2509. link = document.createElement('link');
  2510. if (link.relList && link.relList.supports) {
  2511. 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)
  2512. } else {
  2513. kptPF = 0;
  2514. }
  2515.  
  2516. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  2517. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  2518. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  2519. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  2520. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  2521. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  2522. console.groupEnd();
  2523.  
  2524. }
  2525.  
  2526. for (const h of hostL1) {
  2527.  
  2528. if (kptPF === null) kn();
  2529. if (ENABLE_BASE_PREFETCHING) {
  2530. // if (kptPF & 1) {
  2531. // linker(link, 'dns-prefetch', h);
  2532. // link = null;
  2533. // }
  2534. if (kptPF & 2) {
  2535. linker(link, 'preconnect', h);
  2536. link = null;
  2537. }
  2538. }
  2539. }
  2540.  
  2541. for (const h of hostL2) {
  2542. if (kptPF === null) kn();
  2543. if (ENABLE_BASE_PREFETCHING) {
  2544. if (kptPF & 1) {
  2545. linker(link, 'dns-prefetch', h);
  2546. link = null;
  2547. }
  2548. }
  2549. }
  2550.  
  2551. })
  2552.  
  2553.  
  2554. }
  2555.  
  2556. if (DO_LINK_PREFETCH) basePrefetching();
  2557.  
  2558. const { notifyPath7081 } = (() => {
  2559. // DO_PARTICIPANT_LIST_HACKS
  2560.  
  2561. const mutexParticipants = new Mutex();
  2562.  
  2563. let uvid = 0;
  2564. let r95dm = 0;
  2565. let c95dm = -1;
  2566.  
  2567. const foundMap = (base, content) => {
  2568. /*
  2569. let lastSearch = 0;
  2570. let founds = base.map(baseEntry => {
  2571. let search = content.indexOf(baseEntry, lastSearch);
  2572. if (search < 0) return false;
  2573. lastSearch = search + 1;
  2574. return true;
  2575. });
  2576. return founds;
  2577. */
  2578. const contentSet = new Set(content);
  2579. return base.map(baseEntry => contentSet.has(baseEntry));
  2580.  
  2581. }
  2582.  
  2583.  
  2584.  
  2585. let participantsForSpliceWR = null;
  2586.  
  2587. class IndexSpliceEntry {
  2588. /**
  2589. *
  2590. * @param {number} _index
  2591. * @param {number} _addedCount
  2592. * @param {any[]} _removed
  2593. */
  2594. constructor(_index, _addedCount, _removed) {
  2595. this.index = _index;
  2596. this.addedCount = _addedCount;
  2597. this.removed = _removed;
  2598. }
  2599. get __proxy312__() {
  2600. return 1
  2601. }
  2602. get type() {
  2603. return 'splice'
  2604. }
  2605. get object() {
  2606. return kRef(participantsForSpliceWR); // avoid memory leakage
  2607. }
  2608. }
  2609.  
  2610. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  2611.  
  2612. let foundsForAfter = foundMap(idsAfter, idsBefore);
  2613. let foundsForBefore = foundMap(idsBefore, idsAfter);
  2614.  
  2615. const nAfter = foundsForAfter.length;
  2616. const nBefore = foundsForBefore.length;
  2617.  
  2618. const indexSplices = [];
  2619. const contentUpdates = [];
  2620. participantsForSpliceWR = null;
  2621. for (let i = 0, j = 0; i < nBefore || j < nAfter;) {
  2622. if (beforeParticipants[i] === participants[j]) {
  2623. i++; j++;
  2624. } else if (idsBefore[i] === idsAfter[j]) {
  2625. // content changed
  2626. contentUpdates.push({ indexI: i, indexJ: j })
  2627. i++; j++;
  2628. } else {
  2629. let addedCount = 0;
  2630. for (let q = j; q < nAfter; q++) {
  2631. if (foundsForAfter[q] === false) addedCount++;
  2632. else break;
  2633. }
  2634. let removedCount = 0;
  2635. for (let q = i; q < nBefore; q++) {
  2636. if (foundsForBefore[q] === false) removedCount++;
  2637. else break;
  2638. }
  2639. if (!addedCount && !removedCount) {
  2640. throw 'ERROR(0xFF32): spliceIndicesFunc';
  2641. }
  2642. const entry = new IndexSpliceEntry(
  2643. j,
  2644. addedCount,
  2645. removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  2646. );
  2647. indexSplices.push(entry);
  2648. i += removedCount;
  2649. j += addedCount;
  2650. }
  2651. }
  2652. foundsForBefore = null;
  2653. foundsForAfter = null;
  2654. idsBefore = null;
  2655. idsAfter = null;
  2656. beforeParticipants = null;
  2657. participantsForSpliceWR = indexSplices.length > 0 ? mWeakRef(participants) : null;
  2658. participants = null;
  2659. return { indexSplices, contentUpdates };
  2660.  
  2661. }
  2662.  
  2663. /*
  2664.  
  2665. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  2666.  
  2667. VM63631:1 Error
  2668. at customElements.get.notifyPath (<anonymous>:1:122)
  2669. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  2670. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  2671. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  2672. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  2673. at ju (live_chat_polymer.js:1674:217)
  2674. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  2675. at b._flushProperties (live_chat_polymer.js:1597:200)
  2676. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  2677. at a.notifyPath (live_chat_polymer.js:1741:182)
  2678.  
  2679. */
  2680.  
  2681. function convertToIds(participants) {
  2682. return participants.map(participant => {
  2683. if (!participant || typeof participant !== 'object') {
  2684. console.warn('Error(0xFA41): convertToIds', participant);
  2685. return participant; // just in case
  2686. }
  2687. let keys = Object.keys(participant);
  2688. // liveChatTextMessageRenderer
  2689. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  2690. // liveChatPaidMessageRenderer
  2691. /*
  2692.  
  2693. 'yt-live-chat-participant-renderer' utilizes the following:
  2694. authorName.simpleText: string
  2695. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  2696. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  2697. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  2698. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  2699.  
  2700. */
  2701. if (keys.length !== 1) {
  2702. console.warn('Error(0xFA42): convertToIds', participant);
  2703. return participant; // just in case
  2704. }
  2705. let key = keys[0];
  2706. let renderer = (participant[key] || 0);
  2707. let authorName = (renderer.authorName || 0);
  2708. let text = `${authorName.simpleText || authorName.text}`
  2709. let res = participant; // fallback if it is not a vaild entry
  2710. if (typeof text !== 'string') {
  2711. console.warn('Error(0xFA53): convertToIds', participant);
  2712. } else {
  2713. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  2714. if (text.length > 1) res = text;
  2715. }
  2716. return res;
  2717. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  2718. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  2719. });
  2720. }
  2721.  
  2722. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  2723. // just update when content is changed.
  2724. if (p1.authorName !== p2.authorName) return true;
  2725. if (p1.authorPhoto !== p2.authorPhoto) return true;
  2726. if (p1.authorBadges !== p2.authorBadges) return true;
  2727. return false;
  2728. } : (p1, p2) => {
  2729. // keep integrity all the time.
  2730. return p1 !== p2; // always true
  2731. }
  2732.  
  2733. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  2734.  
  2735. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2736. if (path !== "participantsManager.participants") {
  2737. return this.__notifyPath5036__.apply(this, arguments);
  2738. }
  2739. if (c95dm === r95dm) return;
  2740. } else {
  2741. const stack = new Error().stack;
  2742. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  2743. return this.__notifyPath5036__.apply(this, arguments);
  2744. }
  2745. }
  2746.  
  2747. if (uvid > 1e8) uvid = uvid % 100;
  2748. let tid = ++uvid;
  2749.  
  2750.  
  2751. // const cnt = this; // "yt-live-chat-participant-list-renderer"
  2752.  
  2753. const wNode = mWeakRef(this);
  2754.  
  2755. mutexParticipants.lockWith(lockResolve => {
  2756.  
  2757. const cnt = kRef(wNode);
  2758.  
  2759. const participants00 = (((cnt || 0).participantsManager || 0).participants || 0);
  2760.  
  2761. if (tid !== uvid || !cnt || typeof (participants00 || 0).splice !== 'function') {
  2762. lockResolve();
  2763. return;
  2764. }
  2765.  
  2766. let doUpdate = false;
  2767.  
  2768. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2769.  
  2770. if (!participants00.r94dm) {
  2771. participants00.r94dm = 1;
  2772. if (++r95dm > 1e9) r95dm = 9;
  2773. participants00.push = function () {
  2774. if (++r95dm > 1e9) r95dm = 9;
  2775. return Array.prototype.push.apply(this, arguments);
  2776. }
  2777. participants00.pop = function () {
  2778. if (++r95dm > 1e9) r95dm = 9;
  2779. return Array.prototype.pop.apply(this, arguments);
  2780. }
  2781. participants00.shift = function () {
  2782. if (++r95dm > 1e9) r95dm = 9;
  2783. return Array.prototype.shift.apply(this, arguments);
  2784. }
  2785. participants00.unshift = function () {
  2786. if (++r95dm > 1e9) r95dm = 9;
  2787. return Array.prototype.unshift.apply(this, arguments);
  2788. }
  2789. participants00.splice = function () {
  2790. if (++r95dm > 1e9) r95dm = 9;
  2791. return Array.prototype.splice.apply(this, arguments);
  2792. }
  2793. participants00.sort = function () {
  2794. if (++r95dm > 1e9) r95dm = 9;
  2795. return Array.prototype.sort.apply(this, arguments);
  2796. }
  2797. participants00.reverse = function () {
  2798. if (++r95dm > 1e9) r95dm = 9;
  2799. return Array.prototype.reverse.apply(this, arguments);
  2800. }
  2801. }
  2802.  
  2803. if (c95dm !== r95dm) {
  2804. c95dm = r95dm;
  2805. doUpdate = true;
  2806. }
  2807.  
  2808. } else {
  2809. doUpdate = true;
  2810. }
  2811.  
  2812. if (!doUpdate) {
  2813. lockResolve();
  2814. return;
  2815. }
  2816.  
  2817. const participants = participants00.slice(0);
  2818. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  2819. beforeParticipantsMap.set(cnt, participants);
  2820.  
  2821. const resPromise = (async () => {
  2822.  
  2823. if (beforeParticipants.length === 0) {
  2824. // not error
  2825. return 0;
  2826. }
  2827.  
  2828. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  2829.  
  2830. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  2831. if (beforeParticipants.length !== countOfElements) {
  2832. // there is somewrong for the cache. - sometimes happen
  2833. return 0;
  2834. }
  2835.  
  2836. const idsBefore = convertToIds(beforeParticipants);
  2837. const idsAfter = convertToIds(participants);
  2838.  
  2839. let { indexSplices, contentUpdates } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  2840.  
  2841. let res = 1; // default 1 for no update
  2842.  
  2843. if (indexSplices.length >= 1) {
  2844.  
  2845.  
  2846. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  2847. // let p1 = indexSplices[0].removed;
  2848. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  2849.  
  2850. /* folllow
  2851. a.notifyPath(c + ".splices", d);
  2852. a.notifyPath(c + ".length", b.length);
  2853. */
  2854. // stampDomArraySplices_
  2855.  
  2856.  
  2857. await new Promise(resolve => {
  2858. cnt.resolveForDOMRendering781 = resolve;
  2859.  
  2860. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  2861. indexSplices
  2862. });
  2863. indexSplices = null;
  2864. participantsForSpliceWR = null;
  2865. cnt.__notifyPath5036__("participantsManager.participants.length",
  2866. participants.length
  2867. );
  2868.  
  2869. });
  2870.  
  2871. // play safe for the change of 'length'
  2872. if (typeof nextBrowserTick !== 'function') {
  2873. await Promise.resolve(0);
  2874. } else {
  2875. await new Promise(resolve => nextBrowserTick(resolve)).then();
  2876. }
  2877.  
  2878. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  2879.  
  2880. const wrongSize = participants.length !== countOfElements
  2881. if (wrongSize) {
  2882. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  2883. return 0;
  2884. }
  2885.  
  2886. res = 2 | 4;
  2887.  
  2888. } else {
  2889.  
  2890. indexSplices = null;
  2891. participantsForSpliceWR = null;
  2892.  
  2893. if (participants.length !== countOfElements) {
  2894. // other unhandled cases
  2895. return 0;
  2896. }
  2897.  
  2898. }
  2899.  
  2900. // participants.length === countOfElements before contentUpdates
  2901. if (contentUpdates.length >= 1) {
  2902. for (const contentUpdate of contentUpdates) {
  2903. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  2904. if (isChanged) {
  2905. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  2906. res |= 4 | 8;
  2907. }
  2908. }
  2909. }
  2910. contentUpdates = null;
  2911.  
  2912. return res;
  2913.  
  2914.  
  2915. })();
  2916.  
  2917.  
  2918. resPromise.then(resValue => {
  2919.  
  2920. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  2921. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  2922. if (resValue === 0) {
  2923. new Promise(resolve => {
  2924. cnt.resolveForDOMRendering781 = resolve;
  2925. isLogRequired && console.log("Full Refresh begins");
  2926. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  2927. }).then(() => {
  2928. isLogRequired && console.log("Full Refresh ends");
  2929. console.groupEnd();
  2930. }).then(lockResolve);
  2931. return;
  2932. }
  2933.  
  2934. const delayLockResolve = (resValue & 4) === 4;
  2935.  
  2936. if (delayLockResolve) {
  2937. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  2938. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  2939. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  2940. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  2941. isLogRequired && console.groupEnd();
  2942. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  2943. // mutex lock with requestAnimationFrame can also disable participants update in background
  2944. requestAnimationFrame(lockResolve);
  2945. } else {
  2946. lockResolve();
  2947. }
  2948.  
  2949. });
  2950.  
  2951. });
  2952.  
  2953. }
  2954.  
  2955. return { notifyPath7081 };
  2956.  
  2957. })();
  2958.  
  2959. const whenDefinedMultiple = async (tags) => {
  2960.  
  2961. const sTags = [...new Set(tags)];
  2962. const len = sTags.length;
  2963.  
  2964. const pTags = new Array(len);
  2965. for (let i = 0; i < len; i++) {
  2966. pTags[i] = customElements.whenDefined(sTags[i]);
  2967. }
  2968.  
  2969. await Promise.all(pTags);
  2970. pTags.length = 0;
  2971.  
  2972. return sTags;
  2973.  
  2974. }
  2975.  
  2976. const onRegistryReadyForDataManipulation = () => {
  2977.  
  2978. function dummy5035(a, b, c) { }
  2979. function dummy411(a, b, c) { }
  2980.  
  2981.  
  2982.  
  2983. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  2984.  
  2985. if (!DO_PARTICIPANT_LIST_HACKS) return;
  2986.  
  2987. const tag = "yt-live-chat-participant-list-renderer";
  2988. const cProto = getProto(document.createElement(tag));
  2989. if (!cProto || typeof cProto.attached !== 'function') {
  2990. // for _registered, proto.attached shall exist when the element is defined.
  2991. // for controller extraction, attached shall exist when instance creates.
  2992. console.warn(`proto.attached for ${tag} is unavailable.`);
  2993. return;
  2994. }
  2995.  
  2996.  
  2997. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  2998.  
  2999. 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'];
  3000. const fgs = {};
  3001. for (const key of fgsArr) fgs[key] = undefined;
  3002.  
  3003. try {
  3004. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  3005. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  3006. } catch (e) { }
  3007. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  3008.  
  3009. const canDoReplacement = (() => {
  3010. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  3011. console.warn('YouTube Live Chat Tamer is running.');
  3012. return;
  3013. }
  3014.  
  3015. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  3016. console.warn('YouTube Live Chat Tamer is running.');
  3017. return;
  3018. }
  3019.  
  3020. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  3021. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  3022.  
  3023. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  3024. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  3025. return;
  3026. }
  3027.  
  3028. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  3029. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  3030. return;
  3031. }
  3032.  
  3033. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  3034. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  3035. return;
  3036. }
  3037. return true;
  3038. })();
  3039.  
  3040. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  3041.  
  3042. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  3043. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3044. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  3045. // const s = fiRSCB.split('.');
  3046. // Feb 2024: 0.403.247 => NG
  3047. // if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  3048. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  3049. // } else {
  3050. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - NG`);
  3051. // }
  3052. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ###`);
  3053. } else {
  3054. console.log("flushRenderStamperComponentBindings_ - not found");
  3055. }
  3056. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  3057.  
  3058. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3059. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  3060. cProto.flushRenderStamperComponentBindings_ = function () {
  3061. // console.log('flushRenderStamperComponentBindings_')
  3062. this.flushRenderStamperComponentBindings66_();
  3063. if (this.resolveForDOMRendering781) {
  3064. this.resolveForDOMRendering781();
  3065. this.resolveForDOMRendering781 = null;
  3066. }
  3067. };
  3068. }
  3069.  
  3070. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  3071. const container = ((this || 0).$ || 0).participants;
  3072. if (!container) return 0;
  3073. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  3074. }
  3075.  
  3076. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  3077.  
  3078. cProto.__attached412__ = cProto.attached;
  3079. const fpPList = function (hostElement) {
  3080. const cnt = insp(hostElement);
  3081. if (beforeParticipantsMap.has(cnt)) return;
  3082. hostElement.classList.add('n9fJ3');
  3083.  
  3084. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  3085. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  3086. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  3087. return;
  3088. }
  3089.  
  3090. groupCollapsed("Participant List attached", "");
  3091. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  3092. // console.log(123, 'appendChild');
  3093. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  3094. // }
  3095.  
  3096. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  3097. // console.log(123, 'insertBefore');
  3098. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  3099. // }
  3100.  
  3101. cnt.__notifyPath5036__ = cnt.notifyPath
  3102. const participants = ((cnt.participantsManager || 0).participants || 0);
  3103. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  3104. console.log(`initial number of participants: ${participants.length}`);
  3105. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  3106. beforeParticipantsMap.set(cnt, newParticipants);
  3107. cnt.notifyPath = notifyPath7081;
  3108. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  3109. console.groupEnd();
  3110. }
  3111. cProto.attached = function () {
  3112. fpPList(this.hostElement || this);
  3113. this.__attached412__.apply(this, arguments);
  3114. };
  3115.  
  3116.  
  3117. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  3118.  
  3119. /** @type {boolean | (()=>boolean)} */
  3120. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  3121. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  3122.  
  3123. let lastMessageDate = 0;
  3124. cProto.stampDomArray66_ = cProto.stampDomArray_;
  3125.  
  3126. cProto.stampDomArray_ = function (...args) {
  3127. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  3128. if (typeof toUseMaintainStableList === 'function') {
  3129. toUseMaintainStableList = toUseMaintainStableList();
  3130. }
  3131. args[5] = toUseMaintainStableList;
  3132. let currentDate = Date.now();
  3133. if (currentDate - lastMessageDate > 440) {
  3134. lastMessageDate = currentDate;
  3135. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  3136. }
  3137. }
  3138. return this.stampDomArray66_.apply(this, args);
  3139. }
  3140.  
  3141. cProto.stampDomArray_.nIegT = 1;
  3142.  
  3143. }
  3144. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  3145. } else {
  3146. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  3147. }
  3148.  
  3149. console.groupEnd();
  3150.  
  3151. if (onPageElements.length >= 1) {
  3152. for (const s of onPageElements) {
  3153. if (insp(s).isAttached === true) {
  3154. fpPList(s);
  3155. }
  3156. }
  3157. }
  3158.  
  3159. }).catch(console.warn);
  3160.  
  3161. };
  3162.  
  3163. if (DO_PARTICIPANT_LIST_HACKS) {
  3164. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  3165. }
  3166.  
  3167.  
  3168.  
  3169. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  3170.  
  3171.  
  3172. const fixChildrenIssue = !!fixChildrenIssue801;
  3173. if (fixChildrenIssue && typeof Object.getOwnPropertyDescriptor === 'function' && typeof Proxy !== 'undefined') {
  3174. const divProto = HTMLDivElement.prototype;
  3175. const polymerControllerSetData3 = function (c, d, e) {
  3176. return insp(this).set(c, d, e);
  3177. }
  3178. const polymerControllerSetData2 = function (c, d) {
  3179. return insp(this).set(c, d);
  3180. }
  3181. const dummyFn = function () {
  3182. console.log('dummyFn', ...arguments);
  3183. };
  3184.  
  3185. const wm44 = new Map();
  3186. function unPolymerSet(elem) {
  3187. const is = elem.is;
  3188. if (is && !elem.set) {
  3189. let rt = wm44.get(is);
  3190. if (!rt) {
  3191. rt = 1;
  3192. const cnt = insp(elem);
  3193. if (cnt !== elem && cnt && typeof cnt.set === 'function') {
  3194. const pcSet = cnt.constructor.prototype.set;
  3195. if (pcSet && typeof pcSet === 'function' && pcSet.length === 3) {
  3196. rt = polymerControllerSetData3;
  3197. } else if (pcSet && typeof pcSet === 'function' && pcSet.length === 2) {
  3198. rt = polymerControllerSetData2;
  3199. }
  3200. }
  3201. wm44.set(is, rt);
  3202. }
  3203. if (typeof rt === 'function') {
  3204. elem.set = rt;
  3205. } else {
  3206. elem.set = dummyFn;
  3207. }
  3208. }
  3209. }
  3210. if (!divProto.__children577__ && !divProto.__children578__) {
  3211.  
  3212. const dp = Object.getOwnPropertyDescriptor(Element.prototype, 'children');
  3213. const dp2 = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'children');
  3214. const dp3 = Object.getOwnPropertyDescriptor(divProto, 'children');
  3215.  
  3216. if (dp && dp.configurable === true && dp.enumerable === true && typeof dp.get === 'function' && !dp2 && !dp3) {
  3217.  
  3218. if (divProto instanceof HTMLElement && divProto instanceof Element) {
  3219.  
  3220. let m = Object.assign({}, dp);
  3221. divProto.__children577__ = dp.get;
  3222. divProto.__children578__ = function () {
  3223. if (this.__children803__) return this.__children803__;
  3224. if (this.__children801__) {
  3225. let arr = [];
  3226. for (let elem = this.firstElementChild; elem !== null; elem = elem.nextElementSibling) {
  3227. if (elem.is) {
  3228. unPolymerSet(elem);
  3229. arr.push(elem);
  3230. }
  3231. }
  3232. if (this.__children801__ === 2) this.__children803__ = arr;
  3233. return arr;
  3234. }
  3235. return 577;
  3236. };
  3237. m.get = function () {
  3238. const r = this.__children578__();
  3239. if (r !== 577) return r;
  3240. return this.__children577__();
  3241. };
  3242. Object.defineProperty(divProto, 'children', m);
  3243.  
  3244. console.log('fixChildrenIssue - set OK')
  3245.  
  3246. }
  3247. }
  3248.  
  3249. }
  3250.  
  3251.  
  3252. }
  3253.  
  3254.  
  3255. const bnForDelayChatOccurrence = () => {
  3256.  
  3257. document.addEventListener('animationstart', (evt) => {
  3258.  
  3259. if (evt.animationName === 'dontRenderAnimation') {
  3260. evt.target.classList.remove('dont-render');
  3261. if (scrollChatFn) scrollChatFn();
  3262. }
  3263.  
  3264. }, true);
  3265.  
  3266. const f = (elm) => {
  3267. if (elm && elm.nodeType === 1) {
  3268. if (!skipDontRender && allowDontRender === true) {
  3269. // innerTextFixFn();
  3270. elm.classList.add('dont-render');
  3271. }
  3272. }
  3273. }
  3274.  
  3275. Node.prototype.__appendChild931__ = function (a) {
  3276. a = dr(a);
  3277. if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  3278. if (a && a.nodeType === 1) f(a);
  3279. else if (a instanceof DocumentFragment) {
  3280. for (let n = a.firstChild; n; n = n.nextSibling) {
  3281. f(n);
  3282. }
  3283. }
  3284. }
  3285. }
  3286.  
  3287. Node.prototype.__appendChild932__ = function () {
  3288. this.__appendChild931__.apply(this, arguments);
  3289. return Node.prototype.appendChild.apply(this, arguments);
  3290. }
  3291.  
  3292.  
  3293. };
  3294.  
  3295. const watchUserCSS = () => {
  3296.  
  3297. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  3298.  
  3299. const getElemFromWR = (nr) => {
  3300. const n = kRef(nr);
  3301. if (n && n.isConnected) return n;
  3302. return null;
  3303. }
  3304.  
  3305. const clearContentVisibilitySizing = () => {
  3306. Promise.resolve().then(() => {
  3307.  
  3308. const e = document.querySelector('#show-more[disabled]');
  3309. let btnShowMoreWR = e ? mWeakRef(e) : null;
  3310.  
  3311. let lastVisibleItemWR = null;
  3312. for (const elm of document.querySelectorAll('[wSr93]')) {
  3313. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  3314. elm.setAttribute('wSr93', '');
  3315. // custom CSS property --wsr94 not working when attribute wSr93 removed
  3316. }
  3317. foregroundPromiseFn().then(() => {
  3318. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  3319. if (btnShowMore) btnShowMore.click();
  3320. else {
  3321. // would not work if switch it frequently
  3322. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  3323. if (lastVisibleItem) {
  3324.  
  3325. Promise.resolve()
  3326. .then(() => lastVisibleItem.scrollIntoView())
  3327. .then(() => lastVisibleItem.scrollIntoView(false))
  3328. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  3329. .catch(e => { }) // break the chain when method not callable
  3330.  
  3331. }
  3332. }
  3333. });
  3334.  
  3335. });
  3336.  
  3337. }
  3338.  
  3339. const mutObserver = new MutationObserver((mutations) => {
  3340. for (const mutation of mutations) {
  3341. if ((mutation.addedNodes || 0).length >= 1) {
  3342. for (const addedNode of mutation.addedNodes) {
  3343. if (addedNode.nodeName === 'STYLE') {
  3344. clearContentVisibilitySizing();
  3345. return;
  3346. }
  3347. }
  3348. }
  3349. if ((mutation.removedNodes || 0).length >= 1) {
  3350. for (const removedNode of mutation.removedNodes) {
  3351. if (removedNode.nodeName === 'STYLE') {
  3352. clearContentVisibilitySizing();
  3353. return;
  3354. }
  3355. }
  3356. }
  3357. }
  3358. });
  3359.  
  3360. mutObserver.observe(document.documentElement, {
  3361. childList: true,
  3362. subtree: false
  3363. });
  3364. mutObserver.observe(document.head, {
  3365. childList: true,
  3366. subtree: false
  3367. });
  3368. mutObserver.observe(document.body, {
  3369. childList: true,
  3370. subtree: false
  3371. });
  3372.  
  3373. }
  3374.  
  3375.  
  3376. class WillChangeController {
  3377. constructor(itemScroller, willChangeValue) {
  3378. this.element = itemScroller;
  3379. this.counter = 0;
  3380. this.active = false;
  3381. this.willChangeValue = willChangeValue;
  3382. }
  3383.  
  3384. beforeOper() {
  3385. if (!this.active) {
  3386. this.active = true;
  3387. this.element.style.willChange = this.willChangeValue;
  3388. }
  3389. this.counter++;
  3390. }
  3391.  
  3392. afterOper() {
  3393. const c = this.counter;
  3394. foregroundPromiseFn().then(() => {
  3395. if (c === this.counter) {
  3396. this.active = false;
  3397. this.element.style.willChange = '';
  3398. }
  3399. });
  3400. }
  3401.  
  3402. release() {
  3403. const element = this.element;
  3404. this.element = null;
  3405. this.counter = 1e16;
  3406. this.active = false;
  3407. try {
  3408. element.style.willChange = '';
  3409. } catch (e) { }
  3410. }
  3411.  
  3412. }
  3413.  
  3414.  
  3415. const skzData = (skz) => skz.data = {
  3416. "message": {
  3417. "runs": [
  3418. {
  3419. "text": "em2o"
  3420. },
  3421. {
  3422. "emoji": {
  3423. "emojiId": "cm35z",
  3424. "shortcuts": [
  3425. ":_s:",
  3426. ":s:"
  3427. ],
  3428. "searchTerms": [
  3429. "_s",
  3430. "s"
  3431. ],
  3432. "image": {
  3433. "thumbnails": [
  3434. {
  3435. "url": dummyImgURL,
  3436. "width": 48,
  3437. "height": 48
  3438. }
  3439. ],
  3440. "accessibility": {
  3441. "accessibilityData": {
  3442. "label": "s"
  3443. }
  3444. }
  3445. },
  3446. "isCustomEmoji": true
  3447. }
  3448. },
  3449. {
  3450. "text": "ji"
  3451. }
  3452. ]
  3453. },
  3454. "authorName": {
  3455. "simpleText": "N"
  3456. },
  3457. "authorPhoto": {
  3458. "thumbnails": [
  3459. {
  3460. "url": dummyImgURL,
  3461. "width": 64,
  3462. "height": 64
  3463. }
  3464. ]
  3465. },
  3466. "contextMenuEndpoint": {
  3467. "commandMetadata": {
  3468. "webCommandMetadata": {
  3469. "ignoreNavigation": true
  3470. }
  3471. },
  3472. "liveChatItemContextMenuEndpoint": {
  3473. "params": "123=="
  3474. }
  3475. },
  3476. "id": "sk35z",
  3477. "timestampUsec": "1232302352350000",
  3478. "authorBadges": [
  3479. {
  3480. "liveChatAuthorBadgeRenderer": {
  3481. "customThumbnail": {
  3482. "thumbnails": [
  3483. {
  3484. "url": dummyImgURL,
  3485. "width": 16,
  3486. "height": 16
  3487. },
  3488. {
  3489. "url": dummyImgURL,
  3490. "width": 32,
  3491. "height": 32
  3492. }
  3493. ]
  3494. },
  3495. "tooltip": "T",
  3496. "accessibility": {
  3497. "accessibilityData": {
  3498. "label": "E"
  3499. }
  3500. }
  3501. }
  3502. }
  3503. ],
  3504. "authorExternalChannelId": "A",
  3505. "contextMenuAccessibility": {
  3506. "accessibilityData": {
  3507. "label": "E"
  3508. }
  3509. },
  3510. "timestampText": {
  3511. "simpleText": "0:43"
  3512. }
  3513. };
  3514.  
  3515.  
  3516.  
  3517. const { lcRendererElm, visObserver } = (() => {
  3518.  
  3519.  
  3520.  
  3521. let lcRendererWR = null;
  3522.  
  3523. const lcRendererElm = () => {
  3524. let lcRenderer = kRef(lcRendererWR);
  3525. if (!lcRenderer || !lcRenderer.isConnected) {
  3526. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  3527. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  3528. }
  3529. return lcRenderer;
  3530. };
  3531.  
  3532.  
  3533. let hasFirstShowMore = false;
  3534.  
  3535. const visObserverFn = (entry) => {
  3536.  
  3537. const target = entry.target;
  3538. if (!target) return;
  3539. // if(target.classList.contains('dont-render')) return;
  3540. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  3541. // const h = entry.boundingClientRect.height;
  3542. /*
  3543. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  3544. // e.g. under fullscreen. the element created but not rendered.
  3545. target.setAttribute('wSr93', '');
  3546. return;
  3547. }
  3548. */
  3549. if (isVisible) {
  3550. // target.style.setProperty('--wsr94', h + 'px');
  3551. target.setAttribute('wSr93', 'visible');
  3552. if (nNextElem(target) === null) {
  3553.  
  3554. // firstVisibleItemDetected = true;
  3555. /*
  3556. if (dateNow() - lastScroll < 80) {
  3557. lastLShow = 0;
  3558. lastScroll = 0;
  3559. Promise.resolve().then(clickShowMore);
  3560. } else {
  3561. lastLShow = dateNow();
  3562. }
  3563. */
  3564. // lastLShow = dateNow();
  3565. } else if (!hasFirstShowMore) { // should more than one item being visible
  3566. // implement inside visObserver to ensure there is sufficient delay
  3567. hasFirstShowMore = true;
  3568. foregroundPromiseFn().then(() => {
  3569. // foreground page
  3570. // page visibly ready -> load the latest comments at initial loading
  3571. const lcRenderer = lcRendererElm();
  3572. if (lcRenderer) {
  3573. if (typeof nextBrowserTick !== 'function') {
  3574. insp(lcRenderer).scrollToBottom_();
  3575. } else {
  3576. nextBrowserTick(() => {
  3577. const cnt = insp(lcRenderer);
  3578. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3579. cnt.scrollToBottom_();
  3580. });
  3581. }
  3582. }
  3583. });
  3584. }
  3585. }
  3586. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  3587.  
  3588. // target.style.setProperty('--wsr94', h + 'px');
  3589. target.setAttribute('wSr93', 'hidden');
  3590. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  3591.  
  3592. }
  3593.  
  3594.  
  3595.  
  3596. const visObserver = new IntersectionObserver((entries) => {
  3597.  
  3598. for (const entry of entries) {
  3599.  
  3600. Promise.resolve(entry).then(visObserverFn);
  3601.  
  3602. }
  3603.  
  3604. }, {
  3605. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  3606. rootMargin: "0px",
  3607. threshold: [0.05, 0.95],
  3608. });
  3609.  
  3610.  
  3611. return { lcRendererElm, visObserver }
  3612.  
  3613.  
  3614. })();
  3615.  
  3616. const { setupMutObserver } = (() => {
  3617.  
  3618. async function asyncTickerBackgroundOverridedChecker() {
  3619.  
  3620. try {
  3621. await promiseForCustomYtElementsReady.then();
  3622. await customElements.whenDefined('yt-live-chat-text-message-renderer');
  3623. await new Promise(r => setTimeout(r, 800));
  3624.  
  3625. if (!hasTimerModified) return;
  3626. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  3627. if (!tickerRenderer) return;
  3628.  
  3629. const tickerRendererDollar = indr(tickerRenderer);
  3630. const items = (tickerRendererDollar || 0).items || 0;
  3631. if (!items) return;
  3632. const template = document.createElement('template');
  3633. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  3634. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  3635. dimmed="" [dummy777]>
  3636. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  3637. 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));">
  3638. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  3639. <yt-img-shadow777 id="author-photo" height="24" width="24"
  3640. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  3641. style="background-color: transparent;" loaded=""><img id="img"
  3642. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  3643. src="${dummyImgURL}"></yt-img-shadow777>
  3644.  
  3645. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  3646. </div>
  3647. </div>
  3648. </yt-live-chat-ticker-dummy777-item-renderer>`;
  3649. const dummy777 = template.content.firstElementChild;
  3650. await Promise.resolve().then();
  3651. let res = 0;
  3652. if (items instanceof HTMLElement && items.isConnected === true) {
  3653. try {
  3654. items.appendChild(dummy777);
  3655. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  3656. if (container.isConnected === true) {
  3657. const evaluated = `${getComputedStyleCached(container).background}`;
  3658. container = null;
  3659. res = evaluated.indexOf('0.') < 4 ? 1 : 2;
  3660. }
  3661. } catch (e) { console.warn(e) }
  3662. HTMLElement.prototype.remove.call(dummy777);
  3663. }
  3664. await Promise.resolve().then();
  3665. dummy777.textContent = '';
  3666. if (res === 1) {
  3667. // not fulfilling
  3668. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3669. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3670. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3671. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3672. );
  3673. 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');
  3674. console.groupEnd();
  3675. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  3676. } else if (res === 2) {
  3677. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3678. }
  3679. } catch (e) {
  3680. console.warn(e);
  3681. }
  3682. }
  3683.  
  3684. // async function asyncDelayChatOccurrence(m2) {
  3685. // try {
  3686. // await promiseForCustomYtElementsReady.then();
  3687. // await customElements.whenDefined('yt-live-chat-text-message-renderer');
  3688. // await new Promise(r => setTimeout(r, 1));
  3689. // const dummy888 = document.createElement('yt-live-chat-text-message-renderer');
  3690. // // const template = document.createElement('template');
  3691. // // template.innerHTML = "<yt-live-chat-text-message-renderer></yt-live-chat-text-message-renderer>"
  3692. // // const dummy888 = template.content.firstElementChild;
  3693. // const skzCnt = insp(dummy888);
  3694. // if (!(skzCnt && 'data' in skzCnt && 'attached' in skzCnt)) {
  3695. // return;
  3696. // }
  3697. // if (!skzCnt.hostElement) skzCnt.hostElement = dummy888;
  3698. // /** @type {HTMLTemplateElement} */
  3699. // const skzElem = dummy888;
  3700. // let cz1 = null;
  3701. // const deferredZy1 = new Promise(resolve => {
  3702. // skzCnt.attached = function () {
  3703. // cz1 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  3704. // resolve(skzElem.textContent);
  3705. // }
  3706. // skzCnt.detached = function () {
  3707. // }
  3708. // });
  3709. // skzElem.id = 'sk35z';
  3710. // skzData(skzCnt);
  3711. // sk35zResolveFn = null;
  3712. // const deferredMutation = new Promise(resolve => {
  3713. // sk35zResolveFn = resolve;
  3714. // HTMLElement.prototype.appendChild.call(m2, skzElem);
  3715. // });
  3716. // const [zy1, _] = await Promise.all([deferredZy1, deferredMutation]);
  3717. // skzCnt.attached = function () { };
  3718. // function fn() {
  3719. // const zy2 = skzElem.textContent;
  3720. // const cz2 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  3721. // if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  3722. // allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  3723. // }
  3724. // if (allowDontRender === true) return true;
  3725. // if (allowDontRender === false) {
  3726. // console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3727. // "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3728. // "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3729. // );
  3730. // 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');
  3731. // console.groupEnd();
  3732. // }
  3733. // }
  3734. // await new Promise(r => setTimeout(r, 1));
  3735. // if (!fn()) return;
  3736. // await foregroundPromiseFn().then();
  3737. // if (!fn()) return;
  3738. // skzElem.remove();
  3739. // await Promise.resolve().then();
  3740. // skzElem.textContent = '';
  3741. // console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3742. // } catch (e) {
  3743. // console.warn(e);
  3744. // }
  3745. // }
  3746.  
  3747. const mutFn = (items) => {
  3748. let seqIndex = -1;
  3749. const elementSet = new Set();
  3750. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  3751. if (node.hasAttribute('wSr93')) {
  3752. seqIndex = parseInt(node.getAttribute('yt-chat-item-seq'), 10);
  3753. break;
  3754. }
  3755. node.setAttribute('wSr93', '');
  3756. visObserver.observe(node);
  3757. elementSet.add(node);
  3758. }
  3759. let iter = elementSet.values();
  3760. let i = seqIndex + elementSet.size;
  3761. for (let curr; curr = iter.next().value;) {
  3762. curr.setAttribute('yt-chat-item-seq', i % 60);
  3763. curr.classList.add('yt-chat-item-' + ((i % 2) ? 'odd' : 'even'));
  3764. i--;
  3765. }
  3766. iter = null;
  3767. elementSet.clear();
  3768. }
  3769.  
  3770. const mutObserver = new MutationObserver((mutations) => {
  3771. const items = (mutations[0] || 0).target;
  3772. if (!items) return;
  3773. if (sk35zResolveFn) {
  3774. sk35zResolveFn();
  3775. sk35zResolveFn = null;
  3776. }
  3777. mutFn(items);
  3778. });
  3779.  
  3780. const setupMutObserver = (m2) => {
  3781. scrollChatFn = null;
  3782. mutObserver.disconnect();
  3783. mutObserver.takeRecords();
  3784. if (m2) {
  3785. if (typeof m2.__appendChild932__ === 'function') {
  3786. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  3787. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  3788. }
  3789. mutObserver.observe(m2, {
  3790. childList: true,
  3791. subtree: false
  3792. });
  3793. mutFn(m2);
  3794.  
  3795. const isFirstList = firstList;
  3796. firstList = false;
  3797.  
  3798. if (ENABLE_OVERFLOW_ANCHOR) {
  3799.  
  3800. let items = m2;
  3801. let addedAnchor = false;
  3802. if (items) {
  3803. if (items.nextElementSibling === null) {
  3804. items.classList.add('no-anchor');
  3805. addedAnchor = true;
  3806. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  3807. }
  3808. }
  3809.  
  3810.  
  3811.  
  3812. if (addedAnchor) {
  3813. nodeParent(m2).classList.add('no-anchor'); // required
  3814. }
  3815.  
  3816. }
  3817.  
  3818.  
  3819.  
  3820. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  3821.  
  3822. (() => {
  3823.  
  3824. const tag = 'yt-iframed-player-events-relay'
  3825. const dummy = document.createElement(tag);
  3826.  
  3827. const cProto = getProto(dummy);
  3828. if (!cProto || !cProto.handlePostMessage_) {
  3829. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  3830. return;
  3831. }
  3832.  
  3833. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_ && !cProto.handlePostMessage67_ ) {
  3834.  
  3835. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  3836.  
  3837. const handlePostMessageAfterPromiseA = (da) => {
  3838.  
  3839. if (!da || typeof da !== 'object') return;
  3840.  
  3841. if ('yt-player-state-change' in da) {
  3842.  
  3843. const qc = da['yt-player-state-change'];
  3844.  
  3845.  
  3846. let isQcChanged = false;
  3847.  
  3848. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  3849. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  3850. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  3851.  
  3852.  
  3853. if ((isQcChanged) && playerState !== _playerState) {
  3854. playerEventsByIframeRelay = true;
  3855. onPlayStateChangePromise = new Promise((resolve) => {
  3856. const k = _playerState;
  3857. foregroundPromiseFn().then(() => {
  3858. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  3859. onPlayStateChangePromise = null;
  3860. resolve();
  3861. })
  3862. }).catch(console.warn);
  3863.  
  3864. }
  3865.  
  3866. } else if ('yt-player-video-progress' in da) {
  3867. const vp = da['yt-player-video-progress'];
  3868.  
  3869.  
  3870. relayCount++;
  3871. lastPlayerProgress = vp > 0 ? vp : 0;
  3872.  
  3873.  
  3874. if (relayPromise && vp > 0 && relayCount >= 2) {
  3875. if (onPlayStateChangePromise) {
  3876. onPlayStateChangePromise.then(() => {
  3877. relayPromise && relayPromise.resolve();
  3878. relayPromise = null;
  3879. })
  3880. } else {
  3881. relayPromise.resolve();
  3882. relayPromise = null;
  3883. }
  3884. }
  3885.  
  3886. }
  3887.  
  3888. };
  3889.  
  3890. cProto.handlePostMessage67_ = function (a) {
  3891.  
  3892. let da = a.data;
  3893. const wNode = mWeakRef(this);
  3894. // const wData = mWeakRef(da);
  3895.  
  3896. playEventsStack = playEventsStack.then(() => {
  3897.  
  3898. const cnt = kRef(wNode);
  3899. // const da = kRef(wData);
  3900.  
  3901. if (!cnt || !a || !da) return;
  3902. handlePostMessageAfterPromiseA(da);
  3903. da = null;
  3904.  
  3905. const r = cnt.handlePostMessage66_(a);
  3906. a = null;
  3907.  
  3908. }).catch(console.warn);
  3909.  
  3910. }
  3911.  
  3912. const handlePostMessageAfterPromiseB = (da) => {
  3913.  
  3914. const lcr = document.querySelector('yt-live-chat-renderer');
  3915. const psc = document.querySelector("yt-player-seek-continuation");
  3916. if (lcr && psc && lcr.replayBuffer_) {
  3917.  
  3918. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  3919. const daProgress = da['yt-player-video-progress'] * 1000
  3920. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  3921.  
  3922. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  3923. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  3924.  
  3925. // console.log(deepCopy( front_))
  3926. // console.log(deepCopy( back_))
  3927. // console.log(rbProgress, daProgress, )
  3928. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  3929. // no action
  3930. // console.log('ss1')
  3931. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  3932. // daProgress - 1200 < rbProgress < daProgress + 3400
  3933. // console.log('ss2')
  3934. } else {
  3935.  
  3936. lcr.previousProgressSec = 1E-5;
  3937. // lcr._setIsSeeking(!0),
  3938. lcr.replayBuffer_.clear()
  3939. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  3940. }
  3941.  
  3942. }
  3943.  
  3944.  
  3945. };
  3946.  
  3947. cProto.handlePostMessage_ = function (a) {
  3948.  
  3949. let da = (a || 0).data || 0;
  3950. const wNode = mWeakRef(this);
  3951.  
  3952. if (typeof da !== 'object') return;
  3953.  
  3954. if (waitForInitialDataCompletion === 1) return;
  3955.  
  3956. if (!isPlayProgressTriggered) {
  3957. isPlayProgressTriggered = true; // set once
  3958.  
  3959. if ('yt-player-video-progress' in da) {
  3960. waitForInitialDataCompletion = 1;
  3961.  
  3962. const wrapWith = (data) => {
  3963. const { origin } = a;
  3964. return {
  3965. origin,
  3966. data
  3967. };
  3968. }
  3969.  
  3970. this.handlePostMessage67_(wrapWith({
  3971. "yt-iframed-parent-ready": true
  3972. }));
  3973.  
  3974.  
  3975. playEventsStack = playEventsStack.then(() => {
  3976.  
  3977. const cnt = kRef(wNode);
  3978.  
  3979. if (!cnt || !a || !da) return;
  3980.  
  3981. handlePostMessageAfterPromiseB(da);
  3982. da = null;
  3983.  
  3984. waitForInitialDataCompletion = 2;
  3985.  
  3986. const r = cnt.handlePostMessage_(a); // isPlayProgressTriggered is set
  3987. a = null;
  3988.  
  3989. }).catch(console.warn);
  3990.  
  3991. return;
  3992.  
  3993. }
  3994.  
  3995. }
  3996.  
  3997. this.handlePostMessage67_(a);
  3998.  
  3999. }
  4000.  
  4001. }
  4002.  
  4003.  
  4004. })();
  4005.  
  4006. }
  4007.  
  4008. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  4009. asyncTickerBackgroundOverridedChecker();
  4010. }
  4011.  
  4012. }
  4013. }
  4014.  
  4015. return { setupMutObserver };
  4016.  
  4017.  
  4018.  
  4019. })();
  4020.  
  4021. const setupEvents = () => {
  4022.  
  4023.  
  4024. let scrollCount = 0;
  4025.  
  4026. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  4027.  
  4028.  
  4029. const delayFlushActiveItemsAfterUserActionK_ = () => {
  4030.  
  4031. const lcRenderer = lcRendererElm();
  4032. if (lcRenderer) {
  4033. const cnt = insp(lcRenderer);
  4034. if (!cnt.hasUserJustInteracted11_) return;
  4035. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  4036. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  4037. }
  4038. }
  4039.  
  4040. }
  4041.  
  4042. document.addEventListener('scroll', (evt) => {
  4043. if (!evt || !evt.isTrusted) return;
  4044. // lastScroll = dateNow();
  4045. if (++scrollCount > 1e9) scrollCount = 9;
  4046. }, passiveCapture); // support contain => support passive
  4047.  
  4048. let lastScrollCount = -1;
  4049. document.addEventListener('wheel', (evt) => {
  4050. if (!evt || !evt.isTrusted) return;
  4051. if (lastScrollCount === scrollCount) return;
  4052. lastScrollCount = scrollCount;
  4053. lastWheel = dateNow();
  4054. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4055. }, passiveCapture); // support contain => support passive
  4056.  
  4057. document.addEventListener('mousedown', (evt) => {
  4058. if (!evt || !evt.isTrusted) return;
  4059. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4060. lastMouseDown = dateNow();
  4061. currentMouseDown = true;
  4062. lastUserInteraction = lastMouseDown;
  4063. }, passiveCapture);
  4064.  
  4065. document.addEventListener('pointerdown', (evt) => {
  4066. if (!evt || !evt.isTrusted) return;
  4067. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4068. lastMouseDown = dateNow();
  4069. currentMouseDown = true;
  4070. lastUserInteraction = lastMouseDown;
  4071. }, passiveCapture);
  4072.  
  4073. document.addEventListener('click', (evt) => {
  4074. if (!evt || !evt.isTrusted) return;
  4075. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4076. lastMouseDown = lastMouseUp = dateNow();
  4077. currentMouseDown = false;
  4078. lastUserInteraction = lastMouseDown;
  4079. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4080. }, passiveCapture);
  4081.  
  4082. document.addEventListener('tap', (evt) => {
  4083. if (!evt || !evt.isTrusted) return;
  4084. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4085. lastMouseDown = lastMouseUp = dateNow();
  4086. currentMouseDown = false;
  4087. lastUserInteraction = lastMouseDown;
  4088. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4089. }, passiveCapture);
  4090.  
  4091.  
  4092. document.addEventListener('mouseup', (evt) => {
  4093. if (!evt || !evt.isTrusted) return;
  4094. if (currentMouseDown) {
  4095. lastMouseUp = dateNow();
  4096. currentMouseDown = false;
  4097. lastUserInteraction = lastMouseUp;
  4098. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4099. }
  4100. }, passiveCapture);
  4101.  
  4102.  
  4103. document.addEventListener('pointerup', (evt) => {
  4104. if (!evt || !evt.isTrusted) return;
  4105. if (currentMouseDown) {
  4106. lastMouseUp = dateNow();
  4107. currentMouseDown = false;
  4108. lastUserInteraction = lastMouseUp;
  4109. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4110. }
  4111. }, passiveCapture);
  4112.  
  4113. document.addEventListener('touchstart', (evt) => {
  4114. if (!evt || !evt.isTrusted) return;
  4115. lastTouchDown = dateNow();
  4116. currentTouchDown = true;
  4117. lastUserInteraction = lastTouchDown;
  4118. }, passiveCapture);
  4119.  
  4120. document.addEventListener('touchmove', (evt) => {
  4121. if (!evt || !evt.isTrusted) return;
  4122. lastTouchDown = dateNow();
  4123. currentTouchDown = true;
  4124. lastUserInteraction = lastTouchDown;
  4125. }, passiveCapture);
  4126.  
  4127. document.addEventListener('touchend', (evt) => {
  4128. if (!evt || !evt.isTrusted) return;
  4129. if (currentTouchDown) {
  4130. lastTouchUp = dateNow();
  4131. currentTouchDown = false;
  4132. lastUserInteraction = lastTouchUp;
  4133. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4134. }
  4135. }, passiveCapture);
  4136.  
  4137. document.addEventListener('touchcancel', (evt) => {
  4138. if (!evt || !evt.isTrusted) return;
  4139. if (currentTouchDown) {
  4140. lastTouchUp = dateNow();
  4141. currentTouchDown = false;
  4142. lastUserInteraction = lastTouchUp;
  4143. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4144. }
  4145. }, passiveCapture);
  4146.  
  4147.  
  4148. }
  4149.  
  4150. const getTimestampUsec = (itemRenderer) => {
  4151. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  4152. return itemRenderer.timestampUsec
  4153. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  4154. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  4155. if (messageRenderer) {
  4156.  
  4157. const messageRendererKey = firstObjectKey(messageRenderer);
  4158. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  4159. const messageRendererData = messageRenderer[messageRendererKey];
  4160. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  4161. return messageRendererData.timestampUsec
  4162. }
  4163. }
  4164. }
  4165. }
  4166. return null;
  4167. }
  4168.  
  4169. const onRegistryReadyForDOMOperations = () => {
  4170.  
  4171. let firstCheckedOnYtInit = false;
  4172.  
  4173. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  4174.  
  4175. const mightFirstCheckOnYtInit = () => {
  4176. if (firstCheckedOnYtInit) return;
  4177. firstCheckedOnYtInit = true;
  4178.  
  4179. if (!document.body || !document.head) return;
  4180. if (!assertorURL()) return;
  4181.  
  4182. addCssManaged();
  4183.  
  4184. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  4185. if (efsContainer && efsContainer.parentNode !== document.body) {
  4186. document.body.appendChild(efsContainer);
  4187. }
  4188.  
  4189. };
  4190.  
  4191. if (!assertorURL()) return;
  4192. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  4193.  
  4194.  
  4195. const { weakWrap } = (() => {
  4196.  
  4197.  
  4198. // const tickerFuncProps = new Set([
  4199. // 'animateShowStats', 'animateHideStats', // updateStatsBarAndMaybeShowAnimationRevised
  4200. // 'collapse', // slideDownNoSelfLeakage
  4201. // 'requestRemoval', // collapseNoSelfLeakage
  4202. // 'setContainerWidth', 'get', 'set', // deletedChangedNoSelfLeakage
  4203. // 'computeAriaLabel', //dataChanged
  4204. // 'startCountdown', // dataChanged [in case]
  4205. // ]);
  4206.  
  4207. // const tickerTags = new Set([
  4208. // "yt-live-chat-ticker-renderer",
  4209. // "yt-live-chat-ticker-paid-message-item-renderer",
  4210. // "yt-live-chat-ticker-paid-sticker-item-renderer",
  4211. // "yt-live-chat-ticker-sponsor-item-renderer"
  4212. // ]);
  4213.  
  4214. // const emptySet = new Set();
  4215.  
  4216.  
  4217.  
  4218. // const tickerFuncPropsFn = (cnt) => {
  4219.  
  4220. // const is = `${cnt.is}`;
  4221.  
  4222. // if (tickerTags.has(is)) {
  4223. // let flg = 0;
  4224. // if (cnt.get && cnt.set) flg |= 1;
  4225. // if (cnt.setContainerWidth && cnt.collapse && cnt.requestRemoval) flg |= 2;
  4226. // if (cnt.animateShowStats && cnt.animateHideStats) flg |= 4;
  4227. // if (cnt.startCountdown) flg |= 8;
  4228. // console.log(`DEBUG flag_6877 = ${flg}`, is);
  4229. // // DEBUG flag_6877 = 15 yt-live-chat-ticker-paid-message-item-renderer
  4230. // // DEBUG flag_6877 = 11 yt-live-chat-ticker-sponsor-item-renderer
  4231. // return tickerFuncProps;
  4232. // }
  4233.  
  4234. // return emptySet;
  4235.  
  4236.  
  4237. // }
  4238.  
  4239.  
  4240. // const smb = Symbol();
  4241. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  4242. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  4243. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  4244.  
  4245.  
  4246.  
  4247.  
  4248. const thisConversionFn = (thisArg) => {
  4249. if (!thisArg) return null;
  4250. const kThis = thisArg[vmb];
  4251. if (kThis) {
  4252. const ref = kThis.ref;
  4253. return (ref ? kRef(ref) : null) || null;
  4254. }
  4255. return thisArg;
  4256. }
  4257. const pFnHandler2 = {
  4258. get(target, prop) {
  4259. if (prop === vmc) return target;
  4260. return Reflect.get(target, prop);
  4261. },
  4262. apply(target, thisArg, argumentsList) {
  4263. thisArg = thisConversionFn(thisArg);
  4264. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  4265. }
  4266. }
  4267. const proxySelfHandler = {
  4268. get(target, prop) {
  4269. if(prop === vmb) return target;
  4270. const ref = target.ref;
  4271. const cnt = kRef(ref);
  4272. if (!cnt) return;
  4273. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  4274. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  4275. return cnt[prop][vmd];
  4276. }
  4277. return cnt[prop];
  4278. },
  4279. set(target, prop, value) {
  4280. const cnt = kRef(target.ref);
  4281. if (!cnt) return true;
  4282. if(value && (value[vmc] || value[vmb])){
  4283. cnt[prop] = value[vmc] || thisConversionFn(value);
  4284. return true;
  4285. }
  4286. cnt[prop] = value;
  4287. return true;
  4288. }
  4289. };
  4290. const weakWrap = (thisArg) => {
  4291. thisArg = thisConversionFn(thisArg);
  4292. if (!thisArg) {
  4293. console.error('thisArg is not found');
  4294. return null;
  4295. }
  4296. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  4297. }
  4298.  
  4299.  
  4300.  
  4301.  
  4302.  
  4303.  
  4304. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  4305. window.getComputedStyle533 = window.getComputedStyle;
  4306. window.getComputedStyle = function (a, ...args) {
  4307. a = thisConversionFn(a);
  4308. if (a) {
  4309. return getComputedStyle533(a, ...args);
  4310. }
  4311. return null;
  4312. }
  4313. }
  4314.  
  4315.  
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  
  4321. // const fnProxySelf = function (...args) {
  4322. // const cnt = kRef(this.ref);
  4323. // if (cnt) {
  4324. // return cnt[this.prop](...args); // might throw error
  4325. // }
  4326. // }
  4327. // const proxySelfHandler = {
  4328. // get(target, prop) {
  4329. // const ref = target.ref;
  4330. // const cnt = kRef(ref);
  4331. // if (!cnt) return;
  4332. // if (prop === 'dtz06') return 1;
  4333. // if (typeof cnt[prop] === 'function') {
  4334. // if (!target.funcs.has(prop)) {
  4335. // console.warn(`proxy get to function | prop: ${prop} | is: ${cnt.is}`);
  4336. // }
  4337. // if (!target[`$$${prop}$$`]) target[`$$${prop}$$`] = fnProxySelf.bind({ prop, ref });
  4338. // return target[`$$${prop}$$`];
  4339. // }
  4340. // return cnt[prop];
  4341. // },
  4342. // set(target, prop, value) {
  4343. // const cnt = kRef(target.ref);
  4344. // if (!cnt) return true;
  4345. // if (typeof value === 'function') {
  4346. // console.warn(`proxy set to function | prop: ${prop} | is: ${cnt.is}`);
  4347. // cnt[prop] = value;
  4348. // return true;
  4349. // }
  4350. // cnt[prop] = value;
  4351. // return true;
  4352. // }
  4353. // };
  4354.  
  4355. // return { tickerFuncPropsFn, proxySelfHandler }
  4356.  
  4357. return {weakWrap}
  4358. })();
  4359.  
  4360.  
  4361.  
  4362. if (document.documentElement && document.head) {
  4363. addCssManaged();
  4364. }
  4365. // console.log(document.body===null)
  4366.  
  4367. const preprocessChatLiveActionsMap = new WeakSet();
  4368.  
  4369. const toLAObj=(aItem)=>{
  4370.  
  4371. if (!aItem || typeof aItem !== 'object') return false;
  4372. const key = firstObjectKey(aItem); // addLiveChatTickerItemAction
  4373. if (!key) return false;
  4374. let obj = aItem[key];
  4375. if (!obj || typeof obj !== 'object') return false;
  4376.  
  4377. if (typeof (obj.item || 0) == 'object' && firstObjectKey(obj) === 'item') {
  4378. obj = obj.item;
  4379. const key = firstObjectKey(obj);
  4380. if (key) {
  4381. obj = obj[key];
  4382. }
  4383. }
  4384.  
  4385. return obj;
  4386.  
  4387. };
  4388.  
  4389. const preprocessChatLiveActions = (arr) =>{
  4390.  
  4391. if(!arr || !arr.length) return arr;
  4392.  
  4393. if(preprocessChatLiveActionsMap.has(arr)) return arr;
  4394. preprocessChatLiveActionsMap.add(arr);
  4395.  
  4396. const ct = Date.now();
  4397.  
  4398. // console.log('preprocessChatLiveActions', arr)
  4399.  
  4400.  
  4401. const mapper = new Map();
  4402.  
  4403. // without delaying. get the time of request
  4404. // (both streaming and replay, but replay relys on progress update so background operation is suppressed)
  4405. for (let j = 0, l = arr.length; j < l; j++) {
  4406. const aItem = arr[j];
  4407.  
  4408. const obj = toLAObj(aItem);
  4409. if(obj === false) continue;
  4410. if (obj.id && !obj.__timestampActionRequest__) {
  4411. // for all item entries
  4412. obj.__timestampActionRequest__ = ct;
  4413. }
  4414.  
  4415. if (obj.id && obj.__timestampActionRequest__ > 0 && obj.durationSec > 0 && obj.fullDurationSec) {
  4416.  
  4417. // console.log(948700, obj , obj.id, (obj.fullDurationSec - obj.durationSec) * 1000)
  4418. const m = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  4419. // obj.__orderTime__ = m;
  4420. mapper.set(aItem, m);
  4421.  
  4422.  
  4423. }
  4424.  
  4425. }
  4426.  
  4427. if (mapper.size > 1) {
  4428.  
  4429. const idxices = [];
  4430.  
  4431. // sort ticker
  4432. let mArr1 = arr.filter((aItem,idx) => {
  4433.  
  4434. if (mapper.has(aItem)) {
  4435. idxices.push(idx);
  4436. return true;
  4437. }
  4438. return false;
  4439.  
  4440. });
  4441.  
  4442.  
  4443. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  4444. return mapper.get(a) - mapper.get(b);
  4445. // low index = oldest = smallest timestamp
  4446. });
  4447.  
  4448.  
  4449.  
  4450. // console.log(948701, arr.slice(0));
  4451. for(let j = 0, l=mArr1.length;j <l;j++){
  4452.  
  4453. const idx = idxices[j];
  4454. // arr[idx] = mArr1[j]
  4455. arr[idx] = mArr2[j];
  4456.  
  4457. // const obj1 = toObj(mArr1[j]);
  4458. // const obj2 = toObj(mArr2[j]);
  4459.  
  4460. // console.log(948705, idx, obj1 , obj1.id, (obj1.fullDurationSec - obj1.durationSec) * 1000, obj1.__orderTime__)
  4461.  
  4462. // console.log(948706, idx, obj2 , obj2.id, (obj2.fullDurationSec - obj2.durationSec) * 1000, obj2.__orderTime__)
  4463.  
  4464. }
  4465.  
  4466. // console.log(948702, arr.slice(0));
  4467. // console.log(948701, arr);
  4468. // arr = arr.map(aItem => {
  4469. // const idx = mArr1.indexOf(aItem);
  4470. // if (idx < 0) return aItem;
  4471. // return mArr2[idx];
  4472. // });
  4473. // console.log(948702, arr);
  4474.  
  4475. // mostly in order, but some not in order
  4476.  
  4477.  
  4478. // eg
  4479.  
  4480. /*
  4481.  
  4482.  
  4483. 948711 68 '1734488590715474'
  4484. 948711 69 '1734488590909853'
  4485. 948711 70 '1734488594763719'
  4486. 948711 71 '1734488602334615' <
  4487. 948711 72 '1734488602267214' <
  4488. 948711 73 '1734488602751771'
  4489. */
  4490.  
  4491. // arr.filter(aItem=>{
  4492.  
  4493. // const p = toObj(aItem);
  4494. // if(p.timestampUsec) return true;
  4495.  
  4496. // }).forEach((aItem,idx)=>{
  4497.  
  4498. // const p = toObj(aItem);
  4499. // console.log(948711, idx, p.timestampUsec);
  4500. // })
  4501.  
  4502. // return arr;
  4503.  
  4504. }
  4505.  
  4506.  
  4507. {
  4508.  
  4509.  
  4510. const mapper = new Map();
  4511.  
  4512.  
  4513. const idxices = [];
  4514.  
  4515. let mArr1 = arr.filter((aItem,idx) => {
  4516.  
  4517. const timestampUsec = +toLAObj(aItem).timestampUsec; // +false.x = NaN
  4518. if(timestampUsec > 0){
  4519. idxices.push(idx);
  4520. mapper.set(aItem, timestampUsec)
  4521. return true;
  4522. }
  4523. return false;
  4524. });
  4525.  
  4526. if(mapper.size > 1){
  4527.  
  4528.  
  4529. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  4530. return mapper.get(a) - mapper.get(b);
  4531. // low index = oldest = smallest timestamp
  4532. });
  4533. // console.log(948701, arr.slice(0));
  4534. for(let j = 0, l=mArr1.length;j <l;j++){
  4535. const idx = idxices[j];
  4536. arr[idx] = mArr2[j];
  4537. // const obj1 = toObj(mArr1[j]);
  4538. // const obj2 = toObj(mArr2[j]);
  4539. // console.log(948711, idx, obj1 === obj2, obj1, obj1.timestampUsec);
  4540. // console.log(948712, idx, obj1 === obj2, obj2, obj2.timestampUsec);
  4541. }
  4542.  
  4543. }
  4544.  
  4545. }
  4546.  
  4547.  
  4548. return arr;
  4549.  
  4550.  
  4551. }
  4552.  
  4553. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  4554. getLCRDummy().then(async (lcrDummy) => {
  4555.  
  4556. const tag = "yt-live-chat-renderer"
  4557. const dummy = lcrDummy;
  4558.  
  4559. const cProto = getProto(dummy);
  4560. if (!cProto || !cProto.attached) {
  4561. console.warn(`proto.attached for ${tag} is unavailable.`);
  4562. return;
  4563. }
  4564.  
  4565. mightFirstCheckOnYtInit();
  4566. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  4567. console.log("[Begin]");
  4568.  
  4569.  
  4570.  
  4571.  
  4572.  
  4573.  
  4574. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  4575.  
  4576. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  4577.  
  4578. const pop078 = function () {
  4579. const r = this.pop78();
  4580.  
  4581. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  4582. for (const action of r.actions) {
  4583.  
  4584. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  4585. if (itemActionKey) {
  4586.  
  4587. const itemAction = action[itemActionKey];
  4588. const item = (itemAction || 0).item;
  4589. if (typeof item === 'object') {
  4590.  
  4591. const rendererKey = firstObjectKey(item);
  4592. if (rendererKey) {
  4593. const renderer = item[rendererKey];
  4594. if (renderer && typeof renderer === 'object') {
  4595. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  4596. renderer.__progressAt__ = playerProgressChangedArg1;
  4597.  
  4598. // console.log(48117006)
  4599. }
  4600.  
  4601. }
  4602.  
  4603. }
  4604. }
  4605. }
  4606. }
  4607. return r;
  4608. }
  4609.  
  4610. const replayQueueProxyHandler = {
  4611. get(target, prop, receiver) {
  4612. if (prop === 'qe3') return 1;
  4613. const v = target[prop];
  4614. if (prop === 'front_') {
  4615. if (v && typeof v.length === 'number') {
  4616. if (!v.pop78) {
  4617. v.pop78 = v.pop;
  4618. v.pop = pop078;
  4619. }
  4620. }
  4621. }
  4622. return v;
  4623. }
  4624. };
  4625.  
  4626. cProto.playerProgressChanged_ = function (a, b, c) {
  4627. // console.log(48117005)
  4628. playerProgressChangedArg1 = a;
  4629. playerProgressChangedArg2 = b;
  4630. playerProgressChangedArg3 = c;
  4631. const replayBuffer_ = this.replayBuffer_;
  4632. if (replayBuffer_) {
  4633. const replayQueue = replayBuffer_.replayQueue
  4634. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  4635. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, replayQueueProxyHandler);
  4636. }
  4637. }
  4638. Promise.resolve().then(updateTickerCurrentTime);
  4639. return this.playerProgressChanged32_.apply(this, arguments);
  4640. };
  4641.  
  4642. }
  4643.  
  4644. console.log("[End]");
  4645. console.groupEnd();
  4646.  
  4647.  
  4648. });
  4649.  
  4650. }
  4651.  
  4652.  
  4653.  
  4654. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  4655.  
  4656.  
  4657. const tag = "yt-live-chat-item-list-renderer"
  4658. const dummy = document.createElement(tag);
  4659.  
  4660. const cProto = getProto(dummy);
  4661. if (!cProto || !cProto.attached) {
  4662. console.warn(`proto.attached for ${tag} is unavailable.`);
  4663. return;
  4664. }
  4665.  
  4666. mightFirstCheckOnYtInit();
  4667. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  4668. console.log("[Begin]");
  4669.  
  4670. const mclp = cProto;
  4671. const _flag0281_ = window._flag0281_ || mclp._flag0281_;
  4672.  
  4673. try {
  4674. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  4675. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  4676. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  4677. assertor(() => typeof mclp.setAtBottom === 'function');
  4678. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  4679. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  4680. } catch (e) { }
  4681.  
  4682.  
  4683. try {
  4684. assertor(() => typeof mclp.attached === 'function');
  4685. assertor(() => typeof mclp.detached === 'function');
  4686. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  4687. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  4688. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  4689. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  4690. assertor(() => typeof mclp.smoothScroll_ === 'function');
  4691. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  4692. } catch (e) { }
  4693.  
  4694. mclp.__intermediate_delay__ = null;
  4695.  
  4696. let myk = 0;
  4697. let mlf = 0;
  4698. let myw = 0;
  4699. let mzt = 0;
  4700. let zarr = null;
  4701. let mlg = 0;
  4702.  
  4703. if ((_flag0281_ & 0x2000) == 0) {
  4704.  
  4705. if ((mclp.clearList || 0).length === 0) {
  4706. (_flag0281_ & 0x2) == 0 && assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  4707. mclp.clearList66 = mclp.clearList;
  4708. mclp.clearList = function () {
  4709. myk++;
  4710. mlf++;
  4711. myw++;
  4712. mzt++;
  4713. mlg++;
  4714. zarr = null;
  4715. this.__intermediate_delay__ = null;
  4716. this.clearList66();
  4717. };
  4718. console.log("clearList", "OK");
  4719. } else {
  4720. console.log("clearList", "NG");
  4721. }
  4722.  
  4723. }
  4724.  
  4725.  
  4726.  
  4727. let onListRendererAttachedDone = false;
  4728.  
  4729. function setList(itemOffset, items) {
  4730.  
  4731. const isFirstTime = onListRendererAttachedDone === false;
  4732.  
  4733. if (isFirstTime) {
  4734. onListRendererAttachedDone = true;
  4735. Promise.resolve().then(watchUserCSS);
  4736. addCssManaged();
  4737. setupEvents();
  4738. }
  4739.  
  4740. setupStyle(itemOffset, items);
  4741.  
  4742. setupMutObserver(items);
  4743. }
  4744.  
  4745. mclp.attached419 = async function () {
  4746.  
  4747. if (!this.isAttached) return;
  4748.  
  4749. let maxTrial = 16;
  4750. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  4751. if (--maxTrial < 0 || !this.isAttached) return;
  4752. await iAFP(this.hostElement).then();
  4753. // await new Promise(requestAnimationFrame);
  4754. }
  4755.  
  4756. if (this.isAttached !== true) return;
  4757.  
  4758. if (!this.$) {
  4759. console.warn("!this.$");
  4760. return;
  4761. }
  4762. if (!this.$) return;
  4763. /** @type {HTMLElement | null} */
  4764. const itemScroller = this.$['item-scroller'];
  4765. /** @type {HTMLElement | null} */
  4766. const itemOffset = this.$['item-offset'];
  4767. /** @type {HTMLElement | null} */
  4768. const items = this.$['items'];
  4769.  
  4770. if (!itemScroller || !itemOffset || !items) {
  4771. console.warn("items.parentNode !== itemOffset");
  4772. return;
  4773. }
  4774.  
  4775. if (nodeParent(items) !== itemOffset) {
  4776.  
  4777. console.warn("items.parentNode !== itemOffset");
  4778. return;
  4779. }
  4780.  
  4781.  
  4782. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  4783.  
  4784. console.warn("id incorrect");
  4785. return;
  4786. }
  4787.  
  4788. 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')
  4789.  
  4790. if (!isTargetItems) {
  4791. console.warn("!isTargetItems");
  4792. return;
  4793. }
  4794.  
  4795. setList(itemOffset, items);
  4796.  
  4797. }
  4798.  
  4799. mclp.attached331 = mclp.attached;
  4800. mclp.attached = function () {
  4801. this.attached419 && this.attached419();
  4802. return this.attached331();
  4803. }
  4804.  
  4805. mclp.detached331 = mclp.detached;
  4806.  
  4807. mclp.detached = function () {
  4808. setupMutObserver();
  4809. return this.detached331();
  4810. }
  4811.  
  4812. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  4813. for (const t29 of t29s) {
  4814. if (insp(t29).isAttached === true) {
  4815. t29.attached419();
  4816. }
  4817. }
  4818.  
  4819. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  4820.  
  4821. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  4822. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  4823.  
  4824. /** @type {Map<number, any>} */
  4825. const aMap = new Map();
  4826. let count = 6150;
  4827. mclp.async66 = mclp.async;
  4828. mclp.async = function (e, f) {
  4829. // ensure the previous operation is done
  4830. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  4831. const hasF = arguments.length === 2;
  4832. const stack = new Error().stack;
  4833. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  4834. if (count > 1e9) count = 6159;
  4835. const resId = ++count;
  4836. aMap.set(resId, e);
  4837. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  4838. const rp = aMap.get(resId);
  4839. if (typeof rp !== 'function') {
  4840. return;
  4841. }
  4842. let cancelCall = false;
  4843. if (isFlushAsync) {
  4844. if (rk < 0) {
  4845. cancelCall = true;
  4846. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  4847. cancelCall = true;
  4848. }
  4849. }
  4850. if (cancelCall) {
  4851. aMap.delete(resId);
  4852. } else {
  4853. const asyncEn = function () {
  4854. aMap.delete(resId);
  4855. return rp.apply(this, arguments);
  4856. };
  4857. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  4858. }
  4859. });
  4860.  
  4861. return resId;
  4862. }
  4863.  
  4864. mclp.cancelAsync66 = mclp.cancelAsync;
  4865. mclp.cancelAsync = function (resId) {
  4866. if (resId <= 6150) {
  4867. this.cancelAsync66(resId);
  4868. } else if (aMap.has(resId)) {
  4869. const rp = aMap.get(resId);
  4870. aMap.delete(resId);
  4871. if (typeof rp !== 'function') {
  4872. this.cancelAsync66(rp);
  4873. }
  4874. }
  4875. }
  4876.  
  4877. console.log("async", "OK");
  4878. } else {
  4879. console.log("async", "NG");
  4880. }
  4881.  
  4882.  
  4883. if ((_flag0281_ & 0x2) == 0) {
  4884. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  4885.  
  4886. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  4887. mclp.showNewItems66_ = mclp.showNewItems_;
  4888.  
  4889. mclp.showNewItems77_ = async function () {
  4890. if (myk > 1e9) myk = 9;
  4891. let tid = ++myk;
  4892.  
  4893. await iAFP(this.hostElement).then();
  4894. // await new Promise(requestAnimationFrame);
  4895.  
  4896. if (tid !== myk) {
  4897. return;
  4898. }
  4899.  
  4900. const cnt = this;
  4901.  
  4902. await Promise.resolve();
  4903. cnt.showNewItems66_();
  4904.  
  4905. await Promise.resolve();
  4906.  
  4907. }
  4908.  
  4909. mclp.showNewItems_ = function () {
  4910.  
  4911. const cnt = this;
  4912. cnt.__intermediate_delay__ = new Promise(resolve => {
  4913. cnt.showNewItems77_().then(() => {
  4914. resolve();
  4915. });
  4916. });
  4917. }
  4918.  
  4919. console.log("showNewItems_", "OK");
  4920. } else {
  4921. console.log("showNewItems_", "NG");
  4922. }
  4923.  
  4924. }
  4925.  
  4926. if ((_flag0281_ & 0x2000) == 0) {
  4927. if ((mclp.flushActiveItems_ || 0).length === 0) {
  4928.  
  4929. if ((_flag0281_ & 0x2) == 0) {
  4930.  
  4931. const sfi = fnIntegrity(mclp.flushActiveItems_);
  4932. if (sfi === '0.156.86') {
  4933. // https://www.youtube.com/s/desktop/f61c8d85/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4934.  
  4935. // added "refreshOffsetContainerHeight_"
  4936.  
  4937. // f.flushActiveItems_ = function() {
  4938. // var a = this;
  4939. // if (0 < this.activeItems_.length)
  4940. // if (this.canScrollToBottom_()) {
  4941. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  4942. // b && this.splice("visibleItems", 0, b);
  4943. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  4944. // this.preinsertHeight_ = this.items.clientHeight;
  4945. // this.activeItems_.unshift("visibleItems");
  4946. // try {
  4947. // this.push.apply(this, this.activeItems_)
  4948. // } catch (c) {
  4949. // fm(c)
  4950. // }
  4951. // this.activeItems_ = [];
  4952. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && Mw(function() {
  4953. // a.showNewItems_()
  4954. // }) : Mw(function() {
  4955. // a.refreshOffsetContainerHeight_();
  4956. // a.maybeScrollToBottom_()
  4957. // })
  4958. // } else
  4959. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  4960. // }
  4961. // ;
  4962.  
  4963. } else if (sfi === '0.150.84') {
  4964. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4965. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  4966. // b && this.splice("visibleItems", 0, b);
  4967. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  4968. // this.preinsertHeight_ = this.items.clientHeight;
  4969. // this.activeItems_.unshift("visibleItems");
  4970. // try {
  4971. // this.push.apply(this, this.activeItems_)
  4972. // } catch (c) {
  4973. // nm(c)
  4974. // }
  4975. // this.activeItems_ = [];
  4976. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && zQ(function() {
  4977. // a.showNewItems_()
  4978. // }) : zQ(function() {
  4979. // a.maybeScrollToBottom_()
  4980. // })
  4981. } else if (sfi === '0.137.81' || sfi === '0.138.81') {
  4982. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  4983. } else {
  4984. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.150.84'));
  4985. }
  4986. }
  4987.  
  4988. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  4989.  
  4990. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  4991.  
  4992.  
  4993. const preloadFn = (acItems) => {
  4994. let waitFor = [];
  4995. /** @type {Set<string>} */
  4996. const imageLinks = new Set();
  4997.  
  4998. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  4999. for (const item of acItems) {
  5000. fixLiveChatItem(item, imageLinks);
  5001. }
  5002. }
  5003. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  5004.  
  5005. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  5006. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  5007. // preload performs the high priority fetching.
  5008. // prefetch delays the chat display if the video resoruce is demanding.
  5009.  
  5010. if (rel) {
  5011.  
  5012. imageLinks.forEach(imageLink => {
  5013. let d = false;
  5014. if (SKIP_PRELOAD_EMOJI && imageLink.includes('.ggpht.com/')) return;
  5015. const isEmoji = imageLink.includes('/emoji/');
  5016. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  5017. if (!pretechedSet.has(imageLink)) {
  5018. pretechedSet.add(imageLink);
  5019. d = true;
  5020. }
  5021. if (d) {
  5022. waitFor.push(linker(null, rel, imageLink, 'image'));
  5023.  
  5024. }
  5025. })
  5026.  
  5027. }
  5028.  
  5029. }
  5030.  
  5031. return async () => {
  5032. if (waitFor.length > 0) {
  5033. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  5034. }
  5035. waitFor.length = 0;
  5036. waitFor = null;
  5037. };
  5038.  
  5039. };
  5040.  
  5041. mclp.flushActiveItems78_ = async function (tid) {
  5042. try {
  5043.  
  5044. if (tid !== mlf) return;
  5045. if ((this._flag0281_ & 0x4) == 0x4) {
  5046. const cnt = this;
  5047.  
  5048. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5049. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  5050.  
  5051. mlf++;
  5052. if (mlg > 1e9) mlg = 9;
  5053. ++mlg;
  5054. const acItems = cnt.activeItems_;
  5055. if (acItems.length < MAX_ITEMS_FOR_FULL_FLUSH) {
  5056. const pn = preloadFn(acItems);
  5057. await pn();
  5058. }
  5059. cnt.flushActiveItems66_();
  5060.  
  5061. return 1;
  5062.  
  5063. }
  5064. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  5065. let logger = false;
  5066. const cnt = this;
  5067. let immd = cnt.__intermediate_delay__;
  5068. await iAFP(this.hostElement).then();
  5069. // await new Promise(requestAnimationFrame);
  5070.  
  5071. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5072. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  5073.  
  5074. mlf++;
  5075. if (mlg > 1e9) mlg = 9;
  5076. ++mlg;
  5077.  
  5078. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  5079. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  5080. let changeMaxItemsToDisplay = false;
  5081. const activeItemsLen = this.activeItems_.length;
  5082. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  5083. logger = true;
  5084.  
  5085. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  5086.  
  5087. logger && console.log('[Begin]')
  5088.  
  5089. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  5090. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  5091. console.log('reduce maxitems');
  5092. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  5093. // as all the rendered chats are already "outdated"
  5094. // all old chats shall remove and reduced number of few chats will be rendered
  5095. // then restore to the original number
  5096. changeMaxItemsToDisplay = true;
  5097. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  5098. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  5099. }
  5100. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  5101. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  5102.  
  5103. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  5104. } else {
  5105. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  5106.  
  5107. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  5108. }
  5109. }
  5110. // it is found that it will render all stacked chats after switching back from background
  5111. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  5112. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  5113.  
  5114. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  5115. await Promise.resolve();
  5116. const acItems = cnt.activeItems_;
  5117. const len1 = acItems.length;
  5118. if (!len1) console.warn('cnt.activeItems_.length = 0');
  5119.  
  5120. const pn = preloadFn(acItems);
  5121. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  5122. skipDontRender = noVisibleItem1;
  5123. await pn();
  5124. // console.log('ss2', Date.now())
  5125. cnt.flushActiveItems66_();
  5126. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  5127. skipDontRender = noVisibleItem2;
  5128. await Promise.resolve();
  5129. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  5130. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  5131.  
  5132. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  5133. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  5134. } else if (changeMaxItemsToDisplay) {
  5135.  
  5136. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  5137. maxItemsToDisplay: this.data.maxItemsToDisplay,
  5138. reducedMaxItemsToDisplay,
  5139. originalMaxItemsToDisplay: tmpMaxItemsCount
  5140. });
  5141. }
  5142. logger && console.log('[End]');
  5143.  
  5144. logger && console.groupEnd();
  5145.  
  5146. if (noVisibleItem1 && !noVisibleItem2) {
  5147. // fix possible no auto scroll issue.
  5148. !((cnt.__notRequired__ || 0) & 256) && setTimeout(() => cnt.setAtBottom(), 1);
  5149. }
  5150.  
  5151. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  5152.  
  5153.  
  5154. const ff = () => {
  5155.  
  5156. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5157. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5158. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  5159.  
  5160. if (typeof nextBrowserTick !== 'function') {
  5161. cnt.scrollToBottom_();
  5162. Promise.resolve().then(() => {
  5163. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5164. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  5165. });
  5166. } else {
  5167. nextBrowserTick(() => {
  5168. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  5169. cnt.scrollToBottom_();
  5170. });
  5171. }
  5172.  
  5173. }
  5174. }
  5175.  
  5176. ff();
  5177.  
  5178.  
  5179. Promise.resolve().then(ff);
  5180.  
  5181. // requestAnimationFrame(ff);
  5182. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  5183.  
  5184. const knt = cnt;
  5185. if (!scrollChatFn) {
  5186. const cnt = knt;
  5187. const f = () => {
  5188. const itemScroller = cnt.itemScroller;
  5189. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  5190. if (!cnt.atBottom) {
  5191. cnt.scrollToBottom_();
  5192. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  5193. itemScroller.scrollTop = itemScroller.scrollHeight;
  5194. }
  5195. };
  5196. if (typeof nextBrowserTick !== 'function') {
  5197. scrollChatFn = () => Promise.resolve().then(f).then(f);
  5198. } else {
  5199. scrollChatFn = () => nextBrowserTick(f);
  5200. }
  5201. }
  5202.  
  5203. scrollChatFn();
  5204. }
  5205.  
  5206. return 1;
  5207.  
  5208.  
  5209. } catch (e) {
  5210. console.warn(e);
  5211. }
  5212. }
  5213.  
  5214. mclp.flushActiveItems77_ = function () {
  5215.  
  5216. return new Promise(resResolve => {
  5217. try {
  5218. const cnt = this;
  5219. if (mlf > 1e9) mlf = 9;
  5220. let tid = ++mlf;
  5221. const hostElement = cnt.hostElement || cnt;
  5222. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  5223. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  5224.  
  5225. // 4 times to maxItems to avoid frequent trimming.
  5226. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  5227.  
  5228. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  5229. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  5230. if (cnt.canScrollToBottom_()) {
  5231. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  5232. .then(() => cnt.flushActiveItems78_(tid)) // async function
  5233. .then((asyncResult) => {
  5234. resResolve(asyncResult); // either undefined or 1
  5235. resResolve = null;
  5236. }).catch((e) => {
  5237. console.warn(e);
  5238. if (resResolve) resResolve();
  5239. });
  5240. } else {
  5241. resResolve(2);
  5242. resResolve = null;
  5243. }
  5244. } catch (e) {
  5245. console.warn(e);
  5246. if (resResolve) resResolve();
  5247. }
  5248.  
  5249.  
  5250. });
  5251.  
  5252. }
  5253.  
  5254. mclp.flushActiveItems_ = function () {
  5255. const cnt = this;
  5256.  
  5257. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  5258.  
  5259. if (cnt.activeItems_.length === 0) {
  5260. cnt.__intermediate_delay__ = null;
  5261. return;
  5262. }
  5263.  
  5264. const cntData = ((cnt || 0).data || 0);
  5265. if (cntData.maxItemsToDisplay944 === undefined) {
  5266. cntData.maxItemsToDisplay944 = null;
  5267. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  5268. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  5269. }
  5270.  
  5271. // ignore previous __intermediate_delay__ and create a new one
  5272. cnt.__intermediate_delay__ = new Promise(resolve => {
  5273. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  5274. if (rt === 1) {
  5275. resolve(1); // success, scroll to bottom
  5276. if (hasMoreMessageState === 1) {
  5277. hasMoreMessageState = 0;
  5278. const showMore = (cnt.$ || 0)['show-more'];
  5279. if (showMore) {
  5280. showMore.classList.remove('has-new-messages-miuzp');
  5281. }
  5282. }
  5283. }
  5284. else if (rt === 2) {
  5285. resolve(2); // success, trim
  5286. if (hasMoreMessageState === 0) {
  5287. hasMoreMessageState = 1;
  5288. const showMore = cnt.$['show-more'];
  5289. if (showMore) {
  5290. showMore.classList.add('has-new-messages-miuzp');
  5291. }
  5292. }
  5293. }
  5294. else resolve(-1); // skip
  5295. }).catch(e => {
  5296. console.warn(e);
  5297. });
  5298. });
  5299.  
  5300. }
  5301. console.log("flushActiveItems_", "OK");
  5302. } else {
  5303. console.log("flushActiveItems_", "NG");
  5304. }
  5305. }
  5306.  
  5307. if ((_flag0281_ & 0x40) == 0) {
  5308.  
  5309. if (ENABLE_NO_SMOOTH_TRANSFORM && SUPPRESS_refreshOffsetContainerHeight_ && typeof mclp.refreshOffsetContainerHeight_ === 'function' && !mclp.refreshOffsetContainerHeight26_ && mclp.refreshOffsetContainerHeight_.length === 0) {
  5310. assertor(() => fnIntegrity(mclp.refreshOffsetContainerHeight_, '0.31.21'));
  5311. mclp.refreshOffsetContainerHeight26_ = mclp.refreshOffsetContainerHeight_;
  5312. mclp.refreshOffsetContainerHeight_ = function () {
  5313. // var a = this.itemScroller.clientHeight;
  5314. // this.itemOffset.style.height = this.items.clientHeight + "px";
  5315. // this.bottomAlignMessages && (this.itemOffset.style.minHeight = a + "px")
  5316. }
  5317. console.log("refreshOffsetContainerHeight_", "OK");
  5318. } else {
  5319. console.log("refreshOffsetContainerHeight_", "NG");
  5320. }
  5321.  
  5322. }
  5323.  
  5324. if ((_flag0281_ & 0x80) == 0) {
  5325. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  5326. try {
  5327. if (mlg > 1e9) mlg = 9;
  5328. const tid = ++mlg;
  5329. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  5330. const runCond = () => this.canScrollToBottom_();
  5331. if (!keepTrialCond()) return;
  5332. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  5333. await new Promise(r => setTimeout(r, 80));
  5334. if (!keepTrialCond()) return;
  5335. if (runCond()) return this.flushActiveItems_() | 1;
  5336. await iAFP(this.hostElement).then();
  5337. // await new Promise(requestAnimationFrame);
  5338. if (runCond()) return this.flushActiveItems_() | 1;
  5339. } catch (e) {
  5340. console.warn(e);
  5341. }
  5342. }
  5343. }
  5344.  
  5345. if ((_flag0281_ & 0x40) == 0 ) {
  5346.  
  5347. if( (mclp.atBottomChanged_ || 0).length === 0) {
  5348. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  5349.  
  5350.  
  5351.  
  5352.  
  5353.  
  5354. const sfi = fnIntegrity(mclp.atBottomChanged_);
  5355.  
  5356. if(sfi === '0.75.37'){
  5357. // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  5358.  
  5359.  
  5360. // Dec 2024.
  5361.  
  5362. /**
  5363. *
  5364. *
  5365. f.atBottomChanged_ = function() {
  5366. var a = this;
  5367. this.atBottom ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = Zu(function() {
  5368. R(a.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5369. }, 200)) : (this.hideShowMoreAsync_ && $u(this.hideShowMoreAsync_),
  5370. this.hideShowMoreAsync_ = null,
  5371. R(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5372. }
  5373. *
  5374. */
  5375.  
  5376. } else {
  5377. assertor(() => fnIntegrity(mclp.atBottomChanged_, '0.75.37'));
  5378. }
  5379.  
  5380.  
  5381. const querySelector = HTMLElement.prototype.querySelector;
  5382. const U = (element) => ({
  5383. querySelector: (selector) => querySelector.call(element, selector)
  5384. });
  5385.  
  5386. let qid = 0;
  5387. mclp.__updateButtonVisibility371__ = function (button) {
  5388. Promise.resolve(this).then((cnt) => {
  5389. button.style.visibility = cnt.__buttonVisibility371__;
  5390. });
  5391. }
  5392. const fixButtonOnClick = function (cnt, button) {
  5393. button.addEventListener('click', (evt) => {
  5394. evt.stopImmediatePropagation();
  5395. evt.stopPropagation();
  5396. evt.preventDefault();
  5397. Promise.resolve(cnt).then((cnt) => {
  5398. cnt.scrollToBottom_();
  5399. });
  5400. }, true);
  5401. // button.addEventListener('pointerup', (evt)=>{
  5402. // evt.stopImmediatePropagation();
  5403. // evt.stopPropagation();
  5404. // }, true);
  5405. // button.addEventListener('mouseup', (evt)=>{
  5406. // evt.stopImmediatePropagation();
  5407. // evt.stopPropagation();
  5408. // }, true);
  5409. }
  5410. mclp.atBottomChanged_ = function () {
  5411. let a = this.atBottom;
  5412. const button = (this.$ || 0)['show-more'];
  5413. if (button) {
  5414. // primary execution
  5415. if (a) {
  5416. if (this.__buttonVisibility371__ !== "hidden") {
  5417. this.__buttonVisibility371__ = "hidden";
  5418. if (!this.hideShowMoreAsync_) {
  5419. const tid = ++qid;
  5420. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  5421. if (tid !== qid) {
  5422. return;
  5423. }
  5424. this.__updateButtonVisibility371__(button);
  5425. });
  5426. }
  5427. }
  5428. } else {
  5429. if (this.__buttonVisibility371__ !== "visible") {
  5430. this.__buttonVisibility371__ = "visible";
  5431. if (this.hideShowMoreAsync_) {
  5432. qid++;
  5433. }
  5434. this.hideShowMoreAsync_ = null;
  5435. if (!button.__fix_onclick__) {
  5436. button.__fix_onclick__ = true;
  5437. fixButtonOnClick(this, button);
  5438. }
  5439. this.__updateButtonVisibility371__(button);
  5440. }
  5441. }
  5442. } else {
  5443. // fallback
  5444. let tid = ++qid;
  5445. let b = this;
  5446. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  5447. if (tid !== qid) return;
  5448. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5449. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  5450. this.hideShowMoreAsync_ = null,
  5451. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5452. }
  5453. }
  5454.  
  5455. console.log("atBottomChanged_", "OK");
  5456.  
  5457. } else if ((mclp.atBottomChanged_ || 0).length === 1) {
  5458. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  5459.  
  5460. const sfi = fnIntegrity(mclp.atBottomChanged_);
  5461. if (sfi === '1.73.37') {
  5462. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  5463.  
  5464. /**
  5465. *
  5466. *
  5467. *
  5468. f.atBottomChanged_ = function(a) {
  5469. var b = this;
  5470. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = zQ(function() {
  5471. T(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5472. }, 200)) : (this.hideShowMoreAsync_ && AQ(this.hideShowMoreAsync_),
  5473. this.hideShowMoreAsync_ = null,
  5474. T(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5475. };
  5476.  
  5477. *
  5478. *
  5479. */
  5480.  
  5481.  
  5482. } else if (sfi === '1.75.39') {
  5483. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  5484. } else {
  5485. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.73.37'));
  5486. }
  5487.  
  5488. const querySelector = HTMLElement.prototype.querySelector;
  5489. const U = (element) => ({
  5490. querySelector: (selector) => querySelector.call(element, selector)
  5491. });
  5492.  
  5493. let qid = 0;
  5494. mclp.__updateButtonVisibility371__ = function (button) {
  5495. Promise.resolve(this).then((cnt) => {
  5496. button.style.visibility = cnt.__buttonVisibility371__;
  5497. });
  5498. }
  5499. const fixButtonOnClick = function (cnt, button) {
  5500. button.addEventListener('click', (evt) => {
  5501. evt.stopImmediatePropagation();
  5502. evt.stopPropagation();
  5503. evt.preventDefault();
  5504. Promise.resolve(cnt).then((cnt) => {
  5505. cnt.scrollToBottom_();
  5506. });
  5507. }, true);
  5508. // button.addEventListener('pointerup', (evt)=>{
  5509. // evt.stopImmediatePropagation();
  5510. // evt.stopPropagation();
  5511. // }, true);
  5512. // button.addEventListener('mouseup', (evt)=>{
  5513. // evt.stopImmediatePropagation();
  5514. // evt.stopPropagation();
  5515. // }, true);
  5516. }
  5517. mclp.atBottomChanged_ = function (a) {
  5518. const button = (this.$ || 0)['show-more'];
  5519. if (button) {
  5520. // primary execution
  5521. if (a) {
  5522. if (this.__buttonVisibility371__ !== "hidden") {
  5523. this.__buttonVisibility371__ = "hidden";
  5524. if (!this.hideShowMoreAsync_) {
  5525. const tid = ++qid;
  5526. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  5527. if (tid !== qid) {
  5528. return;
  5529. }
  5530. this.__updateButtonVisibility371__(button);
  5531. });
  5532. }
  5533. }
  5534. } else {
  5535. if (this.__buttonVisibility371__ !== "visible") {
  5536. this.__buttonVisibility371__ = "visible";
  5537. if (this.hideShowMoreAsync_) {
  5538. qid++;
  5539. }
  5540. this.hideShowMoreAsync_ = null;
  5541. if (!button.__fix_onclick__) {
  5542. button.__fix_onclick__ = true;
  5543. fixButtonOnClick(this, button);
  5544. }
  5545. this.__updateButtonVisibility371__(button);
  5546. }
  5547. }
  5548. } else {
  5549. // fallback
  5550. let tid = ++qid;
  5551. let b = this;
  5552. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  5553. if (tid !== qid) return;
  5554. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  5555. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  5556. this.hideShowMoreAsync_ = null,
  5557. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  5558. }
  5559. }
  5560.  
  5561. console.log("atBottomChanged_", "OK");
  5562. } else {
  5563. console.log("atBottomChanged_", "NG");
  5564. }
  5565. }
  5566.  
  5567.  
  5568. if ((_flag0281_ & 0x2) == 0) {
  5569. if ((mclp.onScrollItems_ || 0).length === 1) {
  5570.  
  5571. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  5572. mclp.onScrollItems66_ = mclp.onScrollItems_;
  5573. mclp.onScrollItems77_ = async function (evt) {
  5574. if (myw > 1e9) myw = 9;
  5575. let tid = ++myw;
  5576.  
  5577. await iAFP(this.hostElement).then();
  5578. // await new Promise(requestAnimationFrame);
  5579.  
  5580. if (tid !== myw) {
  5581. return;
  5582. }
  5583.  
  5584. const cnt = this;
  5585.  
  5586. await Promise.resolve();
  5587. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  5588. const onScrollItemsBasicOnly_ = !!((cnt.__notRequired__ || 0) & 512);
  5589. await Promise.resolve().then(() => {
  5590. this.ytRendererBehavior.onScroll(evt);
  5591. }).then(() => {
  5592. if (onScrollItemsBasicOnly_) return;
  5593. if (this.canScrollToBottom_()) {
  5594. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  5595. if (hasUserJustInteracted) {
  5596. // only when there is an user action
  5597. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  5598. return 1;
  5599. }
  5600. } else {
  5601. // no message inserting
  5602. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  5603. return 1;
  5604. }
  5605. }).then((r) => {
  5606.  
  5607. if (onScrollItemsBasicOnly_) return;
  5608. if (this.activeItems_.length) {
  5609.  
  5610. if (this.canScrollToBottom_()) {
  5611. this.flushActiveItems_();
  5612. return 1 && r;
  5613. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  5614. // delayed due to user action
  5615. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  5616. return 0;
  5617. }
  5618. }
  5619. }).then((r) => {
  5620. if (onScrollItemsBasicOnly_) return;
  5621. if (r) {
  5622. // ensure setAtBottom is correctly set
  5623. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  5624. }
  5625. });
  5626. } else {
  5627. cnt.onScrollItems66_(evt);
  5628. }
  5629.  
  5630. await Promise.resolve();
  5631.  
  5632. }
  5633.  
  5634. mclp.onScrollItems_ = function (evt) {
  5635.  
  5636. const cnt = this;
  5637. cnt.__intermediate_delay__ = new Promise(resolve => {
  5638. cnt.onScrollItems77_(evt).then(() => {
  5639. resolve();
  5640. });
  5641. });
  5642. }
  5643. console.log("onScrollItems_", "OK");
  5644. } else {
  5645. console.log("onScrollItems_", "NG");
  5646. }
  5647. }
  5648.  
  5649. if ((_flag0281_ & 0x2) == 0) {
  5650. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  5651.  
  5652. const sfi = fnIntegrity(mclp.handleLiveChatActions_);
  5653. if (sfi === '1.39.20') {
  5654. // TBC
  5655. } else if (sfi === '1.31.17') {
  5656. // original
  5657. } else {
  5658. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.31.17'));
  5659. }
  5660.  
  5661. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  5662.  
  5663. mclp.handleLiveChatActions77_ = async function (arr) {
  5664. if (typeof (arr || 0).length !== 'number') {
  5665. this.handleLiveChatActions66_(arr);
  5666. return;
  5667. }
  5668. if (mzt > 1e9) mzt = 9;
  5669. let tid = ++mzt;
  5670.  
  5671. if (zarr === null) zarr = arr;
  5672. else Array.prototype.push.apply(zarr, arr);
  5673. arr = null;
  5674.  
  5675. await iAFP(this.hostElement).then();
  5676. // await new Promise(requestAnimationFrame);
  5677.  
  5678. if (tid !== mzt || zarr === null) {
  5679. return;
  5680. }
  5681.  
  5682. const carr = zarr;
  5683. zarr = null;
  5684.  
  5685. await Promise.resolve();
  5686. this.handleLiveChatActions66_(carr);
  5687. await Promise.resolve();
  5688.  
  5689. }
  5690.  
  5691. mclp.handleLiveChatActions_ = function (arr) {
  5692.  
  5693.  
  5694. preprocessChatLiveActions(arr);
  5695.  
  5696.  
  5697.  
  5698. // console.log(1929, cnt.activeItems_)
  5699. // console.log(9487, arr);
  5700.  
  5701. const cnt = this;
  5702. cnt.__intermediate_delay__ = new Promise(resolve => {
  5703. cnt.handleLiveChatActions77_(arr).then(() => {
  5704. resolve();
  5705. });
  5706. });
  5707.  
  5708. resistanceUpdateFn_();
  5709. }
  5710. console.log("handleLiveChatActions_", "OK");
  5711. } else {
  5712. console.log("handleLiveChatActions_", "NG");
  5713. }
  5714. }
  5715.  
  5716. mclp.hasUserJustInteracted11_ = () => {
  5717. const t = dateNow();
  5718. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  5719. }
  5720.  
  5721. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  5722.  
  5723. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  5724.  
  5725. mclp.canScrollToBottom_ = function () {
  5726. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  5727. }
  5728.  
  5729. console.log("canScrollToBottom_", "OK");
  5730. } else {
  5731. console.log("canScrollToBottom_", "NG");
  5732. }
  5733.  
  5734. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  5735.  
  5736. mclp.isSmoothScrollEnabled_ = function () {
  5737. return false;
  5738. }
  5739.  
  5740. mclp.maybeResizeScrollContainer_ = function () {
  5741. //
  5742. }
  5743.  
  5744. mclp.refreshOffsetContainerHeight_ = function () {
  5745. //
  5746. }
  5747.  
  5748. mclp.smoothScroll_ = function () {
  5749. //
  5750. }
  5751.  
  5752. mclp.resetSmoothScroll_ = function () {
  5753. //
  5754. }
  5755. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  5756. } else {
  5757. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  5758. }
  5759.  
  5760. if ((_flag0281_ & 0x8) == 0) {
  5761.  
  5762.  
  5763. if (typeof mclp.forEachItem_ === 'function' && !mclp.forEachItem66_ && skipErrorForhandleAddChatItemAction_ && mclp.forEachItem_.length === 1) {
  5764.  
  5765. mclp.forEachItem66_ = mclp.forEachItem_;
  5766. mclp.forEachItem_ = function (a) {
  5767.  
  5768. if ((this._flag0281_ & 0x8) == 0x8) return this.forEachItem66_(a);
  5769.  
  5770. // ƒ (a){this.visibleItems.forEach(a.bind(this,"visibleItems"));this.activeItems_.forEach(a.bind(this,"activeItems_"))}
  5771.  
  5772. try {
  5773.  
  5774. let items801 = false;
  5775. if (typeof a === 'function') {
  5776. const items = this.items;
  5777. if (items instanceof HTMLDivElement) {
  5778. const ev = this.visibleItems;
  5779. const ea = this.activeItems_;
  5780. if (ev && ea && ev.length >= 0 && ea.length >= 0) {
  5781. items801 = items;
  5782. }
  5783. }
  5784. }
  5785.  
  5786. if (items801) {
  5787. items801.__children801__ = 1;
  5788. const res = this.forEachItem66_(a);
  5789. items801.__children801__ = 0;
  5790. return res;
  5791. }
  5792.  
  5793. } catch (e) { }
  5794. return this.forEachItem66_(a);
  5795.  
  5796.  
  5797. // this.visibleItems.forEach((val, idx, arr)=>{
  5798. // a.call(this, 'visibleItems', val, idx, arr);
  5799. // });
  5800.  
  5801. // this.activeItems_.forEach((val, idx, arr)=>{
  5802. // a.call(this, 'activeItems_', val, idx, arr);
  5803. // });
  5804.  
  5805.  
  5806.  
  5807. }
  5808.  
  5809.  
  5810. }
  5811.  
  5812. }
  5813.  
  5814. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  5815.  
  5816. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  5817. mclp.handleAddChatItemAction_ = function (a) {
  5818. try {
  5819. if (a && typeof a === 'object' && !('length' in a)) {
  5820. fixLiveChatItem(a.item, null);
  5821. console.assert(arguments[0] === a);
  5822. }
  5823. } catch (e) { console.warn(e) }
  5824. let res;
  5825. if (skipErrorForhandleAddChatItemAction_) { // YouTube Native Engine Issue
  5826. try {
  5827. res = this.handleAddChatItemAction66_.apply(this, arguments);
  5828. } catch (e) {
  5829. if (e && (e.message || '').includes('.querySelector(')) {
  5830. console.log("skipErrorForhandleAddChatItemAction_", e.message);
  5831. } else {
  5832. throw e;
  5833. }
  5834. }
  5835. } else {
  5836. res = this.handleAddChatItemAction66_.apply(this, arguments);
  5837. }
  5838. return res;
  5839. }
  5840.  
  5841. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  5842. } else {
  5843.  
  5844. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  5845. }
  5846.  
  5847.  
  5848. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  5849.  
  5850. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  5851. mclp.handleReplaceChatItemAction_ = function (a) {
  5852. try {
  5853. if (a && typeof a === 'object' && !('length' in a)) {
  5854. fixLiveChatItem(a.replacementItem, null);
  5855. console.assert(arguments[0] === a);
  5856. }
  5857. } catch (e) { console.warn(e) }
  5858. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  5859. }
  5860.  
  5861. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  5862. } else {
  5863.  
  5864. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  5865. }
  5866.  
  5867. console.log("[End]");
  5868. console.groupEnd();
  5869.  
  5870. }).catch(console.warn);
  5871.  
  5872.  
  5873. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  5874.  
  5875. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  5876.  
  5877. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  5878.  
  5879. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  5880. let v = `${attrValue}`;
  5881. // conside a ticker is 101px width
  5882. // 1% = 1.01px
  5883. // 0.2% = 0.202px
  5884.  
  5885.  
  5886. const ratio1 = (yd.ratio * 100);
  5887. if (ratio1 > -1) { // avoid NaN
  5888.  
  5889. // countdownDurationMs
  5890. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  5891. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  5892. // 150000 - 1% <1% = 1.5s>
  5893. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  5894. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  5895.  
  5896. // 99px * 5% = 4.95px
  5897.  
  5898. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  5899.  
  5900.  
  5901. // 1% Duration
  5902.  
  5903. let ratio2 = ratio1;
  5904.  
  5905. const ydd = yd.data;
  5906. if (ydd) {
  5907.  
  5908. const d1 = ydd.durationSec;
  5909. const d2 = ydd.fullDurationSec;
  5910.  
  5911. // @ step timing [min. 0.2%]
  5912. let numOfSteps = 500;
  5913. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  5914. if (d2 > 400) numOfSteps = 500; // 0.2%
  5915. else if (d2 > 200) numOfSteps = 200; // 0.5%
  5916. else if (d2 > 100) numOfSteps = 100; // 1%
  5917. else if (d2 > 50) numOfSteps = 50; // 2%
  5918. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  5919. else numOfSteps = 20;
  5920. }
  5921. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  5922. if (numOfSteps < 5) numOfSteps = 5;
  5923.  
  5924. const rd = numOfSteps / 100.0;
  5925.  
  5926. ratio2 = Math.round(ratio2 * rd) / rd;
  5927.  
  5928. // ratio2 = Math.round(ratio2 * 5) / 5;
  5929. ratio2 = ratio2.toFixed(1);
  5930. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  5931.  
  5932. if (yd.__style_last__ === v) return;
  5933. yd.__style_last__ = v;
  5934. // do not consider any delay here.
  5935. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  5936.  
  5937. }
  5938. }
  5939.  
  5940. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  5941.  
  5942.  
  5943. } else {
  5944. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  5945. }
  5946.  
  5947. };
  5948.  
  5949.  
  5950. const fpTicker = (renderer) => {
  5951. if (FLAG_001a) return;
  5952. const cnt = insp(renderer);
  5953. assertor(() => typeof (cnt || 0).is === 'string');
  5954. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  5955. const container = (cnt.$ || 0).container;
  5956. if (container) {
  5957. assertor(() => (container || 0).nodeType === 1);
  5958. assertor(() => typeof container.setAttribute === 'function');
  5959. container.setAttribute = tickerContainerSetAttribute;
  5960. } else {
  5961. console.warn(`"container" does not exist in ${cnt.is}`);
  5962. }
  5963. };
  5964.  
  5965.  
  5966. const tags = [
  5967. "yt-live-chat-ticker-renderer",
  5968. "yt-live-chat-ticker-paid-message-item-renderer",
  5969. "yt-live-chat-ticker-paid-sticker-item-renderer",
  5970. "yt-live-chat-ticker-sponsor-item-renderer"
  5971. ];
  5972.  
  5973. const tagsItemRenderer = [
  5974. "yt-live-chat-ticker-renderer",
  5975. "yt-live-chat-ticker-paid-message-item-renderer",
  5976. "yt-live-chat-ticker-paid-sticker-item-renderer",
  5977. "yt-live-chat-ticker-sponsor-item-renderer"
  5978. ];
  5979.  
  5980. const wmList = new Set;
  5981. if (DEBUG_wmList) {
  5982.  
  5983. setInterval(() => {
  5984. let q = document.querySelector('#label-text');
  5985. if(!q) return;
  5986. const size = new Set([...wmList].filter(e => e?.deref()?.isConnected === false).map(e => e?.deref())).size;
  5987. q.textContent = `${48833}, ${DEBUG_wmList_started}, ${size}`;
  5988.  
  5989. // console.log(48833, )
  5990. }, 100);
  5991. }
  5992.  
  5993.  
  5994. /*
  5995. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  5996. const dProto = {
  5997. detachedForTickerInit: function () {
  5998. try {
  5999. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  6000. // this.behaviorActionMap = 0;
  6001. // this.isVisibilityRoot = 0;
  6002. } catch (e) { }
  6003. return this.detached582MemoryLeak();
  6004. },
  6005. attachedForTickerInit: function () {
  6006. wmList.add(new WeakRef(this))
  6007. // fpTicker(this.hostElement || this);
  6008. return this.attached77();
  6009. },
  6010. }
  6011. for (const tag of tagsItemRenderer) { // ##tag##
  6012. const dummy = document.createElement(tag);
  6013. const cProto = getProto(dummy);
  6014. if (!cProto || !cProto.attached) {
  6015. console.warn(`proto.attached for ${tag} is unavailable.`);
  6016. continue;
  6017. }
  6018. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  6019. cProto.detached582MemoryLeak = cProto.detached;
  6020. cProto.detached = cProto.detachedForTickerInit;
  6021. }
  6022. cProto.attached77 = cProto.attached;
  6023. cProto.attached = dProto.attachedForTickerInit;
  6024. }
  6025. });
  6026. */
  6027.  
  6028.  
  6029. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  6030.  
  6031. if (FLAG_001b) return;
  6032. mightFirstCheckOnYtInit();
  6033. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  6034. console.log("[Begin]");
  6035.  
  6036. let dummyValueForStyleReturn = null;
  6037.  
  6038. const genDummyValueForStyleReturn = () => {
  6039. let s = `--nx:82;`
  6040. let ro = {
  6041. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  6042. "implementsGoogStringTypedString": true
  6043. };
  6044. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  6045. return ro;
  6046. }
  6047.  
  6048. let isCSSPropertySupported_ = null;
  6049. const isCSSPropertySupported = () => {
  6050.  
  6051. // @property --ticker-rtime
  6052.  
  6053. if (typeof isCSSPropertySupported_ === 'boolean') return isCSSPropertySupported_;
  6054. isCSSPropertySupported_ = false;
  6055.  
  6056. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return false;
  6057. const documentElement = document.documentElement;
  6058. if (!documentElement) {
  6059. console.warn('document.documentElement is not found');
  6060. return false;
  6061. }
  6062. if (`${getComputedStyleCached(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  6063. return false;
  6064. }
  6065.  
  6066. const ae = animate.call(documentElement,
  6067. [
  6068. { '--ticker-rtime': '70%' },
  6069. { '--ticker-rtime': '30%' }
  6070. ],
  6071. {
  6072. fill: "forwards",
  6073. duration: 1000 * 40,
  6074. easing: 'linear'
  6075. }
  6076. );
  6077.  
  6078. let animatedValue = getComputedStyleCached(document.documentElement).getPropertyValue('--ticker-rtime');
  6079. ae.finish();
  6080. if (`${animatedValue}`.length !== 3) return false;
  6081.  
  6082. isCSSPropertySupported_ = true;
  6083. return true;
  6084.  
  6085. };
  6086.  
  6087. let tickerAttachmentId = 0;
  6088.  
  6089. let windowShownAt = -1;
  6090. const setupEventForWindowShownAt = () => {
  6091. window.addEventListener('visibilitychange', () => {
  6092. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  6093. else windowShownAt = 0;
  6094. }, false);
  6095. }
  6096.  
  6097. const __requestRemoval__ = function (cnt) {
  6098. if (cnt.hostElement && typeof cnt.requestRemoval === 'function') {
  6099. try {
  6100. const id = (cnt.data || 0).id;
  6101. if (!id) cnt.data = { id: 1 };
  6102. } catch (e) { }
  6103. try {
  6104. cnt.requestRemoval();
  6105. return true;
  6106. } catch (e) { }
  6107. }
  6108. return false;
  6109. }
  6110.  
  6111.  
  6112.  
  6113. const dProto = {
  6114.  
  6115.  
  6116. /**
  6117. *
  6118.  
  6119. f.updateStatsBarAndMaybeShowAnimation = function(a, b, c) {
  6120. var d = this;
  6121. a || c();
  6122. a && this.statsBar && this.username && this.textContent && (this.isMouseOver ? (b(),
  6123. c()) : (a = this.animateShowStats(),
  6124. this.data.animationOrigin && this.data.trackingParams && aB().stateChanged(this.data.trackingParams, {
  6125. animationEventData: {
  6126. origin: this.data.animationOrigin
  6127. }
  6128. }),
  6129. a.finished.then(function() {
  6130. var e;
  6131. setTimeout(function() {
  6132. b();
  6133. c();
  6134. if (!d.isMouseOver) {
  6135. var g, k;
  6136. d.animateHideStats(((g = d.data) == null ? void 0 : g.dynamicStateData.stateSlideDurationMs) || 0, ((k = d.data) == null ? void 0 : k.dynamicStateData.stateUpdateDelayAfterMs) || 0)
  6137. }
  6138. }, ((e = d.data) == null ? void 0 : e.dynamicStateData.stateUpdateDelayBeforeMs) || 0)
  6139. })))
  6140. }
  6141.  
  6142. *
  6143. */
  6144.  
  6145.  
  6146.  
  6147. /**
  6148. *
  6149. *
  6150.  
  6151. f.animateShowStats = function() {
  6152. var a = this.textContent.animate({
  6153. transform: "translateY(-30px)"
  6154. }, {
  6155. duration: this.data.dynamicStateData.stateSlideDurationMs,
  6156. fill: "forwards"
  6157. });
  6158. this.username.animate({
  6159. opacity: 0
  6160. }, {
  6161. duration: 500,
  6162. fill: "forwards"
  6163. });
  6164. this.statsBar.animate({
  6165. opacity: 1
  6166. }, {
  6167. duration: 500,
  6168. fill: "forwards"
  6169. });
  6170. return a
  6171. }
  6172. ;
  6173. f.animateHideStats = function(a, b) {
  6174. this.textContent.animate({
  6175. transform: "translateY(0)"
  6176. }, {
  6177. duration: a,
  6178. fill: "forwards",
  6179. delay: b
  6180. });
  6181. this.username.animate({
  6182. opacity: 1
  6183. }, {
  6184. duration: 300,
  6185. fill: "forwards",
  6186. delay: b
  6187. });
  6188. this.statsBar.animate({
  6189. opacity: 0
  6190. }, {
  6191. duration: 300,
  6192. fill: "forwards",
  6193. delay: b
  6194. })
  6195. }
  6196. *
  6197. */
  6198. updateStatsBarAndMaybeShowAnimationRevised: function (a, b, c) {
  6199. // prevent memory leakage due to d.data was asked in a.finished.then
  6200. try{
  6201. // console.log('updateStatsBarAndMaybeShowAnimation called', this.is)
  6202. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6203. return this.updateStatsBarAndMaybeShowAnimation38.call(this.__proxySelf0__, a, b, c);
  6204. }catch(e){
  6205. console.log('updateStatsBarAndMaybeShowAnimationRevised ERROR');
  6206. console.error(e);
  6207. }
  6208. },
  6209.  
  6210. detachedForMemoryLeakage: function () {
  6211.  
  6212. try{
  6213. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  6214. // this.behaviorActionMap = 0;
  6215. // this.isVisibilityRoot = 0;
  6216. }catch(e){}
  6217. return this.detached582MemoryLeak();
  6218. },
  6219.  
  6220. detachedForTickerInit: function () {
  6221.  
  6222. Promise.resolve(this).then((cnt) => {
  6223. if (cnt.isAttached) return;
  6224. cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false && __requestRemoval__(cnt);
  6225. cnt.rafId > 1 && rafHub.cancel(cnt.rafId);
  6226. }).catch(console.warn);
  6227.  
  6228. let r;
  6229. try {
  6230. r = this.detached77();
  6231. } catch (e) {
  6232. console.warn(e);
  6233. }
  6234. this.__ticker_attachmentId__ = 0;
  6235. return r;
  6236. },
  6237.  
  6238. attachedForTickerInit: function () {
  6239. if (tickerAttachmentId > 1e9) tickerAttachmentId = 9;
  6240. this.__ticker_attachmentId__ = ++tickerAttachmentId;
  6241.  
  6242. DEBUG_wmList && wmList.add(new WeakRef(this))
  6243. if (DEBUG_wmList && !DEBUG_wmList_started) {
  6244. console.log('!!!!!!!!!!!!! DEBUG_wmList_started !!!!!!!!!')
  6245. DEBUG_wmList_started = 1;
  6246. }
  6247.  
  6248. fpTicker(this.hostElement || this);
  6249. return this.attached77();
  6250.  
  6251. },
  6252.  
  6253.  
  6254. // doAnimator
  6255.  
  6256. _makeAnimator: function () {
  6257. if (this._r782) return;
  6258. // if (!this.isAttached) return;
  6259. if (!this._runnerAE) {
  6260. /** @type {HTMLElement | null} */
  6261. const aElement = (this.$ || 0).container;
  6262. if (!aElement) return console.warn("this.$.container is undefined");
  6263. const da = this.data;
  6264. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  6265. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  6266. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  6267. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  6268.  
  6269. // if (!this.__tickerBackgroundInitialChecked__) {
  6270. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  6271. // console.log('__tickerBackgroundInitialChecked__')
  6272. // this._checkTickerBackgroundChanged();
  6273. // }
  6274.  
  6275. aElement.style.setProperty('--ticker-c1', c1);
  6276. aElement.style.setProperty('--ticker-c2', c2);
  6277. aElement.classList.add(runTickerClassName);
  6278. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  6279. // this._aeStartV = this.countdownMs;
  6280. // this._aeStartT = this.countdownDurationMs;
  6281. if (!(p >= 0 && p <= 100)) {
  6282. console.warn('incorrect time ratio', p);
  6283. } else {
  6284. /*
  6285. const u0 = p.toFixed(4) + '%';
  6286. this._runnerAE = animate.call(aElement,
  6287. [
  6288. { '--ticker-rtime': u0 },
  6289. { '--ticker-rtime': '0%' }
  6290. ]
  6291. ,
  6292. {
  6293. fill: "forwards",
  6294. duration: this.countdownMs,
  6295. easing: "linear"
  6296. }
  6297. );
  6298. */
  6299.  
  6300. let timingFn = 'linear';
  6301.  
  6302. const totalDuration = this.countdownDurationMs;
  6303.  
  6304. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  6305.  
  6306. // @ step timing [min. 0.2%]
  6307. let stepInterval = 0.2; // unit: %
  6308. if (totalDuration > 400000) stepInterval = 0.2;
  6309. else if (totalDuration > 200000) stepInterval = 0.5;
  6310. else if (totalDuration > 100000) stepInterval = 1;
  6311. else if (totalDuration > 50000) stepInterval = 2;
  6312. else if (totalDuration > 25000) stepInterval = 5;
  6313. else stepInterval = 5;
  6314.  
  6315. let numOfSteps = Math.round(100 / stepInterval);
  6316.  
  6317. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  6318. if (numOfSteps < 5) numOfSteps = 5;
  6319.  
  6320. timingFn = `steps(${numOfSteps}, end)`;
  6321.  
  6322. }
  6323.  
  6324.  
  6325. /** @type {Animation} */
  6326. const ae = animate.call(aElement,
  6327. [
  6328. { '--ticker-rtime': '100%' },
  6329. { '--ticker-rtime': '0%' }
  6330. ]
  6331. ,
  6332. {
  6333. fill: "forwards",
  6334. duration: totalDuration,
  6335. easing: timingFn
  6336. }
  6337. );
  6338.  
  6339. this._runnerAE = ae;
  6340.  
  6341. ae.onfinish = (event) => {
  6342. this.onfinish = null;
  6343. if (this._runnerAE !== ae) return;
  6344. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  6345. this._aeFinished(event);
  6346. }
  6347. }
  6348.  
  6349. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  6350.  
  6351. if (bq >= 0 && bq <= totalDuration) {
  6352.  
  6353. if (bq > totalDuration - 1) {
  6354. ae.currentTime = bq;
  6355. // setTimeout(() => {
  6356. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  6357. // }, 1);
  6358. } else {
  6359. ae.currentTime = bq;
  6360. }
  6361. } else {
  6362. console.warn('Error on setting _runnerAE.currentTime!');
  6363. }
  6364.  
  6365.  
  6366. aeConstructor = ae.constructor; // constructor is from iframe
  6367. return ae;
  6368. }
  6369. } else {
  6370. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  6371. // assume just time update
  6372. const ae = this._runnerAE;
  6373. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  6374. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  6375. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  6376. if (!(p >= 0 && p <= 100)) {
  6377. console.warn('incorrect time ratio', p);
  6378. } else {
  6379. // let u0 = p.toFixed(4) + '%'
  6380. /*
  6381. ae.effect.setKeyframes([
  6382. { '--ticker-rtime': u0 },
  6383. { '--ticker-rtime': '0%' }
  6384. ]);
  6385. ae.effect.updateTiming({ duration: this.countdownMs });
  6386. */
  6387. // ae.currentTime = 0;
  6388.  
  6389.  
  6390.  
  6391. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  6392. if (bq >= 0 && bq <= this.countdownDurationMs) {
  6393.  
  6394. this._runnerAE.currentTime = bq
  6395. } else {
  6396. console.warn('Error on setting _runnerAE.currentTime!');
  6397. }
  6398.  
  6399.  
  6400. ae.play();
  6401. return ae;
  6402. }
  6403. }
  6404. },
  6405.  
  6406. _aeFinished: function (event) {
  6407.  
  6408. if (this._r782) return;
  6409.  
  6410. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  6411. this._throwOut();
  6412. return;
  6413. }
  6414.  
  6415. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  6416.  
  6417. let lc = window.performance.now();
  6418. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  6419. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  6420. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  6421. if (this.countdownMs > 76) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs, this, event); // just warning.
  6422.  
  6423. this.countdownMs = 0;
  6424. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null;
  6425.  
  6426. if (this.isAttached) {
  6427. let fastRemoved = false;
  6428. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  6429. // no animation if the video page is switched from background to foreground
  6430. // this.hostElement.style.display = 'none';
  6431.  
  6432. fastRemoved = __requestRemoval__(this);
  6433. }
  6434.  
  6435. if (!fastRemoved) {
  6436. "auto" === this.hostElement.style.width && this.setContainerWidth();
  6437. this.slideDown();
  6438. }
  6439. }
  6440.  
  6441.  
  6442.  
  6443. },
  6444.  
  6445.  
  6446. /** @type {()} */
  6447. _throwOut: function () {
  6448. this._r782 = 1;
  6449. Promise.resolve(this).then((cnt) => {
  6450. __requestRemoval__(cnt);
  6451. cnt.detached();
  6452. if (cnt.__dataClientsReady === true) cnt.__dataClientsReady = false;
  6453. if (cnt.__dataEnabled === true) cnt.__dataEnabled = false;
  6454. if (cnt.__dataReady === true) cnt.__dataReady = false;
  6455. cnt.data = null;
  6456. cnt.countdownMs = 0;
  6457. cnt.lastCountdownTimeMs = null;
  6458. const hm = cnt.hostElement || cnt;
  6459. if (hm.parentNode) hm.remove();
  6460. for (let t; t = hm.firstChild;) t.remove();
  6461. }).catch(e => {
  6462. console.warn(e);
  6463. });
  6464. },
  6465.  
  6466.  
  6467. // doTimerFnModification
  6468.  
  6469.  
  6470. /** @type {(a, b)} */
  6471. startCountdownForTimerFnModA: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  6472. try {
  6473.  
  6474. const cnt = kRef(this);
  6475. if (!cnt) return;
  6476. if (!cnt.hostElement) return;
  6477.  
  6478. const attachementId = cnt.__ticker_attachmentId__;
  6479. if(!attachementId) return;
  6480.  
  6481. // a.durationSec [s] => countdownMs [ms]
  6482. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  6483. // lastCountdownTimeMs => raf ongoing
  6484. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  6485.  
  6486. if (cnt._r782) return;
  6487.  
  6488. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6489. cnt._throwOut();
  6490. return;
  6491. }
  6492.  
  6493. // TimerFnModA
  6494.  
  6495. b = void 0 === b ? 0 : b;
  6496. if (void 0 !== a) {
  6497.  
  6498. cnt.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  6499. cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs; // constant throughout the animation
  6500. if (!(cnt.lastCountdownTimeMs || cnt.isAnimationPaused)) {
  6501. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now()
  6502. cnt.rafId = 1
  6503. if (cnt._runnerAE) console.warn('Error in .startCountdown; cnt._runnerAE already created.')
  6504. cnt.detlaSincePausedSecs = 0;
  6505. const ae = cnt._makeAnimator();
  6506. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  6507.  
  6508. // if (playerProgressChangedArg1 === null) {
  6509. // console.log('startCountdownForTimerFnModA', cnt.data)
  6510. // }
  6511.  
  6512. if (isPlayProgressTriggered && cnt.isAnimationPaused !== true && cnt.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__) {
  6513.  
  6514.  
  6515.  
  6516.  
  6517. cnt.playerProgressSec = lastPlayerProgress > 0 ? lastPlayerProgress : 0; // save the progress first
  6518. cnt.isAnimationPaused = true; // trigger isAnimationPausedChanged
  6519. cnt.detlaSincePausedSecs = 0;
  6520. cnt._forceNoDetlaSincePausedSecs783 = 1; // reset cnt.detlaSincePausedSecs = 0 when resumed
  6521.  
  6522. relayPromise = relayPromise || new PromiseExternal();
  6523.  
  6524. relayPromise.then(() => {
  6525.  
  6526. const cnt = kRef(this);
  6527. if (!cnt) return;
  6528. if (!cnt.hostElement) return;
  6529.  
  6530. if (cnt && attachementId !== cnt.__ticker_attachmentId__) return;
  6531. if (cnt.isAttached === true && cnt.countdownDurationMs > 0 && cnt.isAnimationPaused === true && cnt.isReplayPaused !== true) {
  6532. cnt.isAnimationPaused = false;
  6533. }
  6534. });
  6535.  
  6536.  
  6537. }
  6538.  
  6539.  
  6540.  
  6541. }
  6542. }
  6543.  
  6544. } catch (e) {
  6545. console.warn(e);
  6546. }
  6547.  
  6548. },
  6549.  
  6550.  
  6551.  
  6552. /** @type {(a, b)} */
  6553. startCountdownForTimerFnModT: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  6554.  
  6555. try {
  6556. const cnt = kRef(this);
  6557. if (!cnt) return;
  6558. if (!cnt.hostElement) return;
  6559.  
  6560. const attachementId = cnt.__ticker_attachmentId__;
  6561. if(!attachementId) return;
  6562.  
  6563. // a.durationSec [s] => countdownMs [ms]
  6564. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  6565. // lastCountdownTimeMs => raf ongoing
  6566. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  6567.  
  6568. if (cnt._r782) return;
  6569.  
  6570. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6571. cnt._throwOut();
  6572. return;
  6573. }
  6574.  
  6575. // TimerFnModT
  6576.  
  6577. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  6578. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  6579. b = void 0 === b ? 0 : b;
  6580. void 0 !== a && (cnt.countdownMs = 1E3 * a,
  6581. cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs,
  6582. cnt.ratio = 1,
  6583. cnt.lastCountdownTimeMs || cnt.isAnimationPaused || (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now(),
  6584. cnt.rafId = rafHub.request(cnt.boundUpdateTimeout37_)))
  6585.  
  6586. } catch (e) {
  6587. console.warn(e);
  6588. }
  6589.  
  6590. },
  6591.  
  6592.  
  6593. /** @type {(a,)} */
  6594. updateTimeoutForTimerFnModA: function (a) {
  6595.  
  6596. try {
  6597. const cnt = kRef(this);
  6598. if (!cnt) return;
  6599. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6600.  
  6601. const attachementId = cnt.__ticker_attachmentId__;
  6602. if(!attachementId) return;
  6603.  
  6604. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  6605.  
  6606. if (cnt._r782) return;
  6607.  
  6608. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6609. cnt._throwOut();
  6610. return;
  6611. }
  6612.  
  6613. // TimerFnModA
  6614.  
  6615. if (!cnt._runnerAE) console.warn('Error in .updateTimeout; cnt._runnerAE is undefined');
  6616. if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  6617. cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  6618. }
  6619. if (cnt.countdownMs > cnt.countdownDurationMs) cnt.countdownMs = cnt.countdownDurationMs;
  6620. if (cnt.isAttached && cnt.countdownMs) {
  6621. cnt.lastCountdownTimeMs = a
  6622. const ae = cnt._makeAnimator(); // request raf
  6623. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  6624. } else {
  6625. (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  6626. cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  6627. cnt.slideDown()));
  6628. }
  6629.  
  6630. } catch (e) {
  6631. console.warn(e);
  6632. }
  6633.  
  6634.  
  6635. },
  6636.  
  6637. /** @type {(a,)} */
  6638. updateTimeoutForTimerFnModT: function (a) {
  6639.  
  6640. try {
  6641. const cnt = kRef(this);
  6642. if (!cnt) return;
  6643. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6644.  
  6645. const attachementId = cnt.__ticker_attachmentId__;
  6646. if(!attachementId) return;
  6647.  
  6648. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  6649.  
  6650. if (cnt._r782) return;
  6651.  
  6652. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6653. cnt._throwOut();
  6654. return;
  6655. }
  6656.  
  6657. // TimerFnModT
  6658.  
  6659. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  6660. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  6661. if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  6662. cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  6663. }
  6664. // console.log(703, cnt.countdownMs)
  6665. cnt.ratio = cnt.countdownMs / cnt.countdownDurationMs;
  6666. cnt.isAttached && cnt.countdownMs ? (cnt.lastCountdownTimeMs = a,
  6667. cnt.rafId = rafHub.request(cnt.boundUpdateTimeout37_)) : (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  6668. cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  6669. cnt.slideDown()))
  6670.  
  6671.  
  6672. } catch (e) {
  6673. console.warn(e);
  6674. }
  6675. },
  6676.  
  6677. /** @type {(a,b)} */
  6678. isAnimationPausedChangedForTimerFnModA: function (a, b) {
  6679.  
  6680. const cnt = kRef(this);
  6681. if (!cnt) return;
  6682. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6683.  
  6684. const attachementId = cnt.__ticker_attachmentId__;
  6685. if(!attachementId) return;
  6686.  
  6687. if (cnt._r782) return;
  6688.  
  6689. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6690. cnt._throwOut();
  6691. return;
  6692. }
  6693. let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  6694. cnt._forceNoDetlaSincePausedSecs783 = 0;
  6695.  
  6696. Promise.resolve(cnt).then((cnt) => {
  6697.  
  6698. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6699.  
  6700. if (a) {
  6701.  
  6702. if (cnt._runnerAE && cnt._runnerAE.playState === 'running') {
  6703.  
  6704. cnt._runnerAE.pause()
  6705. let lc = window.performance.now();
  6706. cnt.countdownMs = Math.max(0, cnt.countdownMs - (lc - cnt.lastCountdownTimeMs));
  6707. if (cnt.countdownMs > cnt.countdownDurationMs) cnt.countdownMs = cnt.countdownDurationMs;
  6708. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = lc;
  6709. }
  6710.  
  6711. } else if (!a && b) {
  6712.  
  6713.  
  6714. if (forceNoDetlaSincePausedSecs783) cnt.detlaSincePausedSecs = 0;
  6715. a = cnt.detlaSincePausedSecs ? (cnt.lastCountdownTimeMs || 0) + 1000 * cnt.detlaSincePausedSecs : (cnt.lastCountdownTimeMs || 0);
  6716. cnt.detlaSincePausedSecs = 0;
  6717. cnt.updateTimeout(a);
  6718. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now();
  6719.  
  6720. }
  6721.  
  6722. cnt = null;
  6723.  
  6724.  
  6725. }).catch(e => {
  6726. console.log(e);
  6727. });
  6728.  
  6729.  
  6730.  
  6731. },
  6732.  
  6733.  
  6734. /** @type {(a,b)} */
  6735. isAnimationPausedChangedForTimerFnModT: function (a, b) {
  6736.  
  6737. const cnt = kRef(this);
  6738. if (!cnt) return;
  6739. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  6740.  
  6741. const attachementId = cnt.__ticker_attachmentId__;
  6742. if(!attachementId) return;
  6743.  
  6744. if (cnt._r782) return;
  6745.  
  6746. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  6747. cnt._throwOut();
  6748. return;
  6749. }
  6750. // let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  6751. // cnt._forceNoDetlaSincePausedSecs783 = 0;
  6752.  
  6753. Promise.resolve(cnt).then((cnt) => {
  6754.  
  6755. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6756.  
  6757. // TimerFnModT
  6758.  
  6759. // ez++;
  6760. // if(ez> 1e9) ez=9;
  6761. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  6762. a ? rafHub.cancel(cnt.rafId) : !a && b && (a = cnt.lastCountdownTimeMs || 0,
  6763. cnt.detlaSincePausedSecs && (a = (cnt.lastCountdownTimeMs || 0) + 1E3 * cnt.detlaSincePausedSecs,
  6764. cnt.detlaSincePausedSecs = 0),
  6765. cnt.boundUpdateTimeout37_(a),
  6766. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now())
  6767.  
  6768. cnt = null;
  6769.  
  6770. }).catch(e => {
  6771. console.log(e);
  6772. });
  6773.  
  6774.  
  6775.  
  6776. },
  6777.  
  6778. setContainerWidthNoSelfLeakage: function(){
  6779. // prevent memory leakage due ot delay function
  6780. try{
  6781. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6782. return this.setContainerWidth55.call(this.__proxySelf0__);
  6783. }catch(e){
  6784. console.log('setContainerWidthNoSelfLeakage ERROR');
  6785. console.error(e);
  6786. }
  6787.  
  6788. },
  6789.  
  6790. slideDownNoSelfLeakage: function(){
  6791. // prevent memory leakage due ot delay function
  6792. try{
  6793. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6794. return this.slideDown55.call(this.__proxySelf0__);
  6795. }catch(e){
  6796. console.log('slideDownNoSelfLeakage ERROR');
  6797. console.error(e);
  6798. }
  6799. },
  6800.  
  6801. collapseNoSelfLeakage: function(){
  6802. // prevent memory leakage due ot delay function
  6803. try{
  6804. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6805. return this.collapse55.call(this.__proxySelf0__);
  6806. }catch(e){
  6807. console.log('collapseNoSelfLeakage ERROR');
  6808. console.error(e);
  6809. }
  6810. },
  6811.  
  6812. deletedChangedNoSelfLeakage: function(){
  6813. // prevent memory leakage due ot delay function
  6814. try{
  6815. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  6816. return this.deletedChanged55.call(this.__proxySelf0__);
  6817. }catch(e){
  6818. console.log('deletedChangedNoSelfLeakage ERROR');
  6819. console.error(e);
  6820. }
  6821.  
  6822. },
  6823.  
  6824.  
  6825. /** @type {(a,b)} */
  6826. computeContainerStyleForAnimatorEnabled: function (a, b) {
  6827.  
  6828. if (this._r782) return;
  6829. const attachementId = this.__ticker_attachmentId__;
  6830. if(!attachementId) return;
  6831.  
  6832. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  6833. this._throwOut();
  6834. return;
  6835. }
  6836.  
  6837. return (dummyValueForStyleReturn || (dummyValueForStyleReturn = genDummyValueForStyleReturn()));
  6838.  
  6839. },
  6840.  
  6841.  
  6842.  
  6843. /** @type {()} */
  6844. handlePauseReplayForPlaybackProgressState: function () {
  6845. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  6846.  
  6847. const attachementId = this.__ticker_attachmentId__;
  6848. if(!attachementId) return;
  6849.  
  6850. const jr = mWeakRef(this);
  6851.  
  6852. if (onPlayStateChangePromise) {
  6853.  
  6854. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  6855. const tid = ++this.rtu;
  6856.  
  6857. onPlayStateChangePromise.then(() => {
  6858. const cnt = kRef(jr);
  6859. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6860. if (cnt.isAttached) {
  6861. if (tid === cnt.rtu && !onPlayStateChangePromise && typeof cnt.handlePauseReplay === 'function' && cnt.hostElement) cnt.handlePauseReplay.apply(cnt, arguments);
  6862. // this.handlePauseReplay can be undefined if it is memory cleaned
  6863. }
  6864. });
  6865.  
  6866. return;
  6867. }
  6868.  
  6869. if (playerState !== 2) return;
  6870. if (this.isAttached) {
  6871. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  6872. const tid = ++this.rtk;
  6873. const tc = relayCount;
  6874. foregroundPromiseFn().then(() => {
  6875. const cnt = kRef(jr);
  6876. if (attachementId !== cnt.__ticker_attachmentId__) return;
  6877. if (cnt.isAttached) {
  6878. if (tid === cnt.rtk && tc === relayCount && playerState === 2 && _playerState === playerState && cnt.hostElement) {
  6879. cnt.handlePauseReplay66();
  6880. }
  6881. }
  6882.  
  6883. })
  6884. }
  6885. },
  6886.  
  6887. /** @type {()} */
  6888. handleResumeReplayForPlaybackProgressState: function () {
  6889. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  6890.  
  6891. const attachementId = this.__ticker_attachmentId__;
  6892. if(!attachementId) return;
  6893.  
  6894. const jr = mWeakRef(this);
  6895. if (onPlayStateChangePromise) {
  6896.  
  6897. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  6898. const tid = ++this.rtv;
  6899.  
  6900. onPlayStateChangePromise.then(() => {
  6901. const cnt = kRef(jr);
  6902. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6903. if (tid === cnt.rtv && !onPlayStateChangePromise && typeof cnt.handleResumeReplay === 'function' && cnt.hostElement) cnt.handleResumeReplay.apply(cnt, arguments);
  6904. // this.handleResumeReplay can be undefined if it is memory cleaned
  6905. });
  6906.  
  6907. return;
  6908. }
  6909.  
  6910.  
  6911. if (playerState !== 1) return;
  6912. if (this.isAttached) {
  6913. const tc = relayCount;
  6914.  
  6915. relayPromise = relayPromise || new PromiseExternal();
  6916. relayPromise.then(() => {
  6917. const cnt = kRef(jr);
  6918. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6919. if (relayCount > tc && playerState === 1 && _playerState === playerState && cnt.hostElement) {
  6920. cnt.handleResumeReplay66();
  6921. }
  6922. });
  6923. }
  6924. },
  6925.  
  6926. /** @type {(a,)} */
  6927. handleReplayProgressForPlaybackProgressState: function (a) {
  6928. if (this.isAttached) {
  6929. const attachementId = this.__ticker_attachmentId__;
  6930. if(!attachementId) return;
  6931. const tid = ++this.rtk;
  6932. const jr = mWeakRef(kRef(this));
  6933. foregroundPromiseFn().then(() => {
  6934. const cnt = kRef(jr);
  6935. if(attachementId !== cnt.__ticker_attachmentId__) return;
  6936. if (cnt.isAttached) {
  6937. if (tid === cnt.rtk && cnt.hostElement) {
  6938. cnt.handleReplayProgress66(a);
  6939. }
  6940. }
  6941. })
  6942. }
  6943. }
  6944.  
  6945.  
  6946. }
  6947.  
  6948.  
  6949. for (const tag of tagsItemRenderer) { // ##tag##
  6950.  
  6951.  
  6952. const dummy = document.createElement(tag);
  6953.  
  6954. const cProto = getProto(dummy);
  6955. if (!cProto || !cProto.attached) {
  6956. console.warn(`proto.attached for ${tag} is unavailable.`);
  6957. continue;
  6958. }
  6959.  
  6960. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  6961. cProto.detached582MemoryLeak = cProto.detached;
  6962. cProto.detached = dProto.detachedForMemoryLeakage;
  6963. }
  6964.  
  6965. cProto.detached77 = cProto.detached;
  6966. cProto.detached = dProto.detachedForTickerInit;
  6967.  
  6968. cProto.attached77 = cProto.attached;
  6969.  
  6970. cProto.attached = dProto.attachedForTickerInit;
  6971.  
  6972. if (FLAG_001c) continue;
  6973.  
  6974. let flgLeakageFixApplied = 0;
  6975.  
  6976. if (FIX_MEMORY_LEAKAGE_TICKER_STATSBAR && typeof cProto.updateStatsBarAndMaybeShowAnimation === 'function' && !cProto.updateStatsBarAndMaybeShowAnimation38 && cProto.updateStatsBarAndMaybeShowAnimation.length === 3) {
  6977.  
  6978. cProto.updateStatsBarAndMaybeShowAnimation38 = cProto.updateStatsBarAndMaybeShowAnimation;
  6979. cProto.updateStatsBarAndMaybeShowAnimation = dProto.updateStatsBarAndMaybeShowAnimationRevised;
  6980.  
  6981. flgLeakageFixApplied |= 2;
  6982. } else {
  6983. // the function is only in yt-live-chat-ticker-paid-message-item-renderer
  6984. }
  6985.  
  6986.  
  6987. // ------------- withTimerFn_ -------------
  6988.  
  6989. let withTimerFn_ = 0;
  6990. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  6991.  
  6992. // console.log('startCountdown', typeof cProto.startCountdown)
  6993. // console.log('updateTimeout', typeof cProto.updateTimeout)
  6994. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  6995.  
  6996. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  6997. const isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  6998. if (!isTimingFunctionHackable) console.log('isTimingFunctionHackable = false');
  6999. withTimerFn_ = isTimingFunctionHackable ? 2 : 1;
  7000. } else {
  7001. let flag = 0;
  7002. if (typeof cProto.startCountdown === 'function') flag |= 1;
  7003. if (typeof cProto.updateTimeout === 'function') flag |= 2;
  7004. if (typeof cProto.isAnimationPausedChanged === 'function') flag |= 4;
  7005.  
  7006. console.log(`Skip Timing Function Modification: ${flag} / ${1 + 2 + 4}`, ` ${tag}`);
  7007. // console.log(Object.getOwnPropertyNames(cProto))
  7008. // continue;
  7009. }
  7010. // ------------- withTimerFn_ -------------
  7011.  
  7012. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7013.  
  7014. let urt = 0;
  7015.  
  7016. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  7017.  
  7018.  
  7019. /**
  7020. *
  7021. f.handlePauseReplay = function() {
  7022. this.isAnimationPaused = !0;
  7023. this.detlaSincePausedSecs = 0
  7024. }
  7025. */
  7026.  
  7027. /**
  7028. *
  7029. f.handlePauseReplay = function() {
  7030. this.isReplayPaused = !0
  7031. }
  7032. *
  7033. */
  7034.  
  7035. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  7036. const fi = fnIntegrity(cProto.handlePauseReplay);
  7037. urt++;
  7038. if (fi === '0.8.2' || fi === '0.12.4') {
  7039. } else {
  7040. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  7041. }
  7042. } else {
  7043. if (withTimerFn_ > 0) console.log('Error for setting cProto.handlePauseReplay', tag)
  7044. }
  7045.  
  7046. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handleResumeReplay.length === 0) {
  7047. urt++;
  7048. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  7049. } else {
  7050. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleResumeReplay', tag)
  7051. }
  7052.  
  7053. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  7054. urt++;
  7055. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  7056. } else {
  7057. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleReplayProgress', tag)
  7058. }
  7059.  
  7060.  
  7061.  
  7062. }
  7063.  
  7064. 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);
  7065. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  7066.  
  7067. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  7068.  
  7069. cProto.rtk = 0;
  7070. cProto.rtu = 0;
  7071. cProto.rtv = 0;
  7072.  
  7073. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  7074. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  7075.  
  7076. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  7077. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  7078.  
  7079. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  7080. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  7081.  
  7082. }
  7083.  
  7084. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7085.  
  7086. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7087.  
  7088. if (FIX_MEMORY_LEAKAGE_TICKER_TIMER) {
  7089. if (typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth55 && cProto.setContainerWidth.length === 0) {
  7090. cProto.setContainerWidth55 = cProto.setContainerWidth;
  7091. cProto.setContainerWidth = dProto.setContainerWidthNoSelfLeakage;
  7092. flgLeakageFixApplied |= 4;
  7093. }
  7094. if (typeof cProto.slideDown === 'function' && !cProto.slideDown55 && cProto.slideDown.length === 0) {
  7095. cProto.slideDown55 = cProto.slideDown;
  7096. cProto.slideDown = dProto.slideDownNoSelfLeakage;
  7097. flgLeakageFixApplied |= 8;
  7098. }
  7099. if (typeof cProto.collapse === 'function' && !cProto.collapse55 && cProto.collapse.length === 0) {
  7100. cProto.collapse55 = cProto.collapse;
  7101. cProto.collapse = dProto.collapseNoSelfLeakage;
  7102. flgLeakageFixApplied |= 16;
  7103. }
  7104. if (typeof cProto.deletedChanged === 'function' && !cProto.deletedChanged55 && cProto.deletedChanged.length === 0) {
  7105.  
  7106. cProto.deletedChanged55 = cProto.deletedChanged;
  7107. cProto.deletedChanged = dProto.deletedChangedNoSelfLeakage;
  7108. flgLeakageFixApplied |= 32;
  7109. }
  7110.  
  7111. }
  7112.  
  7113. console.log(`FIX_MEMORY_LEAKAGE_TICKER_: ${flgLeakageFixApplied} / ${1 + 2 + 4 + 8 + 16 + 32}`, cProto.is);
  7114.  
  7115. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7116.  
  7117.  
  7118.  
  7119.  
  7120. if (withTimerFn_ > 0) {
  7121.  
  7122. const isTimingFunctionHackable = withTimerFn_ & 2;
  7123.  
  7124. let doAnimator_ = false;
  7125.  
  7126. let rafHackState = 0;
  7127. // continue;
  7128. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  7129.  
  7130. // cancelable - this.rafId < isAnimationPausedChanged >
  7131. rafHackState = 1;
  7132.  
  7133. if (isTimingFunctionHackable) {
  7134. rafHackState = 2;
  7135.  
  7136. } else {
  7137. rafHackState = 4;
  7138. }
  7139.  
  7140. }
  7141. // continue;
  7142.  
  7143. doAnimator_ = !USE_ADVANCED_TICKING && !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  7144.  
  7145.  
  7146. const doAnimator = doAnimator_;
  7147.  
  7148. cProto._throwOut = dProto._throwOut;
  7149.  
  7150. cProto._makeAnimator = doAnimator ? dProto._makeAnimator : null;
  7151.  
  7152. cProto._aeFinished = doAnimator ? dProto._aeFinished : null;
  7153.  
  7154.  
  7155. const doRAFHack = rafHackState === 2;
  7156.  
  7157.  
  7158. const doTimerFnModification = !USE_ADVANCED_TICKING && (doRAFHack || doAnimator);
  7159. // doTimerFnModification = false; // M55
  7160.  
  7161. if (doTimerFnModification) { // including memory fix leakage
  7162.  
  7163. if (doAnimator && windowShownAt < 0) {
  7164. windowShownAt = 0;
  7165. setupEventForWindowShownAt();
  7166. }
  7167.  
  7168. cProto.startCountdown = (
  7169. doAnimator ? dProto.startCountdownForTimerFnModA : dProto.startCountdownForTimerFnModT
  7170. );
  7171.  
  7172. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  7173. cProto.updateTimeout = (
  7174. doAnimator ? dProto.updateTimeoutForTimerFnModA : dProto.updateTimeoutForTimerFnModT
  7175. );
  7176.  
  7177.  
  7178. // let ez = 0;
  7179. cProto.isAnimationPausedChanged = (
  7180. doAnimator ? dProto.isAnimationPausedChangedForTimerFnModA : dProto.isAnimationPausedChangedForTimerFnModT
  7181. );
  7182.  
  7183. flgLeakageFixApplied |= 1;
  7184. }
  7185.  
  7186.  
  7187. if (doAnimator) {
  7188.  
  7189.  
  7190. const s = fnIntegrity(cProto.computeContainerStyle);
  7191.  
  7192. if (s === '2.46.29') {
  7193. // f.computeContainerStyle = function(a, b) {
  7194. // if (!a)
  7195. // return $h(kmb);
  7196. // var c = this.colorFromDecimal(a.startBackgroundColor);
  7197. // a = this.colorFromDecimal(a.endBackgroundColor);
  7198. // b = 100 * b + "%";
  7199. // return $h(lmb, c, c, b, a, b, a)
  7200. // }
  7201. } else if (s === '2.44.29' || s === '2.81.31') {
  7202.  
  7203. // var ofb = da([""])
  7204. // pfb = da("background:linear-gradient(90deg, {,{ {,{ {,{);".split("{"))
  7205.  
  7206. // f.computeContainerStyle = function(a, b) {
  7207. // if (!a)
  7208. // return pi(ofb);
  7209. // var c = this.colorFromDecimal(a.startBackgroundColor);
  7210. // a = this.colorFromDecimal(a.endBackgroundColor);
  7211. // b = 100 * b + "%";
  7212. // return pi(pfb, c, c, b, a, b, a)
  7213. // }
  7214.  
  7215. } else {
  7216. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.46.29'));
  7217. }
  7218.  
  7219. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  7220.  
  7221. cProto.computeContainerStyle = dProto.computeContainerStyleForAnimatorEnabled;
  7222.  
  7223. }
  7224.  
  7225. if (doTimerFnModification === true) hasTimerModified = true;
  7226.  
  7227.  
  7228. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  7229. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  7230. }
  7231.  
  7232.  
  7233. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  7234. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  7235. }
  7236. }
  7237.  
  7238. const canDoAdvancedTicking = 1 &&
  7239. typeof cProto.startCountdown === 'function' && !cProto.startCountdown49 && cProto.startCountdown.length === 2 &&
  7240. typeof cProto.updateTimeout === 'function' && !cProto.updateTimeout49 && cProto.updateTimeout.length === 1 &&
  7241. typeof cProto.isAnimationPausedChanged === 'function' && !cProto.isAnimationPausedChanged49 && cProto.isAnimationPausedChanged.length === 2 &&
  7242. typeof cProto.setContainerWidth === 'function' && cProto.setContainerWidth.length === 0 &&
  7243. typeof cProto.slideDown === 'function' && cProto.slideDown.length === 0 &&
  7244. CSS.supports("left","clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)");
  7245.  
  7246.  
  7247. if (USE_ADVANCED_TICKING && canDoAdvancedTicking) {
  7248. // startResistanceUpdater();
  7249. // live replay video -> 48117005 -> 48117006 keep fire. ->48117007 0 -> 48117007 {...}
  7250. // live stream video -> 48117007 0 -> 48117007 YES
  7251.  
  7252. console.log('USE_ADVANCED_TICKING')
  7253.  
  7254. const wio2 = dProto.wio2 || (dProto.wio2 = new IntersectionObserver((mutations) => {
  7255.  
  7256. for (const mutation of mutations) {
  7257. if (mutation.isIntersecting) {
  7258.  
  7259. const marker = mutation.target;
  7260. let endId = marker.id
  7261. if(!endId) continue;
  7262. let tid = endId.substring(0, endId.length -2 );
  7263. if(!tid) continue;
  7264. // let bId = `${tid}-b`;
  7265. const bgElm = document.querySelector(`#${tid}-b`);
  7266. if(!bgElm) continue;
  7267. const overlay = bgElm;
  7268.  
  7269. wio2.unobserve(marker);
  7270. marker.remove();
  7271. let p = overlay || 0;
  7272. let cn = 4;
  7273. while ((p = p.parentElement) instanceof HTMLElement) {
  7274. if (p instanceof HTMLElement) {
  7275. const cnt = insp(p);
  7276. if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1 ) {
  7277.  
  7278. cnt.__advancedTicking038__ = 2;
  7279.  
  7280. let deletionMode = false;
  7281. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7282. if (timestampUnderLiveMode && cntData && cntData.duration > 0 && cntData.__timestampActionRequest__ > 0) {
  7283.  
  7284. const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  7285. // check whether the targetFutureTime is already the past
  7286. if (targetFutureTime + 800 < Date.now()) {
  7287. // just dispose
  7288. deletionMode = true;
  7289. }
  7290. }
  7291.  
  7292. if (deletionMode) {
  7293. __requestRemoval__(cnt);
  7294. } else {
  7295.  
  7296. ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7297. cnt.slideDown());
  7298. }
  7299.  
  7300. break;
  7301. }
  7302. }
  7303. cn--;
  7304. if (!cn) {
  7305. console.log('cnt not found for ticker-bg-overlay');
  7306. break;
  7307. }
  7308. }
  7309.  
  7310.  
  7311. }
  7312. }
  7313.  
  7314. // console.log(mutations);
  7315. },{
  7316.  
  7317. rootMargin: '0px',
  7318. threshold: [1]
  7319.  
  7320. }));
  7321.  
  7322. // const wio = dProto.wio || (dProto.wio = new IntersectionObserver((mutations) => {
  7323.  
  7324. // // for (const mutation of mutations) {
  7325. // // if (mutation.isIntersecting) {
  7326. // // const marker = mutation.target;
  7327. // // const overlay = marker instanceof HTMLElement ? marker.closest('ticker-bg-overlay') : 0;
  7328. // // wio.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.duration > 0 && cntData.__timestampActionRequest__ > 0) {
  7342.  
  7343. // // const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  7344. // // // check whether the targetFutureTime is already the past
  7345. // // if (targetFutureTime + 800 < Date.now()) {
  7346. // // // just dispose
  7347. // // deletionMode = true;
  7348. // // }
  7349. // // }
  7350.  
  7351. // // if (deletionMode) {
  7352. // // __requestRemoval__(cnt);
  7353. // // } else {
  7354.  
  7355. // // ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7356. // // cnt.slideDown());
  7357. // // }
  7358.  
  7359. // // break;
  7360. // // }
  7361. // // }
  7362. // // cn--;
  7363. // // if (!cn) {
  7364. // // console.log('cnt not found for ticker-bg-overlay');
  7365. // // break;
  7366. // // }
  7367. // // }
  7368. // // }
  7369. // // }
  7370. // }, {
  7371. // rootMargin: '1px',
  7372. // threshold: [0]
  7373. // }));
  7374.  
  7375. // cProto._throwOut = dProto._throwOut;
  7376.  
  7377.  
  7378. const u37fn = dProto.u37fn || (dProto.u37fn = function (cnt) {
  7379.  
  7380. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7381. if(!cntData) return;
  7382. const cntElement = cnt.hostElement;
  7383. if(!(cntElement instanceof HTMLElement)) return;
  7384.  
  7385. const duration = (cntData.fullDurationSec || cntData.durationSec || 0);
  7386.  
  7387. let ct;
  7388.  
  7389. if (cntData && duration > 0 && !('__progressAt__' in cntData)) {
  7390. ct = Date.now();
  7391. cntData.__liveTimestamp__ = (cntData.__timestampActionRequest__ || ct) / 1000 - timeOriginDT / 1000;
  7392. timestampUnderLiveMode = true;
  7393. } else if (cntData && duration > 0 && cntData.__progressAt__ > 0) {
  7394. timestampUnderLiveMode = false;
  7395. }
  7396. // console.log(48117007, cntData)
  7397.  
  7398. let tk = cntData.__progressAt__ || cntData.__liveTimestamp__;
  7399.  
  7400. if (!tk) {
  7401. console.log('time property is not found');
  7402. return;
  7403. }
  7404.  
  7405.  
  7406.  
  7407. const liveOffsetMs = ct > 0 && cntData.__timestampActionRequest__ > 0 ? ct - cntData.__timestampActionRequest__ : 0;
  7408.  
  7409. // console.log(1237, liveOffsetMs, cntData.durationSec)
  7410.  
  7411. if (liveOffsetMs > 0) {
  7412. cntData.durationSec -= Math.floor(liveOffsetMs / 1000);
  7413. if (cntData.durationSec < 0) cntData.durationSec = 0;
  7414. // console.log(1238, liveOffsetMs, cntData.durationSec)
  7415. if (!cntData.durationSec) {
  7416. try {
  7417. cnt.requestRemoval();
  7418. } catch (e) { }
  7419. return;
  7420. }
  7421. }
  7422.  
  7423.  
  7424. let offset = cntData.fullDurationSec - cntData.durationSec; // consider this is live replay video, offset can be > 0
  7425. if (offset > 0) tk -= offset;
  7426. // in livestreaming. tk can be negative as we use performance.timeOrigin for t=0s time frame
  7427.  
  7428.  
  7429.  
  7430. const existingOverlaySelector = `ticker-bg-overlay[ticker-id="${cnt.__ticker_attachmentId__}"]`;
  7431.  
  7432. if (valAssign(cntElement, '--ticker-start-time', tk) && duration > 0) {
  7433.  
  7434. // t0 ...... 1 ... fullDurationSec
  7435. // tk ...... k ... fullDurationSec-durationSec
  7436. // t0-fullDurationSec ...... 0 ... 0
  7437.  
  7438. // now - (fullDurationSec-durationSec)
  7439.  
  7440.  
  7441. // update dntElementWeak
  7442. const dnt = cnt.parentComponent;
  7443. const dntElement = dnt ? dnt.hostElement || dnt : 0;
  7444. if (dntElement) {
  7445. dntElementWeak = mWeakRef(dntElement);
  7446. resistanceUpdateBusy = false;
  7447. if (!startResistanceUpdaterStarted) startResistanceUpdater();
  7448. else updateTickerCurrentTime();
  7449. }
  7450.  
  7451. // create overlay if needed
  7452. if (!cntElement.querySelector(existingOverlaySelector)) {
  7453.  
  7454. // remove if any
  7455. const oldElement = cntElement.querySelector('ticker-bg-overlay');
  7456. if (oldElement) oldElement.remove();
  7457. // use advancedTicking, ticker enabled
  7458. cnt.__advancedTicking038__ = 1;
  7459.  
  7460. const em = document.createElement('ticker-bg-overlay');
  7461. // const ey = document.createElement('ticker-bg-overlay-end');
  7462. const wy = document.createElement('ticker-bg-overlay-end2');
  7463.  
  7464. const cr1 = cnt.colorFromDecimal(cntData.startBackgroundColor);
  7465. const cr2 = cnt.colorFromDecimal(cntData.endBackgroundColor);
  7466.  
  7467. const container = cnt.$.container;
  7468. em.setAttribute('ticker-id', `${cnt.__ticker_attachmentId__}`);
  7469.  
  7470. const tid = `ticker-${cnt.__ticker_attachmentId__}-${ Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  7471.  
  7472. em.id = `${tid}-b`;
  7473. em.style.background = `linear-gradient(90deg, ${cr1},${cr1} 50%,${cr2} 50%,${cr2})`;
  7474.  
  7475. if (!(container instanceof HTMLElement)) {
  7476. // em.insertBefore(ey, em.firstChild);
  7477. cntElement.insertBefore(em, cntElement.firstChild);
  7478. cntElement.style.borderRadius = '16px';
  7479. container.style.borderRadius = 'initial';
  7480. } else {
  7481. // em.insertBefore(ey, em.firstChild);
  7482. container.insertBefore(em, container.firstChild);
  7483. }
  7484.  
  7485. // em.style.left = '-50%';
  7486. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  7487.  
  7488. if (container instanceof HTMLElement) {
  7489.  
  7490. container.style.background = 'transparent';
  7491. container.style.backgroundColor = 'transparent';
  7492. // container.style.zIndex = '1';
  7493. }
  7494. // em.style.zIndex = '-1';
  7495. valAssign(cntElement, '--ticker-duration-time', duration)
  7496.  
  7497. valAssign(wy, '--ticker-start-time', tk);
  7498. valAssign(wy, '--ticker-duration-time', duration);
  7499. wy.id = `${tid}-e`;
  7500.  
  7501. dntElement.appendChild(wy);
  7502.  
  7503. // if (wio instanceof IntersectionObserver) {
  7504. // wio.observe(ey);
  7505. // }
  7506.  
  7507. if (wio2 instanceof IntersectionObserver) {
  7508. wio2.observe(wy);
  7509. }
  7510.  
  7511. }
  7512. }
  7513. });
  7514.  
  7515. const timeFn = (cnt)=>{
  7516.  
  7517. if (!cnt) return;
  7518. if (!cnt.hostElement) return;
  7519.  
  7520. const attachementId = cnt.__ticker_attachmentId__;
  7521. if (!attachementId) return;
  7522.  
  7523. Promise.resolve(cnt).then(u37fn);
  7524.  
  7525. }
  7526.  
  7527. cProto.startCountdown = dProto.startCountdownAdv || (dProto.startCountdownAdv = function (a, b) {
  7528.  
  7529. timeFn(kRef(this));
  7530.  
  7531. // try {
  7532. // const cnt = kRef(this);
  7533. // if (!cnt) return;
  7534. // if (!cnt.hostElement) return;
  7535.  
  7536. // const attachementId = cnt.__ticker_attachmentId__;
  7537. // if (!attachementId) return;
  7538.  
  7539. // // a.durationSec [s] => countdownMs [ms]
  7540. // // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  7541. // // lastCountdownTimeMs => raf ongoing
  7542. // // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  7543.  
  7544. // // if (cnt._r782) return;
  7545.  
  7546. // // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7547. // // cnt._throwOut();
  7548. // // return;
  7549. // // }
  7550.  
  7551. // // TimerFnModT
  7552.  
  7553. // // b = void 0 === b ? 0 : b;
  7554. // // void 0 !== a && (cnt.countdownMs = 1E3 * a,
  7555. // // cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs,
  7556. // // // cnt.ratio = 1,
  7557. // // cnt.lastCountdownTimeMs || cnt.isAnimationPaused || (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now(),
  7558. // // cnt.rafId = -1))
  7559.  
  7560. // Promise.resolve(cnt).then((cnt) => {
  7561. // u37fn(cnt);
  7562. // })
  7563.  
  7564. // } catch (e) {
  7565. // console.warn(e);
  7566. // }
  7567.  
  7568.  
  7569. });
  7570.  
  7571. cProto.updateTimeout = dProto.updateTimeoutAdv || (dProto.updateTimeoutAdv = function (a) {
  7572.  
  7573.  
  7574. // timeFn(kRef(this));
  7575.  
  7576. // try {
  7577. // const cnt = kRef(this);
  7578. // if (!cnt) return;
  7579. // if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7580.  
  7581. // const attachementId = cnt.__ticker_attachmentId__;
  7582. // if (!attachementId) return;
  7583.  
  7584. // // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  7585.  
  7586. // // if (cnt._r782) return;
  7587.  
  7588. // // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7589. // // cnt._throwOut();
  7590. // // return;
  7591. // // }
  7592.  
  7593. // // if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  7594. // // cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  7595. // // }
  7596. // // console.log(703, cnt.countdownMs)
  7597. // // cnt.ratio = cnt.countdownMs / cnt.countdownDurationMs;
  7598.  
  7599. // // u37fn(cnt);
  7600. // // cnt.isAttached && cnt.countdownMs ? (cnt.lastCountdownTimeMs = a,
  7601. // // cnt.rafId = -1) : (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  7602. // // cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7603. // // cnt.slideDown()))
  7604.  
  7605.  
  7606. // } catch (e) {
  7607. // console.warn(e);
  7608. // }
  7609.  
  7610. });
  7611.  
  7612. cProto.isAnimationPausedChanged = dProto.isAnimationPausedChangedAdv || (dProto.isAnimationPausedChangedAdv = function (a, b) {
  7613.  
  7614.  
  7615. // timeFn(kRef(this));
  7616.  
  7617. // const cnt = kRef(this);
  7618. // if (!cnt) return;
  7619. // if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7620.  
  7621. // const attachementId = cnt.__ticker_attachmentId__;
  7622. // if (!attachementId) return;
  7623.  
  7624. // if (cnt._r782) return;
  7625.  
  7626. // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7627. // cnt._throwOut();
  7628. // return;
  7629. // }
  7630. // let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  7631. // cnt._forceNoDetlaSincePausedSecs783 = 0;
  7632.  
  7633. // u37fn(cnt);
  7634. // Promise.resolve(cnt).then((cnt) => {
  7635.  
  7636. // if (attachementId !== cnt.__ticker_attachmentId__) return;
  7637.  
  7638. // // a ? 0 : !a && b && (a = cnt.lastCountdownTimeMs || 0,
  7639. // // cnt.detlaSincePausedSecs && (a = (cnt.lastCountdownTimeMs || 0) + 1E3 * cnt.detlaSincePausedSecs,
  7640. // // cnt.detlaSincePausedSecs = 0),
  7641. // // cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now())
  7642.  
  7643. // cnt = null;
  7644.  
  7645. // }).catch(e => {
  7646. // console.log(e);
  7647. // });
  7648.  
  7649.  
  7650. });
  7651.  
  7652. if (typeof cProto.computeContainerStyle === 'function' && !cProto.computeContainerStyle49 && cProto.computeContainerStyle.length === 2) {
  7653. cProto.computeContainerStyle49 = cProto.computeContainerStyle;
  7654. cProto.computeContainerStyle = dProto.computeContainerStyleAdv || (dProto.computeContainerStyleAdv = function (a, b) {
  7655. if (this.__advancedTicking038__) {
  7656. return "";
  7657. }
  7658. return this.computeContainerStyle49(a, b);
  7659. });
  7660. }
  7661.  
  7662. }
  7663.  
  7664.  
  7665.  
  7666. }
  7667.  
  7668. const selector = tags.join(', ');
  7669. const elements = document.querySelectorAll(selector);
  7670. if (elements.length >= 1) {
  7671. for (const elm of elements) {
  7672. if (insp(elm).isAttached === true) {
  7673. fpTicker(elm);
  7674. }
  7675. }
  7676. }
  7677.  
  7678. console.log("[End]");
  7679. console.groupEnd();
  7680.  
  7681.  
  7682. }).catch(console.warn);
  7683.  
  7684. if(FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth){
  7685.  
  7686. /**
  7687. *
  7688. *
  7689. *
  7690. *
  7691. cT.prototype.dataChanged = function() {
  7692. var a = this;
  7693. this.data && (Q(this.hostElement).querySelector("#content").style.color = this.ytLiveChatTickerItemBehavior.colorFromDecimal(this.data.detailTextColor),
  7694. this.hostElement.ariaLabel = this.computeAriaLabel(this.data),
  7695. this.ytLiveChatTickerItemBehavior.startCountdown(this.data.durationSec, this.data.fullDurationSec),
  7696. qw(function() {
  7697. a.ytLiveChatTickerItemBehavior.setContainerWidth()
  7698. }))
  7699. }
  7700.  
  7701.  
  7702. znb.prototype.dataChanged = function(a) {
  7703. var b = this;
  7704. a && (a.tickerThumbnails.length > 1 && Q(this.hostElement).querySelector("#content").classList.add("multiple-thumbnails"),
  7705. this.ytLiveChatTickerItemBehavior.startCountdown(a.durationSec, a.fullDurationSec),
  7706. qw(function() {
  7707. b.ytLiveChatTickerItemBehavior.setContainerWidth()
  7708. }))
  7709. }
  7710.  
  7711. *
  7712. */
  7713.  
  7714. const dProto = {
  7715. dataChanged54500: function () {
  7716. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  7717. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  7718. try {
  7719. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7720. return this.dataChanged544.call(this.__proxySelf0__);
  7721. } catch (e) {
  7722. console.log('dataChanged54500 ERROR');
  7723. console.error(e);
  7724. }
  7725. } else {
  7726. return this.dataChanged544();
  7727. }
  7728. },
  7729. dataChanged54501: function (a) {
  7730. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  7731. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  7732. try {
  7733. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7734. return this.dataChanged544.call(this.__proxySelf0__, a);
  7735. } catch (e) {
  7736. console.log('dataChanged54501 ERROR');
  7737. console.error(e);
  7738. }
  7739. } else {
  7740. return this.dataChanged544(a);
  7741. }
  7742. },
  7743. }
  7744.  
  7745. for (const sto of [
  7746. 'yt-live-chat-ticker-sponsor-item-renderer',
  7747. 'yt-live-chat-ticker-paid-sticker-item-renderer'
  7748. ].map(tag => [tag, customElements.whenDefined(tag)])) {
  7749. const [tag, promise] = sto;
  7750. promise.then(()=>{
  7751. const dummy = document.createElement(tag);
  7752. const cProto = getProto(dummy);
  7753. if (!cProto || !cProto.attached) {
  7754. console.warn(`proto.attached for ${tag} is unavailable.`);
  7755. return;
  7756. }
  7757. if (!cProto.dataChanged || cProto.dataChanged544 || typeof cProto.dataChanged !== 'function' || !(cProto.dataChanged.length >= 0 && cProto.dataChanged.length <= 1)) return;
  7758.  
  7759. cProto.dataChanged544 = cProto.dataChanged;
  7760.  
  7761. if (cProto.dataChanged.length === 0) cProto.dataChanged = dProto.dataChanged54500;
  7762. else if (cProto.dataChanged.length === 1) cProto.dataChanged = dProto.dataChanged54501;
  7763. })
  7764. }
  7765.  
  7766. }
  7767.  
  7768. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  7769.  
  7770. if (FLAG_001d) return;
  7771.  
  7772. mightFirstCheckOnYtInit();
  7773. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  7774. console.log("[Begin]");
  7775. (() => {
  7776.  
  7777. /* pending!!
  7778.  
  7779. handleLiveChatAction
  7780.  
  7781. removeTickerItemById
  7782.  
  7783. _itemsChanged
  7784. itemsChanged
  7785.  
  7786. handleMarkChatItemAsDeletedAction
  7787. handleMarkChatItemsByAuthorAsDeletedAction
  7788. handleRemoveChatItemByAuthorAction
  7789.  
  7790.  
  7791. */
  7792.  
  7793. const tag = "yt-live-chat-ticker-renderer"
  7794. const dummy = document.createElement(tag);
  7795.  
  7796. const cProto = getProto(dummy);
  7797. if (!cProto || !cProto.attached) {
  7798. console.warn(`proto.attached for ${tag} is unavailable.`);
  7799. return;
  7800. }
  7801.  
  7802. const do_amend_ticker_handleLiveChatAction = AMEND_TICKER_handleLiveChatAction && !AMEND_TICKER_handleLiveChatAction_v3
  7803. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && cProto.handleLiveChatAction.length === 1
  7804. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && cProto.handleLiveChatActions.length === 1
  7805. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  7806. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  7807. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  7808. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  7809. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  7810. ;
  7811.  
  7812. console.log('do_amend_ticker_handleLiveChatAction', fnIntegrity(cProto.handleLiveChatAction), fnIntegrity(cProto.handleLiveChatActions))
  7813.  
  7814.  
  7815. if (do_amend_ticker_handleLiveChatAction) {
  7816.  
  7817.  
  7818. if (fnIntegrity(cProto.handleLiveChatActions) === '1.23.12') {
  7819.  
  7820. console.log(`handleLiveChatActions`, 'modified');
  7821.  
  7822. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  7823.  
  7824. cProto.handleLiveChatActions = function (a) {
  7825. /**
  7826. *
  7827. f.handleLiveChatActions = function(a) {
  7828. a.length && (a.forEach(this.handleLiveChatAction, this),
  7829. this.updateHighlightedItem(),
  7830. this.shouldAnimateIn = !0)
  7831. }
  7832. *
  7833. */
  7834. const len = a.length;
  7835. if (len) {
  7836. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  7837.  
  7838. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  7839.  
  7840. // Primarily for the initial batch, this is due to replayBuffer._back.
  7841. const entries = [];
  7842. const entriesI = [];
  7843. for (let i = 0; i < len; i++) {
  7844. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  7845. const timestampUsec = item ? parseInt(getTimestampUsec(item[firstObjectKey(item)]), 10) : 0;
  7846. if (timestampUsec > 0) {
  7847. entriesI.push(i);
  7848. binaryInsert(entries, { e: a[i], timestampUsec }, (a, b) => {
  7849. const diff = a.timestampUsec - b.timestampUsec;
  7850. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  7851. });
  7852. }
  7853. }
  7854. const mLen = entries.length;
  7855. if (mLen >= 2) {
  7856. for (let j = 0; j < mLen; j++) {
  7857. a[entriesI[j]] = entries[j].e;
  7858. }
  7859. }
  7860. entries.length = 0;
  7861. entriesI.length = 0;
  7862. }
  7863. for (const action of a) {
  7864. action.__batchId45__ = batchToken;
  7865. this.handleLiveChatAction(action);
  7866. }
  7867. }
  7868. }
  7869.  
  7870.  
  7871. }
  7872.  
  7873.  
  7874. console.log(`handleLiveChatAction`, 'modified');
  7875.  
  7876. const cacheChatActions = new LimitedSizeSet(16);
  7877.  
  7878. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  7879.  
  7880. cProto.handleLiveChatAction = function (a) {
  7881.  
  7882. const key = firstObjectKey(a);
  7883. if (!key) return;
  7884.  
  7885. const val = a[key];
  7886. let itemKey = '';
  7887. let itemId = '';
  7888. const valItem = val ? val.item : null;
  7889. if (valItem) {
  7890. itemKey = firstObjectKey(valItem);
  7891. if (itemKey) {
  7892. const itemVal = valItem[itemKey];
  7893. itemId = itemVal ? itemVal.id : '';
  7894. if (itemId) {
  7895. const cacheKey = `${key}.${itemKey}::${itemId}`;
  7896. if (key === 'addChatItemAction' && itemId) return; // no need
  7897. if (cacheChatActions.has(cacheKey)) {
  7898. console.log('handleLiveChatAction Repeated Item', cacheKey);
  7899. return;
  7900. } else {
  7901. cacheChatActions.add(cacheKey);
  7902. }
  7903. }
  7904. }
  7905. }
  7906. return this.handleLiveChatAction45(a);
  7907. };
  7908.  
  7909. console.log("AMEND_TICKER_handleLiveChatAction - OK (v2)");
  7910.  
  7911. } else if (0 && do_amend_ticker_handleLiveChatAction
  7912. && '|1.63.48|1.64.48|'.includes(`|${fnIntegrity(cProto.handleLiveChatAction)}|`)
  7913. && fnIntegrity(cProto.handleLiveChatActions) === '1.23.12'
  7914. ) {
  7915.  
  7916. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  7917.  
  7918. cProto.handleLiveChatActions = function (a) {
  7919. /**
  7920. *
  7921. f.handleLiveChatActions = function(a) {
  7922. a.length && (a.forEach(this.handleLiveChatAction, this),
  7923. this.updateHighlightedItem(),
  7924. this.shouldAnimateIn = !0)
  7925. }
  7926. *
  7927. */
  7928.  
  7929. if (a.length) {
  7930. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  7931. const len = a.length;
  7932. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  7933. // Primarily for the initial batch, this is due to replayBuffer._back.
  7934. const entries = [];
  7935. const entriesI = [];
  7936. for (let i = 0; i < len; i++) {
  7937. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  7938. if (item) {
  7939. const itemRendererKey = firstObjectKey(item);
  7940. const itemRenderer = item[itemRendererKey];
  7941. if (itemRenderer) {
  7942. let timestampUsec = getTimestampUsec(itemRenderer);
  7943. if (timestampUsec !== null) {
  7944. timestampUsec = parseInt(timestampUsec, 10);
  7945. if (timestampUsec > 0) {
  7946. entriesI.push(i);
  7947. entries.push({ e: a[i], timestampUsec })
  7948. }
  7949. }
  7950. }
  7951. }
  7952. }
  7953. const mLen = entries.length;
  7954. if (mLen >= 2) {
  7955. entries.sort((a, b) => {
  7956. const diff = a.timestampUsec - b.timestampUsec;
  7957. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  7958. });
  7959. for (let j = 0; j < mLen; j++) {
  7960. const i = entriesI[j];
  7961. a[i] = entries[j].e;
  7962. }
  7963. }
  7964. entries.length = 0;
  7965. entriesI.length = 0;
  7966. }
  7967. for (const action of a) {
  7968. action.__batchId45__ = batchToken;
  7969. this.handleLiveChatAction(action);
  7970. }
  7971. }
  7972. }
  7973.  
  7974. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  7975.  
  7976. cProto._nszlv_ = 0;
  7977. cProto._stackedLCAs_ = null;
  7978. cProto._lastAddItem_ = null;
  7979. cProto._lastAddItemInStack_ = false;
  7980. cProto.handleLiveChatAction = function (a) {
  7981.  
  7982. /**
  7983. *
  7984. *
  7985. f.handleLiveChatAction = function(a) {
  7986. var b = C(a, xO)
  7987. , c = C(a, yO)
  7988. , d = C(a, o1a)
  7989. , e = C(a, p1a);
  7990. a = C(a, A1a);
  7991. b ? this.unshift("items", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : a && this.handleRemoveChatItemByAuthorAction(a)
  7992. }
  7993. *
  7994. */
  7995.  
  7996. // return this.handleLiveChatAction45(a)
  7997. const { addChatItemAction, addLiveChatTickerItemAction, markChatItemAsDeletedAction,
  7998. removeChatItemAction, markChatItemsByAuthorAsDeletedAction, removeChatItemByAuthorAction, __batchId45__ } = a
  7999.  
  8000. if (addChatItemAction) return;
  8001. const d = Date.now();
  8002.  
  8003. if (this._stackedLCAs_ === null) this._stackedLCAs_ = [];
  8004. const stackArr = this._stackedLCAs_;
  8005. let newStackEntry = null;
  8006. if (addLiveChatTickerItemAction) {
  8007. let isDuplicated = false;
  8008.  
  8009. const newItem = addLiveChatTickerItemAction.item;
  8010. const tickerType = firstObjectKey(newItem);
  8011. if (!tickerType) return;
  8012. const tickerItem = newItem[tickerType];
  8013. const tickerId = tickerItem.id;
  8014. if (!tickerId) return;
  8015.  
  8016. if (this._lastAddItem_ && this._lastAddItem_.id === tickerId) {
  8017. let prevTickerItem = null;
  8018. if (this._lastAddItemInStack_) {
  8019. const entry = stackArr[stackArr.length - 1]; // only consider the last entry
  8020. if (entry && entry.action === 'addItem') {
  8021. prevTickerItem = entry.data; // only consider the first item;
  8022. }
  8023. } else {
  8024. prevTickerItem = this.items[0]; // only consider the first item;
  8025. }
  8026. if (prevTickerItem && prevTickerItem[tickerType]) {
  8027. if (prevTickerItem[tickerType].id === tickerId) {
  8028. isDuplicated = true;
  8029. }
  8030. }
  8031. }
  8032. if (!isDuplicated) {
  8033. this._lastAddItem_ = tickerItem;
  8034. this._lastAddItemInStack_ = true;
  8035. // console.log('newItem', newItem)
  8036.  
  8037. const item = newItem;
  8038. const key = firstObjectKey(item);
  8039. if (key) {
  8040. const itemRenderer = item[key] || 0;
  8041. if (itemRenderer.fullDurationSec > 0) {
  8042. itemRenderer.__actionAt__ = d;
  8043. }
  8044. }
  8045.  
  8046. newStackEntry = { action: 'addItem', data: newItem };
  8047.  
  8048. } else {
  8049. console.log('handleLiveChatAction Repeated Item', tickerItem.id, tickerItem); // happen in both live and playback. Reason Unknown.
  8050. return;
  8051. }
  8052.  
  8053. } else {
  8054. markChatItemAsDeletedAction && (newStackEntry = { action: 'mcItemD', data: markChatItemAsDeletedAction });
  8055. removeChatItemAction && (newStackEntry = { action: 'removeItemById', data: removeChatItemAction.targetId });
  8056. markChatItemsByAuthorAsDeletedAction && (newStackEntry = { action: 'mcItemAD', data: markChatItemsByAuthorAsDeletedAction });
  8057. removeChatItemByAuthorAction && (newStackEntry = { action: 'removeItemA', data: removeChatItemByAuthorAction })
  8058. }
  8059.  
  8060.  
  8061. if (!newStackEntry) return;
  8062. stackArr.push(newStackEntry);
  8063.  
  8064.  
  8065. this._nszlv_++;
  8066. if (this._nszlv_ > 1e9) this._nszlv_ = 9;
  8067. const tid = this._nszlv_;
  8068.  
  8069. newStackEntry.__batchId45__ = __batchId45__ || '';
  8070. newStackEntry.dateTime = Date.now();
  8071.  
  8072.  
  8073. foregroundPromiseFn().then(() => {
  8074.  
  8075. if (tid !== this._nszlv_) return;
  8076. const dateNow = Date.now(); // time difference to shift animation start time shall be considered. (pending)
  8077. const stackArr = this._stackedLCAs_.slice(0);
  8078. this._stackedLCAs_.length = 0;
  8079. this._lastAddItemInStack_ = false;
  8080. let lastDateTime = 0;
  8081. let prevBatchId = '';
  8082. const addItems = [];
  8083. // const previousShouldAnimateIn = this.shouldAnimateIn;
  8084.  
  8085. const addItemsFx = () => {
  8086.  
  8087. if (addItems.length >= 1) {
  8088. const eArr = addItems.slice(0);
  8089. addItems.length = 0;
  8090. if (ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME) {
  8091.  
  8092. const arr = []; // size of arr <= size of eArr
  8093. const d = Date.now();
  8094. for (const item of eArr) {
  8095. const key = firstObjectKey(item);
  8096. if (key) {
  8097.  
  8098.  
  8099. const itemRenderer = item[key] || 0;
  8100. const { durationSec, fullDurationSec, __actionAt__ } = itemRenderer;
  8101. if (__actionAt__ > 0 && durationSec > 0 && fullDurationSec > 0) {
  8102.  
  8103.  
  8104. const offset = d - __actionAt__;
  8105. if (offset > 0 && typeof durationSec === 'number' && typeof fullDurationSec === 'number' && fullDurationSec >= durationSec) {
  8106. const adjustedDurationSec = durationSec - Math.floor(offset / 1000);
  8107. if (adjustedDurationSec < durationSec) { // prevent NaN
  8108. // console.log('adjustedDurationSec', adjustedDurationSec);
  8109. if (adjustedDurationSec > 0) {
  8110. // console.log('offset Sec', Math.floor(offset / 1000));
  8111. itemRenderer.durationSec = adjustedDurationSec;
  8112. } else {
  8113. // if adjustedDurationSec equal 0 or invalid
  8114. continue; // skip adding
  8115. }
  8116. }
  8117.  
  8118. }
  8119.  
  8120. }
  8121.  
  8122. if (fullDurationSec > 0 && durationSec < 1) continue; // fallback check
  8123.  
  8124.  
  8125.  
  8126. }
  8127. arr.push(item)
  8128. // arr.unshift(item);
  8129. }
  8130.  
  8131.  
  8132. // console.log(arr.slice(0))
  8133. this.unshift("items", ...arr);
  8134. } else {
  8135. this.unshift("items", ...eArr);
  8136. }
  8137. }
  8138. }
  8139.  
  8140. for (const entry of stackArr) {
  8141.  
  8142. const { action, data, dateTime, __batchId45__ } = entry;
  8143.  
  8144. const finishLastAction = (
  8145. (prevBatchId !== __batchId45__ && prevBatchId)
  8146. || (dateNow - lastDateTime >= 1000 && dateNow - dateTime < 1000)
  8147. );
  8148.  
  8149. const addPrevItems = addItems.length >= 1 && (finishLastAction || action !== 'addItem');
  8150. lastDateTime = dateTime;
  8151. prevBatchId = __batchId45__;
  8152.  
  8153. if (addPrevItems) {
  8154. addItemsFx();
  8155. }
  8156.  
  8157. if (action === 'addItem') addItems.unshift(data);
  8158. else if (action === 'mcItemD') this.handleMarkChatItemAsDeletedAction(data);
  8159. else if (action === 'removeItemById') this.removeTickerItemById(data);
  8160. else if (action === 'mcItemAD') this.handleMarkChatItemsByAuthorAsDeletedAction(data);
  8161. else if (action === 'removeItemA') this.handleRemoveChatItemByAuthorAction(data);
  8162.  
  8163. }
  8164.  
  8165. addItemsFx();
  8166. })
  8167.  
  8168. }
  8169.  
  8170. console.log("AMEND_TICKER_handleLiveChatAction - OK (v1)");
  8171. } else {
  8172. console.log("AMEND_TICKER_handleLiveChatAction - NG");
  8173. }
  8174.  
  8175.  
  8176.  
  8177. const do_amend_ticker_handleLiveChatAction_v3 = AMEND_TICKER_handleLiveChatAction_v3 && !AMEND_TICKER_handleLiveChatAction
  8178. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && cProto.handleLiveChatAction.length === 1
  8179. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && cProto.handleLiveChatActions.length === 1
  8180. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  8181. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  8182. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  8183. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  8184. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  8185. ;
  8186.  
  8187. if (do_amend_ticker_handleLiveChatAction_v3) {
  8188.  
  8189. /*
  8190. f.handleLiveChatActions = function(a) {
  8191. a.length && (a.forEach(this.handleLiveChatAction, this),
  8192. this.updateHighlightedItem(),
  8193. this.shouldAnimateIn = !0)
  8194. }
  8195. */
  8196.  
  8197. /*
  8198.  
  8199. f.handleLiveChatAction = function(a) {
  8200. var b = y(a, PM)
  8201. , c = y(a, QM)
  8202. , d = y(a, OM)
  8203. , e = y(a, Yab);
  8204. a = y(a, ibb);
  8205. 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)
  8206. }
  8207. */
  8208.  
  8209. const arr00 = new Array(1);
  8210. arr00.forEach = () => { };
  8211. arr00.push = (...args) => { return 1 + args.length };
  8212. arr00.pop = () => { };
  8213. arr00.shift = () => { };
  8214. arr00.unshift = () => { };
  8215. arr00.splice = () => [];
  8216. cProto.handleLiveChatActionsArr0 = arr00;
  8217.  
  8218. cProto.handleLiveChatActions58 = cProto.handleLiveChatActions;
  8219. cProto.xGqq4mo = null;
  8220. cProto.xGqq4Flg = 0;
  8221. cProto.xGqq4moPreparePromise = null;
  8222. cProto.xGqq4f = function () {
  8223. if (this.xGqq4Flg === 2) {
  8224. this.xGqq4Flg = 0;
  8225. tickerPE(async () => { // avoid confliction with ticker generation
  8226. await this.xGqq4moPreparePromise; // just in case
  8227. const s = this.handleLiveChatActionsArr0;
  8228. try {
  8229. this.handleLiveChatActions58(s);
  8230. } catch (e) {
  8231. console.warn(e);
  8232. }
  8233. // console.log('xGqq4f done')
  8234. });
  8235.  
  8236. }
  8237. }
  8238. const liveActionQM = new WeakSet();
  8239. let liveActionsLastTickerAction = null;
  8240. const lastTickerActionM = new WeakSet();
  8241. cProto.handleLiveChatActions = function (a) {
  8242. // let promise = null;
  8243. if (a && a.length) {
  8244. /** @type {MutationObserver | null} */
  8245. let mo = this.xGqq4mo;
  8246. // console.log('xGqq4f aaaa')
  8247. const hostElement = this.hostElement;
  8248. if (hostElement instanceof HTMLElement) {
  8249. if (mo === null || (mo instanceof MutationObserver && this.xGqq4p !== hostElement.xGqq4q)) {
  8250. if (mo instanceof MutationObserver) {
  8251. mo.disconnect();
  8252. mo.takeRecords();
  8253. }
  8254. this.xGqq4mo = mo = new MutationObserver(() => {
  8255. this.xGqq4f();
  8256. })
  8257. const moid = `dm-${Date.now()}-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;;
  8258. this.xGqq4p = moid;
  8259. hostElement.xGqq4q = moid;
  8260. mo.observe(hostElement, { subtree: true, childList: true });
  8261. }
  8262. }
  8263. for (const u of a) {
  8264. u && liveActionQM.add(u)
  8265. }
  8266.  
  8267. /** @type {Promise} */
  8268. const pastPromise = this.xGqq4moPreparePromise || null;
  8269. this.xGqq4moPreparePromise = (async () => {
  8270. try {
  8271. await pastPromise; // just in case
  8272. liveActionsLastTickerAction = null;
  8273. a.forEach(this.handleLiveChatAction, this);
  8274. if (liveActionsLastTickerAction) lastTickerActionM.add(liveActionsLastTickerAction)
  8275. } catch (e) { console.warn(e); } // Promise catch can make the promise always resolved
  8276. // now tickerPE can execute
  8277. })();
  8278.  
  8279.  
  8280. // console.log('xGqq4f bbbb')
  8281. // promise = this.handleLiveChatAction_LastPromise;
  8282. // const f = () => {
  8283. // const s = this.handleLiveChatActionsArr0;
  8284. // try {
  8285. // return this.handleLiveChatActions58(s);
  8286. // } catch (e) {
  8287. // console.warn(e);
  8288. // }
  8289. // }
  8290. // if (!promise) {
  8291. // f();
  8292. // } else {
  8293. // promise.then(f);
  8294. // }
  8295. } else {
  8296. return this.handleLiveChatActions58(a);
  8297. }
  8298. }
  8299.  
  8300. // 12:17:05.748 PM
  8301. // 12:17:05.785 v {name: 'addLiveChatTickerItemAction'}
  8302. // 12:17:08.059 QM
  8303. // 12:17:08.068 v {name: 'markChatItemAsDeletedAction'}
  8304. // 12:17:09.123 OM
  8305. // 12:17:09.133 v {name: 'removeChatItemAction'}
  8306. // 12:17:11.566 Yab
  8307. // 12:17:11.574 v {name: 'markChatItemsByAuthorAsDeletedAction'}
  8308. // 12:17:14.272 ibb
  8309. // 12:17:14.282 v {name: 'removeChatItemByAuthorAction'}
  8310.  
  8311. const keyFilter = (a, keySet) => {
  8312. if (typeof (a || 0) === 'object') {
  8313. for (const k of Object.keys(a)) {
  8314. if (keySet.has(k)) {
  8315. return k;
  8316. }
  8317. }
  8318. }
  8319. return null;
  8320. }
  8321.  
  8322. cProto.lcuJB = function () {
  8323. this.ddnB8 = 1;
  8324. let res = new Set();
  8325. const pxy = new Proxy({}, {
  8326. get(target, prop) {
  8327. res.add(prop);
  8328. },
  8329. set(target, prop, value) {
  8330. return true;
  8331. }
  8332. });
  8333. this.handleLiveChatAction(pxy);
  8334. this.ddnB8 = 0;
  8335. return res.size > 0 ? res : null;
  8336. }
  8337.  
  8338. cProto.ddnB8 = 0;
  8339. cProto.handleLiveChatAction58 = cProto.handleLiveChatAction;
  8340. cProto.liveChatActionFilterKeys = null;
  8341. cProto.handleLiveChatActionTM = new LimitedSizeMap(24);
  8342. const tt0 = Date.now() - 100000;
  8343. cProto.handleLiveChatAction = function (a) {
  8344. if (this.ddnB8) return this.handleLiveChatAction58(a);
  8345. const inQM = a && liveActionQM.delete(a); // true if added from handleLiveChatActions
  8346. let keySet = this.liveChatActionFilterKeys;
  8347. if (keySet === null) {
  8348. const keys = this.lcuJB();
  8349. this.liveChatActionFilterKeys = keySet = (keys || false);
  8350. }
  8351. if (!keySet) {
  8352. if (!unexpectedErr) {
  8353. console.error(unexpectedErr = "************************ [YouTube Super Fast Chat] TickerRenderer:handleLiveChatAction keySet not found; ERR 0xF3D0 ************************");
  8354. }
  8355. return this.handleLiveChatAction58(a);
  8356. }
  8357. const key = keyFilter(a, keySet);
  8358. if (!key) {
  8359. return this.handleLiveChatAction58(a); // just by default
  8360. }
  8361.  
  8362. // ------ avoid duplicate items -------
  8363. const item = ((a[key] || 0).item || 0);
  8364. const ifk = item ? firstObjectKey(item) : null;
  8365. const rendererItem = ifk ? item[ifk] : null;
  8366. if (rendererItem && rendererItem.id) {
  8367. const id = rendererItem.id || 0;
  8368. if (typeof id === 'string') {
  8369. const map = this.handleLiveChatActionTM;
  8370. if (map) {
  8371. const mid = `${rendererItem.authorExternalChannelId}::${rendererItem.id}`;
  8372. const prevTime = map.get(mid);
  8373. const now = Date.now() - tt0;
  8374. map.removeSet(mid, now);
  8375. if (prevTime > 0 && now - prevTime < 2400) {
  8376. console.log('handleLiveChatAction Repeated Item OK', rendererItem.id, rendererItem);
  8377. return; // skip
  8378. } else if (prevTime) {
  8379. console.log('handleLiveChatAction Repeated Item NG', mid, now, prevTime, rendererItem.id, rendererItem);
  8380. }
  8381. // map.removeSet(mid, now);
  8382. }
  8383. }
  8384. }
  8385. // ------ avoid duplicate items -------
  8386.  
  8387. if (inQM) {
  8388. liveActionsLastTickerAction = a;
  8389. }
  8390. this.handleLiveChatAction_LastPromise = tickerPE(async () => {
  8391. await this.xGqq4moPreparePromise; // avoid tickerPE is called before actions under looping in handleLiveChatActions
  8392. const inLQM = lastTickerActionM.delete(a); // multiple candidates
  8393. if (inLQM) this.xGqq4Flg = 2; // 2 to 2 in case two batches are added "in the same time"
  8394. this.handleLiveChatAction58(a);
  8395. // if (inLQM) await timelineResolve(); // timing split by marco event to make tickers generation in different 16ms frame
  8396. // else await Promise.resolve();
  8397. // await Promise.resolve();
  8398. await timelineResolve(); // timing split by marco event to make tickers generation in different 16ms frame
  8399. });
  8400. }
  8401.  
  8402. }
  8403.  
  8404. if (RAF_FIX_keepScrollClamped) {
  8405.  
  8406. // to be improved
  8407.  
  8408. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  8409.  
  8410. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  8411. cProto.keepScrollClamped = function () {
  8412.  
  8413. const cnt = kRef(this);
  8414. if (!cnt) return;
  8415. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8416.  
  8417. cnt._bound_keepScrollClamped = cnt._bound_keepScrollClamped || cnt.keepScrollClamped.bind(mWeakRef(cnt));
  8418. cnt.scrollClampRaf = requestAnimationFrame(cnt._bound_keepScrollClamped);
  8419. cnt.maybeClampScroll()
  8420. }
  8421.  
  8422. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  8423. } else {
  8424.  
  8425. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  8426. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  8427. }
  8428.  
  8429. }
  8430.  
  8431.  
  8432. 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) {
  8433. // to be replaced by animator
  8434.  
  8435. cProto.startScrolling = function (a) {
  8436.  
  8437. const cnt = kRef(this);
  8438. if (!cnt) return;
  8439. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8440.  
  8441. cnt.scrollStopHandle && cnt.cancelAsync(cnt.scrollStopHandle);
  8442. cnt.asyncHandle && cancelAnimationFrame(cnt.asyncHandle);
  8443. cnt.lastFrameTimestamp = cnt.scrollStartTime = performance.now();
  8444. cnt.scrollRatePixelsPerSecond = a;
  8445. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8446. cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally)
  8447. };
  8448.  
  8449. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  8450.  
  8451. /**
  8452. *
  8453. * // 2024.12.17
  8454. * // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  8455.  
  8456. f.startScrolling = function(a) {
  8457. this.scrollStopHandle && $u(this.scrollStopHandle);
  8458. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  8459. this.scrollStartTime = performance.now();
  8460. this.lastFrameTimestamp = performance.now();
  8461. this.scrollRatePixelsPerSecond = a;
  8462. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  8463. }
  8464. ;
  8465. f.scrollIncrementally = function(a) {
  8466. var b = a - (this.lastFrameTimestamp || 0);
  8467. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  8468. this.maybeClampScroll();
  8469. this.updateArrows();
  8470. this.lastFrameTimestamp = a;
  8471. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft > 0 || this.scrollRatePixelsPerSecond && this.scrollRatePixelsPerSecond > 0 ? this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this)) : this.stopScrolling()
  8472. }
  8473. ;
  8474. *
  8475. */
  8476.  
  8477. cProto.__getTickerBarQuery__ = function () {
  8478. const tickerBarQuery = this.tickerBarQuery === '#items' ? this.$.items : this.hostElement.querySelector(this.tickerBarQuery);
  8479. return tickerBarQuery;
  8480. }
  8481.  
  8482. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  8483.  
  8484. const cnt = kRef(this);
  8485. if (!cnt) return;
  8486. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8487.  
  8488. const b = a - (cnt.lastFrameTimestamp || 0);
  8489. const rate = cnt.scrollRatePixelsPerSecond
  8490. const q = b / 1E3 * (rate || 0);
  8491.  
  8492. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8493. const sl = tickerBarQuery.scrollLeft;
  8494. // console.log(rate, sl, q)
  8495. if (cnt.lastFrameTimestamp == cnt.scrollStartTime) {
  8496.  
  8497. } else if (q > -1e-5 && q < 1e-5) {
  8498.  
  8499. } else {
  8500. let cond1 = sl > 0 && rate > 0 && q > 0;
  8501. let cond2 = sl > 0 && rate < 0 && q < 0;
  8502. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  8503. if (cond1 || cond2 || cond3) {
  8504. tickerBarQuery.scrollLeft += q;
  8505. cnt.maybeClampScroll();
  8506. cnt.updateArrows();
  8507. }
  8508. }
  8509.  
  8510. cnt.lastFrameTimestamp = a;
  8511. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8512. 0 < tickerBarQuery.scrollLeft || rate && 0 < rate ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8513. } : function (a) {
  8514.  
  8515. const cnt = kRef(this);
  8516. if (!cnt) return;
  8517. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8518.  
  8519. const b = a - (cnt.lastFrameTimestamp || 0);
  8520. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8521. tickerBarQuery.scrollLeft += b / 1E3 * (cnt.scrollRatePixelsPerSecond || 0);
  8522. cnt.maybeClampScroll();
  8523. cnt.updateArrows();
  8524. cnt.lastFrameTimestamp = a;
  8525. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8526. 0 < tickerBarQuery.scrollLeft || cnt.scrollRatePixelsPerSecond && 0 < cnt.scrollRatePixelsPerSecond ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8527. };
  8528.  
  8529. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  8530. } else {
  8531. assertor(() => fnIntegrity(cProto.startScrolling, '1.44.31'));
  8532. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.78.45'));
  8533. console.log('cProto.startScrolling', cProto.startScrolling);
  8534. console.log('cProto.scrollIncrementally', cProto.scrollIncrementally);
  8535. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  8536. }
  8537.  
  8538.  
  8539. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  8540.  
  8541. cProto.attached37 = cProto.attached;
  8542. cProto.detached37 = cProto.detached;
  8543.  
  8544. let naohzId = 0;
  8545. cProto.__naohzId__ = 0;
  8546. cProto.attached = function () {
  8547. Promise.resolve(this).then((cnt) => {
  8548.  
  8549. const hostElement = cnt.hostElement || cnt;
  8550. if (!(hostElement instanceof HTMLElement)) return;
  8551. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  8552. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  8553. // or #chat-messages
  8554. if (!ironPage) return;
  8555.  
  8556. if (cnt.__naohzId__) removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8557. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  8558. cnt.__naohzId__ = ++naohzId;
  8559. ironPage.setAttribute('naohz', `${+cnt.__naohzId__}`);
  8560.  
  8561. addEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8562. cnt = null;
  8563.  
  8564. });
  8565. return this.attached37.apply(this, arguments);
  8566. };
  8567. cProto.detached = function () {
  8568. Promise.resolve(this).then((cnt) => {
  8569.  
  8570. const ironPage = document.querySelector(`iron-pages[naohz="${+cnt.__naohzId__}"]`);
  8571. if (!ironPage) return;
  8572.  
  8573. removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8574.  
  8575. cnt = null;
  8576.  
  8577. });
  8578. return this.detached37.apply(this, arguments);
  8579. };
  8580.  
  8581. const clickFade = (u) => {
  8582. u.click();
  8583. };
  8584. cProto.messageBoxClickHandlerForFade = async (evt) => {
  8585.  
  8586. const target = (evt || 0).target || 0;
  8587. if (!target) return;
  8588.  
  8589. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  8590. const is = p.is;
  8591. if (typeof is === 'string' && is) {
  8592.  
  8593. if (is === 'yt-live-chat-pinned-message-renderer') {
  8594. return;
  8595. }
  8596. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  8597. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  8598. if (fade) {
  8599. Promise.resolve(fade).then(clickFade);
  8600. evt && evt.stopPropagation();
  8601. }
  8602. return;
  8603. }
  8604. if (is !== 'yt-live-chat-ticker-renderer') {
  8605. if (is.startsWith('yt-live-chat-ticker-')) return;
  8606. if (!is.endsWith('-renderer')) return;
  8607. }
  8608.  
  8609. } else {
  8610. if ((p.nodeName || '').includes('BUTTON')) return;
  8611. }
  8612.  
  8613. }
  8614. };
  8615.  
  8616. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  8617.  
  8618. } else {
  8619. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  8620. }
  8621.  
  8622.  
  8623. })();
  8624.  
  8625. console.log("[End]");
  8626.  
  8627. console.groupEnd();
  8628.  
  8629. }).catch(console.warn);
  8630.  
  8631.  
  8632.  
  8633. if (ENABLE_RAF_HACK_INPUT_RENDERER || DELAY_FOCUSEDCHANGED) {
  8634.  
  8635. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  8636.  
  8637. mightFirstCheckOnYtInit();
  8638. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  8639. console.log("[Begin]");
  8640. (() => {
  8641.  
  8642.  
  8643.  
  8644. const tag = "yt-live-chat-message-input-renderer"
  8645. const dummy = document.createElement(tag);
  8646.  
  8647. const cProto = getProto(dummy);
  8648. if (!cProto || !cProto.attached) {
  8649. console.warn(`proto.attached for ${tag} is unavailable.`);
  8650. return;
  8651. }
  8652.  
  8653.  
  8654. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  8655.  
  8656. let doHack = false;
  8657. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  8658.  
  8659. // not cancellable
  8660.  
  8661. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  8662.  
  8663. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  8664.  
  8665. if (!doHack) console.log('doHack = false')
  8666.  
  8667. }
  8668. // doHack = false; // M55
  8669.  
  8670. if (doHack) {
  8671.  
  8672. cProto.handleTimeout = function (a) {
  8673.  
  8674. const cnt = kRef(this);
  8675. if (!cnt) return;
  8676. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8677.  
  8678. console.log('cProto.handleTimeout', tag)
  8679. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  8680. cnt.timeoutDurationMs = cnt.timeoutMs = a;
  8681. cnt.countdownRatio = 1;
  8682. 0 === cnt.lastTimeoutTimeMs && rafHub.request(cnt.boundUpdateTimeout38_)
  8683. };
  8684. cProto.updateTimeout = function (a) {
  8685.  
  8686. const cnt = kRef(this);
  8687. if (!cnt) return;
  8688. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8689.  
  8690. console.log('cProto.updateTimeout', tag)
  8691. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  8692. cnt.lastTimeoutTimeMs && (cnt.timeoutMs = Math.max(0, cnt.timeoutMs - (a - cnt.lastTimeoutTimeMs)),
  8693. cnt.countdownRatio = cnt.timeoutMs / cnt.timeoutDurationMs);
  8694. cnt.isAttached && cnt.timeoutMs ? (cnt.lastTimeoutTimeMs = a,
  8695. rafHub.request(cnt.boundUpdateTimeout38_)) : cnt.lastTimeoutTimeMs = 0
  8696. };
  8697.  
  8698. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  8699. } else {
  8700.  
  8701. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  8702. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  8703.  
  8704. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  8705. }
  8706.  
  8707.  
  8708. }
  8709.  
  8710. if (DELAY_FOCUSEDCHANGED && typeof cProto.onFocusedChanged === 'function' && cProto.onFocusedChanged.length === 1 && !cProto.onFocusedChanged372) {
  8711. cProto.onFocusedChanged372 = cProto.onFocusedChanged;
  8712. cProto.onFocusedChanged = function (a) {
  8713. Promise.resolve(this).then((cnt) => {
  8714. if (cnt.isAttached === true) cnt.onFocusedChanged372(a);
  8715. cnt = null;
  8716. }).catch(console.warn);
  8717. }
  8718. }
  8719.  
  8720. })();
  8721.  
  8722. console.log("[End]");
  8723.  
  8724. console.groupEnd();
  8725.  
  8726.  
  8727. })
  8728.  
  8729. }
  8730.  
  8731.  
  8732. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  8733.  
  8734. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  8735.  
  8736. mightFirstCheckOnYtInit();
  8737. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  8738. console.log("[Begin]");
  8739. (() => {
  8740.  
  8741. const tag = "yt-emoji-picker-renderer"
  8742. const dummy = document.createElement(tag);
  8743.  
  8744. const cProto = getProto(dummy);
  8745. if (!cProto || !cProto.attached) {
  8746. console.warn(`proto.attached for ${tag} is unavailable.`);
  8747. return;
  8748. }
  8749.  
  8750. let doHack = false;
  8751. if (typeof cProto.animateScroll_ === 'function') {
  8752.  
  8753. // not cancellable
  8754. console.log('animateScroll_', typeof cProto.animateScroll_)
  8755.  
  8756. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  8757.  
  8758. }
  8759.  
  8760. if (doHack) {
  8761.  
  8762. const querySelector = HTMLElement.prototype.querySelector;
  8763. const U = (element) => ({
  8764. querySelector: (selector) => querySelector.call(element, selector)
  8765. });
  8766.  
  8767. cProto.animateScroll_ = function (a) {
  8768.  
  8769. const cnt = kRef(this);
  8770. if (!cnt) return;
  8771. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8772.  
  8773. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  8774. if (!cnt.boundAnimateScroll39_) cnt.boundAnimateScroll39_ = cnt.animateScroll_.bind(mWeakRef(cnt));
  8775. cnt.lastAnimationTime_ || (cnt.lastAnimationTime_ = a);
  8776. a -= cnt.lastAnimationTime_;
  8777. 200 > a ? (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationStart_ + (cnt.animationEnd_ - cnt.animationStart_) * a / 200,
  8778. rafHub.request(cnt.boundAnimateScroll39_)) : (null != cnt.animationEnd_ && (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationEnd_),
  8779. cnt.animationEnd_ = cnt.animationStart_ = null,
  8780. cnt.lastAnimationTime_ = 0);
  8781. cnt.updateButtons_()
  8782. }
  8783.  
  8784. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  8785. } else {
  8786.  
  8787. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  8788. }
  8789.  
  8790. })();
  8791.  
  8792. console.log("[End]");
  8793.  
  8794. console.groupEnd();
  8795. });
  8796. }
  8797.  
  8798. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  8799.  
  8800. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  8801.  
  8802. mightFirstCheckOnYtInit();
  8803. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  8804. console.log("[Begin]");
  8805. (() => {
  8806.  
  8807. const tag = "yt-live-chat-docked-message"
  8808. const dummy = document.createElement(tag);
  8809.  
  8810. const cProto = getProto(dummy);
  8811. if (!cProto || !cProto.attached) {
  8812. console.warn(`proto.attached for ${tag} is unavailable.`);
  8813. return;
  8814. }
  8815.  
  8816. let doHack = false;
  8817. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  8818.  
  8819. // cancelable - this.intersectRAF <detached>
  8820. // yt-live-chat-docked-message
  8821. // boundCheckIntersections <-> checkIntersections
  8822. // onDockableMessagesChanged
  8823. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  8824.  
  8825. console.log('detached', typeof cProto.detached)
  8826. console.log('checkIntersections', typeof cProto.checkIntersections)
  8827. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  8828.  
  8829. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  8830.  
  8831. }
  8832.  
  8833. if (doHack) {
  8834.  
  8835. cProto.__boundCheckIntersectionsSubstitutionFn__ = function () {
  8836. const cnt = this;
  8837. if (!cnt.i5zmk && typeof cnt.boundCheckIntersections === 'function' && typeof cnt.checkIntersections === 'function') {
  8838. cnt.i5zmk = 1
  8839. cnt.boundCheckIntersections = cnt.checkIntersections.bind(mWeakRef(cnt));
  8840. }
  8841. }
  8842.  
  8843. cProto.checkIntersections = function () {
  8844.  
  8845. const cnt = kRef(this);
  8846. if (!cnt) return;
  8847. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8848.  
  8849. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  8850.  
  8851. // console.log('cProto.checkIntersections', tag)
  8852. if (cnt.dockableMessages.length) {
  8853. cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections);
  8854. let a = cnt.dockableMessages[0]
  8855. , b = cnt.hostElement.getBoundingClientRect();
  8856. a = a.getBoundingClientRect();
  8857. let c = a.top - b.top
  8858. , d = 8 >= c;
  8859. c = 8 >= c - cnt.hostElement.clientHeight;
  8860. if (d) {
  8861. let e;
  8862. for (; d;) {
  8863. e = cnt.dockableMessages.shift();
  8864. d = cnt.dockableMessages[0];
  8865. if (!d)
  8866. break;
  8867. d = d.getBoundingClientRect();
  8868. c = d.top - b.top;
  8869. let f = 8 >= c;
  8870. if (8 >= c - a.height)
  8871. if (f)
  8872. a = d;
  8873. else
  8874. return;
  8875. d = f
  8876. }
  8877. cnt.dock(e)
  8878. } else
  8879. c && cnt.dockedItem && cnt.clear()
  8880. } else
  8881. cnt.intersectRAF = 0
  8882. }
  8883.  
  8884. cProto.onDockableMessagesChanged = function () {
  8885. const cnt = this;
  8886. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  8887. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  8888. cnt.dockableMessages.length && !cnt.intersectRAF && (cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections))
  8889. }
  8890.  
  8891. cProto.detached = function () {
  8892. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  8893. }
  8894.  
  8895. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  8896. } else {
  8897.  
  8898. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  8899. }
  8900.  
  8901. })();
  8902.  
  8903. console.log("[End]");
  8904.  
  8905. console.groupEnd();
  8906.  
  8907. }).catch(console.warn);
  8908.  
  8909. }
  8910.  
  8911. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  8912.  
  8913. customElements.whenDefined("yt-img-shadow").then(() => {
  8914.  
  8915. mightFirstCheckOnYtInit();
  8916. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  8917. console.log("[Begin]");
  8918. (() => {
  8919.  
  8920. const tag = "yt-img-shadow"
  8921. const dummy = document.createElement(tag);
  8922.  
  8923. const cProto = getProto(dummy);
  8924. if (!cProto || !cProto.attached) {
  8925. console.warn(`proto.attached for ${tag} is unavailable.`);
  8926. return;
  8927. }
  8928.  
  8929. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  8930.  
  8931. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  8932. cProto.thumbnailChanged_ = function (a) {
  8933.  
  8934. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  8935. if (!this.oldThumbnail_ && !this.thumbnail) return;
  8936.  
  8937. return this.thumbnailChanged66_.apply(this, arguments)
  8938.  
  8939. }
  8940. console.log("cProto.thumbnailChanged_ - OK");
  8941.  
  8942. } else {
  8943. console.log("cProto.thumbnailChanged_ - NG");
  8944.  
  8945. }
  8946. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  8947.  
  8948. cProto.setSrc66_ = cProto.setSrc_;
  8949. cProto.setSrc_ = function (a) {
  8950. if ((((this || 0).$ || 0).img || 0).src === a) return;
  8951. return this.setSrc66_.apply(this, arguments)
  8952. }
  8953.  
  8954. console.log("cProto.setSrc_ - OK");
  8955. } else {
  8956.  
  8957. console.log("cProto.setSrc_ - NG");
  8958. }
  8959.  
  8960. })();
  8961.  
  8962. console.log("[End]");
  8963.  
  8964. console.groupEnd();
  8965.  
  8966. }).catch(console.warn);
  8967.  
  8968. }
  8969.  
  8970. if (FIX_THUMBNAIL_DATACHANGED) {
  8971.  
  8972. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  8973.  
  8974. mightFirstCheckOnYtInit();
  8975. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  8976. console.log("[Begin]");
  8977. (() => {
  8978.  
  8979. const tag = "yt-live-chat-author-badge-renderer"
  8980. const dummy = document.createElement(tag);
  8981.  
  8982. const cProto = getProto(dummy);
  8983. if (!cProto || !cProto.attached) {
  8984. console.warn(`proto.attached for ${tag} is unavailable.`);
  8985. return;
  8986. }
  8987.  
  8988. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|0.169.106|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  8989.  
  8990. cProto.dataChanged86 = cProto.dataChanged;
  8991. cProto.dataChanged = function () {
  8992.  
  8993. /* 2024.12.15 */
  8994. /*
  8995. zO.prototype.dataChanged = function() {
  8996. for (var a = Ov(R(this.hostElement).querySelector("#image")); a.firstChild; )
  8997. a.removeChild(a.firstChild);
  8998. if (this.data)
  8999. if (this.data.icon) {
  9000. var b = document.createElement("yt-icon");
  9001. this.data.icon.iconType === "MODERATOR" && this.enableNewModeratorBadge ? (b.polymerController.icon = "yt-sys-icons:shield-filled",
  9002. b.polymerController.defaultToFilled = !0) : b.polymerController.icon = "live-chat-badges:" + this.data.icon.iconType.toLowerCase();
  9003. a.appendChild(b)
  9004. } else if (this.data.customThumbnail) {
  9005. b = document.createElement("img");
  9006. var c;
  9007. (c = (c = UA(this.data.customThumbnail.thumbnails, 16)) ? Yb(kc(c)) : null) ? (b.src = c,
  9008. a.appendChild(b),
  9009. b.setAttribute("alt", this.hostElement.ariaLabel || "")) : Fq(new Zn("Could not compute URL for thumbnail",this.data.customThumbnail))
  9010. }
  9011. }
  9012. */
  9013.  
  9014. const a = (this || 0).data;
  9015. const image = ((this || 0).$ || 0).image;
  9016. if (image && a && image.firstElementChild) {
  9017. const exisiting = image.firstElementChild;
  9018. if (exisiting === image.lastElementChild) {
  9019.  
  9020. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9021.  
  9022. const c = exisiting;
  9023. const t = insp(c);
  9024. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9025. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9026. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9027. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9028. } else {
  9029. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9030. if (w.icon !== p) w.icon = p;
  9031. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9032. }
  9033. return;
  9034.  
  9035.  
  9036. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9037.  
  9038. const c = exisiting;
  9039. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9040.  
  9041. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9042. return;
  9043. }
  9044. /*
  9045.  
  9046. var d;
  9047. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9048.  
  9049. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9050. */
  9051. }
  9052.  
  9053. }
  9054. }
  9055. return this.dataChanged86.apply(this, arguments)
  9056.  
  9057. }
  9058. console.log("cProto.dataChanged - OK");
  9059.  
  9060. } else if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|1.163.100|1.162.100|1.160.97|1.159.97|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9061.  
  9062. cProto.dataChanged86 = cProto.dataChanged;
  9063. cProto.dataChanged = function (a) {
  9064.  
  9065. /*
  9066.  
  9067. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  9068. b.removeChild(b.firstChild);
  9069. if (a)
  9070. if (a.icon) {
  9071. var c = document.createElement("yt-icon");
  9072. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  9073. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9074. b.appendChild(c)
  9075. } else if (a.customThumbnail) {
  9076. c = document.createElement("img");
  9077. var d;
  9078. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9079. b.appendChild(c),
  9080. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  9081. }
  9082.  
  9083. */
  9084.  
  9085.  
  9086. /* 2024.04.20 */
  9087. /*
  9088. for (var b = Tx(N(this.hostElement).querySelector("#image")); b.firstChild; )
  9089. b.removeChild(b.firstChild);
  9090. if (a)
  9091. if (a.icon) {
  9092. var c = document.createElement("yt-icon");
  9093. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.polymerController.icon = "yt-sys-icons:shield-filled",
  9094. c.polymerController.defaultToFilled = !0) : c.polymerController.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9095. b.appendChild(c)
  9096. } else if (a.customThumbnail) {
  9097. c = document.createElement("img");
  9098. var d;
  9099. (d = (d = WD(a.customThumbnail.thumbnails, 16)) ? Sb(ec(d)) : null) ? (c.src = d,
  9100. b.appendChild(c),
  9101. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : nr(new mn("Could not compute URL for thumbnail",a.customThumbnail))
  9102. }
  9103. */
  9104.  
  9105. const image = ((this || 0).$ || 0).image
  9106. if (image && a && image.firstElementChild) {
  9107. const exisiting = image.firstElementChild;
  9108. if (exisiting === image.lastElementChild) {
  9109.  
  9110. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9111.  
  9112. const c = exisiting;
  9113. const t = insp(c);
  9114. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9115. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9116. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9117. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9118. } else {
  9119. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9120. if (w.icon !== p) w.icon = p;
  9121. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9122. }
  9123. return;
  9124.  
  9125.  
  9126. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9127.  
  9128. const c = exisiting;
  9129. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9130.  
  9131. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9132. return;
  9133. }
  9134. /*
  9135.  
  9136. var d;
  9137. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9138.  
  9139. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9140. */
  9141. }
  9142.  
  9143. }
  9144. }
  9145. return this.dataChanged86.apply(this, arguments)
  9146.  
  9147. }
  9148. console.log("cProto.dataChanged - OK");
  9149.  
  9150. } else {
  9151. assertor(() => fnIntegrity(cProto.dataChanged, '0.169.106'));
  9152. console.log("cProto.dataChanged - NG");
  9153.  
  9154. }
  9155.  
  9156. })();
  9157.  
  9158. console.log("[End]");
  9159.  
  9160. console.groupEnd();
  9161.  
  9162. }).catch(console.warn);
  9163.  
  9164.  
  9165. }
  9166.  
  9167.  
  9168.  
  9169. if(USE_ADVANCED_TICKING){
  9170.  
  9171.  
  9172. customElements.whenDefined("yt-live-chat-renderer").then(() => {
  9173.  
  9174. const tag = "yt-live-chat-renderer"
  9175. const dummy = document.createElement(tag);
  9176.  
  9177.  
  9178. const cProto = getProto(dummy);
  9179.  
  9180. dummy.usePatchedLifecycles = false;
  9181. dummy.data = null;
  9182. dummy.__data = null;
  9183. Object.setPrototypeOf(dummy, Object.prototype);
  9184. if (!cProto || !cProto.attached) {
  9185. console.warn(`proto.attached for ${tag} is unavailable.`);
  9186. return;
  9187. }
  9188.  
  9189. /*
  9190. <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;
  9191. */
  9192.  
  9193. if (cProto && typeof cProto.immediatelyApplyLiveChatActions === 'function' && cProto.immediatelyApplyLiveChatActions.length === 1 && !cProto.immediatelyApplyLiveChatActions82) {
  9194. cProto.immediatelyApplyLiveChatActions82 = cProto.immediatelyApplyLiveChatActions;
  9195. cProto.immediatelyApplyLiveChatActions = function(arr){
  9196.  
  9197. try{
  9198. preprocessChatLiveActions(arr);
  9199.  
  9200. }catch(e){
  9201. console.warn(e);
  9202. }
  9203. return this.immediatelyApplyLiveChatActions82(arr);
  9204. };
  9205. }
  9206.  
  9207.  
  9208. if (cProto && typeof cProto.preprocessActions_ === 'function' && cProto.preprocessActions_.length === 1 && !cProto.preprocessActions82_) {
  9209. cProto.preprocessActions82_ = cProto.preprocessActions_;
  9210. cProto.preprocessActions_ = function(arr){
  9211. arr = this.preprocessActions82_(arr);
  9212. preprocessChatLiveActions(arr);
  9213. return arr;
  9214. };
  9215. }
  9216.  
  9217.  
  9218. });
  9219. }
  9220.  
  9221.  
  9222. if (FIX_TOOLTIP_DISPLAY) {
  9223.  
  9224. // ----------------------------------------------------------------------------------------------------
  9225.  
  9226. const checkPDGet = (pd) => {
  9227. return pd && pd.get && !pd.set && pd.enumerable && pd.configurable;
  9228. }
  9229.  
  9230. const tooltipUIWM = new WeakMap();
  9231. const tooltipInitProps = {};
  9232. const createTooltipIfRequired_ = function () {
  9233. let r;
  9234. if (tooltipUIWM.get(this) === void 0) {
  9235. const w = document.createElement;
  9236. let EU = null;
  9237. tooltipUIWM.set(this, null);
  9238. document.createElement = function () {
  9239. let r = w.apply(this, arguments);
  9240. EU = r;
  9241. return r;
  9242. };
  9243. r = this.createTooltipIfRequired14_();
  9244. document.createElement = w;
  9245. if (EU instanceof HTMLElement && EU.is) {
  9246. tooltipUIWM.set(this, EU);
  9247. EU.setAttribute('__nogc__', ''); // avoid gc process script
  9248.  
  9249. if (typeof EU.offset === 'number') tooltipInitProps['offset'] = EU.offset;
  9250. if (typeof EU.fitToVisibleBounds === 'boolean') tooltipInitProps['fitToVisibleBounds'] = EU.fitToVisibleBounds;
  9251. if (typeof EU.position === 'string') tooltipInitProps['position'] = EU.position;
  9252. if (typeof EU.for === 'string') tooltipInitProps['for'] = EU.for;
  9253.  
  9254. // this.__mcT__ = EU.outerHTML;
  9255. // EU.__dataX = JSON.stringify(EU.__data);
  9256. // EU.__dataY = Object.entries(EU);
  9257.  
  9258. // <<< FOR DEBUG >>>
  9259. // let kx;
  9260. // Object.defineProperty(EU, '_target', {
  9261. // get(){
  9262. // return kx;
  9263. // },
  9264. // set(nv){
  9265. // kx= nv;
  9266. // debugger;
  9267. // return true;
  9268. // }
  9269. // });
  9270. // <<< FOR DEBUG >>>
  9271.  
  9272. if (typeof Polymer !== 'undefined' && Polymer.__fixedGetOwnerRoot__ && Polymer.__fixedQuerySelector__) {
  9273.  
  9274. } else {
  9275. let eProto = null;
  9276. const euCnt = insp(EU);
  9277. if (checkPDGet(Object.getOwnPropertyDescriptor(euCnt.constructor.prototype || {}, 'target'))) {
  9278.  
  9279. eProto = euCnt.constructor.prototype;
  9280. } else if (checkPDGet(Object.getOwnPropertyDescriptor(EU.constructor.prototype || {}, 'target'))) {
  9281.  
  9282. eProto = EU.constructor.prototype;
  9283. }
  9284. if (eProto) {
  9285. delete eProto.target;
  9286. /*
  9287.  
  9288. get target() {
  9289. var a = Pv(this).parentNode, b = Pv(this).getOwnerRoot(), c;
  9290. this.for ? c = Pv(b).querySelector("#" + this.for) : c = a.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? b.host : a;
  9291. return c
  9292. },
  9293. */
  9294. Object.defineProperty(eProto, 'target', {
  9295. get() {
  9296. let a = this.parentNode, b = this.getRootNode();
  9297. return (this.for ? b.querySelector("#" + this.for) : a)
  9298. }
  9299. })
  9300. }
  9301. }
  9302. // setInterval(()=>EU.updatePosition(), 100)
  9303.  
  9304. } else {
  9305. tooltipUIWM.set(this, null);
  9306. }
  9307. } else {
  9308. r = this.createTooltipIfRequired14_();
  9309. }
  9310.  
  9311. const EU = tooltipUIWM.get(this);
  9312. if (EU) {
  9313. EU.remove();
  9314. if (typeof tooltipInitProps.offset === 'number') EU['offset'] = tooltipInitProps.offset;
  9315. if (typeof tooltipInitProps.fitToVisibleBounds === 'boolean') EU['fitToVisibleBounds'] = tooltipInitProps.fitToVisibleBounds;
  9316. try {
  9317. if (typeof tooltipInitProps.position === 'string') EU['position'] = tooltipInitProps.position;
  9318. if (typeof tooltipInitProps.for === 'string') EU['for'] = tooltipInitProps.for; else delete EU.for;
  9319. } catch (e) { }
  9320. }
  9321. return r;
  9322. };
  9323.  
  9324.  
  9325. // added in 2024.05.02
  9326. getLCRDummy().then(async (lcrDummy) => {
  9327.  
  9328. // console.log(8171, 99);
  9329. const tag = "yt-live-chat-renderer"
  9330. const dummy = lcrDummy;
  9331.  
  9332. const cProto = getProto(dummy);
  9333. if (!cProto || !cProto.attached) {
  9334. console.warn(`proto.attached for ${tag} is unavailable.`);
  9335. return;
  9336. }
  9337.  
  9338. /*
  9339. <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;
  9340. */
  9341.  
  9342. if (cProto && typeof cProto.createTooltipIfRequired_ === 'function' && cProto.createTooltipIfRequired_.length === 0 && !cProto.createTooltipIfRequired14_) {
  9343. cProto.createTooltipIfRequired14_ = cProto.createTooltipIfRequired_;
  9344. cProto.createTooltipIfRequired_ = createTooltipIfRequired_;
  9345. }
  9346.  
  9347. });
  9348.  
  9349. // ----------------------------------------------------------------------------------------------------
  9350.  
  9351. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  9352.  
  9353. mightFirstCheckOnYtInit();
  9354. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  9355. console.log("[Begin]");
  9356. (() => {
  9357.  
  9358. const tag = "tp-yt-paper-tooltip"
  9359. const dummy = document.createElement(tag);
  9360.  
  9361. const cProto = getProto(dummy);
  9362. if (!cProto || !cProto.attached) {
  9363. console.warn(`proto.attached for ${tag} is unavailable.`);
  9364. return;
  9365. }
  9366.  
  9367. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  9368.  
  9369. cProto._readyClients43 = cProto._readyClients;
  9370. cProto._readyClients = function () {
  9371. // console.log(1238)
  9372.  
  9373. let r = cProto._readyClients43.apply(this, arguments);
  9374. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  9375. return r;
  9376. }
  9377.  
  9378. console.log("_readyClients - OK");
  9379.  
  9380. } else {
  9381. console.log("_readyClients - NG");
  9382.  
  9383. }
  9384.  
  9385. if (typeof cProto.show === 'function' && !cProto.show17) {
  9386. cProto.show17 = cProto.show;
  9387. cProto.show = function () {
  9388.  
  9389. let r = this.show17.apply(this, arguments);
  9390. this._showing === true && Promise.resolve(this).then((cnt) => {
  9391. const tooltip = (cnt.$ || 0).tooltip;
  9392.  
  9393. if (tooltip && tooltip.firstElementChild === null) {
  9394. let text = tooltip.textContent;
  9395. if (typeof text === 'string' && text.length >= 2) {
  9396. tooltip.textContent = text.trim();
  9397. }
  9398. }
  9399. cnt = null;
  9400. }).catch(console.warn)
  9401. return r;
  9402. }
  9403.  
  9404. console.log("trim tooltip content - OK");
  9405.  
  9406. } else {
  9407. console.log("trim tooltip content - NG");
  9408.  
  9409. }
  9410.  
  9411.  
  9412. })();
  9413.  
  9414. console.log("[End]");
  9415.  
  9416. console.groupEnd();
  9417.  
  9418. }).catch(console.warn);
  9419.  
  9420. }
  9421.  
  9422.  
  9423. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  9424.  
  9425. const hookDocumentMouseDownSetupFn = () => {
  9426.  
  9427. let muzTimestamp = 0;
  9428. let nszDropdown = null;
  9429.  
  9430. const handlerObject = {
  9431.  
  9432. muHandler282: function (evt) {
  9433. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  9434. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9435. const dropdown = nszDropdown;
  9436. muzTimestamp = 0;
  9437. nszDropdown = null;
  9438.  
  9439. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9440. const hostElement = kurMPCe.hostElement || kurMPCe; // should be always hostElement === kurMPCe ?
  9441. if (!hostElement.hasAttribute('menu-visible')) return;
  9442.  
  9443. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  9444. if (chatBanner) return;
  9445.  
  9446. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  9447. muzTimestamp = Date.now();
  9448. evt.stopImmediatePropagation();
  9449. evt.stopPropagation();
  9450. Promise.resolve(dropdown).then((dropdown) => {
  9451. dropdown.cancel();
  9452. dropdown = null;
  9453. });
  9454. }
  9455.  
  9456. },
  9457.  
  9458. mlHandler282: function (evt) {
  9459. muzTimestamp = 0;
  9460. nszDropdown = null;
  9461. },
  9462.  
  9463. ckHandler282: function (evt) {
  9464. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9465. if (Date.now() - muzTimestamp < 40) {
  9466. muzTimestamp = Date.now();
  9467. evt.stopImmediatePropagation();
  9468. evt.stopPropagation();
  9469. }
  9470. },
  9471.  
  9472. tapHandler282: function (evt) {
  9473. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9474. if (Date.now() - muzTimestamp < 40) {
  9475. muzTimestamp = Date.now();
  9476. evt.stopImmediatePropagation();
  9477. evt.stopPropagation();
  9478. }
  9479. },
  9480.  
  9481. handleEvent(evt) {
  9482. if (evt) {
  9483. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9484. const kurMPCc = insp(kurMPCe);
  9485. const hostElement = kurMPCc.hostElement || kurMPCc;
  9486. if (!kurMPCc || kurMPCc.isAttached !== true || hostElement.isConnected !== true) return;
  9487. switch (evt.type) {
  9488. case 'mouseup':
  9489. return this.muHandler282(evt);
  9490. case 'mouseleave':
  9491. return this.mlHandler282(evt);
  9492. case 'tap':
  9493. return this.tapHandler282(evt);
  9494. case 'click':
  9495. return this.ckHandler282(evt);
  9496. }
  9497. }
  9498. }
  9499.  
  9500. }
  9501.  
  9502. document.addEventListener('mousedown', function (evt) {
  9503.  
  9504. if (!evt || !evt.isTrusted || !evt.target) return;
  9505.  
  9506. muzTimestamp = 0;
  9507. nszDropdown = null;
  9508.  
  9509. /** @type {HTMLElement | null} */
  9510. const kurMP = kRef(currentMenuPivotWR);
  9511. if (!kurMP) return;
  9512. const kurMPCe = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0; // element
  9513.  
  9514. if (!kurMPCe || !kurMPCe.hasAttribute('whole-message-clickable')) return;
  9515.  
  9516. const kurMPCc = insp(kurMPCe); // controller
  9517.  
  9518. if (!kurMPCc.isClickableChatRow111 || !kurMPCc.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPCe, evt.target)) return;
  9519.  
  9520. const chatBanner = HTMLElement.prototype.closest.call(kurMPCe, 'yt-live-chat-banner-renderer') || 0;
  9521. if (chatBanner) return;
  9522.  
  9523. let targetDropDown = null;
  9524. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  9525. if (dropdown && dropdown.positionTarget === kurMP) {
  9526. targetDropDown = dropdown;
  9527. }
  9528. }
  9529.  
  9530. if (!targetDropDown) return;
  9531.  
  9532. if ((nszDropdown = targetDropDown)) {
  9533. muzTimestamp = Date.now();
  9534. evt.stopImmediatePropagation();
  9535. evt.stopPropagation();
  9536. currentMenuPivotWR = mWeakRef(kurMPCe);
  9537.  
  9538. const listenOpts = { capture: true, passive: false, once: true };
  9539.  
  9540. // remove unexcecuted eventHandler
  9541. document.removeEventListener('mouseup', handlerObject, listenOpts);
  9542. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  9543. document.removeEventListener('tap', handlerObject, listenOpts);
  9544. document.removeEventListener('click', handlerObject, listenOpts);
  9545.  
  9546. // inject one time eventHandler to by pass events
  9547. document.addEventListener('mouseup', handlerObject, listenOpts);
  9548. document.addEventListener('mouseleave', handlerObject, listenOpts);
  9549. document.addEventListener('tap', handlerObject, listenOpts);
  9550. document.addEventListener('click', handlerObject, listenOpts);
  9551.  
  9552. }
  9553.  
  9554. }, true);
  9555.  
  9556. }
  9557.  
  9558.  
  9559. // yt-live-chat-paid-message-renderer ??
  9560.  
  9561. /*
  9562.  
  9563. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  9564.  
  9565.  
  9566. "yt-live-chat-ticker-paid-message-item-renderer"
  9567. "yt-live-chat-ticker-paid-sticker-item-renderer"
  9568. "yt-live-chat-paid-message-renderer"
  9569. "yt-live-chat-text-message-renderer"
  9570. "yt-live-chat-paid-sticker-renderer"
  9571.  
  9572. */
  9573.  
  9574.  
  9575. whenDefinedMultiple([
  9576.  
  9577. "yt-live-chat-paid-message-renderer",
  9578. "yt-live-chat-membership-item-renderer",
  9579. "yt-live-chat-paid-sticker-renderer",
  9580. "yt-live-chat-text-message-renderer",
  9581. "yt-live-chat-auto-mod-message-renderer",
  9582.  
  9583. /*
  9584. "yt-live-chat-ticker-paid-message-item-renderer",
  9585. "yt-live-chat-ticker-paid-sticker-item-renderer",
  9586. "yt-live-chat-paid-message-renderer",
  9587. "yt-live-chat-text-message-renderer",
  9588. "yt-live-chat-paid-sticker-renderer",
  9589.  
  9590. "yt-live-chat-ticker-sponsor-item-renderer",
  9591. "yt-live-chat-banner-header-renderer",
  9592. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  9593. "ytd-sponsorships-live-chat-header-renderer",
  9594. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  9595.  
  9596.  
  9597.  
  9598.  
  9599. "yt-live-chat-auto-mod-message-renderer",
  9600. "yt-live-chat-text-message-renderer",
  9601. "yt-live-chat-paid-message-renderer",
  9602.  
  9603. "yt-live-chat-legacy-paid-message-renderer",
  9604. "yt-live-chat-membership-item-renderer",
  9605. "yt-live-chat-paid-sticker-renderer",
  9606. "yt-live-chat-donation-announcement-renderer",
  9607. "yt-live-chat-moderation-message-renderer",
  9608. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  9609. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  9610. "yt-live-chat-viewer-engagement-message-renderer",
  9611.  
  9612. */
  9613.  
  9614.  
  9615. ]).then(sTags => {
  9616. // return; // M33
  9617.  
  9618. if (FLAG_001e) return;
  9619.  
  9620. mightFirstCheckOnYtInit();
  9621. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  9622. console.log("[Begin]");
  9623. let doMouseHook = false;
  9624.  
  9625. const dProto = {
  9626. isClickableChatRow111: function () {
  9627. return (
  9628. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  9629. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  9630. ); // follow .onItemTap(a)
  9631. }
  9632. };
  9633.  
  9634. for (const sTag of sTags) { // ##tag##
  9635.  
  9636.  
  9637. (() => {
  9638.  
  9639. const tag = sTag;
  9640. const dummy = document.createElement(tag);
  9641.  
  9642. const cProto = getProto(dummy);
  9643. if (!cProto || !cProto.attached) {
  9644. console.warn(`proto.attached for ${tag} is unavailable.`);
  9645. return;
  9646. }
  9647.  
  9648. const dCnt = insp(dummy);
  9649. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  9650.  
  9651. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  9652.  
  9653. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  9654.  
  9655. if (toHookDocumentMouseDown) {
  9656. doMouseHook = true;
  9657. }
  9658.  
  9659. console.log("shouldSupportWholeItemClick Y", tag);
  9660.  
  9661. } else {
  9662.  
  9663. console.log("shouldSupportWholeItemClick N", tag);
  9664. }
  9665.  
  9666.  
  9667. })();
  9668.  
  9669. }
  9670.  
  9671.  
  9672. if (doMouseHook) {
  9673.  
  9674. hookDocumentMouseDownSetupFn();
  9675.  
  9676. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  9677. }
  9678.  
  9679. console.log("[End]");
  9680.  
  9681. console.groupEnd();
  9682.  
  9683.  
  9684. }).catch(console.warn);
  9685.  
  9686.  
  9687. // https://www.youtube.com/watch?v=oQzFi1NO7io
  9688.  
  9689.  
  9690. }
  9691.  
  9692. if (NO_ITEM_TAP_FOR_NON_STATIONARY_TAP) {
  9693. let targetElementCntWR = null;
  9694. let _e0 = null;
  9695. document.addEventListener('mousedown', (e) => {
  9696. if (!e || !e.isTrusted) return;
  9697. let element = e.target;
  9698. for (; element instanceof HTMLElement; element = element.parentNode) {
  9699. if (element.is) break;
  9700. }
  9701. if (!element || !element.is) return;
  9702. const cnt = insp(element);
  9703. if (typeof cnt.onItemTap === 'function') {
  9704. cnt._onItemTap_isNonStationary = 0;
  9705. const cProto = getProto(element);
  9706. if (!cProto.onItemTap366 && typeof cProto.onItemTap === 'function' && cProto.onItemTap.length === 1) {
  9707. cProto.onItemTap366 = cProto.onItemTap; // note: [onItemTap] .some(function(){...})
  9708. cProto.onItemTap = function (a) {
  9709. const t = this._onItemTap_isNonStationary;
  9710. this._onItemTap_isNonStationary = 0;
  9711. if (t > Date.now()) return;
  9712. return this.onItemTap366.apply(this, arguments)
  9713. }
  9714. }
  9715. _e0 = e;
  9716. targetElementCntWR = mWeakRef(cnt);
  9717. } else {
  9718. _e0 = null;
  9719. targetElementCntWR = null;
  9720. }
  9721. }, { capture: true, passive: true });
  9722.  
  9723. document.addEventListener('mouseup', (e) => {
  9724. if (!e || !e.isTrusted) return;
  9725. const e0 = _e0;
  9726. _e0 = null;
  9727. if (!e0) return;
  9728. const cnt = kRef(targetElementCntWR);
  9729. targetElementCntWR = null;
  9730. if (!cnt) return;
  9731. if (e.timeStamp - e0.timeStamp > TAP_ACTION_DURATION) {
  9732. cnt._onItemTap_isNonStationary = Date.now() + 40;
  9733. } else if ((window.getSelection() + "").trim().replace(/[\u2000-\u200a\u202f\u2800\u200B\u200C\u200D\uFEFF]+/g, '').length >= 1) {
  9734. cnt._onItemTap_isNonStationary = Date.now() + 40;
  9735. } else {
  9736. const dx = e.clientX - e0.clientX;
  9737. const dy = e.clientY - e0.clientY;
  9738. const dd = Math.sqrt(dx * dx + dy * dy);
  9739. const ddmm = px2mm(dd);
  9740. if (ddmm > 1.0) {
  9741. cnt._onItemTap_isNonStationary = Date.now() + 40;
  9742. } else {
  9743. cnt._onItemTap_isNonStationary = 0;
  9744. }
  9745. }
  9746. }, { capture: true, passive: true });
  9747.  
  9748. }
  9749.  
  9750.  
  9751. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  9752.  
  9753. let rr = null;
  9754. const p1 = new Promise(resolve => {
  9755. rr = resolve;
  9756. });
  9757.  
  9758. const p1unlock = () => {
  9759. const f = rr;
  9760. if (f) {
  9761. rr = null;
  9762. f();
  9763. }
  9764. }
  9765.  
  9766. return {
  9767. p1,
  9768. p1unlock,
  9769. assignLock: (targetCnt, timeout) => {
  9770. targetCnt.__showContextMenu_assign_lock__(p1);
  9771. if (timeout) setTimeout(p1unlock, timeout);
  9772. }
  9773. }
  9774.  
  9775. }
  9776.  
  9777. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  9778.  
  9779. document.addEventListener('mousedown', function (evt) {
  9780.  
  9781. const maxloopDOMTreeElements = 4;
  9782. const maxloopYtCompontents = 4;
  9783. let j1 = 0;
  9784. let j2 = 0;
  9785. let target = (evt || 0).target || 0;
  9786. if (!target) return;
  9787.  
  9788.  
  9789. while (target instanceof HTMLElement) {
  9790. if (++j1 > maxloopDOMTreeElements) break;
  9791. if (typeof (target.is || insp(target).is || null) === 'string') break;
  9792. target = nodeParent(target);
  9793. }
  9794. const components = [];
  9795. while (target instanceof HTMLElement) {
  9796. if (++j2 > maxloopYtCompontents) break;
  9797. const cnt = insp(target);
  9798. if (typeof (target.is || cnt.is || null) === 'string') {
  9799. components.push(target);
  9800. }
  9801. if (typeof cnt.showContextMenu === 'function') break;
  9802. target = target.parentComponent || cnt.parentComponent || null;
  9803. }
  9804. if (!(target instanceof HTMLElement)) return;
  9805. const targetCnt = insp(target);
  9806. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  9807. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  9808. return;
  9809. }
  9810.  
  9811. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  9812. if (!endpoint) return;
  9813. if (targetCnt.opened || !targetCnt.isAttached) return;
  9814.  
  9815. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  9816. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  9817. }
  9818.  
  9819. const targetDollar = indr(target);
  9820.  
  9821. let doPreRequest = false;
  9822. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  9823. doPreRequest = true;
  9824. } else if (components.length === 1 && components[0] === target) {
  9825. doPreRequest = true;
  9826. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  9827. doPreRequest = true;
  9828. }
  9829. if (doPreRequest === false) {
  9830. console.log('doPreRequest = fasle on showContextMenu', components);
  9831. return;
  9832. }
  9833.  
  9834. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  9835.  
  9836. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  9837. console.log('preRequest on showContextMenu aborted due to stacked network request');
  9838. return;
  9839. }
  9840.  
  9841.  
  9842. const onSuccess = (a) => {
  9843. /*
  9844.  
  9845. dQ() && (a = a.response);
  9846. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  9847. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  9848.  
  9849. */
  9850.  
  9851. a = a.response || a;
  9852.  
  9853. if (!a) {
  9854. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  9855. return;
  9856. }
  9857.  
  9858. let z = null;
  9859. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  9860.  
  9861. if (z) {
  9862. a = z;
  9863. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  9864. }
  9865.  
  9866. };
  9867. const onFailure = (a) => {
  9868.  
  9869. /*
  9870.  
  9871. if (a instanceof Error || a instanceof Object || a instanceof String)
  9872. var b = a;
  9873. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  9874.  
  9875. */
  9876.  
  9877. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  9878. // console.log('onFailure', a)
  9879.  
  9880. };
  9881.  
  9882. if (doPreRequest) {
  9883.  
  9884. let propertyCounter = 0;
  9885. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  9886. const p1Timeout = 800;
  9887. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  9888.  
  9889. try {
  9890.  
  9891. const onSuccessHelperFn = function () {
  9892. pm1.p1unlock();
  9893. if (propertyCounter !== 5) {
  9894. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  9895. return;
  9896. }
  9897. if (this[proxyKey] !== targetCnt) {
  9898. console.log('Error in prerequest for showContextMenu.this');
  9899. return;
  9900. }
  9901. onSuccess(...arguments);
  9902. };
  9903. const onFailureHelperFn = function () {
  9904. pm1.p1unlock();
  9905. if (propertyCounter !== 5) {
  9906. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  9907. return;
  9908. }
  9909. if (this[proxyKey] !== targetCnt) {
  9910. console.log('Error in prerequest for showContextMenu.this');
  9911. return;
  9912. }
  9913. onFailure(...arguments);
  9914.  
  9915. }
  9916. const fakeTargetCnt = new Proxy({
  9917. __showContextMenu_forceNativeRequest__: 1,
  9918. get handleGetContextMenuResponse_() {
  9919. propertyCounter += 2;
  9920. return onSuccessHelperFn;
  9921. },
  9922. get handleGetContextMenuError() {
  9923. propertyCounter += 3;
  9924. return onFailureHelperFn;
  9925. }
  9926. }, {
  9927. get(_, key, receiver) {
  9928. if (key in _) return _[key];
  9929. if (key === proxyKey) return targetCnt;
  9930.  
  9931. let giveNative = false;
  9932. if (key in targetCnt) {
  9933. if (key === 'data') giveNative = true;
  9934. else if (typeof targetCnt[key] === 'function') giveNative = true;
  9935. }
  9936. if (giveNative) return targetCnt[key];
  9937. }
  9938. });
  9939.  
  9940. const fakeEvent = (() => {
  9941. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  9942. const nf = function () { }
  9943. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  9944.  
  9945. return {
  9946. type: 'tap',
  9947. eventPhase: 0,
  9948. isTrusted: false,
  9949. __composed: true,
  9950. bubbles, cancelable, cancelBubble, timeStamp,
  9951. target, srcElement, defaultPrevented, currentTarget, composed,
  9952. stopPropagation, stopImmediatePropagation, preventDefault
  9953. };
  9954. })(evt);
  9955. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  9956.  
  9957.  
  9958. } catch (e) {
  9959. console.warn(e);
  9960. propertyCounter = 7;
  9961.  
  9962. }
  9963. if (propertyCounter !== 5) {
  9964. console.log('Error in prerequest for showContextMenu', propertyCounter);
  9965. return;
  9966. }
  9967.  
  9968. pm1.assignLock(targetCnt, p1Timeout);
  9969.  
  9970. }
  9971.  
  9972.  
  9973.  
  9974.  
  9975.  
  9976.  
  9977. }, true);
  9978.  
  9979.  
  9980. }
  9981.  
  9982.  
  9983.  
  9984. /*
  9985.  
  9986. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  9987.  
  9988. */
  9989.  
  9990. whenDefinedMultiple([
  9991. "yt-live-chat-ticker-sponsor-item-renderer",
  9992. "yt-live-chat-ticker-paid-message-item-renderer",
  9993.  
  9994. "yt-live-chat-banner-header-renderer",
  9995. "yt-live-chat-text-message-renderer",
  9996. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  9997. "ytd-sponsorships-live-chat-header-renderer",
  9998. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  9999.  
  10000. "yt-live-chat-paid-sticker-renderer",
  10001. "yt-live-chat-viewer-engagement-message-renderer",
  10002. "yt-live-chat-paid-message-renderer"
  10003.  
  10004.  
  10005.  
  10006.  
  10007. ]).then(sTags => {
  10008.  
  10009. if (FLAG_001f) return;
  10010.  
  10011. mightFirstCheckOnYtInit();
  10012. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  10013. console.log("[Begin]");
  10014.  
  10015.  
  10016. const __showContextMenu_mutex__ = new Mutex();
  10017. let __showContextMenu_mutex_unlock__ = null;
  10018. let lastShowMenuTarget = null;
  10019.  
  10020.  
  10021.  
  10022.  
  10023. const wm37 = new WeakMap();
  10024.  
  10025. const dProto = {
  10026.  
  10027.  
  10028. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  10029.  
  10030. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  10031. if (a) {
  10032. if (doDeepCopy) a = deepCopy(a);
  10033. wm37.set(endpoint, a);
  10034. } else {
  10035. wm37.remove(endpoint);
  10036. }
  10037. },
  10038. __getCachedEndpointData__: function (endpoint) {
  10039. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  10040. if (endpoint) return wm37.get(endpoint);
  10041. return null;
  10042. },
  10043. /** @type {(resolvedEndpoint: any) => void 0} */
  10044. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  10045.  
  10046. resolvedEndpoint = deepCopy(resolvedEndpoint);
  10047. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  10048. Promise.resolve(resolvedEndpoint).then((resolvedEndpoint) => {
  10049. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  10050. this.showContextMenu_(resolvedEndpoint);
  10051. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  10052. resolvedEndpoint = null;
  10053. });
  10054.  
  10055.  
  10056. },
  10057.  
  10058.  
  10059.  
  10060. showContextMenuForCacheReopen: function (a) {
  10061. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37(a);
  10062. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10063. if (!this.__showContextMenu_forceNativeRequest__) {
  10064. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10065. if (endpoint) {
  10066. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  10067. if (resolvedEndpoint) {
  10068. this.__showCachedContextMenu__(resolvedEndpoint);
  10069. a && a.stopPropagation()
  10070. return;
  10071. }
  10072. }
  10073. }
  10074. return this.showContextMenu37(a);
  10075. },
  10076.  
  10077. showContextMenuForCacheReopen_: function (a) {
  10078. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37_(a);
  10079. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10080. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  10081. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10082. if (endpoint) {
  10083. const f = this.__cacheResolvedEndpointData__;
  10084. if (typeof f === 'function') f(endpoint, a, true);
  10085. }
  10086. }
  10087. return this.showContextMenu37_(a);
  10088. },
  10089.  
  10090. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  10091.  
  10092. showContextMenuWithDisableScroll: function (a) {
  10093.  
  10094. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10095. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  10096.  
  10097. const parentComponent = this.parentComponent;
  10098. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  10099. parentComponent.contextMenuOpen = true; // computeAllowScroll_(contextMenuOpen, moderationModeEnabled): allowScroll = !(contextMenuOpen || moderationModeEnabled)
  10100. }
  10101. }
  10102.  
  10103. return this.showContextMenu48.apply(this, arguments);
  10104.  
  10105. },
  10106.  
  10107. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  10108.  
  10109. __showContextMenu_mutex_unlock_isEmpty__: () => {
  10110. return __showContextMenu_mutex_unlock__ === null;
  10111. },
  10112.  
  10113. __showContextMenu_assign_lock__: function (p) {
  10114.  
  10115. const mutex = __showContextMenu_mutex__;
  10116.  
  10117. mutex.lockWith(unlock => {
  10118. p.then(unlock);
  10119. p = null;
  10120. unlock = null;
  10121. });
  10122.  
  10123. },
  10124.  
  10125. showContextMenuWithMutex: function (a) {
  10126. if (this.__showContextMenu_forceNativeRequest__) return this.showContextMenu47(a);
  10127. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10128. lastShowMenuTarget = this;
  10129. const wNode = mWeakRef(this);
  10130.  
  10131.  
  10132. const mutex = __showContextMenu_mutex__;
  10133.  
  10134. mutex.lockWith(unlock => {
  10135. const cnt = kRef(wNode);
  10136. if (lastShowMenuTarget !== cnt || !cnt) {
  10137. unlock();
  10138. return;
  10139. }
  10140.  
  10141. setTimeout(unlock, 800); // in case network failure
  10142. __showContextMenu_mutex_unlock__ = unlock;
  10143. try {
  10144. cnt.showContextMenu47(a);
  10145. } catch (e) {
  10146. console.warn(e);
  10147. unlock(); // in case function script error
  10148. }
  10149.  
  10150. });
  10151.  
  10152.  
  10153. },
  10154.  
  10155. showContextMenuWithMutex_: function (a) {
  10156.  
  10157. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  10158. __showContextMenu_mutex_unlock__();
  10159. __showContextMenu_mutex_unlock__ = null;
  10160. }
  10161. return this.showContextMenu47_(a);
  10162.  
  10163. }
  10164.  
  10165. }
  10166.  
  10167. for (const tag of sTags) { // ##tag##
  10168.  
  10169. (() => {
  10170.  
  10171. const dummy = document.createElement(tag);
  10172.  
  10173. const cProto = getProto(dummy);
  10174. if (!cProto || !cProto.attached) {
  10175. console.warn(`proto.attached for ${tag} is unavailable.`);
  10176. return;
  10177. }
  10178.  
  10179.  
  10180. 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) {
  10181. cProto.showContextMenu37_ = cProto.showContextMenu_;
  10182. cProto.showContextMenu37 = cProto.showContextMenu;
  10183. cProto.__showContextMenu_forceNativeRequest__ = 0;
  10184. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  10185. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  10186. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  10187. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  10188. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  10189. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  10190. } else {
  10191. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  10192. }
  10193.  
  10194. 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) {
  10195. cProto.showContextMenu48 = cProto.showContextMenu;
  10196. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  10197. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10198. } else if (!ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU) {
  10199. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - N/A", tag);
  10200. } else {
  10201. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10202. }
  10203.  
  10204.  
  10205. 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) {
  10206. cProto.showContextMenu47_ = cProto.showContextMenu_;
  10207. cProto.showContextMenu47 = cProto.showContextMenu;
  10208. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  10209. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  10210. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  10211. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  10212. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10213. } else {
  10214. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10215. }
  10216.  
  10217. })();
  10218.  
  10219. }
  10220.  
  10221. console.log("[End]");
  10222.  
  10223. console.groupEnd();
  10224.  
  10225. }).catch(console.warn);
  10226.  
  10227.  
  10228.  
  10229. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  10230.  
  10231. mightFirstCheckOnYtInit();
  10232. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  10233. console.log("[Begin]");
  10234. (() => {
  10235.  
  10236. const tag = "tp-yt-iron-dropdown";
  10237. const dummy = document.createElement(tag);
  10238.  
  10239. const cProto = getProto(dummy);
  10240. if (!cProto || !cProto.attached) {
  10241. console.warn(`proto.attached for ${tag} is unavailable.`);
  10242. return;
  10243. }
  10244.  
  10245. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  10246. cProto.__deraf_hn__ = function (sId, fn) {
  10247. const rhKey = `_rafHandler_${sId}`;
  10248. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  10249. if (m.has(fn)) return m.get(fn);
  10250. const resFn = () => {
  10251. this.__rafs[sId] = null;
  10252. fn.call(this)
  10253. };
  10254. m.set(fn, resFn);
  10255. m.set(resFn, resFn);
  10256. return resFn;
  10257. };
  10258. cProto.__deraf34 = cProto.__deraf;
  10259. cProto.__deraf = function (a, b) { // sId, fn
  10260. let c = this.__rafs;
  10261. null !== c[a] && cancelAnimationFrame(c[a]);
  10262. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  10263. };
  10264. console.log("USE_VANILLA_DEREF - OK");
  10265. } else {
  10266. console.log("USE_VANILLA_DEREF - NG");
  10267. }
  10268.  
  10269. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  10270. cProto.__deraf66 = cProto.__deraf;
  10271. cProto.__deraf = function (sId, fn) {
  10272. if (this.__byPassRAF__) {
  10273. Promise.resolve(this).then((cnt) => {
  10274. fn.call(cnt);
  10275. cnt = null;
  10276. });
  10277. }
  10278. let r = this.__deraf66.apply(this, arguments);
  10279. return r;
  10280. }
  10281. console.log("FIX_DROPDOWN_DERAF - OK");
  10282. } else {
  10283. console.log("FIX_DROPDOWN_DERAF - NG");
  10284. }
  10285.  
  10286.  
  10287. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  10288.  
  10289. let lastClose = null;
  10290. let lastOpen = null;
  10291. let cid = 0;
  10292.  
  10293. cProto.__mtChanged__ = function (b) {
  10294.  
  10295. Promise.resolve(this).then((cnt) => {
  10296. cnt._applyFocus();
  10297. return cnt;
  10298. }).then((cnt) => {
  10299. b ? cnt._renderOpened() : cnt._renderClosed();
  10300. cnt = null;
  10301. }).catch(console.warn);
  10302.  
  10303. };
  10304.  
  10305. const __moChanged__ = () => {
  10306. if (!cid) return;
  10307. // console.log(553, !!lastOpen, !!lastClose);
  10308. cid = 0;
  10309. if (lastOpen && !lastClose && lastOpen.isAttached) {
  10310. lastOpen.__mtChanged__(1)
  10311. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  10312. lastClose.__mtChanged__(0);
  10313. }
  10314. lastOpen = null;
  10315. lastClose = null;
  10316. };
  10317.  
  10318.  
  10319. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  10320. cProto._openedChanged66 = cProto._openedChanged;
  10321. cProto._openedChanged = function () {
  10322. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  10323. this.__byPassRAF__ = true;
  10324. let r = this._openedChanged66.apply(this, arguments);
  10325. this.__byPassRAF__ = false;
  10326. return r;
  10327. }
  10328. }
  10329.  
  10330. const pSetGet = (key, pdThis, pdBase) => {
  10331. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  10332. return {
  10333. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  10334. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  10335. };
  10336. };
  10337.  
  10338. cProto.__modifiedMenuPropsFn__ = function () {
  10339. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  10340. const pdBase = Object.getOwnPropertyDescriptors(this)
  10341.  
  10342. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  10343. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  10344. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  10345.  
  10346. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  10347. console.warn('there is setter/getter for autoFitOnAttach');
  10348. return;
  10349. }
  10350. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  10351. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  10352. return;
  10353. }
  10354. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  10355. console.warn('there is NO setter-getter for allowOutsideScroll');
  10356. return;
  10357. }
  10358.  
  10359. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  10360.  
  10361. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  10362.  
  10363. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  10364.  
  10365. Object.defineProperties(this, {
  10366. autoFitOnAttach: {
  10367. get() {
  10368. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10369. return autoFitOnAttach;
  10370. },
  10371. set(nv) {
  10372. autoFitOnAttach = nv;
  10373. return true;
  10374. },
  10375. enumerable: true,
  10376. configurable: true
  10377. }, expandSizingTargetForScrollbars: {
  10378. get() {
  10379. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10380. return expandSizingTargetForScrollbars;
  10381. },
  10382. set(nv) {
  10383. expandSizingTargetForScrollbars = nv;
  10384. return true;
  10385. },
  10386. enumerable: true,
  10387. configurable: true
  10388. }, allowOutsideScroll: {
  10389. get() {
  10390. if (this._modifiedMenuPropOn062__) return true;
  10391. return allowOutsideScroll;
  10392. },
  10393. set(nv) {
  10394. allowOutsideScroll = nv;
  10395. this.__AllowOutsideScrollPD__.set.call(this, nv);
  10396. return true;
  10397. },
  10398. enumerable: true,
  10399. configurable: true
  10400. }
  10401. })
  10402. };
  10403.  
  10404. /*
  10405. // ***** position() to be changed. *****
  10406. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  10407.  
  10408. overflow: visible !important;
  10409. min-width: max-content !important;
  10410. max-width: max-content !important;
  10411. max-height: max-content !important;
  10412. min-height: max-content !important;
  10413. white-space: nowrap;
  10414. }
  10415.  
  10416. */
  10417. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  10418.  
  10419. let m34 = 0;
  10420. cProto.__refitByPosition__ = function () {
  10421. m34++;
  10422. if (m34 <= 0) m34 = 0;
  10423. if (m34 !== 1) return;
  10424. const hostElement = this.hostElement || this;
  10425. if (document.visibilityState === 'visible') {
  10426. const sizingTarget = this.sizingTarget;
  10427. if (!sizingTarget) {
  10428. m34 = 0;
  10429. return;
  10430. }
  10431. hostElement.setAttribute('rNgzQ', '');
  10432. sizingTarget.setAttribute('rNgzQ', '');
  10433.  
  10434. const gn = () => {
  10435. hostElement.removeAttribute('rNgzQ');
  10436. sizingTarget.removeAttribute('rNgzQ');
  10437. }
  10438.  
  10439. const an = async () => {
  10440. while (m34 >= 1) {
  10441. await renderReadyPn(sizingTarget);
  10442. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  10443. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  10444. }
  10445. m34--;
  10446. }
  10447. m34 = 0;
  10448. Promise.resolve().then(gn);
  10449. }
  10450. setTimeout(an, 4); // wait those resizing function calls
  10451.  
  10452.  
  10453. } else {
  10454. m34 = 0;
  10455. }
  10456. }
  10457. cProto.position34 = cProto.position
  10458. cProto.position = function () {
  10459. if (this._positionInitialize_) {
  10460. this._positionInitialize_ = 0;
  10461. this.__refitByPosition__();
  10462. }
  10463. let r = cProto.position34.apply(this, arguments);
  10464. return r;
  10465. }
  10466. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  10467.  
  10468. } else {
  10469.  
  10470. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  10471.  
  10472. }
  10473.  
  10474.  
  10475.  
  10476. cProto.__openedChanged = function () {
  10477. this._positionInitialize_ = 1;
  10478. // this.removeAttribute('horizontal-align')
  10479. // this.removeAttribute('vertical-align')
  10480. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  10481. this.__menuTypeCheck__ = true;
  10482. if (CHAT_MENU_SCROLL_UNLOCKING) {
  10483. this._modifiedMenuPropOn062__ = false;
  10484. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10485. // this.autoFitOnAttach = true;
  10486. // this.expandSizingTargetForScrollbars = true;
  10487. // this.allowOutsideScroll = true;
  10488. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  10489. this.__modifiedMenuPropsFn__();
  10490. // this.constrain= function(){}
  10491. // this.position= function(){}
  10492.  
  10493. // this.autoFitOnAttach = true;
  10494. // this.expandSizingTargetForScrollbars = true;
  10495. // this.allowOutsideScroll = true;
  10496. }
  10497. }
  10498. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  10499. let newValue = null;
  10500. const positionTarget = this.positionTarget;
  10501. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  10502. if (this._modifiedMenuPropOn062__ === false) {
  10503. newValue = true;
  10504. }
  10505. } else if (this._modifiedMenuPropOn062__ === true) {
  10506. newValue = false;
  10507. }
  10508. if (newValue !== null) {
  10509. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  10510. this._modifiedMenuPropOn062__ = newValue;
  10511. const afterAllowOutsideScroll = this.allowOutsideScroll;
  10512. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  10513. }
  10514. }
  10515.  
  10516. if (this.opened) {
  10517.  
  10518. Promise.resolve().then(() => {
  10519.  
  10520. this._prepareRenderOpened();
  10521. }).then(() => {
  10522. this._manager.addOverlay(this);
  10523. if (this._manager._overlays.length === 1) {
  10524. lastOpen = this;
  10525. lastClose = null;
  10526. } else {
  10527. return 1;
  10528. }
  10529. // if (cid) {
  10530. // clearTimeout(cid);
  10531. // cid = -1;
  10532. // this.__moChanged__();
  10533. // cid = 0;
  10534. // } else {
  10535. // cid = -1;
  10536. // this.__moChanged__();
  10537. // cid = 0;
  10538. // }
  10539. // cid = cid > 0 ? clearTimeout(cid) : 0;
  10540. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10541. // cid = cid || setTimeout(__moChanged__, delay1);
  10542. cid = cid || requestAnimationFrame(__moChanged__);
  10543. }).then((r) => {
  10544.  
  10545. if (r) this.__mtChanged__(1);
  10546. }).catch(console.warn);
  10547.  
  10548. } else {
  10549. Promise.resolve().then(() => {
  10550. this._manager.removeOverlay(this);
  10551. if (this._manager._overlays.length === 0) {
  10552. lastClose = this;
  10553. lastOpen = null;
  10554. } else {
  10555. return 1;
  10556. }
  10557. // cid = cid > 0 ? clearTimeout(cid) : 0;
  10558. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10559. // cid = cid || setTimeout(__moChanged__, delay1);
  10560. cid = cid || requestAnimationFrame(__moChanged__);
  10561. }).then((r) => {
  10562. if (r) this.__mtChanged__(0);
  10563. }).catch(console.warn);
  10564.  
  10565. }
  10566.  
  10567. }
  10568. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  10569.  
  10570. } else {
  10571.  
  10572. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  10573. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  10574.  
  10575. }
  10576.  
  10577.  
  10578. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  10579.  
  10580. cProto.__openedChanged82 = cProto.__openedChanged;
  10581.  
  10582.  
  10583. cProto.__openedChanged = function () {
  10584. const positionTarget = this.positionTarget;
  10585. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  10586. return this.__openedChanged82.apply(this, arguments);
  10587. }
  10588. }
  10589.  
  10590.  
  10591. })();
  10592.  
  10593. console.log("[End]");
  10594.  
  10595. console.groupEnd();
  10596.  
  10597. }).catch(console.warn);
  10598.  
  10599.  
  10600.  
  10601. FIX_ToggleRenderPolymerControllerExtractionBug && customElements.whenDefined('yt-live-chat-toggle-renderer').then(() => {
  10602.  
  10603. mightFirstCheckOnYtInit();
  10604. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-toggle-renderer hacks");
  10605. console.log("[Begin]");
  10606. (() => {
  10607.  
  10608. const tag = "yt-live-chat-toggle-renderer";
  10609. const dummy = document.createElement(tag);
  10610.  
  10611. const cProto = getProto(dummy);
  10612. if (!cProto || !cProto.attached) {
  10613. console.warn(`proto.attached for ${tag} is unavailable.`);
  10614. return;
  10615. }
  10616.  
  10617. })();
  10618.  
  10619. console.log("[End]");
  10620. console.groupEnd();
  10621.  
  10622. });
  10623.  
  10624.  
  10625.  
  10626.  
  10627. /*
  10628.  
  10629.  
  10630.  
  10631.  
  10632.  
  10633. var FU = function() {
  10634. var a = this;
  10635. this.nextHandle_ = 1;
  10636. this.clients_ = {};
  10637. this.JSC$10323_callbacks_ = {};
  10638. this.unsubscribeAsyncHandles_ = {};
  10639. this.subscribe = vl(function(b, c, d) {
  10640. var e = Geb(b);
  10641. if (e in a.clients_)
  10642. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  10643. else {
  10644. a: {
  10645. var h = Geb(b), l;
  10646. for (l in a.unsubscribeAsyncHandles_) {
  10647. var m = a.clients_[l];
  10648. if (m instanceof KO) {
  10649. delete a.clients_[l];
  10650. delete a.JSC$10323_callbacks_[l];
  10651. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  10652. delete a.unsubscribeAsyncHandles_[l];
  10653. i6a(m);
  10654. m.objectId_ = new FQa(h);
  10655. m.register();
  10656. d = m;
  10657. break a
  10658. }
  10659. }
  10660. d.objectSource = b.invalidationId.objectSource;
  10661. d.objectId = h;
  10662. if (b = b.webAuthConfigurationData)
  10663. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  10664. b.pageId && (d.pageId = b.pageId);
  10665. d = new KO(d,a.handleInvalidationData_.bind(a));
  10666. d.register()
  10667. }
  10668. a.clients_[e] = d;
  10669. a.JSC$10323_callbacks_[e] = {}
  10670. }
  10671. d = a.nextHandle_++;
  10672. a.JSC$10323_callbacks_[e][d] = c;
  10673. return d
  10674. })
  10675. };
  10676. FU.prototype.unsubscribe = function(a, b) {
  10677. var c = Geb(a);
  10678. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  10679. !this.JSC$10323_callbacks_[c].length)) {
  10680. var d = this.clients_[c];
  10681. b = Jq.run(function() {
  10682. ei(d);
  10683. delete this.clients_[c];
  10684. delete this.unsubscribeAsyncHandles_[c]
  10685. }
  10686. .bind(this));
  10687. this.unsubscribeAsyncHandles_[c] = b
  10688. }
  10689. }
  10690. ;
  10691.  
  10692.  
  10693. */
  10694.  
  10695.  
  10696. const onManagerFound = (dummyManager) => {
  10697. if (!dummyManager || typeof dummyManager !== 'object') return;
  10698.  
  10699. const mgrProto = dummyManager.constructor.prototype;
  10700.  
  10701. let keyCallbackStore = '';
  10702. for (const [key, v] of Object.entries(dummyManager)) {
  10703. if (key.includes('_callbacks_')) keyCallbackStore = key;
  10704. }
  10705.  
  10706. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  10707.  
  10708. if (mgrProto.unsubscribe16) return;
  10709.  
  10710. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  10711.  
  10712. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  10713. console.log("[Begin]");
  10714.  
  10715. const isEmptyObject = ((obj) => (firstKey(obj) === null));
  10716.  
  10717. const idMapper = new Map();
  10718.  
  10719. const convertId = function (objectId) {
  10720. if (!objectId || typeof objectId !== 'string') return null;
  10721.  
  10722. let result = idMapper.get(objectId)
  10723. if (result) return result;
  10724. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  10725. idMapper.set(objectId, result)
  10726. return result;
  10727. }
  10728.  
  10729.  
  10730. const rafHandleHolder = [];
  10731.  
  10732. let pzw = 0;
  10733. let lza = 0;
  10734. const rafHandlerFn = () => {
  10735. pzw = 0;
  10736. if (rafHandleHolder.length === 1) {
  10737. const f = rafHandleHolder[0];
  10738. rafHandleHolder.length = 0;
  10739. f();
  10740. } else if (rafHandleHolder.length > 1) {
  10741. const arr = rafHandleHolder.slice(0);
  10742. rafHandleHolder.length = 0;
  10743. for (const fn of arr) fn();
  10744. }
  10745. };
  10746.  
  10747.  
  10748. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  10749.  
  10750. const checkIntegrityForSubscribe = (mgr) => {
  10751. if (mgr
  10752. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  10753. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  10754.  
  10755. const ns = new Set(Object.keys(mgr));
  10756. const ms = new Set(Object.keys(mgr.constructor.prototype));
  10757.  
  10758. if (ns.size >= 6 && ms.size >= 4) {
  10759. // including 'subscribe18'
  10760. // 'unsubscribe16', 'subscribe19'
  10761.  
  10762. let r = 0;
  10763. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  10764. r += ns.has(k) ? 1 : 0;
  10765. }
  10766. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  10767. r += ms.has(k) ? 1 : 0;
  10768. }
  10769. if (r === 10) {
  10770. const isObject = (c) => (c || 0).constructor === Object;
  10771.  
  10772. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  10773.  
  10774. return true;
  10775. }
  10776.  
  10777.  
  10778. }
  10779.  
  10780. }
  10781.  
  10782.  
  10783. }
  10784. return false;
  10785. }
  10786.  
  10787. mgrProto.subscribe19 = function (o, f, opts) {
  10788.  
  10789. const ct_clients_ = this.clients_ || 0;
  10790. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  10791.  
  10792. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  10793.  
  10794. let objectId = ((o || 0).invalidationId || 0).objectId;
  10795. if (!objectId) return this.subscribe18.apply(this, arguments);
  10796. objectId = convertId(objectId);
  10797.  
  10798. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  10799.  
  10800. if (ct_clients_[objectId]) {
  10801. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  10802. }
  10803.  
  10804. return this.subscribe18.apply(this, arguments);
  10805. }
  10806.  
  10807. mgrProto.unsubscribe = function (o, d) {
  10808. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  10809. this.subscribe18 = this.subscribe;
  10810. this.subscribe = this.subscribe19;
  10811. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  10812. }
  10813. const ct_clients_ = this.clients_;
  10814. const ct_handles_ = this.unsubscribeAsyncHandles_;
  10815. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  10816.  
  10817. let objectId = ((o || 0).invalidationId || 0).objectId;
  10818. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  10819.  
  10820. objectId = convertId(objectId);
  10821.  
  10822.  
  10823. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  10824.  
  10825. const callbacks = this[keyCallbackStore] || 0;
  10826. const callbackObj = callbacks[objectId] || 0;
  10827.  
  10828.  
  10829. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  10830. const w = ct_clients_[objectId];
  10831. --lza;
  10832. if (lza < -1e9) lza = -1;
  10833. const qta = lza;
  10834. rafHandleHolder.push(() => {
  10835. if (qta === ct_handles_[objectId]) {
  10836. const o = {
  10837. callbacks, callbackObj,
  10838. client: ct_clients_[objectId],
  10839. handle: ct_handles_[objectId]
  10840. };
  10841. let p = 0;
  10842. try {
  10843. if (ct_clients_[objectId] === w) {
  10844. w && "function" === typeof w.dispose && w.dispose();
  10845. delete ct_clients_[objectId];
  10846. delete ct_handles_[objectId];
  10847. p = 1;
  10848. } else {
  10849. // w && "function" === typeof w.dispose && w.dispose();
  10850. // delete ct_clients_[objectId];
  10851. // delete ct_handles_[objectId];
  10852. p = 2;
  10853. }
  10854. } catch (e) {
  10855. console.warn(e);
  10856. }
  10857. console.log(`unsubscribed: ${p}`, this, o);
  10858. }
  10859. });
  10860. ct_handles_[objectId] = qta;
  10861. if (pzw === 0) {
  10862. pzw = requestAnimationFrame(rafHandlerFn);
  10863. }
  10864. }
  10865. }
  10866.  
  10867.  
  10868. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  10869.  
  10870. } else {
  10871.  
  10872. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  10873. }
  10874.  
  10875. console.log("[End]");
  10876.  
  10877. console.groupEnd();
  10878.  
  10879. }
  10880.  
  10881.  
  10882.  
  10883. /*
  10884.  
  10885.  
  10886. a.prototype.async = function(e, h) {
  10887. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  10888. }
  10889. ;
  10890. a.prototype.cancelAsync = function(e) {
  10891. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  10892. }
  10893.  
  10894. */
  10895.  
  10896.  
  10897. (FASTER_ICON_RENDERING && Promise.all(
  10898. [
  10899. customElements.whenDefined("yt-icon-shape"),
  10900. customElements.whenDefined("yt-icon")
  10901. // document.createElement('icon-shape'),
  10902. ]
  10903. )).then(() => {
  10904. let cq = 0;
  10905. let dummys = [document.createElement('yt-icon-shape'), document.createElement('yt-icon')]
  10906. for (const dummy of dummys) {
  10907. let cProto = getProto(dummy);
  10908. if (cProto && typeof cProto.shouldRenderIconShape === 'function' && !cProto.shouldRenderIconShape571 && cProto.shouldRenderIconShape.length === 1) {
  10909. assertor(() => fnIntegrity(cProto.shouldRenderIconShape, '1.70.38'));
  10910. cq++;
  10911. cProto.shouldRenderIconShape571 = cProto.shouldRenderIconShape;
  10912. cProto.shouldRenderIconShape = function (a) {
  10913. if (this.isAnimatedIcon) return this.shouldRenderIconShape571(a);
  10914. if (!this.iconType || !this.iconShapeData) return this.shouldRenderIconShape571(a);
  10915. if (!this.iconName) return this.shouldRenderIconShape571(a);
  10916. return false;
  10917. // console.log(1051, this.iconType)
  10918. // console.log(1052, this.iconShapeData)
  10919. // console.log(1053, this.isAnimatedIcon)
  10920. }
  10921. }
  10922. // if(cProto && cProto.switchTemplateAtRegistration){
  10923. // cProto.switchTemplateAtRegistration = false;
  10924. // }
  10925. }
  10926. if (cq === 1) {
  10927. console.log("modified shouldRenderIconShape - Y")
  10928. } else {
  10929. console.log("modified shouldRenderIconShape - N", cq)
  10930. }
  10931. });
  10932.  
  10933. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  10934.  
  10935. let __dummyManager__ = null;
  10936.  
  10937. mightFirstCheckOnYtInit();
  10938. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  10939. console.log("[Begin]");
  10940. (() => {
  10941.  
  10942. const tag = "yt-invalidation-continuation"
  10943. const dummy = document.createElement(tag);
  10944.  
  10945. const cProto = getProto(dummy);
  10946. if (!cProto || !cProto.attached) {
  10947. console.warn(`proto.attached for ${tag} is unavailable.`);
  10948. return;
  10949. }
  10950.  
  10951. const dummyManager = insp(dummy).manager_ || 0;
  10952. __dummyManager__ = dummyManager;
  10953.  
  10954. 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) {
  10955.  
  10956.  
  10957. const rafHub = new RAFHub();
  10958.  
  10959. rafHub.keepRAF = true;
  10960. cProto.async71 = cProto.async;
  10961. cProto.cancelAsync71 = cProto.cancelAsync;
  10962.  
  10963. // mostly for subscription timeoutMs 10000ms
  10964. let mcw = 1; // 1, 3, 5, ...
  10965. let arr = new Map();
  10966.  
  10967. let __asyncInited__ = 0;
  10968. let __timeoutStartId__ = null;
  10969. const __asyncInit__ = () => {
  10970.  
  10971. if (__asyncInited__) return;
  10972. __asyncInited__ = 1;
  10973.  
  10974. __timeoutStartId__ = setTimeout(() => { });
  10975. mcw = __timeoutStartId__ * 2 + 1;
  10976.  
  10977. setInterval(() => {
  10978.  
  10979. if (!arr.length) return;
  10980.  
  10981. const p = Date.now();
  10982. let deleteKeys = [];
  10983. arr.forEach((entry, key) => {
  10984.  
  10985.  
  10986. if (entry.cid === -1) {
  10987. entry.cid = -2;
  10988. } else if (entry.cid === -2) {
  10989.  
  10990. let offset = p - entry.add
  10991. if (offset < 0) offset = 0;
  10992. let delay2 = entry.delay - offset;
  10993. if (delay2 < 0) delay2 = 0;
  10994. entry.cid = setTimeout(entry.q(), delay2);
  10995. entry.q = null;
  10996.  
  10997. } else if (entry.add + entry.delay < p) {
  10998. deleteKeys.push(key);
  10999.  
  11000. }
  11001.  
  11002. })
  11003.  
  11004. for (const key of deleteKeys) arr.delete(key);
  11005.  
  11006. }, 2000)
  11007.  
  11008. }
  11009.  
  11010.  
  11011. cProto.async = function (e, h) {
  11012.  
  11013. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  11014.  
  11015. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  11016.  
  11017. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  11018.  
  11019.  
  11020. if (!this.__asyncInited__) {
  11021. this.__asyncInited__ = 1;
  11022. __asyncInit__();
  11023. }
  11024. mcw += 2; // 2K+3, 2K+4, ...
  11025. if (mcw > 1e9) mcw = mcw % 1e4;
  11026. const cid = mcw;
  11027. const q = () => {
  11028. return () => {
  11029. console.log('async h > 8000');
  11030. e.call(this);
  11031. }
  11032. }
  11033. // setTimeout(q, delay)
  11034. arr.set(cid, {
  11035. cid: -1, // -1 -> -2 -> cid
  11036. add: Date.now(),
  11037. q,
  11038. delay: h
  11039. });
  11040. // console.log('cid-async', cid)
  11041. return cid;
  11042.  
  11043. }
  11044.  
  11045.  
  11046. cProto.cancelAsync = function (e) {
  11047.  
  11048. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  11049.  
  11050. // console.log('cid-unasync', e)
  11051.  
  11052. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  11053.  
  11054. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  11055.  
  11056. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  11057.  
  11058. if (!arr.has(e)) return; // duplciated cancel
  11059.  
  11060. const entry = arr.get(e);
  11061. if (entry.cid < 0) {
  11062. entry.cid = 0;
  11063. arr.delete(e);
  11064. } else {
  11065. clearTimeout(entry.cid); // cid >= 1
  11066. entry.cid = 0;
  11067. arr.delete(e);
  11068. }
  11069.  
  11070. } else {
  11071.  
  11072. return this.cancelAsync71(e);
  11073.  
  11074. }
  11075.  
  11076. }
  11077.  
  11078. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  11079.  
  11080. } else if(!CHANGE_DATA_FLUSH_ASYNC){
  11081. console.log("CHANGE_DATA_FLUSH_ASYNC - N/A");
  11082. } else {
  11083. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  11084.  
  11085. }
  11086.  
  11087. })();
  11088.  
  11089. console.log("[End]");
  11090.  
  11091. console.groupEnd();
  11092.  
  11093.  
  11094.  
  11095. onManagerFound(__dummyManager__);
  11096.  
  11097. }).catch(console.warn);
  11098.  
  11099.  
  11100. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  11101.  
  11102. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  11103.  
  11104. mightFirstCheckOnYtInit();
  11105. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  11106. console.log("[Begin]");
  11107. (() => {
  11108.  
  11109. const tag = "yt-live-interactivity-component-background"
  11110. const dummy = document.createElement(tag);
  11111.  
  11112. const cProto = getProto(dummy);
  11113. if (!cProto || !cProto.attached) {
  11114. console.warn(`proto.attached for ${tag} is unavailable.`);
  11115. return;
  11116. }
  11117.  
  11118. cProto.__toStopAfterRun__ = function (hostElement) {
  11119. let mo = new MutationObserver(() => {
  11120. mo.disconnect();
  11121. mo.takeRecords();
  11122. mo = null;
  11123. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  11124. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  11125. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  11126. });
  11127. });
  11128. mo.observe(hostElement, { subtree: true, childList: true });
  11129. }
  11130.  
  11131. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  11132.  
  11133. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  11134. cProto.maybeLoadAnimationBackground = function () {
  11135. let toRun = true;
  11136. let stopAfterRun = false;
  11137. if (!this.__bypassDisableAnimationBackground__) {
  11138. let doFix = false;
  11139. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  11140. if (!this.lottieAnimation) {
  11141. doFix = true;
  11142. }
  11143. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  11144. doFix = true;
  11145. }
  11146. if (doFix) {
  11147. if (this.useAnimationBackground === true) {
  11148. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  11149. }
  11150. toRun = true;
  11151. stopAfterRun = true;
  11152. }
  11153. }
  11154. if (toRun) {
  11155. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  11156. this.__toStopAfterRun__(this.hostElement); // primary
  11157. }
  11158. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  11159. if (stopAfterRun && this.lottieAnimation) {
  11160. this.lottieAnimation.stop(); // fallback if no mutation
  11161. }
  11162. return r;
  11163. }
  11164. }
  11165.  
  11166. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - OK`);
  11167.  
  11168. } else {
  11169. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - NG`);
  11170.  
  11171. }
  11172.  
  11173. })();
  11174.  
  11175. console.log("[End]");
  11176.  
  11177. console.groupEnd();
  11178.  
  11179.  
  11180. }).catch(console.warn);
  11181.  
  11182. }
  11183.  
  11184.  
  11185. if (DELAY_FOCUSEDCHANGED) {
  11186.  
  11187. customElements.whenDefined("yt-live-chat-text-input-field-renderer").then(() => {
  11188.  
  11189.  
  11190. mightFirstCheckOnYtInit();
  11191. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-input-field-renderer hacks");
  11192. console.log("[Begin]");
  11193. (() => {
  11194.  
  11195. const tag = "yt-live-chat-text-input-field-renderer"
  11196. const dummy = document.createElement(tag);
  11197.  
  11198. const cProto = getProto(dummy);
  11199. if (!cProto || !cProto.attached) {
  11200. console.warn(`proto.attached for ${tag} is unavailable.`);
  11201. return;
  11202. }
  11203.  
  11204. if (DELAY_FOCUSEDCHANGED && typeof cProto.focusedChanged === 'function' && cProto.focusedChanged.length === 0 && !cProto.focusedChanged372) {
  11205. cProto.focusedChanged372 = cProto.focusedChanged;
  11206. cProto.focusedChanged = function () {
  11207. Promise.resolve(this).then((cnt) => {
  11208. if (cnt.isAttached === true) cnt.focusedChanged372();
  11209. });
  11210. }
  11211. }
  11212.  
  11213. })();
  11214.  
  11215. console.log("[End]");
  11216.  
  11217. console.groupEnd();
  11218.  
  11219. });
  11220.  
  11221. }
  11222.  
  11223.  
  11224. }
  11225.  
  11226.  
  11227.  
  11228.  
  11229. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  11230.  
  11231. const fixJsonParse = () => {
  11232.  
  11233. let p1 = window.onerror;
  11234.  
  11235. try {
  11236. JSON.parse("{}");
  11237. } catch (e) {
  11238. console.warn(e);
  11239. }
  11240.  
  11241. let p2 = window.onerror;
  11242.  
  11243. if (p1 !== p2) {
  11244.  
  11245.  
  11246. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  11247. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  11248. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  11249. );
  11250.  
  11251. 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");
  11252.  
  11253. console.groupEnd();
  11254.  
  11255. }
  11256.  
  11257. }
  11258.  
  11259. if (CHECK_JSONPRUNE) {
  11260. promiseForCustomYtElementsReady.then(fixJsonParse);
  11261. }
  11262.  
  11263. });
  11264.  
  11265.  
  11266.  
  11267. })({ IntersectionObserver });