YouTube 超快聊天

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

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

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.66.9
  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.gf.qytechs.cn/scripts/475632/1361351/ytConfigHacks.js
  19. //
  20. // @compatible firefox Violentmonkey
  21. // @compatible firefox Tampermonkey
  22. // @compatible firefox FireMonkey
  23. // @compatible chrome Violentmonkey
  24. // @compatible chrome Tampermonkey
  25. // @compatible opera Violentmonkey
  26. // @compatible opera Tampermonkey
  27. // @compatible safari Stay
  28. // @compatible edge Violentmonkey
  29. // @compatible edge Tampermonkey
  30. // @compatible brave Violentmonkey
  31. // @compatible brave Tampermonkey
  32. //
  33. // @description Ultimate Performance Boost for YouTube Live Chats
  34. // @description:ja YouTubeのライブチャットの究極のパフォーマンスブースト
  35. // @description:zh-TW YouTube直播聊天的終極性能提升
  36. // @description:zh-CN YouTube直播聊天的终极性能提升
  37. //
  38. // ==/UserScript==
  39.  
  40. ((__CONTEXT__) => {
  41. 'use strict';
  42.  
  43. /** @type {WeakMapConstructor} */
  44. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  45.  
  46. const DEBUG_LOG_GROUP_EXPAND = true;
  47.  
  48. // *********** DON'T REPORT NOT WORKING DUE TO THE CHANGED SETTINGS ********************
  49. // 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
  50.  
  51. 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
  52. 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)
  53. 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)
  54.  
  55. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages <<< DON'T CHANGE >>>
  56. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  57. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  58.  
  59. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  60. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  61. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  62. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  63.  
  64. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  65. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  66.  
  67. // Replace requestAnimationFrame timers with custom implementation
  68. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  69. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  70. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  71. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  72.  
  73. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  74. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  75.  
  76. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  77. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  78.  
  79. // Data Manipulation for Participants (Participant List)
  80. // << if DO_PARTICIPANT_LIST_HACKS >>
  81. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  82. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  83. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  84. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  85. // << end >>
  86.  
  87. // show more button
  88. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  89.  
  90. // faster stampDomArray_ for participants list creation
  91. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  92. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  93.  
  94. // reuse yt components
  95. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  96.  
  97. // ShadyDom Free is buggy
  98. const DISABLE_FLAGS_SHADYDOM_FREE = true;
  99.  
  100. // images <Group#I01>
  101. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  102. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  103. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  104.  
  105. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  106. // << if DO_LINK_PREFETCH >>
  107. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  108. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  109. const SKIP_PRELOAD_EMOJI = true;
  110. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  111. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  112. // << end >>
  113.  
  114. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  115. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  116. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  117.  
  118. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  119. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  120.  
  121. const ATTEMPT_ANIMATED_TICKER_BACKGROUND = ''; // false OR '' for disabled, 'linear', 'steps' for easing-function
  122. // <<<< ATTEMPT_ANIMATED_TICKER_BACKGROUND to be reviewed with memory leakage issues >>>>
  123. // << if ATTEMPT_ANIMATED_TICKER_BACKGROUND >>
  124. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  125. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  126. // [limiting 500 max steps] is recommended for "confortable visual change"
  127. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  128. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  129. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  130. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  131. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  132. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  133. 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
  134. // << end >>
  135.  
  136. const FIX_TOOLTIP_DISPLAY = true; // changed in 2024.05.02
  137. const USE_VANILLA_DEREF = true;
  138. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  139.  
  140.  
  141. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  142. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = false; // pause auto scroll faster when the context menu is about to show
  143. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  144.  
  145. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  146. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  147. const NO_ITEM_TAP_FOR_NON_STATIONARY_TAP = true; // dont open the menu (e.g. text message) if cursor is moved or long press
  148. const TAP_ACTION_DURATION = 280; // exceeding 280ms would not consider as a tap action
  149. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  150. // const FIX_MENU_CAPTURE_SCROLL = true;
  151. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  152.  
  153. const RAF_FIX_keepScrollClamped = true;
  154. const RAF_FIX_scrollIncrementally = 2; // 0: no action; 1: basic fix; 2: also fix scroll position
  155.  
  156. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  157. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  158.  
  159. const CHECK_JSONPRUNE = true; // This is a bug in Brave
  160. // << end >>
  161.  
  162. // const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = false;
  163.  
  164. const CHANGE_DATA_FLUSH_ASYNC = false;
  165. // CHANGE_DATA_FLUSH_ASYNC is disabled due to bug report: https://gf.qytechs.cn/scripts/469878/discussions/199479
  166. // to be further investigated
  167.  
  168. const CHANGE_MANAGER_UNSUBSCRIBE = true;
  169.  
  170. const INTERACTIVITY_BACKGROUND_ANIMATION = 1; // mostly for pinned message
  171. // 0 = default Yt animation background [= no fix];
  172. // 1 = disable default animation background [= keep special animation];
  173. // 2 = disable all animation backgrounds [= no animation backbround]
  174.  
  175. const CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED = true;
  176.  
  177. const MAX_TOOLTIP_NO_WRAP_WIDTH = '72vw'; // '' for disable; accept values like '60px', '25vw'
  178.  
  179.  
  180.  
  181. // (Dec 2024: AMEND_TICKER_handleLiveChatAction to be removed)
  182. const AMEND_TICKER_handleLiveChatAction = false; // to fix ticker duplication and unresponsively fast ticker generation
  183. // AMEND_TICKER_handleLiveChatAction to be fixed (2024.05.21)
  184.  
  185. // (Dec 2024: AMEND_TICKER_handleLiveChatAction_v3 to be removed)
  186. const AMEND_TICKER_handleLiveChatAction_v3 = false; // responsiveness fix (Major Feature)
  187.  
  188. const USE_ADVANCED_TICKING = true; // added in Dec 2024 v0.66.0; need to ensure it would not affect the function if ticker design changed. to be reviewed
  189. // const END_ANIMATING_TICKERS = true; // added in Dec 2024 v0.66.5; see pressure test like https://www.youtube.com/watch?v=CQaUs-vNgXo
  190. const FIX_TIMESTAMP_FOR_REPLAY = true;
  191.  
  192.  
  193. const ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION = true;
  194. const ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME = true;
  195. const FIX_BATCH_TICKER_ORDER = true;
  196.  
  197. const DISABLE_Translation_By_Google = true;
  198.  
  199. const FASTER_ICON_RENDERING = true;
  200.  
  201. const DELAY_FOCUSEDCHANGED = true;
  202.  
  203. const skipErrorForhandleAddChatItemAction_ = true; // currently depends on ENABLE_NO_SMOOTH_TRANSFORM
  204. const fixChildrenIssue801 = true; // if __children801__ is set [fix polymer controller method extration for `.set()`]
  205.  
  206. const SUPPRESS_refreshOffsetContainerHeight_ = true; // added in FEB 2024; true for default layout options; no effect if ENABLE_NO_SMOOTH_TRANSFORM is false
  207.  
  208. const NO_FILTER_DROPDOWN_BORDER = true; // added in 2024.03.02
  209.  
  210. const FIX_ANIMATION_TICKER_TEXT_POSITION = true; // CSS fix; experimental; added in 2024.04.07
  211. const FIX_AUTHOR_CHIP_BADGE_POSITION = true;
  212.  
  213. const FIX_ToggleRenderPolymerControllerExtractionBug = false; // to be reviewed
  214.  
  215. const REACTION_ANIMATION_PANEL_CSS_FIX = true;
  216.  
  217. // -------------------------------
  218.  
  219. const USE_OBTAIN_LCR_BY_BOTH_METHODS = false; // true for play safe
  220.  
  221. const FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP = true; // To fix Memory Leakage in yt-live-chat-ticker-...-item-renderer
  222. const FIX_MEMORY_LEAKAGE_TICKER_STATSBAR = true; // To fix Memory Leakage in updateStatsBarAndMaybeShowAnimation
  223. const FIX_MEMORY_LEAKAGE_TICKER_TIMER = true; // To fix Memory Leakage in setContainerWidth, slideDown, collapse // Dec 2024 fix in advance tickering
  224. const FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth = true; // To fix Memory Leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth()
  225.  
  226. // leakage in ytd-sponsorships-live-chat-gift-purchase-announcement-renderer - to be confirmed
  227.  
  228. // <<<<< FOR MEMORY LEAKAGE >>>>
  229. const DEBUG_wmList = false;
  230. let DEBUG_wmList_started = false;
  231. // const FLAG_001 = true;
  232. const FLAG_001a = false;
  233. const FLAG_001b = false;
  234. const FLAG_001c = false;
  235. const FLAG_001d = false;
  236. const FLAG_001e = false;
  237. const FLAG_001f = false;
  238. // const FLAG_001g = true;
  239.  
  240.  
  241.  
  242. /**
  243. *
  244. *
  245. *
  246. *
  247. *
  248. rendererStamperObserver_: function(a, b, c) {
  249. if (c.path == a) {
  250. if (c.value === void 0 && !this.hasDataPath_[a])
  251. return;
  252. this.hasDataPath_[a] = c.value !== void 0
  253. }
  254. this.rendererStamperApplyChangeRecord_(a, b, c)
  255. },
  256.  
  257.  
  258. addStampDomObserverFns_: function() {
  259. for (var a in this.stampDom) {
  260. var b = this.stampDom[a];
  261. b.id ? (this[SQa(b.id)] = this.rendererStamperObserver_.bind(this, a, b.id),
  262. this.hasDataPath_[a] = !1) : Er(new Dn("Bad rendererstamper config",this.is + ":" + a))
  263. }
  264. },
  265. *
  266. *
  267. *
  268. *
  269. *
  270. */
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277. // <<<<< FOR MEMORY LEAKAGE >>>>
  278.  
  279. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  280. /*
  281.  
  282. ### Time Approach
  283.  
  284. // all below values can make the time interval > 250ms
  285. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  286. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  287. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  288. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  289. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  290. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  291.  
  292. ### Pixel Check
  293. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  294. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  295. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  296.  
  297. ### Example - totalDuration = 280000
  298. totalDuration 280000
  299. stepInterval 0.5
  300. numOfSteps = Math.round(100 / stepInterval) = 200
  301. time interval = 280000 / 200 = 1400ms <acceptable>
  302.  
  303. ### Example - totalDuration = 18000
  304. totalDuration 18000
  305. stepInterval 5
  306. numOfSteps = Math.round(100 / stepInterval) = 20
  307. time interval = 18000 / 20 = 900ms <acceptable>
  308.  
  309. ### Example - totalDuration = 5000
  310. totalDuration 5000
  311. stepInterval 5
  312. numOfSteps = Math.round(100 / stepInterval) = 20
  313. time interval = 5000 / 20 = 250ms <threshold value>
  314.  
  315. ### Example - totalDuration = 3600
  316. totalDuration 3600
  317. stepInterval 5
  318. numOfSteps = Math.round(100 / stepInterval) = 20
  319. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  320.  
  321. */
  322.  
  323. // =======================================================================================================
  324.  
  325. // AUTOMAICALLY DETERMINED
  326. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  327. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  328. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  329. let runTickerClassName = 'run-ticker';
  330.  
  331. const dummyImgURL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  332. /*
  333. WebP: data:image/webp;base64,UklGRjAB
  334. PNG: data:image/png;base64,iVBORw0KGg==
  335. JPEG: data:image/jpeg;base64,/9j/4AA=
  336. GIF: data:image/gif;base64,R0lGODlhAQABAIA=
  337. BMP: data:image/bmp;base64,Qk1oAAAA
  338. SVG: data:image/svg+xml;base64,PHN2Zy8+Cg==
  339.  
  340. WebP: data:image/webp;base64,AAAAAAA=
  341. PNG: data:image/png;base64,AAAAAAA=
  342. JPEG: data:image/jpeg;base64,AAAAAAA=
  343. GIF: data:image/gif;base64,AAAAAAA=
  344. BMP: data:image/bmp;base64,AAAAAAA=
  345.  
  346. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  347.  
  348.  
  349. */
  350.  
  351. // image sizing code
  352. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  353.  
  354.  
  355. // function KC(a, b, c, d) {
  356. // d = void 0 === d ? "width" : d;
  357. // if (!a || !a.length)
  358. // return null;
  359. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  360. // var e = window.devicePixelRatio;
  361. // 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"));
  362. // HC = e
  363. // } else
  364. // HC || (HC = window.devicePixelRatio);
  365. // e = HC;
  366. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  367. // if (z("kevlar_tuner_min_thumbnail_quality"))
  368. // return a[0].url || null;
  369. // e = a.length;
  370. // if (z("kevlar_tuner_max_thumbnail_quality"))
  371. // return a[e - 1].url || null;
  372. // if (c)
  373. // for (var h = 0; h < e; h++)
  374. // if (0 <= a[h].url.indexOf(c))
  375. // return a[h].url || null;
  376. // for (c = 0; c < e; c++)
  377. // if (a[c][d] >= b)
  378. // return a[c].url || null;
  379. // for (b = e - 1; 0 < b; b--)
  380. // if (a[b][d])
  381. // return a[b].url || null;
  382. // return a[0].url || null
  383. // }
  384.  
  385. const { IntersectionObserver } = __CONTEXT__;
  386. let _x69;
  387. try {
  388. _x69 = document.createAttributeNS("http://www.w3.org/2000/svg", "nil").addEventListener;
  389. } catch (e) { }
  390. const pureAddEventListener = _x69;
  391. if (!pureAddEventListener) return console.warn("pureAddEventListener cannot be obtained.");
  392.  
  393. /** @type {globalThis.PromiseConstructor} */
  394. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  395.  
  396. // let jsonParseFix = null;
  397.  
  398. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  399. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  400.  
  401. // necessity of cssText3_smooth_transform_position to be checked.
  402. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  403.  
  404. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  405. position: static !important;
  406. }
  407.  
  408. `: '';
  409.  
  410. // fallback if dummy style fn fails
  411. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  412.  
  413. /* optional */
  414. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  415. height: auto !important;
  416. min-height: unset !important;
  417. }
  418.  
  419. #items.style-scope.yt-live-chat-item-list-renderer {
  420. transform: translateY(0px) !important;
  421. }
  422.  
  423. /* optional */
  424.  
  425. `: '';
  426.  
  427. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  428.  
  429. /* ------------------------------------------------------------------------------------------------------------- */
  430.  
  431. 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 {
  432. contain: layout style;
  433. }
  434.  
  435. #items.style-scope.yt-live-chat-item-list-renderer {
  436. contain: layout paint style;
  437. }
  438.  
  439. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  440. contain: style;
  441. }
  442.  
  443. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  444. contain: size style;
  445. }
  446.  
  447. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  448. contain: size layout paint style;
  449. }
  450.  
  451. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  452. contain: layout paint style;
  453. }
  454.  
  455. 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 {
  456. contain: layout style;
  457. }
  458.  
  459. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  460. contain: layout paint style;
  461. }
  462.  
  463. /* ------------------------------------------------------------------------------------------------------------- */
  464.  
  465. ` : '';
  466.  
  467. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  468.  
  469. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  470. top: 4px;
  471. transition-property: top;
  472. bottom: unset;
  473. }
  474.  
  475. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  476. top: -42px;
  477. }
  478.  
  479. `: '';
  480.  
  481. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  482.  
  483. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  484. contain: layout style;
  485. }
  486.  
  487. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  488. overflow: visible;
  489. }
  490.  
  491. `: '';
  492.  
  493. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  494.  
  495. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  496. --yt-live-chat-action-panel-top-border: none;
  497. }
  498.  
  499. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  500. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  501. }
  502.  
  503. html #panel-pages.yt-live-chat-renderer {
  504. border-top: 0;
  505. border-bottom: 0;
  506. }
  507.  
  508. `: '';
  509.  
  510. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  511.  
  512. img,
  513. yt-img-shadow[height][width],
  514. yt-img-shadow {
  515. content-visibility: visible !important;
  516. }
  517.  
  518. ` : '';
  519.  
  520. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  521.  
  522. /* remove YouTube constant will-change */
  523. /* constant value will slow down the performance; default auto */
  524.  
  525. /* www-player.css */
  526. html .ytp-contextmenu,
  527. html .ytp-settings-menu {
  528. will-change: unset;
  529. }
  530.  
  531. /* frequently matched elements */
  532. html .fill.yt-interaction,
  533. html .stroke.yt-interaction,
  534. html .yt-spec-touch-feedback-shape__fill,
  535. html .yt-spec-touch-feedback-shape__stroke {
  536. will-change: unset;
  537. }
  538.  
  539. /* live_chat_polymer.js */
  540. /*
  541. html .toggle-button.tp-yt-paper-toggle-button,
  542. html #primaryProgress.tp-yt-paper-progress,
  543. html #secondaryProgress.tp-yt-paper-progress,
  544. html #onRadio.tp-yt-paper-radio-button,
  545. html .fill.yt-interaction,
  546. html .stroke.yt-interaction,
  547. html .yt-spec-touch-feedback-shape__fill,
  548. html .yt-spec-touch-feedback-shape__stroke {
  549. will-change: unset;
  550. }
  551. */
  552.  
  553. /* desktop_polymer_enable_wil_icons.js */
  554. /* html .fill.yt-interaction,
  555. html .stroke.yt-interaction, */
  556. html tp-yt-app-header::before,
  557. html tp-yt-iron-list,
  558. html #items.tp-yt-iron-list > *,
  559. html #onRadio.tp-yt-paper-radio-button,
  560. html .toggle-button.tp-yt-paper-toggle-button,
  561. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  562. html #items.ytd-post-multi-image-renderer,
  563. html #items.ytd-horizontal-card-list-renderer,
  564. html #items.yt-horizontal-list-renderer,
  565. html #left-arrow.yt-horizontal-list-renderer,
  566. html #right-arrow.yt-horizontal-list-renderer,
  567. html #items.ytd-video-description-infocards-section-renderer,
  568. html #items.ytd-video-description-music-section-renderer,
  569. html #chips.ytd-feed-filter-chip-bar-renderer,
  570. html #chips.yt-chip-cloud-renderer,
  571. html #items.ytd-merch-shelf-renderer,
  572. html #items.ytd-product-details-image-carousel-renderer,
  573. html ytd-video-preview,
  574. html #player-container.ytd-video-preview,
  575. html #primaryProgress.tp-yt-paper-progress,
  576. html #secondaryProgress.tp-yt-paper-progress,
  577. html ytd-miniplayer[enabled] /* ,
  578. html .yt-spec-touch-feedback-shape__fill,
  579. html .yt-spec-touch-feedback-shape__stroke */ {
  580. will-change: unset;
  581. }
  582.  
  583. /* other */
  584. .ytp-videowall-still-info-content[class],
  585. .ytp-suggestion-image[class] {
  586. will-change: unset !important;
  587. }
  588.  
  589. ` : '';
  590.  
  591. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  592. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  593.  
  594. elzm-fonts {
  595. visibility: collapse;
  596. position: fixed;
  597. top: -10px;
  598. left: -10px;
  599. font-size: 10pt;
  600. line-height: 100%;
  601. width: 100px;
  602. height: 100px;
  603. transform: scale(0.1);
  604. transform: scale(0.01);
  605. transform: scale(0.001);
  606. transform-origin: 0 0;
  607. contain: strict;
  608. display: block;
  609.  
  610. pointer-events: none !important;
  611. user-select: none !important;
  612. }
  613.  
  614. elzm-fonts[id]#elzm-fonts-yk75g {
  615. user-select: none !important;
  616. pointer-events: none !important;
  617. }
  618.  
  619. elzm-font {
  620. visibility: collapse;
  621. position: absolute;
  622. line-height: 100%;
  623. width: 100px;
  624. height: 100px;
  625. contain: strict;
  626. display: block;
  627.  
  628. user-select: none !important;
  629. pointer-events: none !important;
  630. }
  631.  
  632. elzm-font::before {
  633. visibility: collapse;
  634. position: absolute;
  635. line-height: 100%;
  636. width: 100px;
  637. height: 100px;
  638. contain: strict;
  639. display: block;
  640.  
  641. 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';
  642.  
  643. user-select: none !important;
  644. pointer-events: none !important;
  645. }
  646.  
  647. `: '';
  648.  
  649. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  650. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  651. -webkit-backdrop-filter: none;
  652. backdrop-filter: none;
  653. }
  654. `: '';
  655.  
  656. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  657.  
  658. @keyframes blinker-miuzp {
  659. 0%, 60%, 100% {
  660. opacity: 1;
  661. }
  662. 30% {
  663. opacity: 0.6;
  664. }
  665. }
  666.  
  667. yt-icon-button#show-more.has-new-messages-miuzp {
  668. animation: blinker-miuzp 1.74s linear infinite;
  669. }
  670.  
  671. `: '';
  672.  
  673. const cssText11_entire_message_clickable = FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK ? `
  674.  
  675. yt-live-chat-paid-message-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-membership-item-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-paid-sticker-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  684. pointer-events: none !important;
  685. }
  686.  
  687. yt-live-chat-text-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  688. pointer-events: none !important; /* TO_BE_REVIEWED */
  689. }
  690.  
  691. yt-live-chat-auto-mod-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  692. pointer-events: none !important;
  693. }
  694.  
  695. `: '';
  696.  
  697. const cssText12_nowrap_tooltip = MAX_TOOLTIP_NO_WRAP_WIDTH && typeof MAX_TOOLTIP_NO_WRAP_WIDTH === 'string' ? `
  698.  
  699.  
  700. tp-yt-paper-tooltip[role="tooltip"] {
  701. box-sizing: content-box !important;
  702. margin: 0px !important;
  703. padding: 0px !important;
  704. contain: none !important;
  705. }
  706.  
  707. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"] {
  708. box-sizing: content-box !important;
  709. display: inline-block;
  710. contain: none !important;
  711. }
  712.  
  713.  
  714. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"]{
  715. max-width: ${MAX_TOOLTIP_NO_WRAP_WIDTH};
  716. width: max-content;
  717. text-overflow: ellipsis;
  718. overflow: hidden;
  719. white-space: nowrap;
  720. }
  721.  
  722.  
  723. `: '';
  724.  
  725.  
  726. const cssText13_no_text_select_when_menu_visible = `
  727. [menu-visible] {
  728. --sfc47-text-select: none;
  729. }
  730. [menu-visible] #header[id][class],
  731. [menu-visible] #content[id][class],
  732. [menu-visible] #header[id][class] *,
  733. [menu-visible] #content[id][class] * {
  734. user-select: var(--sfc47-text-select) !important;
  735. }
  736. [menu-visible] #menu {
  737. --sfc47-text-select: inherit;
  738. }
  739. `;
  740.  
  741. const cssText14_NO_FILTER_DROPDOWN_BORDER = NO_FILTER_DROPDOWN_BORDER ? `
  742. yt-live-chat-header-renderer.yt-live-chat-renderer #label.yt-dropdown-menu::before {
  743. border:0;
  744. }
  745. ` : '';
  746.  
  747. const cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION = FIX_ANIMATION_TICKER_TEXT_POSITION ? `
  748. .style-scope.yt-live-chat-ticker-renderer #animation-container[id][class] {
  749. position: relative;
  750. display: grid;
  751. grid-auto-columns: 1fr;
  752. grid-auto-rows: 1fr;
  753. grid-template-columns: repeat(1, 1fr);
  754. gap: 7px;
  755. padding-bottom: 0;
  756. margin-bottom: 0;
  757. padding-top: 0;
  758. align-self: flex-start;
  759. flex-wrap: nowrap;
  760. margin-top: 1px;
  761. }
  762.  
  763. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class] {
  764. margin-top: 0px;
  765. margin-bottom: 0px;
  766. flex-direction: row;
  767. flex-wrap: nowrap;
  768. align-items: center;
  769. justify-content: flex-start;
  770. }
  771.  
  772. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class]:first-child::after {
  773. content: '補';
  774. visibility: collapse;
  775. display: inline-block;
  776. position: relative;
  777. width: 0;
  778. line-height: 22px;
  779. }
  780.  
  781. ` : '';
  782.  
  783. const cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION = FIX_AUTHOR_CHIP_BADGE_POSITION ? `
  784. #card #author-name-chip > yt-live-chat-author-chip[single-line] {
  785. flex-wrap: nowrap;
  786. white-space: nowrap;
  787. display: inline-flex;
  788. flex-direction: row;
  789. text-wrap: nowrap;
  790. flex-shrink: 0;
  791. align-items: center;
  792. }
  793.  
  794. #card #author-name-chip {
  795. display: inline-flex;
  796. flex-direction: row;
  797. align-items: flex-start;
  798. }
  799. `: '';
  800.  
  801.  
  802. // Example: https://www.youtube.com/watch?v=Xfytz-igsuc
  803. const cssText17_FIX_overwidth_banner_message = `
  804. yt-live-chat-banner-manager#live-chat-banner.style-scope.yt-live-chat-item-list-renderer {
  805. max-width: 100%;
  806. box-sizing: border-box;
  807. }
  808. `;
  809.  
  810.  
  811. const cssText18_REACTION_ANIMATION_PANEL_CSS_FIX = REACTION_ANIMATION_PANEL_CSS_FIX ? `
  812. #reaction-control-panel-overlay[class] {
  813. contain: strict;
  814. margin: 0;
  815. padding: 0;
  816. border: 0;
  817. box-sizing: border-box;
  818. will-change: initial;
  819. }
  820. #reaction-control-panel-overlay[class] *[class] {
  821. will-change: initial;
  822. }
  823. `: '';
  824.  
  825. const cssText19_FOR_ADVANCED_TICKING =`
  826. ticker-bg-overlay {
  827. display: block;
  828. position: absolute;
  829. z-index: -1;
  830. box-sizing: border-box;
  831. border: 0;
  832. padding: 0;
  833. margin: 0;
  834. width: 200%;
  835. top: 0;
  836. bottom: 0;
  837. left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  838. contain: strict;
  839. }
  840. ticker-bg-overlay-end2 {
  841.  
  842. all:unset;
  843. position: fixed;
  844. display: block;
  845. margin-left: -0.5px;
  846. top: 8px;
  847. left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  848.  
  849. width: 1px;
  850. height: 1px;
  851. opacity: 0;
  852. pointer-events: none;
  853. box-sizing: border-box;
  854. border: 0;
  855. padding: 0;
  856. margin: 0;
  857. contain: strict;
  858. z-index: -1;
  859. visibility: collapse;
  860.  
  861. }
  862.  
  863.  
  864. .r6-width-adjustable ~ .r6-width-adjustable {
  865. --r6-min-width: max-content;
  866. }
  867. .r6-closing-ticker[class] {
  868. --r6-min-width: 0px;
  869. }
  870. .r6-width-adjustable {
  871. min-width: var(--r6-min-width, 0px);
  872. }
  873.  
  874. `;
  875. // const cssText19_FOR_ADVANCED_TICKING = `
  876. // ticker-bg-overlay {
  877. // display: block;
  878. // position: absolute;
  879. // z-index: -1;
  880. // box-sizing: border-box;
  881. // border: 0;
  882. // padding: 0;
  883. // margin: 0;
  884. // width: 200%;
  885. // top: 0;
  886. // bottom: 0;
  887. // left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  888. // contain: strict;
  889. // }
  890. // /*
  891. // ticker-bg-overlay-end {
  892. // position: absolute;
  893. // right: 0px;
  894. // top: 50%;
  895. // display: block;
  896. // width: 1px;
  897. // height: 1px;
  898. // opacity: 0;
  899. // pointer-events: none;
  900. // box-sizing: border-box;
  901. // border: 0;
  902. // padding: 0;
  903. // margin: 0;
  904. // contain: strict;
  905. // }
  906. // */
  907.  
  908. // ticker-bg-overlay-end2 {
  909.  
  910. // all:unset;
  911. // position: fixed;
  912. // display: block;
  913. // margin-left: -0.5px;
  914. // top: 8px;
  915. // left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  916.  
  917. // width: 1px;
  918. // height: 1px;
  919. // opacity: 0;
  920. // pointer-events: none;
  921. // box-sizing: border-box;
  922. // border: 0;
  923. // padding: 0;
  924. // margin: 0;
  925. // contain: strict;
  926. // z-index: -1;
  927. // visibility: collapse;
  928.  
  929. // }
  930.  
  931. // /* USE_ADVANCED_TICKING */
  932.  
  933. // /*
  934.  
  935. // .ticker-no-transition-time, .ticker-no-transition-time [id] {
  936. // transition-duration: 0s !important;
  937. // }
  938.  
  939. // [r6-advanced-ticking] .style-scope.yt-live-chat-ticker-renderer ~ .style-scope.yt-live-chat-ticker-renderer:not(.r6-closing-ticker) {
  940. // transition-duration: 0s !important;
  941. // }
  942.  
  943. // */
  944.  
  945. // .r6-width-adjustable ~ .r6-width-adjustable {
  946. // --r6-min-width: max-content;
  947. // }
  948.  
  949. // .r6-closing-ticker[class] {
  950. // --r6-min-width: 0px;
  951. // }
  952.  
  953. // .r6-width-adjustable {
  954. // min-width: var(--r6-min-width, 0px);
  955. // }
  956.  
  957.  
  958. // /*
  959.  
  960.  
  961. // .r6-width-adjustable {
  962. // transition-duration: var(--r6-transition-duration, 0s) !important;
  963. // }
  964.  
  965. // .r6-width-adjustable-first {
  966. // --r6-transition-duration: 0.2s;
  967. // }
  968.  
  969. // .r6-width-adjustable ~ .r6-width-adjustable-first {
  970. // --r6-transition-duration: 0s;
  971. // }
  972.  
  973. // .r6-closing-ticker {
  974. // --r6-transition-duration: 0.2s;
  975. // }
  976. // */
  977.  
  978. // /*
  979.  
  980.  
  981. // ey.style.position = 'absolute';
  982. // ey.style.right = '0px';
  983. // ey.style.top = '50%';
  984. // ey.style.display='block';
  985. // ey.style.width='1px';
  986. // ey.style.height='1px';
  987. // ey.style.opacity = '0';
  988.  
  989. // em.style.display = 'block';
  990. // em.style.position = 'absolute';
  991. // em.style.boxSizing = 'border-box';
  992. // em.style.width = '200%';
  993. // em.style.top = '0';
  994. // em.style.bottom = '0';
  995. // // em.style.height = '100%';
  996.  
  997.  
  998. // // em.style.left = '-50%';
  999. // // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  1000.  
  1001. // */
  1002.  
  1003. // `;
  1004.  
  1005. const addCss = () => `
  1006.  
  1007. @property --ticker-rtime {
  1008. syntax: "<percentage>";
  1009. inherits: false;
  1010. initial-value: 0%;
  1011. }
  1012.  
  1013. /*
  1014. .run-ticker {
  1015. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  1016. }
  1017.  
  1018. .run-ticker-test {
  1019. background: #00000001;
  1020. }
  1021.  
  1022. .run-ticker-forced,
  1023. yt-live-chat-ticker-renderer #items > * > #container.run-ticker-forced,
  1024. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker-forced[class]
  1025. {
  1026. background:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2)) !important;
  1027. }
  1028. */
  1029.  
  1030. .run-ticker {
  1031. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  1032. }
  1033.  
  1034. .run-ticker,
  1035. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  1036. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  1037. {
  1038. background: var(--ticker-bg) !important;
  1039. }
  1040.  
  1041. yt-live-chat-ticker-dummy777-item-renderer {
  1042. background: #00000001;
  1043. }
  1044.  
  1045. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  1046. position: fixed !important;
  1047. top: -1000px !important;
  1048. left: -1000px !important;
  1049. font-size: 1px !important;
  1050. color: transparent !important;
  1051. pointer-events: none !important;
  1052. z-index: -1 !important;
  1053. contain: strict !important;
  1054. box-sizing: border-box !important;
  1055. pointer-events: none !important;
  1056. user-select: none !important;
  1057. max-width: 1px !important;
  1058. max-height: 1px !important;
  1059. overflow: hidden !important;
  1060. visibility: collapse !important;
  1061. display: none !important;
  1062. }
  1063.  
  1064. yt-live-chat-ticker-dummy777-item-renderer #container {
  1065. background: inherit;
  1066. }
  1067.  
  1068.  
  1069. ${cssText8_fonts_pre_render}
  1070.  
  1071. ${cssText9_no_backdrop_filter_when_menu_shown}
  1072.  
  1073. @supports (contain: layout paint style) {
  1074.  
  1075. ${cssText5}
  1076.  
  1077. }
  1078.  
  1079. @supports (color: var(--general)) {
  1080.  
  1081. html {
  1082. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  1083. }
  1084.  
  1085. ${cssText3_smooth_transform_position}
  1086.  
  1087. ${cssText7c_will_change_unset}
  1088.  
  1089. ${cssText7b_content_visibility_unset}
  1090.  
  1091. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  1092. overflow-y: scroll;
  1093. padding-right: 0;
  1094. }
  1095.  
  1096. ${cssText4_smooth_transform_forced_props}
  1097.  
  1098. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  1099. pointer-events: none !important;
  1100. }
  1101.  
  1102. #continuations, #continuations * {
  1103. contain: strict;
  1104. position: fixed;
  1105. top: 2px;
  1106. height: 1px;
  1107. width: 2px;
  1108. height: 1px;
  1109. visibility: collapse;
  1110. }
  1111.  
  1112. ${cssText6b_show_more_button}
  1113.  
  1114. ${cssText6d_input_panel_border}
  1115.  
  1116. ${cssText6c_input_panel_overflow}
  1117.  
  1118. }
  1119.  
  1120.  
  1121. @supports (overflow-anchor: auto) {
  1122.  
  1123. .no-anchor * {
  1124. overflow-anchor: none;
  1125. }
  1126. .no-anchor > item-anchor {
  1127. overflow-anchor: auto;
  1128. }
  1129.  
  1130. item-anchor {
  1131.  
  1132. height:1px;
  1133. width: 100%;
  1134. transform: scaleY(0.00001);
  1135. transform-origin:0 0;
  1136. contain: strict;
  1137. opacity:0;
  1138. display:flex;
  1139. position:relative;
  1140. flex-shrink:0;
  1141. flex-grow:0;
  1142. margin-bottom:0;
  1143. overflow:hidden;
  1144. box-sizing:border-box;
  1145. visibility: visible;
  1146. content-visibility: visible;
  1147. contain-intrinsic-size: auto 1px;
  1148. pointer-events:none !important;
  1149.  
  1150. }
  1151.  
  1152. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  1153. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  1154. }
  1155.  
  1156. html item-anchor {
  1157.  
  1158. height: 1px;
  1159. width: 1px;
  1160. top: auto;
  1161. left: auto;
  1162. right: auto;
  1163. bottom: auto;
  1164. transform: translateY(-1px);
  1165. position: absolute;
  1166. z-index: -1;
  1167.  
  1168. }
  1169.  
  1170. }
  1171.  
  1172. @supports (color: var(--pre-rendering)) {
  1173.  
  1174. @keyframes dontRenderAnimation {
  1175. 0% {
  1176. background-position-x: 3px;
  1177. }
  1178. 100% {
  1179. background-position-x: 4px;
  1180. }
  1181. }
  1182.  
  1183. .dont-render[class] {
  1184. /* visibility: collapse !important; */
  1185. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://gf.qytechs.cn/scripts/469878/discussions/197267 */
  1186.  
  1187. transform: scale(0.01) !important;
  1188. transform: scale(0.00001) !important;
  1189. transform: scale(0.0000001) !important;
  1190. transform-origin: 0 0 !important;
  1191. z-index: -1 !important;
  1192. contain: strict !important;
  1193. box-sizing: border-box !important;
  1194.  
  1195. height: 1px !important;
  1196. height: 0.1px !important;
  1197. height: 0.01px !important;
  1198. height: 0.0001px !important;
  1199. height: 0.000001px !important;
  1200.  
  1201. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  1202.  
  1203. pointer-events: none !important;
  1204. user-select: none !important;
  1205.  
  1206. }
  1207.  
  1208. #sk35z {
  1209. display: block !important;
  1210.  
  1211. visibility: collapse !important;
  1212.  
  1213. transform: scale(0.01) !important;
  1214. transform: scale(0.00001) !important;
  1215. transform: scale(0.0000001) !important;
  1216. transform-origin: 0 0 !important;
  1217. z-index: -1 !important;
  1218. contain: strict !important;
  1219. box-sizing: border-box !important;
  1220.  
  1221. height: 1px !important;
  1222. height: 0.1px !important;
  1223. height: 0.01px !important;
  1224. height: 0.0001px !important;
  1225. height: 0.000001px !important;
  1226.  
  1227. position: absolute !important;
  1228. top: -1000px !important;
  1229. left: -1000px !important;
  1230.  
  1231. }
  1232.  
  1233. }
  1234.  
  1235. [rNgzQ] {
  1236. opacity: 0 !important;
  1237. pointer-events: none !important;
  1238. }
  1239.  
  1240.  
  1241. ${cssText10_show_more_blinker}
  1242.  
  1243. ${cssText11_entire_message_clickable}
  1244.  
  1245. ${cssText12_nowrap_tooltip}
  1246.  
  1247. ${cssText13_no_text_select_when_menu_visible}
  1248.  
  1249. ${cssText14_NO_FILTER_DROPDOWN_BORDER}
  1250.  
  1251. ${cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION}
  1252.  
  1253. ${cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION}
  1254.  
  1255. ${cssText17_FIX_overwidth_banner_message}
  1256.  
  1257. ${cssText18_REACTION_ANIMATION_PANEL_CSS_FIX}
  1258.  
  1259. ${cssText19_FOR_ADVANCED_TICKING}
  1260.  
  1261. `;
  1262.  
  1263.  
  1264. const konsole = {
  1265. nil: Symbol(),
  1266. logs: [],
  1267. style: '',
  1268. log(...args) {
  1269. konsole.logs.push({
  1270. type: 'log',
  1271. msg: [konsole.tag || konsole.nil, ...args, konsole.style || konsole.nil].filter(e => e !== konsole.nil)
  1272. });
  1273. },
  1274. setTag(tag) {
  1275. konsole.tag = tag;
  1276. },
  1277. setStyle(style) {
  1278. konsole.style = style;
  1279. },
  1280. groupCollapsed(...args) {
  1281.  
  1282. konsole.logs.push({
  1283. type: 'groupCollapsed',
  1284. msg: [...args].filter(e => e !== konsole.nil)
  1285. });
  1286. },
  1287. groupEnd() {
  1288.  
  1289. konsole.logs.push({
  1290. type: 'groupEnd'
  1291. })
  1292. },
  1293. print() {
  1294. const copy = konsole.logs.slice(0);
  1295. konsole.logs.length = 0;
  1296. for (const { type, msg } of copy) {
  1297. if (type === 'log') {
  1298. console.log(...msg)
  1299. } else if (type === 'groupCollapsed') {
  1300.  
  1301. console.groupCollapsed(...msg)
  1302. } else if (type === 'groupEnd') {
  1303. console.groupEnd();
  1304. }
  1305.  
  1306. }
  1307.  
  1308. }
  1309. };
  1310.  
  1311. /*
  1312. konsole.groupCollapsedX = (text1, text2) => {
  1313.  
  1314. if(!text2){
  1315.  
  1316. konsole.groupCollapsed(`%c${text1}`,
  1317. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;"
  1318. );
  1319. }else{
  1320.  
  1321. konsole.groupCollapsed(`%c${text1}%c${text2}`,
  1322. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1323. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1324. );
  1325. }
  1326. }
  1327.  
  1328. konsole.groupCollapsedX('YouTube Super Fast Chat');
  1329.  
  1330. setTimeout(()=>{
  1331.  
  1332. konsole.setTag('[[Fonts Pre-Rendering]]');
  1333. konsole.log(123);
  1334. konsole.log('wsd',332, 'ssa');
  1335. konsole.setTag('');
  1336. }, 100);
  1337.  
  1338. setTimeout(()=>{
  1339.  
  1340. konsole.setTag('[[Fonts Pre-Rendering 2]]');
  1341. konsole.log(123);
  1342. konsole.log('wsd',332, 'ssa');
  1343. konsole.setTag('');
  1344. }, 300);
  1345.  
  1346. setTimeout(()=>{
  1347.  
  1348. konsole.groupEnd();
  1349. konsole.print();
  1350. }, 1000);
  1351.  
  1352. */
  1353.  
  1354. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  1355.  
  1356. // Create a unique key for the script and check if it is already running
  1357. const hkey_script = 'mchbwnoasqph';
  1358. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  1359. win[hkey_script] = true;
  1360.  
  1361. let unexpectedErr = "";
  1362.  
  1363. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  1364.  
  1365. let te4 = setTimeout(() => { }); // dummy; skip timerId only;
  1366. if (te4 < 3) {
  1367. setTimeout(() => { });
  1368. setTimeout(() => { });
  1369. }
  1370.  
  1371. }
  1372.  
  1373. const firstKey = (obj) => {
  1374. for (const key in obj) {
  1375. if (obj.hasOwnProperty(key)) return key;
  1376. }
  1377. return null;
  1378. }
  1379.  
  1380. const firstObjectKey = (obj) => {
  1381. for (const key in obj) {
  1382. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1383. }
  1384. return null;
  1385. }
  1386.  
  1387. /**
  1388. * Takes in a __SORTED__ array and inserts the provided value into
  1389. * the correct, sorted, position.
  1390. * > https://github.com/bhowell2/binary-insert-js/
  1391. * @param array the sorted array where the provided value needs to be inserted (in order)
  1392. * @param insertValue value to be added to the array
  1393. * @param comparator function that helps determine where to insert the value (
  1394. */
  1395. function binaryInsert(array, insertValue, comparator) {
  1396. let left = 0;
  1397. let right = array.length;
  1398.  
  1399. let z;
  1400. // Directly return if array is empty or the insertValue should be at the end
  1401. if (right === 0 || (z = comparator(array[right - 1], insertValue)) <= 0) {
  1402. array.push(insertValue);
  1403. return array;
  1404. }
  1405.  
  1406. // Check if the insertValue should be at the beginning
  1407. if ((right === 1 ? z : comparator(array[0], insertValue)) >= 0) {
  1408. array.unshift(insertValue);
  1409. return array;
  1410. }
  1411. ++left; --right;
  1412.  
  1413. // Main binary search loop to find the insertion position
  1414. while (left < right) {
  1415. const mid = Math.floor((right + left) / 2);
  1416. const compared = comparator(array[mid], insertValue);
  1417. if (compared < 0) {
  1418. left = mid + 1;
  1419. } else if (compared > 0) {
  1420. right = mid;
  1421. } else {
  1422. // If equal, insert at the mid position
  1423. left = right = mid;
  1424. break;
  1425. }
  1426. }
  1427.  
  1428. // Insertion is always at the right position due to the nature of the binary search
  1429. array.splice(right, 0, insertValue);
  1430. return array;
  1431. }
  1432.  
  1433.  
  1434.  
  1435.  
  1436. class LimitedSizeSet extends Set {
  1437. constructor(n) {
  1438. super();
  1439. this.limit = n;
  1440. }
  1441.  
  1442. add(key) {
  1443. if (!super.has(key)) {
  1444. super.add(key);
  1445. let n = super.size - this.limit;
  1446. if (n > 0) {
  1447. const iterator = super.values();
  1448. do {
  1449. const firstKey = iterator.next().value; // Get the first (oldest) key
  1450. super.delete(firstKey); // Delete the oldest key
  1451. } while (--n > 0)
  1452. }
  1453. }
  1454. }
  1455.  
  1456. removeAdd(key) {
  1457. super.delete(key);
  1458. this.add(key);
  1459. }
  1460.  
  1461. }
  1462.  
  1463.  
  1464. class LimitedSizeMap extends Map {
  1465. constructor(n) {
  1466. super();
  1467. this.limit = n;
  1468. }
  1469.  
  1470. set(key, val) {
  1471. if (!super.has(key)) {
  1472. super.set(key, val);
  1473. let n = super.size - this.limit;
  1474. if (n > 0) {
  1475. const iterator = super.keys();
  1476. do {
  1477. const firstKey = iterator.next().value; // Get the first (oldest) key
  1478. super.delete(firstKey); // Delete the oldest key
  1479. } while (--n > 0)
  1480. }
  1481. }
  1482. }
  1483.  
  1484. removeSet(key, val) {
  1485. super.delete(key);
  1486. this.set(key, val);
  1487. }
  1488.  
  1489. }
  1490.  
  1491. // function removeElementFromArray(arr, index) {
  1492. // if (index >= 0 && index < arr.length) {
  1493. // arr.splice(index, 1);
  1494. // }
  1495. // }
  1496.  
  1497. // function getRandomInt(a, b) {
  1498. // // Ensure that 'a' and 'b' are integers
  1499. // a = Math.ceil(a);
  1500. // b = Math.floor(b);
  1501.  
  1502. // // Generate a random integer in the range [a, b]
  1503. // return Math.floor(Math.random() * (b - a + 1)) + a;
  1504. // }
  1505.  
  1506. function deepCopy(obj, skipKeys) {
  1507. skipKeys = skipKeys || [];
  1508. if (!obj || typeof obj !== 'object') return obj;
  1509. if (Array.isArray(obj)) {
  1510. return obj.map(item => deepCopy(item, skipKeys));
  1511. }
  1512. const copy = {};
  1513. for (let key in obj) {
  1514. if (!skipKeys.includes(key)) {
  1515. copy[key] = deepCopy(obj[key], skipKeys);
  1516. }
  1517. }
  1518. return copy;
  1519. }
  1520.  
  1521. class Mutex {
  1522.  
  1523. constructor() {
  1524. this.p = Promise.resolve()
  1525. }
  1526.  
  1527. /**
  1528. * @param {(lockResolve: () => void)} f
  1529. */
  1530. lockWith(f) {
  1531. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  1532. }
  1533.  
  1534. }
  1535.  
  1536. const PromiseExternal = ((resolve_, reject_) => {
  1537. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  1538. return class PromiseExternal extends Promise {
  1539. constructor(cb = h) {
  1540. super(cb);
  1541. if (cb === h) {
  1542. /** @type {(value: any) => void} */
  1543. this.resolve = resolve_;
  1544. /** @type {(reason?: any) => void} */
  1545. this.reject = reject_;
  1546. }
  1547. }
  1548. };
  1549. })();
  1550.  
  1551.  
  1552. const createPipeline = () => {
  1553. let pipelineMutex = Promise.resolve();
  1554. const pipelineExecution = fn => {
  1555. return new Promise((resolve, reject) => {
  1556. pipelineMutex = pipelineMutex.then(async () => {
  1557. let res;
  1558. try {
  1559. res = await fn();
  1560. } catch (e) {
  1561. console.log('error_F1', e);
  1562. reject(e);
  1563. }
  1564. resolve(res);
  1565. }).catch(console.warn);
  1566. });
  1567. };
  1568. return pipelineExecution;
  1569. };
  1570.  
  1571. const tickerPE = createPipeline();
  1572.  
  1573. /** @type {typeof PromiseExternal.prototype | null} */
  1574. let relayPromise = null;
  1575.  
  1576.  
  1577. /** @type {typeof PromiseExternal.prototype | null} */
  1578. let onPlayStateChangePromise = null;
  1579.  
  1580.  
  1581.  
  1582.  
  1583. const valAssign = (elm, attr, val) => {
  1584. if (typeof val === 'number') val = val.toFixed(3);
  1585. if (!(Math.abs(elm.style.getPropertyValue(attr) - val) < 1e-5)) {
  1586. elm.style.setProperty(attr, val);
  1587. return true;
  1588. }
  1589. return false;
  1590. };
  1591.  
  1592. let playEventsStack = Promise.resolve();
  1593.  
  1594.  
  1595. let playerProgressChangedArg1 = null;
  1596. let playerProgressChangedArg2 = null;
  1597. let playerProgressChangedArg3 = null;
  1598.  
  1599. let dntElementWeak = null;
  1600.  
  1601.  
  1602. let timestampUnderLiveMode = false;
  1603.  
  1604. const updateTickerCurrentTime = () => {
  1605.  
  1606. if(resistanceUpdateDebugMode){
  1607. console.log('updateTickerCurrentTime')
  1608.  
  1609. if(!dntElementWeak || !kRef(dntElementWeak)) dntElementWeak = mWeakRef(document.querySelector('yt-live-chat-ticker-renderer'));
  1610. timestampUnderLiveMode = true;
  1611. }
  1612.  
  1613. const dntElement = kRef(dntElementWeak);
  1614. const v = timestampUnderLiveMode ? (Date.now() / 1000 - timeOriginDT / 1000) : playerProgressChangedArg1;
  1615. if (dntElement instanceof HTMLElement && v >= 0) {
  1616. valAssign(dntElement, '--ticker-current-time', v);
  1617. }
  1618. }
  1619.  
  1620. // ================== FOR USE_ADVANCED_TICKING ================
  1621.  
  1622. const timeOriginDT = +new Date(performance.timeOrigin);
  1623. let startResistanceUpdaterStarted = false;
  1624.  
  1625. const RESISTANCE_UPDATE_OPT = 3;
  1626. let resistanceUpdateLast = 0;
  1627. let resistanceUpdateBusy = false;
  1628. let resistanceUpdateRetry = false;
  1629. const resistanceUpdateDebugMode = false;
  1630. const allBackgroundOverLays = document.getElementsByTagName('ticker-bg-overlay');
  1631. const rgFlag = {};
  1632. const resistanceUpdateFn = (b) => {
  1633. if(b !== rgFlag && resistanceUpdateRetry === false) return;
  1634. if (!resistanceUpdateDebugMode && allBackgroundOverLays.length === 0) return;
  1635. resistanceUpdateBusy = false;
  1636. const t = Date.now();
  1637. const d = t - resistanceUpdateLast;
  1638. if (d > 375) {
  1639. resistanceUpdateLast = t;
  1640. resistanceUpdateRetry = false;
  1641. updateTickerCurrentTime();
  1642. } else if (typeof requestIdleCallback === 'function') {
  1643. resistanceUpdateRetry = true;
  1644. requestIdleCallback(resistanceUpdateFn);
  1645. } else {
  1646. resistanceUpdateRetry = true;
  1647. setTimeout(resistanceUpdateFn, d + 17);
  1648. }
  1649. }
  1650. const resistanceUpdateFn_ = ()=>{
  1651. if (!resistanceUpdateBusy) {
  1652. resistanceUpdateBusy = true;
  1653. resistanceUpdateRetry = false;
  1654. Promise.resolve(rgFlag).then(resistanceUpdateFn);
  1655. }
  1656. }
  1657. const startResistanceUpdater = () => {
  1658.  
  1659. if (startResistanceUpdaterStarted) return;
  1660. startResistanceUpdaterStarted = true;
  1661.  
  1662.  
  1663. if (RESISTANCE_UPDATE_OPT & 1)
  1664. document.addEventListener('yt-action', () => {
  1665. resistanceUpdateFn_();
  1666. }, true)
  1667.  
  1668. if (RESISTANCE_UPDATE_OPT & 2)
  1669. new MutationObserver(() => {
  1670. resistanceUpdateFn_();
  1671. }).observe(document, {
  1672. subtree: true, childList: true, attributes: true
  1673. });
  1674. resistanceUpdateFn_();
  1675. }
  1676.  
  1677. if(resistanceUpdateDebugMode) startResistanceUpdater();
  1678.  
  1679.  
  1680. function dr(s) {
  1681. // reserved for future use
  1682. return s;
  1683. // return window.deWeakJS ? window.deWeakJS(s) : s;
  1684. }
  1685.  
  1686. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1687. const indr = o => insp(o).$ || o.$ || 0;
  1688.  
  1689. const getProto = (element) => {
  1690. if (element) {
  1691. const cnt = insp(element);
  1692. return cnt.constructor.prototype || null;
  1693. }
  1694. return null;
  1695. }
  1696.  
  1697.  
  1698.  
  1699. const logFn = (key, f) => {
  1700. return Function.prototype.bind.call(console.log, console, `%c ${key}`, 'background: #222; color: #bada55', f);
  1701. }
  1702.  
  1703.  
  1704. const assertor = (f) => f() || (console.assert(false, f + ""), false);
  1705.  
  1706. const fnIntegrity = (f, d) => {
  1707.  
  1708.  
  1709. if (!f || typeof f !== 'function') {
  1710. console.warn('f is not a function', f);
  1711. return;
  1712. }
  1713. // return; // M44
  1714. let p = `${f}`, s = 0, j = -1, w = 0;
  1715. // return; // M44
  1716. for (let i = 0, l = p.length; i < l; i++) {
  1717. const t = p[i];
  1718. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1719. if (j < i - 1) w++;
  1720. j = i;
  1721. } else {
  1722. s++;
  1723. }
  1724. }
  1725. // if(p.length > 44 && p.length < 50){
  1726.  
  1727. // (window.skam|| (window.skam=[])).push(p);
  1728. // return false;
  1729. // }
  1730.  
  1731. // if(p.length > 405 && p.length < 415 ){ //350 450
  1732.  
  1733.  
  1734. // //  [353, 411, 411, 411]
  1735.  
  1736. // // if(p.length >= 350 && p.length<=450){
  1737.  
  1738. // // (window.skam|| (window.skam=[])).push(p.length);
  1739. // // }
  1740. // (window.skam|| (window.skam=[])).push(p);
  1741. // return false;
  1742. // }
  1743.  
  1744. // if(p.length < 50) return true; else return false;
  1745. // return; // M44
  1746. let itz = `${f.length}.${s}.${w}`;
  1747. if (!d) {
  1748. return itz;
  1749. } else if (itz !== d) {
  1750. console.warn('fnIntegrity=false', itz);
  1751. return false;
  1752. } else {
  1753. return true;
  1754. }
  1755. }
  1756.  
  1757. const px2cm = (px) => px * window.devicePixelRatio * 0.026458333;
  1758. const px2mm = (px) => px * window.devicePixelRatio * 0.26458333;
  1759.  
  1760.  
  1761. ; (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS || DISABLE_FLAGS_SHADYDOM_FREE) && (() => {
  1762.  
  1763. const _config_ = () => {
  1764. try {
  1765. return ytcfg.data_;
  1766. } catch (e) { }
  1767. return null;
  1768. };
  1769.  
  1770. const flagsFn = (EXPERIMENT_FLAGS) => {
  1771.  
  1772. // console.log(700)
  1773.  
  1774. if (!EXPERIMENT_FLAGS) return;
  1775.  
  1776. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1777. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1778. // EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true; // timestamp toggle issue
  1779. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1780. // console.log(701)
  1781. }
  1782. }
  1783.  
  1784. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1785. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1786. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1787. // console.log(702);
  1788. }
  1789.  
  1790. if (DISABLE_FLAGS_SHADYDOM_FREE) {
  1791. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_node_methods = false;
  1792. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_query_methods = false;
  1793. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_readonly_properties_batch_one = false;
  1794. EXPERIMENT_FLAGS.enable_shadydom_free_parent_node = false;
  1795. EXPERIMENT_FLAGS.enable_shadydom_free_children = false;
  1796. EXPERIMENT_FLAGS.enable_shadydom_free_last_child = false;
  1797. }
  1798.  
  1799. // EXPERIMENT_FLAGS.enable_button_behavior_reuse = false;
  1800.  
  1801. };
  1802.  
  1803. const uf = (config_) => {
  1804. config_ = config_ || _config_();
  1805. if (config_) {
  1806. const { EXPERIMENT_FLAGS, EXPERIMENTS_FORCED_FLAGS } = config_;
  1807. if (EXPERIMENT_FLAGS) {
  1808. flagsFn(EXPERIMENT_FLAGS);
  1809. if (EXPERIMENTS_FORCED_FLAGS) flagsFn(EXPERIMENTS_FORCED_FLAGS);
  1810. }
  1811. }
  1812. }
  1813.  
  1814. window._ytConfigHacks.add((config_) => {
  1815. uf(config_);
  1816. });
  1817.  
  1818. uf();
  1819.  
  1820. })();
  1821.  
  1822. if (DISABLE_Translation_By_Google) {
  1823.  
  1824. let mo = new MutationObserver(() => {
  1825.  
  1826. if (!mo) return;
  1827. let h = document.head;
  1828. if (!h) return;
  1829. mo.disconnect();
  1830. mo.takeRecords();
  1831. mo = null;
  1832.  
  1833. let meta = document.createElement('meta');
  1834. meta.setAttribute('name', 'google');
  1835. meta.setAttribute('content', 'notranslate');
  1836. h.appendChild(meta);
  1837.  
  1838.  
  1839. });
  1840. mo.observe(document, { subtree: true, childList: true });
  1841. }
  1842.  
  1843.  
  1844. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  1845.  
  1846. const isContainSupport = CSS.supports('contain', 'layout paint style');
  1847. if (!isContainSupport) {
  1848. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  1849. }
  1850.  
  1851. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  1852. if (!isOverflowAnchorSupport) {
  1853. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  1854. }
  1855.  
  1856. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && isOverflowAnchorSupport && ENABLE_NO_SMOOTH_TRANSFORM;
  1857.  
  1858. let hasTimerModified = null;
  1859. const DO_CHECK_TICKER_BACKGROUND_OVERRIDED = !!ATTEMPT_ANIMATED_TICKER_BACKGROUND || ENABLE_RAF_HACK_TICKERS;
  1860.  
  1861. const fxOperator = (proto, propertyName) => {
  1862. let propertyDescriptorGetter = null;
  1863. try {
  1864. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  1865. } catch (e) { }
  1866. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  1867. try {
  1868.  
  1869. return propertyDescriptorGetter.call(dr(e));
  1870. } catch (e) { }
  1871. return e[propertyName];
  1872. } : (e) => e[propertyName];
  1873. };
  1874.  
  1875. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  1876. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  1877. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  1878. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  1879. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  1880.  
  1881. const groupCollapsed = (text1, text2) => {
  1882.  
  1883. let w = 'groupCollapsed';
  1884. if (DEBUG_LOG_GROUP_EXPAND) w = 'group';
  1885. console[w](`%c${text1}%c${text2}`,
  1886. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1887. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1888. );
  1889. }
  1890.  
  1891. // const microNow = () => performance.now() + (performance.timeOrigin || performance.timing.navigationStart);
  1892.  
  1893.  
  1894. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1895. const onRegistryReady = (callback) => {
  1896. if (typeof customElements === 'undefined') {
  1897. if (!('__CE_registry' in document)) {
  1898. // https://github.com/webcomponents/polyfills/
  1899. Object.defineProperty(document, '__CE_registry', {
  1900. get() {
  1901. // return undefined
  1902. },
  1903. set(nv) {
  1904. if (typeof nv == 'object') {
  1905. delete this.__CE_registry;
  1906. this.__CE_registry = nv;
  1907. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1908. }
  1909. return true;
  1910. },
  1911. enumerable: false,
  1912. configurable: true
  1913. })
  1914. }
  1915. let eventHandler = (evt) => {
  1916. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1917. const f = callback;
  1918. callback = null;
  1919. eventHandler = null;
  1920. f();
  1921. };
  1922. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1923. } else {
  1924. callback();
  1925. }
  1926. };
  1927.  
  1928. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  1929.  
  1930. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  1931.  
  1932. return new Promise(resolve => {
  1933.  
  1934. let ro = new ResizeObserver(entries => {
  1935. if (entries && entries.length >= 1) {
  1936. resolve();
  1937. ro.disconnect();
  1938. ro = null;
  1939. }
  1940. });
  1941. ro.observe(sizingTarget);
  1942.  
  1943.  
  1944.  
  1945. });
  1946.  
  1947. } : (sizingTarget) => {
  1948.  
  1949.  
  1950. return new Promise(resolve => {
  1951.  
  1952. let io = new IntersectionObserver(entries => {
  1953. if (entries && entries.length >= 1) {
  1954. resolve();
  1955. io.disconnect();
  1956. io = null;
  1957. }
  1958. });
  1959. io.observe(sizingTarget);
  1960.  
  1961.  
  1962.  
  1963. });
  1964.  
  1965. };
  1966.  
  1967. /* globals WeakRef:false */
  1968.  
  1969. /** @type {(o: Object | null) => WeakRef | null} */
  1970. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1971.  
  1972. /** @type {(wr: Object | null) => Object | null} */
  1973. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1974.  
  1975. let getLCRDummyP_ = null;
  1976. // lcrPromiseFn
  1977. const getLCRDummy = () => {
  1978. // direct createElement or createComponent_ will make the emoji rendering crashed. reason TBC
  1979.  
  1980. return getLCRDummyP_ || (getLCRDummyP_ = Promise.all([customElements.whenDefined('yt-live-chat-app'), customElements.whenDefined('yt-live-chat-renderer')]).then(async () => {
  1981.  
  1982. const tag = "yt-live-chat-renderer"
  1983. let dummy = document.querySelector(tag);
  1984. if (!dummy) {
  1985.  
  1986. let mo = null;
  1987.  
  1988. const ytLiveChatApp = document.querySelector('yt-live-chat-app') || document.createElement('yt-live-chat-app');
  1989.  
  1990. const lcaProto = getProto(ytLiveChatApp);
  1991. let fz38;
  1992.  
  1993. let qt38=0;
  1994. let bypass = false;
  1995.  
  1996. dummy = await new Promise(resolve => {
  1997.  
  1998.  
  1999. if (typeof lcaProto.createComponent_ === 'function' && !lcaProto.createComponent99_) {
  2000. console.log('[yt-chat-lcr] lcaProto.createComponent_ is found');
  2001.  
  2002. lcaProto.createComponent99_ = lcaProto.createComponent_;
  2003. lcaProto.createComponent98_ = function (a, b, c) {
  2004. // (3) ['yt-live-chat-renderer', {…}, true]
  2005. const r = this.createComponent99_.apply(this, arguments);
  2006. if (a === 'yt-live-chat-renderer' && !bypass) {
  2007. qt38 = 1;
  2008. resolve(r); // note: this dom is not yet adopted, but promise resolve is later than ops.
  2009. console.log('[yt-chat-lcr] element found by method 1');
  2010. }
  2011. return r;
  2012. };
  2013. lcaProto.createComponent_ = lcaProto.createComponent98_;
  2014.  
  2015. if (!USE_OBTAIN_LCR_BY_BOTH_METHODS) return;
  2016.  
  2017. }
  2018.  
  2019. // console.log('[yt-chat] lcaProto traditional');
  2020.  
  2021. const pz38 = document.getElementsByTagName(tag);
  2022. fz38 = () => {
  2023. const t = pz38[0]
  2024. if (t) {
  2025. qt38 = 2;
  2026. resolve(t);
  2027. console.log('[yt-chat-lcr] element found by method 2');
  2028. }
  2029. };
  2030. mo = new MutationObserver(fz38);
  2031. mo.observe(document, { subtree: true, childList: true, attributes: true });
  2032. document.addEventListener('yt-action', fz38, true);
  2033. fz38();
  2034.  
  2035. });
  2036.  
  2037. bypass = true;
  2038.  
  2039. if (mo) {
  2040. mo.disconnect();
  2041. mo.takeRecords();
  2042. mo = null;
  2043. }
  2044. if (fz38) {
  2045. document.removeEventListener('yt-action', fz38, true);
  2046. fz38 = null;
  2047. }
  2048. console.log(`[yt-chat-lcr] lcr appears, dom = ${document.getElementsByTagName(tag).length}, method = ${qt38}`);
  2049.  
  2050.  
  2051. if (lcaProto.createComponent99_ && lcaProto.createComponent_ && lcaProto.createComponent98_ === lcaProto.createComponent_) {
  2052. lcaProto.createComponent_ = lcaProto.createComponent99_;
  2053. lcaProto.createComponent99_ = null;
  2054. lcaProto.createComponent98_ = null;
  2055. }
  2056.  
  2057. } else {
  2058. console.log('[yt-chat-lcr] lcr exists');
  2059. }
  2060. return dummy;
  2061.  
  2062. }));
  2063. }
  2064.  
  2065.  
  2066. // keeps as alternative option
  2067. let lcrPromise_ = null;
  2068. const lcrPromiseFn = () => {
  2069. if (lcrPromise_) return lcrPromise_;
  2070. const pz38 = document.getElementsByTagName("yt-live-chat-renderer");
  2071. const qz38 = new PromiseExternal();
  2072. const fz38 = () => {
  2073. if (pz38.length > 0) {
  2074. qz38.resolve(() => (pz38[0] || document.createElement("yt-live-chat-renderer")));
  2075. mo.disconnect();
  2076. document.removeEventListener('yt-action', fz38, true);
  2077. }
  2078. };
  2079. const mo = new MutationObserver(fz38);
  2080. mo.observe(document, {
  2081. subtree: true, childList: true, attributes: true
  2082. });
  2083. document.addEventListener('yt-action', fz38, true);
  2084. fz38();
  2085. return (lcrPromise_ = qz38);
  2086. }
  2087.  
  2088. const { addCssManaged } = (() => {
  2089.  
  2090. const addFontPreRendering = () => {
  2091.  
  2092. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  2093.  
  2094. let efsContainer = document.createElement('elzm-fonts');
  2095. efsContainer.id = 'elzm-fonts-yk75g'
  2096.  
  2097. const arr = [];
  2098. let p = document.createElement('elzm-font');
  2099. arr.push(p);
  2100.  
  2101. if (ENABLE_FONT_PRE_RENDERING & 1) {
  2102. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2103.  
  2104. p = document.createElement('elzm-font');
  2105. p.style.fontWeight = size;
  2106. arr.push(p);
  2107. }
  2108. }
  2109.  
  2110. if (ENABLE_FONT_PRE_RENDERING & 2) {
  2111. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2112.  
  2113. p = document.createElement('elzm-font');
  2114. p.style.fontFamily = 'Roboto';
  2115. p.style.fontWeight = size;
  2116. arr.push(p);
  2117. }
  2118. }
  2119.  
  2120. if (ENABLE_FONT_PRE_RENDERING & 4) {
  2121. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2122.  
  2123. p = document.createElement('elzm-font');
  2124. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  2125. p.style.fontWeight = size;
  2126. arr.push(p);
  2127. }
  2128. }
  2129.  
  2130.  
  2131. if (ENABLE_FONT_PRE_RENDERING & 8) {
  2132. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2133.  
  2134. p = document.createElement('elzm-font');
  2135. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  2136. p.style.fontWeight = size;
  2137. arr.push(p);
  2138. }
  2139. }
  2140.  
  2141.  
  2142. if (ENABLE_FONT_PRE_RENDERING & 16) {
  2143. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2144.  
  2145. p = document.createElement('elzm-font');
  2146. p.style.fontFamily = 'sans-serif';
  2147. p.style.fontWeight = size;
  2148. arr.push(p);
  2149. }
  2150. }
  2151.  
  2152. console.log('number of elzm-font elements', arr.length);
  2153.  
  2154. HTMLElement.prototype.append.apply(efsContainer, arr);
  2155.  
  2156. (document.body || document.documentElement).appendChild(efsContainer);
  2157.  
  2158.  
  2159. console.log('elzm-font elements have been added to the page for rendering.');
  2160.  
  2161. console.groupEnd();
  2162.  
  2163. }
  2164.  
  2165. let isCssAdded = false;
  2166.  
  2167. function addCssElement() {
  2168. let s = document.createElement('style');
  2169. s.id = 'ewRvC';
  2170. return s;
  2171. }
  2172.  
  2173. const addCssManaged = () => {
  2174. if (!isCssAdded && document.documentElement && document.head) {
  2175. isCssAdded = true;
  2176. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  2177. if (ENABLE_FONT_PRE_RENDERING) {
  2178. Promise.resolve().then(addFontPreRendering)
  2179. }
  2180. }
  2181. }
  2182.  
  2183. return { addCssManaged };
  2184. })();
  2185.  
  2186.  
  2187. const { setupStyle } = (() => {
  2188.  
  2189. const sp7 = Symbol();
  2190.  
  2191. const proxyHelperFn = (dummy) => ({
  2192.  
  2193. get(target, prop) {
  2194. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  2195. },
  2196. set(target, prop, value) {
  2197. if (!(prop in dummy)) {
  2198. target[prop] = value;
  2199. }
  2200. return true;
  2201. },
  2202. has(target, prop) {
  2203. return (prop in target);
  2204. },
  2205. deleteProperty(target, prop) {
  2206. return true;
  2207. },
  2208. ownKeys(target) {
  2209. return Object.keys(target);
  2210. },
  2211. defineProperty(target, key, descriptor) {
  2212. return Object.defineProperty(target, key, descriptor);
  2213. },
  2214. getOwnPropertyDescriptor(target, key) {
  2215. return Object.getOwnPropertyDescriptor(target, key);
  2216. },
  2217.  
  2218. });
  2219.  
  2220. const setupStyle = (m1, m2) => {
  2221. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  2222.  
  2223. const dummy1v = {
  2224. transform: '',
  2225. height: '',
  2226. minHeight: '',
  2227. paddingBottom: '',
  2228. paddingTop: ''
  2229. };
  2230.  
  2231. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  2232. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  2233. dummy1v[k] = dummyStyleFn(k);
  2234. }
  2235.  
  2236. const dummy1p = proxyHelperFn(dummy1v);
  2237. const sp1v = new Proxy(m1.style, dummy1p);
  2238. const sp2v = new Proxy(m2.style, dummy1p);
  2239. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  2240. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  2241. m1.removeAttribute("style");
  2242. m2.removeAttribute("style");
  2243.  
  2244. }
  2245.  
  2246. return { setupStyle };
  2247.  
  2248. })();
  2249.  
  2250.  
  2251.  
  2252. function setThumbnails(config) {
  2253.  
  2254. const { baseObject, thumbnails, flag0, imageLinks } = config;
  2255.  
  2256. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  2257.  
  2258.  
  2259. if (thumbnails && thumbnails.length > 0) {
  2260. if (flag0 > 0 && thumbnails.length > 1) {
  2261. let pSize = 0;
  2262. let newThumbnails = [];
  2263. for (const thumbnail of thumbnails) {
  2264. if (!thumbnail || !thumbnail.url) continue;
  2265. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  2266. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  2267. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  2268. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  2269. newThumbnails.push(thumbnail);
  2270. if (imageLinks) imageLinks.add(thumbnail.url);
  2271. }
  2272. if (squarePhoto && condSize && leastSizeFulfilled) {
  2273. pSize = thumbnail.width;
  2274. }
  2275. }
  2276. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  2277. baseObject.thumbnails = newThumbnails;
  2278. } else {
  2279. newThumbnails.length = 0;
  2280. }
  2281. newThumbnails = null;
  2282. } else {
  2283. for (const thumbnail of thumbnails) {
  2284. if (thumbnail && thumbnail.url) {
  2285. if (imageLinks) imageLinks.add(thumbnail.url);
  2286. }
  2287. }
  2288. }
  2289. }
  2290.  
  2291. }
  2292. }
  2293.  
  2294. function fixLiveChatItem(item, imageLinks) {
  2295. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  2296. if (liveChatTextMessageRenderer) {
  2297. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  2298. if (messageRuns && messageRuns.length > 0) {
  2299. for (const run of messageRuns) {
  2300. const emojiImage = (((run || 0).emoji || 0).image || 0);
  2301. setThumbnails({
  2302. baseObject: emojiImage,
  2303. thumbnails: emojiImage.thumbnails,
  2304. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  2305. imageLinks
  2306. });
  2307. }
  2308. }
  2309. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  2310. setThumbnails({
  2311. baseObject: authorPhoto,
  2312. thumbnails: authorPhoto.thumbnails,
  2313. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  2314. imageLinks
  2315. });
  2316. }
  2317. }
  2318.  
  2319.  
  2320.  
  2321. let kptPF = null;
  2322. const emojiPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_EMOJI);
  2323. const authorPhotoPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO);
  2324.  
  2325. function linker(link, rel, href, _as) {
  2326. return new Promise(resolve => {
  2327. if (!link) link = document.createElement('link');
  2328. link.rel = rel;
  2329. if (_as) link.setAttribute('as', _as);
  2330. link.onload = function () {
  2331. resolve({
  2332. link: this,
  2333. success: true
  2334. })
  2335. this.remove();
  2336. };
  2337. link.onerror = function () {
  2338. resolve({
  2339. link: this,
  2340. success: false
  2341. });
  2342. this.remove();
  2343. };
  2344. link.href = href;
  2345. document.head.appendChild(link);
  2346. link = null;
  2347. });
  2348. }
  2349.  
  2350.  
  2351.  
  2352. const cleanContext = async (win) => {
  2353. const waitFn = requestAnimationFrame; // shall have been binded to window
  2354. try {
  2355. let mx = 16; // MAX TRIAL
  2356. const frameId = 'vanillajs-iframe-v1';
  2357. /** @type {HTMLIFrameElement | null} */
  2358. let frame = document.getElementById(frameId);
  2359. let removeIframeFn = null;
  2360. if (!frame) {
  2361. frame = document.createElement('iframe');
  2362. frame.id = frameId;
  2363. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2364. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2365. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2366. n.appendChild(frame);
  2367. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2368. const root = document.documentElement;
  2369. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2370. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2371.  
  2372. removeIframeFn = (setTimeout) => {
  2373. const removeIframeOnDocumentReady = (e) => {
  2374. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2375. e = n;
  2376. n = win = removeIframeFn = 0;
  2377. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2378. }
  2379. if (!setTimeout || document.readyState !== 'loading') {
  2380. removeIframeOnDocumentReady();
  2381. } else {
  2382. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2383. }
  2384. }
  2385. }
  2386. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2387. const fc = frame.contentWindow;
  2388. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2389. try {
  2390. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle } = fc;
  2391. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle };
  2392. for (let k in res) res[k] = res[k].bind(win); // necessary
  2393. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2394.  
  2395. /** @type {HTMLElement} */
  2396. const HTMLElementProto = fc.HTMLElement.prototype;
  2397. /** @type {EventTarget} */
  2398. const EventTargetProto = fc.EventTarget.prototype;
  2399. // jsonParseFix = {
  2400. // _JSON: fc.JSON, _parse: fc.JSON.parse
  2401. // }
  2402. return {
  2403. ...res,
  2404. animate: HTMLElementProto.animate,
  2405. addEventListener: EventTargetProto.addEventListener,
  2406. removeEventListener: EventTargetProto.removeEventListener
  2407. };
  2408. } catch (e) {
  2409. if (removeIframeFn) removeIframeFn();
  2410. return null;
  2411. }
  2412. } catch (e) {
  2413. console.warn(e);
  2414. return null;
  2415. }
  2416. };
  2417.  
  2418.  
  2419. let xoIcjPr = null;
  2420. window.addEventListener('message', (evt) => {
  2421. if ((evt || 0).data === 'xoIcj' && xoIcjPr !== null) xoIcjPr.resolve();
  2422. });
  2423. const timelineResolve = async () => {
  2424. if (xoIcjPr !== null) {
  2425. await xoIcjPr.then();
  2426. return;
  2427. }
  2428. xoIcjPr = new PromiseExternal();
  2429. window.postMessage('xoIcj');
  2430. await xoIcjPr.then();
  2431. xoIcjPr = null;
  2432. }
  2433.  
  2434. cleanContext(win).then(__CONTEXT__ => {
  2435. if (!__CONTEXT__) return null;
  2436.  
  2437. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, getComputedStyle, addEventListener, removeEventListener } = __CONTEXT__;
  2438.  
  2439. const wmComputedStyle = new WeakMap();
  2440. const getComputedStyleCached = (elem) => {
  2441. let cs = wmComputedStyle.get(elem);
  2442. if (!cs) {
  2443. cs = getComputedStyle(elem);
  2444. wmComputedStyle.set(elem, cs);
  2445. }
  2446. return cs;
  2447. }
  2448.  
  2449.  
  2450. const isGPUAccelerationAvailable = (() => {
  2451. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  2452. try {
  2453. const canvas = document.createElement('canvas');
  2454. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  2455. } catch (e) {
  2456. return false;
  2457. }
  2458. })();
  2459.  
  2460. const foregroundPromiseFn_noGPU = (() => {
  2461.  
  2462. if (isGPUAccelerationAvailable) return null;
  2463.  
  2464. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  2465. if (!pd || typeof pd.get !== 'function') return null;
  2466. const pdGet = pd.get;
  2467.  
  2468. let pr = null;
  2469.  
  2470. let hState = pdGet.call(document) === 'hidden';
  2471. // let cid = 0;
  2472. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  2473. const newHState = pdGet.call(document) === 'hidden';
  2474. if (hState !== newHState) {
  2475. // if (cid > 0) cid = clearInterval(cid);
  2476. hState = newHState;
  2477. if (!hState && pr) pr = pr.resolve();
  2478. }
  2479. });
  2480.  
  2481. // cid = setInterval(() => {
  2482. // const newHState = document.visibilityState === 'hidden';
  2483. // if (hState !== newHState) {
  2484. // hState = newHState;
  2485. // if (!hState && pr) pr = pr.resolve();
  2486. // }
  2487. // }, 100);
  2488.  
  2489.  
  2490. return (() => {
  2491. if (pr) return pr;
  2492. const w = ((!hState && setTimeout(() => {
  2493. if (!hState && pr === w) pr = pr.resolve();
  2494. })), (pr = new PromiseExternal()));
  2495. return w;
  2496. });
  2497.  
  2498. })();
  2499.  
  2500. // window.foregroundPromiseFn_noGPU = foregroundPromiseFn_noGPU;
  2501.  
  2502. let rafPromise = null;
  2503. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2504. requestAnimationFrame(hRes => {
  2505. rafPromise = null;
  2506. resolve(hRes);
  2507. });
  2508. }));
  2509. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  2510.  
  2511. const iAFP = foregroundPromiseFn_noGPU ? foregroundPromiseFn_noGPU : typeof IntersectionObserver === 'undefined' ? getRafPromise : (() => {
  2512.  
  2513. const ioWM = new WeakMap();
  2514. const ek = Symbol();
  2515. /** @type {IntersectionObserverCallback} */
  2516. const ioCb = (entries, observer) => {
  2517. /** @type {PromiseExternal} */
  2518. const pr = observer[ek];
  2519. const resolve = pr.resolve;
  2520. let target;
  2521. if (resolve && (target = ((entries ? entries[0] : 0) || 0).target) instanceof Element) {
  2522. pr.resolve = null;
  2523. observer.unobserve(target);
  2524. resolve();
  2525. }
  2526. };
  2527. /**
  2528. *
  2529. * @param {Element} elm
  2530. * @returns {Promise<void>}
  2531. */
  2532. const iAFP = (elm) => {
  2533. let io = ioWM.get(elm);
  2534. if (!io) {
  2535. io = new IntersectionObserver(ioCb);
  2536. ioWM.set(elm, io); // strong reference
  2537. }
  2538. let pr = io[ek];
  2539. if (!pr) {
  2540. pr = io[ek] = new PromiseExternal();
  2541. io.observe(elm);
  2542. }
  2543. return pr;
  2544. }
  2545.  
  2546. return iAFP;
  2547.  
  2548. })();
  2549.  
  2550. let playerState = null;
  2551. let _playerState = null;
  2552. let lastPlayerProgress = null;
  2553. let relayCount = 0;
  2554. let playerEventsByIframeRelay = false;
  2555. let isPlayProgressTriggered = false;
  2556. let waitForInitialDataCompletion = 0;
  2557.  
  2558.  
  2559.  
  2560. let aeConstructor = null;
  2561.  
  2562. // << __openedChanged82 >>
  2563. let currentMenuPivotWR = null;
  2564.  
  2565. // << if DO_PARTICIPANT_LIST_HACKS >>
  2566. const beforeParticipantsMap = new WeakMap();
  2567. // << end >>
  2568.  
  2569.  
  2570.  
  2571. // << if onRegistryReadyForDOMOperations >>
  2572.  
  2573. let dt0 = Date.now() - 2000;
  2574. const dateNow = () => Date.now() - dt0;
  2575. // let lastScroll = 0;
  2576. // let lastLShow = 0;
  2577. let lastWheel = 0;
  2578. let lastMouseDown = 0;
  2579. let lastMouseUp = 0;
  2580. let currentMouseDown = false;
  2581. let lastTouchDown = 0;
  2582. let lastTouchUp = 0;
  2583. let currentTouchDown = false;
  2584. let lastUserInteraction = 0;
  2585.  
  2586. let scrollChatFn = null;
  2587.  
  2588. let skipDontRender = true; // true first; false by flushActiveItems_
  2589. let allowDontRender = null;
  2590.  
  2591. // ---- #items mutation ----
  2592. let sk35zResolveFn = null;
  2593. let firstList = true;
  2594.  
  2595. // << end >>
  2596.  
  2597. class RAFHub {
  2598. constructor() {
  2599. /** @type {number} */
  2600. this.startAt = 8170;
  2601. /** @type {number} */
  2602. this.counter = 0;
  2603. /** @type {number} */
  2604. this.rid = 0;
  2605. /** @type {Map<number, FrameRequestCallback>} */
  2606. this.funcs = new Map();
  2607. const funcs = this.funcs;
  2608. /** @type {FrameRequestCallback} */
  2609. this.bCallback = this.mCallback.bind(this);
  2610. this.pClear = () => funcs.clear();
  2611. this.keepRAF = false;
  2612. }
  2613. /** @param {DOMHighResTimeStamp} highResTime */
  2614. mCallback(highResTime) {
  2615. this.rid = 0;
  2616. Promise.resolve().then(this.pClear);
  2617. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2618. }
  2619. /** @param {FrameRequestCallback} f */
  2620. request(f) {
  2621. if (this.counter > 1e9) this.counter = 9;
  2622. let cid = this.startAt + (++this.counter);
  2623. this.funcs.set(cid, f);
  2624. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  2625. return cid;
  2626. }
  2627. /** @param {number} cid */
  2628. cancel(cid) {
  2629. cid = +cid;
  2630. if (cid > 0) {
  2631. if (cid <= this.startAt) {
  2632. return cancelAnimationFrame(cid);
  2633. }
  2634. if (this.rid > 0) {
  2635. this.funcs.delete(cid);
  2636. if (this.funcs.size === 0 && !this.keepRAF) {
  2637. cancelAnimationFrame(this.rid);
  2638. this.rid = 0;
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644.  
  2645. function basePrefetching() {
  2646.  
  2647. new Promise(resolve => {
  2648.  
  2649. if (document.readyState !== 'loading') {
  2650. resolve();
  2651. } else {
  2652. win.addEventListener("DOMContentLoaded", resolve, false);
  2653. }
  2654.  
  2655. }).then(() => {
  2656. const hostL1 = [
  2657. 'https://www.youtube.com', 'https://googlevideo.com',
  2658. 'https://googleapis.com', 'https://accounts.youtube.com',
  2659. 'https://www.gstatic.com', 'https://ggpht.com',
  2660. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  2661. ];
  2662.  
  2663. const hostL2 = [
  2664. 'https://youtube.com',
  2665. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  2666. ];
  2667.  
  2668. let link = null;
  2669.  
  2670. function kn() {
  2671.  
  2672. link = document.createElement('link');
  2673. if (link.relList && link.relList.supports) {
  2674. 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)
  2675. } else {
  2676. kptPF = 0;
  2677. }
  2678.  
  2679. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  2680. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  2681. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  2682. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  2683. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  2684. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  2685. console.groupEnd();
  2686.  
  2687. }
  2688.  
  2689. for (const h of hostL1) {
  2690.  
  2691. if (kptPF === null) kn();
  2692. if (ENABLE_BASE_PREFETCHING) {
  2693. // if (kptPF & 1) {
  2694. // linker(link, 'dns-prefetch', h);
  2695. // link = null;
  2696. // }
  2697. if (kptPF & 2) {
  2698. linker(link, 'preconnect', h);
  2699. link = null;
  2700. }
  2701. }
  2702. }
  2703.  
  2704. for (const h of hostL2) {
  2705. if (kptPF === null) kn();
  2706. if (ENABLE_BASE_PREFETCHING) {
  2707. if (kptPF & 1) {
  2708. linker(link, 'dns-prefetch', h);
  2709. link = null;
  2710. }
  2711. }
  2712. }
  2713.  
  2714. })
  2715.  
  2716.  
  2717. }
  2718.  
  2719. if (DO_LINK_PREFETCH) basePrefetching();
  2720.  
  2721. const { notifyPath7081 } = (() => {
  2722. // DO_PARTICIPANT_LIST_HACKS
  2723.  
  2724. const mutexParticipants = new Mutex();
  2725.  
  2726. let uvid = 0;
  2727. let r95dm = 0;
  2728. let c95dm = -1;
  2729.  
  2730. const foundMap = (base, content) => {
  2731. /*
  2732. let lastSearch = 0;
  2733. let founds = base.map(baseEntry => {
  2734. let search = content.indexOf(baseEntry, lastSearch);
  2735. if (search < 0) return false;
  2736. lastSearch = search + 1;
  2737. return true;
  2738. });
  2739. return founds;
  2740. */
  2741. const contentSet = new Set(content);
  2742. return base.map(baseEntry => contentSet.has(baseEntry));
  2743.  
  2744. }
  2745.  
  2746.  
  2747.  
  2748. let participantsForSpliceWR = null;
  2749.  
  2750. class IndexSpliceEntry {
  2751. /**
  2752. *
  2753. * @param {number} _index
  2754. * @param {number} _addedCount
  2755. * @param {any[]} _removed
  2756. */
  2757. constructor(_index, _addedCount, _removed) {
  2758. this.index = _index;
  2759. this.addedCount = _addedCount;
  2760. this.removed = _removed;
  2761. }
  2762. get __proxy312__() {
  2763. return 1
  2764. }
  2765. get type() {
  2766. return 'splice'
  2767. }
  2768. get object() {
  2769. return kRef(participantsForSpliceWR); // avoid memory leakage
  2770. }
  2771. }
  2772.  
  2773. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  2774.  
  2775. let foundsForAfter = foundMap(idsAfter, idsBefore);
  2776. let foundsForBefore = foundMap(idsBefore, idsAfter);
  2777.  
  2778. const nAfter = foundsForAfter.length;
  2779. const nBefore = foundsForBefore.length;
  2780.  
  2781. const indexSplices = [];
  2782. const contentUpdates = [];
  2783. participantsForSpliceWR = null;
  2784. for (let i = 0, j = 0; i < nBefore || j < nAfter;) {
  2785. if (beforeParticipants[i] === participants[j]) {
  2786. i++; j++;
  2787. } else if (idsBefore[i] === idsAfter[j]) {
  2788. // content changed
  2789. contentUpdates.push({ indexI: i, indexJ: j })
  2790. i++; j++;
  2791. } else {
  2792. let addedCount = 0;
  2793. for (let q = j; q < nAfter; q++) {
  2794. if (foundsForAfter[q] === false) addedCount++;
  2795. else break;
  2796. }
  2797. let removedCount = 0;
  2798. for (let q = i; q < nBefore; q++) {
  2799. if (foundsForBefore[q] === false) removedCount++;
  2800. else break;
  2801. }
  2802. if (!addedCount && !removedCount) {
  2803. throw 'ERROR(0xFF32): spliceIndicesFunc';
  2804. }
  2805. const entry = new IndexSpliceEntry(
  2806. j,
  2807. addedCount,
  2808. removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  2809. );
  2810. indexSplices.push(entry);
  2811. i += removedCount;
  2812. j += addedCount;
  2813. }
  2814. }
  2815. foundsForBefore = null;
  2816. foundsForAfter = null;
  2817. idsBefore = null;
  2818. idsAfter = null;
  2819. beforeParticipants = null;
  2820. participantsForSpliceWR = indexSplices.length > 0 ? mWeakRef(participants) : null;
  2821. participants = null;
  2822. return { indexSplices, contentUpdates };
  2823.  
  2824. }
  2825.  
  2826. /*
  2827.  
  2828. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  2829.  
  2830. VM63631:1 Error
  2831. at customElements.get.notifyPath (<anonymous>:1:122)
  2832. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  2833. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  2834. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  2835. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  2836. at ju (live_chat_polymer.js:1674:217)
  2837. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  2838. at b._flushProperties (live_chat_polymer.js:1597:200)
  2839. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  2840. at a.notifyPath (live_chat_polymer.js:1741:182)
  2841.  
  2842. */
  2843.  
  2844. function convertToIds(participants) {
  2845. return participants.map(participant => {
  2846. if (!participant || typeof participant !== 'object') {
  2847. console.warn('Error(0xFA41): convertToIds', participant);
  2848. return participant; // just in case
  2849. }
  2850. let keys = Object.keys(participant);
  2851. // liveChatTextMessageRenderer
  2852. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  2853. // liveChatPaidMessageRenderer
  2854. /*
  2855.  
  2856. 'yt-live-chat-participant-renderer' utilizes the following:
  2857. authorName.simpleText: string
  2858. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  2859. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  2860. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  2861. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  2862.  
  2863. */
  2864. if (keys.length !== 1) {
  2865. console.warn('Error(0xFA42): convertToIds', participant);
  2866. return participant; // just in case
  2867. }
  2868. let key = keys[0];
  2869. let renderer = (participant[key] || 0);
  2870. let authorName = (renderer.authorName || 0);
  2871. let text = `${authorName.simpleText || authorName.text}`
  2872. let res = participant; // fallback if it is not a vaild entry
  2873. if (typeof text !== 'string') {
  2874. console.warn('Error(0xFA53): convertToIds', participant);
  2875. } else {
  2876. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  2877. if (text.length > 1) res = text;
  2878. }
  2879. return res;
  2880. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  2881. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  2882. });
  2883. }
  2884.  
  2885. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  2886. // just update when content is changed.
  2887. if (p1.authorName !== p2.authorName) return true;
  2888. if (p1.authorPhoto !== p2.authorPhoto) return true;
  2889. if (p1.authorBadges !== p2.authorBadges) return true;
  2890. return false;
  2891. } : (p1, p2) => {
  2892. // keep integrity all the time.
  2893. return p1 !== p2; // always true
  2894. }
  2895.  
  2896. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  2897.  
  2898. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2899. if (path !== "participantsManager.participants") {
  2900. return this.__notifyPath5036__.apply(this, arguments);
  2901. }
  2902. if (c95dm === r95dm) return;
  2903. } else {
  2904. const stack = new Error().stack;
  2905. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  2906. return this.__notifyPath5036__.apply(this, arguments);
  2907. }
  2908. }
  2909.  
  2910. if (uvid > 1e8) uvid = uvid % 100;
  2911. let tid = ++uvid;
  2912.  
  2913.  
  2914. // const cnt = this; // "yt-live-chat-participant-list-renderer"
  2915.  
  2916. const wNode = mWeakRef(this);
  2917.  
  2918. mutexParticipants.lockWith(lockResolve => {
  2919.  
  2920. const cnt = kRef(wNode);
  2921.  
  2922. const participants00 = (((cnt || 0).participantsManager || 0).participants || 0);
  2923.  
  2924. if (tid !== uvid || !cnt || typeof (participants00 || 0).splice !== 'function') {
  2925. lockResolve();
  2926. return;
  2927. }
  2928.  
  2929. let doUpdate = false;
  2930.  
  2931. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  2932.  
  2933. if (!participants00.r94dm) {
  2934. participants00.r94dm = 1;
  2935. if (++r95dm > 1e9) r95dm = 9;
  2936. participants00.push = function () {
  2937. if (++r95dm > 1e9) r95dm = 9;
  2938. return Array.prototype.push.apply(this, arguments);
  2939. }
  2940. participants00.pop = function () {
  2941. if (++r95dm > 1e9) r95dm = 9;
  2942. return Array.prototype.pop.apply(this, arguments);
  2943. }
  2944. participants00.shift = function () {
  2945. if (++r95dm > 1e9) r95dm = 9;
  2946. return Array.prototype.shift.apply(this, arguments);
  2947. }
  2948. participants00.unshift = function () {
  2949. if (++r95dm > 1e9) r95dm = 9;
  2950. return Array.prototype.unshift.apply(this, arguments);
  2951. }
  2952. participants00.splice = function () {
  2953. if (++r95dm > 1e9) r95dm = 9;
  2954. return Array.prototype.splice.apply(this, arguments);
  2955. }
  2956. participants00.sort = function () {
  2957. if (++r95dm > 1e9) r95dm = 9;
  2958. return Array.prototype.sort.apply(this, arguments);
  2959. }
  2960. participants00.reverse = function () {
  2961. if (++r95dm > 1e9) r95dm = 9;
  2962. return Array.prototype.reverse.apply(this, arguments);
  2963. }
  2964. }
  2965.  
  2966. if (c95dm !== r95dm) {
  2967. c95dm = r95dm;
  2968. doUpdate = true;
  2969. }
  2970.  
  2971. } else {
  2972. doUpdate = true;
  2973. }
  2974.  
  2975. if (!doUpdate) {
  2976. lockResolve();
  2977. return;
  2978. }
  2979.  
  2980. const participants = participants00.slice(0);
  2981. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  2982. beforeParticipantsMap.set(cnt, participants);
  2983.  
  2984. const resPromise = (async () => {
  2985.  
  2986. if (beforeParticipants.length === 0) {
  2987. // not error
  2988. return 0;
  2989. }
  2990.  
  2991. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  2992.  
  2993. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  2994. if (beforeParticipants.length !== countOfElements) {
  2995. // there is somewrong for the cache. - sometimes happen
  2996. return 0;
  2997. }
  2998.  
  2999. const idsBefore = convertToIds(beforeParticipants);
  3000. const idsAfter = convertToIds(participants);
  3001.  
  3002. let { indexSplices, contentUpdates } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  3003.  
  3004. let res = 1; // default 1 for no update
  3005.  
  3006. if (indexSplices.length >= 1) {
  3007.  
  3008.  
  3009. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  3010. // let p1 = indexSplices[0].removed;
  3011. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  3012.  
  3013. /* folllow
  3014. a.notifyPath(c + ".splices", d);
  3015. a.notifyPath(c + ".length", b.length);
  3016. */
  3017. // stampDomArraySplices_
  3018.  
  3019.  
  3020. await new Promise(resolve => {
  3021. cnt.resolveForDOMRendering781 = resolve;
  3022.  
  3023. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  3024. indexSplices
  3025. });
  3026. indexSplices = null;
  3027. participantsForSpliceWR = null;
  3028. cnt.__notifyPath5036__("participantsManager.participants.length",
  3029. participants.length
  3030. );
  3031.  
  3032. });
  3033.  
  3034. // play safe for the change of 'length'
  3035. if (typeof nextBrowserTick !== 'function') {
  3036. await Promise.resolve(0);
  3037. } else {
  3038. await new Promise(resolve => nextBrowserTick(resolve)).then();
  3039. }
  3040.  
  3041. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  3042.  
  3043. const wrongSize = participants.length !== countOfElements
  3044. if (wrongSize) {
  3045. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  3046. return 0;
  3047. }
  3048.  
  3049. res = 2 | 4;
  3050.  
  3051. } else {
  3052.  
  3053. indexSplices = null;
  3054. participantsForSpliceWR = null;
  3055.  
  3056. if (participants.length !== countOfElements) {
  3057. // other unhandled cases
  3058. return 0;
  3059. }
  3060.  
  3061. }
  3062.  
  3063. // participants.length === countOfElements before contentUpdates
  3064. if (contentUpdates.length >= 1) {
  3065. for (const contentUpdate of contentUpdates) {
  3066. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  3067. if (isChanged) {
  3068. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  3069. res |= 4 | 8;
  3070. }
  3071. }
  3072. }
  3073. contentUpdates = null;
  3074.  
  3075. return res;
  3076.  
  3077.  
  3078. })();
  3079.  
  3080.  
  3081. resPromise.then(resValue => {
  3082.  
  3083. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  3084. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  3085. if (resValue === 0) {
  3086. new Promise(resolve => {
  3087. cnt.resolveForDOMRendering781 = resolve;
  3088. isLogRequired && console.log("Full Refresh begins");
  3089. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  3090. }).then(() => {
  3091. isLogRequired && console.log("Full Refresh ends");
  3092. console.groupEnd();
  3093. }).then(lockResolve);
  3094. return;
  3095. }
  3096.  
  3097. const delayLockResolve = (resValue & 4) === 4;
  3098.  
  3099. if (delayLockResolve) {
  3100. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  3101. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  3102. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  3103. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  3104. isLogRequired && console.groupEnd();
  3105. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  3106. // mutex lock with requestAnimationFrame can also disable participants update in background
  3107. requestAnimationFrame(lockResolve);
  3108. } else {
  3109. lockResolve();
  3110. }
  3111.  
  3112. });
  3113.  
  3114. });
  3115.  
  3116. }
  3117.  
  3118. return { notifyPath7081 };
  3119.  
  3120. })();
  3121.  
  3122. const whenDefinedMultiple = async (tags) => {
  3123.  
  3124. const sTags = [...new Set(tags)];
  3125. const len = sTags.length;
  3126.  
  3127. const pTags = new Array(len);
  3128. for (let i = 0; i < len; i++) {
  3129. pTags[i] = customElements.whenDefined(sTags[i]);
  3130. }
  3131.  
  3132. await Promise.all(pTags);
  3133. pTags.length = 0;
  3134.  
  3135. return sTags;
  3136.  
  3137. }
  3138.  
  3139. const onRegistryReadyForDataManipulation = () => {
  3140.  
  3141. function dummy5035(a, b, c) { }
  3142. function dummy411(a, b, c) { }
  3143.  
  3144.  
  3145.  
  3146. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  3147.  
  3148. if (!DO_PARTICIPANT_LIST_HACKS) return;
  3149.  
  3150. const tag = "yt-live-chat-participant-list-renderer";
  3151. const cProto = getProto(document.createElement(tag));
  3152. if (!cProto || typeof cProto.attached !== 'function') {
  3153. // for _registered, proto.attached shall exist when the element is defined.
  3154. // for controller extraction, attached shall exist when instance creates.
  3155. console.warn(`proto.attached for ${tag} is unavailable.`);
  3156. return;
  3157. }
  3158.  
  3159.  
  3160. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  3161.  
  3162. 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'];
  3163. const fgs = {};
  3164. for (const key of fgsArr) fgs[key] = undefined;
  3165.  
  3166. try {
  3167. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  3168. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  3169. } catch (e) { }
  3170. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  3171.  
  3172. const canDoReplacement = (() => {
  3173. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  3174. console.warn('YouTube Live Chat Tamer is running.');
  3175. return;
  3176. }
  3177.  
  3178. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  3179. console.warn('YouTube Live Chat Tamer is running.');
  3180. return;
  3181. }
  3182.  
  3183. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  3184. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  3185.  
  3186. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  3187. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  3188. return;
  3189. }
  3190.  
  3191. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  3192. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  3193. return;
  3194. }
  3195.  
  3196. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  3197. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  3198. return;
  3199. }
  3200. return true;
  3201. })();
  3202.  
  3203. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  3204.  
  3205. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  3206. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3207. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  3208. // const s = fiRSCB.split('.');
  3209. // Feb 2024: 0.403.247 => NG
  3210. // if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  3211. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  3212. // } else {
  3213. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - NG`);
  3214. // }
  3215. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ###`);
  3216. } else {
  3217. console.log("flushRenderStamperComponentBindings_ - not found");
  3218. }
  3219. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  3220.  
  3221. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3222. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  3223. cProto.flushRenderStamperComponentBindings_ = function () {
  3224. // console.log('flushRenderStamperComponentBindings_')
  3225. this.flushRenderStamperComponentBindings66_();
  3226. if (this.resolveForDOMRendering781) {
  3227. this.resolveForDOMRendering781();
  3228. this.resolveForDOMRendering781 = null;
  3229. }
  3230. };
  3231. }
  3232.  
  3233. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  3234. const container = ((this || 0).$ || 0).participants;
  3235. if (!container) return 0;
  3236. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  3237. }
  3238.  
  3239. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  3240.  
  3241. cProto.__attached412__ = cProto.attached;
  3242. const fpPList = function (hostElement) {
  3243. const cnt = insp(hostElement);
  3244. if (beforeParticipantsMap.has(cnt)) return;
  3245. hostElement.classList.add('n9fJ3');
  3246.  
  3247. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  3248. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  3249. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  3250. return;
  3251. }
  3252.  
  3253. groupCollapsed("Participant List attached", "");
  3254. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  3255. // console.log(123, 'appendChild');
  3256. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  3257. // }
  3258.  
  3259. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  3260. // console.log(123, 'insertBefore');
  3261. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  3262. // }
  3263.  
  3264. cnt.__notifyPath5036__ = cnt.notifyPath
  3265. const participants = ((cnt.participantsManager || 0).participants || 0);
  3266. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  3267. console.log(`initial number of participants: ${participants.length}`);
  3268. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  3269. beforeParticipantsMap.set(cnt, newParticipants);
  3270. cnt.notifyPath = notifyPath7081;
  3271. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  3272. console.groupEnd();
  3273. }
  3274. cProto.attached = function () {
  3275. fpPList(this.hostElement || this);
  3276. this.__attached412__.apply(this, arguments);
  3277. };
  3278.  
  3279.  
  3280. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  3281.  
  3282. /** @type {boolean | (()=>boolean)} */
  3283. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  3284. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  3285.  
  3286. let lastMessageDate = 0;
  3287. cProto.stampDomArray66_ = cProto.stampDomArray_;
  3288.  
  3289. cProto.stampDomArray_ = function (...args) {
  3290. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  3291. if (typeof toUseMaintainStableList === 'function') {
  3292. toUseMaintainStableList = toUseMaintainStableList();
  3293. }
  3294. args[5] = toUseMaintainStableList;
  3295. let currentDate = Date.now();
  3296. if (currentDate - lastMessageDate > 440) {
  3297. lastMessageDate = currentDate;
  3298. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  3299. }
  3300. }
  3301. return this.stampDomArray66_.apply(this, args);
  3302. }
  3303.  
  3304. cProto.stampDomArray_.nIegT = 1;
  3305.  
  3306. }
  3307. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  3308. } else {
  3309. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  3310. }
  3311.  
  3312. console.groupEnd();
  3313.  
  3314. if (onPageElements.length >= 1) {
  3315. for (const s of onPageElements) {
  3316. if (insp(s).isAttached === true) {
  3317. fpPList(s);
  3318. }
  3319. }
  3320. }
  3321.  
  3322. }).catch(console.warn);
  3323.  
  3324. };
  3325.  
  3326. if (DO_PARTICIPANT_LIST_HACKS) {
  3327. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  3328. }
  3329.  
  3330.  
  3331.  
  3332. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  3333.  
  3334. const transitionEndAfterFnSimple = new WeakMap();
  3335. // let prevTransitionClosing = null;
  3336.  
  3337. const fixChildrenIssue = !!fixChildrenIssue801;
  3338. if (fixChildrenIssue && typeof Object.getOwnPropertyDescriptor === 'function' && typeof Proxy !== 'undefined') {
  3339. const divProto = HTMLDivElement.prototype;
  3340. const polymerControllerSetData3 = function (c, d, e) {
  3341. return insp(this).set(c, d, e);
  3342. }
  3343. const polymerControllerSetData2 = function (c, d) {
  3344. return insp(this).set(c, d);
  3345. }
  3346. const dummyFn = function () {
  3347. console.log('dummyFn', ...arguments);
  3348. };
  3349.  
  3350. const wm44 = new Map();
  3351. function unPolymerSet(elem) {
  3352. const is = elem.is;
  3353. if (is && !elem.set) {
  3354. let rt = wm44.get(is);
  3355. if (!rt) {
  3356. rt = 1;
  3357. const cnt = insp(elem);
  3358. if (cnt !== elem && cnt && typeof cnt.set === 'function') {
  3359. const pcSet = cnt.constructor.prototype.set;
  3360. if (pcSet && typeof pcSet === 'function' && pcSet.length === 3) {
  3361. rt = polymerControllerSetData3;
  3362. } else if (pcSet && typeof pcSet === 'function' && pcSet.length === 2) {
  3363. rt = polymerControllerSetData2;
  3364. }
  3365. }
  3366. wm44.set(is, rt);
  3367. }
  3368. if (typeof rt === 'function') {
  3369. elem.set = rt;
  3370. } else {
  3371. elem.set = dummyFn;
  3372. }
  3373. }
  3374. }
  3375. if (!divProto.__children577__ && !divProto.__children578__) {
  3376.  
  3377. const dp = Object.getOwnPropertyDescriptor(Element.prototype, 'children');
  3378. const dp2 = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'children');
  3379. const dp3 = Object.getOwnPropertyDescriptor(divProto, 'children');
  3380.  
  3381. if (dp && dp.configurable === true && dp.enumerable === true && typeof dp.get === 'function' && !dp2 && !dp3) {
  3382.  
  3383. if (divProto instanceof HTMLElement && divProto instanceof Element) {
  3384.  
  3385. let m = Object.assign({}, dp);
  3386. divProto.__children577__ = dp.get;
  3387. divProto.__children578__ = function () {
  3388. if (this.__children803__) return this.__children803__;
  3389. if (this.__children801__) {
  3390. let arr = [];
  3391. for (let elem = this.firstElementChild; elem !== null; elem = elem.nextElementSibling) {
  3392. if (elem.is) {
  3393. unPolymerSet(elem);
  3394. arr.push(elem);
  3395. }
  3396. }
  3397. if (this.__children801__ === 2) this.__children803__ = arr;
  3398. return arr;
  3399. }
  3400. return 577;
  3401. };
  3402. m.get = function () {
  3403. const r = this.__children578__();
  3404. if (r !== 577) return r;
  3405. return this.__children577__();
  3406. };
  3407. Object.defineProperty(divProto, 'children', m);
  3408.  
  3409. console.log('fixChildrenIssue - set OK')
  3410.  
  3411. }
  3412. }
  3413.  
  3414. }
  3415.  
  3416.  
  3417. }
  3418.  
  3419.  
  3420. // const bnForDelayChatOccurrence = () => {
  3421.  
  3422. // document.addEventListener('animationstart', (evt) => {
  3423.  
  3424. // if (evt.animationName === 'dontRenderAnimation') {
  3425. // evt.target.classList.remove('dont-render');
  3426. // if (scrollChatFn) scrollChatFn();
  3427. // }
  3428.  
  3429. // }, true);
  3430.  
  3431. // const f = (elm) => {
  3432. // if (elm && elm.nodeType === 1) {
  3433. // if (!skipDontRender && allowDontRender === true) {
  3434. // // innerTextFixFn();
  3435. // elm.classList.add('dont-render');
  3436. // }
  3437. // }
  3438. // }
  3439.  
  3440. // Node.prototype.__appendChild931__ = function (a) {
  3441. // a = dr(a);
  3442. // if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  3443. // if (a && a.nodeType === 1) f(a);
  3444. // else if (a instanceof DocumentFragment) {
  3445. // for (let n = a.firstChild; n; n = n.nextSibling) {
  3446. // f(n);
  3447. // }
  3448. // }
  3449. // }
  3450. // }
  3451.  
  3452. // Node.prototype.__appendChild932__ = function () {
  3453. // this.__appendChild931__.apply(this, arguments);
  3454. // return Node.prototype.appendChild.apply(this, arguments);
  3455. // }
  3456.  
  3457.  
  3458. // };
  3459.  
  3460. const watchUserCSS = () => {
  3461.  
  3462. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  3463.  
  3464. const getElemFromWR = (nr) => {
  3465. const n = kRef(nr);
  3466. if (n && n.isConnected) return n;
  3467. return null;
  3468. }
  3469.  
  3470. const clearContentVisibilitySizing = () => {
  3471. Promise.resolve().then(() => {
  3472.  
  3473. const e = document.querySelector('#show-more[disabled]');
  3474. let btnShowMoreWR = e ? mWeakRef(e) : null;
  3475.  
  3476. let lastVisibleItemWR = null;
  3477. for (const elm of document.querySelectorAll('[wSr93]')) {
  3478. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  3479. elm.setAttribute('wSr93', '');
  3480. // custom CSS property --wsr94 not working when attribute wSr93 removed
  3481. }
  3482. foregroundPromiseFn().then(() => {
  3483. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  3484. if (btnShowMore) btnShowMore.click();
  3485. else {
  3486. // would not work if switch it frequently
  3487. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  3488. if (lastVisibleItem) {
  3489.  
  3490. Promise.resolve()
  3491. .then(() => lastVisibleItem.scrollIntoView())
  3492. .then(() => lastVisibleItem.scrollIntoView(false))
  3493. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  3494. .catch(e => { }) // break the chain when method not callable
  3495.  
  3496. }
  3497. }
  3498. });
  3499.  
  3500. });
  3501.  
  3502. }
  3503.  
  3504. const mutObserver = new MutationObserver((mutations) => {
  3505. for (const mutation of mutations) {
  3506. if ((mutation.addedNodes || 0).length >= 1) {
  3507. for (const addedNode of mutation.addedNodes) {
  3508. if (addedNode.nodeName === 'STYLE') {
  3509. clearContentVisibilitySizing();
  3510. return;
  3511. }
  3512. }
  3513. }
  3514. if ((mutation.removedNodes || 0).length >= 1) {
  3515. for (const removedNode of mutation.removedNodes) {
  3516. if (removedNode.nodeName === 'STYLE') {
  3517. clearContentVisibilitySizing();
  3518. return;
  3519. }
  3520. }
  3521. }
  3522. }
  3523. });
  3524.  
  3525. mutObserver.observe(document.documentElement, {
  3526. childList: true,
  3527. subtree: false
  3528. });
  3529. mutObserver.observe(document.head, {
  3530. childList: true,
  3531. subtree: false
  3532. });
  3533. mutObserver.observe(document.body, {
  3534. childList: true,
  3535. subtree: false
  3536. });
  3537.  
  3538. }
  3539.  
  3540.  
  3541. // class WillChangeController {
  3542. // constructor(itemScroller, willChangeValue) {
  3543. // this.element = itemScroller;
  3544. // this.counter = 0;
  3545. // this.active = false;
  3546. // this.willChangeValue = willChangeValue;
  3547. // }
  3548.  
  3549. // beforeOper() {
  3550. // if (!this.active) {
  3551. // this.active = true;
  3552. // this.element.style.willChange = this.willChangeValue;
  3553. // }
  3554. // this.counter++;
  3555. // }
  3556.  
  3557. // afterOper() {
  3558. // const c = this.counter;
  3559. // foregroundPromiseFn().then(() => {
  3560. // if (c === this.counter) {
  3561. // this.active = false;
  3562. // this.element.style.willChange = '';
  3563. // }
  3564. // });
  3565. // }
  3566.  
  3567. // release() {
  3568. // const element = this.element;
  3569. // this.element = null;
  3570. // this.counter = 1e16;
  3571. // this.active = false;
  3572. // try {
  3573. // element.style.willChange = '';
  3574. // } catch (e) { }
  3575. // }
  3576.  
  3577. // }
  3578.  
  3579.  
  3580. // const skzData = (skz) => skz.data = {
  3581. // "message": {
  3582. // "runs": [
  3583. // {
  3584. // "text": "em2o"
  3585. // },
  3586. // {
  3587. // "emoji": {
  3588. // "emojiId": "cm35z",
  3589. // "shortcuts": [
  3590. // ":_s:",
  3591. // ":s:"
  3592. // ],
  3593. // "searchTerms": [
  3594. // "_s",
  3595. // "s"
  3596. // ],
  3597. // "image": {
  3598. // "thumbnails": [
  3599. // {
  3600. // "url": dummyImgURL,
  3601. // "width": 48,
  3602. // "height": 48
  3603. // }
  3604. // ],
  3605. // "accessibility": {
  3606. // "accessibilityData": {
  3607. // "label": "s"
  3608. // }
  3609. // }
  3610. // },
  3611. // "isCustomEmoji": true
  3612. // }
  3613. // },
  3614. // {
  3615. // "text": "ji"
  3616. // }
  3617. // ]
  3618. // },
  3619. // "authorName": {
  3620. // "simpleText": "N"
  3621. // },
  3622. // "authorPhoto": {
  3623. // "thumbnails": [
  3624. // {
  3625. // "url": dummyImgURL,
  3626. // "width": 64,
  3627. // "height": 64
  3628. // }
  3629. // ]
  3630. // },
  3631. // "contextMenuEndpoint": {
  3632. // "commandMetadata": {
  3633. // "webCommandMetadata": {
  3634. // "ignoreNavigation": true
  3635. // }
  3636. // },
  3637. // "liveChatItemContextMenuEndpoint": {
  3638. // "params": "123=="
  3639. // }
  3640. // },
  3641. // "id": "sk35z",
  3642. // "timestampUsec": "1232302352350000",
  3643. // "authorBadges": [
  3644. // {
  3645. // "liveChatAuthorBadgeRenderer": {
  3646. // "customThumbnail": {
  3647. // "thumbnails": [
  3648. // {
  3649. // "url": dummyImgURL,
  3650. // "width": 16,
  3651. // "height": 16
  3652. // },
  3653. // {
  3654. // "url": dummyImgURL,
  3655. // "width": 32,
  3656. // "height": 32
  3657. // }
  3658. // ]
  3659. // },
  3660. // "tooltip": "T",
  3661. // "accessibility": {
  3662. // "accessibilityData": {
  3663. // "label": "E"
  3664. // }
  3665. // }
  3666. // }
  3667. // }
  3668. // ],
  3669. // "authorExternalChannelId": "A",
  3670. // "contextMenuAccessibility": {
  3671. // "accessibilityData": {
  3672. // "label": "E"
  3673. // }
  3674. // },
  3675. // "timestampText": {
  3676. // "simpleText": "0:43"
  3677. // }
  3678. // };
  3679.  
  3680.  
  3681.  
  3682. const { lcRendererElm, visObserver } = (() => {
  3683.  
  3684.  
  3685.  
  3686. let lcRendererWR = null;
  3687.  
  3688. const lcRendererElm = () => {
  3689. let lcRenderer = kRef(lcRendererWR);
  3690. if (!lcRenderer || !lcRenderer.isConnected) {
  3691. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  3692. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  3693. }
  3694. return lcRenderer;
  3695. };
  3696.  
  3697.  
  3698. let hasFirstShowMore = false;
  3699.  
  3700. const visObserverFn = (entry) => {
  3701.  
  3702. const target = entry.target;
  3703. if (!target) return;
  3704. // if(target.classList.contains('dont-render')) return;
  3705. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  3706. // const h = entry.boundingClientRect.height;
  3707. /*
  3708. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  3709. // e.g. under fullscreen. the element created but not rendered.
  3710. target.setAttribute('wSr93', '');
  3711. return;
  3712. }
  3713. */
  3714. if (isVisible) {
  3715. // target.style.setProperty('--wsr94', h + 'px');
  3716. target.setAttribute('wSr93', 'visible');
  3717. if (nNextElem(target) === null) {
  3718.  
  3719. // firstVisibleItemDetected = true;
  3720. /*
  3721. if (dateNow() - lastScroll < 80) {
  3722. lastLShow = 0;
  3723. lastScroll = 0;
  3724. Promise.resolve().then(clickShowMore);
  3725. } else {
  3726. lastLShow = dateNow();
  3727. }
  3728. */
  3729. // lastLShow = dateNow();
  3730. } else if (!hasFirstShowMore) { // should more than one item being visible
  3731. // implement inside visObserver to ensure there is sufficient delay
  3732. hasFirstShowMore = true;
  3733. foregroundPromiseFn().then(() => {
  3734. // foreground page
  3735. // page visibly ready -> load the latest comments at initial loading
  3736. const lcRenderer = lcRendererElm();
  3737. if (lcRenderer) {
  3738. if (typeof nextBrowserTick !== 'function') {
  3739. insp(lcRenderer).scrollToBottom_();
  3740. } else {
  3741. nextBrowserTick(() => {
  3742. const cnt = insp(lcRenderer);
  3743. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3744. cnt.scrollToBottom_();
  3745. });
  3746. }
  3747. }
  3748. });
  3749. }
  3750. }
  3751. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  3752.  
  3753. // target.style.setProperty('--wsr94', h + 'px');
  3754. target.setAttribute('wSr93', 'hidden');
  3755. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  3756.  
  3757. }
  3758.  
  3759.  
  3760.  
  3761. const visObserver = new IntersectionObserver((entries) => {
  3762.  
  3763. for (const entry of entries) {
  3764.  
  3765. Promise.resolve(entry).then(visObserverFn);
  3766.  
  3767. }
  3768.  
  3769. }, {
  3770. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  3771. rootMargin: "0px",
  3772. threshold: [0.05, 0.95],
  3773. });
  3774.  
  3775.  
  3776. return { lcRendererElm, visObserver }
  3777.  
  3778.  
  3779. })();
  3780.  
  3781. const { setupMutObserver } = (() => {
  3782.  
  3783. async function asyncTickerBackgroundOverridedChecker() {
  3784.  
  3785. try {
  3786. await promiseForCustomYtElementsReady.then();
  3787. await customElements.whenDefined('yt-live-chat-text-message-renderer');
  3788. await new Promise(r => setTimeout(r, 800));
  3789.  
  3790. if (!hasTimerModified) return;
  3791. const tickerRenderer = document.querySelector('#ticker yt-live-chat-ticker-renderer.style-scope.yt-live-chat-renderer');
  3792. if (!tickerRenderer) return;
  3793.  
  3794. const tickerRendererDollar = indr(tickerRenderer);
  3795. const items = (tickerRendererDollar || 0).items || 0;
  3796. if (!items) return;
  3797. const template = document.createElement('template');
  3798. template.innerHTML = `<yt-live-chat-ticker-dummy777-item-renderer class="style-scope yt-live-chat-ticker-renderer" whole-message-clickable=""
  3799. modern="" aria-label="¥1,000" role="button" tabindex="0" id="Chw777" style="width: 94px; overflow: hidden;"
  3800. dimmed="" [dummy777]>
  3801. <div id="container" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"
  3802. 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));">
  3803. <div id="content" class="style-scope yt-live-chat-ticker-dummy777-item-renderer" style="color: rgb(255, 255, 255);">
  3804. <yt-img-shadow777 id="author-photo" height="24" width="24"
  3805. class="style-scope yt-live-chat-ticker-dummy777-item-renderer no-transition"
  3806. style="background-color: transparent;" loaded=""><img id="img"
  3807. draggable="false" class="style-scope yt-img-shadow" alt="I" height="24" width="24"
  3808. src="${dummyImgURL}"></yt-img-shadow777>
  3809.  
  3810. <span id="text" dir="ltr" class="style-scope yt-live-chat-ticker-dummy777-item-renderer"1,000</span>
  3811. </div>
  3812. </div>
  3813. </yt-live-chat-ticker-dummy777-item-renderer>`;
  3814. const dummy777 = template.content.firstElementChild;
  3815. await Promise.resolve().then();
  3816. let res = 0;
  3817. if (items instanceof HTMLElement && items.isConnected === true) {
  3818. try {
  3819. items.appendChild(dummy777);
  3820. let container = HTMLElement.prototype.querySelector.call(dummy777, '#container') || 0;
  3821. if (container.isConnected === true) {
  3822. const evaluated = `${getComputedStyleCached(container).background}`;
  3823. container = null;
  3824. res = evaluated.indexOf('0.') < 4 ? 1 : 2;
  3825. }
  3826. } catch (e) { console.warn(e) }
  3827. HTMLElement.prototype.remove.call(dummy777);
  3828. }
  3829. await Promise.resolve().then();
  3830. dummy777.textContent = '';
  3831. if (res === 1) {
  3832. // not fulfilling
  3833. // rgba(0, 0, 0, 0.004) none repeat scroll 0% 0% / auto padding-box border-box
  3834. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3835. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3836. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3837. );
  3838. 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');
  3839. console.groupEnd();
  3840. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND (Overriding other scripting)', 'background-color: #7eb32b; color: #102624; padding: 2px 4px');
  3841. } else if (res === 2) {
  3842. console.log('%cALLOW_ADVANCED_ANIMATED_TICKER_BACKGROUND', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3843. }
  3844. } catch (e) {
  3845. console.warn(e);
  3846. }
  3847. }
  3848.  
  3849. // async function asyncDelayChatOccurrence(m2) {
  3850. // try {
  3851. // await promiseForCustomYtElementsReady.then();
  3852. // await customElements.whenDefined('yt-live-chat-text-message-renderer');
  3853. // await new Promise(r => setTimeout(r, 1));
  3854. // const dummy888 = document.createElement('yt-live-chat-text-message-renderer');
  3855. // // const template = document.createElement('template');
  3856. // // template.innerHTML = "<yt-live-chat-text-message-renderer></yt-live-chat-text-message-renderer>"
  3857. // // const dummy888 = template.content.firstElementChild;
  3858. // const skzCnt = insp(dummy888);
  3859. // if (!(skzCnt && 'data' in skzCnt && 'attached' in skzCnt)) {
  3860. // return;
  3861. // }
  3862. // if (!skzCnt.hostElement) skzCnt.hostElement = dummy888;
  3863. // /** @type {HTMLTemplateElement} */
  3864. // const skzElem = dummy888;
  3865. // let cz1 = null;
  3866. // const deferredZy1 = new Promise(resolve => {
  3867. // skzCnt.attached = function () {
  3868. // cz1 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  3869. // resolve(skzElem.textContent);
  3870. // }
  3871. // skzCnt.detached = function () {
  3872. // }
  3873. // });
  3874. // skzElem.id = 'sk35z';
  3875. // skzData(skzCnt);
  3876. // sk35zResolveFn = null;
  3877. // const deferredMutation = new Promise(resolve => {
  3878. // sk35zResolveFn = resolve;
  3879. // HTMLElement.prototype.appendChild.call(m2, skzElem);
  3880. // });
  3881. // const [zy1, _] = await Promise.all([deferredZy1, deferredMutation]);
  3882. // skzCnt.attached = function () { };
  3883. // function fn() {
  3884. // const zy2 = skzElem.textContent;
  3885. // const cz2 = HTMLElement.prototype.querySelector.call(skzElem, '#message img') !== null;
  3886. // if (typeof zy1 === 'string' && typeof zy2 === 'string') {
  3887. // allowDontRender = zy1 === zy2 && cz1 === cz2; // '0:43N​em2oji'
  3888. // }
  3889. // if (allowDontRender === true) return true;
  3890. // if (allowDontRender === false) {
  3891. // console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | Incompatibility Found"}`,
  3892. // "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  3893. // "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  3894. // );
  3895. // 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');
  3896. // console.groupEnd();
  3897. // }
  3898. // }
  3899. // await new Promise(r => setTimeout(r, 1));
  3900. // if (!fn()) return;
  3901. // await foregroundPromiseFn().then();
  3902. // if (!fn()) return;
  3903. // skzElem.remove();
  3904. // await Promise.resolve().then();
  3905. // skzElem.textContent = '';
  3906. // console.log('%cALLOW_DELAYED_CHAT_OCCURRENCE', 'background-color: #16c450; color: #102624; padding: 2px 4px');
  3907. // } catch (e) {
  3908. // console.warn(e);
  3909. // }
  3910. // }
  3911.  
  3912. const mutFn = (items) => {
  3913. let seqIndex = -1;
  3914. const elementSet = new Set();
  3915. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  3916. if (node.hasAttribute('wSr93')) {
  3917. seqIndex = parseInt(node.getAttribute('yt-chat-item-seq'), 10);
  3918. break;
  3919. }
  3920. node.setAttribute('wSr93', '');
  3921. visObserver.observe(node);
  3922. elementSet.add(node);
  3923. }
  3924. let iter = elementSet.values();
  3925. let i = seqIndex + elementSet.size;
  3926. for (let curr; curr = iter.next().value;) {
  3927. curr.setAttribute('yt-chat-item-seq', i % 60);
  3928. curr.classList.add('yt-chat-item-' + ((i % 2) ? 'odd' : 'even'));
  3929. i--;
  3930. }
  3931. iter = null;
  3932. elementSet.clear();
  3933. }
  3934.  
  3935. const mutObserver = new MutationObserver((mutations) => {
  3936. const items = (mutations[0] || 0).target;
  3937. if (!items) return;
  3938. if (sk35zResolveFn) {
  3939. sk35zResolveFn();
  3940. sk35zResolveFn = null;
  3941. }
  3942. mutFn(items);
  3943. });
  3944.  
  3945. const setupMutObserver = (m2) => {
  3946. scrollChatFn = null;
  3947. mutObserver.disconnect();
  3948. mutObserver.takeRecords();
  3949. if (m2) {
  3950. if (typeof m2.__appendChild932__ === 'function') {
  3951. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  3952. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  3953. }
  3954. mutObserver.observe(m2, {
  3955. childList: true,
  3956. subtree: false
  3957. });
  3958. mutFn(m2);
  3959.  
  3960. const isFirstList = firstList;
  3961. firstList = false;
  3962.  
  3963. if (ENABLE_OVERFLOW_ANCHOR) {
  3964.  
  3965. let items = m2;
  3966. let addedAnchor = false;
  3967. if (items) {
  3968. if (items.nextElementSibling === null) {
  3969. items.classList.add('no-anchor');
  3970. addedAnchor = true;
  3971. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  3972. }
  3973. }
  3974.  
  3975.  
  3976.  
  3977. if (addedAnchor) {
  3978. nodeParent(m2).classList.add('no-anchor'); // required
  3979. }
  3980.  
  3981. }
  3982.  
  3983.  
  3984.  
  3985. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  3986.  
  3987. (() => {
  3988.  
  3989. const tag = 'yt-iframed-player-events-relay'
  3990. const dummy = document.createElement(tag);
  3991.  
  3992. const cProto = getProto(dummy);
  3993. if (!cProto || !cProto.handlePostMessage_) {
  3994. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  3995. return;
  3996. }
  3997.  
  3998. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_ && !cProto.handlePostMessage67_ ) {
  3999.  
  4000. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  4001.  
  4002. const handlePostMessageAfterPromiseA = (da) => {
  4003.  
  4004. if (!da || typeof da !== 'object') return;
  4005.  
  4006. if ('yt-player-state-change' in da) {
  4007.  
  4008. const qc = da['yt-player-state-change'];
  4009.  
  4010.  
  4011. let isQcChanged = false;
  4012.  
  4013. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  4014. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  4015. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  4016.  
  4017.  
  4018. if ((isQcChanged) && playerState !== _playerState) {
  4019. playerEventsByIframeRelay = true;
  4020. onPlayStateChangePromise = new Promise((resolve) => {
  4021. const k = _playerState;
  4022. foregroundPromiseFn().then(() => {
  4023. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  4024. onPlayStateChangePromise = null;
  4025. resolve();
  4026. })
  4027. }).catch(console.warn);
  4028.  
  4029. }
  4030.  
  4031. } else if ('yt-player-video-progress' in da) {
  4032. const vp = da['yt-player-video-progress'];
  4033.  
  4034.  
  4035. relayCount++;
  4036. lastPlayerProgress = vp > 0 ? vp : 0;
  4037.  
  4038.  
  4039. if (relayPromise && vp > 0 && relayCount >= 2) {
  4040. if (onPlayStateChangePromise) {
  4041. onPlayStateChangePromise.then(() => {
  4042. relayPromise && relayPromise.resolve();
  4043. relayPromise = null;
  4044. })
  4045. } else {
  4046. relayPromise.resolve();
  4047. relayPromise = null;
  4048. }
  4049. }
  4050.  
  4051. }
  4052.  
  4053. };
  4054.  
  4055. cProto.handlePostMessage67_ = function (a) {
  4056.  
  4057. let da = a.data;
  4058. const wNode = mWeakRef(this);
  4059. // const wData = mWeakRef(da);
  4060.  
  4061. playEventsStack = playEventsStack.then(() => {
  4062.  
  4063. const cnt = kRef(wNode);
  4064. // const da = kRef(wData);
  4065.  
  4066. if (!cnt || !a || !da) return;
  4067. handlePostMessageAfterPromiseA(da);
  4068. da = null;
  4069.  
  4070. const r = cnt.handlePostMessage66_(a);
  4071. a = null;
  4072.  
  4073. }).catch(console.warn);
  4074.  
  4075. }
  4076.  
  4077. const handlePostMessageAfterPromiseB = (da) => {
  4078.  
  4079. const lcr = document.querySelector('yt-live-chat-renderer');
  4080. const psc = document.querySelector("yt-player-seek-continuation");
  4081. if (lcr && psc && lcr.replayBuffer_) {
  4082.  
  4083. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  4084. const daProgress = da['yt-player-video-progress'] * 1000
  4085. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  4086.  
  4087. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  4088. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  4089.  
  4090. // console.log(deepCopy( front_))
  4091. // console.log(deepCopy( back_))
  4092. // console.log(rbProgress, daProgress, )
  4093. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  4094. // no action
  4095. // console.log('ss1')
  4096. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  4097. // daProgress - 1200 < rbProgress < daProgress + 3400
  4098. // console.log('ss2')
  4099. } else {
  4100.  
  4101. lcr.previousProgressSec = 1E-5;
  4102. // lcr._setIsSeeking(!0),
  4103. lcr.replayBuffer_.clear()
  4104. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  4105. }
  4106.  
  4107. }
  4108.  
  4109.  
  4110. };
  4111.  
  4112. cProto.handlePostMessage_ = function (a) {
  4113.  
  4114. let da = (a || 0).data || 0;
  4115. const wNode = mWeakRef(this);
  4116.  
  4117. if (typeof da !== 'object') return;
  4118.  
  4119. if (waitForInitialDataCompletion === 1) return;
  4120.  
  4121. if (!isPlayProgressTriggered) {
  4122. isPlayProgressTriggered = true; // set once
  4123.  
  4124. if ('yt-player-video-progress' in da) {
  4125. waitForInitialDataCompletion = 1;
  4126.  
  4127. const wrapWith = (data) => {
  4128. const { origin } = a;
  4129. return {
  4130. origin,
  4131. data
  4132. };
  4133. }
  4134.  
  4135. this.handlePostMessage67_(wrapWith({
  4136. "yt-iframed-parent-ready": true
  4137. }));
  4138.  
  4139.  
  4140. playEventsStack = playEventsStack.then(() => {
  4141.  
  4142. const cnt = kRef(wNode);
  4143.  
  4144. if (!cnt || !a || !da) return;
  4145.  
  4146. handlePostMessageAfterPromiseB(da);
  4147. da = null;
  4148.  
  4149. waitForInitialDataCompletion = 2;
  4150.  
  4151. const r = cnt.handlePostMessage_(a); // isPlayProgressTriggered is set
  4152. a = null;
  4153.  
  4154. }).catch(console.warn);
  4155.  
  4156. return;
  4157.  
  4158. }
  4159.  
  4160. }
  4161.  
  4162. this.handlePostMessage67_(a);
  4163.  
  4164. }
  4165.  
  4166. }
  4167.  
  4168.  
  4169. })();
  4170.  
  4171. }
  4172.  
  4173. if (isFirstList && DO_CHECK_TICKER_BACKGROUND_OVERRIDED) {
  4174. asyncTickerBackgroundOverridedChecker();
  4175. }
  4176.  
  4177. }
  4178. }
  4179.  
  4180. return { setupMutObserver };
  4181.  
  4182.  
  4183.  
  4184. })();
  4185.  
  4186. const setupEvents = () => {
  4187.  
  4188.  
  4189. let scrollCount = 0;
  4190.  
  4191. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  4192.  
  4193.  
  4194. const delayFlushActiveItemsAfterUserActionK_ = () => {
  4195.  
  4196. const lcRenderer = lcRendererElm();
  4197. if (lcRenderer) {
  4198. const cnt = insp(lcRenderer);
  4199. if (!cnt.hasUserJustInteracted11_) return;
  4200. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  4201. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  4202. }
  4203. }
  4204.  
  4205. }
  4206.  
  4207. document.addEventListener('scroll', (evt) => {
  4208. if (!evt || !evt.isTrusted) return;
  4209. // lastScroll = dateNow();
  4210. if (++scrollCount > 1e9) scrollCount = 9;
  4211. }, passiveCapture); // support contain => support passive
  4212.  
  4213. let lastScrollCount = -1;
  4214. document.addEventListener('wheel', (evt) => {
  4215. if (!evt || !evt.isTrusted) return;
  4216. if (lastScrollCount === scrollCount) return;
  4217. lastScrollCount = scrollCount;
  4218. lastWheel = dateNow();
  4219. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4220. }, passiveCapture); // support contain => support passive
  4221.  
  4222. document.addEventListener('mousedown', (evt) => {
  4223. if (!evt || !evt.isTrusted) return;
  4224. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4225. lastMouseDown = dateNow();
  4226. currentMouseDown = true;
  4227. lastUserInteraction = lastMouseDown;
  4228. }, passiveCapture);
  4229.  
  4230. document.addEventListener('pointerdown', (evt) => {
  4231. if (!evt || !evt.isTrusted) return;
  4232. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4233. lastMouseDown = dateNow();
  4234. currentMouseDown = true;
  4235. lastUserInteraction = lastMouseDown;
  4236. }, passiveCapture);
  4237.  
  4238. document.addEventListener('click', (evt) => {
  4239. if (!evt || !evt.isTrusted) return;
  4240. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4241. lastMouseDown = lastMouseUp = dateNow();
  4242. currentMouseDown = false;
  4243. lastUserInteraction = lastMouseDown;
  4244. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4245. }, passiveCapture);
  4246.  
  4247. document.addEventListener('tap', (evt) => {
  4248. if (!evt || !evt.isTrusted) return;
  4249. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4250. lastMouseDown = lastMouseUp = dateNow();
  4251. currentMouseDown = false;
  4252. lastUserInteraction = lastMouseDown;
  4253. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4254. }, passiveCapture);
  4255.  
  4256.  
  4257. document.addEventListener('mouseup', (evt) => {
  4258. if (!evt || !evt.isTrusted) return;
  4259. if (currentMouseDown) {
  4260. lastMouseUp = dateNow();
  4261. currentMouseDown = false;
  4262. lastUserInteraction = lastMouseUp;
  4263. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4264. }
  4265. }, passiveCapture);
  4266.  
  4267.  
  4268. document.addEventListener('pointerup', (evt) => {
  4269. if (!evt || !evt.isTrusted) return;
  4270. if (currentMouseDown) {
  4271. lastMouseUp = dateNow();
  4272. currentMouseDown = false;
  4273. lastUserInteraction = lastMouseUp;
  4274. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4275. }
  4276. }, passiveCapture);
  4277.  
  4278. document.addEventListener('touchstart', (evt) => {
  4279. if (!evt || !evt.isTrusted) return;
  4280. lastTouchDown = dateNow();
  4281. currentTouchDown = true;
  4282. lastUserInteraction = lastTouchDown;
  4283. }, passiveCapture);
  4284.  
  4285. document.addEventListener('touchmove', (evt) => {
  4286. if (!evt || !evt.isTrusted) return;
  4287. lastTouchDown = dateNow();
  4288. currentTouchDown = true;
  4289. lastUserInteraction = lastTouchDown;
  4290. }, passiveCapture);
  4291.  
  4292. document.addEventListener('touchend', (evt) => {
  4293. if (!evt || !evt.isTrusted) return;
  4294. if (currentTouchDown) {
  4295. lastTouchUp = dateNow();
  4296. currentTouchDown = false;
  4297. lastUserInteraction = lastTouchUp;
  4298. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4299. }
  4300. }, passiveCapture);
  4301.  
  4302. document.addEventListener('touchcancel', (evt) => {
  4303. if (!evt || !evt.isTrusted) return;
  4304. if (currentTouchDown) {
  4305. lastTouchUp = dateNow();
  4306. currentTouchDown = false;
  4307. lastUserInteraction = lastTouchUp;
  4308. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4309. }
  4310. }, passiveCapture);
  4311.  
  4312.  
  4313. }
  4314.  
  4315. const getTimestampUsec = (itemRenderer) => {
  4316. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  4317. return itemRenderer.timestampUsec
  4318. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  4319. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  4320. if (messageRenderer) {
  4321.  
  4322. const messageRendererKey = firstObjectKey(messageRenderer);
  4323. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  4324. const messageRendererData = messageRenderer[messageRendererKey];
  4325. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  4326. return messageRendererData.timestampUsec
  4327. }
  4328. }
  4329. }
  4330. }
  4331. return null;
  4332. }
  4333.  
  4334. const onRegistryReadyForDOMOperations = () => {
  4335.  
  4336. let firstCheckedOnYtInit = false;
  4337.  
  4338. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  4339.  
  4340. const mightFirstCheckOnYtInit = () => {
  4341. if (firstCheckedOnYtInit) return;
  4342. firstCheckedOnYtInit = true;
  4343.  
  4344. if (!document.body || !document.head) return;
  4345. if (!assertorURL()) return;
  4346.  
  4347. addCssManaged();
  4348.  
  4349. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  4350. if (efsContainer && efsContainer.parentNode !== document.body) {
  4351. document.body.appendChild(efsContainer);
  4352. }
  4353.  
  4354. };
  4355.  
  4356. if (!assertorURL()) return;
  4357. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  4358.  
  4359.  
  4360. const { weakWrap } = (() => {
  4361.  
  4362.  
  4363. // const tickerFuncProps = new Set([
  4364. // 'animateShowStats', 'animateHideStats', // updateStatsBarAndMaybeShowAnimationRevised
  4365. // 'collapse', // slideDownNoSelfLeakage
  4366. // 'requestRemoval', // collapseNoSelfLeakage
  4367. // 'setContainerWidth', 'get', 'set', // deletedChangedNoSelfLeakage
  4368. // 'computeAriaLabel', //dataChanged
  4369. // 'startCountdown', // dataChanged [in case]
  4370. // ]);
  4371.  
  4372. // const tickerTags = new Set([
  4373. // "yt-live-chat-ticker-renderer",
  4374. // "yt-live-chat-ticker-paid-message-item-renderer",
  4375. // "yt-live-chat-ticker-paid-sticker-item-renderer",
  4376. // "yt-live-chat-ticker-sponsor-item-renderer"
  4377. // ]);
  4378.  
  4379. // const emptySet = new Set();
  4380.  
  4381.  
  4382.  
  4383. // const tickerFuncPropsFn = (cnt) => {
  4384.  
  4385. // const is = `${cnt.is}`;
  4386.  
  4387. // if (tickerTags.has(is)) {
  4388. // let flg = 0;
  4389. // if (cnt.get && cnt.set) flg |= 1;
  4390. // if (cnt.setContainerWidth && cnt.collapse && cnt.requestRemoval) flg |= 2;
  4391. // if (cnt.animateShowStats && cnt.animateHideStats) flg |= 4;
  4392. // if (cnt.startCountdown) flg |= 8;
  4393. // console.log(`DEBUG flag_6877 = ${flg}`, is);
  4394. // // DEBUG flag_6877 = 15 yt-live-chat-ticker-paid-message-item-renderer
  4395. // // DEBUG flag_6877 = 11 yt-live-chat-ticker-sponsor-item-renderer
  4396. // return tickerFuncProps;
  4397. // }
  4398.  
  4399. // return emptySet;
  4400.  
  4401.  
  4402. // }
  4403.  
  4404.  
  4405. // const smb = Symbol();
  4406. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  4407. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  4408. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  4409.  
  4410.  
  4411.  
  4412.  
  4413. const thisConversionFn = (thisArg) => {
  4414. if (!thisArg) return null;
  4415. const kThis = thisArg[vmb];
  4416. if (kThis) {
  4417. const ref = kThis.ref;
  4418. return (ref ? kRef(ref) : null) || null;
  4419. }
  4420. return thisArg;
  4421. }
  4422. const pFnHandler2 = {
  4423. get(target, prop) {
  4424. if (prop === vmc) return target;
  4425. return Reflect.get(target, prop);
  4426. },
  4427. apply(target, thisArg, argumentsList) {
  4428. thisArg = thisConversionFn(thisArg);
  4429. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  4430. }
  4431. }
  4432. const proxySelfHandler = {
  4433. get(target, prop) {
  4434. if(prop === vmb) return target;
  4435. const ref = target.ref;
  4436. const cnt = kRef(ref);
  4437. if (!cnt) return;
  4438. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  4439. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  4440. return cnt[prop][vmd];
  4441. }
  4442. return cnt[prop];
  4443. },
  4444. set(target, prop, value) {
  4445. const cnt = kRef(target.ref);
  4446. if (!cnt) return true;
  4447. if(value && (value[vmc] || value[vmb])){
  4448. cnt[prop] = value[vmc] || thisConversionFn(value);
  4449. return true;
  4450. }
  4451. cnt[prop] = value;
  4452. return true;
  4453. }
  4454. };
  4455. const weakWrap = (thisArg) => {
  4456. thisArg = thisConversionFn(thisArg);
  4457. if (!thisArg) {
  4458. console.error('thisArg is not found');
  4459. return null;
  4460. }
  4461. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  4462. }
  4463.  
  4464.  
  4465.  
  4466.  
  4467.  
  4468.  
  4469. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  4470. window.getComputedStyle533 = window.getComputedStyle;
  4471. window.getComputedStyle = function (a, ...args) {
  4472. a = thisConversionFn(a);
  4473. if (a) {
  4474. return getComputedStyle533(a, ...args);
  4475. }
  4476. return null;
  4477. }
  4478. }
  4479.  
  4480.  
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486. // const fnProxySelf = function (...args) {
  4487. // const cnt = kRef(this.ref);
  4488. // if (cnt) {
  4489. // return cnt[this.prop](...args); // might throw error
  4490. // }
  4491. // }
  4492. // const proxySelfHandler = {
  4493. // get(target, prop) {
  4494. // const ref = target.ref;
  4495. // const cnt = kRef(ref);
  4496. // if (!cnt) return;
  4497. // if (prop === 'dtz06') return 1;
  4498. // if (typeof cnt[prop] === 'function') {
  4499. // if (!target.funcs.has(prop)) {
  4500. // console.warn(`proxy get to function | prop: ${prop} | is: ${cnt.is}`);
  4501. // }
  4502. // if (!target[`$$${prop}$$`]) target[`$$${prop}$$`] = fnProxySelf.bind({ prop, ref });
  4503. // return target[`$$${prop}$$`];
  4504. // }
  4505. // return cnt[prop];
  4506. // },
  4507. // set(target, prop, value) {
  4508. // const cnt = kRef(target.ref);
  4509. // if (!cnt) return true;
  4510. // if (typeof value === 'function') {
  4511. // console.warn(`proxy set to function | prop: ${prop} | is: ${cnt.is}`);
  4512. // cnt[prop] = value;
  4513. // return true;
  4514. // }
  4515. // cnt[prop] = value;
  4516. // return true;
  4517. // }
  4518. // };
  4519.  
  4520. // return { tickerFuncPropsFn, proxySelfHandler }
  4521.  
  4522. return {weakWrap}
  4523. })();
  4524.  
  4525.  
  4526.  
  4527. if (document.documentElement && document.head) {
  4528. addCssManaged();
  4529. }
  4530. // console.log(document.body===null)
  4531.  
  4532. const preprocessChatLiveActionsMap = new WeakSet();
  4533.  
  4534. const toLAObj=(aItem)=>{
  4535.  
  4536. if (!aItem || typeof aItem !== 'object') return false;
  4537. const key = firstObjectKey(aItem); // addLiveChatTickerItemAction
  4538. if (!key) return false;
  4539. let obj = aItem[key];
  4540. if (!obj || typeof obj !== 'object') return false;
  4541.  
  4542. if (typeof (obj.item || 0) == 'object' && firstObjectKey(obj) === 'item') {
  4543. obj = obj.item;
  4544. const key = firstObjectKey(obj);
  4545. if (key) {
  4546. obj = obj[key];
  4547. }
  4548. }
  4549.  
  4550. return obj;
  4551.  
  4552. };
  4553.  
  4554. const groupsK38=[];
  4555.  
  4556. const weightingFn = (values, weights)=>{
  4557. // assume all weights are positive
  4558. // inf -> NaN
  4559.  
  4560.  
  4561. // Calculate weighted average:
  4562. // Weighted average = (sum of (value_i * weight_i)) / (sum of weights)
  4563. let weightedSum = 0;
  4564. let totalWeight = 0;
  4565.  
  4566. let qv = 0, qw = 0;
  4567. for (let i = 0, l = values.length; i < l; i++) {
  4568. const w = weights[i], v = values[i];
  4569. if (Number.isFinite(w)) {
  4570. weightedSum += v * w;
  4571. totalWeight += w;
  4572. } else {
  4573. qv += v; qw++;
  4574. }
  4575. }
  4576. return qw > 0 ? qv / qw : weightedSum / totalWeight;
  4577. }
  4578.  
  4579. const doConsolidation = (groups)=>{
  4580.  
  4581. const b = 5e5;
  4582. try{
  4583.  
  4584. const nl = groups.length;
  4585. for(const group of groups){
  4586. const [groupStart, groupEnd, groupMid] = group;
  4587. const gCen = (groupStart + groupEnd) / 2;
  4588.  
  4589. group[3] = gCen;
  4590. group[4] = null;
  4591.  
  4592. }
  4593.  
  4594. const resArr = [];
  4595.  
  4596. for (let j = 0; j < nl; j++) {
  4597. const gCenJ = groups[j][3];
  4598.  
  4599. let sb = groups[j][4];
  4600. if(!sb){
  4601. groups[j][4] = sb = new Set();
  4602. resArr.push(sb);
  4603. }
  4604. sb.add(j);
  4605. for (let k = j+1; k < nl; k++) {
  4606. const gCenK = groups[k][3];
  4607.  
  4608. let r = ((gCenK-b >= gCenJ-b && gCenK-b <= gCenJ+b) || (gCenK+b >= gCenJ-b && gCenK+b <= gCenJ+b));
  4609. if(r) {
  4610. sb.add(k);
  4611. if(!groups[k][4]) groups[k][4] = sb;
  4612. }
  4613.  
  4614.  
  4615. }
  4616.  
  4617. }
  4618.  
  4619.  
  4620. const resArr2 = resArr.map(e=>[...e]).map(entry=>{
  4621.  
  4622.  
  4623.  
  4624. const edge1s = entry.map(k => (groups[k][0]));
  4625. const edge2s = entry.map(k => (groups[k][1]));
  4626. const ws = entry.map(k => (groups[k][2]));
  4627.  
  4628. const maxW = Math.max(...ws);
  4629.  
  4630. const weights = ws.map(w=> maxW/w );
  4631.  
  4632. const edge1 = weightingFn(edge1s, weights);
  4633. const edge2 = weightingFn(edge2s, weights);
  4634.  
  4635. const cen = (edge1 + edge2)/2;
  4636.  
  4637.  
  4638. return {
  4639. edge1,
  4640. edge2,
  4641. cen,
  4642. size: ws.reduce((a, b) => a + b, 0),
  4643. entry
  4644. };
  4645.  
  4646. });
  4647. for(const e of resArr){
  4648. e.clear();
  4649. }
  4650. resArr.length = 0;
  4651.  
  4652.  
  4653. return resArr2;
  4654.  
  4655. }catch(e){
  4656.  
  4657. console.warn(e)
  4658. return [];
  4659.  
  4660. }
  4661.  
  4662. // console.log(4546, 'resArr', resArr2)
  4663.  
  4664.  
  4665.  
  4666. }
  4667.  
  4668. /*
  4669. const doConsolidation = (groups)=>{
  4670.  
  4671. const consolidatedGroups = [];
  4672. for(const group of groups){
  4673. const [groupStart, groupEnd] = group;
  4674. const gCen = (groupStart + groupEnd) / 2;
  4675. let [gMin, gMax] = [gCen - 0.5, gCen + 0.5];
  4676. consolidatedGroups.push({gMin, gCen, gMax, groups:[], reductionFactor: 1.0});
  4677.  
  4678. }
  4679.  
  4680. for (let j = 0; j < consolidatedGroups.length; j++) {
  4681. const { gMin: gMinJ, gCen: gCenJ, gMax: gMaxJ, groups: groupsJ } = consolidatedGroups[j];
  4682. for (let k = 0; k < consolidatedGroups.length; k++) {
  4683.  
  4684. const { gMin: gMinK, gCen: gCenK, gMax: gMaxK } = consolidatedGroups[k];
  4685.  
  4686. let r = ((gMinK >= gMinJ && gMinK <= gMaxJ) || (gMaxK >= gMinJ && gMaxK <= gMaxJ));
  4687. if (r) groupsJ.push(k);
  4688.  
  4689. }
  4690. if(groupsJ.length > 1){
  4691.  
  4692. let vMin = 0.0, vMax = 1.0; // vMin = no overlapping; vMax = with overlapping
  4693.  
  4694. while ((vMax - vMin) > 1e-3 && vMin > 0) {
  4695. let vMid = (vMin+vMax)/2;
  4696.  
  4697. let wJ = (gMaxJ - gMinJ);
  4698. let gMinJr = gCenJ - wJ * vMid;
  4699. let gMaxJr = gCenJ + wJ * vMid;
  4700. let overlapped = false;
  4701.  
  4702. for (const k of groupsJ) {
  4703. if (k === j) continue;
  4704.  
  4705. const { gMin: gMinK, gCen: gCenK, gMax: gMaxK } = consolidatedGroups[k];
  4706.  
  4707. let wK = (gMaxK - gMinK);
  4708. let gMinKr = gCenK - wK * vMid;
  4709. let gMaxKr = gCenK + wK * vMid;
  4710.  
  4711. let r = ((gMinKr >= gMinJr && gMinKr <= gMaxJr) || (gMaxKr >= gMinJr && gMaxKr <= gMaxJr));
  4712. if (r) {
  4713. overlapped = true;
  4714. break;
  4715. }
  4716.  
  4717. }
  4718. if(overlapped) vMax = vMid;
  4719. else vMin = vMid;
  4720. }
  4721.  
  4722. // 0.14453125 0.1455078125
  4723. // 0.0322265625 0.033203125
  4724. consolidatedGroups[j].reductionFactor = vMin;
  4725. // console.log(3475, groupsJ, vMin, vMax )
  4726.  
  4727.  
  4728. }
  4729. }
  4730.  
  4731. const aFactors = new Array(consolidatedGroups.length).fill(1);
  4732. for (let j = 0; j < consolidatedGroups.length; j++) {
  4733. const groups = consolidatedGroups[j].groups;
  4734. const reductionFactor = consolidatedGroups[j].reductionFactor;
  4735. if (reductionFactor < 1) {
  4736. for (const k of groups) {
  4737. if (reductionFactor < aFactors[k]) aFactors[k] = reductionFactor;
  4738. }
  4739. }
  4740. }
  4741.  
  4742.  
  4743. const consolidatedGroups2 = new Array(consolidatedGroups.length);
  4744. for (let j = 0; j < consolidatedGroups.length; j++) {
  4745.  
  4746. const factor = aFactors[j];
  4747. const gCen = consolidatedGroups[j].gCen;
  4748. const gW = consolidatedGroups[j].gMax - consolidatedGroups[j].gMin;
  4749. consolidatedGroups2[j] = {
  4750. gMin:consolidatedGroups[j].gMin,
  4751. gMax:consolidatedGroups[j].gMax,
  4752. sMin: gCen - gW * factor,
  4753. gCen: gCen,
  4754. sMax: gCen + gW * factor,
  4755. reductionFactor: factor
  4756. }
  4757.  
  4758. }
  4759.  
  4760. console.log('consolidatedGroups2', consolidatedGroups2)
  4761.  
  4762. return consolidatedGroups2;
  4763. }
  4764. */
  4765.  
  4766. function insertIntoSortedArray(arr, val) {
  4767. // Define the binary search boundaries
  4768. let left = 0;
  4769. let right = arr.length;
  4770. // Perform binary search to find correct insertion index
  4771. while (left < right) {
  4772. const mid = (left + right) >>> 1; // Using bitwise for floor division
  4773. if (arr[mid] < val) {
  4774. left = mid + 1;
  4775. } else {
  4776. right = mid;
  4777. }
  4778. }
  4779. // Insert the value at the found index
  4780. arr.splice(left, 0, val);
  4781. }
  4782.  
  4783. function intervalsOverlap(a1, a2, b1, b2) {
  4784. // Order the intervals without using Math functions
  4785. var startA = a1 <= a2 ? a1 : a2;
  4786. var endA = a1 <= a2 ? a2 : a1;
  4787. var startB = b1 <= b2 ? b1 : b2;
  4788. var endB = b1 <= b2 ? b2 : b1;
  4789. // Check for overlap
  4790. return endA >= startB && endB >= startA;
  4791. }
  4792.  
  4793.  
  4794. const insertIntoSortedArrayA27 = (arr, val) => {
  4795. let left = 0;
  4796. let right = arr.length;
  4797. // Binary search to find the correct insertion index:
  4798. // We want the first index where arr[index][2] >= val[2].
  4799. while (left < right) {
  4800. const mid = (left + right) >>> 1;
  4801. if (arr[mid][2] < val[2]) {
  4802. left = mid + 1;
  4803. } else {
  4804. right = mid;
  4805. }
  4806. }
  4807. // 'left' is now the insertion index
  4808. left === right ? arr.push(val): arr.splice(left, 0, val);
  4809. };
  4810.  
  4811.  
  4812. const insertIntoSortedArrayA28 = (arr, val) => {
  4813. let left = 0;
  4814. const n = arr.length;
  4815. let right = n;
  4816. // Binary search to find the correct insertion index:
  4817. // We want the first index where arr[index][2] >= val[2].
  4818. while (left < right) {
  4819. const mid = (left + right) >>> 1;
  4820. if (arr[mid][0] < val[0]) {
  4821. left = mid + 1;
  4822. } else {
  4823. right = mid;
  4824. }
  4825. }
  4826. // 'left' is now the insertion index
  4827. left === n ? arr.push(val): arr.splice(left, 0, val);
  4828. };
  4829.  
  4830. /*
  4831. const insertIntoSortedArrayA27 = (arr, val)=>{
  4832. // Define the binary search boundaries
  4833. let left = 0;
  4834. let right = arr.length-1;
  4835. // Perform binary search to find correct insertion index
  4836. while (right - left > 1) {
  4837. const mid = (left + right) >>> 1; // Using bitwise for floor division
  4838. if (arr[mid][2] <= val[2]) {
  4839. left = mid;
  4840. } else {
  4841. right = mid;
  4842. }
  4843. }
  4844. let i = -1;
  4845. if (right >= 0 && right >= left && arr[right][2] <= val[2]) i = right + 1;
  4846. else if (left >= 0 && right >= left && arr[left][2] <= val[2]) i = left + 1;
  4847. else if (left === 0 && right >= left) i = 0;
  4848. if (i >= 0) {
  4849.  
  4850. // Insert the value at the found index
  4851. arr.splice(i, 0, val);
  4852.  
  4853. } else {
  4854. arr.push(val);
  4855. }
  4856.  
  4857. }
  4858. */
  4859. function removeNullsInPlace(arr, startI = 0) {
  4860. let insertPos = startI;
  4861. for (let i = startI; i < arr.length; i++) {
  4862. if (arr[i] !== null) {
  4863. insertPos !== i && (arr[insertPos] = arr[i]);
  4864. insertPos++;
  4865. }
  4866. }
  4867. arr.length = insertPos; // Remove the trailing nulls.
  4868. }
  4869.  
  4870. const preprocessChatLiveActions = (arr) =>{
  4871.  
  4872. if(!arr || !arr.length) return arr;
  4873.  
  4874. if(preprocessChatLiveActionsMap.has(arr)) return arr;
  4875. preprocessChatLiveActionsMap.add(arr);
  4876.  
  4877.  
  4878.  
  4879. const ct = Date.now();
  4880.  
  4881. let groups_ = null;
  4882.  
  4883. // console.log(1237005);
  4884. // const conversionMap = new WeakMap();
  4885.  
  4886. const additionalInfo = new WeakMap();
  4887.  
  4888. // const adjustmentMap = new Map();
  4889.  
  4890. if (FIX_TIMESTAMP_FOR_REPLAY) {
  4891.  
  4892. // console.log('group02331')
  4893. // console.time('FIX_TIMESTAMP_FOR_REPLAY')
  4894.  
  4895. // const stack = new Array(arr.length);
  4896. // let stackL = 0;
  4897.  
  4898. // const arrHash = new Array(arr.length);
  4899.  
  4900.  
  4901. const groups = groupsK38;
  4902. // const delta = 2.0; // head-to-tail + 0.5 + 0.5 = 1.0 -> symmetric -> 1.0 * 2 = 2.0
  4903. // (2)
  4904. // (1.5, 2.5)
  4905. // (1.51, 2.49)
  4906. // -> (1.01, 2.01) , (1.99, 2.99)
  4907. // 2.99 - 1.01 = 1.98 -> 2
  4908.  
  4909.  
  4910.  
  4911. const pushToGroup = (t0mu)=>{
  4912.  
  4913. const t0auDv = t0mu - 1e6; // t0buDv - t0auDv = 2e6
  4914. const t0buDv = t0mu + 1e6;
  4915. // const t0auEv = t0mu - 2e6;
  4916. // const t0buEv = t0mu + 2e6;
  4917.  
  4918. let groupK = false;
  4919. // let m = -1;
  4920. // let q= 0;
  4921. //const qq =true;
  4922. //qq && console.log('-------')
  4923.  
  4924. let lastRight = null;
  4925. let lastK = null;
  4926. let deletedStartIndex = -1;
  4927.  
  4928. for (let k = 0, kl = groups.length; k < kl; k++) {
  4929.  
  4930. const group = groups[k];
  4931. const [groupStart, groupEnd, gCount] = group;
  4932. //qq && console.log(`-- ${k} ----- ${groupMid} : [${groupStart},${groupEnd}] || C1 = ${t0buEv < groupMid} || C2 = ${t0auEv > groupMid}`);
  4933.  
  4934. // if (t0bsEv < groupMid) continue; // if(t0m + 1.0 < groupMid - 1.0) continue;
  4935. // if (m < 0) m = k;
  4936. // if (t0asEv > groupMid){
  4937. // continue; // if(t0m - 1.0 > groupMid + 1.0) break;
  4938. // }
  4939.  
  4940.  
  4941. // if (m < 0) m = k;
  4942.  
  4943. if (lastRight > groupStart) {
  4944. if (!groupK) {
  4945. // just in case sth wrong
  4946. console.warn('logic ERROR');
  4947. groups[k] = null;
  4948. if(deletedStartIndex < 0) deletedStartIndex = k;
  4949. break;
  4950. } else {
  4951.  
  4952.  
  4953. // GroupA: N_a' = N_a + n_e{1} ; Note n_e is the only way to shift right to cause " (lastRight > groupStart) "
  4954. // GroupB: N_b
  4955. // Merge Group (A) = N_a' + N_b
  4956.  
  4957. // without entry moditification, no overlap
  4958. // this must be due to entry moditifcation
  4959. // entry is already count. so can be skipped after merging
  4960.  
  4961. // for merging, groupA will move to right side but left than groupB, so no overlap to groupC
  4962.  
  4963. const group = groups[lastK];
  4964.  
  4965. group[0] = (group[0] * group[2] + groupStart * gCount) / (group[2] + gCount)
  4966.  
  4967. group[1] = lastRight = (group[1] * group[2] + groupEnd * gCount) / (group[2] + gCount)
  4968.  
  4969. group[2] = (group[2] + gCount);
  4970. // no change of lastK
  4971. groups[k] = null;
  4972. if(deletedStartIndex < 0) deletedStartIndex = k;
  4973. continue;
  4974. }
  4975. }
  4976.  
  4977. const minGroupStart = lastRight; // all groupStart, groupEnd >= minGroupStart for k, k+1, ...
  4978. if (t0buDv < minGroupStart) {
  4979. // no overlapping could be possible
  4980. break;
  4981. }
  4982.  
  4983. if (intervalsOverlap(t0auDv, t0buDv, groupStart, groupEnd)) {
  4984.  
  4985. groupK = true;
  4986.  
  4987. // if (t0auDv > groupStart) group[0] = t0auDv;
  4988. // else if (t0buDv < groupEnd) group[1] = t0buDv;
  4989.  
  4990. const newStart = (groupStart * gCount + t0auDv) / (gCount + 1);
  4991.  
  4992. if (newStart < lastRight) {
  4993. // n_e{1} will make N_b shift left
  4994.  
  4995. // GroupA: N_a
  4996. // GroupB: N_b
  4997. // Merge Group (A) = N_a + N_b + n_e{1}
  4998.  
  4999. const group = groups[lastK];
  5000.  
  5001. group[0] = (group[0] * group[2] + groupStart * gCount + t0auDv) / (group[2] + gCount + 1)
  5002.  
  5003. group[1] = lastRight = (group[1] * group[2] + groupEnd * gCount + t0buDv) / (group[2] + gCount + 1)
  5004.  
  5005. group[2] = (group[2] + gCount + 1);
  5006. // no change of lastK
  5007. groups[k] = null;
  5008. if(deletedStartIndex < 0) deletedStartIndex = k;
  5009. continue;
  5010.  
  5011. } else {
  5012. // n_e{1} will make N_b shift either left or right
  5013.  
  5014. // GroupT: N_t
  5015. // Group (T) = N_t + n_e{1}
  5016.  
  5017. group[0] = newStart;
  5018. group[1] = lastRight = (groupEnd * gCount + t0buDv) / (gCount + 1);
  5019. group[2] = gCount + 1;
  5020.  
  5021. lastK = k;
  5022.  
  5023. // (t0asDv > groupStart) && (t0bsDv < groupEnd) means full containement
  5024. // however, group size is smaller than or equal to t0width
  5025. }
  5026.  
  5027. } else {
  5028. // just update record for next iteration
  5029.  
  5030. lastRight = groupEnd;
  5031. lastK = k;
  5032. }
  5033.  
  5034.  
  5035.  
  5036. }
  5037.  
  5038. if (deletedStartIndex >= 0) {
  5039. // rarely used
  5040.  
  5041. removeNullsInPlace(groups, deletedStartIndex);
  5042.  
  5043. }
  5044. if (!groupK) {
  5045. // groups.push([t0auDv, t0buDv, 1]);
  5046. insertIntoSortedArrayA28(groups, [t0auDv, t0buDv, 1]);
  5047. // insertIntoSortedArrayA27(groups, [t0auDv, t0buDv, t0mu]);
  5048. }
  5049.  
  5050.  
  5051. }
  5052.  
  5053. let autoTimeStampFrameChoose = 0;
  5054.  
  5055. const noTransform = (x) => {
  5056. return x;
  5057. }
  5058.  
  5059. const prettyNum = (x) => {
  5060.  
  5061. if (x > 1110553200000000) return +(x / 1e6 - autoTimeStampFrameChoose).toFixed(2);
  5062. return x;
  5063. }
  5064.  
  5065.  
  5066. // console.log('group02332')
  5067. for (let j = 0, l = arr.length; j < l; j++) {
  5068. const aItem = arr[j];
  5069.  
  5070. const obj = toLAObj(aItem);
  5071. if (obj === false) continue;
  5072.  
  5073. let p = obj.timestampText;
  5074. let p2, p3=null, p4a=null, p4b=null;
  5075. if(p&&p.simpleText ) p2 = p.simpleText;
  5076.  
  5077. let q = obj.timestampUsec ;
  5078. let q2;
  5079. if(q && +q > 1110553200000000) q2 = +q;
  5080. if (q2 > 0 && !autoTimeStampFrameChoose) {
  5081. const q2cc = Math.round(q2 / 1e6);
  5082. autoTimeStampFrameChoose = q2cc - (q2cc % 10000000);
  5083. if (q2cc - autoTimeStampFrameChoose < 2000000) autoTimeStampFrameChoose -= 10000000;
  5084. // around 10day range
  5085. // exceeded ~10day -> above 10000000
  5086. }
  5087.  
  5088. // console.log('group02333', p2, q2)
  5089. // console.log(3775, q2/1e6, autoTimeStampFrameChoose)
  5090.  
  5091. if(p2 && q2){
  5092.  
  5093. let m;
  5094.  
  5095. if (m = /^\s*(-?)(\d+):(\d+)\s*$/.exec(p2)) {
  5096. let c0z = m[1] ? -1 : 1;
  5097. let c1 = (+m[2]);
  5098. let c2 = (+m[3]);
  5099. if (c0z > 0 && c1 >= 0 && c2 >= 0) {
  5100.  
  5101. p3 = c1 * 60 + c2;
  5102. } else if (c0z < 0 && c1 >= 0 && c2 >= 0) {
  5103. // -4:43 -> -4:42 -> -4:41 ... -> -4:01 -> -4:00 -> -3:59 -> -3:58
  5104. // -> ... -1:01 -> -1:00 -> -0:59 -> ... -> -0:02 -> -0:01 -> -0:00 -> 0:00 -> ...
  5105.  
  5106. p3 = (-c1 * 60) + (-c2);
  5107.  
  5108. }
  5109. if (p3 !== null) {
  5110. // 0:14 -> 13.5s ~ 14.4999s -> [13.5, 14.5)
  5111. p4a = p3 - 0.5;
  5112. p4b = p3 + 0.5;
  5113. }
  5114. } else if (m = /^\s*(-?)(\d+):(\d+):(\d+)\s*$/.exec(p2)) {
  5115.  
  5116. let c0z = m[1] ? -1 : 1;
  5117. let c1 = (+m[2]);
  5118. let c2 = (+m[3]);
  5119. let c3 = (+m[4]);
  5120.  
  5121.  
  5122.  
  5123. if (c0z > 0 && c1 >= 0 && c2 >= 0 && c3 >= 0) {
  5124.  
  5125. p3 = c1 * 60 * 60 + c2 * 60 + c3;
  5126. } else if (c0z < 0 && c1 >= 0 && c2 >= 0 && c3>=0) {
  5127. // -4:43 -> -4:42 -> -4:41 ... -> -4:01 -> -4:00 -> -3:59 -> -3:58
  5128. // -> ... -1:01 -> -1:00 -> -0:59 -> ... -> -0:02 -> -0:01 -> -0:00 -> 0:00 -> ...
  5129.  
  5130. p3 = (-c1 * 60 * 60) + (-c2 * 60) + (-c3);
  5131.  
  5132. }
  5133. if (p3 !== null) {
  5134. // 0:14 -> 13.5s ~ 14.4999s -> [13.5, 14.5)
  5135. p4a = p3 - 0.5;
  5136. p4b = p3 + 0.5;
  5137. }
  5138.  
  5139.  
  5140. }
  5141.  
  5142. }
  5143.  
  5144. if(p4a !== null && p4b !== null && q2 > 0){
  5145.  
  5146. // q2_us = t0_us + dt_us
  5147. // p4a_us <= dt_us < p4b_us
  5148. let p4au = p4a * 1e6;
  5149. let p4bu = p4b * 1e6;
  5150.  
  5151. // p4a_us <= q2_us - t0_us < p4b_us
  5152.  
  5153.  
  5154. // p4a_us - q2_us <= - t0_us < p4b_us - q2_us
  5155.  
  5156. // -p4a_us + q2_us >= t0_us > -p4b_us + q2_us
  5157.  
  5158.  
  5159. let t0au = q2 - p4bu; // q2_us - p4b_us
  5160. let t0bu = q2 - p4au; // q2_us - p4a_us
  5161.  
  5162. // t0 (t0au, t0bu]
  5163.  
  5164. const t0mu = (t0au+t0bu)/2;
  5165.  
  5166. // stack[stackL++]=({
  5167. // id: obj.id,
  5168. // idx: j,
  5169. // p2,
  5170. // // q2s : (q2/ 1e6 - autoTimeStampFrameChoose).toFixed(2),
  5171. // p3,
  5172. // /*
  5173. // timestampText: obj.timestampText,
  5174. // timestampUsec: obj.timestampUsec, // us = 1/1000 ms
  5175. // q2,
  5176. // p4a,
  5177. // p4b,
  5178. // */
  5179. // q2s: +(q2 / 1e6 - autoTimeStampFrameChoose).toFixed(2),
  5180. // t0as: +(t0au / 1e6 - autoTimeStampFrameChoose).toFixed(2),
  5181. // t0bs: +(t0bu /1e6 - autoTimeStampFrameChoose).toFixed(2),
  5182.  
  5183. // t0au,
  5184. // t0bu,
  5185. // t0mu
  5186. // });
  5187.  
  5188. // console.log('group02334')
  5189. let wobj = additionalInfo.get(obj);
  5190. if(!wobj) additionalInfo.set(obj, wobj = {});
  5191.  
  5192. wobj.timestampUsecOriginal = q2;
  5193. // wobj.timestampUsecAdjusted = q2;
  5194. wobj.t0au = t0au;
  5195. wobj.t0bu = t0bu;
  5196. wobj.t0mu = t0mu;
  5197.  
  5198. // arrHash[j] = {
  5199. // index: j,
  5200. // id: obj.id,
  5201. // timestampUsec: q2,
  5202. // t0au,
  5203. // t0bu,
  5204. // t0mu
  5205. // };
  5206.  
  5207. pushToGroup(t0mu);
  5208.  
  5209. // console.log('group02335')
  5210. // console.log('grouping', `${obj.id}.${obj.timestampUsec}`);
  5211.  
  5212. // timestamp (q2) can be incorrect.
  5213.  
  5214. // https://www.youtube.com/watch?v=IKKar5SS29E
  5215. // ChwKGkNQZUxfXzZxLS04Q0ZXNGxyUVlkODZrQzNR
  5216.  
  5217. /*
  5218.  
  5219.  
  5220. [
  5221. {
  5222. "id": "ChwKGkNNWHZqXy1xLS04Q0ZXNGxyUVlkODZrQzNR",
  5223. "p2": "2:04",
  5224. "p3": 124,
  5225. "t0as": 8320733.78,
  5226. "t0bs": 8320734.78
  5227. },
  5228. {
  5229. "id": "ChwKGkNQZUxfXzZxLS04Q0ZXNGxyUVlkODZrQzNR",
  5230. "p2": "2:04",
  5231. "p3": 124,
  5232. "t0as": 8320898.89, // incorrect
  5233. "t0bs": 8320899.89
  5234. }
  5235. ]
  5236.  
  5237.  
  5238. */
  5239.  
  5240. }
  5241.  
  5242.  
  5243. }
  5244.  
  5245. // stack.length = stackL;
  5246.  
  5247.  
  5248. groups_ = groups;
  5249. // console.log('groups', groups)
  5250.  
  5251. }
  5252.  
  5253. // console.log(1237006);
  5254.  
  5255. const groupMids = FIX_TIMESTAMP_FOR_REPLAY ? groups_.map(group=>{
  5256.  
  5257. const [groupStart, groupEnd ] = group;
  5258. const groupMid = (groupStart+groupEnd)/2;
  5259. return groupMid;
  5260. }): null;
  5261. // console.log('groupMids', groupMids)
  5262.  
  5263.  
  5264. // console.log(1237007);
  5265.  
  5266. const adjustTimestampFn = (obj) => {
  5267.  
  5268. const groupCount = groupMids.length;
  5269.  
  5270. if (groupCount < 1) return null;
  5271.  
  5272. // const obj = toLAObj(aItem);
  5273. if (obj === false) return null;
  5274.  
  5275. const wobj = additionalInfo.get(obj);
  5276. if (!wobj) return null;
  5277.  
  5278. const { t0mu } = wobj;
  5279.  
  5280.  
  5281. let i0 = 0;
  5282.  
  5283. if (groupCount >= 3) {
  5284. // For larger arrays, use binary search.
  5285. let low = 0;
  5286. let high = groupCount - 1;
  5287.  
  5288. while (high - low > 1) {
  5289. const mid = (low + high) >>> 1;
  5290. if (groupMids[mid] >= t0mu) {
  5291. high = mid;
  5292. } else {
  5293. low = mid;
  5294. }
  5295. }
  5296. i0 = low;
  5297.  
  5298. }
  5299.  
  5300. let upperDiff = -1;
  5301. let lowerDiff = -1;
  5302. for (let i = i0; i < groupCount; i++) {
  5303. const y = groupMids[i] - t0mu;
  5304. if (y >= 0) {
  5305. upperDiff = y; // >=0, entry > value is found
  5306. break;
  5307. }
  5308. lowerDiff = -y; // >0, cache
  5309. }
  5310.  
  5311. const d1 = upperDiff;
  5312. const d2 = lowerDiff;
  5313.  
  5314.  
  5315. // console.log(5381, index1 ,d1, index2 , d2);
  5316.  
  5317. if (d1 >= 0 && ((d2 < 0) || (d1 <= d2))) {
  5318. wobj.chosenT0 = t0mu + d1; // groupMids[index1];
  5319. } else if (d2 >= 0 && ((d1 < 0) || (d2 <= d1))) {
  5320. wobj.chosenT0 = t0mu - d2; // groupMids[index2];
  5321. } else {
  5322. console.warn('logic error');
  5323. return null;
  5324. }
  5325.  
  5326. const adjusted = wobj.timestampUsecOriginal - wobj.chosenT0;
  5327.  
  5328. wobj.timestampUsecAdjusted = adjusted + 1110553200000000;
  5329.  
  5330. // console.log('adjusted', `${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5331.  
  5332. // adjustmentMap.set(`${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5333.  
  5334. return adjusted;
  5335.  
  5336.  
  5337.  
  5338. };
  5339.  
  5340.  
  5341. // console.log(1237008);
  5342. // if (FIX_TIMESTAMP_FOR_REPLAY) {
  5343.  
  5344.  
  5345. // try{
  5346.  
  5347. // // console.log('groupmid',groupMids, groups);
  5348.  
  5349. // for(let j = 0; j< arr.length;j++){
  5350. // if(groupMids.length<1) break;
  5351.  
  5352. // const aItem = arr[j];
  5353. // const obj = toLAObj(aItem);
  5354. // if (obj === false) continue;
  5355.  
  5356. // const wobj = additionalInfo.get(obj);
  5357. // if(!wobj) continue;
  5358.  
  5359. // // wobj.timestampUsecOriginal = q2;
  5360. // // wobj.timestampUsecAdjusted = q2;
  5361. // // wobj.t0au = t0au;
  5362. // // wobj.t0bu = t0bu;
  5363. // // wobj.t0mu = t0mu;
  5364.  
  5365. // const {t0au, t0bu, t0mu} = wobj;
  5366.  
  5367. // let upper = -1;
  5368.  
  5369. // for(let i = 0; i <groupMids.length;i++){
  5370. // const groupMid = groupMids[i];
  5371. // if(groupMid>= t0mu){
  5372. // upper = i;
  5373. // break;
  5374. // }
  5375. // }
  5376. // let index1, index2;
  5377. // if(upper>-1){
  5378. // index1 = upper-1;
  5379. // index2 = upper;
  5380. // }else{
  5381. // index1 = groups.length-1;
  5382. // index2 = -1;
  5383. // }
  5384. // let d1 = null;
  5385. // if(index1 >=0){
  5386. // d1 = Math.abs(groupMids[index1] - t0mu);
  5387. // }
  5388. // let d2 = null;
  5389. // if(index2 >=0){
  5390. // d2 = Math.abs(groupMids[index2] - t0mu);
  5391. // }
  5392. // // console.log(5381, index1 ,d1, index2 , d2);
  5393. // if(d1 >= 0 && ((d1 <= d2) || (d2 === null)) ){
  5394. // wobj.chosenT0 = groupMids[index1];
  5395. // } else if(d2 >= 0 && ((d2 <= d1) || (d1 === null))){
  5396. // wobj.chosenT0 = groupMids[index2];
  5397. // } else {
  5398. // console.warn('logic error');
  5399. // continue;
  5400. // }
  5401.  
  5402. // wobj.timestampUsecAdjusted = wobj.timestampUsecOriginal - wobj.chosenT0 + 1110553200000000;
  5403.  
  5404. // console.log('adjusted', `${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5405.  
  5406. // adjustmentMap.set(`${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5407. // // conversionMap.set(obj, arrHash[j].adjustedTime);
  5408.  
  5409. // // console.log(5382, index, id, t0mu, arrHash[j].adjustedT0, arrHash[j].timestampUsec, arrHash[j].adjustedTime);
  5410. // }
  5411.  
  5412. // }catch(e){
  5413. // console.warn(e);
  5414. // }
  5415.  
  5416.  
  5417.  
  5418.  
  5419.  
  5420. // // if(stack.length > 1){
  5421. // // stack.sort((a,b)=>{
  5422. // // return a.t0mu - b.t0mu
  5423. // // });
  5424. // // // small to large
  5425. // // // console.log(34588, stack.map(e=>e.t0as))
  5426. // // }
  5427.  
  5428. // // grouping
  5429.  
  5430.  
  5431.  
  5432.  
  5433. // // if (stack.length > 0) {
  5434.  
  5435. // // try {
  5436.  
  5437. // // for (let j = 0, l = stack.length; j < l; j++) {
  5438. // // pushToGroup(stack[j].t0mu);
  5439.  
  5440. // // }
  5441.  
  5442. // // }catch(e){
  5443.  
  5444. // // console.warn(e)
  5445. // // }
  5446.  
  5447. // // // console.log(4882, groups.map(e=>e.slice()), stack.slice())
  5448.  
  5449. // // }
  5450.  
  5451.  
  5452.  
  5453. // // console.log(376, 'group', groups);
  5454.  
  5455.  
  5456. // // consolidated group
  5457. // // const consolidatedGroups = doConsolidation(groups);
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464. // // if(stack.length > 1){
  5465.  
  5466.  
  5467. // // // // console.log(341, 'consolidatedGroups', consolidatedGroups ,groups.map(e=>{
  5468. // // // // return e.map(noTransform);
  5469. // // // // // return e.map(prettyNum);
  5470. // // // // }))
  5471.  
  5472.  
  5473. // // // console.log(344, 'groups', groups.map(e=>{
  5474. // // // return e.map(noTransform);
  5475. // // // // return e.map(prettyNum);
  5476. // // // }))
  5477.  
  5478. // // // // for(const s of stack){
  5479. // // // // for(const g of consolidatedGroups){
  5480. // // // // if(s.t0as<=g.cen && s.t0bs >=g.cen ){
  5481. // // // // s.cen = g.cen;
  5482. // // // // break;
  5483. // // // // }
  5484. // // // // }
  5485.  
  5486. // // // // }
  5487.  
  5488. // // // console.log(377, stack) // Ms
  5489.  
  5490. // // }
  5491.  
  5492.  
  5493. // // console.timeEnd('FIX_TIMESTAMP_FOR_REPLAY')
  5494.  
  5495. // }
  5496.  
  5497.  
  5498.  
  5499.  
  5500.  
  5501.  
  5502.  
  5503.  
  5504.  
  5505.  
  5506. // console.log('preprocessChatLiveActions', arr)
  5507.  
  5508.  
  5509. const mapper = new Map();
  5510.  
  5511. // without delaying. get the time of request
  5512. // (both streaming and replay, but replay relys on progress update so background operation is suppressed)
  5513. for (let j = 0, l = arr.length; j < l; j++) {
  5514. const aItem = arr[j];
  5515.  
  5516. const obj = toLAObj(aItem);
  5517. if(obj === false) continue;
  5518. if (obj.id && !obj.__timestampActionRequest__) {
  5519. // for all item entries
  5520. obj.__timestampActionRequest__ = ct;
  5521. }
  5522.  
  5523. if (obj.id && obj.__timestampActionRequest__ > 0 && obj.durationSec > 0 && obj.fullDurationSec) {
  5524.  
  5525. // console.log(948700, obj , obj.id, (obj.fullDurationSec - obj.durationSec) * 1000)
  5526. const m = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  5527. // obj.__orderTime__ = m;
  5528. mapper.set(aItem, m);
  5529.  
  5530.  
  5531. }
  5532.  
  5533. }
  5534.  
  5535. if (mapper.size > 1) {
  5536.  
  5537. const idxices = [];
  5538.  
  5539. // sort ticker
  5540. let mArr1 = arr.filter((aItem,idx) => {
  5541.  
  5542. if (mapper.has(aItem)) {
  5543. idxices.push(idx);
  5544. return true;
  5545. }
  5546. return false;
  5547.  
  5548. });
  5549.  
  5550.  
  5551. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  5552. return mapper.get(a) - mapper.get(b);
  5553. // low index = oldest = smallest timestamp
  5554. });
  5555.  
  5556.  
  5557.  
  5558. // console.log(948701, arr.slice(0));
  5559. for(let j = 0, l=mArr1.length;j <l;j++){
  5560.  
  5561. const idx = idxices[j];
  5562. // arr[idx] = mArr1[j]
  5563. arr[idx] = mArr2[j];
  5564.  
  5565. // const obj1 = toObj(mArr1[j]);
  5566. // const obj2 = toObj(mArr2[j]);
  5567.  
  5568. // console.log(948705, idx, obj1 , obj1.id, (obj1.fullDurationSec - obj1.durationSec) * 1000, obj1.__orderTime__)
  5569.  
  5570. // console.log(948706, idx, obj2 , obj2.id, (obj2.fullDurationSec - obj2.durationSec) * 1000, obj2.__orderTime__)
  5571.  
  5572. }
  5573.  
  5574. // console.log(948702, arr.slice(0));
  5575. // console.log(948701, arr);
  5576. // arr = arr.map(aItem => {
  5577. // const idx = mArr1.indexOf(aItem);
  5578. // if (idx < 0) return aItem;
  5579. // return mArr2[idx];
  5580. // });
  5581. // console.log(948702, arr);
  5582.  
  5583. // mostly in order, but some not in order
  5584.  
  5585.  
  5586. // eg
  5587.  
  5588. /*
  5589.  
  5590.  
  5591. 948711 68 '1734488590715474'
  5592. 948711 69 '1734488590909853'
  5593. 948711 70 '1734488594763719'
  5594. 948711 71 '1734488602334615' <
  5595. 948711 72 '1734488602267214' <
  5596. 948711 73 '1734488602751771'
  5597. */
  5598.  
  5599. // arr.filter(aItem=>{
  5600.  
  5601. // const p = toObj(aItem);
  5602. // if(p.timestampUsec) return true;
  5603.  
  5604. // }).forEach((aItem,idx)=>{
  5605.  
  5606. // const p = toObj(aItem);
  5607. // console.log(948711, idx, p.timestampUsec);
  5608. // })
  5609.  
  5610. // return arr;
  5611.  
  5612. }
  5613.  
  5614. // console.log(1237001);
  5615.  
  5616. {
  5617.  
  5618.  
  5619. const mapper = new Map();
  5620.  
  5621.  
  5622. const idxices = [];
  5623.  
  5624.  
  5625. let mArr1 = arr.filter((aItem,idx) => {
  5626.  
  5627. const obj = toLAObj(aItem);
  5628. if (!obj) return false;
  5629.  
  5630. const baseText = obj.timestampText;
  5631. const baseTime = +obj.timestampUsec;
  5632. if (!baseTime || !baseText) return false;
  5633. // const timestampUsec = +toLAObj(aItem).timestampUsec; // +false.x = NaN
  5634. // const timestampUsec = +toLAObj(aItem).adjustedTime;
  5635.  
  5636. let timestampUsec;
  5637.  
  5638. // console.log(1237002)
  5639. if (FIX_TIMESTAMP_FOR_REPLAY) {
  5640.  
  5641. // const adjustmentTime = adjustmentMap.get(`${obj.id}.${obj.timestampUsec}`);
  5642.  
  5643. // // const wobj = additionalInfo.get(obj);
  5644.  
  5645. // // if(!wobj){
  5646. // // console.warn('FIX_TIMESTAMP_FOR_REPLAY - no wobj', obj)
  5647. // // return false;
  5648. // // }
  5649.  
  5650. // // timestampUsec = +wobj.timestampUsecAdjusted;
  5651. // if (!Number.isFinite(adjustmentTime)) {
  5652. // console.warn(`FIX_TIMESTAMP_FOR_REPLAY - no adjustmentTime for ${obj.id}.${obj.timestampUsec}`, obj, [...adjustmentMap])
  5653. // return false;
  5654. // }
  5655. // timestampUsec = adjustmentTime;
  5656.  
  5657.  
  5658. const adjustmentTime = adjustTimestampFn(obj);
  5659.  
  5660. if (!Number.isFinite(adjustmentTime)) {
  5661.  
  5662. console.warn(`FIX_TIMESTAMP_FOR_REPLAY - no adjustmentTime for ${obj.id}.${obj.timestampUsec}`, obj);
  5663. return false;
  5664. }
  5665. timestampUsec = adjustmentTime;
  5666.  
  5667.  
  5668. } else {
  5669.  
  5670. if (!Number.isFinite(baseTime)) {
  5671. console.warn(`no baseTime for ${obj.id}.${obj.timestampUsec}`, obj);
  5672. return false;
  5673. }
  5674. timestampUsec = baseTime;
  5675.  
  5676. }
  5677.  
  5678. // if(timestampUsec > 0){
  5679. idxices.push(idx);
  5680. mapper.set(aItem, timestampUsec)
  5681. return true;
  5682. // }
  5683. // return false;
  5684. });
  5685.  
  5686. if(mapper.size > 1){
  5687.  
  5688. // console.log(1237004)
  5689. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  5690. return mapper.get(a) - mapper.get(b);
  5691. // low index = oldest = smallest timestamp
  5692. });
  5693. // console.log(948701, arr.slice(0));
  5694. for(let j = 0, l=mArr1.length;j <l;j++){
  5695. const idx = idxices[j];
  5696. arr[idx] = mArr2[j];
  5697. // const obj1 = toObj(mArr1[j]);
  5698. // const obj2 = toObj(mArr2[j]);
  5699. // console.log(948711, idx, obj1 === obj2, obj1, obj1.timestampUsec);
  5700. // console.log(948712, idx, obj1 === obj2, obj2, obj2.timestampUsec);
  5701. }
  5702.  
  5703. }
  5704.  
  5705. }
  5706.  
  5707. // console.log(1237005)
  5708.  
  5709. // console.log(378, arr);
  5710.  
  5711. return arr;
  5712.  
  5713.  
  5714. }
  5715.  
  5716. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  5717. getLCRDummy().then(async (lcrDummy) => {
  5718.  
  5719. const tag = "yt-live-chat-renderer"
  5720. const dummy = lcrDummy;
  5721.  
  5722. const cProto = getProto(dummy);
  5723. if (!cProto || !cProto.attached) {
  5724. console.warn(`proto.attached for ${tag} is unavailable.`);
  5725. return;
  5726. }
  5727.  
  5728. mightFirstCheckOnYtInit();
  5729. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  5730. console.log("[Begin]");
  5731.  
  5732.  
  5733.  
  5734.  
  5735.  
  5736.  
  5737. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  5738.  
  5739. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  5740.  
  5741. const pop078 = function () {
  5742. const r = this.pop78();
  5743.  
  5744. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  5745. for (const action of r.actions) {
  5746.  
  5747. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  5748. if (itemActionKey) {
  5749.  
  5750. const itemAction = action[itemActionKey];
  5751. const item = (itemAction || 0).item;
  5752. if (typeof item === 'object') {
  5753.  
  5754. const rendererKey = firstObjectKey(item);
  5755. if (rendererKey) {
  5756. const renderer = item[rendererKey];
  5757. if (renderer && typeof renderer === 'object') {
  5758. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  5759. renderer.__progressAt__ = playerProgressChangedArg1;
  5760.  
  5761. // console.log(48117006)
  5762. }
  5763.  
  5764. }
  5765.  
  5766. }
  5767. }
  5768. }
  5769. }
  5770. return r;
  5771. }
  5772.  
  5773. const replayQueueProxyHandler = {
  5774. get(target, prop, receiver) {
  5775. if (prop === 'qe3') return 1;
  5776. const v = target[prop];
  5777. if (prop === 'front_') {
  5778. if (v && typeof v.length === 'number') {
  5779. if (!v.pop78) {
  5780. v.pop78 = v.pop;
  5781. v.pop = pop078;
  5782. }
  5783. }
  5784. }
  5785. return v;
  5786. }
  5787. };
  5788.  
  5789. cProto.playerProgressChanged_ = function (a, b, c) {
  5790. // console.log(48117005)
  5791. playerProgressChangedArg1 = a;
  5792. playerProgressChangedArg2 = b;
  5793. playerProgressChangedArg3 = c;
  5794. const replayBuffer_ = this.replayBuffer_;
  5795. if (replayBuffer_) {
  5796. const replayQueue = replayBuffer_.replayQueue
  5797. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  5798. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, replayQueueProxyHandler);
  5799. }
  5800. }
  5801. Promise.resolve().then(updateTickerCurrentTime);
  5802. return this.playerProgressChanged32_.apply(this, arguments);
  5803. };
  5804.  
  5805. }
  5806.  
  5807. console.log("[End]");
  5808. console.groupEnd();
  5809.  
  5810.  
  5811. });
  5812.  
  5813. }
  5814.  
  5815.  
  5816.  
  5817. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  5818.  
  5819.  
  5820. const tag = "yt-live-chat-item-list-renderer"
  5821. const dummy = document.createElement(tag);
  5822.  
  5823. const cProto = getProto(dummy);
  5824. if (!cProto || !cProto.attached) {
  5825. console.warn(`proto.attached for ${tag} is unavailable.`);
  5826. return;
  5827. }
  5828.  
  5829. mightFirstCheckOnYtInit();
  5830. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  5831. console.log("[Begin]");
  5832.  
  5833. const mclp = cProto;
  5834. const _flag0281_ = window._flag0281_ || mclp._flag0281_;
  5835.  
  5836. try {
  5837. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  5838. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  5839. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  5840. assertor(() => typeof mclp.setAtBottom === 'function');
  5841. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  5842. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  5843. } catch (e) { }
  5844.  
  5845.  
  5846. try {
  5847. assertor(() => typeof mclp.attached === 'function');
  5848. assertor(() => typeof mclp.detached === 'function');
  5849. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  5850. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  5851. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  5852. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  5853. assertor(() => typeof mclp.smoothScroll_ === 'function');
  5854. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  5855. } catch (e) { }
  5856.  
  5857. mclp.__intermediate_delay__ = null;
  5858.  
  5859. let myk = 0;
  5860. let mlf = 0;
  5861. let myw = 0;
  5862. let mzt = 0;
  5863. let zarr = null;
  5864. let mlg = 0;
  5865.  
  5866. if ((_flag0281_ & 0x2000) == 0) {
  5867.  
  5868. if ((mclp.clearList || 0).length === 0) {
  5869. (_flag0281_ & 0x2) == 0 && assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  5870. mclp.clearList66 = mclp.clearList;
  5871. mclp.clearList = function () {
  5872. myk++;
  5873. mlf++;
  5874. myw++;
  5875. mzt++;
  5876. mlg++;
  5877. zarr = null;
  5878. this.__intermediate_delay__ = null;
  5879. this.clearList66();
  5880. };
  5881. console.log("clearList", "OK");
  5882. } else {
  5883. console.log("clearList", "NG");
  5884. }
  5885.  
  5886. }
  5887.  
  5888.  
  5889.  
  5890. let onListRendererAttachedDone = false;
  5891.  
  5892. function setList(itemOffset, items) {
  5893.  
  5894. const isFirstTime = onListRendererAttachedDone === false;
  5895.  
  5896. if (isFirstTime) {
  5897. onListRendererAttachedDone = true;
  5898. Promise.resolve().then(watchUserCSS);
  5899. addCssManaged();
  5900. setupEvents();
  5901. }
  5902.  
  5903. setupStyle(itemOffset, items);
  5904.  
  5905. setupMutObserver(items);
  5906. }
  5907.  
  5908. mclp.attached419 = async function () {
  5909.  
  5910. if (!this.isAttached) return;
  5911.  
  5912. let maxTrial = 16;
  5913. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  5914. if (--maxTrial < 0 || !this.isAttached) return;
  5915. await iAFP(this.hostElement).then();
  5916. // await new Promise(requestAnimationFrame);
  5917. }
  5918.  
  5919. if (this.isAttached !== true) return;
  5920.  
  5921. if (!this.$) {
  5922. console.warn("!this.$");
  5923. return;
  5924. }
  5925. if (!this.$) return;
  5926. /** @type {HTMLElement | null} */
  5927. const itemScroller = this.$['item-scroller'];
  5928. /** @type {HTMLElement | null} */
  5929. const itemOffset = this.$['item-offset'];
  5930. /** @type {HTMLElement | null} */
  5931. const items = this.$['items'];
  5932.  
  5933. if (!itemScroller || !itemOffset || !items) {
  5934. console.warn("items.parentNode !== itemOffset");
  5935. return;
  5936. }
  5937.  
  5938. if (nodeParent(items) !== itemOffset) {
  5939.  
  5940. console.warn("items.parentNode !== itemOffset");
  5941. return;
  5942. }
  5943.  
  5944.  
  5945. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  5946.  
  5947. console.warn("id incorrect");
  5948. return;
  5949. }
  5950.  
  5951. 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')
  5952.  
  5953. if (!isTargetItems) {
  5954. console.warn("!isTargetItems");
  5955. return;
  5956. }
  5957.  
  5958. setList(itemOffset, items);
  5959.  
  5960. }
  5961.  
  5962. mclp.attached331 = mclp.attached;
  5963. mclp.attached = function () {
  5964. this.attached419 && this.attached419();
  5965. return this.attached331();
  5966. }
  5967.  
  5968. mclp.detached331 = mclp.detached;
  5969.  
  5970. mclp.detached = function () {
  5971. setupMutObserver();
  5972. return this.detached331();
  5973. }
  5974.  
  5975. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  5976. for (const t29 of t29s) {
  5977. if (insp(t29).isAttached === true) {
  5978. t29.attached419();
  5979. }
  5980. }
  5981.  
  5982. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  5983.  
  5984. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  5985. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  5986.  
  5987. /** @type {Map<number, any>} */
  5988. const aMap = new Map();
  5989. let count = 6150;
  5990. mclp.async66 = mclp.async;
  5991. mclp.async = function (e, f) {
  5992. // ensure the previous operation is done
  5993. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  5994. const hasF = arguments.length === 2;
  5995. const stack = new Error().stack;
  5996. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  5997. if (count > 1e9) count = 6159;
  5998. const resId = ++count;
  5999. aMap.set(resId, e);
  6000. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  6001. const rp = aMap.get(resId);
  6002. if (typeof rp !== 'function') {
  6003. return;
  6004. }
  6005. let cancelCall = false;
  6006. if (isFlushAsync) {
  6007. if (rk < 0) {
  6008. cancelCall = true;
  6009. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  6010. cancelCall = true;
  6011. }
  6012. }
  6013. if (cancelCall) {
  6014. aMap.delete(resId);
  6015. } else {
  6016. const asyncEn = function () {
  6017. aMap.delete(resId);
  6018. return rp.apply(this, arguments);
  6019. };
  6020. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  6021. }
  6022. });
  6023.  
  6024. return resId;
  6025. }
  6026.  
  6027. mclp.cancelAsync66 = mclp.cancelAsync;
  6028. mclp.cancelAsync = function (resId) {
  6029. if (resId <= 6150) {
  6030. this.cancelAsync66(resId);
  6031. } else if (aMap.has(resId)) {
  6032. const rp = aMap.get(resId);
  6033. aMap.delete(resId);
  6034. if (typeof rp !== 'function') {
  6035. this.cancelAsync66(rp);
  6036. }
  6037. }
  6038. }
  6039.  
  6040. console.log("async", "OK");
  6041. } else {
  6042. console.log("async", "NG");
  6043. }
  6044.  
  6045.  
  6046. if ((_flag0281_ & 0x2) == 0) {
  6047. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  6048.  
  6049. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  6050. mclp.showNewItems66_ = mclp.showNewItems_;
  6051.  
  6052. mclp.showNewItems77_ = async function () {
  6053. if (myk > 1e9) myk = 9;
  6054. let tid = ++myk;
  6055.  
  6056. await iAFP(this.hostElement).then();
  6057. // await new Promise(requestAnimationFrame);
  6058.  
  6059. if (tid !== myk) {
  6060. return;
  6061. }
  6062.  
  6063. const cnt = this;
  6064.  
  6065. await Promise.resolve();
  6066. cnt.showNewItems66_();
  6067.  
  6068. await Promise.resolve();
  6069.  
  6070. }
  6071.  
  6072. mclp.showNewItems_ = function () {
  6073.  
  6074. const cnt = this;
  6075. cnt.__intermediate_delay__ = new Promise(resolve => {
  6076. cnt.showNewItems77_().then(() => {
  6077. resolve();
  6078. });
  6079. });
  6080. }
  6081.  
  6082. console.log("showNewItems_", "OK");
  6083. } else {
  6084. console.log("showNewItems_", "NG");
  6085. }
  6086.  
  6087. }
  6088.  
  6089. if ((_flag0281_ & 0x2000) == 0) {
  6090. if ((mclp.flushActiveItems_ || 0).length === 0) {
  6091.  
  6092. if ((_flag0281_ & 0x2) == 0) {
  6093.  
  6094. const sfi = fnIntegrity(mclp.flushActiveItems_);
  6095. if(sfi === '0.158.86'){
  6096.  
  6097. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6098.  
  6099.  
  6100. // f.flushActiveItems_ = function() {
  6101. // var a = this;
  6102. // if (this.activeItems_.length > 0)
  6103. // if (this.canScrollToBottom_()) {
  6104. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6105. // b && this.splice("visibleItems", 0, b);
  6106. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6107. // this.preinsertHeight_ = this.items.clientHeight;
  6108. // this.activeItems_.unshift("visibleItems");
  6109. // try {
  6110. // this.push.apply(this, this.activeItems_)
  6111. // } catch (c) {
  6112. // Tm(c)
  6113. // }
  6114. // this.activeItems_ = [];
  6115. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && $u(function() {
  6116. // a.showNewItems_()
  6117. // }) : $u(function() {
  6118. // a.refreshOffsetContainerHeight_();
  6119. // a.maybeScrollToBottom_()
  6120. // })
  6121. // } else
  6122. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  6123. // }
  6124.  
  6125. } else if (sfi === '0.156.86') {
  6126. // https://www.youtube.com/s/desktop/f61c8d85/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6127.  
  6128. // added "refreshOffsetContainerHeight_"
  6129.  
  6130. // f.flushActiveItems_ = function() {
  6131. // var a = this;
  6132. // if (0 < this.activeItems_.length)
  6133. // if (this.canScrollToBottom_()) {
  6134. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6135. // b && this.splice("visibleItems", 0, b);
  6136. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6137. // this.preinsertHeight_ = this.items.clientHeight;
  6138. // this.activeItems_.unshift("visibleItems");
  6139. // try {
  6140. // this.push.apply(this, this.activeItems_)
  6141. // } catch (c) {
  6142. // fm(c)
  6143. // }
  6144. // this.activeItems_ = [];
  6145. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && Mw(function() {
  6146. // a.showNewItems_()
  6147. // }) : Mw(function() {
  6148. // a.refreshOffsetContainerHeight_();
  6149. // a.maybeScrollToBottom_()
  6150. // })
  6151. // } else
  6152. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  6153. // }
  6154. // ;
  6155.  
  6156. } else if (sfi === '0.150.84') {
  6157. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6158. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6159. // b && this.splice("visibleItems", 0, b);
  6160. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6161. // this.preinsertHeight_ = this.items.clientHeight;
  6162. // this.activeItems_.unshift("visibleItems");
  6163. // try {
  6164. // this.push.apply(this, this.activeItems_)
  6165. // } catch (c) {
  6166. // nm(c)
  6167. // }
  6168. // this.activeItems_ = [];
  6169. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && zQ(function() {
  6170. // a.showNewItems_()
  6171. // }) : zQ(function() {
  6172. // a.maybeScrollToBottom_()
  6173. // })
  6174. } else if (sfi === '0.137.81' || sfi === '0.138.81') {
  6175. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  6176. } else {
  6177. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.158.86'))
  6178. || logFn('mclp.flushActiveItems_', mclp.flushActiveItems_)();
  6179. }
  6180. }
  6181.  
  6182. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  6183.  
  6184. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  6185.  
  6186.  
  6187. const preloadFn = (acItems) => {
  6188. let waitFor = [];
  6189. /** @type {Set<string>} */
  6190. const imageLinks = new Set();
  6191.  
  6192. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  6193. for (const item of acItems) {
  6194. fixLiveChatItem(item, imageLinks);
  6195. }
  6196. }
  6197. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  6198.  
  6199. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  6200. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  6201. // preload performs the high priority fetching.
  6202. // prefetch delays the chat display if the video resoruce is demanding.
  6203.  
  6204. if (rel) {
  6205.  
  6206. imageLinks.forEach(imageLink => {
  6207. let d = false;
  6208. if (SKIP_PRELOAD_EMOJI && imageLink.includes('.ggpht.com/')) return;
  6209. const isEmoji = imageLink.includes('/emoji/');
  6210. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  6211. if (!pretechedSet.has(imageLink)) {
  6212. pretechedSet.add(imageLink);
  6213. d = true;
  6214. }
  6215. if (d) {
  6216. waitFor.push(linker(null, rel, imageLink, 'image'));
  6217.  
  6218. }
  6219. })
  6220.  
  6221. }
  6222.  
  6223. }
  6224.  
  6225. return async () => {
  6226. if (waitFor.length > 0) {
  6227. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  6228. }
  6229. waitFor.length = 0;
  6230. waitFor = null;
  6231. };
  6232.  
  6233. };
  6234.  
  6235. mclp.flushActiveItems78_ = async function (tid) {
  6236. try {
  6237.  
  6238. if (tid !== mlf) return;
  6239. if ((this._flag0281_ & 0x4) == 0x4) {
  6240. const cnt = this;
  6241.  
  6242. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6243. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  6244.  
  6245. mlf++;
  6246. if (mlg > 1e9) mlg = 9;
  6247. ++mlg;
  6248. const acItems = cnt.activeItems_;
  6249. if (acItems.length < MAX_ITEMS_FOR_FULL_FLUSH) {
  6250. const pn = preloadFn(acItems);
  6251. await pn();
  6252. }
  6253. cnt.flushActiveItems66_();
  6254.  
  6255. return 1;
  6256.  
  6257. }
  6258. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  6259. let logger = false;
  6260. const cnt = this;
  6261. let immd = cnt.__intermediate_delay__;
  6262. await iAFP(this.hostElement).then();
  6263. // await new Promise(requestAnimationFrame);
  6264.  
  6265. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6266. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  6267.  
  6268. mlf++;
  6269. if (mlg > 1e9) mlg = 9;
  6270. ++mlg;
  6271.  
  6272. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  6273. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  6274. let changeMaxItemsToDisplay = false;
  6275. const activeItemsLen = this.activeItems_.length;
  6276. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  6277. logger = true;
  6278.  
  6279. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  6280.  
  6281. logger && console.log('[Begin]')
  6282.  
  6283. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  6284. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  6285. console.log('reduce maxitems');
  6286. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  6287. // as all the rendered chats are already "outdated"
  6288. // all old chats shall remove and reduced number of few chats will be rendered
  6289. // then restore to the original number
  6290. changeMaxItemsToDisplay = true;
  6291. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  6292. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  6293. }
  6294. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  6295. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  6296.  
  6297. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  6298. } else {
  6299. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  6300.  
  6301. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  6302. }
  6303. }
  6304. // it is found that it will render all stacked chats after switching back from background
  6305. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  6306. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  6307.  
  6308. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  6309. await Promise.resolve();
  6310. const acItems = cnt.activeItems_;
  6311. const len1 = acItems.length;
  6312. if (!len1) console.warn('cnt.activeItems_.length = 0');
  6313.  
  6314. const pn = preloadFn(acItems);
  6315. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  6316. skipDontRender = noVisibleItem1;
  6317. await pn();
  6318. // console.log('ss2', Date.now())
  6319. cnt.flushActiveItems66_();
  6320. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  6321. skipDontRender = noVisibleItem2;
  6322. await Promise.resolve();
  6323. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  6324. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  6325.  
  6326. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  6327. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  6328. } else if (changeMaxItemsToDisplay) {
  6329.  
  6330. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  6331. maxItemsToDisplay: this.data.maxItemsToDisplay,
  6332. reducedMaxItemsToDisplay,
  6333. originalMaxItemsToDisplay: tmpMaxItemsCount
  6334. });
  6335. }
  6336. logger && console.log('[End]');
  6337.  
  6338. logger && console.groupEnd();
  6339.  
  6340. if (noVisibleItem1 && !noVisibleItem2) {
  6341. // fix possible no auto scroll issue.
  6342. !((cnt.__notRequired__ || 0) & 256) && setTimeout(() => cnt.setAtBottom(), 1);
  6343. }
  6344.  
  6345. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  6346.  
  6347.  
  6348. const ff = () => {
  6349.  
  6350. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6351. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6352. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  6353.  
  6354. if (typeof nextBrowserTick !== 'function') {
  6355. cnt.scrollToBottom_();
  6356. Promise.resolve().then(() => {
  6357. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6358. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  6359. });
  6360. } else {
  6361. nextBrowserTick(() => {
  6362. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6363. cnt.scrollToBottom_();
  6364. });
  6365. }
  6366.  
  6367. }
  6368. }
  6369.  
  6370. ff();
  6371.  
  6372.  
  6373. Promise.resolve().then(ff);
  6374.  
  6375. // requestAnimationFrame(ff);
  6376. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  6377.  
  6378. const knt = cnt;
  6379. if (!scrollChatFn) {
  6380. const cnt = knt;
  6381. const f = () => {
  6382. const itemScroller = cnt.itemScroller;
  6383. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  6384. if (!cnt.atBottom) {
  6385. cnt.scrollToBottom_();
  6386. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  6387. itemScroller.scrollTop = itemScroller.scrollHeight;
  6388. }
  6389. };
  6390. if (typeof nextBrowserTick !== 'function') {
  6391. scrollChatFn = () => Promise.resolve().then(f).then(f);
  6392. } else {
  6393. scrollChatFn = () => nextBrowserTick(f);
  6394. }
  6395. }
  6396.  
  6397. scrollChatFn();
  6398. }
  6399.  
  6400. return 1;
  6401.  
  6402.  
  6403. } catch (e) {
  6404. console.warn(e);
  6405. }
  6406. }
  6407.  
  6408. mclp.flushActiveItems77_ = function () {
  6409.  
  6410. return new Promise(resResolve => {
  6411. try {
  6412. const cnt = this;
  6413. if (mlf > 1e9) mlf = 9;
  6414. let tid = ++mlf;
  6415. const hostElement = cnt.hostElement || cnt;
  6416. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  6417. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  6418.  
  6419. // 4 times to maxItems to avoid frequent trimming.
  6420. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  6421.  
  6422. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  6423. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  6424. if (cnt.canScrollToBottom_()) {
  6425. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  6426. .then(() => cnt.flushActiveItems78_(tid)) // async function
  6427. .then((asyncResult) => {
  6428. resResolve(asyncResult); // either undefined or 1
  6429. resResolve = null;
  6430. }).catch((e) => {
  6431. console.warn(e);
  6432. if (resResolve) resResolve();
  6433. });
  6434. } else {
  6435. resResolve(2);
  6436. resResolve = null;
  6437. }
  6438. } catch (e) {
  6439. console.warn(e);
  6440. if (resResolve) resResolve();
  6441. }
  6442.  
  6443.  
  6444. });
  6445.  
  6446. }
  6447.  
  6448. mclp.flushActiveItems_ = function () {
  6449. const cnt = this;
  6450.  
  6451. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  6452.  
  6453. if (cnt.activeItems_.length === 0) {
  6454. cnt.__intermediate_delay__ = null;
  6455. return;
  6456. }
  6457.  
  6458. const cntData = ((cnt || 0).data || 0);
  6459. if (cntData.maxItemsToDisplay944 === undefined) {
  6460. cntData.maxItemsToDisplay944 = null;
  6461. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  6462. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  6463. }
  6464.  
  6465. // ignore previous __intermediate_delay__ and create a new one
  6466. cnt.__intermediate_delay__ = new Promise(resolve => {
  6467. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  6468. if (rt === 1) {
  6469. resolve(1); // success, scroll to bottom
  6470. if (hasMoreMessageState === 1) {
  6471. hasMoreMessageState = 0;
  6472. const showMore = (cnt.$ || 0)['show-more'];
  6473. if (showMore) {
  6474. showMore.classList.remove('has-new-messages-miuzp');
  6475. }
  6476. }
  6477. }
  6478. else if (rt === 2) {
  6479. resolve(2); // success, trim
  6480. if (hasMoreMessageState === 0) {
  6481. hasMoreMessageState = 1;
  6482. const showMore = cnt.$['show-more'];
  6483. if (showMore) {
  6484. showMore.classList.add('has-new-messages-miuzp');
  6485. }
  6486. }
  6487. }
  6488. else resolve(-1); // skip
  6489. }).catch(e => {
  6490. console.warn(e);
  6491. });
  6492. });
  6493.  
  6494. }
  6495. console.log("flushActiveItems_", "OK");
  6496. } else {
  6497. console.log("flushActiveItems_", "NG");
  6498. }
  6499. }
  6500.  
  6501. if ((_flag0281_ & 0x40) == 0) {
  6502.  
  6503. if (ENABLE_NO_SMOOTH_TRANSFORM && SUPPRESS_refreshOffsetContainerHeight_ && typeof mclp.refreshOffsetContainerHeight_ === 'function' && !mclp.refreshOffsetContainerHeight26_ && mclp.refreshOffsetContainerHeight_.length === 0) {
  6504. assertor(() => fnIntegrity(mclp.refreshOffsetContainerHeight_, '0.31.21'));
  6505. mclp.refreshOffsetContainerHeight26_ = mclp.refreshOffsetContainerHeight_;
  6506. mclp.refreshOffsetContainerHeight_ = function () {
  6507. // var a = this.itemScroller.clientHeight;
  6508. // this.itemOffset.style.height = this.items.clientHeight + "px";
  6509. // this.bottomAlignMessages && (this.itemOffset.style.minHeight = a + "px")
  6510. }
  6511. console.log("refreshOffsetContainerHeight_", "OK");
  6512. } else {
  6513. console.log("refreshOffsetContainerHeight_", "NG");
  6514. }
  6515.  
  6516. }
  6517.  
  6518. if ((_flag0281_ & 0x80) == 0) {
  6519. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  6520. try {
  6521. if (mlg > 1e9) mlg = 9;
  6522. const tid = ++mlg;
  6523. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  6524. const runCond = () => this.canScrollToBottom_();
  6525. if (!keepTrialCond()) return;
  6526. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  6527. await new Promise(r => setTimeout(r, 80));
  6528. if (!keepTrialCond()) return;
  6529. if (runCond()) return this.flushActiveItems_() | 1;
  6530. await iAFP(this.hostElement).then();
  6531. // await new Promise(requestAnimationFrame);
  6532. if (runCond()) return this.flushActiveItems_() | 1;
  6533. } catch (e) {
  6534. console.warn(e);
  6535. }
  6536. }
  6537. }
  6538.  
  6539. if ((_flag0281_ & 0x40) == 0 ) {
  6540.  
  6541. if( (mclp.atBottomChanged_ || 0).length === 0) {
  6542. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  6543.  
  6544.  
  6545.  
  6546.  
  6547.  
  6548. const sfi = fnIntegrity(mclp.atBottomChanged_);
  6549.  
  6550. if(sfi === '0.75.37'){
  6551. // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6552.  
  6553.  
  6554. // Dec 2024.
  6555.  
  6556. /**
  6557. *
  6558. *
  6559. f.atBottomChanged_ = function() {
  6560. var a = this;
  6561. this.atBottom ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = Zu(function() {
  6562. R(a.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6563. }, 200)) : (this.hideShowMoreAsync_ && $u(this.hideShowMoreAsync_),
  6564. this.hideShowMoreAsync_ = null,
  6565. R(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6566. }
  6567. *
  6568. */
  6569.  
  6570. } else {
  6571. assertor(() => fnIntegrity(mclp.atBottomChanged_, '0.75.37'));
  6572. }
  6573.  
  6574.  
  6575. const querySelector = HTMLElement.prototype.querySelector;
  6576. const U = (element) => ({
  6577. querySelector: (selector) => querySelector.call(element, selector)
  6578. });
  6579.  
  6580. let qid = 0;
  6581. mclp.__updateButtonVisibility371__ = function (button) {
  6582. Promise.resolve(this).then((cnt) => {
  6583. button.style.visibility = cnt.__buttonVisibility371__;
  6584. });
  6585. }
  6586. const fixButtonOnClick = function (cnt, button) {
  6587. button.addEventListener('click', (evt) => {
  6588. evt.stopImmediatePropagation();
  6589. evt.stopPropagation();
  6590. evt.preventDefault();
  6591. Promise.resolve(cnt).then((cnt) => {
  6592. cnt.scrollToBottom_();
  6593. });
  6594. }, true);
  6595. // button.addEventListener('pointerup', (evt)=>{
  6596. // evt.stopImmediatePropagation();
  6597. // evt.stopPropagation();
  6598. // }, true);
  6599. // button.addEventListener('mouseup', (evt)=>{
  6600. // evt.stopImmediatePropagation();
  6601. // evt.stopPropagation();
  6602. // }, true);
  6603. }
  6604. mclp.atBottomChanged_ = function () {
  6605. let a = this.atBottom;
  6606. const button = (this.$ || 0)['show-more'];
  6607. if (button) {
  6608. // primary execution
  6609. if (a) {
  6610. if (this.__buttonVisibility371__ !== "hidden") {
  6611. this.__buttonVisibility371__ = "hidden";
  6612. if (!this.hideShowMoreAsync_) {
  6613. const tid = ++qid;
  6614. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  6615. if (tid !== qid) {
  6616. return;
  6617. }
  6618. this.__updateButtonVisibility371__(button);
  6619. });
  6620. }
  6621. }
  6622. } else {
  6623. if (this.__buttonVisibility371__ !== "visible") {
  6624. this.__buttonVisibility371__ = "visible";
  6625. if (this.hideShowMoreAsync_) {
  6626. qid++;
  6627. }
  6628. this.hideShowMoreAsync_ = null;
  6629. if (!button.__fix_onclick__) {
  6630. button.__fix_onclick__ = true;
  6631. fixButtonOnClick(this, button);
  6632. }
  6633. this.__updateButtonVisibility371__(button);
  6634. }
  6635. }
  6636. } else {
  6637. // fallback
  6638. let tid = ++qid;
  6639. let b = this;
  6640. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  6641. if (tid !== qid) return;
  6642. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6643. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  6644. this.hideShowMoreAsync_ = null,
  6645. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6646. }
  6647. }
  6648.  
  6649. console.log("atBottomChanged_", "OK");
  6650.  
  6651. } else if ((mclp.atBottomChanged_ || 0).length === 1) {
  6652. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  6653.  
  6654. const sfi = fnIntegrity(mclp.atBottomChanged_);
  6655. if (sfi === '1.73.37') {
  6656. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6657.  
  6658. /**
  6659. *
  6660. *
  6661. *
  6662. f.atBottomChanged_ = function(a) {
  6663. var b = this;
  6664. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = zQ(function() {
  6665. T(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6666. }, 200)) : (this.hideShowMoreAsync_ && AQ(this.hideShowMoreAsync_),
  6667. this.hideShowMoreAsync_ = null,
  6668. T(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6669. };
  6670.  
  6671. *
  6672. *
  6673. */
  6674.  
  6675.  
  6676. } else if (sfi === '1.75.39') {
  6677. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  6678. } else {
  6679. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.73.37'));
  6680. }
  6681.  
  6682. const querySelector = HTMLElement.prototype.querySelector;
  6683. const U = (element) => ({
  6684. querySelector: (selector) => querySelector.call(element, selector)
  6685. });
  6686.  
  6687. let qid = 0;
  6688. mclp.__updateButtonVisibility371__ = function (button) {
  6689. Promise.resolve(this).then((cnt) => {
  6690. button.style.visibility = cnt.__buttonVisibility371__;
  6691. });
  6692. }
  6693. const fixButtonOnClick = function (cnt, button) {
  6694. button.addEventListener('click', (evt) => {
  6695. evt.stopImmediatePropagation();
  6696. evt.stopPropagation();
  6697. evt.preventDefault();
  6698. Promise.resolve(cnt).then((cnt) => {
  6699. cnt.scrollToBottom_();
  6700. });
  6701. }, true);
  6702. // button.addEventListener('pointerup', (evt)=>{
  6703. // evt.stopImmediatePropagation();
  6704. // evt.stopPropagation();
  6705. // }, true);
  6706. // button.addEventListener('mouseup', (evt)=>{
  6707. // evt.stopImmediatePropagation();
  6708. // evt.stopPropagation();
  6709. // }, true);
  6710. }
  6711. mclp.atBottomChanged_ = function (a) {
  6712. const button = (this.$ || 0)['show-more'];
  6713. if (button) {
  6714. // primary execution
  6715. if (a) {
  6716. if (this.__buttonVisibility371__ !== "hidden") {
  6717. this.__buttonVisibility371__ = "hidden";
  6718. if (!this.hideShowMoreAsync_) {
  6719. const tid = ++qid;
  6720. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  6721. if (tid !== qid) {
  6722. return;
  6723. }
  6724. this.__updateButtonVisibility371__(button);
  6725. });
  6726. }
  6727. }
  6728. } else {
  6729. if (this.__buttonVisibility371__ !== "visible") {
  6730. this.__buttonVisibility371__ = "visible";
  6731. if (this.hideShowMoreAsync_) {
  6732. qid++;
  6733. }
  6734. this.hideShowMoreAsync_ = null;
  6735. if (!button.__fix_onclick__) {
  6736. button.__fix_onclick__ = true;
  6737. fixButtonOnClick(this, button);
  6738. }
  6739. this.__updateButtonVisibility371__(button);
  6740. }
  6741. }
  6742. } else {
  6743. // fallback
  6744. let tid = ++qid;
  6745. let b = this;
  6746. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  6747. if (tid !== qid) return;
  6748. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6749. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  6750. this.hideShowMoreAsync_ = null,
  6751. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6752. }
  6753. }
  6754.  
  6755. console.log("atBottomChanged_", "OK");
  6756. } else {
  6757. console.log("atBottomChanged_", "NG");
  6758. }
  6759. }
  6760.  
  6761.  
  6762. if ((_flag0281_ & 0x2) == 0) {
  6763. if ((mclp.onScrollItems_ || 0).length === 1) {
  6764.  
  6765. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  6766. mclp.onScrollItems66_ = mclp.onScrollItems_;
  6767. mclp.onScrollItems77_ = async function (evt) {
  6768. if (myw > 1e9) myw = 9;
  6769. let tid = ++myw;
  6770.  
  6771. await iAFP(this.hostElement).then();
  6772. // await new Promise(requestAnimationFrame);
  6773.  
  6774. if (tid !== myw) {
  6775. return;
  6776. }
  6777.  
  6778. const cnt = this;
  6779.  
  6780. await Promise.resolve();
  6781. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  6782. const onScrollItemsBasicOnly_ = !!((cnt.__notRequired__ || 0) & 512);
  6783. await Promise.resolve().then(() => {
  6784. this.ytRendererBehavior.onScroll(evt);
  6785. }).then(() => {
  6786. if (onScrollItemsBasicOnly_) return;
  6787. if (this.canScrollToBottom_()) {
  6788. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  6789. if (hasUserJustInteracted) {
  6790. // only when there is an user action
  6791. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6792. return 1;
  6793. }
  6794. } else {
  6795. // no message inserting
  6796. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6797. return 1;
  6798. }
  6799. }).then((r) => {
  6800.  
  6801. if (onScrollItemsBasicOnly_) return;
  6802. if (this.activeItems_.length) {
  6803.  
  6804. if (this.canScrollToBottom_()) {
  6805. this.flushActiveItems_();
  6806. return 1 && r;
  6807. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  6808. // delayed due to user action
  6809. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  6810. return 0;
  6811. }
  6812. }
  6813. }).then((r) => {
  6814. if (onScrollItemsBasicOnly_) return;
  6815. if (r) {
  6816. // ensure setAtBottom is correctly set
  6817. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6818. }
  6819. });
  6820. } else {
  6821. cnt.onScrollItems66_(evt);
  6822. }
  6823.  
  6824. await Promise.resolve();
  6825.  
  6826. }
  6827.  
  6828. mclp.onScrollItems_ = function (evt) {
  6829.  
  6830. const cnt = this;
  6831. cnt.__intermediate_delay__ = new Promise(resolve => {
  6832. cnt.onScrollItems77_(evt).then(() => {
  6833. resolve();
  6834. });
  6835. });
  6836. }
  6837. console.log("onScrollItems_", "OK");
  6838. } else {
  6839. console.log("onScrollItems_", "NG");
  6840. }
  6841. }
  6842.  
  6843. if ((_flag0281_ & 0x2) == 0) {
  6844. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  6845.  
  6846. const sfi = fnIntegrity(mclp.handleLiveChatActions_);
  6847. // handleLiveChatActions66_
  6848. if(sfi === '1.40.20') {
  6849. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6850.  
  6851.  
  6852. // f.handleLiveChatActions_ = function(a) {
  6853. // var b = this;
  6854. // a.length && (a.forEach(this.handleLiveChatAction_, this),
  6855. // this.maybeResizeScrollContainer_(a),
  6856. // this.flushActiveItems_(),
  6857. // $u(function() {
  6858. // b.maybeScrollToBottom_()
  6859. // }))
  6860. // }
  6861.  
  6862. } else if (sfi === '1.39.20') {
  6863. // TBC
  6864. } else if (sfi === '1.31.17') {
  6865. // original
  6866. } else {
  6867. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.40.20'))
  6868. || logFn('mclp.handleLiveChatActions_', mclp.handleLiveChatActions_)();
  6869. }
  6870.  
  6871. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  6872.  
  6873. mclp.handleLiveChatActions77_ = async function (arr) {
  6874. if (typeof (arr || 0).length !== 'number') {
  6875. this.handleLiveChatActions66_(arr);
  6876. return;
  6877. }
  6878. if (mzt > 1e9) mzt = 9;
  6879. let tid = ++mzt;
  6880.  
  6881. if (zarr === null) zarr = arr;
  6882. else Array.prototype.push.apply(zarr, arr);
  6883. arr = null;
  6884.  
  6885. await iAFP(this.hostElement).then();
  6886. // await new Promise(requestAnimationFrame);
  6887.  
  6888. if (tid !== mzt || zarr === null) {
  6889. return;
  6890. }
  6891.  
  6892. const carr = zarr;
  6893. zarr = null;
  6894.  
  6895. await Promise.resolve();
  6896. this.handleLiveChatActions66_(carr);
  6897. await Promise.resolve();
  6898.  
  6899. }
  6900.  
  6901. mclp.handleLiveChatActions_ = function (arr) {
  6902.  
  6903.  
  6904. preprocessChatLiveActions(arr);
  6905.  
  6906.  
  6907.  
  6908. // console.log(1929, cnt.activeItems_)
  6909. // console.log(9487, arr);
  6910.  
  6911. const cnt = this;
  6912. cnt.__intermediate_delay__ = new Promise(resolve => {
  6913. cnt.handleLiveChatActions77_(arr).then(() => {
  6914. resolve();
  6915. });
  6916. });
  6917.  
  6918. resistanceUpdateFn_();
  6919. }
  6920. console.log("handleLiveChatActions_", "OK");
  6921. } else {
  6922. console.log("handleLiveChatActions_", "NG");
  6923. }
  6924. }
  6925.  
  6926. mclp.hasUserJustInteracted11_ = () => {
  6927. const t = dateNow();
  6928. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  6929. }
  6930.  
  6931. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  6932.  
  6933. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  6934.  
  6935. mclp.canScrollToBottom_ = function () {
  6936. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  6937. }
  6938.  
  6939. console.log("canScrollToBottom_", "OK");
  6940. } else {
  6941. console.log("canScrollToBottom_", "NG");
  6942. }
  6943.  
  6944. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  6945.  
  6946. mclp.isSmoothScrollEnabled_ = function () {
  6947. return false;
  6948. }
  6949.  
  6950. mclp.maybeResizeScrollContainer_ = function () {
  6951. //
  6952. }
  6953.  
  6954. mclp.refreshOffsetContainerHeight_ = function () {
  6955. //
  6956. }
  6957.  
  6958. mclp.smoothScroll_ = function () {
  6959. //
  6960. }
  6961.  
  6962. mclp.resetSmoothScroll_ = function () {
  6963. //
  6964. }
  6965. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  6966. } else {
  6967. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  6968. }
  6969.  
  6970. if ((_flag0281_ & 0x8) == 0) {
  6971.  
  6972.  
  6973. if (typeof mclp.forEachItem_ === 'function' && !mclp.forEachItem66_ && skipErrorForhandleAddChatItemAction_ && mclp.forEachItem_.length === 1) {
  6974.  
  6975. mclp.forEachItem66_ = mclp.forEachItem_;
  6976. mclp.forEachItem_ = function (a) {
  6977.  
  6978. if ((this._flag0281_ & 0x8) == 0x8) return this.forEachItem66_(a);
  6979.  
  6980. // ƒ (a){this.visibleItems.forEach(a.bind(this,"visibleItems"));this.activeItems_.forEach(a.bind(this,"activeItems_"))}
  6981.  
  6982. try {
  6983.  
  6984. let items801 = false;
  6985. if (typeof a === 'function') {
  6986. const items = this.items;
  6987. if (items instanceof HTMLDivElement) {
  6988. const ev = this.visibleItems;
  6989. const ea = this.activeItems_;
  6990. if (ev && ea && ev.length >= 0 && ea.length >= 0) {
  6991. items801 = items;
  6992. }
  6993. }
  6994. }
  6995.  
  6996. if (items801) {
  6997. items801.__children801__ = 1;
  6998. const res = this.forEachItem66_(a);
  6999. items801.__children801__ = 0;
  7000. return res;
  7001. }
  7002.  
  7003. } catch (e) { }
  7004. return this.forEachItem66_(a);
  7005.  
  7006.  
  7007. // this.visibleItems.forEach((val, idx, arr)=>{
  7008. // a.call(this, 'visibleItems', val, idx, arr);
  7009. // });
  7010.  
  7011. // this.activeItems_.forEach((val, idx, arr)=>{
  7012. // a.call(this, 'activeItems_', val, idx, arr);
  7013. // });
  7014.  
  7015.  
  7016.  
  7017. }
  7018.  
  7019.  
  7020. }
  7021.  
  7022. }
  7023.  
  7024. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  7025.  
  7026. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  7027. mclp.handleAddChatItemAction_ = function (a) {
  7028. try {
  7029. if (a && typeof a === 'object' && !('length' in a)) {
  7030. fixLiveChatItem(a.item, null);
  7031. console.assert(arguments[0] === a);
  7032. }
  7033. } catch (e) { console.warn(e) }
  7034. let res;
  7035. if (skipErrorForhandleAddChatItemAction_) { // YouTube Native Engine Issue
  7036. try {
  7037. res = this.handleAddChatItemAction66_.apply(this, arguments);
  7038. } catch (e) {
  7039. if (e && (e.message || '').includes('.querySelector(')) {
  7040. console.log("skipErrorForhandleAddChatItemAction_", e.message);
  7041. } else {
  7042. throw e;
  7043. }
  7044. }
  7045. } else {
  7046. res = this.handleAddChatItemAction66_.apply(this, arguments);
  7047. }
  7048. return res;
  7049. }
  7050.  
  7051. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  7052. } else {
  7053.  
  7054. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  7055. }
  7056.  
  7057.  
  7058. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  7059.  
  7060. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  7061. mclp.handleReplaceChatItemAction_ = function (a) {
  7062. try {
  7063. if (a && typeof a === 'object' && !('length' in a)) {
  7064. fixLiveChatItem(a.replacementItem, null);
  7065. console.assert(arguments[0] === a);
  7066. }
  7067. } catch (e) { console.warn(e) }
  7068. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  7069. }
  7070.  
  7071. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  7072. } else {
  7073.  
  7074. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  7075. }
  7076.  
  7077. console.log("[End]");
  7078. console.groupEnd();
  7079.  
  7080. }).catch(console.warn);
  7081.  
  7082.  
  7083. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  7084.  
  7085. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  7086.  
  7087. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  7088.  
  7089. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  7090. let v = `${attrValue}`;
  7091. // conside a ticker is 101px width
  7092. // 1% = 1.01px
  7093. // 0.2% = 0.202px
  7094.  
  7095.  
  7096. const ratio1 = (yd.ratio * 100);
  7097. if (ratio1 > -1) { // avoid NaN
  7098.  
  7099. // countdownDurationMs
  7100. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  7101. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  7102. // 150000 - 1% <1% = 1.5s>
  7103. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  7104. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  7105.  
  7106. // 99px * 5% = 4.95px
  7107.  
  7108. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  7109.  
  7110.  
  7111. // 1% Duration
  7112.  
  7113. let ratio2 = ratio1;
  7114.  
  7115. const ydd = yd.data;
  7116. if (ydd) {
  7117.  
  7118. const d1 = ydd.durationSec;
  7119. const d2 = ydd.fullDurationSec;
  7120.  
  7121. // @ step timing [min. 0.2%]
  7122. let numOfSteps = 500;
  7123. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  7124. if (d2 > 400) numOfSteps = 500; // 0.2%
  7125. else if (d2 > 200) numOfSteps = 200; // 0.5%
  7126. else if (d2 > 100) numOfSteps = 100; // 1%
  7127. else if (d2 > 50) numOfSteps = 50; // 2%
  7128. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  7129. else numOfSteps = 20;
  7130. }
  7131. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  7132. if (numOfSteps < 5) numOfSteps = 5;
  7133.  
  7134. const rd = numOfSteps / 100.0;
  7135.  
  7136. ratio2 = Math.round(ratio2 * rd) / rd;
  7137.  
  7138. // ratio2 = Math.round(ratio2 * 5) / 5;
  7139. ratio2 = ratio2.toFixed(1);
  7140. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  7141.  
  7142. if (yd.__style_last__ === v) return;
  7143. yd.__style_last__ = v;
  7144. // do not consider any delay here.
  7145. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  7146.  
  7147. }
  7148. }
  7149.  
  7150. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  7151.  
  7152.  
  7153. } else {
  7154. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  7155. }
  7156.  
  7157. };
  7158.  
  7159.  
  7160. const fpTicker = (renderer) => {
  7161. if (FLAG_001a) return;
  7162. const cnt = insp(renderer);
  7163. assertor(() => typeof (cnt || 0).is === 'string');
  7164. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  7165. const container = (cnt.$ || 0).container;
  7166. if (container) {
  7167. assertor(() => (container || 0).nodeType === 1);
  7168. assertor(() => typeof container.setAttribute === 'function');
  7169. container.setAttribute = tickerContainerSetAttribute;
  7170. } else {
  7171. console.warn(`"container" does not exist in ${cnt.is}`);
  7172. }
  7173. };
  7174.  
  7175.  
  7176. const tags = [
  7177. "yt-live-chat-ticker-renderer",
  7178. "yt-live-chat-ticker-paid-message-item-renderer",
  7179. "yt-live-chat-ticker-paid-sticker-item-renderer",
  7180. "yt-live-chat-ticker-sponsor-item-renderer"
  7181. ];
  7182.  
  7183. const tagsItemRenderer = [
  7184. "yt-live-chat-ticker-renderer",
  7185. "yt-live-chat-ticker-paid-message-item-renderer",
  7186. "yt-live-chat-ticker-paid-sticker-item-renderer",
  7187. "yt-live-chat-ticker-sponsor-item-renderer"
  7188. ];
  7189.  
  7190. const wmList = new Set;
  7191. if (DEBUG_wmList) {
  7192.  
  7193. setInterval(() => {
  7194. let q = document.querySelector('#label-text');
  7195. if(!q) return;
  7196. const size = new Set([...wmList].filter(e => e?.deref()?.isConnected === false).map(e => e?.deref())).size;
  7197. q.textContent = `${48833}, ${DEBUG_wmList_started}, ${size}`;
  7198.  
  7199. // console.log(48833, )
  7200. }, 100);
  7201. }
  7202.  
  7203.  
  7204. /*
  7205. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  7206. const dProto = {
  7207. detachedForTickerInit: function () {
  7208. try {
  7209. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  7210. // this.behaviorActionMap = 0;
  7211. // this.isVisibilityRoot = 0;
  7212. } catch (e) { }
  7213. return this.detached582MemoryLeak();
  7214. },
  7215. attachedForTickerInit: function () {
  7216. wmList.add(new WeakRef(this))
  7217. // fpTicker(this.hostElement || this);
  7218. return this.attached77();
  7219. },
  7220. }
  7221. for (const tag of tagsItemRenderer) { // ##tag##
  7222. const dummy = document.createElement(tag);
  7223. const cProto = getProto(dummy);
  7224. if (!cProto || !cProto.attached) {
  7225. console.warn(`proto.attached for ${tag} is unavailable.`);
  7226. continue;
  7227. }
  7228. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  7229. cProto.detached582MemoryLeak = cProto.detached;
  7230. cProto.detached = cProto.detachedForTickerInit;
  7231. }
  7232. cProto.attached77 = cProto.attached;
  7233. cProto.attached = dProto.attachedForTickerInit;
  7234. }
  7235. });
  7236. */
  7237.  
  7238.  
  7239. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  7240.  
  7241. if (FLAG_001b) return;
  7242. mightFirstCheckOnYtInit();
  7243. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  7244. console.log("[Begin]");
  7245.  
  7246. let dummyValueForStyleReturn = null;
  7247.  
  7248. const genDummyValueForStyleReturn = () => {
  7249. let s = `--nx:82;`
  7250. let ro = {
  7251. "privateDoNotAccessOrElseSafeStyleWrappedValue_": s,
  7252. "implementsGoogStringTypedString": true
  7253. };
  7254. ro.getTypedStringValue = ro.toString = function () { return this.privateDoNotAccessOrElseSafeStyleWrappedValue_ };
  7255. return ro;
  7256. }
  7257.  
  7258. let isCSSPropertySupported_ = null;
  7259. const isCSSPropertySupported = () => {
  7260.  
  7261. // @property --ticker-rtime
  7262.  
  7263. if (typeof isCSSPropertySupported_ === 'boolean') return isCSSPropertySupported_;
  7264. isCSSPropertySupported_ = false;
  7265.  
  7266. if (typeof CSS !== 'object' || typeof (CSS || 0).registerProperty !== 'function') return false;
  7267. const documentElement = document.documentElement;
  7268. if (!documentElement) {
  7269. console.warn('document.documentElement is not found');
  7270. return false;
  7271. }
  7272. if (`${getComputedStyleCached(documentElement).getPropertyValue('--ticker-rtime')}`.length === 0) {
  7273. return false;
  7274. }
  7275.  
  7276. const ae = animate.call(documentElement,
  7277. [
  7278. { '--ticker-rtime': '70%' },
  7279. { '--ticker-rtime': '30%' }
  7280. ],
  7281. {
  7282. fill: "forwards",
  7283. duration: 1000 * 40,
  7284. easing: 'linear'
  7285. }
  7286. );
  7287.  
  7288. let animatedValue = getComputedStyleCached(document.documentElement).getPropertyValue('--ticker-rtime');
  7289. ae.finish();
  7290. if (`${animatedValue}`.length !== 3) return false;
  7291.  
  7292. isCSSPropertySupported_ = true;
  7293. return true;
  7294.  
  7295. };
  7296.  
  7297. let tickerAttachmentId = 0;
  7298.  
  7299. let windowShownAt = -1;
  7300. const setupEventForWindowShownAt = () => {
  7301. window.addEventListener('visibilitychange', () => {
  7302. if (document.visibilityState === 'visible') windowShownAt = Date.now();
  7303. else windowShownAt = 0;
  7304. }, false);
  7305. }
  7306.  
  7307. const __requestRemoval__ = function (cnt) {
  7308. if (cnt.hostElement && typeof cnt.requestRemoval === 'function') {
  7309. try {
  7310. const id = (cnt.data || 0).id;
  7311. if (!id) cnt.data = { id: 1 };
  7312. } catch (e) { }
  7313. try {
  7314. cnt.requestRemoval();
  7315. return true;
  7316. } catch (e) { }
  7317. }
  7318. return false;
  7319. }
  7320.  
  7321. const widthIORes = new WeakMap();
  7322. const widthIO = new IntersectionObserver((mutations) => {
  7323. for (const mutation of mutations) {
  7324. const elm = mutation.target;
  7325. widthIO.unobserve(elm);
  7326. const {promise, values} =widthIORes.get(elm) || {};
  7327. if(promise && values){
  7328.  
  7329.  
  7330. widthIORes.delete(elm);
  7331. values.width= mutation.boundingClientRect.width;
  7332. promise.resolve(values);
  7333. }
  7334. }
  7335. });
  7336. const widthReq = (elm)=>{
  7337.  
  7338. {
  7339.  
  7340. const {promise, values} =widthIORes.get(elm) || {};
  7341. if(promise) return promise;
  7342. }
  7343. const promise = new PromiseExternal();
  7344. widthIORes.set(elm, {promise, values: {}});
  7345. widthIO.unobserve(elm);
  7346. widthIO.observe(elm);
  7347.  
  7348. return promise;
  7349.  
  7350. }
  7351.  
  7352. let mo43p = null;
  7353. const mo43 = new MutationObserver(()=>{
  7354.  
  7355. const p = mo43p;
  7356. mo43p = null;
  7357. if(p){
  7358. p.resolve();
  7359. }
  7360. });
  7361.  
  7362.  
  7363. const dProto = {
  7364.  
  7365.  
  7366. /**
  7367. *
  7368.  
  7369. f.updateStatsBarAndMaybeShowAnimation = function(a, b, c) {
  7370. var d = this;
  7371. a || c();
  7372. a && this.statsBar && this.username && this.textContent && (this.isMouseOver ? (b(),
  7373. c()) : (a = this.animateShowStats(),
  7374. this.data.animationOrigin && this.data.trackingParams && aB().stateChanged(this.data.trackingParams, {
  7375. animationEventData: {
  7376. origin: this.data.animationOrigin
  7377. }
  7378. }),
  7379. a.finished.then(function() {
  7380. var e;
  7381. setTimeout(function() {
  7382. b();
  7383. c();
  7384. if (!d.isMouseOver) {
  7385. var g, k;
  7386. d.animateHideStats(((g = d.data) == null ? void 0 : g.dynamicStateData.stateSlideDurationMs) || 0, ((k = d.data) == null ? void 0 : k.dynamicStateData.stateUpdateDelayAfterMs) || 0)
  7387. }
  7388. }, ((e = d.data) == null ? void 0 : e.dynamicStateData.stateUpdateDelayBeforeMs) || 0)
  7389. })))
  7390. }
  7391.  
  7392. *
  7393. */
  7394.  
  7395.  
  7396.  
  7397. /**
  7398. *
  7399. *
  7400.  
  7401. f.animateShowStats = function() {
  7402. var a = this.textContent.animate({
  7403. transform: "translateY(-30px)"
  7404. }, {
  7405. duration: this.data.dynamicStateData.stateSlideDurationMs,
  7406. fill: "forwards"
  7407. });
  7408. this.username.animate({
  7409. opacity: 0
  7410. }, {
  7411. duration: 500,
  7412. fill: "forwards"
  7413. });
  7414. this.statsBar.animate({
  7415. opacity: 1
  7416. }, {
  7417. duration: 500,
  7418. fill: "forwards"
  7419. });
  7420. return a
  7421. }
  7422. ;
  7423. f.animateHideStats = function(a, b) {
  7424. this.textContent.animate({
  7425. transform: "translateY(0)"
  7426. }, {
  7427. duration: a,
  7428. fill: "forwards",
  7429. delay: b
  7430. });
  7431. this.username.animate({
  7432. opacity: 1
  7433. }, {
  7434. duration: 300,
  7435. fill: "forwards",
  7436. delay: b
  7437. });
  7438. this.statsBar.animate({
  7439. opacity: 0
  7440. }, {
  7441. duration: 300,
  7442. fill: "forwards",
  7443. delay: b
  7444. })
  7445. }
  7446. *
  7447. */
  7448. updateStatsBarAndMaybeShowAnimationRevised: function (a, b, c) {
  7449. // prevent memory leakage due to d.data was asked in a.finished.then
  7450. try{
  7451. // console.log('updateStatsBarAndMaybeShowAnimation called', this.is)
  7452. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7453. return this.updateStatsBarAndMaybeShowAnimation38.call(this.__proxySelf0__, a, b, c);
  7454. }catch(e){
  7455. console.log('updateStatsBarAndMaybeShowAnimationRevised ERROR');
  7456. console.error(e);
  7457. }
  7458. },
  7459.  
  7460. detachedForMemoryLeakage: function () {
  7461.  
  7462. try{
  7463. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  7464. // this.behaviorActionMap = 0;
  7465. // this.isVisibilityRoot = 0;
  7466. }catch(e){}
  7467. return this.detached582MemoryLeak();
  7468. },
  7469.  
  7470. detachedForTickerInit: function () {
  7471.  
  7472. Promise.resolve(this).then((cnt) => {
  7473. if (cnt.isAttached) return;
  7474. cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false && __requestRemoval__(cnt);
  7475. cnt.rafId > 1 && rafHub.cancel(cnt.rafId);
  7476. }).catch(console.warn);
  7477.  
  7478. let r;
  7479. try {
  7480. r = this.detached77();
  7481. } catch (e) {
  7482. console.warn(e);
  7483. }
  7484. this.__ticker_attachmentId__ = 0;
  7485. return r;
  7486. },
  7487.  
  7488. attachedForTickerInit: function () {
  7489. if (tickerAttachmentId > 1e9) tickerAttachmentId = 9;
  7490. this.__ticker_attachmentId__ = ++tickerAttachmentId;
  7491.  
  7492. const hostElement = this.hostElement;
  7493. if (hostElement instanceof HTMLElement) {
  7494. hostElement.classList.add('r6-width-adjustable');
  7495. }
  7496.  
  7497. DEBUG_wmList && wmList.add(new WeakRef(this))
  7498. if (DEBUG_wmList && !DEBUG_wmList_started) {
  7499. console.log('!!!!!!!!!!!!! DEBUG_wmList_started !!!!!!!!!')
  7500. DEBUG_wmList_started = 1;
  7501. }
  7502.  
  7503. fpTicker(this.hostElement || this);
  7504. return this.attached77();
  7505.  
  7506. },
  7507.  
  7508.  
  7509. // doAnimator
  7510.  
  7511. _makeAnimator: function () {
  7512. if (this._r782) return;
  7513. // if (!this.isAttached) return;
  7514. if (!this._runnerAE) {
  7515. /** @type {HTMLElement | null} */
  7516. const aElement = (this.$ || 0).container;
  7517. if (!aElement) return console.warn("this.$.container is undefined");
  7518. const da = this.data;
  7519. if (!da || !da.startBackgroundColor || !da.endBackgroundColor) return console.warn("this.data is undefined or incorrect");
  7520. const c1 = this.colorFromDecimal(da.startBackgroundColor);
  7521. const c2 = this.colorFromDecimal(da.endBackgroundColor);
  7522. if (typeof c1 !== 'string' || typeof c2 !== 'string') return console.warn('c1, c2 is not a string');
  7523.  
  7524. // if (!this.__tickerBackgroundInitialChecked__) {
  7525. // this.constructor.prototype.__tickerBackgroundInitialChecked__ = true;
  7526. // console.log('__tickerBackgroundInitialChecked__')
  7527. // this._checkTickerBackgroundChanged();
  7528. // }
  7529.  
  7530. aElement.style.setProperty('--ticker-c1', c1);
  7531. aElement.style.setProperty('--ticker-c2', c2);
  7532. aElement.classList.add(runTickerClassName);
  7533. const p = (this.countdownMs / this.countdownDurationMs) * 100;
  7534. // this._aeStartV = this.countdownMs;
  7535. // this._aeStartT = this.countdownDurationMs;
  7536. if (!(p >= 0 && p <= 100)) {
  7537. console.warn('incorrect time ratio', p);
  7538. } else {
  7539. /*
  7540. const u0 = p.toFixed(4) + '%';
  7541. this._runnerAE = animate.call(aElement,
  7542. [
  7543. { '--ticker-rtime': u0 },
  7544. { '--ticker-rtime': '0%' }
  7545. ]
  7546. ,
  7547. {
  7548. fill: "forwards",
  7549. duration: this.countdownMs,
  7550. easing: "linear"
  7551. }
  7552. );
  7553. */
  7554.  
  7555. let timingFn = 'linear';
  7556.  
  7557. const totalDuration = this.countdownDurationMs;
  7558.  
  7559. if (ATTEMPT_ANIMATED_TICKER_BACKGROUND === 'steps') {
  7560.  
  7561. // @ step timing [min. 0.2%]
  7562. let stepInterval = 0.2; // unit: %
  7563. if (totalDuration > 400000) stepInterval = 0.2;
  7564. else if (totalDuration > 200000) stepInterval = 0.5;
  7565. else if (totalDuration > 100000) stepInterval = 1;
  7566. else if (totalDuration > 50000) stepInterval = 2;
  7567. else if (totalDuration > 25000) stepInterval = 5;
  7568. else stepInterval = 5;
  7569.  
  7570. let numOfSteps = Math.round(100 / stepInterval);
  7571.  
  7572. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  7573. if (numOfSteps < 5) numOfSteps = 5;
  7574.  
  7575. timingFn = `steps(${numOfSteps}, end)`;
  7576.  
  7577. }
  7578.  
  7579.  
  7580. /** @type {Animation} */
  7581. const ae = animate.call(aElement,
  7582. [
  7583. { '--ticker-rtime': '100%' },
  7584. { '--ticker-rtime': '0%' }
  7585. ]
  7586. ,
  7587. {
  7588. fill: "forwards",
  7589. duration: totalDuration,
  7590. easing: timingFn
  7591. }
  7592. );
  7593.  
  7594. this._runnerAE = ae;
  7595.  
  7596. ae.onfinish = (event) => {
  7597. this.onfinish = null;
  7598. if (this._runnerAE !== ae) return;
  7599. if (this.isAttached === true && !this._r782 && ((this.$ || 0).container || 0).isConnected === true) {
  7600. this._aeFinished(event);
  7601. }
  7602. }
  7603.  
  7604. let bq = (1.0 - (this.countdownMs / totalDuration)) * totalDuration;
  7605.  
  7606. if (bq >= 0 && bq <= totalDuration) {
  7607.  
  7608. if (bq > totalDuration - 1) {
  7609. ae.currentTime = bq;
  7610. // setTimeout(() => {
  7611. // if (this._runnerAE === ae && ae.onfinish) ae.onfinish();
  7612. // }, 1);
  7613. } else {
  7614. ae.currentTime = bq;
  7615. }
  7616. } else {
  7617. console.warn('Error on setting _runnerAE.currentTime!');
  7618. }
  7619.  
  7620.  
  7621. aeConstructor = ae.constructor; // constructor is from iframe
  7622. return ae;
  7623. }
  7624. } else {
  7625. if (!aeConstructor) return console.warn('aeConstructor is undefined');
  7626. // assume just time update
  7627. const ae = this._runnerAE;
  7628. if (!(ae instanceof aeConstructor)) return console.warn('this._runnerAE is not Animation');
  7629. if (ae.playState !== 'paused') console.warn('ae.playState !== paused');
  7630. let p = (this.countdownMs / this.countdownDurationMs) * 100;
  7631. if (!(p >= 0 && p <= 100)) {
  7632. console.warn('incorrect time ratio', p);
  7633. } else {
  7634. // let u0 = p.toFixed(4) + '%'
  7635. /*
  7636. ae.effect.setKeyframes([
  7637. { '--ticker-rtime': u0 },
  7638. { '--ticker-rtime': '0%' }
  7639. ]);
  7640. ae.effect.updateTiming({ duration: this.countdownMs });
  7641. */
  7642. // ae.currentTime = 0;
  7643.  
  7644.  
  7645.  
  7646. let bq = (1.0 - (this.countdownMs / this.countdownDurationMs)) * this.countdownDurationMs;
  7647. if (bq >= 0 && bq <= this.countdownDurationMs) {
  7648.  
  7649. this._runnerAE.currentTime = bq
  7650. } else {
  7651. console.warn('Error on setting _runnerAE.currentTime!');
  7652. }
  7653.  
  7654.  
  7655. ae.play();
  7656. return ae;
  7657. }
  7658. }
  7659. },
  7660.  
  7661. _aeFinished: function (event) {
  7662.  
  7663. if (this._r782) return;
  7664.  
  7665. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  7666. this._throwOut();
  7667. return;
  7668. }
  7669.  
  7670. if (!this._runnerAE) console.warn('Error in .updateTimeout; this._runnerAE is undefined');
  7671.  
  7672. let lc = window.performance.now();
  7673. this.countdownMs = Math.max(0, this.countdownMs - (lc - this.lastCountdownTimeMs));
  7674. if (this.countdownMs > this.countdownDurationMs) this.countdownMs = this.countdownDurationMs;
  7675. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = lc;
  7676. if (this.countdownMs > 76) console.warn('Warning: this.countdownMs is not zero when finished!', this.countdownMs, this, event); // just warning.
  7677.  
  7678. this.countdownMs = 0;
  7679. this.lastCountdownTimeMs = this._lastCountdownTimeMsX0 = null;
  7680.  
  7681. if (this.isAttached) {
  7682. let fastRemoved = false;
  7683. if (Date.now() - windowShownAt < 80 && typeof this.requestRemoval === 'function') {
  7684. // no animation if the video page is switched from background to foreground
  7685. // this.hostElement.style.display = 'none';
  7686.  
  7687. fastRemoved = __requestRemoval__(this);
  7688. }
  7689.  
  7690. if (!fastRemoved) {
  7691. "auto" === this.hostElement.style.width && this.setContainerWidth();
  7692. this.slideDown();
  7693. }
  7694. }
  7695.  
  7696.  
  7697.  
  7698. },
  7699.  
  7700.  
  7701. /** @type {()} */
  7702. _throwOut: function () {
  7703. this._r782 = 1;
  7704. Promise.resolve(this).then((cnt) => {
  7705. __requestRemoval__(cnt);
  7706. cnt.detached();
  7707. if (cnt.__dataClientsReady === true) cnt.__dataClientsReady = false;
  7708. if (cnt.__dataEnabled === true) cnt.__dataEnabled = false;
  7709. if (cnt.__dataReady === true) cnt.__dataReady = false;
  7710. cnt.data = null;
  7711. cnt.countdownMs = 0;
  7712. cnt.lastCountdownTimeMs = null;
  7713. const hm = cnt.hostElement || cnt;
  7714. if (hm.parentNode) hm.remove();
  7715. for (let t; t = hm.firstChild;) t.remove();
  7716. }).catch(e => {
  7717. console.warn(e);
  7718. });
  7719. },
  7720.  
  7721.  
  7722. // doTimerFnModification
  7723.  
  7724.  
  7725. /** @type {(a, b)} */
  7726. startCountdownForTimerFnModA: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  7727. try {
  7728.  
  7729. const cnt = kRef(this);
  7730. if (!cnt) return;
  7731. if (!cnt.hostElement) return;
  7732.  
  7733. const attachementId = cnt.__ticker_attachmentId__;
  7734. if(!attachementId) return;
  7735.  
  7736. // a.durationSec [s] => countdownMs [ms]
  7737. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  7738. // lastCountdownTimeMs => raf ongoing
  7739. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  7740.  
  7741. if (cnt._r782) return;
  7742.  
  7743. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7744. cnt._throwOut();
  7745. return;
  7746. }
  7747.  
  7748. // TimerFnModA
  7749.  
  7750. b = void 0 === b ? 0 : b;
  7751. if (void 0 !== a) {
  7752.  
  7753. cnt.countdownMs = 1E3 * a; // decreasing from durationSec[s] to zero
  7754. cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs; // constant throughout the animation
  7755. if (!(cnt.lastCountdownTimeMs || cnt.isAnimationPaused)) {
  7756. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now()
  7757. cnt.rafId = 1
  7758. if (cnt._runnerAE) console.warn('Error in .startCountdown; cnt._runnerAE already created.')
  7759. cnt.detlaSincePausedSecs = 0;
  7760. const ae = cnt._makeAnimator();
  7761. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  7762.  
  7763. // if (playerProgressChangedArg1 === null) {
  7764. // console.log('startCountdownForTimerFnModA', cnt.data)
  7765. // }
  7766.  
  7767. if (isPlayProgressTriggered && cnt.isAnimationPaused !== true && cnt.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__) {
  7768.  
  7769.  
  7770.  
  7771.  
  7772. cnt.playerProgressSec = lastPlayerProgress > 0 ? lastPlayerProgress : 0; // save the progress first
  7773. cnt.isAnimationPaused = true; // trigger isAnimationPausedChanged
  7774. cnt.detlaSincePausedSecs = 0;
  7775. cnt._forceNoDetlaSincePausedSecs783 = 1; // reset cnt.detlaSincePausedSecs = 0 when resumed
  7776.  
  7777. relayPromise = relayPromise || new PromiseExternal();
  7778.  
  7779. relayPromise.then(() => {
  7780.  
  7781. const cnt = kRef(this);
  7782. if (!cnt) return;
  7783. if (!cnt.hostElement) return;
  7784.  
  7785. if (cnt && attachementId !== cnt.__ticker_attachmentId__) return;
  7786. if (cnt.isAttached === true && cnt.countdownDurationMs > 0 && cnt.isAnimationPaused === true && cnt.isReplayPaused !== true) {
  7787. cnt.isAnimationPaused = false;
  7788. }
  7789. });
  7790.  
  7791.  
  7792. }
  7793.  
  7794.  
  7795.  
  7796. }
  7797. }
  7798.  
  7799. } catch (e) {
  7800. console.warn(e);
  7801. }
  7802.  
  7803. },
  7804.  
  7805.  
  7806.  
  7807. /** @type {(a, b)} */
  7808. startCountdownForTimerFnModT: function (a, b) { // .startCountdown(a.durationSec, a.fullDurationSec)
  7809.  
  7810. try {
  7811. const cnt = kRef(this);
  7812. if (!cnt) return;
  7813. if (!cnt.hostElement) return;
  7814.  
  7815. const attachementId = cnt.__ticker_attachmentId__;
  7816. if(!attachementId) return;
  7817.  
  7818. // a.durationSec [s] => countdownMs [ms]
  7819. // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  7820. // lastCountdownTimeMs => raf ongoing
  7821. // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  7822.  
  7823. if (cnt._r782) return;
  7824.  
  7825. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7826. cnt._throwOut();
  7827. return;
  7828. }
  7829.  
  7830. // TimerFnModT
  7831.  
  7832. // console.log('cProto.startCountdown', tag) // yt-live-chat-ticker-sponsor-item-renderer
  7833. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  7834. b = void 0 === b ? 0 : b;
  7835. void 0 !== a && (cnt.countdownMs = 1E3 * a,
  7836. cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs,
  7837. cnt.ratio = 1,
  7838. cnt.lastCountdownTimeMs || cnt.isAnimationPaused || (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now(),
  7839. cnt.rafId = rafHub.request(cnt.boundUpdateTimeout37_)))
  7840.  
  7841. } catch (e) {
  7842. console.warn(e);
  7843. }
  7844.  
  7845. },
  7846.  
  7847.  
  7848. /** @type {(a,)} */
  7849. updateTimeoutForTimerFnModA: function (a) {
  7850.  
  7851. try {
  7852. const cnt = kRef(this);
  7853. if (!cnt) return;
  7854. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7855.  
  7856. const attachementId = cnt.__ticker_attachmentId__;
  7857. if(!attachementId) return;
  7858.  
  7859. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  7860.  
  7861. if (cnt._r782) return;
  7862.  
  7863. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7864. cnt._throwOut();
  7865. return;
  7866. }
  7867.  
  7868. // TimerFnModA
  7869.  
  7870. if (!cnt._runnerAE) console.warn('Error in .updateTimeout; cnt._runnerAE is undefined');
  7871. if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  7872. cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  7873. }
  7874. if (cnt.countdownMs > cnt.countdownDurationMs) cnt.countdownMs = cnt.countdownDurationMs;
  7875. if (cnt.isAttached && cnt.countdownMs) {
  7876. cnt.lastCountdownTimeMs = a
  7877. const ae = cnt._makeAnimator(); // request raf
  7878. if (!ae) console.warn('Error in startCountdown._makeAnimator()');
  7879. } else {
  7880. (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  7881. cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7882. cnt.slideDown()));
  7883. }
  7884.  
  7885. } catch (e) {
  7886. console.warn(e);
  7887. }
  7888.  
  7889.  
  7890. },
  7891.  
  7892. /** @type {(a,)} */
  7893. updateTimeoutForTimerFnModT: function (a) {
  7894.  
  7895. try {
  7896. const cnt = kRef(this);
  7897. if (!cnt) return;
  7898. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7899.  
  7900. const attachementId = cnt.__ticker_attachmentId__;
  7901. if(!attachementId) return;
  7902.  
  7903. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  7904.  
  7905. if (cnt._r782) return;
  7906.  
  7907. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7908. cnt._throwOut();
  7909. return;
  7910. }
  7911.  
  7912. // TimerFnModT
  7913.  
  7914. // console.log('cProto.updateTimeout', tag) // yt-live-chat-ticker-sponsor-item-renderer
  7915. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  7916. if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  7917. cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  7918. }
  7919. // console.log(703, cnt.countdownMs)
  7920. cnt.ratio = cnt.countdownMs / cnt.countdownDurationMs;
  7921. cnt.isAttached && cnt.countdownMs ? (cnt.lastCountdownTimeMs = a,
  7922. cnt.rafId = rafHub.request(cnt.boundUpdateTimeout37_)) : (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  7923. cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  7924. cnt.slideDown()))
  7925.  
  7926.  
  7927. } catch (e) {
  7928. console.warn(e);
  7929. }
  7930. },
  7931.  
  7932. /** @type {(a,b)} */
  7933. isAnimationPausedChangedForTimerFnModA: function (a, b) {
  7934.  
  7935. const cnt = kRef(this);
  7936. if (!cnt) return;
  7937. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7938.  
  7939. const attachementId = cnt.__ticker_attachmentId__;
  7940. if(!attachementId) return;
  7941.  
  7942. if (cnt._r782) return;
  7943.  
  7944. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  7945. cnt._throwOut();
  7946. return;
  7947. }
  7948. let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  7949. cnt._forceNoDetlaSincePausedSecs783 = 0;
  7950.  
  7951. Promise.resolve(cnt).then((cnt) => {
  7952.  
  7953. if(attachementId !== cnt.__ticker_attachmentId__) return;
  7954.  
  7955. if (a) {
  7956.  
  7957. if (cnt._runnerAE && cnt._runnerAE.playState === 'running') {
  7958.  
  7959. cnt._runnerAE.pause()
  7960. let lc = window.performance.now();
  7961. cnt.countdownMs = Math.max(0, cnt.countdownMs - (lc - cnt.lastCountdownTimeMs));
  7962. if (cnt.countdownMs > cnt.countdownDurationMs) cnt.countdownMs = cnt.countdownDurationMs;
  7963. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = lc;
  7964. }
  7965.  
  7966. } else if (!a && b) {
  7967.  
  7968.  
  7969. if (forceNoDetlaSincePausedSecs783) cnt.detlaSincePausedSecs = 0;
  7970. a = cnt.detlaSincePausedSecs ? (cnt.lastCountdownTimeMs || 0) + 1000 * cnt.detlaSincePausedSecs : (cnt.lastCountdownTimeMs || 0);
  7971. cnt.detlaSincePausedSecs = 0;
  7972. cnt.updateTimeout(a);
  7973. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now();
  7974.  
  7975. }
  7976.  
  7977. cnt = null;
  7978.  
  7979.  
  7980. }).catch(e => {
  7981. console.log(e);
  7982. });
  7983.  
  7984.  
  7985.  
  7986. },
  7987.  
  7988.  
  7989. /** @type {(a,b)} */
  7990. isAnimationPausedChangedForTimerFnModT: function (a, b) {
  7991.  
  7992. const cnt = kRef(this);
  7993. if (!cnt) return;
  7994. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  7995.  
  7996. const attachementId = cnt.__ticker_attachmentId__;
  7997. if(!attachementId) return;
  7998.  
  7999. if (cnt._r782) return;
  8000.  
  8001. if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  8002. cnt._throwOut();
  8003. return;
  8004. }
  8005. // let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  8006. // cnt._forceNoDetlaSincePausedSecs783 = 0;
  8007.  
  8008. Promise.resolve(cnt).then((cnt) => {
  8009.  
  8010. if(attachementId !== cnt.__ticker_attachmentId__) return;
  8011.  
  8012. // TimerFnModT
  8013.  
  8014. // ez++;
  8015. // if(ez> 1e9) ez=9;
  8016. if (!cnt.boundUpdateTimeout37_) cnt.boundUpdateTimeout37_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  8017. a ? rafHub.cancel(cnt.rafId) : !a && b && (a = cnt.lastCountdownTimeMs || 0,
  8018. cnt.detlaSincePausedSecs && (a = (cnt.lastCountdownTimeMs || 0) + 1E3 * cnt.detlaSincePausedSecs,
  8019. cnt.detlaSincePausedSecs = 0),
  8020. cnt.boundUpdateTimeout37_(a),
  8021. cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now())
  8022.  
  8023. cnt = null;
  8024.  
  8025. }).catch(e => {
  8026. console.log(e);
  8027. });
  8028.  
  8029.  
  8030.  
  8031. },
  8032.  
  8033. setContainerWidthNoSelfLeakage: function(){
  8034. // prevent memory leakage due ot delay function
  8035. try{
  8036. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8037. return this.setContainerWidth55.call(this.__proxySelf0__);
  8038. }catch(e){
  8039. console.log('setContainerWidthNoSelfLeakage ERROR');
  8040. console.error(e);
  8041. }
  8042.  
  8043. },
  8044.  
  8045. slideDownNoSelfLeakage: function(){
  8046. // prevent memory leakage due ot delay function
  8047. try{
  8048. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8049. return this.slideDown55.call(this.__proxySelf0__);
  8050. }catch(e){
  8051. console.log('slideDownNoSelfLeakage ERROR');
  8052. console.error(e);
  8053. }
  8054. },
  8055.  
  8056. collapseNoSelfLeakage: function(){
  8057. // prevent memory leakage due ot delay function
  8058. try{
  8059. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8060. return this.collapse55.call(this.__proxySelf0__);
  8061. }catch(e){
  8062. console.log('collapseNoSelfLeakage ERROR');
  8063. console.error(e);
  8064. }
  8065. },
  8066.  
  8067. deletedChangedNoSelfLeakage: function(){
  8068. // prevent memory leakage due ot delay function
  8069. try{
  8070. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8071. return this.deletedChanged55.call(this.__proxySelf0__);
  8072. }catch(e){
  8073. console.log('deletedChangedNoSelfLeakage ERROR');
  8074. console.error(e);
  8075. }
  8076.  
  8077. },
  8078.  
  8079.  
  8080. /** @type {(a,b)} */
  8081. computeContainerStyleForAnimatorEnabled: function (a, b) {
  8082.  
  8083. if (this._r782) return;
  8084. const attachementId = this.__ticker_attachmentId__;
  8085. if(!attachementId) return;
  8086.  
  8087. if (this.isAttached === false && ((this.$ || 0).container || 0).isConnected === false) {
  8088. this._throwOut();
  8089. return;
  8090. }
  8091.  
  8092. return (dummyValueForStyleReturn || (dummyValueForStyleReturn = genDummyValueForStyleReturn()));
  8093.  
  8094. },
  8095.  
  8096.  
  8097.  
  8098. /** @type {()} */
  8099. handlePauseReplayForPlaybackProgressState: function () {
  8100. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  8101.  
  8102. const attachementId = this.__ticker_attachmentId__;
  8103. if(!attachementId) return;
  8104.  
  8105. const jr = mWeakRef(this);
  8106.  
  8107. if (onPlayStateChangePromise) {
  8108.  
  8109. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  8110. const tid = ++this.rtu;
  8111.  
  8112. onPlayStateChangePromise.then(() => {
  8113. const cnt = kRef(jr);
  8114. if(attachementId !== cnt.__ticker_attachmentId__) return;
  8115. if (cnt.isAttached) {
  8116. if (tid === cnt.rtu && !onPlayStateChangePromise && typeof cnt.handlePauseReplay === 'function' && cnt.hostElement) cnt.handlePauseReplay.apply(cnt, arguments);
  8117. // this.handlePauseReplay can be undefined if it is memory cleaned
  8118. }
  8119. });
  8120.  
  8121. return;
  8122. }
  8123.  
  8124. if (playerState !== 2) return;
  8125. if (this.isAttached) {
  8126. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  8127. const tid = ++this.rtk;
  8128. const tc = relayCount;
  8129. foregroundPromiseFn().then(() => {
  8130. const cnt = kRef(jr);
  8131. if (attachementId !== cnt.__ticker_attachmentId__) return;
  8132. if (cnt.isAttached) {
  8133. if (tid === cnt.rtk && tc === relayCount && playerState === 2 && _playerState === playerState && cnt.hostElement) {
  8134. cnt.handlePauseReplay66();
  8135. }
  8136. }
  8137.  
  8138. })
  8139. }
  8140. },
  8141.  
  8142. /** @type {()} */
  8143. handleResumeReplayForPlaybackProgressState: function () {
  8144. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  8145.  
  8146. const attachementId = this.__ticker_attachmentId__;
  8147. if(!attachementId) return;
  8148.  
  8149. const jr = mWeakRef(this);
  8150. if (onPlayStateChangePromise) {
  8151.  
  8152. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  8153. const tid = ++this.rtv;
  8154.  
  8155. onPlayStateChangePromise.then(() => {
  8156. const cnt = kRef(jr);
  8157. if(attachementId !== cnt.__ticker_attachmentId__) return;
  8158. if (tid === cnt.rtv && !onPlayStateChangePromise && typeof cnt.handleResumeReplay === 'function' && cnt.hostElement) cnt.handleResumeReplay.apply(cnt, arguments);
  8159. // this.handleResumeReplay can be undefined if it is memory cleaned
  8160. });
  8161.  
  8162. return;
  8163. }
  8164.  
  8165.  
  8166. if (playerState !== 1) return;
  8167. if (this.isAttached) {
  8168. const tc = relayCount;
  8169.  
  8170. relayPromise = relayPromise || new PromiseExternal();
  8171. relayPromise.then(() => {
  8172. const cnt = kRef(jr);
  8173. if(attachementId !== cnt.__ticker_attachmentId__) return;
  8174. if (relayCount > tc && playerState === 1 && _playerState === playerState && cnt.hostElement) {
  8175. cnt.handleResumeReplay66();
  8176. }
  8177. });
  8178. }
  8179. },
  8180.  
  8181. /** @type {(a,)} */
  8182. handleReplayProgressForPlaybackProgressState: function (a) {
  8183. if (this.isAttached) {
  8184. const attachementId = this.__ticker_attachmentId__;
  8185. if(!attachementId) return;
  8186. const tid = ++this.rtk;
  8187. const jr = mWeakRef(kRef(this));
  8188. foregroundPromiseFn().then(() => {
  8189. const cnt = kRef(jr);
  8190. if(attachementId !== cnt.__ticker_attachmentId__) return;
  8191. if (cnt.isAttached) {
  8192. if (tid === cnt.rtk && cnt.hostElement) {
  8193. cnt.handleReplayProgress66(a);
  8194. }
  8195. }
  8196. })
  8197. }
  8198. }
  8199.  
  8200.  
  8201. }
  8202.  
  8203.  
  8204. for (const tag of tagsItemRenderer) { // ##tag##
  8205.  
  8206.  
  8207. const dummy = document.createElement(tag);
  8208.  
  8209. const cProto = getProto(dummy);
  8210. if (!cProto || !cProto.attached) {
  8211. console.warn(`proto.attached for ${tag} is unavailable.`);
  8212. continue;
  8213. }
  8214.  
  8215. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  8216. cProto.detached582MemoryLeak = cProto.detached;
  8217. cProto.detached = dProto.detachedForMemoryLeakage;
  8218. }
  8219.  
  8220. cProto.detached77 = cProto.detached;
  8221. cProto.detached = dProto.detachedForTickerInit;
  8222.  
  8223. cProto.attached77 = cProto.attached;
  8224.  
  8225. cProto.attached = dProto.attachedForTickerInit;
  8226.  
  8227. if (FLAG_001c) continue;
  8228.  
  8229. let flgLeakageFixApplied = 0;
  8230.  
  8231. if (FIX_MEMORY_LEAKAGE_TICKER_STATSBAR && typeof cProto.updateStatsBarAndMaybeShowAnimation === 'function' && !cProto.updateStatsBarAndMaybeShowAnimation38 && cProto.updateStatsBarAndMaybeShowAnimation.length === 3) {
  8232.  
  8233. cProto.updateStatsBarAndMaybeShowAnimation38 = cProto.updateStatsBarAndMaybeShowAnimation;
  8234. cProto.updateStatsBarAndMaybeShowAnimation = dProto.updateStatsBarAndMaybeShowAnimationRevised;
  8235.  
  8236. flgLeakageFixApplied |= 2;
  8237. } else {
  8238. // the function is only in yt-live-chat-ticker-paid-message-item-renderer
  8239. }
  8240.  
  8241.  
  8242. // ------------- withTimerFn_ -------------
  8243.  
  8244. let withTimerFn_ = 0;
  8245. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  8246.  
  8247. // console.log('startCountdown', typeof cProto.startCountdown)
  8248. // console.log('updateTimeout', typeof cProto.updateTimeout)
  8249. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  8250.  
  8251. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  8252. const isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  8253. if (!isTimingFunctionHackable) console.log('isTimingFunctionHackable = false');
  8254. withTimerFn_ = isTimingFunctionHackable ? 2 : 1;
  8255. } else {
  8256. let flag = 0;
  8257. if (typeof cProto.startCountdown === 'function') flag |= 1;
  8258. if (typeof cProto.updateTimeout === 'function') flag |= 2;
  8259. if (typeof cProto.isAnimationPausedChanged === 'function') flag |= 4;
  8260.  
  8261. console.log(`Skip Timing Function Modification: ${flag} / ${1 + 2 + 4}`, ` ${tag}`);
  8262. // console.log(Object.getOwnPropertyNames(cProto))
  8263. // continue;
  8264. }
  8265. // ------------- withTimerFn_ -------------
  8266.  
  8267. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  8268.  
  8269. let urt = 0;
  8270.  
  8271. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  8272.  
  8273.  
  8274. /**
  8275. *
  8276. f.handlePauseReplay = function() {
  8277. this.isAnimationPaused = !0;
  8278. this.detlaSincePausedSecs = 0
  8279. }
  8280. */
  8281.  
  8282. /**
  8283. *
  8284. f.handlePauseReplay = function() {
  8285. this.isReplayPaused = !0
  8286. }
  8287. *
  8288. */
  8289.  
  8290. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  8291. const fi = fnIntegrity(cProto.handlePauseReplay);
  8292. urt++;
  8293. if (fi === '0.8.2' || fi === '0.12.4') {
  8294. } else {
  8295. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  8296. }
  8297. } else {
  8298. if (withTimerFn_ > 0) console.log('Error for setting cProto.handlePauseReplay', tag)
  8299. }
  8300.  
  8301. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handleResumeReplay.length === 0) {
  8302. urt++;
  8303. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  8304. } else {
  8305. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleResumeReplay', tag)
  8306. }
  8307.  
  8308. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  8309. urt++;
  8310. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  8311. } else {
  8312. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleReplayProgress', tag)
  8313. }
  8314.  
  8315.  
  8316.  
  8317. }
  8318.  
  8319. 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);
  8320. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  8321.  
  8322. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  8323.  
  8324. cProto.rtk = 0;
  8325. cProto.rtu = 0;
  8326. cProto.rtv = 0;
  8327.  
  8328. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  8329. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  8330.  
  8331. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  8332. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  8333.  
  8334. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  8335. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  8336.  
  8337. }
  8338.  
  8339. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  8340.  
  8341. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  8342.  
  8343. if (FIX_MEMORY_LEAKAGE_TICKER_TIMER) {
  8344. if (!USE_ADVANCED_TICKING && typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth55 && cProto.setContainerWidth.length === 0) {
  8345. cProto.setContainerWidth55 = cProto.setContainerWidth;
  8346. cProto.setContainerWidth = dProto.setContainerWidthNoSelfLeakage;
  8347. flgLeakageFixApplied |= 4;
  8348. }
  8349. if (!USE_ADVANCED_TICKING && typeof cProto.slideDown === 'function' && !cProto.slideDown55 && cProto.slideDown.length === 0) {
  8350. cProto.slideDown55 = cProto.slideDown;
  8351. cProto.slideDown = dProto.slideDownNoSelfLeakage;
  8352. flgLeakageFixApplied |= 8;
  8353. }
  8354. if (!USE_ADVANCED_TICKING && typeof cProto.collapse === 'function' && !cProto.collapse55 && cProto.collapse.length === 0) {
  8355. cProto.collapse55 = cProto.collapse;
  8356. cProto.collapse = dProto.collapseNoSelfLeakage;
  8357. flgLeakageFixApplied |= 16;
  8358. }
  8359. if (typeof cProto.deletedChanged === 'function' && !cProto.deletedChanged55 && cProto.deletedChanged.length === 0) {
  8360.  
  8361. cProto.deletedChanged55 = cProto.deletedChanged;
  8362. cProto.deletedChanged = dProto.deletedChangedNoSelfLeakage;
  8363. flgLeakageFixApplied |= 32;
  8364. }
  8365.  
  8366. }
  8367.  
  8368. console.log(`FIX_MEMORY_LEAKAGE_TICKER_: ${flgLeakageFixApplied} / ${1 + 2 + 4 + 8 + 16 + 32}`, cProto.is);
  8369.  
  8370. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  8371.  
  8372.  
  8373.  
  8374.  
  8375. if (withTimerFn_ > 0) {
  8376.  
  8377. const isTimingFunctionHackable = withTimerFn_ & 2;
  8378.  
  8379. let doAnimator_ = false;
  8380.  
  8381. let rafHackState = 0;
  8382. // continue;
  8383. if (ENABLE_RAF_HACK_TICKERS && rafHub !== null) {
  8384.  
  8385. // cancelable - this.rafId < isAnimationPausedChanged >
  8386. rafHackState = 1;
  8387.  
  8388. if (isTimingFunctionHackable) {
  8389. rafHackState = 2;
  8390.  
  8391. } else {
  8392. rafHackState = 4;
  8393. }
  8394.  
  8395. }
  8396. // continue;
  8397.  
  8398. doAnimator_ = !USE_ADVANCED_TICKING && !!ATTEMPT_ANIMATED_TICKER_BACKGROUND && isTimingFunctionHackable && typeof KeyframeEffect === 'function' && typeof animate === 'function' && typeof cProto.computeContainerStyle === 'function' && typeof cProto.colorFromDecimal === 'function' && isCSSPropertySupported();
  8399.  
  8400.  
  8401. const doAnimator = doAnimator_;
  8402.  
  8403. cProto._throwOut = dProto._throwOut;
  8404.  
  8405. cProto._makeAnimator = doAnimator ? dProto._makeAnimator : null;
  8406.  
  8407. cProto._aeFinished = doAnimator ? dProto._aeFinished : null;
  8408.  
  8409.  
  8410. const doRAFHack = rafHackState === 2;
  8411.  
  8412.  
  8413. const doTimerFnModification = !USE_ADVANCED_TICKING && (doRAFHack || doAnimator);
  8414. // doTimerFnModification = false; // M55
  8415.  
  8416. if (doTimerFnModification) { // including memory fix leakage
  8417.  
  8418. if (doAnimator && windowShownAt < 0) {
  8419. windowShownAt = 0;
  8420. setupEventForWindowShownAt();
  8421. }
  8422.  
  8423. cProto.startCountdown = (
  8424. doAnimator ? dProto.startCountdownForTimerFnModA : dProto.startCountdownForTimerFnModT
  8425. );
  8426.  
  8427. // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  8428. cProto.updateTimeout = (
  8429. doAnimator ? dProto.updateTimeoutForTimerFnModA : dProto.updateTimeoutForTimerFnModT
  8430. );
  8431.  
  8432.  
  8433. // let ez = 0;
  8434. cProto.isAnimationPausedChanged = (
  8435. doAnimator ? dProto.isAnimationPausedChangedForTimerFnModA : dProto.isAnimationPausedChangedForTimerFnModT
  8436. );
  8437.  
  8438. flgLeakageFixApplied |= 1;
  8439. }
  8440.  
  8441.  
  8442. if (doAnimator) {
  8443.  
  8444.  
  8445. const s = fnIntegrity(cProto.computeContainerStyle);
  8446.  
  8447. if (s === '2.46.29') {
  8448. // f.computeContainerStyle = function(a, b) {
  8449. // if (!a)
  8450. // return $h(kmb);
  8451. // var c = this.colorFromDecimal(a.startBackgroundColor);
  8452. // a = this.colorFromDecimal(a.endBackgroundColor);
  8453. // b = 100 * b + "%";
  8454. // return $h(lmb, c, c, b, a, b, a)
  8455. // }
  8456. } else if (s === '2.44.29' || s === '2.81.31') {
  8457.  
  8458. // var ofb = da([""])
  8459. // pfb = da("background:linear-gradient(90deg, {,{ {,{ {,{);".split("{"))
  8460.  
  8461. // f.computeContainerStyle = function(a, b) {
  8462. // if (!a)
  8463. // return pi(ofb);
  8464. // var c = this.colorFromDecimal(a.startBackgroundColor);
  8465. // a = this.colorFromDecimal(a.endBackgroundColor);
  8466. // b = 100 * b + "%";
  8467. // return pi(pfb, c, c, b, a, b, a)
  8468. // }
  8469.  
  8470. } else {
  8471. assertor(() => fnIntegrity(cProto.computeContainerStyle, '2.46.29'));
  8472. }
  8473.  
  8474. cProto.computeContainerStyle66 = cProto.computeContainerStyle;
  8475.  
  8476. cProto.computeContainerStyle = dProto.computeContainerStyleForAnimatorEnabled;
  8477.  
  8478. }
  8479.  
  8480. if (doTimerFnModification === true) hasTimerModified = true;
  8481.  
  8482.  
  8483. if (!!ATTEMPT_ANIMATED_TICKER_BACKGROUND) {
  8484. console.log('ATTEMPT_ANIMATED_TICKER_BACKGROUND', tag, doAnimator ? 'OK' : 'NG');
  8485. }
  8486.  
  8487.  
  8488. if (!doAnimator && (rafHackState === 2 || rafHackState === 4)) {
  8489. console.log('RAF_HACK_TICKERS', tag, doRAFHack ? "OK" : "NG");
  8490. }
  8491. }
  8492.  
  8493. const canDoAdvancedTicking = 1 &&
  8494. typeof cProto.startCountdown === 'function' && !cProto.startCountdown49 && cProto.startCountdown.length === 2 &&
  8495. typeof cProto.updateTimeout === 'function' && !cProto.updateTimeout49 && cProto.updateTimeout.length === 1 &&
  8496. typeof cProto.isAnimationPausedChanged === 'function' && !cProto.isAnimationPausedChanged49 && cProto.isAnimationPausedChanged.length === 2 &&
  8497. typeof cProto.setContainerWidth === 'function' && cProto.setContainerWidth.length === 0 &&
  8498. typeof cProto.slideDown === 'function' && cProto.slideDown.length === 0 &&
  8499. CSS.supports("left","clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)");
  8500.  
  8501.  
  8502. if (USE_ADVANCED_TICKING && canDoAdvancedTicking) {
  8503. // startResistanceUpdater();
  8504. // live replay video -> 48117005 -> 48117006 keep fire. ->48117007 0 -> 48117007 {...}
  8505. // live stream video -> 48117007 0 -> 48117007 YES
  8506.  
  8507. document.documentElement.setAttribute('r6-advanced-ticking', '');
  8508. console.log('USE_ADVANCED_TICKING')
  8509.  
  8510. const wio2 = dProto.wio2 || (dProto.wio2 = new IntersectionObserver((mutations) => {
  8511.  
  8512. for (const mutation of mutations) {
  8513. if (mutation.isIntersecting) {
  8514.  
  8515. const marker = mutation.target;
  8516. let endId = marker.id
  8517. if(!endId) continue;
  8518. let tid = endId.substring(0, endId.length -2 );
  8519. if(!tid) continue;
  8520. // let bId = `${tid}-b`;
  8521. const bgElm = document.querySelector(`#${tid}-b`);
  8522. if(!bgElm) continue;
  8523. const overlay = bgElm;
  8524.  
  8525. wio2.unobserve(marker);
  8526. marker.remove();
  8527. let p = overlay || 0;
  8528. let cn = 4;
  8529. while ((p = p.parentElement) instanceof HTMLElement) {
  8530. if (p instanceof HTMLElement) {
  8531. const cnt = insp(p);
  8532. if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1 ) {
  8533.  
  8534. cnt.__advancedTicking038__ = 2;
  8535.  
  8536. let deletionMode = false;
  8537. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  8538. if (timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__timestampActionRequest__ > 0) {
  8539.  
  8540. // time choose - 0.2s for transition (slideDown sliding-down)
  8541. // 60hz = 17ms
  8542. // choose 0.28s
  8543. const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  8544. // check whether the targetFutureTime is already the past
  8545. if (targetFutureTime + 280 < Date.now()) {
  8546. // just dispose
  8547. deletionMode = true;
  8548. }
  8549. } else if (!timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__progressAt__ > 0) {
  8550.  
  8551. const targetFutureTime = (cntData.__progressAt__ + cntData.durationSec) ;
  8552. // check whether the targetFutureTime is already the past
  8553. if (targetFutureTime + 0.28 < playerProgressChangedArg1) {
  8554. // just dispose
  8555. deletionMode = true;
  8556. }
  8557.  
  8558.  
  8559. }
  8560.  
  8561.  
  8562. if (deletionMode) {
  8563. __requestRemoval__(cnt);
  8564. } else {
  8565.  
  8566. const w = cnt.hostElement.style.width;
  8567. if (w === "auto" || w === "") cnt.setContainerWidth();
  8568. cnt.slideDown();
  8569. }
  8570.  
  8571. break;
  8572. }
  8573. }
  8574. cn--;
  8575. if (!cn) {
  8576. console.log('cnt not found for ticker-bg-overlay');
  8577. break;
  8578. }
  8579. }
  8580.  
  8581.  
  8582. }
  8583. }
  8584.  
  8585. // console.log(mutations);
  8586. },{
  8587.  
  8588. rootMargin: '0px',
  8589. threshold: [1]
  8590.  
  8591. }));
  8592.  
  8593. // const wio = dProto.wio || (dProto.wio = new IntersectionObserver((mutations) => {
  8594.  
  8595. // // for (const mutation of mutations) {
  8596. // // if (mutation.isIntersecting) {
  8597. // // const marker = mutation.target;
  8598. // // const overlay = marker instanceof HTMLElement ? marker.closest('ticker-bg-overlay') : 0;
  8599. // // wio.unobserve(marker);
  8600. // // marker.remove();
  8601. // // let p = overlay || 0;
  8602. // // let cn = 4;
  8603. // // while ((p = p.parentElement) instanceof HTMLElement) {
  8604. // // if (p instanceof HTMLElement) {
  8605. // // const cnt = insp(p);
  8606. // // if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1 ) {
  8607.  
  8608. // // cnt.__advancedTicking038__ = 2;
  8609.  
  8610. // // let deletionMode = false;
  8611. // // const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  8612. // // if (timestampUnderLiveMode && cntData && cntData.duration > 0 && cntData.__timestampActionRequest__ > 0) {
  8613.  
  8614. // // const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  8615. // // // check whether the targetFutureTime is already the past
  8616. // // if (targetFutureTime + 800 < Date.now()) {
  8617. // // // just dispose
  8618. // // deletionMode = true;
  8619. // // }
  8620. // // }
  8621.  
  8622. // // if (deletionMode) {
  8623. // // __requestRemoval__(cnt);
  8624. // // } else {
  8625.  
  8626. // // ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  8627. // // cnt.slideDown());
  8628. // // }
  8629.  
  8630. // // break;
  8631. // // }
  8632. // // }
  8633. // // cn--;
  8634. // // if (!cn) {
  8635. // // console.log('cnt not found for ticker-bg-overlay');
  8636. // // break;
  8637. // // }
  8638. // // }
  8639. // // }
  8640. // // }
  8641. // }, {
  8642. // rootMargin: '1px',
  8643. // threshold: [0]
  8644. // }));
  8645.  
  8646. // cProto._throwOut = dProto._throwOut;
  8647.  
  8648.  
  8649. const u37fn = dProto.u37fn || (dProto.u37fn = function (cnt) {
  8650.  
  8651. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  8652. if(!cntData) return;
  8653. const cntElement = cnt.hostElement;
  8654. if(!(cntElement instanceof HTMLElement)) return;
  8655.  
  8656. const duration = (cntData.fullDurationSec || cntData.durationSec || 0);
  8657.  
  8658. let ct;
  8659.  
  8660. if (cntData && duration > 0 && !('__progressAt__' in cntData)) {
  8661. ct = Date.now();
  8662. cntData.__liveTimestamp__ = (cntData.__timestampActionRequest__ || ct) / 1000 - timeOriginDT / 1000;
  8663. timestampUnderLiveMode = true;
  8664. } else if (cntData && duration > 0 && cntData.__progressAt__ > 0) {
  8665. timestampUnderLiveMode = false;
  8666. }
  8667. // console.log(48117007, cntData)
  8668.  
  8669. let tk = cntData.__progressAt__ || cntData.__liveTimestamp__;
  8670.  
  8671. if (!tk) {
  8672. console.log('time property is not found');
  8673. return;
  8674. }
  8675.  
  8676.  
  8677.  
  8678. const liveOffsetMs = ct > 0 && cntData.__timestampActionRequest__ > 0 ? ct - cntData.__timestampActionRequest__ : 0;
  8679.  
  8680. // console.log(1237, liveOffsetMs, cntData.durationSec)
  8681.  
  8682. if (liveOffsetMs > 0) {
  8683. cntData.durationSec -= Math.floor(liveOffsetMs / 1000);
  8684. if (cntData.durationSec < 0) cntData.durationSec = 0;
  8685. // console.log(1238, liveOffsetMs, cntData.durationSec)
  8686. if (!cntData.durationSec) {
  8687. try {
  8688. cnt.requestRemoval();
  8689. } catch (e) { }
  8690. return;
  8691. }
  8692. }
  8693.  
  8694.  
  8695. let offset = cntData.fullDurationSec - cntData.durationSec; // consider this is live replay video, offset can be > 0
  8696. if (offset > 0) tk -= offset;
  8697. // in livestreaming. tk can be negative as we use performance.timeOrigin for t=0s time frame
  8698.  
  8699.  
  8700.  
  8701. const existingOverlaySelector = `ticker-bg-overlay[ticker-id="${cnt.__ticker_attachmentId__}"]`;
  8702.  
  8703. if (valAssign(cntElement, '--ticker-start-time', tk) && duration > 0) {
  8704.  
  8705. // t0 ...... 1 ... fullDurationSec
  8706. // tk ...... k ... fullDurationSec-durationSec
  8707. // t0-fullDurationSec ...... 0 ... 0
  8708.  
  8709. // now - (fullDurationSec-durationSec)
  8710.  
  8711.  
  8712. // update dntElementWeak
  8713. const dnt = cnt.parentComponent;
  8714. const dntElement = dnt ? dnt.hostElement || dnt : 0;
  8715. if (dntElement) {
  8716. dntElementWeak = mWeakRef(dntElement);
  8717. resistanceUpdateBusy = false;
  8718. if (!startResistanceUpdaterStarted) startResistanceUpdater();
  8719. else updateTickerCurrentTime();
  8720. }
  8721.  
  8722. // create overlay if needed
  8723. if (!cntElement.querySelector(existingOverlaySelector)) {
  8724.  
  8725. // remove if any
  8726. const oldElement = cntElement.querySelector('ticker-bg-overlay');
  8727. if (oldElement) oldElement.remove();
  8728. // use advancedTicking, ticker enabled
  8729. cnt.__advancedTicking038__ = 1;
  8730.  
  8731. const em = document.createElement('ticker-bg-overlay');
  8732. // const ey = document.createElement('ticker-bg-overlay-end');
  8733. const wy = document.createElement('ticker-bg-overlay-end2');
  8734.  
  8735. const cr1 = cnt.colorFromDecimal(cntData.startBackgroundColor);
  8736. const cr2 = cnt.colorFromDecimal(cntData.endBackgroundColor);
  8737.  
  8738. const container = cnt.$.container;
  8739. em.setAttribute('ticker-id', `${cnt.__ticker_attachmentId__}`);
  8740.  
  8741. const tid = `ticker-${cnt.__ticker_attachmentId__}-${ Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  8742.  
  8743. em.id = `${tid}-b`;
  8744. em.style.background = `linear-gradient(90deg, ${cr1},${cr1} 50%,${cr2} 50%,${cr2})`;
  8745.  
  8746. if (!(container instanceof HTMLElement)) {
  8747. // em.insertBefore(ey, em.firstChild);
  8748. cntElement.insertBefore(em, cntElement.firstChild);
  8749. cntElement.style.borderRadius = '16px';
  8750. container.style.borderRadius = 'initial';
  8751. } else {
  8752. // em.insertBefore(ey, em.firstChild);
  8753. container.insertBefore(em, container.firstChild);
  8754. }
  8755.  
  8756. // em.style.left = '-50%';
  8757. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  8758.  
  8759. if (container instanceof HTMLElement) {
  8760.  
  8761. container.style.background = 'transparent';
  8762. container.style.backgroundColor = 'transparent';
  8763. // container.style.zIndex = '1';
  8764. }
  8765. // em.style.zIndex = '-1';
  8766. valAssign(cntElement, '--ticker-duration-time', duration)
  8767.  
  8768. valAssign(wy, '--ticker-start-time', tk);
  8769. valAssign(wy, '--ticker-duration-time', duration);
  8770. wy.id = `${tid}-e`;
  8771.  
  8772. dntElement.appendChild(wy);
  8773.  
  8774. // if (wio instanceof IntersectionObserver) {
  8775. // wio.observe(ey);
  8776. // }
  8777.  
  8778. if (wio2 instanceof IntersectionObserver) {
  8779. wio2.observe(wy);
  8780. }
  8781.  
  8782. }
  8783. }
  8784. });
  8785.  
  8786. const timeFn = (cnt)=>{
  8787.  
  8788. if (!cnt) return;
  8789. if (!cnt.hostElement) return;
  8790.  
  8791. const attachementId = cnt.__ticker_attachmentId__;
  8792. if (!attachementId) return;
  8793.  
  8794. Promise.resolve(cnt).then(u37fn);
  8795.  
  8796. }
  8797.  
  8798. cProto.startCountdown = dProto.startCountdownAdv || (dProto.startCountdownAdv = function (a, b) {
  8799.  
  8800. timeFn(kRef(this));
  8801.  
  8802. // try {
  8803. // const cnt = kRef(this);
  8804. // if (!cnt) return;
  8805. // if (!cnt.hostElement) return;
  8806.  
  8807. // const attachementId = cnt.__ticker_attachmentId__;
  8808. // if (!attachementId) return;
  8809.  
  8810. // // a.durationSec [s] => countdownMs [ms]
  8811. // // a.fullDurationSec [s] => countdownDurationMs [ms] OR countdownMs [ms]
  8812. // // lastCountdownTimeMs => raf ongoing
  8813. // // lastCountdownTimeMs = 0 when rafId = 0 OR countdownDurationMs = 0
  8814.  
  8815. // // if (cnt._r782) return;
  8816.  
  8817. // // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  8818. // // cnt._throwOut();
  8819. // // return;
  8820. // // }
  8821.  
  8822. // // TimerFnModT
  8823.  
  8824. // // b = void 0 === b ? 0 : b;
  8825. // // void 0 !== a && (cnt.countdownMs = 1E3 * a,
  8826. // // cnt.countdownDurationMs = b ? 1E3 * b : cnt.countdownMs,
  8827. // // // cnt.ratio = 1,
  8828. // // cnt.lastCountdownTimeMs || cnt.isAnimationPaused || (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = performance.now(),
  8829. // // cnt.rafId = -1))
  8830.  
  8831. // Promise.resolve(cnt).then((cnt) => {
  8832. // u37fn(cnt);
  8833. // })
  8834.  
  8835. // } catch (e) {
  8836. // console.warn(e);
  8837. // }
  8838.  
  8839.  
  8840. });
  8841.  
  8842. cProto.updateTimeout = dProto.updateTimeoutAdv || (dProto.updateTimeoutAdv = function (a) {
  8843.  
  8844.  
  8845. // timeFn(kRef(this));
  8846.  
  8847. // try {
  8848. // const cnt = kRef(this);
  8849. // if (!cnt) return;
  8850. // if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8851.  
  8852. // const attachementId = cnt.__ticker_attachmentId__;
  8853. // if (!attachementId) return;
  8854.  
  8855. // // _lastCountdownTimeMsX0 is required since performance.now() is not fully the same with rAF timestamp
  8856.  
  8857. // // if (cnt._r782) return;
  8858.  
  8859. // // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  8860. // // cnt._throwOut();
  8861. // // return;
  8862. // // }
  8863.  
  8864. // // if (cnt.lastCountdownTimeMs !== cnt._lastCountdownTimeMsX0) {
  8865. // // cnt.countdownMs = Math.max(0, cnt.countdownMs - (a - (cnt.lastCountdownTimeMs || 0)));
  8866. // // }
  8867. // // console.log(703, cnt.countdownMs)
  8868. // // cnt.ratio = cnt.countdownMs / cnt.countdownDurationMs;
  8869.  
  8870. // // u37fn(cnt);
  8871. // // cnt.isAttached && cnt.countdownMs ? (cnt.lastCountdownTimeMs = a,
  8872. // // cnt.rafId = -1) : (cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = null,
  8873. // // cnt.isAttached && ("auto" === cnt.hostElement.style.width && cnt.setContainerWidth(),
  8874. // // cnt.slideDown()))
  8875.  
  8876.  
  8877. // } catch (e) {
  8878. // console.warn(e);
  8879. // }
  8880.  
  8881. });
  8882.  
  8883. cProto.isAnimationPausedChanged = dProto.isAnimationPausedChangedAdv || (dProto.isAnimationPausedChangedAdv = function (a, b) {
  8884.  
  8885.  
  8886. // timeFn(kRef(this));
  8887.  
  8888. // const cnt = kRef(this);
  8889. // if (!cnt) return;
  8890. // if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8891.  
  8892. // const attachementId = cnt.__ticker_attachmentId__;
  8893. // if (!attachementId) return;
  8894.  
  8895. // if (cnt._r782) return;
  8896.  
  8897. // if (cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false) {
  8898. // cnt._throwOut();
  8899. // return;
  8900. // }
  8901. // let forceNoDetlaSincePausedSecs783 = cnt._forceNoDetlaSincePausedSecs783;
  8902. // cnt._forceNoDetlaSincePausedSecs783 = 0;
  8903.  
  8904. // u37fn(cnt);
  8905. // Promise.resolve(cnt).then((cnt) => {
  8906.  
  8907. // if (attachementId !== cnt.__ticker_attachmentId__) return;
  8908.  
  8909. // // a ? 0 : !a && b && (a = cnt.lastCountdownTimeMs || 0,
  8910. // // cnt.detlaSincePausedSecs && (a = (cnt.lastCountdownTimeMs || 0) + 1E3 * cnt.detlaSincePausedSecs,
  8911. // // cnt.detlaSincePausedSecs = 0),
  8912. // // cnt.lastCountdownTimeMs = cnt._lastCountdownTimeMsX0 = window.performance.now())
  8913.  
  8914. // cnt = null;
  8915.  
  8916. // }).catch(e => {
  8917. // console.log(e);
  8918. // });
  8919.  
  8920.  
  8921. });
  8922.  
  8923. if (typeof cProto.slideDown === 'function' && !cProto.slideDown43 && cProto.slideDown.length === 0) {
  8924.  
  8925. cProto.slideDown43 = cProto.slideDown;
  8926. cProto.slideDown = dProto.slideDownAdv || (dProto.slideDownAdv = async function () {
  8927.  
  8928. // console.log('calling slideDown', Date.now())
  8929. if(this.__advancedTicking038__){
  8930.  
  8931. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  8932.  
  8933.  
  8934. const hostElement = this.hostElement;
  8935. const container = this.$.container;
  8936. if (hostElement instanceof HTMLElement && container instanceof HTMLElement) {
  8937. // const prevTransitionClosingElm = kRef(prevTransitionClosing);
  8938. // if (prevTransitionClosingElm !== hostElement) {
  8939. // prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  8940. // prevTransitionClosing = mWeakRef(hostElement);
  8941. // }
  8942. // if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  8943. hostElement.classList.add('r6-closing-ticker');
  8944. const pr = new PromiseExternal();
  8945. transitionEndAfterFnSimple.set(hostElement, pr);
  8946. transitionEndAfterFnSimple.set(container, pr);
  8947. hostElement.classList.add("sliding-down");
  8948. await pr.then();
  8949. transitionEndAfterFnSimple.delete(hostElement);
  8950. transitionEndAfterFnSimple.delete(container);
  8951. if(this && this.hostElement instanceof HTMLElement){
  8952. this.collapse();
  8953. }
  8954. return;
  8955. }
  8956. }
  8957. this.slideDown43();
  8958. });
  8959. }
  8960.  
  8961.  
  8962. if (typeof cProto.collapse === 'function' && !cProto.collapse43 && cProto.collapse.length === 0) {
  8963. cProto.collapse43 = cProto.collapse;
  8964. cProto.collapse = dProto.collapseAdv || (dProto.collapseAdv = async function () {
  8965.  
  8966.  
  8967. if (this.__advancedTicking038__) {
  8968.  
  8969. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  8970.  
  8971.  
  8972. const hostElement = this.hostElement;
  8973. const container = this.$.container;
  8974. if (hostElement instanceof HTMLElement && container instanceof HTMLElement) {
  8975. // const prevTransitionClosingElm = kRef(prevTransitionClosing);
  8976. // if (prevTransitionClosingElm !== hostElement) {
  8977. // prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  8978. // prevTransitionClosing = mWeakRef(hostElement);
  8979. // }
  8980. // if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  8981. hostElement.classList.add('r6-closing-ticker');
  8982.  
  8983. const pr = new PromiseExternal();
  8984. transitionEndAfterFnSimple.set(hostElement, pr);
  8985. transitionEndAfterFnSimple.set(container, pr);
  8986. hostElement.classList.add("collapsing");
  8987. hostElement.style.width = "0";
  8988. await pr.then();
  8989. transitionEndAfterFnSimple.delete(hostElement);
  8990. transitionEndAfterFnSimple.delete(container);
  8991. if (this && this.hostElement instanceof HTMLElement) {
  8992.  
  8993. this.requestRemoval();
  8994. }
  8995.  
  8996. return;
  8997. }
  8998.  
  8999.  
  9000. }
  9001. this.collapse43();
  9002.  
  9003.  
  9004. });
  9005. }
  9006.  
  9007. if (typeof cProto.requestRemoval === 'function' && !cProto.requestRemoval49 && cProto.requestRemoval.length === 0) {
  9008. cProto.requestRemoval49 = cProto.requestRemoval;
  9009. cProto.requestRemoval = dProto.requestRemovalAdv || (dProto.requestRemovalAdv = function () {
  9010. if (this.__advancedTicking038__) {
  9011. try {
  9012. const overlayBg = this.hostElement.querySelector('ticker-bg-overlay[id]');
  9013. if (overlayBg) {
  9014. const overlayBgId = overlayBg.id;
  9015. const tid = overlayBgId ? overlayBgId.substring(0, overlayBgId.length - 2) : '';
  9016. const endElm = tid ? document.querySelector(`#${tid}-e`) : null;
  9017. if (endElm) {
  9018. wio2.unobserve(endElm);
  9019. endElm.remove();
  9020. }
  9021. }
  9022. } catch (e) { }
  9023. this.__advancedTicking038__ = 2;
  9024. }
  9025. const hostElement = this.hostElement;
  9026. if (hostElement instanceof HTMLElement) {
  9027. // try {
  9028. // // hostElement.remove();
  9029. // if (!hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.add('ticker-no-transition-time');
  9030. // } catch (e) { }
  9031.  
  9032. try{
  9033.  
  9034. hostElement.classList.remove('r6-closing-ticker');
  9035. } catch (e) { }
  9036.  
  9037. return this.requestRemoval49();
  9038. }
  9039. });
  9040. }
  9041.  
  9042. if (typeof cProto.computeContainerStyle === 'function' && !cProto.computeContainerStyle49 && cProto.computeContainerStyle.length === 2) {
  9043. cProto.computeContainerStyle49 = cProto.computeContainerStyle;
  9044. cProto.computeContainerStyle = dProto.computeContainerStyleAdv || (dProto.computeContainerStyleAdv = function (a, b) {
  9045. if (this.__advancedTicking038__) {
  9046. return "";
  9047. }
  9048. return this.computeContainerStyle49(a, b);
  9049. });
  9050. }
  9051.  
  9052.  
  9053.  
  9054. if (typeof cProto.setRevampContainerWidth === 'function' && !cProto.setRevampContainerWidth41 && cProto.setRevampContainerWidth.length === 0) {
  9055. cProto.setRevampContainerWidth41 = cProto.setRevampContainerWidth;
  9056. cProto.setRevampContainerWidth = dProto.setRevampContainerWidthAdv || (dProto.setRevampContainerWidthAdv = async function () {
  9057.  
  9058. // not sure the reason for auto instead of pixel.
  9059. // this is a new function in Dec 2024, but not mainly adopted in the coding yet
  9060.  
  9061. /*
  9062. var a = this;
  9063. (R(this.hostElement).querySelector("#container").clientWidth || 0) === 0 ? (this.hostElement.style.overflow = "visible",
  9064. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  9065. this.ytLiveChatTickerItemBehavior.shouldAnimateIn ? (this.hostElement.style.width = "0",
  9066. Zu(function() {
  9067. a.hostElement.style.width = "auto"
  9068. }, 1)) : this.hostElement.style.width = "auto")
  9069. */
  9070.  
  9071.  
  9072.  
  9073.  
  9074. const hostElement = (this || 0).hostElement;
  9075. const container = this.$.container;
  9076.  
  9077.  
  9078. let qw = null;
  9079.  
  9080. {
  9081.  
  9082.  
  9083. let maxC = 4;
  9084.  
  9085. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  9086.  
  9087. const ed = `${hostElement.id}`
  9088. if (!p || !p.startsWith(`${ed}::`)) {
  9089.  
  9090. const w = hostElement.style.width;
  9091. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  9092.  
  9093. const res = await widthReq(container);
  9094.  
  9095. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  9096.  
  9097. } else {
  9098. qw = p.split('::');
  9099. break;
  9100. }
  9101.  
  9102. }
  9103.  
  9104. }
  9105.  
  9106. if (!qw) {
  9107.  
  9108. console.log('container width failure');
  9109. this.setRevampContainerWidth41();
  9110. return; // failure
  9111. }
  9112.  
  9113.  
  9114. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  9115. if (shouldAnimateIn) {
  9116.  
  9117.  
  9118.  
  9119. const w = hostElement.style.width;
  9120. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  9121. // hostElement.classList.remove('ticker-no-transition-time');
  9122. await widthReq(container);
  9123.  
  9124. hostElement.style.width = `${qw[1]}px`;
  9125. return;
  9126.  
  9127.  
  9128. } else {
  9129. hostElement.style.width = `${qw[1]}px`;
  9130. }
  9131.  
  9132.  
  9133. // const container = this.$.container;
  9134. // if(hostElement instanceof HTMLElement && hostElement.style.width) hostElement.style.width = '';
  9135. });
  9136. }
  9137.  
  9138.  
  9139. if (typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth41 && cProto.setContainerWidth.length === 0) {
  9140. cProto.setContainerWidth41 = cProto.setContainerWidth;
  9141. cProto.setContainerWidth = dProto.setContainerWidthAdv || (dProto.setContainerWidthAdv = async function () {
  9142.  
  9143.  
  9144. /*
  9145.  
  9146.  
  9147. var a = this
  9148. , b = R(this.hostElement).querySelector("#container").clientWidth || 0;
  9149. b === 0 ? (this.hostElement.style.overflow = "visible",
  9150. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  9151. this.shouldAnimateIn ? (this.hostElement.style.width = "0",
  9152. Zu(function() {
  9153. a.hostElement.style.width = b + "px"
  9154. }, 1)) : this.hostElement.style.width = b + "px")
  9155.  
  9156. */
  9157.  
  9158. const hostElement = (this || 0).hostElement;
  9159. const container = this.$.container;
  9160.  
  9161. let qw = null;
  9162. {
  9163.  
  9164.  
  9165. let maxC = 4;
  9166.  
  9167. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  9168. const ed = `${hostElement.id}`
  9169. if (!p || !p.startsWith(`${ed}::`)) {
  9170. const w = hostElement.style.width;
  9171. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  9172. const res = await widthReq(container);
  9173. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  9174. } else {
  9175. qw = p.split('::');
  9176. break;
  9177. }
  9178. }
  9179.  
  9180. }
  9181.  
  9182. if(!qw){
  9183.  
  9184. console.log('container width failure');
  9185. this.setContainerWidth41();
  9186. return; // failure
  9187. }
  9188.  
  9189.  
  9190. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  9191. if (shouldAnimateIn) {
  9192.  
  9193.  
  9194.  
  9195. const w = hostElement.style.width;
  9196. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  9197. // hostElement.classList.remove('ticker-no-transition-time');
  9198. await widthReq(container);
  9199.  
  9200. hostElement.style.width = `${qw[1]}px`;
  9201. return;
  9202.  
  9203.  
  9204. } else {
  9205. hostElement.style.width = `${qw[1]}px`;
  9206. }
  9207.  
  9208. });
  9209. }
  9210.  
  9211.  
  9212.  
  9213.  
  9214. }
  9215.  
  9216.  
  9217.  
  9218. }
  9219.  
  9220. const selector = tags.join(', ');
  9221. const elements = document.querySelectorAll(selector);
  9222. if (elements.length >= 1) {
  9223. for (const elm of elements) {
  9224. if (insp(elm).isAttached === true) {
  9225. fpTicker(elm);
  9226. }
  9227. }
  9228. }
  9229.  
  9230. console.log("[End]");
  9231. console.groupEnd();
  9232.  
  9233.  
  9234. }).catch(console.warn);
  9235.  
  9236. if(FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth){
  9237.  
  9238. /**
  9239. *
  9240. *
  9241. *
  9242. *
  9243. cT.prototype.dataChanged = function() {
  9244. var a = this;
  9245. this.data && (Q(this.hostElement).querySelector("#content").style.color = this.ytLiveChatTickerItemBehavior.colorFromDecimal(this.data.detailTextColor),
  9246. this.hostElement.ariaLabel = this.computeAriaLabel(this.data),
  9247. this.ytLiveChatTickerItemBehavior.startCountdown(this.data.durationSec, this.data.fullDurationSec),
  9248. qw(function() {
  9249. a.ytLiveChatTickerItemBehavior.setContainerWidth()
  9250. }))
  9251. }
  9252.  
  9253.  
  9254. znb.prototype.dataChanged = function(a) {
  9255. var b = this;
  9256. a && (a.tickerThumbnails.length > 1 && Q(this.hostElement).querySelector("#content").classList.add("multiple-thumbnails"),
  9257. this.ytLiveChatTickerItemBehavior.startCountdown(a.durationSec, a.fullDurationSec),
  9258. qw(function() {
  9259. b.ytLiveChatTickerItemBehavior.setContainerWidth()
  9260. }))
  9261. }
  9262.  
  9263. *
  9264. */
  9265.  
  9266. const dProto = {
  9267. dataChanged54500: function () {
  9268. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  9269. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  9270. try {
  9271. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  9272. return this.dataChanged544.call(this.__proxySelf0__);
  9273. } catch (e) {
  9274. console.log('dataChanged54500 ERROR');
  9275. console.error(e);
  9276. }
  9277. } else {
  9278. return this.dataChanged544();
  9279. }
  9280. },
  9281. dataChanged54501: function (a) {
  9282. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  9283. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  9284. try {
  9285. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  9286. return this.dataChanged544.call(this.__proxySelf0__, a);
  9287. } catch (e) {
  9288. console.log('dataChanged54501 ERROR');
  9289. console.error(e);
  9290. }
  9291. } else {
  9292. return this.dataChanged544(a);
  9293. }
  9294. },
  9295. }
  9296.  
  9297. for (const sto of [
  9298. 'yt-live-chat-ticker-sponsor-item-renderer',
  9299. 'yt-live-chat-ticker-paid-sticker-item-renderer'
  9300. ].map(tag => [tag, customElements.whenDefined(tag)])) {
  9301. const [tag, promise] = sto;
  9302. promise.then(()=>{
  9303. const dummy = document.createElement(tag);
  9304. const cProto = getProto(dummy);
  9305. if (!cProto || !cProto.attached) {
  9306. console.warn(`proto.attached for ${tag} is unavailable.`);
  9307. return;
  9308. }
  9309. if (!cProto.dataChanged || cProto.dataChanged544 || typeof cProto.dataChanged !== 'function' || !(cProto.dataChanged.length >= 0 && cProto.dataChanged.length <= 1)) return;
  9310.  
  9311. cProto.dataChanged544 = cProto.dataChanged;
  9312.  
  9313. if (cProto.dataChanged.length === 0) cProto.dataChanged = dProto.dataChanged54500;
  9314. else if (cProto.dataChanged.length === 1) cProto.dataChanged = dProto.dataChanged54501;
  9315. })
  9316. }
  9317.  
  9318. }
  9319.  
  9320. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  9321.  
  9322. if (FLAG_001d) return;
  9323.  
  9324. mightFirstCheckOnYtInit();
  9325. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  9326. console.log("[Begin]");
  9327. (() => {
  9328.  
  9329. /* pending!!
  9330.  
  9331. handleLiveChatAction
  9332.  
  9333. removeTickerItemById
  9334.  
  9335. _itemsChanged
  9336. itemsChanged
  9337.  
  9338. handleMarkChatItemAsDeletedAction
  9339. handleMarkChatItemsByAuthorAsDeletedAction
  9340. handleRemoveChatItemByAuthorAction
  9341.  
  9342.  
  9343. */
  9344.  
  9345. const tag = "yt-live-chat-ticker-renderer"
  9346. const dummy = document.createElement(tag);
  9347.  
  9348. const cProto = getProto(dummy);
  9349. if (!cProto || !cProto.attached) {
  9350. console.warn(`proto.attached for ${tag} is unavailable.`);
  9351. return;
  9352. }
  9353.  
  9354. const do_amend_ticker_handleLiveChatAction = AMEND_TICKER_handleLiveChatAction && !AMEND_TICKER_handleLiveChatAction_v3
  9355. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && cProto.handleLiveChatAction.length === 1
  9356. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && cProto.handleLiveChatActions.length === 1
  9357. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  9358. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  9359. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  9360. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  9361. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  9362. ;
  9363.  
  9364. console.log('do_amend_ticker_handleLiveChatAction', fnIntegrity(cProto.handleLiveChatAction), fnIntegrity(cProto.handleLiveChatActions))
  9365.  
  9366.  
  9367. if (do_amend_ticker_handleLiveChatAction) {
  9368.  
  9369.  
  9370. if (fnIntegrity(cProto.handleLiveChatActions) === '1.23.12') {
  9371.  
  9372. console.log(`handleLiveChatActions`, 'modified');
  9373.  
  9374. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  9375.  
  9376. cProto.handleLiveChatActions = function (a) {
  9377. /**
  9378. *
  9379. f.handleLiveChatActions = function(a) {
  9380. a.length && (a.forEach(this.handleLiveChatAction, this),
  9381. this.updateHighlightedItem(),
  9382. this.shouldAnimateIn = !0)
  9383. }
  9384. *
  9385. */
  9386. const len = a.length;
  9387. if (len) {
  9388. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  9389.  
  9390. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  9391.  
  9392. // Primarily for the initial batch, this is due to replayBuffer._back.
  9393. const entries = [];
  9394. const entriesI = [];
  9395. for (let i = 0; i < len; i++) {
  9396. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  9397. const timestampUsec = item ? parseInt(getTimestampUsec(item[firstObjectKey(item)]), 10) : 0;
  9398. if (timestampUsec > 0) {
  9399. entriesI.push(i);
  9400. binaryInsert(entries, { e: a[i], timestampUsec }, (a, b) => {
  9401. const diff = a.timestampUsec - b.timestampUsec;
  9402. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  9403. });
  9404. }
  9405. }
  9406. const mLen = entries.length;
  9407. if (mLen >= 2) {
  9408. for (let j = 0; j < mLen; j++) {
  9409. a[entriesI[j]] = entries[j].e;
  9410. }
  9411. }
  9412. entries.length = 0;
  9413. entriesI.length = 0;
  9414. }
  9415. for (const action of a) {
  9416. action.__batchId45__ = batchToken;
  9417. this.handleLiveChatAction(action);
  9418. }
  9419. }
  9420. }
  9421.  
  9422.  
  9423. }
  9424.  
  9425.  
  9426. console.log(`handleLiveChatAction`, 'modified');
  9427.  
  9428. const cacheChatActions = new LimitedSizeSet(16);
  9429.  
  9430. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  9431.  
  9432. cProto.handleLiveChatAction = function (a) {
  9433.  
  9434. const key = firstObjectKey(a);
  9435. if (!key) return;
  9436.  
  9437. const val = a[key];
  9438. let itemKey = '';
  9439. let itemId = '';
  9440. const valItem = val ? val.item : null;
  9441. if (valItem) {
  9442. itemKey = firstObjectKey(valItem);
  9443. if (itemKey) {
  9444. const itemVal = valItem[itemKey];
  9445. itemId = itemVal ? itemVal.id : '';
  9446. if (itemId) {
  9447. const cacheKey = `${key}.${itemKey}::${itemId}`;
  9448. if (key === 'addChatItemAction' && itemId) return; // no need
  9449. if (cacheChatActions.has(cacheKey)) {
  9450. console.log('handleLiveChatAction Repeated Item', cacheKey);
  9451. return;
  9452. } else {
  9453. cacheChatActions.add(cacheKey);
  9454. }
  9455. }
  9456. }
  9457. }
  9458. return this.handleLiveChatAction45(a);
  9459. };
  9460.  
  9461. console.log("AMEND_TICKER_handleLiveChatAction - OK (v2)");
  9462.  
  9463. } else if (0 && do_amend_ticker_handleLiveChatAction
  9464. && '|1.63.48|1.64.48|'.includes(`|${fnIntegrity(cProto.handleLiveChatAction)}|`)
  9465. && fnIntegrity(cProto.handleLiveChatActions) === '1.23.12'
  9466. ) {
  9467.  
  9468. cProto.handleLiveChatActions45 = cProto.handleLiveChatActions;
  9469.  
  9470. cProto.handleLiveChatActions = function (a) {
  9471. /**
  9472. *
  9473. f.handleLiveChatActions = function(a) {
  9474. a.length && (a.forEach(this.handleLiveChatAction, this),
  9475. this.updateHighlightedItem(),
  9476. this.shouldAnimateIn = !0)
  9477. }
  9478. *
  9479. */
  9480.  
  9481. if (a.length) {
  9482. const batchToken = String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  9483. const len = a.length;
  9484. if (FIX_BATCH_TICKER_ORDER && len >= 2) {
  9485. // Primarily for the initial batch, this is due to replayBuffer._back.
  9486. const entries = [];
  9487. const entriesI = [];
  9488. for (let i = 0; i < len; i++) {
  9489. const item = ((a[i] || 0).addLiveChatTickerItemAction || 0).item || 0;
  9490. if (item) {
  9491. const itemRendererKey = firstObjectKey(item);
  9492. const itemRenderer = item[itemRendererKey];
  9493. if (itemRenderer) {
  9494. let timestampUsec = getTimestampUsec(itemRenderer);
  9495. if (timestampUsec !== null) {
  9496. timestampUsec = parseInt(timestampUsec, 10);
  9497. if (timestampUsec > 0) {
  9498. entriesI.push(i);
  9499. entries.push({ e: a[i], timestampUsec })
  9500. }
  9501. }
  9502. }
  9503. }
  9504. }
  9505. const mLen = entries.length;
  9506. if (mLen >= 2) {
  9507. entries.sort((a, b) => {
  9508. const diff = a.timestampUsec - b.timestampUsec;
  9509. return diff > 0.1 ? 1 : diff < -0.1 ? -1 : 0;
  9510. });
  9511. for (let j = 0; j < mLen; j++) {
  9512. const i = entriesI[j];
  9513. a[i] = entries[j].e;
  9514. }
  9515. }
  9516. entries.length = 0;
  9517. entriesI.length = 0;
  9518. }
  9519. for (const action of a) {
  9520. action.__batchId45__ = batchToken;
  9521. this.handleLiveChatAction(action);
  9522. }
  9523. }
  9524. }
  9525.  
  9526. cProto.handleLiveChatAction45 = cProto.handleLiveChatAction;
  9527.  
  9528. cProto._nszlv_ = 0;
  9529. cProto._stackedLCAs_ = null;
  9530. cProto._lastAddItem_ = null;
  9531. cProto._lastAddItemInStack_ = false;
  9532. cProto.handleLiveChatAction = function (a) {
  9533.  
  9534. /**
  9535. *
  9536. *
  9537. f.handleLiveChatAction = function(a) {
  9538. var b = C(a, xO)
  9539. , c = C(a, yO)
  9540. , d = C(a, o1a)
  9541. , e = C(a, p1a);
  9542. a = C(a, A1a);
  9543. b ? this.unshift("items", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : a && this.handleRemoveChatItemByAuthorAction(a)
  9544. }
  9545. *
  9546. */
  9547.  
  9548. // return this.handleLiveChatAction45(a)
  9549. const { addChatItemAction, addLiveChatTickerItemAction, markChatItemAsDeletedAction,
  9550. removeChatItemAction, markChatItemsByAuthorAsDeletedAction, removeChatItemByAuthorAction, __batchId45__ } = a
  9551.  
  9552. if (addChatItemAction) return;
  9553. const d = Date.now();
  9554.  
  9555. if (this._stackedLCAs_ === null) this._stackedLCAs_ = [];
  9556. const stackArr = this._stackedLCAs_;
  9557. let newStackEntry = null;
  9558. if (addLiveChatTickerItemAction) {
  9559. let isDuplicated = false;
  9560.  
  9561. const newItem = addLiveChatTickerItemAction.item;
  9562. const tickerType = firstObjectKey(newItem);
  9563. if (!tickerType) return;
  9564. const tickerItem = newItem[tickerType];
  9565. const tickerId = tickerItem.id;
  9566. if (!tickerId) return;
  9567.  
  9568. if (this._lastAddItem_ && this._lastAddItem_.id === tickerId) {
  9569. let prevTickerItem = null;
  9570. if (this._lastAddItemInStack_) {
  9571. const entry = stackArr[stackArr.length - 1]; // only consider the last entry
  9572. if (entry && entry.action === 'addItem') {
  9573. prevTickerItem = entry.data; // only consider the first item;
  9574. }
  9575. } else {
  9576. prevTickerItem = this.items[0]; // only consider the first item;
  9577. }
  9578. if (prevTickerItem && prevTickerItem[tickerType]) {
  9579. if (prevTickerItem[tickerType].id === tickerId) {
  9580. isDuplicated = true;
  9581. }
  9582. }
  9583. }
  9584. if (!isDuplicated) {
  9585. this._lastAddItem_ = tickerItem;
  9586. this._lastAddItemInStack_ = true;
  9587. // console.log('newItem', newItem)
  9588.  
  9589. const item = newItem;
  9590. const key = firstObjectKey(item);
  9591. if (key) {
  9592. const itemRenderer = item[key] || 0;
  9593. if (itemRenderer.fullDurationSec > 0) {
  9594. itemRenderer.__actionAt__ = d;
  9595. }
  9596. }
  9597.  
  9598. newStackEntry = { action: 'addItem', data: newItem };
  9599.  
  9600. } else {
  9601. console.log('handleLiveChatAction Repeated Item', tickerItem.id, tickerItem); // happen in both live and playback. Reason Unknown.
  9602. return;
  9603. }
  9604.  
  9605. } else {
  9606. markChatItemAsDeletedAction && (newStackEntry = { action: 'mcItemD', data: markChatItemAsDeletedAction });
  9607. removeChatItemAction && (newStackEntry = { action: 'removeItemById', data: removeChatItemAction.targetId });
  9608. markChatItemsByAuthorAsDeletedAction && (newStackEntry = { action: 'mcItemAD', data: markChatItemsByAuthorAsDeletedAction });
  9609. removeChatItemByAuthorAction && (newStackEntry = { action: 'removeItemA', data: removeChatItemByAuthorAction })
  9610. }
  9611.  
  9612.  
  9613. if (!newStackEntry) return;
  9614. stackArr.push(newStackEntry);
  9615.  
  9616.  
  9617. this._nszlv_++;
  9618. if (this._nszlv_ > 1e9) this._nszlv_ = 9;
  9619. const tid = this._nszlv_;
  9620.  
  9621. newStackEntry.__batchId45__ = __batchId45__ || '';
  9622. newStackEntry.dateTime = Date.now();
  9623.  
  9624.  
  9625. foregroundPromiseFn().then(() => {
  9626.  
  9627. if (tid !== this._nszlv_) return;
  9628. const dateNow = Date.now(); // time difference to shift animation start time shall be considered. (pending)
  9629. const stackArr = this._stackedLCAs_.slice(0);
  9630. this._stackedLCAs_.length = 0;
  9631. this._lastAddItemInStack_ = false;
  9632. let lastDateTime = 0;
  9633. let prevBatchId = '';
  9634. const addItems = [];
  9635. // const previousShouldAnimateIn = this.shouldAnimateIn;
  9636.  
  9637. const addItemsFx = () => {
  9638.  
  9639. if (addItems.length >= 1) {
  9640. const eArr = addItems.slice(0);
  9641. addItems.length = 0;
  9642. if (ADJUST_TICKER_DURATION_ALIGN_RENDER_TIME) {
  9643.  
  9644. const arr = []; // size of arr <= size of eArr
  9645. const d = Date.now();
  9646. for (const item of eArr) {
  9647. const key = firstObjectKey(item);
  9648. if (key) {
  9649.  
  9650.  
  9651. const itemRenderer = item[key] || 0;
  9652. const { durationSec, fullDurationSec, __actionAt__ } = itemRenderer;
  9653. if (__actionAt__ > 0 && durationSec > 0 && fullDurationSec > 0) {
  9654.  
  9655.  
  9656. const offset = d - __actionAt__;
  9657. if (offset > 0 && typeof durationSec === 'number' && typeof fullDurationSec === 'number' && fullDurationSec >= durationSec) {
  9658. const adjustedDurationSec = durationSec - Math.floor(offset / 1000);
  9659. if (adjustedDurationSec < durationSec) { // prevent NaN
  9660. // console.log('adjustedDurationSec', adjustedDurationSec);
  9661. if (adjustedDurationSec > 0) {
  9662. // console.log('offset Sec', Math.floor(offset / 1000));
  9663. itemRenderer.durationSec = adjustedDurationSec;
  9664. } else {
  9665. // if adjustedDurationSec equal 0 or invalid
  9666. continue; // skip adding
  9667. }
  9668. }
  9669.  
  9670. }
  9671.  
  9672. }
  9673.  
  9674. if (fullDurationSec > 0 && durationSec < 1) continue; // fallback check
  9675.  
  9676.  
  9677.  
  9678. }
  9679. arr.push(item)
  9680. // arr.unshift(item);
  9681. }
  9682.  
  9683.  
  9684. // console.log(arr.slice(0))
  9685. this.unshift("items", ...arr);
  9686. } else {
  9687. this.unshift("items", ...eArr);
  9688. }
  9689. }
  9690. }
  9691.  
  9692. for (const entry of stackArr) {
  9693.  
  9694. const { action, data, dateTime, __batchId45__ } = entry;
  9695.  
  9696. const finishLastAction = (
  9697. (prevBatchId !== __batchId45__ && prevBatchId)
  9698. || (dateNow - lastDateTime >= 1000 && dateNow - dateTime < 1000)
  9699. );
  9700.  
  9701. const addPrevItems = addItems.length >= 1 && (finishLastAction || action !== 'addItem');
  9702. lastDateTime = dateTime;
  9703. prevBatchId = __batchId45__;
  9704.  
  9705. if (addPrevItems) {
  9706. addItemsFx();
  9707. }
  9708.  
  9709. if (action === 'addItem') addItems.unshift(data);
  9710. else if (action === 'mcItemD') this.handleMarkChatItemAsDeletedAction(data);
  9711. else if (action === 'removeItemById') this.removeTickerItemById(data);
  9712. else if (action === 'mcItemAD') this.handleMarkChatItemsByAuthorAsDeletedAction(data);
  9713. else if (action === 'removeItemA') this.handleRemoveChatItemByAuthorAction(data);
  9714.  
  9715. }
  9716.  
  9717. addItemsFx();
  9718. })
  9719.  
  9720. }
  9721.  
  9722. console.log("AMEND_TICKER_handleLiveChatAction - OK (v1)");
  9723. } else {
  9724. console.log("AMEND_TICKER_handleLiveChatAction - NG");
  9725. }
  9726.  
  9727.  
  9728.  
  9729. const do_amend_ticker_handleLiveChatAction_v3 = AMEND_TICKER_handleLiveChatAction_v3 && !AMEND_TICKER_handleLiveChatAction
  9730. && typeof cProto.handleLiveChatAction === 'function' && !cProto.handleLiveChatAction45 && cProto.handleLiveChatAction.length === 1
  9731. && typeof cProto.handleLiveChatActions === 'function' && !cProto.handleLiveChatActions45 && cProto.handleLiveChatActions.length === 1
  9732. && typeof cProto.unshift === 'function' && cProto.unshift.length === 1
  9733. && typeof cProto.handleMarkChatItemAsDeletedAction === 'function' && cProto.handleMarkChatItemAsDeletedAction.length === 1
  9734. && typeof cProto.removeTickerItemById === 'function' && cProto.removeTickerItemById.length === 1
  9735. && typeof cProto.handleMarkChatItemsByAuthorAsDeletedAction === 'function' && cProto.handleMarkChatItemsByAuthorAsDeletedAction.length === 1
  9736. && typeof cProto.handleRemoveChatItemByAuthorAction === 'function' && cProto.handleRemoveChatItemByAuthorAction.length === 1
  9737. ;
  9738.  
  9739. // yt-live-chat-ticker-renderer hacks
  9740. // console.log('handleLiveChatActions', cProto.handleLiveChatActions, cProto.is);
  9741. // console.log('handleLiveChatAction', cProto.handleLiveChatAction, cProto.is);
  9742.  
  9743. if (do_amend_ticker_handleLiveChatAction_v3 ) {
  9744.  
  9745. // causing no transition ??
  9746. // affect performance if many tickers need to be added. (become multiple reflows)
  9747. // performance issue shall be fixed by no transition instead (or min-width: max-content)
  9748.  
  9749. /*
  9750. f.handleLiveChatActions = function(a) {
  9751. a.length && (a.forEach(this.handleLiveChatAction, this),
  9752. this.updateHighlightedItem(),
  9753. this.shouldAnimateIn = !0)
  9754. }
  9755. */
  9756.  
  9757. /*
  9758.  
  9759. f.handleLiveChatAction = function(a) {
  9760. var b = y(a, PM)
  9761. , c = y(a, QM)
  9762. , d = y(a, OM)
  9763. , e = y(a, Yab);
  9764. a = y(a, ibb);
  9765. 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)
  9766. }
  9767. */
  9768.  
  9769. /* Dec 2024 */
  9770.  
  9771. /*
  9772.  
  9773.  
  9774. f.handleLiveChatActions = function(a) {
  9775. a.length && (a.forEach(this.handleLiveChatAction, this),
  9776. this.updateHighlightedItem(),
  9777. this.shouldAnimateIn = !0)
  9778. }
  9779. ;
  9780. f.handleLiveChatAction = function(a) {
  9781. var b = z(a, fL)
  9782. , c = z(a, gL)
  9783. , d = z(a, eL)
  9784. , e = z(a, gdb)
  9785. , g = z(a, rdb)
  9786. , k = z(a, Deb);
  9787. a = z(a, Ceb);
  9788. b ? this.unshift("tickerItems", b.item) : c ? this.handleMarkChatItemAsDeletedAction(c) : d ? this.removeTickerItemById(d.targetItemId) : e ? this.handleMarkChatItemsByAuthorAsDeletedAction(e) : g ? this.handleRemoveChatItemByAuthorAction(g) : k ? this.showCreatorGoalTickerChip(k) : a && this.removeCreatorGoalTickerChip(a)
  9789. }
  9790. */
  9791.  
  9792.  
  9793.  
  9794. const arr00 = new Array(1);
  9795. arr00.forEach = () => { };
  9796. arr00.push = (...args) => { return 1 + args.length };
  9797. arr00.pop = () => { };
  9798. arr00.shift = () => { };
  9799. arr00.unshift = () => { };
  9800. arr00.splice = () => [];
  9801. cProto.handleLiveChatActionsArr0 = arr00;
  9802.  
  9803. cProto.handleLiveChatActions58 = cProto.handleLiveChatActions;
  9804. cProto.xGqq4mo = null;
  9805. cProto.xGqq4Flg = 0;
  9806. cProto.xGqq4moPreparePromise = null;
  9807. cProto.xGqq4f = function () {
  9808. if (this.xGqq4Flg === 2) {
  9809. this.xGqq4Flg = 0;
  9810. tickerPE(async () => { // avoid confliction with ticker generation
  9811. await this.xGqq4moPreparePromise; // just in case
  9812. const s = this.handleLiveChatActionsArr0;
  9813. try {
  9814. this.handleLiveChatActions58(s);
  9815. } catch (e) {
  9816. console.warn(e);
  9817. }
  9818. // console.log('xGqq4f done')
  9819. });
  9820.  
  9821. }
  9822. }
  9823. const liveActionQM = new WeakSet();
  9824. let liveActionsLastTickerAction = null;
  9825. const lastTickerActionM = new WeakSet();
  9826. cProto.handleLiveChatActions = function (a) {
  9827. // let promise = null;
  9828. if (a && a.length) {
  9829. /** @type {MutationObserver | null} */
  9830. let mo = this.xGqq4mo;
  9831. // console.log('xGqq4f aaaa')
  9832. const hostElement = this.hostElement;
  9833. if (hostElement instanceof HTMLElement) {
  9834. if (mo === null || (mo instanceof MutationObserver && this.xGqq4p !== hostElement.xGqq4q)) {
  9835. if (mo instanceof MutationObserver) {
  9836. mo.disconnect();
  9837. mo.takeRecords();
  9838. }
  9839. this.xGqq4mo = mo = new MutationObserver(() => {
  9840. this.xGqq4f();
  9841. })
  9842. const moid = `dm-${Date.now()}-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;;
  9843. this.xGqq4p = moid;
  9844. hostElement.xGqq4q = moid;
  9845. mo.observe(hostElement, { subtree: true, childList: true });
  9846. }
  9847. }
  9848. for (const u of a) {
  9849. u && liveActionQM.add(u)
  9850. }
  9851.  
  9852. /** @type {Promise} */
  9853. const pastPromise = this.xGqq4moPreparePromise || null;
  9854. this.xGqq4moPreparePromise = (async () => {
  9855. try {
  9856. await pastPromise; // just in case
  9857. liveActionsLastTickerAction = null;
  9858. a.forEach(this.handleLiveChatAction, this);
  9859. if (liveActionsLastTickerAction) lastTickerActionM.add(liveActionsLastTickerAction)
  9860. } catch (e) { console.warn(e); } // Promise catch can make the promise always resolved
  9861. // now tickerPE can execute
  9862. })();
  9863.  
  9864.  
  9865. // console.log('xGqq4f bbbb')
  9866. // promise = this.handleLiveChatAction_LastPromise;
  9867. // const f = () => {
  9868. // const s = this.handleLiveChatActionsArr0;
  9869. // try {
  9870. // return this.handleLiveChatActions58(s);
  9871. // } catch (e) {
  9872. // console.warn(e);
  9873. // }
  9874. // }
  9875. // if (!promise) {
  9876. // f();
  9877. // } else {
  9878. // promise.then(f);
  9879. // }
  9880. } else {
  9881. return this.handleLiveChatActions58(a);
  9882. }
  9883. }
  9884.  
  9885. // 12:17:05.748 PM
  9886. // 12:17:05.785 v {name: 'addLiveChatTickerItemAction'}
  9887. // 12:17:08.059 QM
  9888. // 12:17:08.068 v {name: 'markChatItemAsDeletedAction'}
  9889. // 12:17:09.123 OM
  9890. // 12:17:09.133 v {name: 'removeChatItemAction'}
  9891. // 12:17:11.566 Yab
  9892. // 12:17:11.574 v {name: 'markChatItemsByAuthorAsDeletedAction'}
  9893. // 12:17:14.272 ibb
  9894. // 12:17:14.282 v {name: 'removeChatItemByAuthorAction'}
  9895.  
  9896. const keyFilter = (a, keySet) => {
  9897. if (typeof (a || 0) === 'object') {
  9898. for (const k of Object.keys(a)) {
  9899. if (keySet.has(k)) {
  9900. return k;
  9901. }
  9902. }
  9903. }
  9904. return null;
  9905. }
  9906.  
  9907. cProto.lcuJB = function () {
  9908. this.ddnB8 = 1;
  9909. let res = new Set();
  9910. const pxy = new Proxy({}, {
  9911. get(target, prop) {
  9912. res.add(prop);
  9913. },
  9914. set(target, prop, value) {
  9915. return true;
  9916. }
  9917. });
  9918. this.handleLiveChatAction(pxy);
  9919. this.ddnB8 = 0;
  9920. return res.size > 0 ? res : null;
  9921. }
  9922.  
  9923. cProto.ddnB8 = 0;
  9924. cProto.handleLiveChatAction58 = cProto.handleLiveChatAction;
  9925. cProto.liveChatActionFilterKeys = null;
  9926. cProto.handleLiveChatActionTM = new LimitedSizeMap(24);
  9927. const tt0 = Date.now() - 100000;
  9928. cProto.handleLiveChatAction = function (a) {
  9929. if (this.ddnB8) return this.handleLiveChatAction58(a);
  9930. const inQM = a && liveActionQM.delete(a); // true if added from handleLiveChatActions
  9931. let keySet = this.liveChatActionFilterKeys;
  9932. if (keySet === null) {
  9933. const keys = this.lcuJB();
  9934. this.liveChatActionFilterKeys = keySet = (keys || false);
  9935. }
  9936. if (!keySet) {
  9937. if (!unexpectedErr) {
  9938. console.error(unexpectedErr = "************************ [YouTube Super Fast Chat] TickerRenderer:handleLiveChatAction keySet not found; ERR 0xF3D0 ************************");
  9939. }
  9940. return this.handleLiveChatAction58(a);
  9941. }
  9942. const key = keyFilter(a, keySet);
  9943. if (!key) {
  9944. return this.handleLiveChatAction58(a); // just by default
  9945. }
  9946.  
  9947. // ------ avoid duplicate items -------
  9948. const item = ((a[key] || 0).item || 0);
  9949. const ifk = item ? firstObjectKey(item) : null;
  9950. const rendererItem = ifk ? item[ifk] : null;
  9951. if (rendererItem && rendererItem.id) {
  9952. const id = rendererItem.id || 0;
  9953. if (typeof id === 'string') {
  9954. const map = this.handleLiveChatActionTM;
  9955. if (map) {
  9956. const mid = `${rendererItem.authorExternalChannelId}::${rendererItem.id}`;
  9957. const prevTime = map.get(mid);
  9958. const now = Date.now() - tt0;
  9959. map.removeSet(mid, now);
  9960. if (prevTime > 0 && now - prevTime < 2400) {
  9961. console.log('handleLiveChatAction Repeated Item OK', rendererItem.id, rendererItem);
  9962. return; // skip
  9963. } else if (prevTime) {
  9964. console.log('handleLiveChatAction Repeated Item NG', mid, now, prevTime, rendererItem.id, rendererItem);
  9965. }
  9966. // map.removeSet(mid, now);
  9967. }
  9968. }
  9969. }
  9970. // ------ avoid duplicate items -------
  9971.  
  9972. if (inQM) {
  9973. liveActionsLastTickerAction = a;
  9974. }
  9975. this.handleLiveChatAction_LastPromise = tickerPE(async () => {
  9976. await this.xGqq4moPreparePromise; // avoid tickerPE is called before actions under looping in handleLiveChatActions
  9977. const inLQM = lastTickerActionM.delete(a); // multiple candidates
  9978. if (inLQM) this.xGqq4Flg = 2; // 2 to 2 in case two batches are added "in the same time"
  9979. this.handleLiveChatAction58(a);
  9980. // if (inLQM) await timelineResolve(); // timing split by marco event to make tickers generation in different 16ms frame
  9981. // else await Promise.resolve();
  9982. // await Promise.resolve();
  9983. await timelineResolve(); // timing split by marco event to make tickers generation in different 16ms frame
  9984. });
  9985. }
  9986.  
  9987. }
  9988.  
  9989. if (RAF_FIX_keepScrollClamped) {
  9990.  
  9991. // to be improved
  9992.  
  9993. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  9994.  
  9995. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  9996. cProto.keepScrollClamped = function () {
  9997.  
  9998. const cnt = kRef(this);
  9999. if (!cnt) return;
  10000. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10001.  
  10002. cnt._bound_keepScrollClamped = cnt._bound_keepScrollClamped || cnt.keepScrollClamped.bind(mWeakRef(cnt));
  10003. cnt.scrollClampRaf = requestAnimationFrame(cnt._bound_keepScrollClamped);
  10004. cnt.maybeClampScroll()
  10005. }
  10006.  
  10007. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  10008. } else {
  10009.  
  10010. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  10011. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  10012. }
  10013.  
  10014. }
  10015.  
  10016.  
  10017. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function'
  10018. && '|1.43.31|1.44.31|'.indexOf('|' + fnIntegrity(cProto.startScrolling) + '|') >= 0
  10019. && '|1.78.45|1.82.43|1.43.31|'.indexOf('|' + fnIntegrity(cProto.scrollIncrementally) + '|') >= 0) {
  10020. // to be replaced by animator
  10021.  
  10022. cProto.startScrolling = function (a) {
  10023.  
  10024. const cnt = kRef(this);
  10025. if (!cnt) return;
  10026. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10027.  
  10028. cnt.scrollStopHandle && cnt.cancelAsync(cnt.scrollStopHandle);
  10029. cnt.asyncHandle && cancelAnimationFrame(cnt.asyncHandle);
  10030. cnt.lastFrameTimestamp = cnt.scrollStartTime = performance.now();
  10031. cnt.scrollRatePixelsPerSecond = a;
  10032. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  10033. cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally)
  10034. };
  10035.  
  10036. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  10037.  
  10038. /**
  10039. *
  10040. * // 2024.12.17
  10041. * // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  10042.  
  10043. f.startScrolling = function(a) {
  10044. this.scrollStopHandle && $u(this.scrollStopHandle);
  10045. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  10046. this.scrollStartTime = performance.now();
  10047. this.lastFrameTimestamp = performance.now();
  10048. this.scrollRatePixelsPerSecond = a;
  10049. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  10050. }
  10051. ;
  10052. f.scrollIncrementally = function(a) {
  10053. var b = a - (this.lastFrameTimestamp || 0);
  10054. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  10055. this.maybeClampScroll();
  10056. this.updateArrows();
  10057. this.lastFrameTimestamp = a;
  10058. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft > 0 || this.scrollRatePixelsPerSecond && this.scrollRatePixelsPerSecond > 0 ? this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this)) : this.stopScrolling()
  10059. }
  10060. ;
  10061. *
  10062. */
  10063.  
  10064. /**
  10065. *
  10066. // 2024.12.20
  10067.  
  10068.  
  10069.  
  10070. f.startScrolling = function(a) {
  10071. this.scrollStopHandle && av(this.scrollStopHandle);
  10072. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  10073. this.scrollStartTime = performance.now();
  10074. this.lastFrameTimestamp = performance.now();
  10075. this.scrollRatePixelsPerSecond = a;
  10076. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  10077. }
  10078.  
  10079. *
  10080. *
  10081. */
  10082.  
  10083. cProto.__getTickerBarQuery__ = function () {
  10084. const tickerBarQuery = this.tickerBarQuery === '#items' ? this.$.items : this.hostElement.querySelector(this.tickerBarQuery);
  10085. return tickerBarQuery;
  10086. }
  10087.  
  10088. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  10089.  
  10090. const cnt = kRef(this);
  10091. if (!cnt) return;
  10092. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10093.  
  10094. const b = a - (cnt.lastFrameTimestamp || 0);
  10095. const rate = cnt.scrollRatePixelsPerSecond
  10096. const q = b / 1E3 * (rate || 0);
  10097.  
  10098. const tickerBarQuery = cnt.__getTickerBarQuery__();
  10099. const sl = tickerBarQuery.scrollLeft;
  10100. // console.log(rate, sl, q)
  10101. if (cnt.lastFrameTimestamp == cnt.scrollStartTime) {
  10102.  
  10103. } else if (q > -1e-5 && q < 1e-5) {
  10104.  
  10105. } else {
  10106. let cond1 = sl > 0 && rate > 0 && q > 0;
  10107. let cond2 = sl > 0 && rate < 0 && q < 0;
  10108. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  10109. if (cond1 || cond2 || cond3) {
  10110. tickerBarQuery.scrollLeft += q;
  10111. cnt.maybeClampScroll();
  10112. cnt.updateArrows();
  10113. }
  10114. }
  10115.  
  10116. cnt.lastFrameTimestamp = a;
  10117. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  10118. 0 < tickerBarQuery.scrollLeft || rate && 0 < rate ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  10119. } : function (a) {
  10120.  
  10121. const cnt = kRef(this);
  10122. if (!cnt) return;
  10123. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10124.  
  10125. const b = a - (cnt.lastFrameTimestamp || 0);
  10126. const tickerBarQuery = cnt.__getTickerBarQuery__();
  10127. tickerBarQuery.scrollLeft += b / 1E3 * (cnt.scrollRatePixelsPerSecond || 0);
  10128. cnt.maybeClampScroll();
  10129. cnt.updateArrows();
  10130. cnt.lastFrameTimestamp = a;
  10131. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  10132. 0 < tickerBarQuery.scrollLeft || cnt.scrollRatePixelsPerSecond && 0 < cnt.scrollRatePixelsPerSecond ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  10133. };
  10134.  
  10135. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  10136. } else {
  10137. assertor(() => fnIntegrity(cProto.startScrolling, '1.43.31'))
  10138. || logFn('cProto.startScrolling', cProto.startScrolling)();
  10139. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.78.45'))
  10140. || logFn('cProto.scrollIncrementally', cProto.scrollIncrementally)();
  10141. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  10142. }
  10143.  
  10144.  
  10145. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  10146.  
  10147. cProto.attached37 = cProto.attached;
  10148. cProto.detached37 = cProto.detached;
  10149.  
  10150. let naohzId = 0;
  10151. cProto.__naohzId__ = 0;
  10152. cProto.attached = function () {
  10153. Promise.resolve(this).then((cnt) => {
  10154.  
  10155. const hostElement = cnt.hostElement || cnt;
  10156. if (!(hostElement instanceof HTMLElement)) return;
  10157. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  10158. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  10159. // or #chat-messages
  10160. if (!ironPage) return;
  10161.  
  10162. if (cnt.__naohzId__) removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  10163. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  10164. cnt.__naohzId__ = ++naohzId;
  10165. ironPage.setAttribute('naohz', `${+cnt.__naohzId__}`);
  10166.  
  10167. addEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  10168. cnt = null;
  10169.  
  10170. });
  10171. return this.attached37.apply(this, arguments);
  10172. };
  10173. cProto.detached = function () {
  10174. Promise.resolve(this).then((cnt) => {
  10175.  
  10176. const ironPage = document.querySelector(`iron-pages[naohz="${+cnt.__naohzId__}"]`);
  10177. if (!ironPage) return;
  10178.  
  10179. removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  10180.  
  10181. cnt = null;
  10182.  
  10183. });
  10184. return this.detached37.apply(this, arguments);
  10185. };
  10186.  
  10187. const clickFade = (u) => {
  10188. u.click();
  10189. };
  10190. cProto.messageBoxClickHandlerForFade = async (evt) => {
  10191.  
  10192. const target = (evt || 0).target || 0;
  10193. if (!target) return;
  10194.  
  10195. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  10196. const is = p.is;
  10197. if (typeof is === 'string' && is) {
  10198.  
  10199. if (is === 'yt-live-chat-pinned-message-renderer') {
  10200. return;
  10201. }
  10202. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  10203. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  10204. if (fade) {
  10205. Promise.resolve(fade).then(clickFade);
  10206. evt && evt.stopPropagation();
  10207. }
  10208. return;
  10209. }
  10210. if (is !== 'yt-live-chat-ticker-renderer') {
  10211. if (is.startsWith('yt-live-chat-ticker-')) return;
  10212. if (!is.endsWith('-renderer')) return;
  10213. }
  10214.  
  10215. } else {
  10216. if ((p.nodeName || '').includes('BUTTON')) return;
  10217. }
  10218.  
  10219. }
  10220. };
  10221.  
  10222. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  10223.  
  10224. } else {
  10225. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  10226. }
  10227.  
  10228.  
  10229. })();
  10230.  
  10231. console.log("[End]");
  10232.  
  10233. console.groupEnd();
  10234.  
  10235. }).catch(console.warn);
  10236.  
  10237.  
  10238.  
  10239. if (ENABLE_RAF_HACK_INPUT_RENDERER || DELAY_FOCUSEDCHANGED) {
  10240.  
  10241. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  10242.  
  10243. mightFirstCheckOnYtInit();
  10244. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  10245. console.log("[Begin]");
  10246. (() => {
  10247.  
  10248.  
  10249.  
  10250. const tag = "yt-live-chat-message-input-renderer"
  10251. const dummy = document.createElement(tag);
  10252.  
  10253. const cProto = getProto(dummy);
  10254. if (!cProto || !cProto.attached) {
  10255. console.warn(`proto.attached for ${tag} is unavailable.`);
  10256. return;
  10257. }
  10258.  
  10259.  
  10260. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  10261.  
  10262. let doHack = false;
  10263. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  10264.  
  10265. // not cancellable
  10266.  
  10267. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  10268.  
  10269. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  10270.  
  10271. if (!doHack) console.log('doHack = false')
  10272.  
  10273. }
  10274. // doHack = false; // M55
  10275.  
  10276. if (doHack) {
  10277.  
  10278. cProto.handleTimeout = function (a) {
  10279.  
  10280. const cnt = kRef(this);
  10281. if (!cnt) return;
  10282. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10283.  
  10284. console.log('cProto.handleTimeout', tag)
  10285. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  10286. cnt.timeoutDurationMs = cnt.timeoutMs = a;
  10287. cnt.countdownRatio = 1;
  10288. 0 === cnt.lastTimeoutTimeMs && rafHub.request(cnt.boundUpdateTimeout38_)
  10289. };
  10290. cProto.updateTimeout = function (a) {
  10291.  
  10292. const cnt = kRef(this);
  10293. if (!cnt) return;
  10294. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10295.  
  10296. console.log('cProto.updateTimeout', tag)
  10297. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  10298. cnt.lastTimeoutTimeMs && (cnt.timeoutMs = Math.max(0, cnt.timeoutMs - (a - cnt.lastTimeoutTimeMs)),
  10299. cnt.countdownRatio = cnt.timeoutMs / cnt.timeoutDurationMs);
  10300. cnt.isAttached && cnt.timeoutMs ? (cnt.lastTimeoutTimeMs = a,
  10301. rafHub.request(cnt.boundUpdateTimeout38_)) : cnt.lastTimeoutTimeMs = 0
  10302. };
  10303.  
  10304. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  10305. } else {
  10306.  
  10307. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  10308. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  10309.  
  10310. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  10311. }
  10312.  
  10313.  
  10314. }
  10315.  
  10316. if (DELAY_FOCUSEDCHANGED && typeof cProto.onFocusedChanged === 'function' && cProto.onFocusedChanged.length === 1 && !cProto.onFocusedChanged372) {
  10317. cProto.onFocusedChanged372 = cProto.onFocusedChanged;
  10318. cProto.onFocusedChanged = function (a) {
  10319. Promise.resolve(this).then((cnt) => {
  10320. if (cnt.isAttached === true) cnt.onFocusedChanged372(a);
  10321. cnt = null;
  10322. }).catch(console.warn);
  10323. }
  10324. }
  10325.  
  10326. })();
  10327.  
  10328. console.log("[End]");
  10329.  
  10330. console.groupEnd();
  10331.  
  10332.  
  10333. })
  10334.  
  10335. }
  10336.  
  10337.  
  10338. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  10339.  
  10340. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  10341.  
  10342. mightFirstCheckOnYtInit();
  10343. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  10344. console.log("[Begin]");
  10345. (() => {
  10346.  
  10347. const tag = "yt-emoji-picker-renderer"
  10348. const dummy = document.createElement(tag);
  10349.  
  10350. const cProto = getProto(dummy);
  10351. if (!cProto || !cProto.attached) {
  10352. console.warn(`proto.attached for ${tag} is unavailable.`);
  10353. return;
  10354. }
  10355.  
  10356. let doHack = false;
  10357. if (typeof cProto.animateScroll_ === 'function') {
  10358.  
  10359. // not cancellable
  10360. console.log('animateScroll_', typeof cProto.animateScroll_)
  10361.  
  10362. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  10363.  
  10364. }
  10365.  
  10366. if (doHack) {
  10367.  
  10368. const querySelector = HTMLElement.prototype.querySelector;
  10369. const U = (element) => ({
  10370. querySelector: (selector) => querySelector.call(element, selector)
  10371. });
  10372.  
  10373. cProto.animateScroll_ = function (a) {
  10374.  
  10375. const cnt = kRef(this);
  10376. if (!cnt) return;
  10377. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10378.  
  10379. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  10380. if (!cnt.boundAnimateScroll39_) cnt.boundAnimateScroll39_ = cnt.animateScroll_.bind(mWeakRef(cnt));
  10381. cnt.lastAnimationTime_ || (cnt.lastAnimationTime_ = a);
  10382. a -= cnt.lastAnimationTime_;
  10383. 200 > a ? (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationStart_ + (cnt.animationEnd_ - cnt.animationStart_) * a / 200,
  10384. rafHub.request(cnt.boundAnimateScroll39_)) : (null != cnt.animationEnd_ && (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationEnd_),
  10385. cnt.animationEnd_ = cnt.animationStart_ = null,
  10386. cnt.lastAnimationTime_ = 0);
  10387. cnt.updateButtons_()
  10388. }
  10389.  
  10390. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  10391. } else {
  10392.  
  10393. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  10394. }
  10395.  
  10396. })();
  10397.  
  10398. console.log("[End]");
  10399.  
  10400. console.groupEnd();
  10401. });
  10402. }
  10403.  
  10404. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  10405.  
  10406. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  10407.  
  10408. mightFirstCheckOnYtInit();
  10409. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  10410. console.log("[Begin]");
  10411. (() => {
  10412.  
  10413. const tag = "yt-live-chat-docked-message"
  10414. const dummy = document.createElement(tag);
  10415.  
  10416. const cProto = getProto(dummy);
  10417. if (!cProto || !cProto.attached) {
  10418. console.warn(`proto.attached for ${tag} is unavailable.`);
  10419. return;
  10420. }
  10421.  
  10422. let doHack = false;
  10423. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  10424.  
  10425. // cancelable - this.intersectRAF <detached>
  10426. // yt-live-chat-docked-message
  10427. // boundCheckIntersections <-> checkIntersections
  10428. // onDockableMessagesChanged
  10429. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  10430.  
  10431. console.log('detached', typeof cProto.detached)
  10432. console.log('checkIntersections', typeof cProto.checkIntersections)
  10433. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  10434.  
  10435. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  10436.  
  10437. }
  10438.  
  10439. if (doHack) {
  10440.  
  10441. cProto.__boundCheckIntersectionsSubstitutionFn__ = function () {
  10442. const cnt = this;
  10443. if (!cnt.i5zmk && typeof cnt.boundCheckIntersections === 'function' && typeof cnt.checkIntersections === 'function') {
  10444. cnt.i5zmk = 1
  10445. cnt.boundCheckIntersections = cnt.checkIntersections.bind(mWeakRef(cnt));
  10446. }
  10447. }
  10448.  
  10449. cProto.checkIntersections = function () {
  10450.  
  10451. const cnt = kRef(this);
  10452. if (!cnt) return;
  10453. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  10454.  
  10455. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  10456.  
  10457. // console.log('cProto.checkIntersections', tag)
  10458. if (cnt.dockableMessages.length) {
  10459. cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections);
  10460. let a = cnt.dockableMessages[0]
  10461. , b = cnt.hostElement.getBoundingClientRect();
  10462. a = a.getBoundingClientRect();
  10463. let c = a.top - b.top
  10464. , d = 8 >= c;
  10465. c = 8 >= c - cnt.hostElement.clientHeight;
  10466. if (d) {
  10467. let e;
  10468. for (; d;) {
  10469. e = cnt.dockableMessages.shift();
  10470. d = cnt.dockableMessages[0];
  10471. if (!d)
  10472. break;
  10473. d = d.getBoundingClientRect();
  10474. c = d.top - b.top;
  10475. let f = 8 >= c;
  10476. if (8 >= c - a.height)
  10477. if (f)
  10478. a = d;
  10479. else
  10480. return;
  10481. d = f
  10482. }
  10483. cnt.dock(e)
  10484. } else
  10485. c && cnt.dockedItem && cnt.clear()
  10486. } else
  10487. cnt.intersectRAF = 0
  10488. }
  10489.  
  10490. cProto.onDockableMessagesChanged = function () {
  10491. const cnt = this;
  10492. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  10493. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  10494. cnt.dockableMessages.length && !cnt.intersectRAF && (cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections))
  10495. }
  10496.  
  10497. cProto.detached = function () {
  10498. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  10499. }
  10500.  
  10501. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  10502. } else {
  10503.  
  10504. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  10505. }
  10506.  
  10507. })();
  10508.  
  10509. console.log("[End]");
  10510.  
  10511. console.groupEnd();
  10512.  
  10513. }).catch(console.warn);
  10514.  
  10515. }
  10516.  
  10517. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  10518.  
  10519. customElements.whenDefined("yt-img-shadow").then(() => {
  10520.  
  10521. mightFirstCheckOnYtInit();
  10522. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  10523. console.log("[Begin]");
  10524. (() => {
  10525.  
  10526. const tag = "yt-img-shadow"
  10527. const dummy = document.createElement(tag);
  10528.  
  10529. const cProto = getProto(dummy);
  10530. if (!cProto || !cProto.attached) {
  10531. console.warn(`proto.attached for ${tag} is unavailable.`);
  10532. return;
  10533. }
  10534.  
  10535. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  10536.  
  10537. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  10538. cProto.thumbnailChanged_ = function (a) {
  10539.  
  10540. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  10541. if (!this.oldThumbnail_ && !this.thumbnail) return;
  10542.  
  10543. return this.thumbnailChanged66_.apply(this, arguments)
  10544.  
  10545. }
  10546. console.log("cProto.thumbnailChanged_ - OK");
  10547.  
  10548. } else {
  10549. console.log("cProto.thumbnailChanged_ - NG");
  10550.  
  10551. }
  10552. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  10553.  
  10554. cProto.setSrc66_ = cProto.setSrc_;
  10555. cProto.setSrc_ = function (a) {
  10556. if ((((this || 0).$ || 0).img || 0).src === a) return;
  10557. return this.setSrc66_.apply(this, arguments)
  10558. }
  10559.  
  10560. console.log("cProto.setSrc_ - OK");
  10561. } else {
  10562.  
  10563. console.log("cProto.setSrc_ - NG");
  10564. }
  10565.  
  10566. })();
  10567.  
  10568. console.log("[End]");
  10569.  
  10570. console.groupEnd();
  10571.  
  10572. }).catch(console.warn);
  10573.  
  10574. }
  10575.  
  10576. if (FIX_THUMBNAIL_DATACHANGED) {
  10577.  
  10578. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  10579.  
  10580. mightFirstCheckOnYtInit();
  10581. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  10582. console.log("[Begin]");
  10583. (() => {
  10584.  
  10585. const tag = "yt-live-chat-author-badge-renderer"
  10586. const dummy = document.createElement(tag);
  10587.  
  10588. const cProto = getProto(dummy);
  10589. if (!cProto || !cProto.attached) {
  10590. console.warn(`proto.attached for ${tag} is unavailable.`);
  10591. return;
  10592. }
  10593.  
  10594. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|0.169.106|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  10595.  
  10596. cProto.dataChanged86 = cProto.dataChanged;
  10597. cProto.dataChanged = function () {
  10598.  
  10599. /* 2024.12.15 */
  10600. /*
  10601. zO.prototype.dataChanged = function() {
  10602. for (var a = Ov(R(this.hostElement).querySelector("#image")); a.firstChild; )
  10603. a.removeChild(a.firstChild);
  10604. if (this.data)
  10605. if (this.data.icon) {
  10606. var b = document.createElement("yt-icon");
  10607. this.data.icon.iconType === "MODERATOR" && this.enableNewModeratorBadge ? (b.polymerController.icon = "yt-sys-icons:shield-filled",
  10608. b.polymerController.defaultToFilled = !0) : b.polymerController.icon = "live-chat-badges:" + this.data.icon.iconType.toLowerCase();
  10609. a.appendChild(b)
  10610. } else if (this.data.customThumbnail) {
  10611. b = document.createElement("img");
  10612. var c;
  10613. (c = (c = UA(this.data.customThumbnail.thumbnails, 16)) ? Yb(kc(c)) : null) ? (b.src = c,
  10614. a.appendChild(b),
  10615. b.setAttribute("alt", this.hostElement.ariaLabel || "")) : Fq(new Zn("Could not compute URL for thumbnail",this.data.customThumbnail))
  10616. }
  10617. }
  10618. */
  10619.  
  10620. const a = (this || 0).data;
  10621. const image = ((this || 0).$ || 0).image;
  10622. if (image && a && image.firstElementChild) {
  10623. const exisiting = image.firstElementChild;
  10624. if (exisiting === image.lastElementChild) {
  10625.  
  10626. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  10627.  
  10628. const c = exisiting;
  10629. const t = insp(c);
  10630. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  10631. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  10632. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  10633. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  10634. } else {
  10635. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  10636. if (w.icon !== p) w.icon = p;
  10637. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  10638. }
  10639. return;
  10640.  
  10641.  
  10642. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  10643.  
  10644. const c = exisiting;
  10645. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  10646.  
  10647. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  10648. return;
  10649. }
  10650. /*
  10651.  
  10652. var d;
  10653. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  10654.  
  10655. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  10656. */
  10657. }
  10658.  
  10659. }
  10660. }
  10661. return this.dataChanged86.apply(this, arguments)
  10662.  
  10663. }
  10664. console.log("cProto.dataChanged - OK");
  10665.  
  10666. } else if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|1.163.100|1.162.100|1.160.97|1.159.97|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  10667.  
  10668. cProto.dataChanged86 = cProto.dataChanged;
  10669. cProto.dataChanged = function (a) {
  10670.  
  10671. /*
  10672.  
  10673. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  10674. b.removeChild(b.firstChild);
  10675. if (a)
  10676. if (a.icon) {
  10677. var c = document.createElement("yt-icon");
  10678. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  10679. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  10680. b.appendChild(c)
  10681. } else if (a.customThumbnail) {
  10682. c = document.createElement("img");
  10683. var d;
  10684. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  10685. b.appendChild(c),
  10686. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  10687. }
  10688.  
  10689. */
  10690.  
  10691.  
  10692. /* 2024.04.20 */
  10693. /*
  10694. for (var b = Tx(N(this.hostElement).querySelector("#image")); b.firstChild; )
  10695. b.removeChild(b.firstChild);
  10696. if (a)
  10697. if (a.icon) {
  10698. var c = document.createElement("yt-icon");
  10699. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.polymerController.icon = "yt-sys-icons:shield-filled",
  10700. c.polymerController.defaultToFilled = !0) : c.polymerController.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  10701. b.appendChild(c)
  10702. } else if (a.customThumbnail) {
  10703. c = document.createElement("img");
  10704. var d;
  10705. (d = (d = WD(a.customThumbnail.thumbnails, 16)) ? Sb(ec(d)) : null) ? (c.src = d,
  10706. b.appendChild(c),
  10707. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : nr(new mn("Could not compute URL for thumbnail",a.customThumbnail))
  10708. }
  10709. */
  10710.  
  10711. const image = ((this || 0).$ || 0).image
  10712. if (image && a && image.firstElementChild) {
  10713. const exisiting = image.firstElementChild;
  10714. if (exisiting === image.lastElementChild) {
  10715.  
  10716. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  10717.  
  10718. const c = exisiting;
  10719. const t = insp(c);
  10720. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  10721. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  10722. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  10723. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  10724. } else {
  10725. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  10726. if (w.icon !== p) w.icon = p;
  10727. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  10728. }
  10729. return;
  10730.  
  10731.  
  10732. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  10733.  
  10734. const c = exisiting;
  10735. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  10736.  
  10737. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  10738. return;
  10739. }
  10740. /*
  10741.  
  10742. var d;
  10743. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  10744.  
  10745. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  10746. */
  10747. }
  10748.  
  10749. }
  10750. }
  10751. return this.dataChanged86.apply(this, arguments)
  10752.  
  10753. }
  10754. console.log("cProto.dataChanged - OK");
  10755.  
  10756. } else {
  10757. assertor(() => fnIntegrity(cProto.dataChanged, '0.169.106'));
  10758. console.log("cProto.dataChanged - NG");
  10759.  
  10760. }
  10761.  
  10762. })();
  10763.  
  10764. console.log("[End]");
  10765.  
  10766. console.groupEnd();
  10767.  
  10768. }).catch(console.warn);
  10769.  
  10770.  
  10771. }
  10772.  
  10773. if(USE_ADVANCED_TICKING){
  10774. // leading the emoji cannot be rendered.
  10775.  
  10776. // const qz38 = lcrPromiseFn();
  10777.  
  10778. // qz38.then((lcrGet) => {
  10779.  
  10780. // const tag = "yt-live-chat-renderer"
  10781. // const dummy = lcrGet();
  10782.  
  10783. getLCRDummy().then(async (lcrDummy) => {
  10784.  
  10785. const tag = "yt-live-chat-renderer"
  10786. const dummy = lcrDummy;
  10787.  
  10788.  
  10789. const cProto = getProto(dummy);
  10790.  
  10791. // dummy.usePatchedLifecycles = false;
  10792. // dummy.data = null;
  10793. // dummy.__data = null;
  10794. // Object.setPrototypeOf(dummy, Object.prototype);
  10795. if (!cProto || !cProto.attached) {
  10796. console.warn(`proto.attached for ${tag} is unavailable.`);
  10797. return;
  10798. }
  10799.  
  10800. /*
  10801. <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;
  10802. */
  10803.  
  10804. if (cProto && typeof cProto.immediatelyApplyLiveChatActions === 'function' && cProto.immediatelyApplyLiveChatActions.length === 1 && !cProto.immediatelyApplyLiveChatActions82) {
  10805. cProto.immediatelyApplyLiveChatActions82 = cProto.immediatelyApplyLiveChatActions;
  10806. cProto.immediatelyApplyLiveChatActions = function(arr){
  10807.  
  10808. // console.log(1237)
  10809. try{
  10810. preprocessChatLiveActions(arr);
  10811.  
  10812. }catch(e){
  10813. console.warn(e);
  10814. }
  10815. return this.immediatelyApplyLiveChatActions82(arr);
  10816. };
  10817. }
  10818.  
  10819.  
  10820. if (cProto && typeof cProto.preprocessActions_ === 'function' && cProto.preprocessActions_.length === 1 && !cProto.preprocessActions82_) {
  10821. cProto.preprocessActions82_ = cProto.preprocessActions_;
  10822. cProto.preprocessActions_ = function(arr){
  10823. arr = this.preprocessActions82_(arr);
  10824. preprocessChatLiveActions(arr);
  10825. return arr;
  10826. };
  10827. }
  10828.  
  10829.  
  10830. });
  10831. }
  10832.  
  10833.  
  10834. if (FIX_TOOLTIP_DISPLAY) {
  10835.  
  10836. // ----------------------------------------------------------------------------------------------------
  10837.  
  10838. const checkPDGet = (pd) => {
  10839. return pd && pd.get && !pd.set && pd.enumerable && pd.configurable;
  10840. }
  10841.  
  10842. const tooltipUIWM = new WeakMap();
  10843. const tooltipInitProps = {};
  10844. const createTooltipIfRequired_ = function () {
  10845. let r;
  10846. if (tooltipUIWM.get(this) === void 0) {
  10847. const w = document.createElement;
  10848. let EU = null;
  10849. tooltipUIWM.set(this, null);
  10850. document.createElement = function () {
  10851. let r = w.apply(this, arguments);
  10852. EU = r;
  10853. return r;
  10854. };
  10855. r = this.createTooltipIfRequired14_();
  10856. document.createElement = w;
  10857. if (EU instanceof HTMLElement && EU.is) {
  10858. tooltipUIWM.set(this, EU);
  10859. EU.setAttribute('__nogc__', ''); // avoid gc process script
  10860.  
  10861. if (typeof EU.offset === 'number') tooltipInitProps['offset'] = EU.offset;
  10862. if (typeof EU.fitToVisibleBounds === 'boolean') tooltipInitProps['fitToVisibleBounds'] = EU.fitToVisibleBounds;
  10863. if (typeof EU.position === 'string') tooltipInitProps['position'] = EU.position;
  10864. if (typeof EU.for === 'string') tooltipInitProps['for'] = EU.for;
  10865.  
  10866. // this.__mcT__ = EU.outerHTML;
  10867. // EU.__dataX = JSON.stringify(EU.__data);
  10868. // EU.__dataY = Object.entries(EU);
  10869.  
  10870. // <<< FOR DEBUG >>>
  10871. // let kx;
  10872. // Object.defineProperty(EU, '_target', {
  10873. // get(){
  10874. // return kx;
  10875. // },
  10876. // set(nv){
  10877. // kx= nv;
  10878. // debugger;
  10879. // return true;
  10880. // }
  10881. // });
  10882. // <<< FOR DEBUG >>>
  10883.  
  10884. if (typeof Polymer !== 'undefined' && Polymer.__fixedGetOwnerRoot__ && Polymer.__fixedQuerySelector__) {
  10885.  
  10886. } else {
  10887. let eProto = null;
  10888. const euCnt = insp(EU);
  10889. if (checkPDGet(Object.getOwnPropertyDescriptor(euCnt.constructor.prototype || {}, 'target'))) {
  10890.  
  10891. eProto = euCnt.constructor.prototype;
  10892. } else if (checkPDGet(Object.getOwnPropertyDescriptor(EU.constructor.prototype || {}, 'target'))) {
  10893.  
  10894. eProto = EU.constructor.prototype;
  10895. }
  10896. if (eProto) {
  10897. delete eProto.target;
  10898. /*
  10899.  
  10900. get target() {
  10901. var a = Pv(this).parentNode, b = Pv(this).getOwnerRoot(), c;
  10902. this.for ? c = Pv(b).querySelector("#" + this.for) : c = a.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? b.host : a;
  10903. return c
  10904. },
  10905. */
  10906. Object.defineProperty(eProto, 'target', {
  10907. get() {
  10908. let a = this.parentNode, b = this.getRootNode();
  10909. return (this.for ? b.querySelector("#" + this.for) : a)
  10910. }
  10911. })
  10912. }
  10913. }
  10914. // setInterval(()=>EU.updatePosition(), 100)
  10915.  
  10916. } else {
  10917. tooltipUIWM.set(this, null);
  10918. }
  10919. } else {
  10920. r = this.createTooltipIfRequired14_();
  10921. }
  10922.  
  10923. const EU = tooltipUIWM.get(this);
  10924. if (EU) {
  10925. EU.remove();
  10926. if (typeof tooltipInitProps.offset === 'number') EU['offset'] = tooltipInitProps.offset;
  10927. if (typeof tooltipInitProps.fitToVisibleBounds === 'boolean') EU['fitToVisibleBounds'] = tooltipInitProps.fitToVisibleBounds;
  10928. try {
  10929. if (typeof tooltipInitProps.position === 'string') EU['position'] = tooltipInitProps.position;
  10930. if (typeof tooltipInitProps.for === 'string') EU['for'] = tooltipInitProps.for; else delete EU.for;
  10931. } catch (e) { }
  10932. }
  10933. return r;
  10934. };
  10935.  
  10936.  
  10937. // added in 2024.05.02
  10938. getLCRDummy().then(async (lcrDummy) => {
  10939.  
  10940. // console.log(8171, 99);
  10941. const tag = "yt-live-chat-renderer"
  10942. const dummy = lcrDummy;
  10943.  
  10944. const cProto = getProto(dummy);
  10945. if (!cProto || !cProto.attached) {
  10946. console.warn(`proto.attached for ${tag} is unavailable.`);
  10947. return;
  10948. }
  10949.  
  10950. /*
  10951. <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;
  10952. */
  10953.  
  10954. if (cProto && typeof cProto.createTooltipIfRequired_ === 'function' && cProto.createTooltipIfRequired_.length === 0 && !cProto.createTooltipIfRequired14_) {
  10955. cProto.createTooltipIfRequired14_ = cProto.createTooltipIfRequired_;
  10956. cProto.createTooltipIfRequired_ = createTooltipIfRequired_;
  10957. }
  10958.  
  10959. });
  10960.  
  10961. // ----------------------------------------------------------------------------------------------------
  10962.  
  10963. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  10964.  
  10965. mightFirstCheckOnYtInit();
  10966. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  10967. console.log("[Begin]");
  10968. (() => {
  10969.  
  10970. const tag = "tp-yt-paper-tooltip"
  10971. const dummy = document.createElement(tag);
  10972.  
  10973. const cProto = getProto(dummy);
  10974. if (!cProto || !cProto.attached) {
  10975. console.warn(`proto.attached for ${tag} is unavailable.`);
  10976. return;
  10977. }
  10978.  
  10979. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  10980.  
  10981. cProto._readyClients43 = cProto._readyClients;
  10982. cProto._readyClients = function () {
  10983. // console.log(1238)
  10984.  
  10985. let r = cProto._readyClients43.apply(this, arguments);
  10986. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  10987. return r;
  10988. }
  10989.  
  10990. console.log("_readyClients - OK");
  10991.  
  10992. } else {
  10993. console.log("_readyClients - NG");
  10994.  
  10995. }
  10996.  
  10997. if (typeof cProto.show === 'function' && !cProto.show17) {
  10998. cProto.show17 = cProto.show;
  10999. cProto.show = function () {
  11000.  
  11001. let r = this.show17.apply(this, arguments);
  11002. this._showing === true && Promise.resolve(this).then((cnt) => {
  11003. const tooltip = (cnt.$ || 0).tooltip;
  11004.  
  11005. if (tooltip && tooltip.firstElementChild === null) {
  11006. let text = tooltip.textContent;
  11007. if (typeof text === 'string' && text.length >= 2) {
  11008. tooltip.textContent = text.trim();
  11009. }
  11010. }
  11011. cnt = null;
  11012. }).catch(console.warn)
  11013. return r;
  11014. }
  11015.  
  11016. console.log("trim tooltip content - OK");
  11017.  
  11018. } else {
  11019. console.log("trim tooltip content - NG");
  11020.  
  11021. }
  11022.  
  11023.  
  11024. })();
  11025.  
  11026. console.log("[End]");
  11027.  
  11028. console.groupEnd();
  11029.  
  11030. }).catch(console.warn);
  11031.  
  11032. }
  11033.  
  11034.  
  11035. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  11036.  
  11037. const hookDocumentMouseDownSetupFn = () => {
  11038.  
  11039. let muzTimestamp = 0;
  11040. let nszDropdown = null;
  11041.  
  11042. const handlerObject = {
  11043.  
  11044. muHandler282: function (evt) {
  11045. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  11046. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  11047. const dropdown = nszDropdown;
  11048. muzTimestamp = 0;
  11049. nszDropdown = null;
  11050.  
  11051. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  11052. const hostElement = kurMPCe.hostElement || kurMPCe; // should be always hostElement === kurMPCe ?
  11053. if (!hostElement.hasAttribute('menu-visible')) return;
  11054.  
  11055. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  11056. if (chatBanner) return;
  11057.  
  11058. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  11059. muzTimestamp = Date.now();
  11060. evt.stopImmediatePropagation();
  11061. evt.stopPropagation();
  11062. Promise.resolve(dropdown).then((dropdown) => {
  11063. dropdown.cancel();
  11064. dropdown = null;
  11065. });
  11066. }
  11067.  
  11068. },
  11069.  
  11070. mlHandler282: function (evt) {
  11071. muzTimestamp = 0;
  11072. nszDropdown = null;
  11073. },
  11074.  
  11075. ckHandler282: function (evt) {
  11076. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  11077. if (Date.now() - muzTimestamp < 40) {
  11078. muzTimestamp = Date.now();
  11079. evt.stopImmediatePropagation();
  11080. evt.stopPropagation();
  11081. }
  11082. },
  11083.  
  11084. tapHandler282: function (evt) {
  11085. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  11086. if (Date.now() - muzTimestamp < 40) {
  11087. muzTimestamp = Date.now();
  11088. evt.stopImmediatePropagation();
  11089. evt.stopPropagation();
  11090. }
  11091. },
  11092.  
  11093. handleEvent(evt) {
  11094. if (evt) {
  11095. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  11096. const kurMPCc = insp(kurMPCe);
  11097. const hostElement = kurMPCc.hostElement || kurMPCc;
  11098. if (!kurMPCc || kurMPCc.isAttached !== true || hostElement.isConnected !== true) return;
  11099. switch (evt.type) {
  11100. case 'mouseup':
  11101. return this.muHandler282(evt);
  11102. case 'mouseleave':
  11103. return this.mlHandler282(evt);
  11104. case 'tap':
  11105. return this.tapHandler282(evt);
  11106. case 'click':
  11107. return this.ckHandler282(evt);
  11108. }
  11109. }
  11110. }
  11111.  
  11112. }
  11113.  
  11114. document.addEventListener('mousedown', function (evt) {
  11115.  
  11116. if (!evt || !evt.isTrusted || !evt.target) return;
  11117.  
  11118. muzTimestamp = 0;
  11119. nszDropdown = null;
  11120.  
  11121. /** @type {HTMLElement | null} */
  11122. const kurMP = kRef(currentMenuPivotWR);
  11123. if (!kurMP) return;
  11124. const kurMPCe = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0; // element
  11125.  
  11126. if (!kurMPCe || !kurMPCe.hasAttribute('whole-message-clickable')) return;
  11127.  
  11128. const kurMPCc = insp(kurMPCe); // controller
  11129.  
  11130. if (!kurMPCc.isClickableChatRow111 || !kurMPCc.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPCe, evt.target)) return;
  11131.  
  11132. const chatBanner = HTMLElement.prototype.closest.call(kurMPCe, 'yt-live-chat-banner-renderer') || 0;
  11133. if (chatBanner) return;
  11134.  
  11135. let targetDropDown = null;
  11136. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  11137. if (dropdown && dropdown.positionTarget === kurMP) {
  11138. targetDropDown = dropdown;
  11139. }
  11140. }
  11141.  
  11142. if (!targetDropDown) return;
  11143.  
  11144. if ((nszDropdown = targetDropDown)) {
  11145. muzTimestamp = Date.now();
  11146. evt.stopImmediatePropagation();
  11147. evt.stopPropagation();
  11148. currentMenuPivotWR = mWeakRef(kurMPCe);
  11149.  
  11150. const listenOpts = { capture: true, passive: false, once: true };
  11151.  
  11152. // remove unexcecuted eventHandler
  11153. document.removeEventListener('mouseup', handlerObject, listenOpts);
  11154. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  11155. document.removeEventListener('tap', handlerObject, listenOpts);
  11156. document.removeEventListener('click', handlerObject, listenOpts);
  11157.  
  11158. // inject one time eventHandler to by pass events
  11159. document.addEventListener('mouseup', handlerObject, listenOpts);
  11160. document.addEventListener('mouseleave', handlerObject, listenOpts);
  11161. document.addEventListener('tap', handlerObject, listenOpts);
  11162. document.addEventListener('click', handlerObject, listenOpts);
  11163.  
  11164. }
  11165.  
  11166. }, true);
  11167.  
  11168. }
  11169.  
  11170.  
  11171. // yt-live-chat-paid-message-renderer ??
  11172.  
  11173. /*
  11174.  
  11175. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  11176.  
  11177.  
  11178. "yt-live-chat-ticker-paid-message-item-renderer"
  11179. "yt-live-chat-ticker-paid-sticker-item-renderer"
  11180. "yt-live-chat-paid-message-renderer"
  11181. "yt-live-chat-text-message-renderer"
  11182. "yt-live-chat-paid-sticker-renderer"
  11183.  
  11184. */
  11185.  
  11186.  
  11187. whenDefinedMultiple([
  11188.  
  11189. "yt-live-chat-paid-message-renderer",
  11190. "yt-live-chat-membership-item-renderer",
  11191. "yt-live-chat-paid-sticker-renderer",
  11192. "yt-live-chat-text-message-renderer",
  11193. "yt-live-chat-auto-mod-message-renderer",
  11194.  
  11195. /*
  11196. "yt-live-chat-ticker-paid-message-item-renderer",
  11197. "yt-live-chat-ticker-paid-sticker-item-renderer",
  11198. "yt-live-chat-paid-message-renderer",
  11199. "yt-live-chat-text-message-renderer",
  11200. "yt-live-chat-paid-sticker-renderer",
  11201.  
  11202. "yt-live-chat-ticker-sponsor-item-renderer",
  11203. "yt-live-chat-banner-header-renderer",
  11204. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  11205. "ytd-sponsorships-live-chat-header-renderer",
  11206. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  11207.  
  11208.  
  11209.  
  11210.  
  11211. "yt-live-chat-auto-mod-message-renderer",
  11212. "yt-live-chat-text-message-renderer",
  11213. "yt-live-chat-paid-message-renderer",
  11214.  
  11215. "yt-live-chat-legacy-paid-message-renderer",
  11216. "yt-live-chat-membership-item-renderer",
  11217. "yt-live-chat-paid-sticker-renderer",
  11218. "yt-live-chat-donation-announcement-renderer",
  11219. "yt-live-chat-moderation-message-renderer",
  11220. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  11221. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  11222. "yt-live-chat-viewer-engagement-message-renderer",
  11223.  
  11224. */
  11225.  
  11226.  
  11227. ]).then(sTags => {
  11228. // return; // M33
  11229.  
  11230. if (FLAG_001e) return;
  11231.  
  11232. mightFirstCheckOnYtInit();
  11233. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  11234. console.log("[Begin]");
  11235. let doMouseHook = false;
  11236.  
  11237. const dProto = {
  11238. isClickableChatRow111: function () {
  11239. return (
  11240. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  11241. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  11242. ); // follow .onItemTap(a)
  11243. }
  11244. };
  11245.  
  11246. for (const sTag of sTags) { // ##tag##
  11247.  
  11248.  
  11249. (() => {
  11250.  
  11251. const tag = sTag;
  11252. const dummy = document.createElement(tag);
  11253.  
  11254. const cProto = getProto(dummy);
  11255. if (!cProto || !cProto.attached) {
  11256. console.warn(`proto.attached for ${tag} is unavailable.`);
  11257. return;
  11258. }
  11259.  
  11260. const dCnt = insp(dummy);
  11261. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  11262.  
  11263. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  11264.  
  11265. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  11266.  
  11267. if (toHookDocumentMouseDown) {
  11268. doMouseHook = true;
  11269. }
  11270.  
  11271. console.log("shouldSupportWholeItemClick Y", tag);
  11272.  
  11273. } else {
  11274.  
  11275. console.log("shouldSupportWholeItemClick N", tag);
  11276. }
  11277.  
  11278.  
  11279. })();
  11280.  
  11281. }
  11282.  
  11283.  
  11284. if (doMouseHook) {
  11285.  
  11286. hookDocumentMouseDownSetupFn();
  11287.  
  11288. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  11289. }
  11290.  
  11291. console.log("[End]");
  11292.  
  11293. console.groupEnd();
  11294.  
  11295.  
  11296. }).catch(console.warn);
  11297.  
  11298.  
  11299. // https://www.youtube.com/watch?v=oQzFi1NO7io
  11300.  
  11301.  
  11302. }
  11303.  
  11304. if (NO_ITEM_TAP_FOR_NON_STATIONARY_TAP) {
  11305. let targetElementCntWR = null;
  11306. let _e0 = null;
  11307. document.addEventListener('mousedown', (e) => {
  11308. if (!e || !e.isTrusted) return;
  11309. let element = e.target;
  11310. for (; element instanceof HTMLElement; element = element.parentNode) {
  11311. if (element.is) break;
  11312. }
  11313. if (!element || !element.is) return;
  11314. const cnt = insp(element);
  11315. if (typeof cnt.onItemTap === 'function') {
  11316. cnt._onItemTap_isNonStationary = 0;
  11317. const cProto = getProto(element);
  11318. if (!cProto.onItemTap366 && typeof cProto.onItemTap === 'function' && cProto.onItemTap.length === 1) {
  11319. cProto.onItemTap366 = cProto.onItemTap; // note: [onItemTap] .some(function(){...})
  11320. cProto.onItemTap = function (a) {
  11321. const t = this._onItemTap_isNonStationary;
  11322. this._onItemTap_isNonStationary = 0;
  11323. if (t > Date.now()) return;
  11324. return this.onItemTap366.apply(this, arguments)
  11325. }
  11326. }
  11327. _e0 = e;
  11328. targetElementCntWR = mWeakRef(cnt);
  11329. } else {
  11330. _e0 = null;
  11331. targetElementCntWR = null;
  11332. }
  11333. }, { capture: true, passive: true });
  11334.  
  11335. document.addEventListener('mouseup', (e) => {
  11336. if (!e || !e.isTrusted) return;
  11337. const e0 = _e0;
  11338. _e0 = null;
  11339. if (!e0) return;
  11340. const cnt = kRef(targetElementCntWR);
  11341. targetElementCntWR = null;
  11342. if (!cnt) return;
  11343. if (e.timeStamp - e0.timeStamp > TAP_ACTION_DURATION) {
  11344. cnt._onItemTap_isNonStationary = Date.now() + 40;
  11345. } else if ((window.getSelection() + "").trim().replace(/[\u2000-\u200a\u202f\u2800\u200B\u200C\u200D\uFEFF]+/g, '').length >= 1) {
  11346. cnt._onItemTap_isNonStationary = Date.now() + 40;
  11347. } else {
  11348. const dx = e.clientX - e0.clientX;
  11349. const dy = e.clientY - e0.clientY;
  11350. const dd = Math.sqrt(dx * dx + dy * dy);
  11351. const ddmm = px2mm(dd);
  11352. if (ddmm > 1.0) {
  11353. cnt._onItemTap_isNonStationary = Date.now() + 40;
  11354. } else {
  11355. cnt._onItemTap_isNonStationary = 0;
  11356. }
  11357. }
  11358. }, { capture: true, passive: true });
  11359.  
  11360. }
  11361.  
  11362.  
  11363. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  11364.  
  11365. let rr = null;
  11366. const p1 = new Promise(resolve => {
  11367. rr = resolve;
  11368. });
  11369.  
  11370. const p1unlock = () => {
  11371. const f = rr;
  11372. if (f) {
  11373. rr = null;
  11374. f();
  11375. }
  11376. }
  11377.  
  11378. return {
  11379. p1,
  11380. p1unlock,
  11381. assignLock: (targetCnt, timeout) => {
  11382. targetCnt.__showContextMenu_assign_lock__(p1);
  11383. if (timeout) setTimeout(p1unlock, timeout);
  11384. }
  11385. }
  11386.  
  11387. }
  11388.  
  11389. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  11390.  
  11391. document.addEventListener('mousedown', function (evt) {
  11392.  
  11393. const maxloopDOMTreeElements = 4;
  11394. const maxloopYtCompontents = 4;
  11395. let j1 = 0;
  11396. let j2 = 0;
  11397. let target = (evt || 0).target || 0;
  11398. if (!target) return;
  11399.  
  11400.  
  11401. while (target instanceof HTMLElement) {
  11402. if (++j1 > maxloopDOMTreeElements) break;
  11403. if (typeof (target.is || insp(target).is || null) === 'string') break;
  11404. target = nodeParent(target);
  11405. }
  11406. const components = [];
  11407. while (target instanceof HTMLElement) {
  11408. if (++j2 > maxloopYtCompontents) break;
  11409. const cnt = insp(target);
  11410. if (typeof (target.is || cnt.is || null) === 'string') {
  11411. components.push(target);
  11412. }
  11413. if (typeof cnt.showContextMenu === 'function') break;
  11414. target = target.parentComponent || cnt.parentComponent || null;
  11415. }
  11416. if (!(target instanceof HTMLElement)) return;
  11417. const targetCnt = insp(target);
  11418. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  11419. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  11420. return;
  11421. }
  11422.  
  11423. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  11424. if (!endpoint) return;
  11425. if (targetCnt.opened || !targetCnt.isAttached) return;
  11426.  
  11427. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  11428. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  11429. }
  11430.  
  11431. const targetDollar = indr(target);
  11432.  
  11433. let doPreRequest = false;
  11434. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  11435. doPreRequest = true;
  11436. } else if (components.length === 1 && components[0] === target) {
  11437. doPreRequest = true;
  11438. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  11439. doPreRequest = true;
  11440. }
  11441. if (doPreRequest === false) {
  11442. console.log('doPreRequest = fasle on showContextMenu', components);
  11443. return;
  11444. }
  11445.  
  11446. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  11447.  
  11448. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  11449. console.log('preRequest on showContextMenu aborted due to stacked network request');
  11450. return;
  11451. }
  11452.  
  11453.  
  11454. const onSuccess = (a) => {
  11455. /*
  11456.  
  11457. dQ() && (a = a.response);
  11458. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  11459. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  11460.  
  11461. */
  11462.  
  11463. a = a.response || a;
  11464.  
  11465. if (!a) {
  11466. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  11467. return;
  11468. }
  11469.  
  11470. let z = null;
  11471. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  11472.  
  11473. if (z) {
  11474. a = z;
  11475. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  11476. }
  11477.  
  11478. };
  11479. const onFailure = (a) => {
  11480.  
  11481. /*
  11482.  
  11483. if (a instanceof Error || a instanceof Object || a instanceof String)
  11484. var b = a;
  11485. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  11486.  
  11487. */
  11488.  
  11489. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  11490. // console.log('onFailure', a)
  11491.  
  11492. };
  11493.  
  11494. if (doPreRequest) {
  11495.  
  11496. let propertyCounter = 0;
  11497. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  11498. const p1Timeout = 800;
  11499. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  11500.  
  11501. try {
  11502.  
  11503. const onSuccessHelperFn = function () {
  11504. pm1.p1unlock();
  11505. if (propertyCounter !== 5) {
  11506. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  11507. return;
  11508. }
  11509. if (this[proxyKey] !== targetCnt) {
  11510. console.log('Error in prerequest for showContextMenu.this');
  11511. return;
  11512. }
  11513. onSuccess(...arguments);
  11514. };
  11515. const onFailureHelperFn = function () {
  11516. pm1.p1unlock();
  11517. if (propertyCounter !== 5) {
  11518. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  11519. return;
  11520. }
  11521. if (this[proxyKey] !== targetCnt) {
  11522. console.log('Error in prerequest for showContextMenu.this');
  11523. return;
  11524. }
  11525. onFailure(...arguments);
  11526.  
  11527. }
  11528. const fakeTargetCnt = new Proxy({
  11529. __showContextMenu_forceNativeRequest__: 1,
  11530. get handleGetContextMenuResponse_() {
  11531. propertyCounter += 2;
  11532. return onSuccessHelperFn;
  11533. },
  11534. get handleGetContextMenuError() {
  11535. propertyCounter += 3;
  11536. return onFailureHelperFn;
  11537. }
  11538. }, {
  11539. get(_, key, receiver) {
  11540. if (key in _) return _[key];
  11541. if (key === proxyKey) return targetCnt;
  11542.  
  11543. let giveNative = false;
  11544. if (key in targetCnt) {
  11545. if (key === 'data') giveNative = true;
  11546. else if (typeof targetCnt[key] === 'function') giveNative = true;
  11547. }
  11548. if (giveNative) return targetCnt[key];
  11549. }
  11550. });
  11551.  
  11552. const fakeEvent = (() => {
  11553. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  11554. const nf = function () { }
  11555. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  11556.  
  11557. return {
  11558. type: 'tap',
  11559. eventPhase: 0,
  11560. isTrusted: false,
  11561. __composed: true,
  11562. bubbles, cancelable, cancelBubble, timeStamp,
  11563. target, srcElement, defaultPrevented, currentTarget, composed,
  11564. stopPropagation, stopImmediatePropagation, preventDefault
  11565. };
  11566. })(evt);
  11567. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  11568.  
  11569.  
  11570. } catch (e) {
  11571. console.warn(e);
  11572. propertyCounter = 7;
  11573.  
  11574. }
  11575. if (propertyCounter !== 5) {
  11576. console.log('Error in prerequest for showContextMenu', propertyCounter);
  11577. return;
  11578. }
  11579.  
  11580. pm1.assignLock(targetCnt, p1Timeout);
  11581.  
  11582. }
  11583.  
  11584.  
  11585.  
  11586.  
  11587.  
  11588.  
  11589. }, true);
  11590.  
  11591.  
  11592. }
  11593.  
  11594.  
  11595.  
  11596. /*
  11597.  
  11598. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  11599.  
  11600. */
  11601.  
  11602. whenDefinedMultiple([
  11603. "yt-live-chat-ticker-sponsor-item-renderer",
  11604. "yt-live-chat-ticker-paid-message-item-renderer",
  11605.  
  11606. "yt-live-chat-banner-header-renderer",
  11607. "yt-live-chat-text-message-renderer",
  11608. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  11609. "ytd-sponsorships-live-chat-header-renderer",
  11610. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  11611.  
  11612. "yt-live-chat-paid-sticker-renderer",
  11613. "yt-live-chat-viewer-engagement-message-renderer",
  11614. "yt-live-chat-paid-message-renderer"
  11615.  
  11616.  
  11617.  
  11618.  
  11619. ]).then(sTags => {
  11620.  
  11621. if (FLAG_001f) return;
  11622.  
  11623. mightFirstCheckOnYtInit();
  11624. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  11625. console.log("[Begin]");
  11626.  
  11627.  
  11628. const __showContextMenu_mutex__ = new Mutex();
  11629. let __showContextMenu_mutex_unlock__ = null;
  11630. let lastShowMenuTarget = null;
  11631.  
  11632.  
  11633.  
  11634.  
  11635. const wm37 = new WeakMap();
  11636.  
  11637. const dProto = {
  11638.  
  11639.  
  11640. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  11641.  
  11642. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  11643. if (a) {
  11644. if (doDeepCopy) a = deepCopy(a);
  11645. wm37.set(endpoint, a);
  11646. } else {
  11647. wm37.remove(endpoint);
  11648. }
  11649. },
  11650. __getCachedEndpointData__: function (endpoint) {
  11651. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  11652. if (endpoint) return wm37.get(endpoint);
  11653. return null;
  11654. },
  11655. /** @type {(resolvedEndpoint: any) => void 0} */
  11656. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  11657.  
  11658. resolvedEndpoint = deepCopy(resolvedEndpoint);
  11659. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  11660. Promise.resolve(resolvedEndpoint).then((resolvedEndpoint) => {
  11661. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  11662. this.showContextMenu_(resolvedEndpoint);
  11663. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  11664. resolvedEndpoint = null;
  11665. });
  11666.  
  11667.  
  11668. },
  11669.  
  11670.  
  11671.  
  11672. showContextMenuForCacheReopen: function (a) {
  11673. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37(a);
  11674. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  11675. if (!this.__showContextMenu_forceNativeRequest__) {
  11676. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  11677. if (endpoint) {
  11678. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  11679. if (resolvedEndpoint) {
  11680. this.__showCachedContextMenu__(resolvedEndpoint);
  11681. a && a.stopPropagation()
  11682. return;
  11683. }
  11684. }
  11685. }
  11686. return this.showContextMenu37(a);
  11687. },
  11688.  
  11689. showContextMenuForCacheReopen_: function (a) {
  11690. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37_(a);
  11691. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  11692. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  11693. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  11694. if (endpoint) {
  11695. const f = this.__cacheResolvedEndpointData__;
  11696. if (typeof f === 'function') f(endpoint, a, true);
  11697. }
  11698. }
  11699. return this.showContextMenu37_(a);
  11700. },
  11701.  
  11702. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  11703.  
  11704. showContextMenuWithDisableScroll: function (a) {
  11705.  
  11706. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  11707. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  11708.  
  11709. const parentComponent = this.parentComponent;
  11710. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  11711. parentComponent.contextMenuOpen = true; // computeAllowScroll_(contextMenuOpen, moderationModeEnabled): allowScroll = !(contextMenuOpen || moderationModeEnabled)
  11712. }
  11713. }
  11714.  
  11715. return this.showContextMenu48.apply(this, arguments);
  11716.  
  11717. },
  11718.  
  11719. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  11720.  
  11721. __showContextMenu_mutex_unlock_isEmpty__: () => {
  11722. return __showContextMenu_mutex_unlock__ === null;
  11723. },
  11724.  
  11725. __showContextMenu_assign_lock__: function (p) {
  11726.  
  11727. const mutex = __showContextMenu_mutex__;
  11728.  
  11729. mutex.lockWith(unlock => {
  11730. p.then(unlock);
  11731. p = null;
  11732. unlock = null;
  11733. });
  11734.  
  11735. },
  11736.  
  11737. showContextMenuWithMutex: function (a) {
  11738. if (this.__showContextMenu_forceNativeRequest__) return this.showContextMenu47(a);
  11739. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  11740. lastShowMenuTarget = this;
  11741. const wNode = mWeakRef(this);
  11742.  
  11743.  
  11744. const mutex = __showContextMenu_mutex__;
  11745.  
  11746. mutex.lockWith(unlock => {
  11747. const cnt = kRef(wNode);
  11748. if (lastShowMenuTarget !== cnt || !cnt) {
  11749. unlock();
  11750. return;
  11751. }
  11752.  
  11753. setTimeout(unlock, 800); // in case network failure
  11754. __showContextMenu_mutex_unlock__ = unlock;
  11755. try {
  11756. cnt.showContextMenu47(a);
  11757. } catch (e) {
  11758. console.warn(e);
  11759. unlock(); // in case function script error
  11760. }
  11761.  
  11762. });
  11763.  
  11764.  
  11765. },
  11766.  
  11767. showContextMenuWithMutex_: function (a) {
  11768.  
  11769. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  11770. __showContextMenu_mutex_unlock__();
  11771. __showContextMenu_mutex_unlock__ = null;
  11772. }
  11773. return this.showContextMenu47_(a);
  11774.  
  11775. }
  11776.  
  11777. }
  11778.  
  11779. for (const tag of sTags) { // ##tag##
  11780.  
  11781. (() => {
  11782.  
  11783. const dummy = document.createElement(tag);
  11784.  
  11785. const cProto = getProto(dummy);
  11786. if (!cProto || !cProto.attached) {
  11787. console.warn(`proto.attached for ${tag} is unavailable.`);
  11788. return;
  11789. }
  11790.  
  11791.  
  11792. 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) {
  11793. cProto.showContextMenu37_ = cProto.showContextMenu_;
  11794. cProto.showContextMenu37 = cProto.showContextMenu;
  11795. cProto.__showContextMenu_forceNativeRequest__ = 0;
  11796. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  11797. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  11798. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  11799. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  11800. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  11801. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  11802. } else {
  11803. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  11804. }
  11805.  
  11806. 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) {
  11807. cProto.showContextMenu48 = cProto.showContextMenu;
  11808. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  11809. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  11810. } else if (!ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU) {
  11811. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - N/A", tag);
  11812. } else {
  11813. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  11814. }
  11815.  
  11816.  
  11817. 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) {
  11818. cProto.showContextMenu47_ = cProto.showContextMenu_;
  11819. cProto.showContextMenu47 = cProto.showContextMenu;
  11820. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  11821. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  11822. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  11823. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  11824. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  11825. } else {
  11826. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  11827. }
  11828.  
  11829. })();
  11830.  
  11831. }
  11832.  
  11833. console.log("[End]");
  11834.  
  11835. console.groupEnd();
  11836.  
  11837. }).catch(console.warn);
  11838.  
  11839.  
  11840.  
  11841. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  11842.  
  11843. mightFirstCheckOnYtInit();
  11844. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  11845. console.log("[Begin]");
  11846. (() => {
  11847.  
  11848. const tag = "tp-yt-iron-dropdown";
  11849. const dummy = document.createElement(tag);
  11850.  
  11851. const cProto = getProto(dummy);
  11852. if (!cProto || !cProto.attached) {
  11853. console.warn(`proto.attached for ${tag} is unavailable.`);
  11854. return;
  11855. }
  11856.  
  11857. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  11858. cProto.__deraf_hn__ = function (sId, fn) {
  11859. const rhKey = `_rafHandler_${sId}`;
  11860. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  11861. if (m.has(fn)) return m.get(fn);
  11862. const resFn = () => {
  11863. this.__rafs[sId] = null;
  11864. fn.call(this)
  11865. };
  11866. m.set(fn, resFn);
  11867. m.set(resFn, resFn);
  11868. return resFn;
  11869. };
  11870. cProto.__deraf34 = cProto.__deraf;
  11871. cProto.__deraf = function (a, b) { // sId, fn
  11872. let c = this.__rafs;
  11873. null !== c[a] && cancelAnimationFrame(c[a]);
  11874. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  11875. };
  11876. console.log("USE_VANILLA_DEREF - OK");
  11877. } else {
  11878. console.log("USE_VANILLA_DEREF - NG");
  11879. }
  11880.  
  11881. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  11882. cProto.__deraf66 = cProto.__deraf;
  11883. cProto.__deraf = function (sId, fn) {
  11884. if (this.__byPassRAF__) {
  11885. Promise.resolve(this).then((cnt) => {
  11886. fn.call(cnt);
  11887. cnt = null;
  11888. });
  11889. }
  11890. let r = this.__deraf66.apply(this, arguments);
  11891. return r;
  11892. }
  11893. console.log("FIX_DROPDOWN_DERAF - OK");
  11894. } else {
  11895. console.log("FIX_DROPDOWN_DERAF - NG");
  11896. }
  11897.  
  11898.  
  11899. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  11900.  
  11901. let lastClose = null;
  11902. let lastOpen = null;
  11903. let cid = 0;
  11904.  
  11905. cProto.__mtChanged__ = function (b) {
  11906.  
  11907. Promise.resolve(this).then((cnt) => {
  11908. cnt._applyFocus();
  11909. return cnt;
  11910. }).then((cnt) => {
  11911. b ? cnt._renderOpened() : cnt._renderClosed();
  11912. cnt = null;
  11913. }).catch(console.warn);
  11914.  
  11915. };
  11916.  
  11917. const __moChanged__ = () => {
  11918. if (!cid) return;
  11919. // console.log(553, !!lastOpen, !!lastClose);
  11920. cid = 0;
  11921. if (lastOpen && !lastClose && lastOpen.isAttached) {
  11922. lastOpen.__mtChanged__(1)
  11923. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  11924. lastClose.__mtChanged__(0);
  11925. }
  11926. lastOpen = null;
  11927. lastClose = null;
  11928. };
  11929.  
  11930.  
  11931. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  11932. cProto._openedChanged66 = cProto._openedChanged;
  11933. cProto._openedChanged = function () {
  11934. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  11935. this.__byPassRAF__ = true;
  11936. let r = this._openedChanged66.apply(this, arguments);
  11937. this.__byPassRAF__ = false;
  11938. return r;
  11939. }
  11940. }
  11941.  
  11942. const pSetGet = (key, pdThis, pdBase) => {
  11943. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  11944. return {
  11945. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  11946. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  11947. };
  11948. };
  11949.  
  11950. cProto.__modifiedMenuPropsFn__ = function () {
  11951. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  11952. const pdBase = Object.getOwnPropertyDescriptors(this)
  11953.  
  11954. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  11955. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  11956. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  11957.  
  11958. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  11959. console.warn('there is setter/getter for autoFitOnAttach');
  11960. return;
  11961. }
  11962. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  11963. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  11964. return;
  11965. }
  11966. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  11967. console.warn('there is NO setter-getter for allowOutsideScroll');
  11968. return;
  11969. }
  11970.  
  11971. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  11972.  
  11973. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  11974.  
  11975. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  11976.  
  11977. Object.defineProperties(this, {
  11978. autoFitOnAttach: {
  11979. get() {
  11980. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  11981. return autoFitOnAttach;
  11982. },
  11983. set(nv) {
  11984. autoFitOnAttach = nv;
  11985. return true;
  11986. },
  11987. enumerable: true,
  11988. configurable: true
  11989. }, expandSizingTargetForScrollbars: {
  11990. get() {
  11991. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  11992. return expandSizingTargetForScrollbars;
  11993. },
  11994. set(nv) {
  11995. expandSizingTargetForScrollbars = nv;
  11996. return true;
  11997. },
  11998. enumerable: true,
  11999. configurable: true
  12000. }, allowOutsideScroll: {
  12001. get() {
  12002. if (this._modifiedMenuPropOn062__) return true;
  12003. return allowOutsideScroll;
  12004. },
  12005. set(nv) {
  12006. allowOutsideScroll = nv;
  12007. this.__AllowOutsideScrollPD__.set.call(this, nv);
  12008. return true;
  12009. },
  12010. enumerable: true,
  12011. configurable: true
  12012. }
  12013. })
  12014. };
  12015.  
  12016. /*
  12017. // ***** position() to be changed. *****
  12018. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  12019.  
  12020. overflow: visible !important;
  12021. min-width: max-content !important;
  12022. max-width: max-content !important;
  12023. max-height: max-content !important;
  12024. min-height: max-content !important;
  12025. white-space: nowrap;
  12026. }
  12027.  
  12028. */
  12029. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  12030.  
  12031. let m34 = 0;
  12032. cProto.__refitByPosition__ = function () {
  12033. m34++;
  12034. if (m34 <= 0) m34 = 0;
  12035. if (m34 !== 1) return;
  12036. const hostElement = this.hostElement || this;
  12037. if (document.visibilityState === 'visible') {
  12038. const sizingTarget = this.sizingTarget;
  12039. if (!sizingTarget) {
  12040. m34 = 0;
  12041. return;
  12042. }
  12043. hostElement.setAttribute('rNgzQ', '');
  12044. sizingTarget.setAttribute('rNgzQ', '');
  12045.  
  12046. const gn = () => {
  12047. hostElement.removeAttribute('rNgzQ');
  12048. sizingTarget.removeAttribute('rNgzQ');
  12049. }
  12050.  
  12051. const an = async () => {
  12052. while (m34 >= 1) {
  12053. await renderReadyPn(sizingTarget);
  12054. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  12055. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  12056. }
  12057. m34--;
  12058. }
  12059. m34 = 0;
  12060. Promise.resolve().then(gn);
  12061. }
  12062. setTimeout(an, 4); // wait those resizing function calls
  12063.  
  12064.  
  12065. } else {
  12066. m34 = 0;
  12067. }
  12068. }
  12069. cProto.position34 = cProto.position
  12070. cProto.position = function () {
  12071. if (this._positionInitialize_) {
  12072. this._positionInitialize_ = 0;
  12073. this.__refitByPosition__();
  12074. }
  12075. let r = cProto.position34.apply(this, arguments);
  12076. return r;
  12077. }
  12078. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  12079.  
  12080. } else {
  12081.  
  12082. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  12083.  
  12084. }
  12085.  
  12086.  
  12087.  
  12088. cProto.__openedChanged = function () {
  12089. this._positionInitialize_ = 1;
  12090. // this.removeAttribute('horizontal-align')
  12091. // this.removeAttribute('vertical-align')
  12092. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  12093. this.__menuTypeCheck__ = true;
  12094. if (CHAT_MENU_SCROLL_UNLOCKING) {
  12095. this._modifiedMenuPropOn062__ = false;
  12096. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  12097. // this.autoFitOnAttach = true;
  12098. // this.expandSizingTargetForScrollbars = true;
  12099. // this.allowOutsideScroll = true;
  12100. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  12101. this.__modifiedMenuPropsFn__();
  12102. // this.constrain= function(){}
  12103. // this.position= function(){}
  12104.  
  12105. // this.autoFitOnAttach = true;
  12106. // this.expandSizingTargetForScrollbars = true;
  12107. // this.allowOutsideScroll = true;
  12108. }
  12109. }
  12110. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  12111. let newValue = null;
  12112. const positionTarget = this.positionTarget;
  12113. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  12114. if (this._modifiedMenuPropOn062__ === false) {
  12115. newValue = true;
  12116. }
  12117. } else if (this._modifiedMenuPropOn062__ === true) {
  12118. newValue = false;
  12119. }
  12120. if (newValue !== null) {
  12121. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  12122. this._modifiedMenuPropOn062__ = newValue;
  12123. const afterAllowOutsideScroll = this.allowOutsideScroll;
  12124. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  12125. }
  12126. }
  12127.  
  12128. if (this.opened) {
  12129.  
  12130. Promise.resolve().then(() => {
  12131.  
  12132. this._prepareRenderOpened();
  12133. }).then(() => {
  12134. this._manager.addOverlay(this);
  12135. if (this._manager._overlays.length === 1) {
  12136. lastOpen = this;
  12137. lastClose = null;
  12138. } else {
  12139. return 1;
  12140. }
  12141. // if (cid) {
  12142. // clearTimeout(cid);
  12143. // cid = -1;
  12144. // this.__moChanged__();
  12145. // cid = 0;
  12146. // } else {
  12147. // cid = -1;
  12148. // this.__moChanged__();
  12149. // cid = 0;
  12150. // }
  12151. // cid = cid > 0 ? clearTimeout(cid) : 0;
  12152. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  12153. // cid = cid || setTimeout(__moChanged__, delay1);
  12154. cid = cid || requestAnimationFrame(__moChanged__);
  12155. }).then((r) => {
  12156.  
  12157. if (r) this.__mtChanged__(1);
  12158. }).catch(console.warn);
  12159.  
  12160. } else {
  12161. Promise.resolve().then(() => {
  12162. this._manager.removeOverlay(this);
  12163. if (this._manager._overlays.length === 0) {
  12164. lastClose = this;
  12165. lastOpen = null;
  12166. } else {
  12167. return 1;
  12168. }
  12169. // cid = cid > 0 ? clearTimeout(cid) : 0;
  12170. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  12171. // cid = cid || setTimeout(__moChanged__, delay1);
  12172. cid = cid || requestAnimationFrame(__moChanged__);
  12173. }).then((r) => {
  12174. if (r) this.__mtChanged__(0);
  12175. }).catch(console.warn);
  12176.  
  12177. }
  12178.  
  12179. }
  12180. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  12181.  
  12182. } else {
  12183.  
  12184. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  12185. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  12186.  
  12187. }
  12188.  
  12189.  
  12190. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  12191.  
  12192. cProto.__openedChanged82 = cProto.__openedChanged;
  12193.  
  12194.  
  12195. cProto.__openedChanged = function () {
  12196. const positionTarget = this.positionTarget;
  12197. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  12198. return this.__openedChanged82.apply(this, arguments);
  12199. }
  12200. }
  12201.  
  12202.  
  12203. })();
  12204.  
  12205. console.log("[End]");
  12206.  
  12207. console.groupEnd();
  12208.  
  12209. }).catch(console.warn);
  12210.  
  12211.  
  12212.  
  12213. FIX_ToggleRenderPolymerControllerExtractionBug && customElements.whenDefined('yt-live-chat-toggle-renderer').then(() => {
  12214.  
  12215. mightFirstCheckOnYtInit();
  12216. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-toggle-renderer hacks");
  12217. console.log("[Begin]");
  12218. (() => {
  12219.  
  12220. const tag = "yt-live-chat-toggle-renderer";
  12221. const dummy = document.createElement(tag);
  12222.  
  12223. const cProto = getProto(dummy);
  12224. if (!cProto || !cProto.attached) {
  12225. console.warn(`proto.attached for ${tag} is unavailable.`);
  12226. return;
  12227. }
  12228.  
  12229. })();
  12230.  
  12231. console.log("[End]");
  12232. console.groupEnd();
  12233.  
  12234. });
  12235.  
  12236.  
  12237.  
  12238.  
  12239. /*
  12240.  
  12241.  
  12242.  
  12243.  
  12244.  
  12245. var FU = function() {
  12246. var a = this;
  12247. this.nextHandle_ = 1;
  12248. this.clients_ = {};
  12249. this.JSC$10323_callbacks_ = {};
  12250. this.unsubscribeAsyncHandles_ = {};
  12251. this.subscribe = vl(function(b, c, d) {
  12252. var e = Geb(b);
  12253. if (e in a.clients_)
  12254. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  12255. else {
  12256. a: {
  12257. var h = Geb(b), l;
  12258. for (l in a.unsubscribeAsyncHandles_) {
  12259. var m = a.clients_[l];
  12260. if (m instanceof KO) {
  12261. delete a.clients_[l];
  12262. delete a.JSC$10323_callbacks_[l];
  12263. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  12264. delete a.unsubscribeAsyncHandles_[l];
  12265. i6a(m);
  12266. m.objectId_ = new FQa(h);
  12267. m.register();
  12268. d = m;
  12269. break a
  12270. }
  12271. }
  12272. d.objectSource = b.invalidationId.objectSource;
  12273. d.objectId = h;
  12274. if (b = b.webAuthConfigurationData)
  12275. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  12276. b.pageId && (d.pageId = b.pageId);
  12277. d = new KO(d,a.handleInvalidationData_.bind(a));
  12278. d.register()
  12279. }
  12280. a.clients_[e] = d;
  12281. a.JSC$10323_callbacks_[e] = {}
  12282. }
  12283. d = a.nextHandle_++;
  12284. a.JSC$10323_callbacks_[e][d] = c;
  12285. return d
  12286. })
  12287. };
  12288. FU.prototype.unsubscribe = function(a, b) {
  12289. var c = Geb(a);
  12290. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  12291. !this.JSC$10323_callbacks_[c].length)) {
  12292. var d = this.clients_[c];
  12293. b = Jq.run(function() {
  12294. ei(d);
  12295. delete this.clients_[c];
  12296. delete this.unsubscribeAsyncHandles_[c]
  12297. }
  12298. .bind(this));
  12299. this.unsubscribeAsyncHandles_[c] = b
  12300. }
  12301. }
  12302. ;
  12303.  
  12304.  
  12305. */
  12306.  
  12307.  
  12308. const onManagerFound = (dummyManager) => {
  12309. if (!dummyManager || typeof dummyManager !== 'object') return;
  12310.  
  12311. const mgrProto = dummyManager.constructor.prototype;
  12312.  
  12313. let keyCallbackStore = '';
  12314. for (const [key, v] of Object.entries(dummyManager)) {
  12315. if (key.includes('_callbacks_')) keyCallbackStore = key;
  12316. }
  12317.  
  12318. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  12319.  
  12320. if (mgrProto.unsubscribe16) return;
  12321.  
  12322. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  12323.  
  12324. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  12325. console.log("[Begin]");
  12326.  
  12327. const isEmptyObject = ((obj) => (firstKey(obj) === null));
  12328.  
  12329. const idMapper = new Map();
  12330.  
  12331. const convertId = function (objectId) {
  12332. if (!objectId || typeof objectId !== 'string') return null;
  12333.  
  12334. let result = idMapper.get(objectId)
  12335. if (result) return result;
  12336. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  12337. idMapper.set(objectId, result)
  12338. return result;
  12339. }
  12340.  
  12341.  
  12342. const rafHandleHolder = [];
  12343.  
  12344. let pzw = 0;
  12345. let lza = 0;
  12346. const rafHandlerFn = () => {
  12347. pzw = 0;
  12348. if (rafHandleHolder.length === 1) {
  12349. const f = rafHandleHolder[0];
  12350. rafHandleHolder.length = 0;
  12351. f();
  12352. } else if (rafHandleHolder.length > 1) {
  12353. const arr = rafHandleHolder.slice(0);
  12354. rafHandleHolder.length = 0;
  12355. for (const fn of arr) fn();
  12356. }
  12357. };
  12358.  
  12359.  
  12360. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  12361.  
  12362. const checkIntegrityForSubscribe = (mgr) => {
  12363. if (mgr
  12364. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  12365. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  12366.  
  12367. const ns = new Set(Object.keys(mgr));
  12368. const ms = new Set(Object.keys(mgr.constructor.prototype));
  12369.  
  12370. if (ns.size >= 6 && ms.size >= 4) {
  12371. // including 'subscribe18'
  12372. // 'unsubscribe16', 'subscribe19'
  12373.  
  12374. let r = 0;
  12375. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  12376. r += ns.has(k) ? 1 : 0;
  12377. }
  12378. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  12379. r += ms.has(k) ? 1 : 0;
  12380. }
  12381. if (r === 10) {
  12382. const isObject = (c) => (c || 0).constructor === Object;
  12383.  
  12384. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  12385.  
  12386. return true;
  12387. }
  12388.  
  12389.  
  12390. }
  12391.  
  12392. }
  12393.  
  12394.  
  12395. }
  12396. return false;
  12397. }
  12398.  
  12399. mgrProto.subscribe19 = function (o, f, opts) {
  12400.  
  12401. const ct_clients_ = this.clients_ || 0;
  12402. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  12403.  
  12404. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  12405.  
  12406. let objectId = ((o || 0).invalidationId || 0).objectId;
  12407. if (!objectId) return this.subscribe18.apply(this, arguments);
  12408. objectId = convertId(objectId);
  12409.  
  12410. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  12411.  
  12412. if (ct_clients_[objectId]) {
  12413. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  12414. }
  12415.  
  12416. return this.subscribe18.apply(this, arguments);
  12417. }
  12418.  
  12419. mgrProto.unsubscribe = function (o, d) {
  12420. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  12421. this.subscribe18 = this.subscribe;
  12422. this.subscribe = this.subscribe19;
  12423. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  12424. }
  12425. const ct_clients_ = this.clients_;
  12426. const ct_handles_ = this.unsubscribeAsyncHandles_;
  12427. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  12428.  
  12429. let objectId = ((o || 0).invalidationId || 0).objectId;
  12430. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  12431.  
  12432. objectId = convertId(objectId);
  12433.  
  12434.  
  12435. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  12436.  
  12437. const callbacks = this[keyCallbackStore] || 0;
  12438. const callbackObj = callbacks[objectId] || 0;
  12439.  
  12440.  
  12441. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  12442. const w = ct_clients_[objectId];
  12443. --lza;
  12444. if (lza < -1e9) lza = -1;
  12445. const qta = lza;
  12446. rafHandleHolder.push(() => {
  12447. if (qta === ct_handles_[objectId]) {
  12448. const o = {
  12449. callbacks, callbackObj,
  12450. client: ct_clients_[objectId],
  12451. handle: ct_handles_[objectId]
  12452. };
  12453. let p = 0;
  12454. try {
  12455. if (ct_clients_[objectId] === w) {
  12456. w && "function" === typeof w.dispose && w.dispose();
  12457. delete ct_clients_[objectId];
  12458. delete ct_handles_[objectId];
  12459. p = 1;
  12460. } else {
  12461. // w && "function" === typeof w.dispose && w.dispose();
  12462. // delete ct_clients_[objectId];
  12463. // delete ct_handles_[objectId];
  12464. p = 2;
  12465. }
  12466. } catch (e) {
  12467. console.warn(e);
  12468. }
  12469. console.log(`unsubscribed: ${p}`, this, o);
  12470. }
  12471. });
  12472. ct_handles_[objectId] = qta;
  12473. if (pzw === 0) {
  12474. pzw = requestAnimationFrame(rafHandlerFn);
  12475. }
  12476. }
  12477. }
  12478.  
  12479.  
  12480. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  12481.  
  12482. } else {
  12483.  
  12484. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  12485. }
  12486.  
  12487. console.log("[End]");
  12488.  
  12489. console.groupEnd();
  12490.  
  12491. }
  12492.  
  12493.  
  12494.  
  12495. /*
  12496.  
  12497.  
  12498. a.prototype.async = function(e, h) {
  12499. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  12500. }
  12501. ;
  12502. a.prototype.cancelAsync = function(e) {
  12503. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  12504. }
  12505.  
  12506. */
  12507.  
  12508.  
  12509. (FASTER_ICON_RENDERING && Promise.all(
  12510. [
  12511. customElements.whenDefined("yt-icon-shape"),
  12512. customElements.whenDefined("yt-icon")
  12513. // document.createElement('icon-shape'),
  12514. ]
  12515. )).then(() => {
  12516. let cq = 0;
  12517. let dummys = [document.createElement('yt-icon-shape'), document.createElement('yt-icon')]
  12518. for (const dummy of dummys) {
  12519. let cProto = getProto(dummy);
  12520. if (cProto && typeof cProto.shouldRenderIconShape === 'function' && !cProto.shouldRenderIconShape571 && cProto.shouldRenderIconShape.length === 1) {
  12521. assertor(() => fnIntegrity(cProto.shouldRenderIconShape, '1.70.38'));
  12522. cq++;
  12523. cProto.shouldRenderIconShape571 = cProto.shouldRenderIconShape;
  12524. cProto.shouldRenderIconShape = function (a) {
  12525. if (this.isAnimatedIcon) return this.shouldRenderIconShape571(a);
  12526. if (!this.iconType || !this.iconShapeData) return this.shouldRenderIconShape571(a);
  12527. if (!this.iconName) return this.shouldRenderIconShape571(a);
  12528. return false;
  12529. // console.log(1051, this.iconType)
  12530. // console.log(1052, this.iconShapeData)
  12531. // console.log(1053, this.isAnimatedIcon)
  12532. }
  12533. }
  12534. // if(cProto && cProto.switchTemplateAtRegistration){
  12535. // cProto.switchTemplateAtRegistration = false;
  12536. // }
  12537. }
  12538. if (cq === 1) {
  12539. console.log("modified shouldRenderIconShape - Y")
  12540. } else {
  12541. console.log("modified shouldRenderIconShape - N", cq)
  12542. }
  12543. });
  12544.  
  12545. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  12546.  
  12547. let __dummyManager__ = null;
  12548.  
  12549. mightFirstCheckOnYtInit();
  12550. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  12551. console.log("[Begin]");
  12552. (() => {
  12553.  
  12554. const tag = "yt-invalidation-continuation"
  12555. const dummy = document.createElement(tag);
  12556.  
  12557. const cProto = getProto(dummy);
  12558. if (!cProto || !cProto.attached) {
  12559. console.warn(`proto.attached for ${tag} is unavailable.`);
  12560. return;
  12561. }
  12562.  
  12563. const dummyManager = insp(dummy).manager_ || 0;
  12564. __dummyManager__ = dummyManager;
  12565.  
  12566. 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) {
  12567.  
  12568.  
  12569. const rafHub = new RAFHub();
  12570.  
  12571. rafHub.keepRAF = true;
  12572. cProto.async71 = cProto.async;
  12573. cProto.cancelAsync71 = cProto.cancelAsync;
  12574.  
  12575. // mostly for subscription timeoutMs 10000ms
  12576. let mcw = 1; // 1, 3, 5, ...
  12577. let arr = new Map();
  12578.  
  12579. let __asyncInited__ = 0;
  12580. let __timeoutStartId__ = null;
  12581. const __asyncInit__ = () => {
  12582.  
  12583. if (__asyncInited__) return;
  12584. __asyncInited__ = 1;
  12585.  
  12586. __timeoutStartId__ = setTimeout(() => { });
  12587. mcw = __timeoutStartId__ * 2 + 1;
  12588.  
  12589. setInterval(() => {
  12590.  
  12591. if (!arr.length) return;
  12592.  
  12593. const p = Date.now();
  12594. let deleteKeys = [];
  12595. arr.forEach((entry, key) => {
  12596.  
  12597.  
  12598. if (entry.cid === -1) {
  12599. entry.cid = -2;
  12600. } else if (entry.cid === -2) {
  12601.  
  12602. let offset = p - entry.add
  12603. if (offset < 0) offset = 0;
  12604. let delay2 = entry.delay - offset;
  12605. if (delay2 < 0) delay2 = 0;
  12606. entry.cid = setTimeout(entry.q(), delay2);
  12607. entry.q = null;
  12608.  
  12609. } else if (entry.add + entry.delay < p) {
  12610. deleteKeys.push(key);
  12611.  
  12612. }
  12613.  
  12614. })
  12615.  
  12616. for (const key of deleteKeys) arr.delete(key);
  12617.  
  12618. }, 2000)
  12619.  
  12620. }
  12621.  
  12622.  
  12623. cProto.async = function (e, h) {
  12624.  
  12625. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  12626.  
  12627. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  12628.  
  12629. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  12630.  
  12631.  
  12632. if (!this.__asyncInited__) {
  12633. this.__asyncInited__ = 1;
  12634. __asyncInit__();
  12635. }
  12636. mcw += 2; // 2K+3, 2K+4, ...
  12637. if (mcw > 1e9) mcw = mcw % 1e4;
  12638. const cid = mcw;
  12639. const q = () => {
  12640. return () => {
  12641. console.log('async h > 8000');
  12642. e.call(this);
  12643. }
  12644. }
  12645. // setTimeout(q, delay)
  12646. arr.set(cid, {
  12647. cid: -1, // -1 -> -2 -> cid
  12648. add: Date.now(),
  12649. q,
  12650. delay: h
  12651. });
  12652. // console.log('cid-async', cid)
  12653. return cid;
  12654.  
  12655. }
  12656.  
  12657.  
  12658. cProto.cancelAsync = function (e) {
  12659.  
  12660. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  12661.  
  12662. // console.log('cid-unasync', e)
  12663.  
  12664. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  12665.  
  12666. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  12667.  
  12668. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  12669.  
  12670. if (!arr.has(e)) return; // duplciated cancel
  12671.  
  12672. const entry = arr.get(e);
  12673. if (entry.cid < 0) {
  12674. entry.cid = 0;
  12675. arr.delete(e);
  12676. } else {
  12677. clearTimeout(entry.cid); // cid >= 1
  12678. entry.cid = 0;
  12679. arr.delete(e);
  12680. }
  12681.  
  12682. } else {
  12683.  
  12684. return this.cancelAsync71(e);
  12685.  
  12686. }
  12687.  
  12688. }
  12689.  
  12690. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  12691.  
  12692. } else if(!CHANGE_DATA_FLUSH_ASYNC){
  12693. console.log("CHANGE_DATA_FLUSH_ASYNC - N/A");
  12694. } else {
  12695. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  12696.  
  12697. }
  12698.  
  12699. })();
  12700.  
  12701. console.log("[End]");
  12702.  
  12703. console.groupEnd();
  12704.  
  12705.  
  12706.  
  12707. onManagerFound(__dummyManager__);
  12708.  
  12709. }).catch(console.warn);
  12710.  
  12711.  
  12712. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  12713.  
  12714. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  12715.  
  12716. mightFirstCheckOnYtInit();
  12717. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  12718. console.log("[Begin]");
  12719. (() => {
  12720.  
  12721. const tag = "yt-live-interactivity-component-background"
  12722. const dummy = document.createElement(tag);
  12723.  
  12724. const cProto = getProto(dummy);
  12725. if (!cProto || !cProto.attached) {
  12726. console.warn(`proto.attached for ${tag} is unavailable.`);
  12727. return;
  12728. }
  12729.  
  12730. cProto.__toStopAfterRun__ = function (hostElement) {
  12731. let mo = new MutationObserver(() => {
  12732. mo.disconnect();
  12733. mo.takeRecords();
  12734. mo = null;
  12735. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  12736. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  12737. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  12738. });
  12739. });
  12740. mo.observe(hostElement, { subtree: true, childList: true });
  12741. }
  12742.  
  12743. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  12744.  
  12745. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  12746. cProto.maybeLoadAnimationBackground = function () {
  12747. let toRun = true;
  12748. let stopAfterRun = false;
  12749. if (!this.__bypassDisableAnimationBackground__) {
  12750. let doFix = false;
  12751. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  12752. if (!this.lottieAnimation) {
  12753. doFix = true;
  12754. }
  12755. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  12756. doFix = true;
  12757. }
  12758. if (doFix) {
  12759. if (this.useAnimationBackground === true) {
  12760. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  12761. }
  12762. toRun = true;
  12763. stopAfterRun = true;
  12764. }
  12765. }
  12766. if (toRun) {
  12767. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  12768. this.__toStopAfterRun__(this.hostElement); // primary
  12769. }
  12770. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  12771. if (stopAfterRun && this.lottieAnimation) {
  12772. this.lottieAnimation.stop(); // fallback if no mutation
  12773. }
  12774. return r;
  12775. }
  12776. }
  12777.  
  12778. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - OK`);
  12779.  
  12780. } else {
  12781. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - NG`);
  12782.  
  12783. }
  12784.  
  12785. })();
  12786.  
  12787. console.log("[End]");
  12788.  
  12789. console.groupEnd();
  12790.  
  12791.  
  12792. }).catch(console.warn);
  12793.  
  12794. }
  12795.  
  12796.  
  12797. if (DELAY_FOCUSEDCHANGED) {
  12798.  
  12799. customElements.whenDefined("yt-live-chat-text-input-field-renderer").then(() => {
  12800.  
  12801.  
  12802. mightFirstCheckOnYtInit();
  12803. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-input-field-renderer hacks");
  12804. console.log("[Begin]");
  12805. (() => {
  12806.  
  12807. const tag = "yt-live-chat-text-input-field-renderer"
  12808. const dummy = document.createElement(tag);
  12809.  
  12810. const cProto = getProto(dummy);
  12811. if (!cProto || !cProto.attached) {
  12812. console.warn(`proto.attached for ${tag} is unavailable.`);
  12813. return;
  12814. }
  12815.  
  12816. if (DELAY_FOCUSEDCHANGED && typeof cProto.focusedChanged === 'function' && cProto.focusedChanged.length === 0 && !cProto.focusedChanged372) {
  12817. cProto.focusedChanged372 = cProto.focusedChanged;
  12818. cProto.focusedChanged = function () {
  12819. Promise.resolve(this).then((cnt) => {
  12820. if (cnt.isAttached === true) cnt.focusedChanged372();
  12821. });
  12822. }
  12823. }
  12824.  
  12825. })();
  12826.  
  12827. console.log("[End]");
  12828.  
  12829. console.groupEnd();
  12830.  
  12831. });
  12832.  
  12833. }
  12834.  
  12835.  
  12836. }
  12837.  
  12838.  
  12839.  
  12840.  
  12841. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  12842.  
  12843. const fixJsonParse = () => {
  12844.  
  12845. let p1 = window.onerror;
  12846.  
  12847. try {
  12848. JSON.parse("{}");
  12849. } catch (e) {
  12850. console.warn(e);
  12851. }
  12852.  
  12853. let p2 = window.onerror;
  12854.  
  12855. if (p1 !== p2) {
  12856.  
  12857.  
  12858. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  12859. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  12860. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  12861. );
  12862.  
  12863. 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://gf.qytechs.cn/scripts/473972-youtube-js-engine-tamer to fix the issue.\n");
  12864.  
  12865. console.groupEnd();
  12866.  
  12867. }
  12868.  
  12869. }
  12870.  
  12871. if (CHECK_JSONPRUNE) {
  12872. promiseForCustomYtElementsReady.then(fixJsonParse);
  12873. }
  12874.  
  12875. if(USE_ADVANCED_TICKING){ // if(END_ANIMATING_TICKERS){
  12876.  
  12877.  
  12878. // let lastElmW = null;
  12879.  
  12880. // document.addEventListener('transitionstart', (evt) => {
  12881.  
  12882. // if (evt.propertyName === 'width' && !evt.pseudoElement) {
  12883.  
  12884. // const elm = evt.target;
  12885. // let act = false;
  12886. // /*
  12887. // switch(elm.nodeName.toLowerCase()){
  12888.  
  12889. // case 'yt-live-chat-ticker-creator-goal-view-model':
  12890. // case 'yt-live-chat-ticker-paid-message-item-renderer':
  12891. // case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  12892.  
  12893. // case 'yt-live-chat-ticker-sponsor-item-renderer':
  12894. // act =true;
  12895. // break;
  12896.  
  12897.  
  12898. // }
  12899. // */
  12900. // if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  12901. // act = true;
  12902. // }
  12903. // if (act) {
  12904. // const lastElm = kRef(lastElmW);
  12905. // if (elm !== lastElm) {
  12906.  
  12907. // if (lastElm instanceof HTMLElement) {
  12908. // lastElm.classList.add('ticker-no-transition-time');
  12909. // }
  12910. // lastElmW = mWeakRef(elm);
  12911.  
  12912. // }
  12913.  
  12914.  
  12915. // }
  12916. // }
  12917.  
  12918. // }, true);
  12919.  
  12920.  
  12921.  
  12922. document.addEventListener('transitionend', (evt) => {
  12923.  
  12924. if (evt.propertyName && !evt.pseudoElement) {
  12925.  
  12926. const elm = evt.target;
  12927. const f = transitionEndAfterFnSimple.get(elm);
  12928. if (f) {
  12929. transitionEndAfterFnSimple.delete(elm);
  12930. f.resolve(evt.propertyName);
  12931. }
  12932. }
  12933.  
  12934. }, true);
  12935.  
  12936. /*
  12937.  
  12938. document.addEventListener('transitionend', (evt) => {
  12939.  
  12940. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  12941.  
  12942. const elm = evt.target;
  12943. let act = false;
  12944. /-*
  12945. switch(elm.nodeName.toLowerCase()){
  12946.  
  12947. case 'yt-live-chat-ticker-creator-goal-view-model':
  12948. case 'yt-live-chat-ticker-paid-message-item-renderer':
  12949. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  12950.  
  12951. case 'yt-live-chat-ticker-sponsor-item-renderer':
  12952. act =true;
  12953. break;
  12954.  
  12955.  
  12956. }
  12957. *-/
  12958. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  12959. act = true;
  12960. }
  12961. if (act) {
  12962. elm.style.transitionDuration = '0s';
  12963.  
  12964. }
  12965. }
  12966.  
  12967. }, true);
  12968.  
  12969.  
  12970. document.addEventListener('transitioncancel', (evt) => {
  12971.  
  12972. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  12973.  
  12974. const elm = evt.target;
  12975. let act = false;
  12976. /-*
  12977. switch(elm.nodeName.toLowerCase()){
  12978.  
  12979. case 'yt-live-chat-ticker-creator-goal-view-model':
  12980. case 'yt-live-chat-ticker-paid-message-item-renderer':
  12981. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  12982.  
  12983. case 'yt-live-chat-ticker-sponsor-item-renderer':
  12984. act =true;
  12985. break;
  12986.  
  12987.  
  12988. }
  12989. *-/
  12990. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  12991. act = true;
  12992. }
  12993. if (act) {
  12994. elm.style.transitionDuration = '0s';
  12995.  
  12996. }
  12997. }
  12998.  
  12999. }, true);
  13000.  
  13001. */
  13002.  
  13003.  
  13004. }
  13005.  
  13006. });
  13007.  
  13008.  
  13009.  
  13010. })({ IntersectionObserver });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址