YouTube 超快聊天

YouTube直播聊天的終極性能提升

安裝腳本?
作者推薦腳本

您可能也會喜歡 YouTube JS Engine Tamer

安裝腳本
  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.68.3
  4. // @license MIT
  5. // @name:ja YouTube スーパーファーストチャット
  6. // @name:zh-TW YouTube 超快聊天
  7. // @name:zh-CN YouTube 超快聊天
  8. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/super-fast-chat.png
  9. // @namespace UserScript
  10. // @match https://www.youtube.com/live_chat*
  11. // @match https://www.youtube.com/live_chat_replay*
  12. // @author CY Fung
  13. // @run-at document-start
  14. // @grant none
  15. // @unwrap
  16. // @allFrames true
  17. // @inject-into page
  18. // @require https://update.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 = +localStorage.__debugSuperFastChat__ > 0;
  47. const DEBUG_LOG_HIDE_OK = true;
  48. const DEBUG_skipLog001 = true;
  49. const DEBUG_preprocessChatLiveActions = false;
  50. const DEBUG_customCreateComponent = false;
  51. // const SHOW_DEVTOOL_DEBUG = true; // for debug use
  52. const SHOW_DEVTOOL_DEBUG = typeof ResizeObserver === 'function' && CSS.supports('position-area:center');
  53.  
  54. // *********** DON'T REPORT NOT WORKING DUE TO THE CHANGED SETTINGS ********************
  55. // 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
  56.  
  57. 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
  58. 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)
  59. 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)
  60.  
  61. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages <<< DON'T CHANGE >>>
  62. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  63. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  64.  
  65. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  66. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  67. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  68. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  69.  
  70. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  71. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  72.  
  73. // Replace requestAnimationFrame timers with custom implementation
  74. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  75. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  76. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  77. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  78.  
  79. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  80. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  81.  
  82. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  83. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  84.  
  85. // Data Manipulation for Participants (Participant List)
  86. // << if DO_PARTICIPANT_LIST_HACKS >>
  87. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  88. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  89. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  90. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  91. // << end >>
  92.  
  93. // show more button
  94. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  95.  
  96. // faster stampDomArray_ for participants list creation
  97. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  98. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  99.  
  100. // reuse yt components
  101. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  102.  
  103. // ShadyDom Free is buggy
  104. const DISABLE_FLAGS_SHADYDOM_FREE = true;
  105.  
  106. // images <Group#I01>
  107. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  108. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  109. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  110.  
  111. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  112. // << if DO_LINK_PREFETCH >>
  113. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  114. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  115. const SKIP_PRELOAD_EMOJI = true;
  116. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  117. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  118. // << end >>
  119.  
  120. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  121. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  122. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  123.  
  124. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  125. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  126.  
  127. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  128. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  129. // (( KEEP AS ALTERNATIVE IF USE_ADVANCED_TICKING NOT WORKING ))
  130. // [limiting 500 max steps] is recommended for "confortable visual change"
  131. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  132. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  133. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  134. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  135. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  136. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  137. 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
  138. // << end >>
  139.  
  140. const FIX_TOOLTIP_DISPLAY = true; // changed in 2024.05.02; updated in 2025.01.10
  141. const USE_VANILLA_DEREF = true;
  142. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  143.  
  144.  
  145. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  146. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = false; // pause auto scroll faster when the context menu is about to show
  147. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  148.  
  149. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  150. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  151. const NO_ITEM_TAP_FOR_NON_STATIONARY_TAP = true; // dont open the menu (e.g. text message) if cursor is moved or long press
  152. const TAP_ACTION_DURATION = 280; // exceeding 280ms would not consider as a tap action
  153. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  154. // const FIX_MENU_CAPTURE_SCROLL = true;
  155. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  156.  
  157. const RAF_FIX_keepScrollClamped = true;
  158. const RAF_FIX_scrollIncrementally = 2; // 0: no action; 1: basic fix; 2: also fix scroll position
  159.  
  160. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  161. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  162.  
  163. const CHECK_JSONPRUNE = true; // This is a bug in Brave
  164. // << end >>
  165.  
  166. // const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = false;
  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. 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
  182. // << if USE_ADVANCED_TICKING >>
  183. const FIX_TIMESTAMP_FOR_REPLAY = true;
  184. const ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION = true; // MUST BE true
  185. const REUSE_TICKER = true; // for better memory control; currently it is only available in ADVANCED_TICKING; to be further reviewed
  186. // << end >>
  187.  
  188. const DISABLE_Translation_By_Google = true;
  189.  
  190. const FASTER_ICON_RENDERING = true;
  191.  
  192. const DELAY_FOCUSEDCHANGED = true;
  193.  
  194. const skipErrorForhandleAddChatItemAction_ = true; // currently depends on ENABLE_NO_SMOOTH_TRANSFORM
  195. const fixChildrenIssue801 = true; // if __children801__ is set [fix polymer controller method extration for `.set()`]
  196.  
  197. const SUPPRESS_refreshOffsetContainerHeight_ = true; // added in FEB 2024; true for default layout options; no effect if ENABLE_NO_SMOOTH_TRANSFORM is false
  198.  
  199. const NO_FILTER_DROPDOWN_BORDER = true; // added in 2024.03.02
  200.  
  201. const FIX_ANIMATION_TICKER_TEXT_POSITION = true; // CSS fix; experimental; added in 2024.04.07
  202. const FIX_AUTHOR_CHIP_BADGE_POSITION = true;
  203.  
  204. const FIX_ToggleRenderPolymerControllerExtractionBug = false; // to be reviewed
  205.  
  206. const REACTION_ANIMATION_PANEL_CSS_FIX = true;
  207.  
  208. const FIX_UNKNOWN_BUG_FOR_OVERLAY = true; // no .prepare() in backdrop element. reason is unknown.
  209.  
  210. const FIX_MOUSEOVER_FN = true; // avoid onMouseOver_ being triggerd quite a lot
  211.  
  212. // -------------------------------
  213.  
  214. const USE_OBTAIN_LCR_BY_BOTH_METHODS = false; // true for play safe
  215.  
  216. const FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP = true; // To fix Memory Leakage in yt-live-chat-ticker-...-item-renderer
  217. const FIX_MEMORY_LEAKAGE_TICKER_STATSBAR = true; // To fix Memory Leakage in updateStatsBarAndMaybeShowAnimation
  218. const FIX_MEMORY_LEAKAGE_TICKER_TIMER = true; // To fix Memory Leakage in setContainerWidth, slideDown, collapse // Dec 2024 fix in advance tickering
  219. const FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth = true; // To fix Memory Leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth()
  220.  
  221.  
  222. const USE_RM_ON_FOUNTAIN_MODEL = true;
  223. const DEBUG_RM_ON_FOUNTAIN_MODEL = false;
  224. const FOUNTAIN_MODEL_TIME_CONFIRM = 1600; // 800 not sufficient; re-adding?
  225. const MODIFY_EMIT_MESSAGES_FOR_BOOST_CHAT = true; // enabled for boost chat only; instant emit & no background flush
  226.  
  227. /**
  228. *
  229. *
  230. *
  231. *
  232. *
  233. rendererStamperObserver_: function(a, b, c) {
  234. if (c.path == a) {
  235. if (c.value === void 0 && !this.hasDataPath_[a])
  236. return;
  237. this.hasDataPath_[a] = c.value !== void 0
  238. }
  239. this.rendererStamperApplyChangeRecord_(a, b, c)
  240. },
  241.  
  242.  
  243. addStampDomObserverFns_: function() {
  244. for (var a in this.stampDom) {
  245. var b = this.stampDom[a];
  246. b.id ? (this[SQa(b.id)] = this.rendererStamperObserver_.bind(this, a, b.id),
  247. this.hasDataPath_[a] = !1) : Er(new Dn("Bad rendererstamper config",this.is + ":" + a))
  248. }
  249. },
  250. *
  251. *
  252. *
  253. *
  254. *
  255. */
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. // <<<<< FOR MEMORY LEAKAGE >>>>
  263.  
  264. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  265. /*
  266.  
  267. ### Time Approach
  268.  
  269. // all below values can make the time interval > 250ms
  270. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  271. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  272. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  273. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  274. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  275. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  276.  
  277. ### Pixel Check
  278. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  279. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  280. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  281.  
  282. ### Example - totalDuration = 280000
  283. totalDuration 280000
  284. stepInterval 0.5
  285. numOfSteps = Math.round(100 / stepInterval) = 200
  286. time interval = 280000 / 200 = 1400ms <acceptable>
  287.  
  288. ### Example - totalDuration = 18000
  289. totalDuration 18000
  290. stepInterval 5
  291. numOfSteps = Math.round(100 / stepInterval) = 20
  292. time interval = 18000 / 20 = 900ms <acceptable>
  293.  
  294. ### Example - totalDuration = 5000
  295. totalDuration 5000
  296. stepInterval 5
  297. numOfSteps = Math.round(100 / stepInterval) = 20
  298. time interval = 5000 / 20 = 250ms <threshold value>
  299.  
  300. ### Example - totalDuration = 3600
  301. totalDuration 3600
  302. stepInterval 5
  303. numOfSteps = Math.round(100 / stepInterval) = 20
  304. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  305.  
  306. */
  307.  
  308. // =======================================================================================================
  309.  
  310. // AUTOMAICALLY DETERMINED
  311. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  312. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  313. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  314.  
  315.  
  316. // image sizing code
  317. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  318.  
  319.  
  320. // function KC(a, b, c, d) {
  321. // d = void 0 === d ? "width" : d;
  322. // if (!a || !a.length)
  323. // return null;
  324. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  325. // var e = window.devicePixelRatio;
  326. // 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"));
  327. // HC = e
  328. // } else
  329. // HC || (HC = window.devicePixelRatio);
  330. // e = HC;
  331. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  332. // if (z("kevlar_tuner_min_thumbnail_quality"))
  333. // return a[0].url || null;
  334. // e = a.length;
  335. // if (z("kevlar_tuner_max_thumbnail_quality"))
  336. // return a[e - 1].url || null;
  337. // if (c)
  338. // for (var h = 0; h < e; h++)
  339. // if (0 <= a[h].url.indexOf(c))
  340. // return a[h].url || null;
  341. // for (c = 0; c < e; c++)
  342. // if (a[c][d] >= b)
  343. // return a[c].url || null;
  344. // for (b = e - 1; 0 < b; b--)
  345. // if (a[b][d])
  346. // return a[b].url || null;
  347. // return a[0].url || null
  348. // }
  349.  
  350.  
  351. /// ------
  352.  
  353. // https://www.youtube.com/watch?v=byyvH5t0hKc
  354. // yt-live-chat-ticker-creator-goal-view-model
  355. // no ticker effect on timing
  356.  
  357. /*
  358.  
  359.  
  360. {
  361. "id": "ChwKGkNQS0pyNV9NdG9vREZVYlB6Z2FkRHWFUv2E",
  362. "initialTickerText": {
  363. "content": "Goal",
  364. "styleRuns": [
  365. {
  366. "startIndex": 0,
  367. "length": 4
  368. }
  369. ]
  370. },
  371. "tickerIcon": {
  372. "sources": [
  373. {
  374. "clientResource": {
  375. "imageName": "TARGET_ADD"
  376. }
  377. }
  378. ]
  379. },
  380. "showGoalStatusCommand": {
  381. "innertubeCommand": {
  382. "clickTrackingParams": "CCQQ7NANIhMI58DT_ef5rhMVxMW1Cx4qBzTz",
  383. "showEngagementPanelEndpoint": {
  384. "engagementPanel": {
  385. "engagementPanelSectionListRenderer": {
  386. "header": {
  387. "engagementPanelTitleHeaderRenderer": {
  388. "actionButton": {
  389. "buttonRenderer": {
  390. "icon": {
  391. "iconType": "QUESTION_CIRCLE"
  392. },
  393. "trackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  394. "command": {
  395. "clickTrackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  396. "commandExecutorCommand": {
  397. "commands": [
  398. {
  399. "clickTrackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  400. "liveChatDialogEndpoint": {
  401. "content": {
  402. "liveChatDialogRenderer": {
  403. "trackingParams": "CCkQzS8iEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  404. "title": {
  405. "runs": [
  406. {
  407. "text": "Super Chat Goal"
  408. }
  409. ]
  410. },
  411. "dialogMessages": [
  412. {
  413. "runs": [
  414. {
  415. "text": "Join the fun by participating in the goal! "
  416. },
  417. {
  418. "text": "Learn more.\n",
  419. "navigationEndpoint": {
  420. "clickTrackingParams": "CCkQzS8iEwjm0Iz72rbKBxXT1EQBJekHNQM="
  421. }
  422. }
  423. ]
  424. },
  425. {
  426. "runs": [
  427. {
  428. "text": "How to participate",
  429. "bold": true,
  430. "textColor": 4294967295
  431. },
  432. {
  433. "text": "\n"
  434. },
  435. {
  436. "text": "1. Press \"Continue\"\n2. Purchase a Super Chat \n3. Watch the progress towards the goal\n4. Celebrate achieving it with the community!",
  437. "textColor": 4294967295
  438. }
  439. ]
  440. }
  441. ],
  442. "confirmButton": {
  443. "buttonRenderer": {
  444. "style": "STYLE_MONO_FILLED",
  445. "size": "SIZE_DEFAULT",
  446. "isDisabled": false,
  447. "text": {
  448. "simpleText": "Got it"
  449. },
  450. "trackingParams": "CCoQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  451. "accessibilityData": {
  452. "accessibilityData": {
  453. "label": "Got it"
  454. }
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. },
  462. {
  463. "clickTrackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  464. "hideEngagementPanelEndpoint": {
  465. "identifier": {
  466. "surface": "ENGAGEMENT_PANEL_SURFACE_LIVE_CHAT",
  467. "tag": "creator_goal_progress_engagement_panel"
  468. }
  469. }
  470. }
  471. ]
  472. }
  473. }
  474. }
  475. },
  476. "trackingParams": "CCUQ040EIhMI58DT_ef5rhMVxMW1Cx4qBzTz"
  477. }
  478. },
  479. "content": {
  480. "sectionListRenderer": {
  481. "contents": [
  482. {
  483. "creatorGoalProgressFlowViewModel": {
  484. "creatorGoalEntityKey": "EgtieXl2SDV0MGhLYyG7BzhF",
  485. "progressFlowButton": {
  486. "buttonViewModel": {
  487. "onTap": {
  488. "innertubeCommand": {
  489. "clickTrackingParams": "CCcQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  490. "commandMetadata": {
  491. "webCommandMetadata": {
  492. "ignoreNavigation": true
  493. }
  494. },
  495. "liveChatPurchaseMessageEndpoint": {
  496. "params": "Q2lrcUp3b1lWVU14ZFdObmIwTmZjMGQzZDE5RmRYVTFhVTF4Y0ZGM0VndGllWGwyU0RWME1HaExZeEFCSUFFNEFFSUNDQUUlM0Q="
  497. }
  498. }
  499. },
  500. "style": "BUTTON_VIEW_MODEL_STYLE_MONO",
  501. "trackingParams": "CCcQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  502. "type": "BUTTON_VIEW_MODEL_TYPE_FILLED",
  503. "titleFormatted": {
  504. "content": "Continue",
  505. "styleRuns": [
  506. {
  507. "startIndex": 0,
  508. "length": 8
  509. }
  510. ]
  511. }
  512. }
  513. },
  514. "progressCountA11yLabel": "Super Chat goal progress: $0 out of $1"
  515. }
  516. }
  517. ],
  518. "trackingParams": "CCYQui8iEwjm0Iz72rbKBxXT1EQBJekHNQM="
  519. }
  520. },
  521. "identifier": {
  522. "surface": "ENGAGEMENT_PANEL_SURFACE_LIVE_CHAT",
  523. "tag": "creator_goal_progress_engagement_panel"
  524. }
  525. }
  526. },
  527. "identifier": {
  528. "surface": "ENGAGEMENT_PANEL_SURFACE_LIVE_CHAT",
  529. "tag": "creator_goal_progress_engagement_panel"
  530. },
  531. "engagementPanelPresentationConfigs": {
  532. "engagementPanelPopupPresentationConfig": {
  533. "popupType": "PANEL_POPUP_TYPE_DIALOG"
  534. }
  535. }
  536. }
  537. }
  538. },
  539. "creatorGoalEntityKey": "EgtieXl2SDV0MGhLYyG7BzhF",
  540. "shouldShowSetUpFlowOnMobile": true,
  541. "a11yLabel": "See Super Chat goal",
  542. "loggingDirectives": {
  543. "trackingParams": "CCQQ7NANIhMI58DT_ef5rhMVxMW1Cx4qBzTz",
  544. "visibility": {
  545. "types": "12"
  546. }
  547. }
  548. }
  549.  
  550.  
  551. */
  552.  
  553.  
  554. // ------
  555.  
  556. const { IntersectionObserver } = __CONTEXT__;
  557. let _x69;
  558. try {
  559. _x69 = document.createAttributeNS("http://www.w3.org/2000/svg", "nil").addEventListener;
  560. } catch (e) { }
  561. const pureAddEventListener = _x69;
  562. if (!pureAddEventListener) return console.warn("pureAddEventListener cannot be obtained.");
  563.  
  564. /** @type {globalThis.PromiseConstructor} */
  565. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  566. const [setTimeout_] = [setTimeout];
  567. // let jsonParseFix = null;
  568.  
  569. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  570. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  571.  
  572. if (typeof CSS === 'undefined' || typeof (CSS || 0).supports !== 'function' || !CSS.supports('left', 'clamp(-100%, calc( -100% * 0.5 ), 0%)')) {
  573. return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for advanced tickering
  574. }
  575.  
  576.  
  577. // necessity of cssText3_smooth_transform_position to be checked.
  578. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  579.  
  580. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  581. position: static !important;
  582. }
  583.  
  584. `: '';
  585.  
  586. // fallback if dummy style fn fails
  587. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  588.  
  589. /* optional */
  590. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  591. height: auto !important;
  592. min-height: unset !important;
  593. }
  594.  
  595. #items.style-scope.yt-live-chat-item-list-renderer {
  596. transform: translateY(0px) !important;
  597. }
  598.  
  599. /* optional */
  600.  
  601. `: '';
  602.  
  603. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  604.  
  605. /* ------------------------------------------------------------------------------------------------------------- */
  606.  
  607. 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 {
  608. contain: layout style;
  609. }
  610.  
  611. #items.style-scope.yt-live-chat-item-list-renderer {
  612. contain: layout paint style;
  613. }
  614.  
  615. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  616. contain: style;
  617. }
  618.  
  619. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  620. contain: size style;
  621. }
  622.  
  623. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  624. contain: size layout paint style;
  625. }
  626.  
  627. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  628. contain: layout paint style;
  629. }
  630.  
  631. 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 {
  632. contain: layout style;
  633. }
  634.  
  635. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  636. contain: layout paint style;
  637. }
  638.  
  639. /* ------------------------------------------------------------------------------------------------------------- */
  640.  
  641. ` : '';
  642.  
  643. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  644.  
  645. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  646. top: 4px;
  647. transition-property: top;
  648. bottom: unset;
  649. }
  650.  
  651. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  652. top: -42px;
  653. }
  654.  
  655. `: '';
  656.  
  657. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  658.  
  659. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  660. contain: layout style;
  661. }
  662.  
  663. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  664. overflow: visible;
  665. }
  666.  
  667. `: '';
  668.  
  669. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  670.  
  671. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  672. --yt-live-chat-action-panel-top-border: none;
  673. }
  674.  
  675. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  676. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  677. }
  678.  
  679. html #panel-pages.yt-live-chat-renderer {
  680. border-top: 0;
  681. border-bottom: 0;
  682. }
  683.  
  684. `: '';
  685.  
  686. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  687.  
  688. img,
  689. yt-img-shadow[height][width],
  690. yt-img-shadow {
  691. content-visibility: visible !important;
  692. }
  693.  
  694. ` : '';
  695.  
  696. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  697.  
  698. /* remove YouTube constant will-change */
  699. /* constant value will slow down the performance; default auto */
  700.  
  701. /* www-player.css */
  702. html .ytp-contextmenu,
  703. html .ytp-settings-menu {
  704. will-change: unset;
  705. }
  706.  
  707. /* frequently matched elements */
  708. html .fill.yt-interaction,
  709. html .stroke.yt-interaction,
  710. html .yt-spec-touch-feedback-shape__fill,
  711. html .yt-spec-touch-feedback-shape__stroke {
  712. will-change: unset;
  713. }
  714.  
  715. /* live_chat_polymer.js */
  716. /*
  717. html .toggle-button.tp-yt-paper-toggle-button,
  718. html #primaryProgress.tp-yt-paper-progress,
  719. html #secondaryProgress.tp-yt-paper-progress,
  720. html #onRadio.tp-yt-paper-radio-button,
  721. html .fill.yt-interaction,
  722. html .stroke.yt-interaction,
  723. html .yt-spec-touch-feedback-shape__fill,
  724. html .yt-spec-touch-feedback-shape__stroke {
  725. will-change: unset;
  726. }
  727. */
  728.  
  729. /* desktop_polymer_enable_wil_icons.js */
  730. /* html .fill.yt-interaction,
  731. html .stroke.yt-interaction, */
  732. html tp-yt-app-header::before,
  733. html tp-yt-iron-list,
  734. html #items.tp-yt-iron-list > *,
  735. html #onRadio.tp-yt-paper-radio-button,
  736. html .toggle-button.tp-yt-paper-toggle-button,
  737. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  738. html #items.ytd-post-multi-image-renderer,
  739. html #items.ytd-horizontal-card-list-renderer,
  740. html #items.yt-horizontal-list-renderer,
  741. html #left-arrow.yt-horizontal-list-renderer,
  742. html #right-arrow.yt-horizontal-list-renderer,
  743. html #items.ytd-video-description-infocards-section-renderer,
  744. html #items.ytd-video-description-music-section-renderer,
  745. html #chips.ytd-feed-filter-chip-bar-renderer,
  746. html #chips.yt-chip-cloud-renderer,
  747. html #items.ytd-merch-shelf-renderer,
  748. html #items.ytd-product-details-image-carousel-renderer,
  749. html ytd-video-preview,
  750. html #player-container.ytd-video-preview,
  751. html #primaryProgress.tp-yt-paper-progress,
  752. html #secondaryProgress.tp-yt-paper-progress,
  753. html ytd-miniplayer[enabled] /* ,
  754. html .yt-spec-touch-feedback-shape__fill,
  755. html .yt-spec-touch-feedback-shape__stroke */ {
  756. will-change: unset;
  757. }
  758.  
  759. /* other */
  760. .ytp-videowall-still-info-content[class],
  761. .ytp-suggestion-image[class] {
  762. will-change: unset !important;
  763. }
  764.  
  765. ` : '';
  766.  
  767. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  768. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  769.  
  770. elzm-fonts {
  771. visibility: collapse;
  772. position: fixed;
  773. top: -10px;
  774. left: -10px;
  775. font-size: 10pt;
  776. line-height: 100%;
  777. width: 100px;
  778. height: 100px;
  779. transform: scale(0.1);
  780. transform: scale(0.01);
  781. transform: scale(0.001);
  782. transform-origin: 0 0;
  783. contain: strict;
  784. display: block;
  785.  
  786. pointer-events: none !important;
  787. user-select: none !important;
  788. }
  789.  
  790. elzm-fonts[id]#elzm-fonts-yk75g {
  791. user-select: none !important;
  792. pointer-events: none !important;
  793. }
  794.  
  795. elzm-font {
  796. visibility: collapse;
  797. position: absolute;
  798. line-height: 100%;
  799. width: 100px;
  800. height: 100px;
  801. contain: strict;
  802. display: block;
  803.  
  804. user-select: none !important;
  805. pointer-events: none !important;
  806. }
  807.  
  808. elzm-font::before {
  809. visibility: collapse;
  810. position: absolute;
  811. line-height: 100%;
  812. width: 100px;
  813. height: 100px;
  814. contain: strict;
  815. display: block;
  816.  
  817. 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';
  818.  
  819. user-select: none !important;
  820. pointer-events: none !important;
  821. }
  822.  
  823. `: '';
  824.  
  825. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  826. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  827. -webkit-backdrop-filter: none;
  828. backdrop-filter: none;
  829. }
  830. `: '';
  831.  
  832. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  833.  
  834. @keyframes blinker-miuzp {
  835. 0%, 60%, 100% {
  836. opacity: 1;
  837. }
  838. 30% {
  839. opacity: 0.6;
  840. }
  841. }
  842.  
  843. yt-icon-button#show-more.has-new-messages-miuzp {
  844. animation: blinker-miuzp 1.74s linear infinite;
  845. }
  846.  
  847. `: '';
  848.  
  849. const cssText11_entire_message_clickable = FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK ? `
  850.  
  851. yt-live-chat-paid-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  852. pointer-events: none !important;
  853. }
  854.  
  855. yt-live-chat-membership-item-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  856. pointer-events: none !important;
  857. }
  858.  
  859. yt-live-chat-paid-sticker-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  860. pointer-events: none !important;
  861. }
  862.  
  863. yt-live-chat-text-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  864. pointer-events: none !important; /* TO_BE_REVIEWED */
  865. }
  866.  
  867. yt-live-chat-auto-mod-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  868. pointer-events: none !important;
  869. }
  870.  
  871. `: '';
  872.  
  873. const cssText12_nowrap_tooltip = MAX_TOOLTIP_NO_WRAP_WIDTH && typeof MAX_TOOLTIP_NO_WRAP_WIDTH === 'string' ? `
  874.  
  875.  
  876. tp-yt-paper-tooltip[role="tooltip"] {
  877. box-sizing: content-box !important;
  878. margin: 0px !important;
  879. padding: 0px !important;
  880. contain: none !important;
  881. }
  882.  
  883. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"] {
  884. box-sizing: content-box !important;
  885. display: inline-block;
  886. contain: none !important;
  887. }
  888.  
  889.  
  890. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"]{
  891. max-width: ${MAX_TOOLTIP_NO_WRAP_WIDTH};
  892. width: max-content;
  893. text-overflow: ellipsis;
  894. overflow: hidden;
  895. white-space: nowrap;
  896. }
  897.  
  898.  
  899. `: '';
  900.  
  901.  
  902. const cssText13_no_text_select_when_menu_visible = `
  903. [menu-visible] {
  904. --sfc47-text-select: none;
  905. }
  906. [menu-visible] #header[id][class],
  907. [menu-visible] #content[id][class],
  908. [menu-visible] #header[id][class] *,
  909. [menu-visible] #content[id][class] * {
  910. user-select: var(--sfc47-text-select) !important;
  911. }
  912. [menu-visible] #menu {
  913. --sfc47-text-select: inherit;
  914. }
  915. `;
  916.  
  917. const cssText14_NO_FILTER_DROPDOWN_BORDER = NO_FILTER_DROPDOWN_BORDER ? `
  918. yt-live-chat-header-renderer.yt-live-chat-renderer #label.yt-dropdown-menu::before {
  919. border:0;
  920. }
  921. ` : '';
  922.  
  923. const cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION = FIX_ANIMATION_TICKER_TEXT_POSITION ? `
  924. .style-scope.yt-live-chat-ticker-renderer #animation-container[id][class] {
  925. position: relative;
  926. display: grid;
  927. grid-auto-columns: 1fr;
  928. grid-auto-rows: 1fr;
  929. grid-template-columns: repeat(1, 1fr);
  930. gap: 7px;
  931. padding-bottom: 0;
  932. margin-bottom: 0;
  933. padding-top: 0;
  934. align-self: flex-start;
  935. flex-wrap: nowrap;
  936. margin-top: 1px;
  937. }
  938.  
  939. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class] {
  940. margin-top: 0px;
  941. margin-bottom: 0px;
  942. flex-direction: row;
  943. flex-wrap: nowrap;
  944. align-items: center;
  945. justify-content: flex-start;
  946. }
  947.  
  948. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class]:first-child::after {
  949. content: '補';
  950. visibility: collapse;
  951. display: inline-block;
  952. position: relative;
  953. width: 0;
  954. line-height: 22px;
  955. }
  956.  
  957. ` : '';
  958.  
  959. const cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION = FIX_AUTHOR_CHIP_BADGE_POSITION ? `
  960. #card #author-name-chip > yt-live-chat-author-chip[single-line] {
  961. flex-wrap: nowrap;
  962. white-space: nowrap;
  963. display: inline-flex;
  964. flex-direction: row;
  965. text-wrap: nowrap;
  966. flex-shrink: 0;
  967. align-items: center;
  968. }
  969.  
  970. #card #author-name-chip {
  971. display: inline-flex;
  972. flex-direction: row;
  973. align-items: flex-start;
  974. }
  975. `: '';
  976.  
  977.  
  978. // Example: https://www.youtube.com/watch?v=Xfytz-igsuc
  979. const cssText17_FIX_overwidth_banner_message = `
  980. yt-live-chat-banner-manager#live-chat-banner.style-scope.yt-live-chat-item-list-renderer {
  981. max-width: 100%;
  982. box-sizing: border-box;
  983. }
  984. `;
  985.  
  986.  
  987. const cssText18_REACTION_ANIMATION_PANEL_CSS_FIX = REACTION_ANIMATION_PANEL_CSS_FIX ? `
  988. #reaction-control-panel-overlay[class] {
  989. contain: strict;
  990. margin: 0;
  991. padding: 0;
  992. border: 0;
  993. box-sizing: border-box;
  994. will-change: initial;
  995. }
  996. #reaction-control-panel-overlay[class] *[class] {
  997. will-change: initial;
  998. }
  999. `: '';
  1000.  
  1001. const cssText19_FOR_ADVANCED_TICKING = USE_ADVANCED_TICKING ? `
  1002.  
  1003. ticker-bg-overlay {
  1004. display: block;
  1005. position: absolute;
  1006. z-index: -1;
  1007. box-sizing: border-box;
  1008. border: 0;
  1009. padding: 0;
  1010. margin: 0;
  1011. width: 200%;
  1012. top: 0;
  1013. bottom: 0;
  1014. left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  1015. contain: strict;
  1016. }
  1017. ticker-bg-overlay-end2 {
  1018.  
  1019. all:unset;
  1020. position: fixed;
  1021. display: block;
  1022. margin-left: -0.5px;
  1023. top: 8px;
  1024. left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  1025.  
  1026. width: 1px;
  1027. height: 1px;
  1028. opacity: 0;
  1029. pointer-events: none;
  1030. box-sizing: border-box;
  1031. border: 0;
  1032. padding: 0;
  1033. margin: 0;
  1034. contain: strict;
  1035. z-index: -1;
  1036. visibility: collapse;
  1037.  
  1038.  
  1039. }
  1040.  
  1041.  
  1042. /* .r6-closing-ticker is provided in ADVANCED_TICKING */
  1043. /* so .r6-width-adjustable is only available for ADVANCED_TICKING too */
  1044.  
  1045. /* DO NOT use .r6-width-adjustable ~ .r6-width-adjustable => very laggy */
  1046.  
  1047. /*
  1048. yt-live-chat-ticker-renderer {
  1049. --r6-transition-duration: 0.2s;
  1050. }
  1051.  
  1052. .r6-width-adjustable {
  1053. --r6-transition-duration-v: var(--r6-transition-duration);
  1054. transition: var(--r6-transition-duration-v);
  1055. }
  1056.  
  1057. .r6-width-adjustable-f {
  1058. --r6-transition-duration-v: 0s;
  1059. }
  1060.  
  1061. .r6-closing-ticker[class] {
  1062. --r6-transition-duration-v: var(--r6-transition-duration);
  1063. }
  1064. */
  1065.  
  1066.  
  1067.  
  1068. .r6-width-adjustable {
  1069. --r6-min-width: 0;
  1070. min-width: var(--r6-min-width);
  1071. }
  1072.  
  1073. .r6-width-adjustable-f {
  1074. --r6-min-width: max-content;
  1075. }
  1076.  
  1077. .r6-closing-ticker[class] {
  1078. --r6-min-width: 0;
  1079. }
  1080.  
  1081. ` : '';
  1082. // const cssText19_FOR_ADVANCED_TICKING = `
  1083.  
  1084. // ticker-bg-overlay {
  1085. // display: block;
  1086. // position: absolute;
  1087. // z-index: -1;
  1088. // box-sizing: border-box;
  1089. // border: 0;
  1090. // padding: 0;
  1091. // margin: 0;
  1092. // width: 200%;
  1093. // top: 0;
  1094. // bottom: 0;
  1095. // left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  1096. // contain: strict;
  1097. // }
  1098. // /*
  1099. // ticker-bg-overlay-end {
  1100. // position: absolute;
  1101. // right: 0px;
  1102. // top: 50%;
  1103. // display: block;
  1104. // width: 1px;
  1105. // height: 1px;
  1106. // opacity: 0;
  1107. // pointer-events: none;
  1108. // box-sizing: border-box;
  1109. // border: 0;
  1110. // padding: 0;
  1111. // margin: 0;
  1112. // contain: strict;
  1113. // }
  1114. // */
  1115.  
  1116. // ticker-bg-overlay-end2 {
  1117.  
  1118. // all:unset;
  1119. // position: fixed;
  1120. // display: block;
  1121. // margin-left: -0.5px;
  1122. // top: 8px;
  1123. // left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  1124.  
  1125. // width: 1px;
  1126. // height: 1px;
  1127. // opacity: 0;
  1128. // pointer-events: none;
  1129. // box-sizing: border-box;
  1130. // border: 0;
  1131. // padding: 0;
  1132. // margin: 0;
  1133. // contain: strict;
  1134. // z-index: -1;
  1135. // visibility: collapse;
  1136.  
  1137.  
  1138. // }
  1139.  
  1140. // /* USE_ADVANCED_TICKING */
  1141.  
  1142. // /*
  1143.  
  1144. // .ticker-no-transition-time, .ticker-no-transition-time [id] {
  1145. // transition-duration: 0s !important;
  1146. // }
  1147.  
  1148. // [r6-advanced-ticking] .style-scope.yt-live-chat-ticker-renderer ~ .style-scope.yt-live-chat-ticker-renderer:not(.r6-closing-ticker) {
  1149. // transition-duration: 0s !important;
  1150. // }
  1151.  
  1152. // */
  1153.  
  1154. // .r6-width-adjustable ~ .r6-width-adjustable {
  1155. // --r6-min-width: max-content;
  1156. // }
  1157.  
  1158. // .r6-closing-ticker[class] {
  1159. // --r6-min-width: 0px;
  1160. // }
  1161.  
  1162. // .r6-width-adjustable {
  1163. // min-width: var(--r6-min-width, 0px);
  1164. // }
  1165.  
  1166.  
  1167. // /*
  1168.  
  1169.  
  1170. // .r6-width-adjustable {
  1171. // transition-duration: var(--r6-transition-duration, 0s) !important;
  1172. // }
  1173.  
  1174. // .r6-width-adjustable-first {
  1175. // --r6-transition-duration: 0.2s;
  1176. // }
  1177.  
  1178. // .r6-width-adjustable ~ .r6-width-adjustable-first {
  1179. // --r6-transition-duration: 0s;
  1180. // }
  1181.  
  1182. // .r6-closing-ticker {
  1183. // --r6-transition-duration: 0.2s;
  1184. // }
  1185. // */
  1186.  
  1187. // /*
  1188.  
  1189.  
  1190. // ey.style.position = 'absolute';
  1191. // ey.style.right = '0px';
  1192. // ey.style.top = '50%';
  1193. // ey.style.display='block';
  1194. // ey.style.width='1px';
  1195. // ey.style.height='1px';
  1196. // ey.style.opacity = '0';
  1197.  
  1198. // em.style.display = 'block';
  1199. // em.style.position = 'absolute';
  1200. // em.style.boxSizing = 'border-box';
  1201. // em.style.width = '200%';
  1202. // em.style.top = '0';
  1203. // em.style.bottom = '0';
  1204. // // em.style.height = '100%';
  1205.  
  1206.  
  1207. // // em.style.left = '-50%';
  1208. // // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  1209.  
  1210. // */
  1211.  
  1212. // `;
  1213.  
  1214. const addCss = () => `
  1215.  
  1216. @property --ticker-rtime {
  1217. syntax: "<percentage>";
  1218. inherits: false;
  1219. initial-value: 0%;
  1220. }
  1221.  
  1222. .run-ticker {
  1223. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  1224. }
  1225.  
  1226. .run-ticker,
  1227. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  1228. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  1229. {
  1230. background: var(--ticker-bg) !important;
  1231. }
  1232.  
  1233. yt-live-chat-ticker-dummy777-item-renderer {
  1234. background: #00000001;
  1235. }
  1236.  
  1237. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  1238. position: fixed !important;
  1239. top: -1000px !important;
  1240. left: -1000px !important;
  1241. font-size: 1px !important;
  1242. color: transparent !important;
  1243. pointer-events: none !important;
  1244. z-index: -1 !important;
  1245. contain: strict !important;
  1246. box-sizing: border-box !important;
  1247. pointer-events: none !important;
  1248. user-select: none !important;
  1249. max-width: 1px !important;
  1250. max-height: 1px !important;
  1251. overflow: hidden !important;
  1252. visibility: collapse !important;
  1253. display: none !important;
  1254. }
  1255.  
  1256. yt-live-chat-ticker-dummy777-item-renderer #container {
  1257. background: inherit;
  1258. }
  1259.  
  1260.  
  1261. ${cssText8_fonts_pre_render}
  1262.  
  1263. ${cssText9_no_backdrop_filter_when_menu_shown}
  1264.  
  1265. @supports (contain: layout paint style) {
  1266.  
  1267. ${cssText5}
  1268.  
  1269. }
  1270.  
  1271. @supports (color: var(--general)) {
  1272.  
  1273. html {
  1274. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  1275. }
  1276.  
  1277. ${cssText3_smooth_transform_position}
  1278.  
  1279. ${cssText7c_will_change_unset}
  1280.  
  1281. ${cssText7b_content_visibility_unset}
  1282.  
  1283. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  1284. overflow-y: scroll;
  1285. padding-right: 0;
  1286. }
  1287.  
  1288. ${cssText4_smooth_transform_forced_props}
  1289.  
  1290. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  1291. pointer-events: none !important;
  1292. }
  1293.  
  1294. #continuations, #continuations * {
  1295. contain: strict;
  1296. position: fixed;
  1297. top: 2px;
  1298. height: 1px;
  1299. width: 2px;
  1300. height: 1px;
  1301. visibility: collapse;
  1302. }
  1303.  
  1304. ${cssText6b_show_more_button}
  1305.  
  1306. ${cssText6d_input_panel_border}
  1307.  
  1308. ${cssText6c_input_panel_overflow}
  1309.  
  1310. }
  1311.  
  1312.  
  1313. @supports (overflow-anchor: auto) {
  1314.  
  1315. .no-anchor * {
  1316. overflow-anchor: none;
  1317. }
  1318. .no-anchor > item-anchor {
  1319. overflow-anchor: auto;
  1320. }
  1321.  
  1322. item-anchor {
  1323.  
  1324. height:1px;
  1325. width: 100%;
  1326. transform: scaleY(0.00001);
  1327. transform-origin:0 0;
  1328. contain: strict;
  1329. opacity:0;
  1330. display:flex;
  1331. position:relative;
  1332. flex-shrink:0;
  1333. flex-grow:0;
  1334. margin-bottom:0;
  1335. overflow:hidden;
  1336. box-sizing:border-box;
  1337. visibility: visible;
  1338. content-visibility: visible;
  1339. contain-intrinsic-size: auto 1px;
  1340. pointer-events:none !important;
  1341.  
  1342. }
  1343.  
  1344. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  1345. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  1346. }
  1347.  
  1348. html item-anchor {
  1349.  
  1350. height: 1px;
  1351. width: 1px;
  1352. top: auto;
  1353. left: auto;
  1354. right: auto;
  1355. bottom: auto;
  1356. transform: translateY(-1px);
  1357. position: absolute;
  1358. z-index: -1;
  1359.  
  1360. }
  1361.  
  1362. }
  1363.  
  1364. @supports (color: var(--pre-rendering)) {
  1365.  
  1366. @keyframes dontRenderAnimation {
  1367. 0% {
  1368. background-position-x: 3px;
  1369. }
  1370. 100% {
  1371. background-position-x: 4px;
  1372. }
  1373. }
  1374.  
  1375. .dont-render[class] {
  1376. /* visibility: collapse !important; */
  1377. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://gf.qytechs.cn/scripts/469878/discussions/197267 */
  1378.  
  1379. transform: scale(0.01) !important;
  1380. transform: scale(0.00001) !important;
  1381. transform: scale(0.0000001) !important;
  1382. transform-origin: 0 0 !important;
  1383. z-index: -1 !important;
  1384. contain: strict !important;
  1385. box-sizing: border-box !important;
  1386.  
  1387. height: 1px !important;
  1388. height: 0.1px !important;
  1389. height: 0.01px !important;
  1390. height: 0.0001px !important;
  1391. height: 0.000001px !important;
  1392.  
  1393. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  1394.  
  1395. pointer-events: none !important;
  1396. user-select: none !important;
  1397.  
  1398. }
  1399.  
  1400. #sk35z {
  1401. display: block !important;
  1402.  
  1403. visibility: collapse !important;
  1404.  
  1405. transform: scale(0.01) !important;
  1406. transform: scale(0.00001) !important;
  1407. transform: scale(0.0000001) !important;
  1408. transform-origin: 0 0 !important;
  1409. z-index: -1 !important;
  1410. contain: strict !important;
  1411. box-sizing: border-box !important;
  1412.  
  1413. height: 1px !important;
  1414. height: 0.1px !important;
  1415. height: 0.01px !important;
  1416. height: 0.0001px !important;
  1417. height: 0.000001px !important;
  1418.  
  1419. position: absolute !important;
  1420. top: -1000px !important;
  1421. left: -1000px !important;
  1422.  
  1423. }
  1424.  
  1425. }
  1426.  
  1427. [rNgzQ] {
  1428. opacity: 0 !important;
  1429. pointer-events: none !important;
  1430. }
  1431.  
  1432.  
  1433. ${cssText10_show_more_blinker}
  1434.  
  1435. ${cssText11_entire_message_clickable}
  1436.  
  1437. ${cssText12_nowrap_tooltip}
  1438.  
  1439. ${cssText13_no_text_select_when_menu_visible}
  1440.  
  1441. ${cssText14_NO_FILTER_DROPDOWN_BORDER}
  1442.  
  1443. ${cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION}
  1444.  
  1445. ${cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION}
  1446.  
  1447. ${cssText17_FIX_overwidth_banner_message}
  1448.  
  1449. ${cssText18_REACTION_ANIMATION_PANEL_CSS_FIX}
  1450.  
  1451. ${cssText19_FOR_ADVANCED_TICKING}
  1452.  
  1453. `;
  1454.  
  1455. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  1456.  
  1457. // Create a unique key for the script and check if it is already running
  1458. const hkey_script = 'mchbwnoasqph';
  1459. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  1460. win[hkey_script] = true;
  1461.  
  1462. const setTimeoutX0 = setTimeout;
  1463. const clearTimeoutX0 = clearTimeout;
  1464. const setIntervalX0 = setInterval;
  1465. const clearIntervalX0 = clearInterval;
  1466.  
  1467. const __shady_native_appendChild = HTMLElement.prototype.__shady_native_appendChild || HTMLElement.prototype.appendChild;
  1468. const __shady_native_removeChild = HTMLElement.prototype.__shady_native_removeChild || HTMLElement.prototype.removeChild;
  1469.  
  1470. const isEmptyObject = (obj) => {
  1471. for (const key in obj) {
  1472. if (obj.hasOwnProperty(key)) return false;
  1473. }
  1474. return true;
  1475. }
  1476.  
  1477. const firstObjectKey = (obj) => {
  1478. for (const key in obj) {
  1479. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1480. }
  1481. return null;
  1482. }
  1483.  
  1484.  
  1485. class LimitedSizeSet extends Set {
  1486. constructor(n) {
  1487. super();
  1488. this.limit = n;
  1489. }
  1490.  
  1491. add(key) {
  1492. if (!super.has(key)) {
  1493. super.add(key);
  1494. let n = super.size - this.limit;
  1495. if (n > 0) {
  1496. const iterator = super.values();
  1497. do {
  1498. const firstKey = iterator.next().value; // Get the first (oldest) key
  1499. super.delete(firstKey); // Delete the oldest key
  1500. } while (--n > 0)
  1501. }
  1502. }
  1503. }
  1504.  
  1505. removeAdd(key) {
  1506. super.delete(key);
  1507. this.add(key);
  1508. }
  1509.  
  1510. }
  1511.  
  1512.  
  1513. function deepCopy(obj, skipKeys) {
  1514. skipKeys = skipKeys || [];
  1515. if (!obj || typeof obj !== 'object') return obj;
  1516. if (Array.isArray(obj)) {
  1517. return obj.map(item => deepCopy(item, skipKeys));
  1518. }
  1519. const copy = {};
  1520. for (let key in obj) {
  1521. if (!skipKeys.includes(key)) {
  1522. copy[key] = deepCopy(obj[key], skipKeys);
  1523. }
  1524. }
  1525. return copy;
  1526. }
  1527.  
  1528. class Mutex {
  1529.  
  1530. constructor() {
  1531. this.p = Promise.resolve()
  1532. }
  1533.  
  1534. /**
  1535. * @param {(lockResolve: () => void)} f
  1536. */
  1537. lockWith(f) {
  1538. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  1539. }
  1540.  
  1541. }
  1542.  
  1543. const PromiseExternal = ((resolve_, reject_) => {
  1544. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  1545. return class PromiseExternal extends Promise {
  1546. constructor(cb = h) {
  1547. super(cb);
  1548. if (cb === h) {
  1549. /** @type {(value: any) => void} */
  1550. this.resolve = resolve_;
  1551. /** @type {(reason?: any) => void} */
  1552. this.reject = reject_;
  1553. }
  1554. }
  1555. };
  1556. })();
  1557.  
  1558. let qWidthAdjustable = null;
  1559.  
  1560. /** @type {typeof PromiseExternal.prototype | null} */
  1561. let relayPromise = null;
  1562.  
  1563.  
  1564. /** @type {typeof PromiseExternal.prototype | null} */
  1565. let onPlayStateChangePromise = null;
  1566.  
  1567.  
  1568. const reuseId = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1569.  
  1570. const reuseStore = new Map();
  1571.  
  1572. let onPageContainer = null;
  1573.  
  1574. const customCreateComponent = (component, data, bool)=>{
  1575.  
  1576. const componentTag = typeof component === 'string' ? component : typeof (component||0).component === 'string' ? (component||0).component : '';
  1577. if(componentTag){
  1578.  
  1579. if(REUSE_TICKER && data.id && data.fullDurationSec){
  1580. // bool (param c) is true by default; just force it to reuse no matter true or false
  1581.  
  1582. if (!bool) {
  1583. // show a warning if it is false.
  1584. console.warn('[yt-chat] REUSE_TICKER: reuse bool is false');
  1585. }
  1586.  
  1587. const record = reuseStore.get(`<${componentTag}>${data.id}:${data.fullDurationSec}`);
  1588.  
  1589. const cnt = kRef(record);
  1590.  
  1591.  
  1592. if(cnt && cnt.isAttached === false){
  1593.  
  1594. const hostElement = cnt.hostElement;
  1595.  
  1596. if(hostElement instanceof HTMLElement && hostElement.isConnected === false && hostElement.parentNode === null && hostElement.getAttribute('__reuseid__')===reuseId ){
  1597.  
  1598. // console.log(952, cnt.hostElement.parentNode)
  1599. // debugger;
  1600. if (hostElement.hasAttribute('__nogc__')) {
  1601.  
  1602. Promise.resolve(hostElement).then((hostElement) => {
  1603. // microtask to provide some time for DOM attachment.
  1604. hostElement.isConnected && hostElement.removeAttribute('__nogc__');
  1605. });
  1606.  
  1607. }
  1608.  
  1609. // ------- follow rm3 -------
  1610.  
  1611. // a.prototype._initializeProtoProperties = function(c) {
  1612. // this.__data = Object.create(c);
  1613. // this.__dataPending = Object.create(c);
  1614. // this.__dataOld = {}
  1615. // }
  1616. // a.prototype._initializeProperties = function() {
  1617. // this.__dataProto && (this._initializeProtoProperties(this.__dataProto),
  1618. // this.__dataProto = null);
  1619. // b.prototype._initializeProperties.call(this)
  1620. // }
  1621. // ;
  1622.  
  1623. if(!cnt.__dataInvalid && cnt.__dataEnabled && cnt.__dataReady ){
  1624.  
  1625. // console.log(12883);
  1626.  
  1627.  
  1628. if (!onPageContainer) {
  1629. let p = document.createElement('noscript');
  1630. p.style.all = 'unset';
  1631. document.body.prepend(p);
  1632. onPageContainer = p;
  1633. }
  1634.  
  1635. onPageContainer.appendChild(hostElement); // to fix some issues for the rendered elements
  1636.  
  1637. cnt.__dataInvalid = false;
  1638. cnt.__dataEnabled = true;
  1639. cnt.__dataReady = true;
  1640. // cnt._initializeProtoProperties(cnt.data)
  1641.  
  1642. // window.meaa = cnt.$.container;
  1643. if (cnt.__data) cnt.__data = Object.assign({}, cnt.__data);
  1644. cnt.__dataPending = {};
  1645. cnt.__dataOld = {}
  1646.  
  1647. try{
  1648. cnt.markDirty();
  1649. }catch(e){}
  1650. try{
  1651. cnt.markDirtyVisibilityObserver();
  1652. }catch(e){}
  1653. try{
  1654. cnt.wasPrescan = cnt.wasVisible = !1
  1655. }catch(e){}
  1656. // try{
  1657. // cnt._setPendingProperty('data', Object.assign({}, cntData), !0);
  1658. // }catch(e){}
  1659. // // cnt.__dataInvalid = false;
  1660. // // cnt._enableProperties();
  1661.  
  1662. // try {
  1663. // cnt._flushProperties();
  1664. // } catch (e) { }
  1665. // cnt.ready();
  1666.  
  1667. return hostElement;
  1668.  
  1669. }
  1670.  
  1671.  
  1672. // console.log(12323)
  1673.  
  1674. // setTimeoutX0(()=>{
  1675. // console.log(window.meaa.parentNode)
  1676. // }, 1000)
  1677.  
  1678.  
  1679. // ------------ commented ------------
  1680. // cnt.__dataInvalid = false;
  1681. // cnt.__dataEnabled = false;
  1682. // if (cnt.__dataPending && typeof cnt.__dataPending === 'object') cnt.__dataPending = null;
  1683. // if (cnt.__dataOld && typeof cnt.__dataOld === 'object') cnt.__dataOld = null;
  1684. // if (cnt.__dataCounter && typeof cnt.__dataCounter === 'number') cnt.__dataCounter = 0;
  1685. // if ('__dataClientsInitialized' in cnt || '__dataClientsReady' in cnt) {
  1686. // cnt.__dataClientsReady = !1;
  1687. // cnt.__dataLinkedPaths = cnt.__dataToNotify = cnt.__dataPendingClients = null;
  1688. // cnt.__dataHasPaths = !1;
  1689. // cnt.__dataCompoundStorage = null; // cnt.__dataCompoundStorage = cnt.__dataCompoundStorage || null;
  1690. // cnt.__dataHost = null; // cnt.__dataHost = cnt.__dataHost || null;
  1691. // if (!cnt.__dataTemp) cnt.__dataTemp = {}; // cnt.__dataTemp = {};
  1692. // cnt.__dataClientsInitialized = !1;
  1693. // }
  1694. // try{
  1695. // cnt._flushProperties();
  1696. // }catch(e){
  1697. // console.warn(e)
  1698. // }
  1699. // for (const elm of cnt.hostElement.getElementsByTagName('*')) {
  1700. // if (elm.is) {
  1701. // const cnt = insp(elm);
  1702. // cnt.__dataInvalid = false;
  1703. // cnt.__dataEnabled = false;
  1704. // if (cnt.__dataPending && typeof cnt.__dataPending === 'object') cnt.__dataPending = null;
  1705. // if (cnt.__dataOld && typeof cnt.__dataOld === 'object') cnt.__dataOld = null;
  1706. // if (cnt.__dataCounter && typeof cnt.__dataCounter === 'number') cnt.__dataCounter = 0;
  1707. // if ('__dataClientsInitialized' in cnt || '__dataClientsReady' in cnt) {
  1708. // cnt.__dataClientsReady = !1;
  1709. // cnt.__dataLinkedPaths = cnt.__dataToNotify = cnt.__dataPendingClients = null;
  1710. // cnt.__dataHasPaths = !1;
  1711. // cnt.__dataCompoundStorage = null; // cnt.__dataCompoundStorage = cnt.__dataCompoundStorage || null;
  1712. // cnt.__dataHost = null; // cnt.__dataHost = cnt.__dataHost || null;
  1713. // if (!cnt.__dataTemp) cnt.__dataTemp = {}; // cnt.__dataTemp = {};
  1714. // cnt.__dataClientsInitialized = !1;
  1715. // }
  1716. // try {
  1717. // cnt._flushProperties();
  1718. // } catch (e) {
  1719. // console.warn(e)
  1720. // }
  1721. // if (elm.nodeName === 'YT-ICON') {
  1722. // // console.log(2133, JSON.stringify( cnt.__data))
  1723. // const qq = Object.assign({}, cnt.__data)
  1724. // console.log(1232466)
  1725. // const _qww = cnt;
  1726. // cnt.__data = new Proxy(Object.assign({}, qq), {
  1727. // get(target, p) {
  1728. // console.log(12838, p)
  1729. // if (p === 'icon') {
  1730. // window.wmk = _qww.hostElement;
  1731. // // debugger;
  1732. // }
  1733. // return target[p]
  1734. // },
  1735. // set(target, p, v) {
  1736. // console.log(12839, p)
  1737. // target[p] = v;
  1738. // if (p === 'icon') debugger;
  1739. // return true;
  1740. // }
  1741. // });
  1742. // Promise.resolve(cnt).then((cnt) => {
  1743. // cnt.__data = Object.assign({}, qq);
  1744. // });
  1745. // }
  1746. // // let q = elm.nextSibling;
  1747. // // let h = elm.parentNode;
  1748. // // elm.remove();
  1749. // // h.insertBefore(elm, q);
  1750. // // console.log(2233, elm)
  1751. // }
  1752. // }
  1753. // ------------ commented ------------
  1754.  
  1755. // ------- follow rm3 -------
  1756.  
  1757. // console.log('[yt-chat] reuse')
  1758.  
  1759.  
  1760.  
  1761. }
  1762.  
  1763. }
  1764.  
  1765. }
  1766.  
  1767. }
  1768. DEBUG_customCreateComponent && console.log(component, data, bool);
  1769. /*
  1770.  
  1771. const cntData = this.data;
  1772. reuseStore.set(`${cntData.id}:${cntData.fullDurationSec}`, mWeakRef(this));
  1773. */
  1774.  
  1775. }
  1776.  
  1777. const valAssign = (elm, attr, val) => {
  1778. if (typeof val === 'number') val = val.toFixed(3);
  1779. if (!(Math.abs(elm.style.getPropertyValue(attr) - val) < 1e-5)) {
  1780. elm.style.setProperty(attr, val);
  1781. return true;
  1782. }
  1783. return false;
  1784. };
  1785.  
  1786. let playEventsStack = Promise.resolve();
  1787.  
  1788.  
  1789. let playerProgressChangedArg1 = null;
  1790. let playerProgressChangedArg2 = null;
  1791. let playerProgressChangedArg3 = null;
  1792.  
  1793. let dntElementWeak = null;
  1794.  
  1795.  
  1796. let timestampUnderLiveMode = false;
  1797.  
  1798. const updateTickerCurrentTime = () => {
  1799.  
  1800. if (resistanceUpdateDebugMode) {
  1801. console.log('updateTickerCurrentTime')
  1802.  
  1803. if (!dntElementWeak || !kRef(dntElementWeak)) dntElementWeak = mWeakRef(document.querySelector('yt-live-chat-ticker-renderer'));
  1804. timestampUnderLiveMode = true;
  1805. }
  1806.  
  1807. const dntElement = kRef(dntElementWeak);
  1808. const v = timestampUnderLiveMode ? (Date.now() / 1000 - timeOriginDT / 1000) : playerProgressChangedArg1;
  1809. if (dntElement instanceof HTMLElement && v >= 0) {
  1810. valAssign(dntElement, '--ticker-current-time', v);
  1811. }
  1812. }
  1813.  
  1814. // ================== FOR USE_ADVANCED_TICKING ================
  1815.  
  1816. const timeOriginDT = +new Date(performance.timeOrigin);
  1817. let startResistanceUpdaterStarted = false;
  1818.  
  1819. const RESISTANCE_UPDATE_OPT = 3;
  1820. let resistanceUpdateLast = 0;
  1821. let resistanceUpdateBusy = false;
  1822. const resistanceUpdateDebugMode = false;
  1823. const allBackgroundOverLays = document.getElementsByTagName('ticker-bg-overlay');
  1824. // const rgFlag = {};
  1825. const resistanceUpdateFn = (b) => {
  1826. if (!resistanceUpdateDebugMode && allBackgroundOverLays.length === 0) return;
  1827. resistanceUpdateBusy = false;
  1828. const t = Date.now();
  1829. const d = t - resistanceUpdateLast;
  1830. if (d > 375) {
  1831. resistanceUpdateLast = t;
  1832. updateTickerCurrentTime();
  1833. }
  1834. }
  1835. const resistanceUpdateFn_ = () => {
  1836. if (!resistanceUpdateBusy) {
  1837. resistanceUpdateBusy = true;
  1838. Promise.resolve().then(resistanceUpdateFn);
  1839. }
  1840. }
  1841. const startResistanceUpdater = () => {
  1842.  
  1843. if (startResistanceUpdaterStarted) return;
  1844. startResistanceUpdaterStarted = true;
  1845.  
  1846.  
  1847. if (RESISTANCE_UPDATE_OPT & 1)
  1848. document.addEventListener('yt-action', () => {
  1849. resistanceUpdateFn_();
  1850. }, true)
  1851.  
  1852. resistanceUpdateFn_();
  1853. setIntervalX0(resistanceUpdateFn_, 400);
  1854. }
  1855.  
  1856. if(resistanceUpdateDebugMode) startResistanceUpdater();
  1857.  
  1858.  
  1859. function dr(s) {
  1860. // reserved for future use
  1861. return s;
  1862. // return window.deWeakJS ? window.deWeakJS(s) : s;
  1863. }
  1864.  
  1865. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1866. const indr = o => insp(o).$ || o.$ || 0;
  1867.  
  1868. const getProto = (element) => {
  1869. if (element) {
  1870. const cnt = insp(element);
  1871. return cnt.constructor.prototype || null;
  1872. }
  1873. return null;
  1874. }
  1875.  
  1876.  
  1877.  
  1878. const logFn = (key, f) => {
  1879. return Function.prototype.bind.call(console.log, console, `%c ${key}`, 'background: #222; color: #bada55', f);
  1880. }
  1881.  
  1882.  
  1883.  
  1884. const assertor = (f) => f() || (console.assert(false, `${f}`), false);
  1885.  
  1886. const fnIntegrity = (f, d) => {
  1887.  
  1888.  
  1889. if (!f || typeof f !== 'function') {
  1890. console.warn('f is not a function', f);
  1891. return;
  1892. }
  1893. // return; // M44
  1894. let p = `${f}`, s = 0, j = -1, w = 0;
  1895. // return; // M44
  1896. for (let i = 0, l = p.length; i < l; i++) {
  1897. const t = p[i];
  1898. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1899. if (j < i - 1) w++;
  1900. j = i;
  1901. } else {
  1902. s++;
  1903. }
  1904. }
  1905. // if(p.length > 44 && p.length < 50){
  1906.  
  1907. // (window.skam|| (window.skam=[])).push(p);
  1908. // return false;
  1909. // }
  1910.  
  1911. // if(p.length > 405 && p.length < 415 ){ //350 450
  1912.  
  1913.  
  1914. // //  [353, 411, 411, 411]
  1915.  
  1916. // // if(p.length >= 350 && p.length<=450){
  1917.  
  1918. // // (window.skam|| (window.skam=[])).push(p.length);
  1919. // // }
  1920. // (window.skam|| (window.skam=[])).push(p);
  1921. // return false;
  1922. // }
  1923.  
  1924. // if(p.length < 50) return true; else return false;
  1925. // return; // M44
  1926. let itz = `${f.length}.${s}.${w}`;
  1927. if (!d) {
  1928. return itz;
  1929. } else if (itz !== d) {
  1930. console.warn('fnIntegrity=false', itz);
  1931. return false;
  1932. } else {
  1933. return true;
  1934. }
  1935. }
  1936.  
  1937. const px2cm = (px) => px * window.devicePixelRatio * 0.026458333;
  1938. const px2mm = (px) => px * window.devicePixelRatio * 0.26458333;
  1939.  
  1940. let createElement_fountain_model_fn = null;
  1941. let createElement_fountain_model_enabled = null;
  1942.  
  1943. ; (USE_RM_ON_FOUNTAIN_MODEL) && (()=>{
  1944. document.createElement4719 = document.createElement;
  1945. document.createElement = function (a) {
  1946. if (createElement_fountain_model_enabled) {
  1947. const r = createElement_fountain_model_fn(a);
  1948. if (r) return r;
  1949. }
  1950. return document.createElement4719(a);
  1951. }
  1952. })();
  1953.  
  1954. ; (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS || DISABLE_FLAGS_SHADYDOM_FREE) && (() => {
  1955.  
  1956. const _config_ = () => {
  1957. try {
  1958. return ytcfg.data_;
  1959. } catch (e) { }
  1960. return null;
  1961. };
  1962.  
  1963. const flagsFn = (EXPERIMENT_FLAGS) => {
  1964.  
  1965. // console.log(700)
  1966.  
  1967. if (!EXPERIMENT_FLAGS) return;
  1968.  
  1969. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  1970. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  1971. // EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true; // timestamp toggle issue
  1972. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  1973. // console.log(701)
  1974. }
  1975. }
  1976.  
  1977. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  1978. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  1979. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  1980. // console.log(702);
  1981. }
  1982.  
  1983. if (DISABLE_FLAGS_SHADYDOM_FREE) {
  1984. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_node_methods = false;
  1985. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_query_methods = false;
  1986. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_readonly_properties_batch_one = false;
  1987. EXPERIMENT_FLAGS.enable_shadydom_free_parent_node = false;
  1988. EXPERIMENT_FLAGS.enable_shadydom_free_children = false;
  1989. EXPERIMENT_FLAGS.enable_shadydom_free_last_child = false;
  1990. }
  1991.  
  1992. // EXPERIMENT_FLAGS.enable_button_behavior_reuse = false;
  1993.  
  1994. };
  1995.  
  1996. const uf = (config_) => {
  1997. config_ = config_ || _config_();
  1998. if (config_) {
  1999. const { EXPERIMENT_FLAGS, EXPERIMENTS_FORCED_FLAGS } = config_;
  2000. if (EXPERIMENT_FLAGS) {
  2001. flagsFn(EXPERIMENT_FLAGS);
  2002. if (EXPERIMENTS_FORCED_FLAGS) flagsFn(EXPERIMENTS_FORCED_FLAGS);
  2003. }
  2004. }
  2005. }
  2006.  
  2007. window._ytConfigHacks.add((config_) => {
  2008. uf(config_);
  2009. });
  2010.  
  2011. uf();
  2012.  
  2013. })();
  2014.  
  2015. if (DISABLE_Translation_By_Google) {
  2016.  
  2017. let mo = new MutationObserver(() => {
  2018.  
  2019. if (!mo) return;
  2020. let h = document.head;
  2021. if (!h) return;
  2022. mo.disconnect();
  2023. mo.takeRecords();
  2024. mo = null;
  2025.  
  2026. let meta = document.createElement('meta');
  2027. meta.setAttribute('name', 'google');
  2028. meta.setAttribute('content', 'notranslate');
  2029. h.appendChild(meta);
  2030.  
  2031.  
  2032. });
  2033. mo.observe(document, { subtree: true, childList: true });
  2034. }
  2035.  
  2036.  
  2037. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  2038.  
  2039. const isContainSupport = CSS.supports('contain', 'layout paint style');
  2040. if (!isContainSupport) {
  2041. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  2042. }
  2043.  
  2044. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  2045. if (!isOverflowAnchorSupport) {
  2046. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  2047. }
  2048.  
  2049. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && isOverflowAnchorSupport && ENABLE_NO_SMOOTH_TRANSFORM;
  2050.  
  2051.  
  2052. const fxOperator = (proto, propertyName) => {
  2053. let propertyDescriptorGetter = null;
  2054. try {
  2055. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  2056. } catch (e) { }
  2057. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  2058. try {
  2059.  
  2060. return propertyDescriptorGetter.call(dr(e));
  2061. } catch (e) { }
  2062. return e[propertyName];
  2063. } : (e) => e[propertyName];
  2064. };
  2065.  
  2066. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  2067. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  2068. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  2069. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  2070. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  2071.  
  2072. let groupCI = [];
  2073. let groupDI = 0;
  2074.  
  2075. const [console_] = [console];
  2076. const console1 = {
  2077. log(...args) {
  2078. if (!SHOW_DEVTOOL_DEBUG) return;
  2079. if (groupDI === 1) return grouppedConsoleLog(...args);
  2080. return console_.log(...args);
  2081. },
  2082. warn(...args) {
  2083. if (!SHOW_DEVTOOL_DEBUG) return;
  2084. if (groupDI === 1) return grouppedConsoleWarn(...args);
  2085. return console_.warn(...args);
  2086. },
  2087. debug(...args) {
  2088. if (!SHOW_DEVTOOL_DEBUG) return;
  2089. if (groupDI === 1) return grouppedConsoleDebug(...args);
  2090. return console_.debug(...args);
  2091. }
  2092. }
  2093. const grouppedConsoleLog = (...args) => {
  2094. if (DEBUG_LOG_HIDE_OK) {
  2095. for (const arg of args) {
  2096. if (typeof arg !== 'string') break;
  2097. if (arg.endsWith('OK')) return;
  2098. }
  2099. }
  2100. groupCI.push(['log', ...args]);
  2101. }
  2102. const grouppedConsoleWarn = (...args) => {
  2103. groupCI.push(['warn', ...args]);
  2104. }
  2105. const grouppedConsoleDebug = (...args) => {
  2106. groupCI.push(['debug', ...args]);
  2107. }
  2108. const groupCollapsed = (text1, text2) => {
  2109. if (!SHOW_DEVTOOL_DEBUG) return;
  2110. if (groupDI !== 0) console_.warn('groupDI in groupCollapsed fails', groupDI);
  2111. groupDI++;
  2112. groupCI.length = 0;
  2113.  
  2114. let w = 'groupCollapsed';
  2115. if (DEBUG_LOG_GROUP_EXPAND) w = 'group';
  2116. groupCI.push([w, `%c${text1}%c${text2}`,
  2117. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  2118. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  2119. ]);
  2120. }
  2121. const groupEnd = () => {
  2122. if (!SHOW_DEVTOOL_DEBUG) return;
  2123. groupDI--;
  2124. if (groupDI !== 0) console_.warn('groupDI in groupEnd fails', groupDI);
  2125. if (groupCI.length >= 0) {
  2126. let withContent = false;
  2127. for (const entry of groupCI) {
  2128. if (entry[0] === 'group' || entry[0] === 'groupCollapsed') continue;
  2129. if (entry[1] === '[Begin]' || entry[1] === '[End]') continue;
  2130. withContent = true;
  2131. break;
  2132. }
  2133. if (withContent) {
  2134. for (const entry of groupCI) {
  2135. const args = entry.slice(1);
  2136. let colorHighLight = '';
  2137. for (const arg of args) {
  2138. if (typeof arg !== 'string') {
  2139. colorHighLight = '';
  2140. break;
  2141. }
  2142. if (arg === 'OK' || arg === 'NG') {
  2143. colorHighLight = arg;
  2144. } else {
  2145. if (arg.endsWith(' OK')) colorHighLight = 'OK';
  2146. else if (arg.endsWith(' NG')) colorHighLight = 'NG';
  2147. }
  2148. }
  2149. let print = args;
  2150. if (colorHighLight) {
  2151. print = [args.map(e => `%c${e}`).join(' '), ...args.map(e => {
  2152. if (colorHighLight === 'OK' && e.includes(colorHighLight)) return "background-color:rgb(29, 29, 29); color:rgb(57, 215, 83); font-weight: 600;";
  2153. if (colorHighLight === 'NG' && e.includes(colorHighLight)) return "background-color:rgb(29, 29, 29); color:rgb(215, 133, 57); font-weight: 600;";
  2154. return "background-color:rgb(29, 29, 29); color:rgb(231, 231, 231); font-weight: 400;";
  2155. })];
  2156. }
  2157. console[entry[0]](...print);
  2158. }
  2159. console.groupEnd();
  2160. groupCI.length = 0;
  2161. }
  2162. }
  2163. }
  2164.  
  2165. // const microNow = () => performance.now() + (performance.timeOrigin || performance.timing.navigationStart);
  2166.  
  2167.  
  2168. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  2169. const onRegistryReady = (callback) => {
  2170. if (typeof customElements === 'undefined') {
  2171. if (!('__CE_registry' in document)) {
  2172. // https://github.com/webcomponents/polyfills/
  2173. Object.defineProperty(document, '__CE_registry', {
  2174. get() {
  2175. // return undefined
  2176. },
  2177. set(nv) {
  2178. if (typeof nv == 'object') {
  2179. delete this.__CE_registry;
  2180. this.__CE_registry = nv;
  2181. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2182. }
  2183. return true;
  2184. },
  2185. enumerable: false,
  2186. configurable: true
  2187. })
  2188. }
  2189. let eventHandler = (evt) => {
  2190. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2191. const f = callback;
  2192. callback = null;
  2193. eventHandler = null;
  2194. f();
  2195. };
  2196. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2197. } else {
  2198. callback();
  2199. }
  2200. };
  2201.  
  2202. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  2203.  
  2204. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  2205.  
  2206. return new Promise(resolve => {
  2207.  
  2208. let ro = new ResizeObserver(entries => {
  2209. if (entries && entries.length >= 1) {
  2210. resolve();
  2211. ro.disconnect();
  2212. ro = null;
  2213. }
  2214. });
  2215. ro.observe(sizingTarget);
  2216.  
  2217.  
  2218.  
  2219. });
  2220.  
  2221. } : (sizingTarget) => {
  2222.  
  2223.  
  2224. return new Promise(resolve => {
  2225.  
  2226. let io = new IntersectionObserver(entries => {
  2227. if (entries && entries.length >= 1) {
  2228. resolve();
  2229. io.disconnect();
  2230. io = null;
  2231. }
  2232. });
  2233. io.observe(sizingTarget);
  2234.  
  2235.  
  2236.  
  2237. });
  2238.  
  2239. };
  2240.  
  2241. /* globals WeakRef:false */
  2242.  
  2243. /** @type {(o: Object | null) => WeakRef | null} */
  2244. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  2245.  
  2246. /** @type {(wr: Object | null) => Object | null} */
  2247. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  2248.  
  2249. const { insertBeforeNaFn, appendChildNaFn } = (() => {
  2250. // native methods
  2251.  
  2252. const dummyElement = document.createElement('dummy-388');
  2253. const HTMLElement = dummyElement.constructor;
  2254.  
  2255. const insertBefore = HTMLElement.prototype.insertBefore;
  2256. const appendChild = HTMLElement.prototype.appendChild;
  2257.  
  2258. return {
  2259. insertBeforeNaFn: (parent, node, child) => {
  2260. insertBefore.call(parent, node, child);
  2261. },
  2262. appendChildNaFn: (parent, node) => {
  2263. appendChild.call(parent, node);
  2264. }
  2265. };
  2266.  
  2267. /*
  2268. const insertBeforeFn = (parent, node, child) => {
  2269. if ('__shady_native_insertBefore' in parent) parent.__shady_native_insertBefore(node, child);
  2270. else parent.insertBefore(node, child);
  2271. }
  2272.  
  2273. const appendChildFn = (parent, node) =>{
  2274. if('__shady_native_appendChild' in parent) parent.__shady_native_appendChild(node);
  2275. else parent.appendChild(node);
  2276. }
  2277. */
  2278.  
  2279. })();
  2280.  
  2281.  
  2282.  
  2283. let __LCRInjection__ = 0; // 0 for no injection
  2284. const LCRImmedidates = []; // array of sync. func
  2285.  
  2286. let getLCRDummyP_ = null;
  2287. // lcrPromiseFn
  2288. const getLCRDummy = () => {
  2289.  
  2290. /* remarks */
  2291.  
  2292. /*
  2293.  
  2294. // YouTube uses `<ps-dom-if class="style-scope ytd-live-chat-frame"><template></template></ps-dom-if>` to create yt-live-chat-renderer
  2295. // <ps-dom-if> is located inside ytd-live-chat-frame#chat in main frame
  2296. // <ps-dom-if>.hostElement is located as iframe's yt-live-chat-app > div#contents > yt-live-chat-renderer
  2297.  
  2298. */
  2299.  
  2300.  
  2301. // direct createElement or createComponent_ will make the emoji rendering crashed. reason TBC
  2302.  
  2303. return getLCRDummyP_ || (getLCRDummyP_ = Promise.all([customElements.whenDefined('yt-live-chat-app'), customElements.whenDefined('yt-live-chat-renderer')]).then(async () => {
  2304.  
  2305. const tag = "yt-live-chat-renderer"
  2306. let dummy = document.querySelector(tag);
  2307. if (!dummy) {
  2308.  
  2309. let mo = null;
  2310.  
  2311. const ytLiveChatApp = document.querySelector('yt-live-chat-app') || document.createElement('yt-live-chat-app');
  2312.  
  2313. const lcaProto = getProto(ytLiveChatApp);
  2314. let fz38;
  2315.  
  2316. let qt38=0;
  2317. let bypass = false;
  2318.  
  2319.  
  2320. dummy = await new Promise(resolve => {
  2321.  
  2322.  
  2323. if (typeof lcaProto.createComponent_ === 'function' && !lcaProto.createComponent99_ && lcaProto.createComponent_.length === 3) {
  2324. console.log('[yt-chat-lcr] lcaProto.createComponent_ is found');
  2325.  
  2326. lcaProto.createComponent99_ = lcaProto.createComponent_;
  2327. lcaProto.createComponent98_ = function (a, b, c) {
  2328. const z = customCreateComponent(a,b,c);
  2329. if(z !== undefined) return z;
  2330. // (3) ['yt-live-chat-renderer', {…}, true]
  2331. const r = this.createComponent99_(a, b,c);
  2332. const componentTag = (typeof a === 'string' ? a : (a||0).component) || `${(r||0).nodeName}`.toLowerCase();
  2333. if ( componentTag === 'yt-live-chat-renderer' && !bypass) {
  2334. qt38 = 1;
  2335.  
  2336. __LCRInjection__ = __LCRInjection__ | 1;
  2337.  
  2338. // r.polymerController.__proto__.handleLiveChatActions471_ = r.polymerController.__proto__.handleLiveChatActions_;
  2339. // r.polymerController.__proto__.handleLiveChatActions_ = function (arr) {
  2340.  
  2341.  
  2342. // preprocessChatLiveActions(arr);
  2343.  
  2344. // return this.handleLiveChatActions471_(arr);
  2345.  
  2346.  
  2347. // }
  2348.  
  2349. for (const f of LCRImmedidates) {
  2350. f(r);
  2351. }
  2352. LCRImmedidates.length = 0;
  2353.  
  2354. resolve(r); // note: this dom is not yet adopted, but promise resolve is later than ops.
  2355. console.log('[yt-chat-lcr] element found by method 1');
  2356. }
  2357. return r;
  2358. };
  2359. lcaProto.createComponent_ = lcaProto.createComponent98_;
  2360.  
  2361. if (!USE_OBTAIN_LCR_BY_BOTH_METHODS) return;
  2362.  
  2363. }
  2364.  
  2365. // console.log('[yt-chat] lcaProto traditional');
  2366.  
  2367. const pz38 = document.getElementsByTagName(tag);
  2368. fz38 = () => {
  2369. const t = pz38[0]
  2370. if (t) {
  2371. qt38 = 2;
  2372.  
  2373. __LCRInjection__ = __LCRInjection__ | 2;
  2374. resolve(t);
  2375. console.log('[yt-chat-lcr] element found by method 2');
  2376. }
  2377. };
  2378. mo = new MutationObserver(fz38);
  2379. mo.observe(document, { subtree: true, childList: true, attributes: true });
  2380. document.addEventListener('yt-action', fz38, true);
  2381. fz38();
  2382.  
  2383. });
  2384.  
  2385. bypass = true;
  2386.  
  2387. if (mo) {
  2388. mo.disconnect();
  2389. mo.takeRecords();
  2390. mo = null;
  2391. }
  2392. if (fz38) {
  2393. document.removeEventListener('yt-action', fz38, true);
  2394. fz38 = null;
  2395. }
  2396. console.log(`[yt-chat-lcr] lcr appears, dom = ${document.getElementsByTagName(tag).length}, method = ${qt38}`);
  2397.  
  2398.  
  2399. // if (lcaProto.createComponent99_ && lcaProto.createComponent_ && lcaProto.createComponent98_ === lcaProto.createComponent_) {
  2400. // lcaProto.createComponent_ = lcaProto.createComponent99_;
  2401. // lcaProto.createComponent99_ = null;
  2402. // lcaProto.createComponent98_ = null;
  2403. // }
  2404.  
  2405. } else {
  2406. console.log('[yt-chat-lcr] lcr exists');
  2407. }
  2408. return dummy;
  2409.  
  2410. }));
  2411. }
  2412.  
  2413. const { addCssManaged } = (() => {
  2414.  
  2415. const addFontPreRendering = () => {
  2416.  
  2417. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  2418.  
  2419. let efsContainer = document.createElement('elzm-fonts');
  2420. efsContainer.id = 'elzm-fonts-yk75g'
  2421.  
  2422. const arr = [];
  2423. let p = document.createElement('elzm-font');
  2424. arr.push(p);
  2425.  
  2426. if (ENABLE_FONT_PRE_RENDERING & 1) {
  2427. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2428.  
  2429. p = document.createElement('elzm-font');
  2430. p.style.fontWeight = size;
  2431. arr.push(p);
  2432. }
  2433. }
  2434.  
  2435. if (ENABLE_FONT_PRE_RENDERING & 2) {
  2436. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2437.  
  2438. p = document.createElement('elzm-font');
  2439. p.style.fontFamily = 'Roboto';
  2440. p.style.fontWeight = size;
  2441. arr.push(p);
  2442. }
  2443. }
  2444.  
  2445. if (ENABLE_FONT_PRE_RENDERING & 4) {
  2446. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2447.  
  2448. p = document.createElement('elzm-font');
  2449. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  2450. p.style.fontWeight = size;
  2451. arr.push(p);
  2452. }
  2453. }
  2454.  
  2455.  
  2456. if (ENABLE_FONT_PRE_RENDERING & 8) {
  2457. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2458.  
  2459. p = document.createElement('elzm-font');
  2460. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  2461. p.style.fontWeight = size;
  2462. arr.push(p);
  2463. }
  2464. }
  2465.  
  2466.  
  2467. if (ENABLE_FONT_PRE_RENDERING & 16) {
  2468. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2469.  
  2470. p = document.createElement('elzm-font');
  2471. p.style.fontFamily = 'sans-serif';
  2472. p.style.fontWeight = size;
  2473. arr.push(p);
  2474. }
  2475. }
  2476.  
  2477. console1.log('number of elzm-font elements', arr.length);
  2478.  
  2479. HTMLElement.prototype.append.apply(efsContainer, arr);
  2480.  
  2481. (document.body || document.documentElement).appendChild(efsContainer);
  2482.  
  2483.  
  2484. console1.log('elzm-font elements have been added to the page for rendering.');
  2485.  
  2486. groupEnd();
  2487.  
  2488. }
  2489.  
  2490. let isCssAdded = false;
  2491.  
  2492. function addCssElement() {
  2493. let s = document.createElement('style');
  2494. s.id = 'ewRvC';
  2495. return s;
  2496. }
  2497.  
  2498. const addCssManaged = () => {
  2499. if (!isCssAdded && document.documentElement && document.head) {
  2500. isCssAdded = true;
  2501. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  2502. if (ENABLE_FONT_PRE_RENDERING) {
  2503. Promise.resolve().then(addFontPreRendering)
  2504. }
  2505. }
  2506. }
  2507.  
  2508. return { addCssManaged };
  2509. })();
  2510.  
  2511.  
  2512. const { setupStyle } = (() => {
  2513.  
  2514. const sp7 = Symbol();
  2515.  
  2516. const proxyHelperFn = (dummy) => ({
  2517.  
  2518. get(target, prop) {
  2519. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  2520. },
  2521. set(target, prop, value) {
  2522. if (!(prop in dummy)) {
  2523. target[prop] = value;
  2524. }
  2525. return true;
  2526. },
  2527. has(target, prop) {
  2528. return (prop in target);
  2529. },
  2530. deleteProperty(target, prop) {
  2531. return true;
  2532. },
  2533. ownKeys(target) {
  2534. return Object.keys(target);
  2535. },
  2536. defineProperty(target, key, descriptor) {
  2537. return Object.defineProperty(target, key, descriptor);
  2538. },
  2539. getOwnPropertyDescriptor(target, key) {
  2540. return Object.getOwnPropertyDescriptor(target, key);
  2541. },
  2542.  
  2543. });
  2544.  
  2545. const setupStyle = (m1, m2) => {
  2546. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  2547.  
  2548. const dummy1v = {
  2549. transform: '',
  2550. height: '',
  2551. minHeight: '',
  2552. paddingBottom: '',
  2553. paddingTop: ''
  2554. };
  2555.  
  2556. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  2557. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  2558. dummy1v[k] = dummyStyleFn(k);
  2559. }
  2560.  
  2561. const dummy1p = proxyHelperFn(dummy1v);
  2562. const sp1v = new Proxy(m1.style, dummy1p);
  2563. const sp2v = new Proxy(m2.style, dummy1p);
  2564. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  2565. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  2566. m1.removeAttribute("style");
  2567. m2.removeAttribute("style");
  2568.  
  2569. }
  2570.  
  2571. return { setupStyle };
  2572.  
  2573. })();
  2574.  
  2575.  
  2576.  
  2577. function setThumbnails(config) {
  2578.  
  2579. const { baseObject, thumbnails, flag0, imageLinks } = config;
  2580.  
  2581. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  2582.  
  2583.  
  2584. if (thumbnails && thumbnails.length > 0) {
  2585. if (flag0 > 0 && thumbnails.length > 1) {
  2586. let pSize = 0;
  2587. let newThumbnails = [];
  2588. for (const thumbnail of thumbnails) {
  2589. if (!thumbnail || !thumbnail.url) continue;
  2590. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  2591. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  2592. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  2593. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  2594. newThumbnails.push(thumbnail);
  2595. if (imageLinks) imageLinks.add(thumbnail.url);
  2596. }
  2597. if (squarePhoto && condSize && leastSizeFulfilled) {
  2598. pSize = thumbnail.width;
  2599. }
  2600. }
  2601. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  2602. baseObject.thumbnails = newThumbnails;
  2603. } else {
  2604. newThumbnails.length = 0;
  2605. }
  2606. newThumbnails = null;
  2607. } else {
  2608. for (const thumbnail of thumbnails) {
  2609. if (thumbnail && thumbnail.url) {
  2610. if (imageLinks) imageLinks.add(thumbnail.url);
  2611. }
  2612. }
  2613. }
  2614. }
  2615.  
  2616. }
  2617. }
  2618.  
  2619. function fixLiveChatItem(item, imageLinks) {
  2620. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  2621. if (liveChatTextMessageRenderer) {
  2622. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  2623. if (messageRuns && messageRuns.length > 0) {
  2624. for (const run of messageRuns) {
  2625. const emojiImage = (((run || 0).emoji || 0).image || 0);
  2626. setThumbnails({
  2627. baseObject: emojiImage,
  2628. thumbnails: emojiImage.thumbnails,
  2629. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  2630. imageLinks
  2631. });
  2632. }
  2633. }
  2634. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  2635. setThumbnails({
  2636. baseObject: authorPhoto,
  2637. thumbnails: authorPhoto.thumbnails,
  2638. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  2639. imageLinks
  2640. });
  2641. }
  2642. }
  2643.  
  2644.  
  2645.  
  2646. let kptPF = null;
  2647. const emojiPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_EMOJI);
  2648. const authorPhotoPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO);
  2649.  
  2650. function linker(link, rel, href, _as) {
  2651. return new Promise(resolve => {
  2652. if (!link) link = document.createElement('link');
  2653. link.rel = rel;
  2654. if (_as) link.setAttribute('as', _as);
  2655. link.onload = function () {
  2656. resolve({
  2657. link: this,
  2658. success: true
  2659. })
  2660. this.remove();
  2661. };
  2662. link.onerror = function () {
  2663. resolve({
  2664. link: this,
  2665. success: false
  2666. });
  2667. this.remove();
  2668. };
  2669. link.href = href;
  2670. document.head.appendChild(link);
  2671. link = null;
  2672. });
  2673. }
  2674.  
  2675.  
  2676.  
  2677. const cleanContext = async (win) => {
  2678. const waitFn = requestAnimationFrame; // shall have been binded to window
  2679. try {
  2680. let mx = 16; // MAX TRIAL
  2681. const frameId = 'vanillajs-iframe-v1';
  2682. /** @type {HTMLIFrameElement | null} */
  2683. let frame = document.getElementById(frameId);
  2684. let removeIframeFn = null;
  2685. if (!frame) {
  2686. frame = document.createElement('iframe');
  2687. frame.id = frameId;
  2688. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2689. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2690. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2691. n.appendChild(frame);
  2692. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2693. const root = document.documentElement;
  2694. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2695. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2696.  
  2697. removeIframeFn = (setTimeout) => {
  2698. const removeIframeOnDocumentReady = (e) => {
  2699. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2700. e = n;
  2701. n = win = removeIframeFn = 0;
  2702. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2703. }
  2704. if (!setTimeout || document.readyState !== 'loading') {
  2705. removeIframeOnDocumentReady();
  2706. } else {
  2707. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2708. }
  2709. }
  2710. }
  2711. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2712. const fc = frame.contentWindow;
  2713. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2714. try {
  2715. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle } = fc;
  2716. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle };
  2717. for (let k in res) res[k] = res[k].bind(win); // necessary
  2718. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2719.  
  2720. /** @type {HTMLElement} */
  2721. const HTMLElementProto = fc.HTMLElement.prototype;
  2722. /** @type {EventTarget} */
  2723. const EventTargetProto = fc.EventTarget.prototype;
  2724. // jsonParseFix = {
  2725. // _JSON: fc.JSON, _parse: fc.JSON.parse
  2726. // }
  2727. return {
  2728. ...res,
  2729. animate: HTMLElementProto.animate,
  2730. addEventListener: EventTargetProto.addEventListener,
  2731. removeEventListener: EventTargetProto.removeEventListener
  2732. };
  2733. } catch (e) {
  2734. if (removeIframeFn) removeIframeFn();
  2735. return null;
  2736. }
  2737. } catch (e) {
  2738. console.warn(e);
  2739. return null;
  2740. }
  2741. };
  2742.  
  2743. let xoIcjPr = null;
  2744. const xoIcjId = `xoIcj${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2745. const xoIcjPost = window.postMessage.bind(window, xoIcjId);
  2746. window.addEventListener('message', (evt) => {
  2747. if ((evt || 0).data === xoIcjId) {
  2748. const t = xoIcjPr;
  2749. if (t !== null) {
  2750. xoIcjPr = null;
  2751. t.resolve();
  2752. }
  2753. }
  2754. });
  2755. const timelineResolve = async () => {
  2756. let t = xoIcjPr;
  2757. if (t === null) {
  2758. t = xoIcjPr = new PromiseExternal();
  2759. xoIcjPost();
  2760. }
  2761. await t.then();
  2762. }
  2763.  
  2764. cleanContext(win).then(__CONTEXT__ => {
  2765. if (!__CONTEXT__) return null;
  2766.  
  2767. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, getComputedStyle, addEventListener, removeEventListener } = __CONTEXT__;
  2768.  
  2769. const wmComputedStyle = new WeakMap();
  2770. const getComputedStyleCached = (elem) => {
  2771. let cs = wmComputedStyle.get(elem);
  2772. if (!cs) {
  2773. cs = getComputedStyle(elem);
  2774. wmComputedStyle.set(elem, cs);
  2775. }
  2776. return cs;
  2777. }
  2778.  
  2779.  
  2780. const isGPUAccelerationAvailable = (() => {
  2781. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  2782. try {
  2783. const canvas = document.createElement('canvas');
  2784. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  2785. } catch (e) {
  2786. return false;
  2787. }
  2788. })();
  2789.  
  2790. const foregroundPromiseFn_noGPU = (() => {
  2791.  
  2792. if (isGPUAccelerationAvailable) return null;
  2793.  
  2794. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  2795. if (!pd || typeof pd.get !== 'function') return null;
  2796. const pdGet = pd.get;
  2797.  
  2798. let pr = null;
  2799.  
  2800. let hState = pdGet.call(document) === 'hidden';
  2801. // let cid = 0;
  2802. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  2803. const newHState = pdGet.call(document) === 'hidden';
  2804. if (hState !== newHState) {
  2805. // if (cid > 0) cid = clearInterval(cid);
  2806. hState = newHState;
  2807. if (!hState && pr) pr = pr.resolve();
  2808. }
  2809. });
  2810.  
  2811. // cid = setInterval(() => {
  2812. // const newHState = document.visibilityState === 'hidden';
  2813. // if (hState !== newHState) {
  2814. // hState = newHState;
  2815. // if (!hState && pr) pr = pr.resolve();
  2816. // }
  2817. // }, 100);
  2818.  
  2819.  
  2820. return (() => {
  2821. if (pr) return pr;
  2822. const w = ((!hState && setTimeout(() => {
  2823. if (!hState && pr === w) pr = pr.resolve();
  2824. })), (pr = new PromiseExternal()));
  2825. return w;
  2826. });
  2827.  
  2828. })();
  2829.  
  2830. // window.foregroundPromiseFn_noGPU = foregroundPromiseFn_noGPU;
  2831.  
  2832. let rafPromise = null;
  2833. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2834. requestAnimationFrame(hRes => {
  2835. rafPromise = null;
  2836. resolve(hRes);
  2837. });
  2838. }));
  2839. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  2840.  
  2841. const iAFP = foregroundPromiseFn_noGPU ? foregroundPromiseFn_noGPU : typeof IntersectionObserver === 'undefined' ? getRafPromise : (() => {
  2842.  
  2843. const ioWM = new WeakMap();
  2844. const ek = Symbol();
  2845. /** @type {IntersectionObserverCallback} */
  2846. const ioCb = (entries, observer) => {
  2847. /** @type {PromiseExternal} */
  2848. const pr = observer[ek];
  2849. const resolve = pr.resolve;
  2850. let target;
  2851. if (resolve && (target = ((entries ? entries[0] : 0) || 0).target) instanceof Element) {
  2852. pr.resolve = null;
  2853. observer.unobserve(target);
  2854. resolve();
  2855. }
  2856. };
  2857. /**
  2858. *
  2859. * @param {Element} elm
  2860. * @returns {Promise<void>}
  2861. */
  2862. const iAFP = (elm) => {
  2863. let io = ioWM.get(elm);
  2864. if (!io) {
  2865. io = new IntersectionObserver(ioCb);
  2866. ioWM.set(elm, io); // strong reference
  2867. }
  2868. let pr = io[ek];
  2869. if (!pr) {
  2870. pr = io[ek] = new PromiseExternal();
  2871. io.observe(elm);
  2872. }
  2873. return pr;
  2874. }
  2875.  
  2876. return iAFP;
  2877.  
  2878. })();
  2879.  
  2880. let playerState = null;
  2881. let _playerState = null;
  2882. let lastPlayerProgress = null;
  2883. let relayCount = 0;
  2884. let playerEventsByIframeRelay = false;
  2885. let isPlayProgressTriggered = false;
  2886. let waitForInitialDataCompletion = 0;
  2887.  
  2888.  
  2889.  
  2890. // let aeConstructor = null;
  2891.  
  2892. // << __openedChanged82 >>
  2893. let currentMenuPivotWR = null;
  2894.  
  2895. // << if DO_PARTICIPANT_LIST_HACKS >>
  2896. const beforeParticipantsMap = new WeakMap();
  2897. // << end >>
  2898.  
  2899.  
  2900.  
  2901. // << if onRegistryReadyForDOMOperations >>
  2902.  
  2903. let dt0 = Date.now() - 2000;
  2904. const dateNow = () => Date.now() - dt0;
  2905. // let lastScroll = 0;
  2906. // let lastLShow = 0;
  2907. let lastWheel = 0;
  2908. let lastMouseUp = 0;
  2909. let currentMouseDown = false;
  2910. let lastTouchDown = 0;
  2911. let lastTouchUp = 0;
  2912. let currentTouchDown = false;
  2913. let lastUserInteraction = 0;
  2914.  
  2915. let scrollChatFn = null;
  2916.  
  2917. // let skipDontRender = true; // true first; false by flushActiveItems_
  2918. // let allowDontRender = null;
  2919.  
  2920. // ---- #items mutation ----
  2921. let sk35zResolveFn = null;
  2922. // let firstList = true;
  2923.  
  2924. // << end >>
  2925.  
  2926. class RAFHub {
  2927. constructor() {
  2928. /** @type {number} */
  2929. this.startAt = 8170;
  2930. /** @type {number} */
  2931. this.counter = 0;
  2932. /** @type {number} */
  2933. this.rid = 0;
  2934. /** @type {Map<number, FrameRequestCallback>} */
  2935. this.funcs = new Map();
  2936. const funcs = this.funcs;
  2937. /** @type {FrameRequestCallback} */
  2938. this.bCallback = this.mCallback.bind(this);
  2939. this.pClear = () => funcs.clear();
  2940. this.keepRAF = false;
  2941. }
  2942. /** @param {DOMHighResTimeStamp} highResTime */
  2943. mCallback(highResTime) {
  2944. this.rid = 0;
  2945. Promise.resolve().then(this.pClear);
  2946. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2947. }
  2948. /** @param {FrameRequestCallback} f */
  2949. request(f) {
  2950. const cid = this.startAt + (this.counter = (this.counter & 1073741823) + 1);
  2951. this.funcs.set(cid, f);
  2952. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  2953. return cid;
  2954. }
  2955. /** @param {number} cid */
  2956. cancel(cid) {
  2957. cid = +cid;
  2958. if (cid > 0) {
  2959. if (cid <= this.startAt) {
  2960. return cancelAnimationFrame(cid);
  2961. }
  2962. if (this.rid > 0) {
  2963. this.funcs.delete(cid);
  2964. if (this.funcs.size === 0 && !this.keepRAF) {
  2965. cancelAnimationFrame(this.rid);
  2966. this.rid = 0;
  2967. }
  2968. }
  2969. }
  2970. }
  2971. }
  2972.  
  2973. function basePrefetching() {
  2974.  
  2975. new Promise(resolve => {
  2976.  
  2977. if (document.readyState !== 'loading') {
  2978. resolve();
  2979. } else {
  2980. win.addEventListener("DOMContentLoaded", resolve, false);
  2981. }
  2982.  
  2983. }).then(() => {
  2984. const hostL1 = [
  2985. 'https://www.youtube.com', 'https://googlevideo.com',
  2986. 'https://googleapis.com', 'https://accounts.youtube.com',
  2987. 'https://www.gstatic.com', 'https://ggpht.com',
  2988. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  2989. ];
  2990.  
  2991. const hostL2 = [
  2992. 'https://youtube.com',
  2993. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  2994. ];
  2995.  
  2996. let link = null;
  2997.  
  2998. function kn() {
  2999.  
  3000. link = document.createElement('link');
  3001. if (link.relList && link.relList.supports) {
  3002. 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)
  3003. } else {
  3004. kptPF = 0;
  3005. }
  3006.  
  3007. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  3008. if (ENABLE_BASE_PREFETCHING) console1.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  3009. if (ENABLE_BASE_PREFETCHING) console1.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  3010. if (ENABLE_PRELOAD_THUMBNAIL) console1.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  3011. if (ENABLE_PRELOAD_THUMBNAIL) console1.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  3012. groupEnd();
  3013.  
  3014. }
  3015.  
  3016. for (const h of hostL1) {
  3017.  
  3018. if (kptPF === null) kn();
  3019. if (ENABLE_BASE_PREFETCHING) {
  3020. // if (kptPF & 1) {
  3021. // linker(link, 'dns-prefetch', h);
  3022. // link = null;
  3023. // }
  3024. if (kptPF & 2) {
  3025. linker(link, 'preconnect', h);
  3026. link = null;
  3027. }
  3028. }
  3029. }
  3030.  
  3031. for (const h of hostL2) {
  3032. if (kptPF === null) kn();
  3033. if (ENABLE_BASE_PREFETCHING) {
  3034. if (kptPF & 1) {
  3035. linker(link, 'dns-prefetch', h);
  3036. link = null;
  3037. }
  3038. }
  3039. }
  3040.  
  3041. })
  3042.  
  3043.  
  3044. }
  3045.  
  3046. if (DO_LINK_PREFETCH) basePrefetching();
  3047.  
  3048. const { notifyPath7081 } = (() => {
  3049. // DO_PARTICIPANT_LIST_HACKS
  3050.  
  3051. const mutexParticipants = new Mutex();
  3052.  
  3053. let uvid = 0;
  3054. let r95dm = 0;
  3055. let c95dm = -1;
  3056.  
  3057. const foundMap = (base, content) => {
  3058. /*
  3059. let lastSearch = 0;
  3060. let founds = base.map(baseEntry => {
  3061. let search = content.indexOf(baseEntry, lastSearch);
  3062. if (search < 0) return false;
  3063. lastSearch = search + 1;
  3064. return true;
  3065. });
  3066. return founds;
  3067. */
  3068. const contentSet = new Set(content);
  3069. return base.map(baseEntry => contentSet.has(baseEntry));
  3070.  
  3071. }
  3072.  
  3073.  
  3074.  
  3075. let participantsForSpliceWR = null;
  3076.  
  3077. class IndexSpliceEntry {
  3078. /**
  3079. *
  3080. * @param {number} _index
  3081. * @param {number} _addedCount
  3082. * @param {any[]} _removed
  3083. */
  3084. constructor(_index, _addedCount, _removed) {
  3085. this.index = _index;
  3086. this.addedCount = _addedCount;
  3087. this.removed = _removed;
  3088. }
  3089. get __proxy312__() {
  3090. return 1
  3091. }
  3092. get type() {
  3093. return 'splice'
  3094. }
  3095. get object() {
  3096. return kRef(participantsForSpliceWR); // avoid memory leakage
  3097. }
  3098. }
  3099.  
  3100. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  3101.  
  3102. let foundsForAfter = foundMap(idsAfter, idsBefore);
  3103. let foundsForBefore = foundMap(idsBefore, idsAfter);
  3104.  
  3105. const nAfter = foundsForAfter.length;
  3106. const nBefore = foundsForBefore.length;
  3107.  
  3108. const indexSplices = [];
  3109. const contentUpdates = [];
  3110. participantsForSpliceWR = null;
  3111. for (let i = 0, j = 0; i < nBefore || j < nAfter;) {
  3112. if (beforeParticipants[i] === participants[j]) {
  3113. i++; j++;
  3114. } else if (idsBefore[i] === idsAfter[j]) {
  3115. // content changed
  3116. contentUpdates.push({ indexI: i, indexJ: j })
  3117. i++; j++;
  3118. } else {
  3119. let addedCount = 0;
  3120. for (let q = j; q < nAfter; q++) {
  3121. if (foundsForAfter[q] === false) addedCount++;
  3122. else break;
  3123. }
  3124. let removedCount = 0;
  3125. for (let q = i; q < nBefore; q++) {
  3126. if (foundsForBefore[q] === false) removedCount++;
  3127. else break;
  3128. }
  3129. if (!addedCount && !removedCount) {
  3130. throw 'ERROR(0xFF32): spliceIndicesFunc';
  3131. }
  3132. const entry = new IndexSpliceEntry(
  3133. j,
  3134. addedCount,
  3135. removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  3136. );
  3137. indexSplices.push(entry);
  3138. i += removedCount;
  3139. j += addedCount;
  3140. }
  3141. }
  3142. foundsForBefore = null;
  3143. foundsForAfter = null;
  3144. idsBefore = null;
  3145. idsAfter = null;
  3146. beforeParticipants = null;
  3147. participantsForSpliceWR = indexSplices.length > 0 ? mWeakRef(participants) : null;
  3148. participants = null;
  3149. return { indexSplices, contentUpdates };
  3150.  
  3151. }
  3152.  
  3153. /*
  3154.  
  3155. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  3156.  
  3157. VM63631:1 Error
  3158. at customElements.get.notifyPath (<anonymous>:1:122)
  3159. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  3160. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  3161. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  3162. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  3163. at ju (live_chat_polymer.js:1674:217)
  3164. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  3165. at b._flushProperties (live_chat_polymer.js:1597:200)
  3166. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  3167. at a.notifyPath (live_chat_polymer.js:1741:182)
  3168.  
  3169. */
  3170.  
  3171. function convertToIds(participants) {
  3172. return participants.map(participant => {
  3173. if (!participant || typeof participant !== 'object') {
  3174. console.warn('Error(0xFA41): convertToIds', participant);
  3175. return participant; // just in case
  3176. }
  3177. let keys = Object.keys(participant);
  3178. // liveChatTextMessageRenderer
  3179. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  3180. // liveChatPaidMessageRenderer
  3181. /*
  3182.  
  3183. 'yt-live-chat-participant-renderer' utilizes the following:
  3184. authorName.simpleText: string
  3185. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  3186. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  3187. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  3188. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  3189.  
  3190. */
  3191. if (keys.length !== 1) {
  3192. console.warn('Error(0xFA42): convertToIds', participant);
  3193. return participant; // just in case
  3194. }
  3195. let key = keys[0];
  3196. let renderer = (participant[key] || 0);
  3197. let authorName = (renderer.authorName || 0);
  3198. let text = `${authorName.simpleText || authorName.text}`
  3199. let res = participant; // fallback if it is not a vaild entry
  3200. if (typeof text !== 'string') {
  3201. console.warn('Error(0xFA53): convertToIds', participant);
  3202. } else {
  3203. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  3204. if (text.length > 1) res = text;
  3205. }
  3206. return res;
  3207. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  3208. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  3209. });
  3210. }
  3211.  
  3212. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  3213. // just update when content is changed.
  3214. if (p1.authorName !== p2.authorName) return true;
  3215. if (p1.authorPhoto !== p2.authorPhoto) return true;
  3216. if (p1.authorBadges !== p2.authorBadges) return true;
  3217. return false;
  3218. } : (p1, p2) => {
  3219. // keep integrity all the time.
  3220. return p1 !== p2; // always true
  3221. }
  3222.  
  3223. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  3224.  
  3225. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  3226. if (path !== "participantsManager.participants") {
  3227. return this.__notifyPath5036__.apply(this, arguments);
  3228. }
  3229. if (c95dm === r95dm) return;
  3230. } else {
  3231. const stack = new Error().stack;
  3232. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  3233. return this.__notifyPath5036__.apply(this, arguments);
  3234. }
  3235. }
  3236.  
  3237. if (uvid > 1e8) uvid = uvid % 100;
  3238. let tid = ++uvid;
  3239.  
  3240.  
  3241. // const cnt = this; // "yt-live-chat-participant-list-renderer"
  3242.  
  3243. const wNode = mWeakRef(this);
  3244.  
  3245. mutexParticipants.lockWith(lockResolve => {
  3246.  
  3247. const cnt = kRef(wNode);
  3248.  
  3249. const participants00 = (((cnt || 0).participantsManager || 0).participants || 0);
  3250.  
  3251. if (tid !== uvid || !cnt || typeof (participants00 || 0).splice !== 'function') {
  3252. lockResolve();
  3253. return;
  3254. }
  3255.  
  3256. let doUpdate = false;
  3257.  
  3258. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  3259.  
  3260. if (!participants00.r94dm) {
  3261. participants00.r94dm = 1;
  3262. r95dm = (r95dm & 1073741823) + 1;
  3263. participants00.push = function () {
  3264. r95dm = (r95dm & 1073741823) + 1;
  3265. return Array.prototype.push.apply(this, arguments);
  3266. }
  3267. participants00.pop = function () {
  3268. r95dm = (r95dm & 1073741823) + 1;
  3269. return Array.prototype.pop.apply(this, arguments);
  3270. }
  3271. participants00.shift = function () {
  3272. r95dm = (r95dm & 1073741823) + 1;
  3273. return Array.prototype.shift.apply(this, arguments);
  3274. }
  3275. participants00.unshift = function () {
  3276. r95dm = (r95dm & 1073741823) + 1;
  3277. return Array.prototype.unshift.apply(this, arguments);
  3278. }
  3279. participants00.splice = function () {
  3280. r95dm = (r95dm & 1073741823) + 1;
  3281. return Array.prototype.splice.apply(this, arguments);
  3282. }
  3283. participants00.sort = function () {
  3284. r95dm = (r95dm & 1073741823) + 1;
  3285. return Array.prototype.sort.apply(this, arguments);
  3286. }
  3287. participants00.reverse = function () {
  3288. r95dm = (r95dm & 1073741823) + 1;
  3289. return Array.prototype.reverse.apply(this, arguments);
  3290. }
  3291. }
  3292.  
  3293. if (c95dm !== r95dm) {
  3294. c95dm = r95dm;
  3295. doUpdate = true;
  3296. }
  3297.  
  3298. } else {
  3299. doUpdate = true;
  3300. }
  3301.  
  3302. if (!doUpdate) {
  3303. lockResolve();
  3304. return;
  3305. }
  3306.  
  3307. const participants = participants00.slice(0);
  3308. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  3309. beforeParticipantsMap.set(cnt, participants);
  3310.  
  3311. const resPromise = (async () => {
  3312.  
  3313. if (beforeParticipants.length === 0) {
  3314. // not error
  3315. return 0;
  3316. }
  3317.  
  3318. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  3319.  
  3320. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  3321. if (beforeParticipants.length !== countOfElements) {
  3322. // there is somewrong for the cache. - sometimes happen
  3323. return 0;
  3324. }
  3325.  
  3326. const idsBefore = convertToIds(beforeParticipants);
  3327. const idsAfter = convertToIds(participants);
  3328.  
  3329. let { indexSplices, contentUpdates } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  3330.  
  3331. let res = 1; // default 1 for no update
  3332.  
  3333. if (indexSplices.length >= 1) {
  3334.  
  3335.  
  3336. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  3337. // let p1 = indexSplices[0].removed;
  3338. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  3339.  
  3340. /* folllow
  3341. a.notifyPath(c + ".splices", d);
  3342. a.notifyPath(c + ".length", b.length);
  3343. */
  3344. // stampDomArraySplices_
  3345.  
  3346.  
  3347. await new Promise(resolve => {
  3348. cnt.resolveForDOMRendering781 = resolve;
  3349.  
  3350. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  3351. indexSplices
  3352. });
  3353. indexSplices = null;
  3354. participantsForSpliceWR = null;
  3355. cnt.__notifyPath5036__("participantsManager.participants.length",
  3356. participants.length
  3357. );
  3358.  
  3359. });
  3360.  
  3361. // play safe for the change of 'length'
  3362. if (typeof nextBrowserTick !== 'function') {
  3363. await Promise.resolve(0);
  3364. } else {
  3365. await new Promise(resolve => nextBrowserTick(resolve)).then();
  3366. }
  3367.  
  3368. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  3369.  
  3370. const wrongSize = participants.length !== countOfElements
  3371. if (wrongSize) {
  3372. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  3373. return 0;
  3374. }
  3375.  
  3376. res = 2 | 4;
  3377.  
  3378. } else {
  3379.  
  3380. indexSplices = null;
  3381. participantsForSpliceWR = null;
  3382.  
  3383. if (participants.length !== countOfElements) {
  3384. // other unhandled cases
  3385. return 0;
  3386. }
  3387.  
  3388. }
  3389.  
  3390. // participants.length === countOfElements before contentUpdates
  3391. if (contentUpdates.length >= 1) {
  3392. for (const contentUpdate of contentUpdates) {
  3393. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  3394. if (isChanged) {
  3395. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  3396. res |= 4 | 8;
  3397. }
  3398. }
  3399. }
  3400. contentUpdates = null;
  3401.  
  3402. return res;
  3403.  
  3404.  
  3405. })();
  3406.  
  3407.  
  3408. resPromise.then(async (resValue) => {
  3409. const condition = resValue === 0 ? 1 : (resValue & 4) === 4 ? 2 : 0;
  3410. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && condition > 0;
  3411. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  3412. if (condition === 1) {
  3413. isLogRequired && console1.log("Full Refresh begins");
  3414. await new Promise(resolve => {
  3415. cnt.resolveForDOMRendering781 = resolve;
  3416. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  3417. });
  3418. isLogRequired && console1.log("Full Refresh ends");
  3419. } else if (condition === 2) {
  3420. isLogRequired && console1.log(`Number of participants (before): ${beforeParticipants.length}`);
  3421. isLogRequired && console1.log(`Number of participants (after): ${participants.length}`);
  3422. isLogRequired && console1.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  3423. isLogRequired && console1.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  3424. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  3425. // mutex lock with requestAnimationFrame can also disable participants update in background
  3426. }
  3427. isLogRequired && groupEnd();
  3428. (condition === 2) && (await new Promise(requestAnimationFrame));
  3429. lockResolve();
  3430. });
  3431.  
  3432. });
  3433.  
  3434. }
  3435.  
  3436. return { notifyPath7081 };
  3437.  
  3438. })();
  3439.  
  3440. const whenDefinedMultiple = async (tags) => {
  3441.  
  3442. const sTags = [...new Set(tags)];
  3443. const len = sTags.length;
  3444.  
  3445. const pTags = new Array(len);
  3446. for (let i = 0; i < len; i++) {
  3447. pTags[i] = customElements.whenDefined(sTags[i]);
  3448. }
  3449.  
  3450. await Promise.all(pTags);
  3451. pTags.length = 0;
  3452.  
  3453. return sTags;
  3454.  
  3455. }
  3456.  
  3457. const onRegistryReadyForDataManipulation = () => {
  3458.  
  3459. function dummy5035(a, b, c) { }
  3460. function dummy411(a, b, c) { }
  3461.  
  3462.  
  3463.  
  3464. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  3465.  
  3466. if (!DO_PARTICIPANT_LIST_HACKS) return;
  3467.  
  3468. const tag = "yt-live-chat-participant-list-renderer";
  3469. const cProto = getProto(document.createElement(tag));
  3470. if (!cProto || typeof cProto.attached !== 'function') {
  3471. // for _registered, proto.attached shall exist when the element is defined.
  3472. // for controller extraction, attached shall exist when instance creates.
  3473. console.warn(`proto.attached for ${tag} is unavailable.`);
  3474. return;
  3475. }
  3476.  
  3477.  
  3478. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  3479.  
  3480. 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'];
  3481. const fgs = {};
  3482. for (const key of fgsArr) fgs[key] = undefined;
  3483.  
  3484. try {
  3485. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  3486. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  3487. } catch (e) { }
  3488. console1.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  3489.  
  3490. const canDoReplacement = (() => {
  3491. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  3492. console.warn('YouTube Live Chat Tamer is running.');
  3493. return;
  3494. }
  3495.  
  3496. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  3497. console.warn('YouTube Live Chat Tamer is running.');
  3498. return;
  3499. }
  3500.  
  3501. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  3502. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  3503.  
  3504. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  3505. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  3506. return;
  3507. }
  3508.  
  3509. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  3510. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  3511. return;
  3512. }
  3513.  
  3514. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  3515. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  3516. return;
  3517. }
  3518. return true;
  3519. })();
  3520.  
  3521. console1.log(`Data Manipulation Boost = ${canDoReplacement}`);
  3522.  
  3523. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  3524. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3525. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  3526. console1.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ###`);
  3527. } else {
  3528. console1.log("flushRenderStamperComponentBindings_ - not found");
  3529. }
  3530. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  3531.  
  3532. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3533. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  3534. cProto.flushRenderStamperComponentBindings_ = function () {
  3535. // console.log('flushRenderStamperComponentBindings_')
  3536. this.flushRenderStamperComponentBindings66_();
  3537. if (this.resolveForDOMRendering781) {
  3538. this.resolveForDOMRendering781();
  3539. this.resolveForDOMRendering781 = null;
  3540. }
  3541. };
  3542. }
  3543.  
  3544. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  3545. const container = ((this || 0).$ || 0).participants;
  3546. if (!container) return 0;
  3547. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  3548. }
  3549.  
  3550. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  3551.  
  3552. cProto.__attached412__ = cProto.attached;
  3553. const fpPList = function (hostElement) {
  3554. const cnt = insp(hostElement);
  3555. if (beforeParticipantsMap.has(cnt)) return;
  3556. hostElement.classList.add('n9fJ3');
  3557.  
  3558. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  3559. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  3560. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  3561. return;
  3562. }
  3563.  
  3564. groupCollapsed("Participant List attached", "");
  3565. cnt.__notifyPath5036__ = cnt.notifyPath
  3566. const participants = ((cnt.participantsManager || 0).participants || 0);
  3567. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  3568. console1.log(`initial number of participants: ${participants.length}`);
  3569. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  3570. beforeParticipantsMap.set(cnt, newParticipants);
  3571. cnt.notifyPath = notifyPath7081;
  3572. console1.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  3573. groupEnd();
  3574. }
  3575. cProto.attached = function () {
  3576. fpPList(this.hostElement || this);
  3577. this.__attached412__.apply(this, arguments);
  3578. };
  3579.  
  3580.  
  3581. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  3582.  
  3583. /** @type {boolean | (()=>boolean)} */
  3584. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  3585. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  3586.  
  3587. let lastMessageDate = 0;
  3588. cProto.stampDomArray66_ = cProto.stampDomArray_;
  3589.  
  3590. cProto.stampDomArray_ = function (...args) {
  3591. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  3592. if (typeof toUseMaintainStableList === 'function') {
  3593. toUseMaintainStableList = toUseMaintainStableList();
  3594. }
  3595. args[5] = toUseMaintainStableList;
  3596. let currentDate = Date.now();
  3597. if (currentDate - lastMessageDate > 440) {
  3598. lastMessageDate = currentDate;
  3599. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  3600. }
  3601. }
  3602. return this.stampDomArray66_.apply(this, args);
  3603. }
  3604.  
  3605. cProto.stampDomArray_.nIegT = 1;
  3606.  
  3607. }
  3608. console1.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - OK`);
  3609. } else {
  3610. console1.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NG`);
  3611. }
  3612.  
  3613. groupEnd();
  3614.  
  3615. if (onPageElements.length >= 1) {
  3616. for (const s of onPageElements) {
  3617. if (insp(s).isAttached === true) {
  3618. fpPList(s);
  3619. }
  3620. }
  3621. }
  3622.  
  3623. }).catch(console.warn);
  3624.  
  3625. };
  3626.  
  3627. if (DO_PARTICIPANT_LIST_HACKS) {
  3628. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  3629. }
  3630.  
  3631.  
  3632.  
  3633. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  3634.  
  3635. const transitionEndHooks = new WeakSet();
  3636. const transitionEndAfterFnSimple = new WeakMap();
  3637. let transitionEndAfterFnSimpleEnable = 0;
  3638. // let prevTransitionClosing = null;
  3639.  
  3640. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  3641.  
  3642.  
  3643. const transitionEndAfterFn = (evt) => {
  3644. if (transitionEndAfterFnSimpleEnable > 0 && evt.propertyName && !evt.pseudoElement) {
  3645. const elm = evt.target;
  3646. const f = transitionEndAfterFnSimple.get(elm);
  3647. if (f) {
  3648. transitionEndAfterFnSimple.delete(elm);
  3649. f.resolve(evt.propertyName);
  3650. }
  3651. }
  3652. };
  3653.  
  3654. const fixChildrenIssue = !!fixChildrenIssue801;
  3655. if (fixChildrenIssue && typeof Object.getOwnPropertyDescriptor === 'function' && typeof Proxy !== 'undefined') {
  3656. let fixChildrenIssue_status = false;
  3657. const divProto = HTMLDivElement.prototype;
  3658. const polymerControllerSetData3 = function (c, d, e) {
  3659. return insp(this).set(c, d, e);
  3660. }
  3661. const polymerControllerSetData2 = function (c, d) {
  3662. return insp(this).set(c, d);
  3663. }
  3664. const dummyFn = function () {
  3665. console.log('dummyFn', ...arguments);
  3666. };
  3667.  
  3668. const wm44 = new Map();
  3669. function unPolymerSet(elem) {
  3670. const is = elem.is;
  3671. if (is && !elem.set) {
  3672. let rt = wm44.get(is);
  3673. if (!rt) {
  3674. rt = 1;
  3675. const cnt = insp(elem);
  3676. if (cnt !== elem && cnt && typeof cnt.set === 'function') {
  3677. const pcSet = cnt.constructor.prototype.set;
  3678. if (pcSet && typeof pcSet === 'function' && pcSet.length === 3) {
  3679. rt = polymerControllerSetData3;
  3680. } else if (pcSet && typeof pcSet === 'function' && pcSet.length === 2) {
  3681. rt = polymerControllerSetData2;
  3682. }
  3683. }
  3684. wm44.set(is, rt);
  3685. }
  3686. if (typeof rt === 'function') {
  3687. elem.set = rt;
  3688. } else {
  3689. elem.set = dummyFn;
  3690. }
  3691. }
  3692. }
  3693. if (!divProto.__children577__ && !divProto.__children578__) {
  3694.  
  3695. const dp = Object.getOwnPropertyDescriptor(Element.prototype, 'children');
  3696. const dp2 = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'children');
  3697. const dp3 = Object.getOwnPropertyDescriptor(divProto, 'children');
  3698.  
  3699. if (dp && dp.configurable === true && dp.enumerable === true && typeof dp.get === 'function' && !dp2 && !dp3) {
  3700.  
  3701. if (divProto instanceof HTMLElement && divProto instanceof Element) {
  3702.  
  3703. let m = Object.assign({}, dp);
  3704. divProto.__children577__ = dp.get;
  3705. divProto.__children578__ = function () {
  3706. if (this.__children803__) return this.__children803__;
  3707. if (this.__children801__) {
  3708. let arr = [];
  3709. for (let elem = this.firstElementChild; elem !== null; elem = elem.nextElementSibling) {
  3710. if (elem.is) {
  3711. unPolymerSet(elem);
  3712. arr.push(elem);
  3713. }
  3714. }
  3715. if (this.__children801__ === 2) this.__children803__ = arr;
  3716. return arr;
  3717. }
  3718. return 577;
  3719. };
  3720. m.get = function () {
  3721. const r = this.__children578__();
  3722. if (r !== 577) return r;
  3723. return this.__children577__();
  3724. };
  3725. Object.defineProperty(divProto, 'children', m);
  3726.  
  3727. fixChildrenIssue_status = true;
  3728.  
  3729. }
  3730. }
  3731.  
  3732. }
  3733.  
  3734. if (!fixChildrenIssue_status) {
  3735. console.log('fixChildrenIssue - set NG')
  3736. }
  3737.  
  3738.  
  3739. }
  3740.  
  3741.  
  3742. const watchUserCSS = () => {
  3743.  
  3744. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  3745.  
  3746. const getElemFromWR = (nr) => {
  3747. const n = kRef(nr);
  3748. if (n && n.isConnected) return n;
  3749. return null;
  3750. }
  3751.  
  3752. const clearContentVisibilitySizing = () => {
  3753. Promise.resolve().then(() => {
  3754.  
  3755. const e = document.querySelector('#show-more[disabled]');
  3756. let btnShowMoreWR = e ? mWeakRef(e) : null;
  3757.  
  3758. let lastVisibleItemWR = null;
  3759. for (const elm of document.querySelectorAll('[wSr93]')) {
  3760. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  3761. elm.setAttribute('wSr93', '');
  3762. // custom CSS property --wsr94 not working when attribute wSr93 removed
  3763. }
  3764. foregroundPromiseFn().then(() => {
  3765. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  3766. if (btnShowMore) btnShowMore.click();
  3767. else {
  3768. // would not work if switch it frequently
  3769. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  3770. if (lastVisibleItem) {
  3771.  
  3772. Promise.resolve()
  3773. .then(() => lastVisibleItem.scrollIntoView())
  3774. .then(() => lastVisibleItem.scrollIntoView(false))
  3775. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  3776. .catch(e => { }) // break the chain when method not callable
  3777.  
  3778. }
  3779. }
  3780. });
  3781.  
  3782. });
  3783.  
  3784. }
  3785.  
  3786. const mutObserver = new MutationObserver((mutations) => {
  3787. for (const mutation of mutations) {
  3788. if ((mutation.addedNodes || 0).length >= 1) {
  3789. for (const addedNode of mutation.addedNodes) {
  3790. if (addedNode.nodeName === 'STYLE') {
  3791. clearContentVisibilitySizing();
  3792. return;
  3793. }
  3794. }
  3795. }
  3796. if ((mutation.removedNodes || 0).length >= 1) {
  3797. for (const removedNode of mutation.removedNodes) {
  3798. if (removedNode.nodeName === 'STYLE') {
  3799. clearContentVisibilitySizing();
  3800. return;
  3801. }
  3802. }
  3803. }
  3804. }
  3805. });
  3806.  
  3807. mutObserver.observe(document.documentElement, {
  3808. childList: true,
  3809. subtree: false
  3810. });
  3811. mutObserver.observe(document.head, {
  3812. childList: true,
  3813. subtree: false
  3814. });
  3815. mutObserver.observe(document.body, {
  3816. childList: true,
  3817. subtree: false
  3818. });
  3819.  
  3820. }
  3821.  
  3822.  
  3823. const { lcRendererElm, visObserver } = (() => {
  3824.  
  3825. let lcRendererWR = null;
  3826.  
  3827. const lcRendererElm = () => {
  3828. let lcRenderer = kRef(lcRendererWR);
  3829. if (!lcRenderer || !lcRenderer.isConnected) {
  3830. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  3831. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  3832. }
  3833. return lcRenderer;
  3834. };
  3835.  
  3836.  
  3837. let hasFirstShowMore = false;
  3838. // let lastVisible = null;
  3839.  
  3840. const visObserverFn = (entry) => {
  3841.  
  3842. const target = entry.target;
  3843. if (!target) return;
  3844. // if(target.classList.contains('dont-render')) return;
  3845. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  3846. // const h = entry.boundingClientRect.height;
  3847. /*
  3848. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  3849. // e.g. under fullscreen. the element created but not rendered.
  3850. target.setAttribute('wSr93', '');
  3851. return;
  3852. }
  3853. */
  3854. if (isVisible) {
  3855. // target.style.setProperty('--wsr94', h + 'px');
  3856. target.setAttribute('wSr93', 'visible');
  3857. // lastVisible = mWeakRef(target);
  3858. if (nNextElem(target) === null) {
  3859.  
  3860. // firstVisibleItemDetected = true;
  3861. /*
  3862. if (dateNow() - lastScroll < 80) {
  3863. lastLShow = 0;
  3864. lastScroll = 0;
  3865. Promise.resolve().then(clickShowMore);
  3866. } else {
  3867. lastLShow = dateNow();
  3868. }
  3869. */
  3870. // lastLShow = dateNow();
  3871. } else if (!hasFirstShowMore) { // should more than one item being visible
  3872. // implement inside visObserver to ensure there is sufficient delay
  3873. hasFirstShowMore = true;
  3874. foregroundPromiseFn().then(() => {
  3875. // foreground page
  3876. // page visibly ready -> load the latest comments at initial loading
  3877. const lcRenderer = lcRendererElm();
  3878. if (lcRenderer) {
  3879. if (typeof nextBrowserTick !== 'function') {
  3880. insp(lcRenderer).scrollToBottom_();
  3881. } else {
  3882. nextBrowserTick(() => {
  3883. const cnt = insp(lcRenderer);
  3884. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  3885. cnt.scrollToBottom_();
  3886. });
  3887. }
  3888. }
  3889. });
  3890. }
  3891. }
  3892. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  3893.  
  3894. // target.style.setProperty('--wsr94', h + 'px');
  3895. target.setAttribute('wSr93', 'hidden');
  3896. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  3897.  
  3898. }
  3899.  
  3900.  
  3901.  
  3902. const visObserver = new IntersectionObserver((entries) => {
  3903.  
  3904. for (const entry of entries) {
  3905.  
  3906. Promise.resolve(entry).then(visObserverFn);
  3907.  
  3908. }
  3909.  
  3910. // const _lastVisible = kRef(lastVisible);
  3911. // for (const entry of entries) {
  3912.  
  3913. // // Promise.resolve(entry).then(visObserverFn);
  3914. // visObserverFn(entry);
  3915.  
  3916. // }
  3917. // const lastVisibleC = kRef(lastVisible);
  3918.  
  3919. // if (_lastVisible !== lastVisibleC) {
  3920. // if (_lastVisible instanceof HTMLElement) _lastVisible.classList.remove('cyt-chat-last-message');
  3921. // if (lastVisibleC instanceof HTMLElement) lastVisibleC.classList.add('cyt-chat-last-message');
  3922. // }
  3923.  
  3924. }, {
  3925. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  3926. rootMargin: "0px",
  3927. threshold: [0.05, 0.95],
  3928. });
  3929.  
  3930.  
  3931. return { lcRendererElm, visObserver }
  3932.  
  3933.  
  3934. })();
  3935.  
  3936. const { setupMutObserver } = (() => {
  3937.  
  3938.  
  3939. const mutFn = (items) => {
  3940. let seqIndex = -1;
  3941. const elementSet = new Set();
  3942. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  3943. if (node.hasAttribute('wSr93')) {
  3944. seqIndex = parseInt(node.getAttribute('yt-chat-item-seq'), 10);
  3945. break;
  3946. }
  3947. node.setAttribute('wSr93', '');
  3948. visObserver.observe(node);
  3949. elementSet.add(node);
  3950. }
  3951. let iter = elementSet.values();
  3952. let i = seqIndex + elementSet.size;
  3953. for (let curr; curr = iter.next().value;) {
  3954. curr.setAttribute('yt-chat-item-seq', i % 60);
  3955. curr.classList.add('yt-chat-item-' + ((i % 2) ? 'odd' : 'even'));
  3956. i--;
  3957. }
  3958. iter = null;
  3959. elementSet.clear();
  3960. }
  3961.  
  3962. const mutObserver = new MutationObserver((mutations) => {
  3963. const items = (mutations[0] || 0).target;
  3964. if (!items) return;
  3965. if (sk35zResolveFn) {
  3966. sk35zResolveFn();
  3967. sk35zResolveFn = null;
  3968. }
  3969. mutFn(items);
  3970. });
  3971.  
  3972. const setupMutObserver = (m2) => {
  3973. scrollChatFn = null;
  3974. mutObserver.disconnect();
  3975. mutObserver.takeRecords();
  3976. if (m2) {
  3977. if (typeof m2.__appendChild932__ === 'function') {
  3978. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  3979. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  3980. }
  3981. mutObserver.observe(m2, {
  3982. childList: true,
  3983. subtree: false
  3984. });
  3985. mutFn(m2);
  3986.  
  3987. // const isFirstList = firstList;
  3988. // firstList = false;
  3989.  
  3990. if (ENABLE_OVERFLOW_ANCHOR) {
  3991. // console.log('ENABLE_OVERFLOW_ANCHOR', m2)
  3992.  
  3993. let items = m2;
  3994. let addedAnchor = false;
  3995. if (items) {
  3996. if (items.nextElementSibling === null) {
  3997. items.classList.add('no-anchor');
  3998. addedAnchor = true;
  3999. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  4000. }
  4001. }
  4002.  
  4003.  
  4004.  
  4005. if (addedAnchor) {
  4006. nodeParent(m2).classList.add('no-anchor'); // required
  4007. }
  4008.  
  4009. }
  4010.  
  4011.  
  4012.  
  4013. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  4014.  
  4015. (() => {
  4016.  
  4017. const tag = 'yt-iframed-player-events-relay'
  4018. const dummy = document.createElement(tag);
  4019.  
  4020. const cProto = getProto(dummy);
  4021. if (!cProto || !cProto.handlePostMessage_) {
  4022. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  4023. return;
  4024. }
  4025.  
  4026. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_ && !cProto.handlePostMessage67_ ) {
  4027.  
  4028. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  4029.  
  4030. const handlePostMessageAfterPromiseA = (da) => {
  4031.  
  4032. if (!da || typeof da !== 'object') return;
  4033.  
  4034. if ('yt-player-state-change' in da) {
  4035.  
  4036. const qc = da['yt-player-state-change'];
  4037.  
  4038.  
  4039. let isQcChanged = false;
  4040.  
  4041. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  4042. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  4043. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  4044.  
  4045.  
  4046. if ((isQcChanged) && playerState !== _playerState) {
  4047. playerEventsByIframeRelay = true;
  4048. onPlayStateChangePromise = new Promise((resolve) => {
  4049. const k = _playerState;
  4050. foregroundPromiseFn().then(() => {
  4051. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  4052. onPlayStateChangePromise = null;
  4053. resolve();
  4054. })
  4055. }).catch(console.warn);
  4056.  
  4057. }
  4058.  
  4059. } else if ('yt-player-video-progress' in da) {
  4060. const vp = da['yt-player-video-progress'];
  4061.  
  4062.  
  4063. relayCount++;
  4064. lastPlayerProgress = vp > 0 ? vp : 0; // no use ?
  4065.  
  4066.  
  4067. if (relayPromise && vp > 0 && relayCount >= 2) {
  4068. if (onPlayStateChangePromise) {
  4069. onPlayStateChangePromise.then(() => {
  4070. relayPromise && relayPromise.resolve();
  4071. relayPromise = null;
  4072. })
  4073. } else {
  4074. relayPromise.resolve();
  4075. relayPromise = null;
  4076. }
  4077. }
  4078.  
  4079. }
  4080.  
  4081. };
  4082.  
  4083. cProto.handlePostMessage67_ = function (a) {
  4084.  
  4085. let da = a.data;
  4086. const wNode = mWeakRef(this);
  4087. // const wData = mWeakRef(da);
  4088.  
  4089. playEventsStack = playEventsStack.then(() => {
  4090.  
  4091. const cnt = kRef(wNode);
  4092. // const da = kRef(wData);
  4093.  
  4094. if (!cnt || !a || !da) return;
  4095. handlePostMessageAfterPromiseA(da);
  4096. da = null;
  4097.  
  4098. const r = cnt.handlePostMessage66_(a);
  4099. a = null;
  4100.  
  4101. }).catch(console.warn);
  4102.  
  4103. }
  4104.  
  4105. const handlePostMessageAfterPromiseB = (da) => {
  4106.  
  4107. const lcr = document.querySelector('yt-live-chat-renderer');
  4108. const psc = document.querySelector("yt-player-seek-continuation");
  4109. if (lcr && psc && lcr.replayBuffer_) {
  4110.  
  4111. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  4112. const daProgress = da['yt-player-video-progress'] * 1000
  4113. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  4114.  
  4115. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  4116. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  4117.  
  4118. // console.log(deepCopy( front_))
  4119. // console.log(deepCopy( back_))
  4120. // console.log(rbProgress, daProgress, )
  4121. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  4122. // no action
  4123. // console.log('ss1')
  4124. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  4125. // daProgress - 1200 < rbProgress < daProgress + 3400
  4126. // console.log('ss2')
  4127. } else {
  4128.  
  4129. lcr.previousProgressSec = 1E-5;
  4130. // lcr._setIsSeeking(!0),
  4131. lcr.replayBuffer_.clear()
  4132. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  4133. }
  4134.  
  4135. }
  4136.  
  4137.  
  4138. };
  4139.  
  4140. cProto.handlePostMessage_ = function (a) {
  4141.  
  4142. let da = (a || 0).data || 0;
  4143. const wNode = mWeakRef(this);
  4144.  
  4145. if (typeof da !== 'object') return;
  4146.  
  4147. if (waitForInitialDataCompletion === 1) return;
  4148.  
  4149. if (!isPlayProgressTriggered) {
  4150. isPlayProgressTriggered = true; // set once
  4151.  
  4152. if ('yt-player-video-progress' in da) {
  4153. waitForInitialDataCompletion = 1;
  4154.  
  4155. const wrapWith = (data) => {
  4156. const { origin } = a;
  4157. return {
  4158. origin,
  4159. data
  4160. };
  4161. }
  4162.  
  4163. this.handlePostMessage67_(wrapWith({
  4164. "yt-iframed-parent-ready": true
  4165. }));
  4166.  
  4167.  
  4168. playEventsStack = playEventsStack.then(() => {
  4169.  
  4170. const cnt = kRef(wNode);
  4171.  
  4172. if (!cnt || !a || !da) return;
  4173.  
  4174. handlePostMessageAfterPromiseB(da);
  4175. da = null;
  4176.  
  4177. waitForInitialDataCompletion = 2;
  4178.  
  4179. const r = cnt.handlePostMessage_(a); // isPlayProgressTriggered is set
  4180. a = null;
  4181.  
  4182. }).catch(console.warn);
  4183.  
  4184. return;
  4185.  
  4186. }
  4187.  
  4188. }
  4189.  
  4190. this.handlePostMessage67_(a);
  4191.  
  4192. }
  4193.  
  4194. }
  4195.  
  4196.  
  4197. })();
  4198.  
  4199. }
  4200.  
  4201.  
  4202. }
  4203. }
  4204.  
  4205. return { setupMutObserver };
  4206.  
  4207.  
  4208.  
  4209. })();
  4210.  
  4211. const setupEvents = () => {
  4212. // not called when boost chat is enabled
  4213.  
  4214. // global - currentMouseDown, lastUserInteraction
  4215.  
  4216. let scrollCount = 0;
  4217. let lastScrollCount = -1;
  4218. let lastMouseDown = 0;
  4219.  
  4220. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  4221.  
  4222. const delayFlushActiveItemsAfterUserActionK_ = () => {
  4223.  
  4224. const lcRenderer = lcRendererElm();
  4225. if (lcRenderer) {
  4226. const cnt = insp(lcRenderer);
  4227. if (!cnt.hasUserJustInteracted11_) return;
  4228. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  4229. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  4230. }
  4231. }
  4232.  
  4233. }
  4234.  
  4235. document.addEventListener('scroll', (evt) => {
  4236. if (!evt || !evt.isTrusted) return;
  4237. // lastScroll = dateNow();
  4238. scrollCount = (scrollCount & 1073741823) + 1;
  4239. }, passiveCapture); // support contain => support passive
  4240.  
  4241. document.addEventListener('wheel', (evt) => {
  4242. if (!evt || !evt.isTrusted) return;
  4243. if (lastScrollCount === scrollCount) return;
  4244. lastScrollCount = scrollCount;
  4245. lastWheel = dateNow();
  4246. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4247. }, passiveCapture); // support contain => support passive
  4248.  
  4249. document.addEventListener('mousedown', (evt) => {
  4250. if (!evt || !evt.isTrusted) return;
  4251. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4252. lastMouseDown = dateNow();
  4253. currentMouseDown = true;
  4254. lastUserInteraction = lastMouseDown;
  4255. }, passiveCapture);
  4256.  
  4257. document.addEventListener('pointerdown', (evt) => {
  4258. if (!evt || !evt.isTrusted) return;
  4259. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4260. lastMouseDown = dateNow();
  4261. currentMouseDown = true;
  4262. lastUserInteraction = lastMouseDown;
  4263. }, passiveCapture);
  4264.  
  4265. document.addEventListener('click', (evt) => {
  4266. if (!evt || !evt.isTrusted) return;
  4267. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4268. lastMouseDown = lastMouseUp = dateNow();
  4269. currentMouseDown = false;
  4270. lastUserInteraction = lastMouseDown;
  4271. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4272. }, passiveCapture);
  4273.  
  4274. document.addEventListener('tap', (evt) => {
  4275. if (!evt || !evt.isTrusted) return;
  4276. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4277. lastMouseDown = lastMouseUp = dateNow();
  4278. currentMouseDown = false;
  4279. lastUserInteraction = lastMouseDown;
  4280. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4281. }, passiveCapture);
  4282.  
  4283.  
  4284. document.addEventListener('mouseup', (evt) => {
  4285. if (!evt || !evt.isTrusted) return;
  4286. if (currentMouseDown) {
  4287. lastMouseUp = dateNow();
  4288. currentMouseDown = false;
  4289. lastUserInteraction = lastMouseUp;
  4290. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4291. }
  4292. }, passiveCapture);
  4293.  
  4294.  
  4295. document.addEventListener('pointerup', (evt) => {
  4296. if (!evt || !evt.isTrusted) return;
  4297. if (currentMouseDown) {
  4298. lastMouseUp = dateNow();
  4299. currentMouseDown = false;
  4300. lastUserInteraction = lastMouseUp;
  4301. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4302. }
  4303. }, passiveCapture);
  4304.  
  4305. document.addEventListener('touchstart', (evt) => {
  4306. if (!evt || !evt.isTrusted) return;
  4307. lastTouchDown = dateNow();
  4308. currentTouchDown = true;
  4309. lastUserInteraction = lastTouchDown;
  4310. }, passiveCapture);
  4311.  
  4312. document.addEventListener('touchmove', (evt) => {
  4313. if (!evt || !evt.isTrusted) return;
  4314. lastTouchDown = dateNow();
  4315. currentTouchDown = true;
  4316. lastUserInteraction = lastTouchDown;
  4317. }, passiveCapture);
  4318.  
  4319. document.addEventListener('touchend', (evt) => {
  4320. if (!evt || !evt.isTrusted) return;
  4321. if (currentTouchDown) {
  4322. lastTouchUp = dateNow();
  4323. currentTouchDown = false;
  4324. lastUserInteraction = lastTouchUp;
  4325. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4326. }
  4327. }, passiveCapture);
  4328.  
  4329. document.addEventListener('touchcancel', (evt) => {
  4330. if (!evt || !evt.isTrusted) return;
  4331. if (currentTouchDown) {
  4332. lastTouchUp = dateNow();
  4333. currentTouchDown = false;
  4334. lastUserInteraction = lastTouchUp;
  4335. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4336. }
  4337. }, passiveCapture);
  4338.  
  4339.  
  4340. }
  4341.  
  4342. const getTimestampUsec = (itemRenderer) => {
  4343. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  4344. return itemRenderer.timestampUsec
  4345. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  4346. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  4347. if (messageRenderer) {
  4348.  
  4349. const messageRendererKey = firstObjectKey(messageRenderer);
  4350. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  4351. const messageRendererData = messageRenderer[messageRendererKey];
  4352. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  4353. return messageRendererData.timestampUsec
  4354. }
  4355. }
  4356. }
  4357. }
  4358. return null;
  4359. }
  4360.  
  4361. const onRegistryReadyForDOMOperations = () => {
  4362.  
  4363. let firstCheckedOnYtInit = false;
  4364.  
  4365. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  4366.  
  4367. const mightFirstCheckOnYtInit = () => {
  4368. if (firstCheckedOnYtInit) return;
  4369. firstCheckedOnYtInit = true;
  4370.  
  4371. if (!document.body || !document.head) return;
  4372. if (!assertorURL()) return;
  4373.  
  4374. addCssManaged();
  4375.  
  4376. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  4377. if (efsContainer && efsContainer.parentNode !== document.body) {
  4378. document.body.appendChild(efsContainer);
  4379. }
  4380.  
  4381. };
  4382.  
  4383. if (!assertorURL()) return;
  4384. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  4385.  
  4386.  
  4387. const { weakWrap } = (() => {
  4388.  
  4389.  
  4390. // const tickerFuncProps = new Set([
  4391. // 'animateShowStats', 'animateHideStats', // updateStatsBarAndMaybeShowAnimationRevised
  4392. // 'collapse', // slideDownNoSelfLeakage
  4393. // 'requestRemoval', // collapseNoSelfLeakage
  4394. // 'setContainerWidth', 'get', 'set', // deletedChangedNoSelfLeakage
  4395. // 'computeAriaLabel', //dataChanged
  4396. // 'startCountdown', // dataChanged [in case]
  4397. // ]);
  4398.  
  4399. // const tickerTags = new Set([
  4400. // "yt-live-chat-ticker-renderer",
  4401. // "yt-live-chat-ticker-paid-message-item-renderer",
  4402. // "yt-live-chat-ticker-paid-sticker-item-renderer",
  4403. // "yt-live-chat-ticker-sponsor-item-renderer"
  4404. // ]);
  4405.  
  4406. // const emptySet = new Set();
  4407.  
  4408.  
  4409.  
  4410. // const tickerFuncPropsFn = (cnt) => {
  4411.  
  4412. // const is = `${cnt.is}`;
  4413.  
  4414. // if (tickerTags.has(is)) {
  4415. // let flg = 0;
  4416. // if (cnt.get && cnt.set) flg |= 1;
  4417. // if (cnt.setContainerWidth && cnt.collapse && cnt.requestRemoval) flg |= 2;
  4418. // if (cnt.animateShowStats && cnt.animateHideStats) flg |= 4;
  4419. // if (cnt.startCountdown) flg |= 8;
  4420. // console.log(`DEBUG flag_6877 = ${flg}`, is);
  4421. // // DEBUG flag_6877 = 15 yt-live-chat-ticker-paid-message-item-renderer
  4422. // // DEBUG flag_6877 = 11 yt-live-chat-ticker-sponsor-item-renderer
  4423. // return tickerFuncProps;
  4424. // }
  4425.  
  4426. // return emptySet;
  4427.  
  4428.  
  4429. // }
  4430.  
  4431.  
  4432. // const smb = Symbol();
  4433. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  4434. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  4435. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  4436.  
  4437.  
  4438.  
  4439.  
  4440. const thisConversionFn = (thisArg) => {
  4441. if (!thisArg) return null;
  4442. const kThis = thisArg[vmb];
  4443. if (kThis) {
  4444. const ref = kThis.ref;
  4445. return (ref ? kRef(ref) : null) || null;
  4446. }
  4447. return thisArg;
  4448. }
  4449.  
  4450. const pFnHandler2 = {
  4451. get(target, prop) {
  4452. if (prop === vmc) return target;
  4453. return Reflect.get(target, prop);
  4454. },
  4455. apply(target, thisArg, argumentsList) {
  4456. thisArg = thisConversionFn(thisArg);
  4457. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  4458. }
  4459. }
  4460.  
  4461.  
  4462. const proxySelfHandler = {
  4463. get(target, prop) {
  4464. if(prop === vmb) return target;
  4465. const ref = target.ref;
  4466. const cnt = kRef(ref);
  4467. if (!cnt) return;
  4468. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  4469. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  4470. return cnt[prop][vmd];
  4471. }
  4472. return cnt[prop];
  4473. },
  4474. set(target, prop, value) {
  4475. const cnt = kRef(target.ref);
  4476. if (!cnt) return true;
  4477. if(value && (value[vmc] || value[vmb])){
  4478. cnt[prop] = value[vmc] || thisConversionFn(value);
  4479. return true;
  4480. }
  4481. cnt[prop] = value;
  4482. return true;
  4483. }
  4484. };
  4485.  
  4486. const weakWrap = (thisArg) => {
  4487. thisArg = thisConversionFn(thisArg);
  4488. if (!thisArg) {
  4489. console.error('thisArg is not found');
  4490. return null;
  4491. }
  4492. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  4493. }
  4494.  
  4495.  
  4496.  
  4497.  
  4498.  
  4499.  
  4500. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  4501. window.getComputedStyle533 = window.getComputedStyle;
  4502. window.getComputedStyle = function (a, ...args) {
  4503. a = thisConversionFn(a);
  4504. if (a) {
  4505. return getComputedStyle533(a, ...args);
  4506. }
  4507. return null;
  4508. }
  4509. }
  4510.  
  4511.  
  4512.  
  4513.  
  4514.  
  4515.  
  4516.  
  4517. // const fnProxySelf = function (...args) {
  4518. // const cnt = kRef(this.ref);
  4519. // if (cnt) {
  4520. // return cnt[this.prop](...args); // might throw error
  4521. // }
  4522. // }
  4523. // const proxySelfHandler = {
  4524. // get(target, prop) {
  4525. // const ref = target.ref;
  4526. // const cnt = kRef(ref);
  4527. // if (!cnt) return;
  4528. // if (prop === 'dtz06') return 1;
  4529. // if (typeof cnt[prop] === 'function') {
  4530. // if (!target.funcs.has(prop)) {
  4531. // console.warn(`proxy get to function | prop: ${prop} | is: ${cnt.is}`);
  4532. // }
  4533. // if (!target[`$$${prop}$$`]) target[`$$${prop}$$`] = fnProxySelf.bind({ prop, ref });
  4534. // return target[`$$${prop}$$`];
  4535. // }
  4536. // return cnt[prop];
  4537. // },
  4538. // set(target, prop, value) {
  4539. // const cnt = kRef(target.ref);
  4540. // if (!cnt) return true;
  4541. // if (typeof value === 'function') {
  4542. // console.warn(`proxy set to function | prop: ${prop} | is: ${cnt.is}`);
  4543. // cnt[prop] = value;
  4544. // return true;
  4545. // }
  4546. // cnt[prop] = value;
  4547. // return true;
  4548. // }
  4549. // };
  4550.  
  4551. // return { tickerFuncPropsFn, proxySelfHandler }
  4552.  
  4553. return {weakWrap}
  4554. })();
  4555.  
  4556.  
  4557.  
  4558. if (document.documentElement && document.head) {
  4559. addCssManaged();
  4560. }
  4561. // console.log(document.body===null)
  4562.  
  4563. const preprocessChatLiveActionsMap = new WeakSet();
  4564.  
  4565. const toLAObj=(aItem)=>{
  4566.  
  4567. if (!aItem || typeof aItem !== 'object') return false;
  4568. const key = firstObjectKey(aItem); // addLiveChatTickerItemAction
  4569. if (!key) return false;
  4570. let obj = aItem[key];
  4571. if (!obj || typeof obj !== 'object') return false;
  4572.  
  4573. if (typeof (obj.item || 0) == 'object' && firstObjectKey(obj) === 'item') {
  4574. obj = obj.item;
  4575. const key = firstObjectKey(obj);
  4576. if (key) {
  4577. obj = obj[key];
  4578. }
  4579. }
  4580.  
  4581. return obj;
  4582.  
  4583. };
  4584.  
  4585. const groupsK38=[];
  4586.  
  4587.  
  4588. function intervalsOverlap(a1, a2, b1, b2) {
  4589. // Order the intervals without using Math functions
  4590. var startA = a1 <= a2 ? a1 : a2;
  4591. var endA = a1 <= a2 ? a2 : a1;
  4592.  
  4593. var startB = b1 <= b2 ? b1 : b2;
  4594. var endB = b1 <= b2 ? b2 : b1;
  4595.  
  4596. // Check for overlap
  4597. return endA >= startB && endB >= startA;
  4598. }
  4599.  
  4600.  
  4601.  
  4602. const insertIntoSortedArrayA28 = (arr, val) => {
  4603. let left = 0;
  4604. const n = arr.length;
  4605. let right = n;
  4606.  
  4607. // Binary search to find the correct insertion index:
  4608. // We want the first index where arr[index][2] >= val[2].
  4609. while (left < right) {
  4610. const mid = (left + right) >>> 1;
  4611. if (arr[mid][0] < val[0]) {
  4612. left = mid + 1;
  4613. } else {
  4614. right = mid;
  4615. }
  4616. }
  4617.  
  4618. // 'left' is now the insertion index
  4619. left === n ? arr.push(val): arr.splice(left, 0, val);
  4620. };
  4621.  
  4622. function removeNullsInPlace(arr, startI = 0) {
  4623. let insertPos = startI;
  4624. for (let i = startI; i < arr.length; i++) {
  4625. if (arr[i] !== null) {
  4626. insertPos !== i && (arr[insertPos] = arr[i]);
  4627. insertPos++;
  4628. }
  4629. }
  4630. arr.length = insertPos; // Remove the trailing nulls.
  4631. }
  4632.  
  4633. let fir = 0;
  4634.  
  4635. const limitAddition = (a, b) => {
  4636. // Number.MAX_SAFE_INTEGER = 9007199254740991
  4637. // formula = Math.round((a + b) / (1 + a * b / k / k))
  4638. // avoid a*b > 9007199254740991
  4639. // say a, b <= 94800000
  4640. // Consider (x+x) - (x+x) / (1 + x^2 / k^2) < 0.49
  4641. // x < 130095
  4642.  
  4643. const w = 130095;
  4644. if (a < w && b < w) return a + b;
  4645. const k2 = 94800000 * 94800000;
  4646. return Math.round((a + b) / (1 + (a * b) / k2));
  4647. }
  4648.  
  4649. const preprocessChatLiveActions = (arr) =>{
  4650.  
  4651. if (!fir) {
  4652.  
  4653. if (!__LCRInjection__) {
  4654. console.error('[yt-chat] preprocessChatLiveActions might fail because of no __LCRInjection__');
  4655. }
  4656.  
  4657. DEBUG_preprocessChatLiveActions && console.log('[yt-chat-debug] 5990', 'preprocessChatLiveActions', arr)
  4658.  
  4659. DEBUG_preprocessChatLiveActions && console.log('[yt-chat-debug] 5991', document.querySelectorAll('yt-live-chat-ticker-renderer #ticker-items [class]').length)
  4660.  
  4661. fir = 1;
  4662. // debugger;
  4663. }
  4664.  
  4665. if (!arr || !arr.length) return arr;
  4666.  
  4667. if (preprocessChatLiveActionsMap.has(arr)) return arr;
  4668. preprocessChatLiveActionsMap.add(arr);
  4669.  
  4670.  
  4671.  
  4672. const ct = Date.now();
  4673.  
  4674. let groups_ = null;
  4675.  
  4676. // console.log(1237005);
  4677. // const conversionMap = new WeakMap();
  4678.  
  4679. const additionalInfo = new WeakMap();
  4680.  
  4681. // const adjustmentMap = new Map();
  4682.  
  4683. if (FIX_TIMESTAMP_FOR_REPLAY) {
  4684.  
  4685. // console.log('group02331')
  4686. // console.time('FIX_TIMESTAMP_FOR_REPLAY')
  4687.  
  4688. // const stack = new Array(arr.length);
  4689. // let stackL = 0;
  4690.  
  4691. // const arrHash = new Array(arr.length);
  4692.  
  4693.  
  4694. const groups = groupsK38;
  4695. // const delta = 2.0; // head-to-tail + 0.5 + 0.5 = 1.0 -> symmetric -> 1.0 * 2 = 2.0
  4696. // (2)
  4697. // (1.5, 2.5)
  4698. // (1.51, 2.49)
  4699. // -> (1.01, 2.01) , (1.99, 2.99)
  4700. // 2.99 - 1.01 = 1.98 -> 2
  4701.  
  4702.  
  4703.  
  4704. const pushToGroup = (t0mu)=>{
  4705.  
  4706. const t0auDv = t0mu - 1e6; // t0buDv - t0auDv = 2e6
  4707. const t0buDv = t0mu + 1e6;
  4708. // const t0auEv = t0mu - 2e6;
  4709. // const t0buEv = t0mu + 2e6;
  4710.  
  4711. let groupK = false;
  4712. // let m = -1;
  4713. // let q= 0;
  4714. //const qq =true;
  4715. //qq && console.log('-------')
  4716.  
  4717. let lastRight = null;
  4718. let lastK = null;
  4719. let deletedStartIndex = -1;
  4720.  
  4721. for (let k = 0, kl = groups.length; k < kl; k++) {
  4722.  
  4723. const group = groups[k];
  4724. const [groupStart, groupEnd, gCount] = group;
  4725. //qq && console.log(`-- ${k} ----- ${groupMid} : [${groupStart},${groupEnd}] || C1 = ${t0buEv < groupMid} || C2 = ${t0auEv > groupMid}`);
  4726.  
  4727. // if (t0bsEv < groupMid) continue; // if(t0m + 1.0 < groupMid - 1.0) continue;
  4728. // if (m < 0) m = k;
  4729. // if (t0asEv > groupMid){
  4730. // continue; // if(t0m - 1.0 > groupMid + 1.0) break;
  4731. // }
  4732.  
  4733.  
  4734. // if (m < 0) m = k;
  4735.  
  4736. if (lastRight > groupStart) {
  4737. if (!groupK) {
  4738. // just in case sth wrong
  4739. console.warn('logic ERROR');
  4740. groups[k] = null;
  4741. if(deletedStartIndex < 0) deletedStartIndex = k;
  4742. break;
  4743. } else {
  4744.  
  4745.  
  4746. // GroupA: N_a' = N_a + n_e{1} ; Note n_e is the only way to shift right to cause " (lastRight > groupStart) "
  4747. // GroupB: N_b
  4748. // Merge Group (A) = N_a' + N_b
  4749.  
  4750. // without entry moditification, no overlap
  4751. // this must be due to entry moditifcation
  4752. // entry is already count. so can be skipped after merging
  4753.  
  4754. // for merging, groupA will move to right side but left than groupB, so no overlap to groupC
  4755.  
  4756. const group = groups[lastK];
  4757. const newN = limitAddition(group[2], gCount);
  4758.  
  4759. const factor = gCount / (group[2] + gCount);
  4760.  
  4761. // group[0] = (group[0] * group[2] + groupStart * gCount) / (group[2] + gCount)
  4762. group[0] += (groupStart - group[0]) * factor;
  4763.  
  4764. // group[1] = lastRight = (group[1] * group[2] + groupEnd * gCount) / (group[2] + gCount)
  4765. group[1] += (groupEnd - group[1]) * factor;
  4766.  
  4767. group[2] = newN;
  4768. // no change of lastK
  4769. groups[k] = null;
  4770. if(deletedStartIndex < 0) deletedStartIndex = k;
  4771. continue;
  4772. }
  4773. }
  4774.  
  4775. const minGroupStart = lastRight; // all groupStart, groupEnd >= minGroupStart for k, k+1, ...
  4776. if (t0buDv < minGroupStart) {
  4777. // no overlapping could be possible
  4778. break;
  4779. }
  4780.  
  4781. if (intervalsOverlap(t0auDv, t0buDv, groupStart, groupEnd)) {
  4782.  
  4783. groupK = true;
  4784.  
  4785. // if (t0auDv > groupStart) group[0] = t0auDv;
  4786. // else if (t0buDv < groupEnd) group[1] = t0buDv;
  4787.  
  4788. // const newStart = (groupStart * gCount + t0auDv) / (gCount + 1);
  4789. const newStart = groupStart + (t0auDv - groupStart) * 1 / (gCount + 1);
  4790.  
  4791. if (newStart < lastRight) {
  4792. // n_e{1} will make N_b shift left
  4793.  
  4794. // GroupA: N_a
  4795. // GroupB: N_b
  4796. // Merge Group (A) = N_a + N_b + n_e{1}
  4797.  
  4798. const group = groups[lastK];
  4799. const newN = limitAddition(limitAddition(group[2], gCount), 1);
  4800. const f1 = gCount / (group[2] + gCount + 1);
  4801. const f2 = 1 / (group[2] + gCount + 1);
  4802.  
  4803. // group[0] = (group[0] * group[2] + groupStart * gCount + t0auDv) / (group[2] + gCount + 1);
  4804. group[0] += (groupStart - group[0]) * f1 + (t0auDv - group[0]) * f2;
  4805.  
  4806. // group[1] = lastRight = (group[1] * group[2] + groupEnd * gCount + t0buDv) / (group[2] + gCount + 1)
  4807. lastRight = (group[1] += (groupEnd - group[1]) * f1 + (t0buDv - group[1]) * f2);
  4808.  
  4809. group[2] = newN;
  4810. // no change of lastK
  4811. groups[k] = null;
  4812. if(deletedStartIndex < 0) deletedStartIndex = k;
  4813. continue;
  4814.  
  4815. } else {
  4816. // n_e{1} will make N_b shift either left or right
  4817.  
  4818. // GroupT: N_t
  4819. // Group (T) = N_t + n_e{1}
  4820.  
  4821. const newN = limitAddition(gCount, 1);
  4822.  
  4823. group[0] = newStart;
  4824. // group[1] = lastRight = (groupEnd * gCount + t0buDv) / (gCount + 1);
  4825. group[1] = lastRight = groupEnd + (t0buDv - groupEnd) * 1 / (gCount + 1);
  4826. group[2] = newN;
  4827.  
  4828. lastK = k;
  4829.  
  4830. // (t0asDv > groupStart) && (t0bsDv < groupEnd) means full containement
  4831. // however, group size is smaller than or equal to t0width
  4832. }
  4833.  
  4834.  
  4835. } else {
  4836. // just update record for next iteration
  4837.  
  4838. lastRight = groupEnd;
  4839. lastK = k;
  4840. }
  4841.  
  4842.  
  4843.  
  4844. }
  4845.  
  4846. if (deletedStartIndex >= 0) {
  4847. // rarely used
  4848.  
  4849. removeNullsInPlace(groups, deletedStartIndex);
  4850.  
  4851. }
  4852. if (!groupK) {
  4853. // groups.push([t0auDv, t0buDv, 1]);
  4854. insertIntoSortedArrayA28(groups, [t0auDv, t0buDv, 1]);
  4855. // insertIntoSortedArrayA27(groups, [t0auDv, t0buDv, t0mu]);
  4856. }
  4857.  
  4858.  
  4859. }
  4860.  
  4861. let autoTimeStampFrameChoose = 0;
  4862.  
  4863. // console.log('group02332')
  4864. for (let j = 0, l = arr.length; j < l; j++) {
  4865. const aItem = arr[j];
  4866.  
  4867. const obj = toLAObj(aItem);
  4868. if (obj === false) continue;
  4869.  
  4870. let p = obj.timestampText;
  4871. let p2, p3=null, p4a=null, p4b=null;
  4872. if(p&&p.simpleText ) p2 = p.simpleText;
  4873.  
  4874. let q = obj.timestampUsec ;
  4875. let q2;
  4876.  
  4877. if(q && +q > 1110553200000000) q2 = +q;
  4878. if (q2 > 0 && !autoTimeStampFrameChoose) {
  4879. const q2cc = Math.round(q2 / 1e6);
  4880. autoTimeStampFrameChoose = q2cc - (q2cc % 10000000);
  4881. if (q2cc - autoTimeStampFrameChoose < 2000000) autoTimeStampFrameChoose -= 10000000;
  4882. // around 10day range
  4883. // exceeded ~10day -> above 10000000
  4884. }
  4885.  
  4886. // console.log('group02333', p2, q2)
  4887. // console.log(3775, q2/1e6, autoTimeStampFrameChoose)
  4888.  
  4889. if(p2 && q2){
  4890.  
  4891. let m;
  4892.  
  4893. if (m = /^\s*(-?)(\d+):(\d+)\s*$/.exec(p2)) {
  4894. let c0z = m[1] ? -1 : 1;
  4895. let c1 = (+m[2]);
  4896. let c2 = (+m[3]);
  4897. if (c0z > 0 && c1 >= 0 && c2 >= 0) {
  4898.  
  4899. p3 = c1 * 60 + c2;
  4900. } else if (c0z < 0 && c1 >= 0 && c2 >= 0) {
  4901. // -4:43 -> -4:42 -> -4:41 ... -> -4:01 -> -4:00 -> -3:59 -> -3:58
  4902. // -> ... -1:01 -> -1:00 -> -0:59 -> ... -> -0:02 -> -0:01 -> -0:00 -> 0:00 -> ...
  4903.  
  4904. p3 = (-c1 * 60) + (-c2);
  4905.  
  4906. }
  4907. if (p3 !== null) {
  4908. // 0:14 -> 13.5s ~ 14.4999s -> [13.5, 14.5)
  4909. p4a = p3 - 0.5;
  4910. p4b = p3 + 0.5;
  4911. }
  4912. } else if (m = /^\s*(-?)(\d+):(\d+):(\d+)\s*$/.exec(p2)) {
  4913.  
  4914. let c0z = m[1] ? -1 : 1;
  4915. let c1 = (+m[2]);
  4916. let c2 = (+m[3]);
  4917. let c3 = (+m[4]);
  4918.  
  4919.  
  4920.  
  4921. if (c0z > 0 && c1 >= 0 && c2 >= 0 && c3 >= 0) {
  4922.  
  4923. p3 = c1 * 60 * 60 + c2 * 60 + c3;
  4924. } else if (c0z < 0 && c1 >= 0 && c2 >= 0 && c3>=0) {
  4925. // -4:43 -> -4:42 -> -4:41 ... -> -4:01 -> -4:00 -> -3:59 -> -3:58
  4926. // -> ... -1:01 -> -1:00 -> -0:59 -> ... -> -0:02 -> -0:01 -> -0:00 -> 0:00 -> ...
  4927.  
  4928. p3 = (-c1 * 60 * 60) + (-c2 * 60) + (-c3);
  4929.  
  4930. }
  4931. if (p3 !== null) {
  4932. // 0:14 -> 13.5s ~ 14.4999s -> [13.5, 14.5)
  4933. p4a = p3 - 0.5;
  4934. p4b = p3 + 0.5;
  4935. }
  4936.  
  4937.  
  4938. }
  4939.  
  4940. }
  4941.  
  4942. if(p4a !== null && p4b !== null && q2 > 0){
  4943.  
  4944. // q2_us = t0_us + dt_us
  4945. // p4a_us <= dt_us < p4b_us
  4946. let p4au = p4a * 1e6;
  4947. let p4bu = p4b * 1e6;
  4948.  
  4949. // p4a_us <= q2_us - t0_us < p4b_us
  4950.  
  4951.  
  4952. // p4a_us - q2_us <= - t0_us < p4b_us - q2_us
  4953.  
  4954. // -p4a_us + q2_us >= t0_us > -p4b_us + q2_us
  4955.  
  4956.  
  4957. let t0au = q2 - p4bu; // q2_us - p4b_us
  4958. let t0bu = q2 - p4au; // q2_us - p4a_us
  4959.  
  4960. // t0 (t0au, t0bu]
  4961.  
  4962. const t0mu = (t0au+t0bu)/2;
  4963.  
  4964. // stack[stackL++]=({
  4965. // id: obj.id,
  4966. // idx: j,
  4967. // p2,
  4968. // // q2s : (q2/ 1e6 - autoTimeStampFrameChoose).toFixed(2),
  4969. // p3,
  4970. // /*
  4971. // timestampText: obj.timestampText,
  4972. // timestampUsec: obj.timestampUsec, // us = 1/1000 ms
  4973. // q2,
  4974. // p4a,
  4975. // p4b,
  4976. // */
  4977. // q2s: +(q2 / 1e6 - autoTimeStampFrameChoose).toFixed(2),
  4978. // t0as: +(t0au / 1e6 - autoTimeStampFrameChoose).toFixed(2),
  4979. // t0bs: +(t0bu /1e6 - autoTimeStampFrameChoose).toFixed(2),
  4980.  
  4981. // t0au,
  4982. // t0bu,
  4983. // t0mu
  4984. // });
  4985.  
  4986. // console.log('group02334')
  4987. let wobj = additionalInfo.get(obj);
  4988. if(!wobj) additionalInfo.set(obj, wobj = {});
  4989.  
  4990. wobj.timestampUsecOriginal = q2;
  4991. // wobj.timestampUsecAdjusted = q2;
  4992. wobj.t0au = t0au;
  4993. wobj.t0bu = t0bu;
  4994. wobj.t0mu = t0mu;
  4995.  
  4996. // arrHash[j] = {
  4997. // index: j,
  4998. // id: obj.id,
  4999. // timestampUsec: q2,
  5000. // t0au,
  5001. // t0bu,
  5002. // t0mu
  5003. // };
  5004.  
  5005. pushToGroup(t0mu);
  5006.  
  5007. // console.log('group02335')
  5008. // console.log('grouping', `${obj.id}.${obj.timestampUsec}`);
  5009.  
  5010. // timestamp (q2) can be incorrect.
  5011.  
  5012. // https://www.youtube.com/watch?v=IKKar5SS29E
  5013. // ChwKGkNQZUxfXzZxLS04Q0ZXNGxyUVlkODZrQzNR
  5014.  
  5015. /*
  5016.  
  5017.  
  5018. [
  5019. {
  5020. "id": "ChwKGkNNWHZqXy1xLS04Q0ZXNGxyUVlkODZrQzNR",
  5021. "p2": "2:04",
  5022. "p3": 124,
  5023. "t0as": 8320733.78,
  5024. "t0bs": 8320734.78
  5025. },
  5026. {
  5027. "id": "ChwKGkNQZUxfXzZxLS04Q0ZXNGxyUVlkODZrQzNR",
  5028. "p2": "2:04",
  5029. "p3": 124,
  5030. "t0as": 8320898.89, // incorrect
  5031. "t0bs": 8320899.89
  5032. }
  5033. ]
  5034.  
  5035.  
  5036. */
  5037.  
  5038. }
  5039.  
  5040.  
  5041.  
  5042.  
  5043. }
  5044.  
  5045. // stack.length = stackL;
  5046.  
  5047.  
  5048. groups_ = groups;
  5049. // console.log('groups', groups)
  5050.  
  5051. }
  5052.  
  5053. // console.log(1237006);
  5054.  
  5055. // console.log(5592,1)
  5056. const groupMids = FIX_TIMESTAMP_FOR_REPLAY ? groups_.map(group=>{
  5057.  
  5058. const [groupStart, groupEnd ] = group;
  5059. const groupMid = (groupStart+groupEnd)/2;
  5060. return groupMid;
  5061. }): null;
  5062. // console.log('groupMids', groupMids)
  5063.  
  5064.  
  5065. // console.log(1237007);
  5066.  
  5067. const adjustTimestampFn = (obj) => {
  5068.  
  5069. const groupCount = groupMids.length;
  5070.  
  5071. if (groupCount < 1) return null;
  5072.  
  5073. // const obj = toLAObj(aItem);
  5074. if (obj === false) return null;
  5075.  
  5076. const wobj = additionalInfo.get(obj);
  5077. if (!wobj) return null;
  5078.  
  5079. const { t0mu } = wobj;
  5080.  
  5081.  
  5082. let i0 = 0;
  5083.  
  5084. if (groupCount >= 3) {
  5085. // For larger arrays, use binary search.
  5086. let low = 0;
  5087. let high = groupCount - 1;
  5088.  
  5089. while (high - low > 1) {
  5090. const mid = (low + high) >>> 1;
  5091. if (groupMids[mid] >= t0mu) {
  5092. high = mid;
  5093. } else {
  5094. low = mid;
  5095. }
  5096. }
  5097. i0 = low;
  5098.  
  5099. }
  5100.  
  5101. let upperDiff = -1;
  5102. let lowerDiff = -1;
  5103. for (let i = i0; i < groupCount; i++) {
  5104. const y = groupMids[i] - t0mu;
  5105. if (y >= 0) {
  5106. upperDiff = y; // >=0, entry > value is found
  5107. break;
  5108. }
  5109. lowerDiff = -y; // >0, cache
  5110. }
  5111.  
  5112.  
  5113. const d1 = upperDiff;
  5114. const d2 = lowerDiff;
  5115.  
  5116.  
  5117. // console.log(5381, index1 ,d1, index2 , d2);
  5118.  
  5119. if (d1 >= 0 && ((d2 < 0) || (d1 <= d2))) {
  5120. wobj.chosenT0 = t0mu + d1; // groupMids[index1];
  5121. } else if (d2 >= 0 && ((d1 < 0) || (d2 <= d1))) {
  5122. wobj.chosenT0 = t0mu - d2; // groupMids[index2];
  5123. } else {
  5124. console.warn('logic error');
  5125. return null;
  5126. }
  5127.  
  5128. const adjusted = wobj.timestampUsecOriginal - wobj.chosenT0;
  5129.  
  5130. wobj.timestampUsecAdjusted = adjusted + 1110553200000000;
  5131.  
  5132. // console.log('adjusted', `${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5133.  
  5134. // adjustmentMap.set(`${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5135.  
  5136. return adjusted;
  5137.  
  5138.  
  5139.  
  5140. };
  5141.  
  5142.  
  5143. // console.log(5592,2)
  5144. // console.log(1237008);
  5145. // if (FIX_TIMESTAMP_FOR_REPLAY) {
  5146.  
  5147.  
  5148. // try{
  5149.  
  5150. // // console.log('groupmid',groupMids, groups);
  5151.  
  5152. // for(let j = 0; j< arr.length;j++){
  5153. // if(groupMids.length<1) break;
  5154.  
  5155. // const aItem = arr[j];
  5156. // const obj = toLAObj(aItem);
  5157. // if (obj === false) continue;
  5158.  
  5159. // const wobj = additionalInfo.get(obj);
  5160. // if(!wobj) continue;
  5161.  
  5162. // // wobj.timestampUsecOriginal = q2;
  5163. // // wobj.timestampUsecAdjusted = q2;
  5164. // // wobj.t0au = t0au;
  5165. // // wobj.t0bu = t0bu;
  5166. // // wobj.t0mu = t0mu;
  5167.  
  5168. // const {t0au, t0bu, t0mu} = wobj;
  5169.  
  5170. // let upper = -1;
  5171.  
  5172. // for(let i = 0; i <groupMids.length;i++){
  5173. // const groupMid = groupMids[i];
  5174. // if(groupMid>= t0mu){
  5175. // upper = i;
  5176. // break;
  5177. // }
  5178. // }
  5179. // let index1, index2;
  5180. // if(upper>-1){
  5181. // index1 = upper-1;
  5182. // index2 = upper;
  5183. // }else{
  5184. // index1 = groups.length-1;
  5185. // index2 = -1;
  5186. // }
  5187. // let d1 = null;
  5188. // if(index1 >=0){
  5189. // d1 = Math.abs(groupMids[index1] - t0mu);
  5190. // }
  5191.  
  5192. // let d2 = null;
  5193. // if(index2 >=0){
  5194. // d2 = Math.abs(groupMids[index2] - t0mu);
  5195. // }
  5196. // // console.log(5381, index1 ,d1, index2 , d2);
  5197. // if(d1 >= 0 && ((d1 <= d2) || (d2 === null)) ){
  5198.  
  5199. // wobj.chosenT0 = groupMids[index1];
  5200. // } else if(d2 >= 0 && ((d2 <= d1) || (d1 === null))){
  5201. // wobj.chosenT0 = groupMids[index2];
  5202. // } else {
  5203. // console.warn('logic error');
  5204. // continue;
  5205. // }
  5206.  
  5207. // wobj.timestampUsecAdjusted = wobj.timestampUsecOriginal - wobj.chosenT0 + 1110553200000000;
  5208.  
  5209. // console.log('adjusted', `${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5210.  
  5211. // adjustmentMap.set(`${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5212. // // conversionMap.set(obj, arrHash[j].adjustedTime);
  5213.  
  5214. // // console.log(5382, index, id, t0mu, arrHash[j].adjustedT0, arrHash[j].timestampUsec, arrHash[j].adjustedTime);
  5215.  
  5216. // }
  5217.  
  5218.  
  5219. // }catch(e){
  5220. // console.warn(e);
  5221. // }
  5222.  
  5223.  
  5224.  
  5225.  
  5226.  
  5227. // // if(stack.length > 1){
  5228. // // stack.sort((a,b)=>{
  5229. // // return a.t0mu - b.t0mu
  5230. // // });
  5231. // // // small to large
  5232. // // // console.log(34588, stack.map(e=>e.t0as))
  5233. // // }
  5234.  
  5235. // // grouping
  5236.  
  5237.  
  5238.  
  5239.  
  5240. // // if (stack.length > 0) {
  5241.  
  5242. // // try {
  5243.  
  5244. // // for (let j = 0, l = stack.length; j < l; j++) {
  5245. // // pushToGroup(stack[j].t0mu);
  5246.  
  5247. // // }
  5248.  
  5249. // // }catch(e){
  5250.  
  5251. // // console.warn(e)
  5252. // // }
  5253.  
  5254. // // // console.log(4882, groups.map(e=>e.slice()), stack.slice())
  5255.  
  5256. // // }
  5257.  
  5258.  
  5259.  
  5260.  
  5261. // // console.log(376, 'group', groups);
  5262.  
  5263.  
  5264. // // consolidated group
  5265. // // const consolidatedGroups = doConsolidation(groups);
  5266.  
  5267.  
  5268.  
  5269.  
  5270.  
  5271.  
  5272. // // if(stack.length > 1){
  5273.  
  5274.  
  5275. // // // // console.log(341, 'consolidatedGroups', consolidatedGroups ,groups.map(e=>{
  5276. // // // // return e.map(noTransform);
  5277. // // // // // return e.map(prettyNum);
  5278. // // // // }))
  5279.  
  5280.  
  5281. // // // console.log(344, 'groups', groups.map(e=>{
  5282. // // // return e.map(noTransform);
  5283. // // // // return e.map(prettyNum);
  5284. // // // }))
  5285.  
  5286. // // // // for(const s of stack){
  5287. // // // // for(const g of consolidatedGroups){
  5288. // // // // if(s.t0as<=g.cen && s.t0bs >=g.cen ){
  5289. // // // // s.cen = g.cen;
  5290. // // // // break;
  5291. // // // // }
  5292. // // // // }
  5293.  
  5294. // // // // }
  5295.  
  5296. // // // console.log(377, stack) // Ms
  5297.  
  5298. // // }
  5299.  
  5300.  
  5301. // // console.timeEnd('FIX_TIMESTAMP_FOR_REPLAY')
  5302.  
  5303. // }
  5304.  
  5305.  
  5306.  
  5307.  
  5308.  
  5309.  
  5310.  
  5311.  
  5312.  
  5313. // console.log(5592,5)
  5314.  
  5315.  
  5316. // console.log('preprocessChatLiveActions', arr)
  5317.  
  5318.  
  5319. const mapper = new Map();
  5320.  
  5321. // without delaying. get the time of request
  5322. // (both streaming and replay, but replay relys on progress update so background operation is suppressed)
  5323.  
  5324. for (let j = 0, l = arr.length; j < l; j++) {
  5325. const aItem = arr[j];
  5326.  
  5327. const obj = toLAObj(aItem);
  5328. if(obj === false) continue;
  5329.  
  5330. if (obj.id && !obj.__timestampActionRequest__) {
  5331. // for all item entries
  5332. obj.__timestampActionRequest__ = ct;
  5333. }
  5334.  
  5335. if (obj.id && obj.__timestampActionRequest__ > 0 && obj.durationSec > 0 && obj.fullDurationSec) {
  5336.  
  5337. // console.log(948700, obj , obj.id, (obj.fullDurationSec - obj.durationSec) * 1000)
  5338. const m = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  5339.  
  5340. // obj.__t374__ = (obj.fullDurationSec - obj.durationSec) * 1000;
  5341. // obj.__t375__ = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  5342. // console.log(5993, obj)
  5343. // obj.__orderTime__ = m;
  5344. mapper.set(aItem, m);
  5345.  
  5346.  
  5347. }
  5348.  
  5349. }
  5350.  
  5351. if (mapper.size > 1) {
  5352.  
  5353. const idxices = [];
  5354.  
  5355. // sort ticker
  5356. let mArr1 = arr.filter((aItem,idx) => {
  5357.  
  5358. if (mapper.has(aItem)) {
  5359. idxices.push(idx);
  5360. return true;
  5361. }
  5362. return false;
  5363.  
  5364. });
  5365.  
  5366.  
  5367. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  5368. return mapper.get(a) - mapper.get(b);
  5369. // low index = oldest = smallest timestamp
  5370. });
  5371.  
  5372.  
  5373.  
  5374. // console.log(948701, arr.slice(0));
  5375. for(let j = 0, l=mArr1.length;j <l;j++){
  5376.  
  5377. const idx = idxices[j];
  5378. // arr[idx] = mArr1[j]
  5379. arr[idx] = mArr2[j];
  5380.  
  5381. // const obj1 = toObj(mArr1[j]);
  5382. // const obj2 = toObj(mArr2[j]);
  5383.  
  5384. // console.log(948705, idx, obj1 , obj1.id, (obj1.fullDurationSec - obj1.durationSec) * 1000, obj1.__orderTime__)
  5385.  
  5386. // console.log(948706, idx, obj2 , obj2.id, (obj2.fullDurationSec - obj2.durationSec) * 1000, obj2.__orderTime__)
  5387.  
  5388. }
  5389.  
  5390. // console.log(5994,arr)
  5391.  
  5392. // console.log(948702, arr.slice(0));
  5393. // console.log(948701, arr);
  5394. // arr = arr.map(aItem => {
  5395. // const idx = mArr1.indexOf(aItem);
  5396. // if (idx < 0) return aItem;
  5397. // return mArr2[idx];
  5398. // });
  5399. // console.log(948702, arr);
  5400.  
  5401. // mostly in order, but some not in order
  5402.  
  5403.  
  5404. // eg
  5405.  
  5406. /*
  5407.  
  5408.  
  5409. 948711 68 '1734488590715474'
  5410. 948711 69 '1734488590909853'
  5411. 948711 70 '1734488594763719'
  5412. 948711 71 '1734488602334615' <
  5413. 948711 72 '1734488602267214' <
  5414. 948711 73 '1734488602751771'
  5415. */
  5416.  
  5417. // arr.filter(aItem=>{
  5418.  
  5419. // const p = toObj(aItem);
  5420. // if(p.timestampUsec) return true;
  5421.  
  5422. // }).forEach((aItem,idx)=>{
  5423.  
  5424. // const p = toObj(aItem);
  5425. // console.log(948711, idx, p.timestampUsec);
  5426. // })
  5427.  
  5428. // return arr;
  5429.  
  5430. }
  5431.  
  5432. // console.log(1237001);
  5433.  
  5434. {
  5435.  
  5436.  
  5437. const mapper = new Map();
  5438.  
  5439.  
  5440. const idxices = [];
  5441.  
  5442.  
  5443. let mArr1 = arr.filter((aItem,idx) => {
  5444.  
  5445. const obj = toLAObj(aItem);
  5446. if (!obj) return false;
  5447.  
  5448. const baseText = obj.timestampText;
  5449. const baseTime = +obj.timestampUsec;
  5450. if (!baseTime || !baseText) return false;
  5451. // const timestampUsec = +toLAObj(aItem).timestampUsec; // +false.x = NaN
  5452. // const timestampUsec = +toLAObj(aItem).adjustedTime;
  5453.  
  5454. let timestampUsec;
  5455.  
  5456. // console.log(1237002)
  5457. if (FIX_TIMESTAMP_FOR_REPLAY) {
  5458.  
  5459. // const adjustmentTime = adjustmentMap.get(`${obj.id}.${obj.timestampUsec}`);
  5460.  
  5461. // // const wobj = additionalInfo.get(obj);
  5462.  
  5463. // // if(!wobj){
  5464. // // console.warn('FIX_TIMESTAMP_FOR_REPLAY - no wobj', obj)
  5465. // // return false;
  5466. // // }
  5467.  
  5468. // // timestampUsec = +wobj.timestampUsecAdjusted;
  5469. // if (!Number.isFinite(adjustmentTime)) {
  5470. // console.warn(`FIX_TIMESTAMP_FOR_REPLAY - no adjustmentTime for ${obj.id}.${obj.timestampUsec}`, obj, [...adjustmentMap])
  5471. // return false;
  5472. // }
  5473. // timestampUsec = adjustmentTime;
  5474.  
  5475.  
  5476. const adjustmentTime = adjustTimestampFn(obj);
  5477.  
  5478. if (!Number.isFinite(adjustmentTime)) {
  5479.  
  5480. console.warn(`FIX_TIMESTAMP_FOR_REPLAY - no adjustmentTime for ${obj.id}.${obj.timestampUsec}`, obj);
  5481. return false;
  5482. }
  5483. timestampUsec = adjustmentTime;
  5484.  
  5485.  
  5486. } else {
  5487.  
  5488. if (!Number.isFinite(baseTime)) {
  5489. console.warn(`no baseTime for ${obj.id}.${obj.timestampUsec}`, obj);
  5490.  
  5491. return false;
  5492. }
  5493. timestampUsec = baseTime;
  5494.  
  5495. }
  5496.  
  5497. // if(timestampUsec > 0){
  5498. idxices.push(idx);
  5499. mapper.set(aItem, timestampUsec)
  5500. return true;
  5501. // }
  5502. // return false;
  5503.  
  5504. });
  5505.  
  5506. if(mapper.size > 1){
  5507.  
  5508.  
  5509. // console.log(1237004)
  5510. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  5511. return mapper.get(a) - mapper.get(b);
  5512. // low index = oldest = smallest timestamp
  5513. });
  5514.  
  5515.  
  5516.  
  5517. // console.log(948701, arr.slice(0));
  5518. for(let j = 0, l=mArr1.length;j <l;j++){
  5519.  
  5520. const idx = idxices[j];
  5521. arr[idx] = mArr2[j];
  5522.  
  5523. // const obj1 = toObj(mArr1[j]);
  5524. // const obj2 = toObj(mArr2[j]);
  5525.  
  5526.  
  5527. // console.log(948711, idx, obj1 === obj2, obj1, obj1.timestampUsec);
  5528. // console.log(948712, idx, obj1 === obj2, obj2, obj2.timestampUsec);
  5529. }
  5530.  
  5531. }
  5532.  
  5533.  
  5534. }
  5535.  
  5536. // console.log(1237005)
  5537.  
  5538. // console.log(378, arr);
  5539.  
  5540. return arr;
  5541.  
  5542.  
  5543. }
  5544.  
  5545. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  5546.  
  5547. console.log('[yt-chat-control] ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION is used.')
  5548.  
  5549. // console.log('ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION 0001')
  5550.  
  5551. const pop078 = function () {
  5552. const r = this.pop78();
  5553.  
  5554. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  5555. for (const action of r.actions) {
  5556.  
  5557. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  5558. if (itemActionKey) {
  5559.  
  5560. const itemAction = action[itemActionKey];
  5561. const item = (itemAction || 0).item;
  5562. if (typeof item === 'object') {
  5563.  
  5564. const rendererKey = firstObjectKey(item);
  5565. if (rendererKey) {
  5566. const renderer = item[rendererKey];
  5567. if (renderer && typeof renderer === 'object') {
  5568. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  5569. renderer.__progressAt__ = playerProgressChangedArg1;
  5570.  
  5571. // console.log(48117006)
  5572. }
  5573.  
  5574. }
  5575.  
  5576. }
  5577. }
  5578. }
  5579. }
  5580. return r;
  5581. }
  5582.  
  5583.  
  5584.  
  5585. const replayQueueProxyHandler = {
  5586. get(target, prop, receiver) {
  5587. if (prop === 'qe3') return 1;
  5588. const v = target[prop];
  5589. if (prop === 'front_') {
  5590. if (v && typeof v.length === 'number') {
  5591. if (!v.pop78) {
  5592. v.pop78 = v.pop;
  5593. v.pop = pop078;
  5594. }
  5595. }
  5596. }
  5597. return v;
  5598. }
  5599. };
  5600.  
  5601. // lcrFn2 will run twice to ensure the method is successfully injected.
  5602. const lcrFn2 = (lcrDummy)=>{
  5603. // make minimal function overhead by pre-defining all possible outside.
  5604.  
  5605. const tag = "yt-live-chat-renderer"
  5606. const dummy = lcrDummy;
  5607.  
  5608. const cProto = getProto(dummy);
  5609. if (!cProto || !cProto.attached) {
  5610. console.warn(`proto.attached for ${tag} is unavailable.`);
  5611. return;
  5612. }
  5613.  
  5614. // mightFirstCheckOnYtInit();
  5615. // groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  5616. // console.log("[Begin]");
  5617.  
  5618.  
  5619. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  5620.  
  5621. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  5622.  
  5623.  
  5624. cProto.playerProgressChanged_ = function (a, b, c) {
  5625. // console.log(48117005)
  5626. playerProgressChangedArg1 = a;
  5627. playerProgressChangedArg2 = b;
  5628. playerProgressChangedArg3 = c;
  5629. const replayBuffer_ = this.replayBuffer_;
  5630. if (replayBuffer_) {
  5631. const replayQueue = replayBuffer_.replayQueue
  5632. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  5633. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, replayQueueProxyHandler);
  5634. }
  5635. }
  5636. Promise.resolve().then(updateTickerCurrentTime);
  5637. return this.playerProgressChanged32_.apply(this, arguments);
  5638. };
  5639.  
  5640. }
  5641.  
  5642. // console.log("[End]");
  5643. // groupEnd();
  5644.  
  5645.  
  5646. };
  5647. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  5648.  
  5649.  
  5650. // console.log('ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION 0002')
  5651.  
  5652. // getLCRDummy() must be called for injection
  5653. getLCRDummy().then(lcrFn2);
  5654.  
  5655. }
  5656.  
  5657.  
  5658.  
  5659. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  5660.  
  5661.  
  5662. const tag = "yt-live-chat-item-list-renderer"
  5663. const dummy = document.createElement(tag);
  5664.  
  5665. const cProto = getProto(dummy);
  5666. if (!cProto || !cProto.attached) {
  5667. console.warn(`proto.attached for ${tag} is unavailable.`);
  5668. return;
  5669. }
  5670.  
  5671. mightFirstCheckOnYtInit();
  5672. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  5673. console1.log("[Begin]");
  5674.  
  5675. const mclp = cProto;
  5676. const _flag0281_ = window._flag0281_;
  5677.  
  5678. try {
  5679. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  5680. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  5681. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  5682. assertor(() => typeof mclp.setAtBottom === 'function');
  5683. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  5684. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  5685. } catch (e) { }
  5686.  
  5687.  
  5688. try {
  5689. assertor(() => typeof mclp.attached === 'function');
  5690. assertor(() => typeof mclp.detached === 'function');
  5691. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  5692. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  5693. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  5694. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  5695. assertor(() => typeof mclp.smoothScroll_ === 'function');
  5696. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  5697. } catch (e) { }
  5698.  
  5699. mclp.__intermediate_delay__ = null;
  5700.  
  5701. let myk = 0; // showNewItems77_
  5702. let mlf = 0; // flushActiveItems77_
  5703. let myw = 0; // onScrollItems77_
  5704. let mzt = 0; // handleLiveChatActions77_
  5705. let mlg = 0; // delayFlushActiveItemsAfterUserAction11_
  5706. let zarr = null;
  5707.  
  5708. if ((_flag0281_ & 0x2000) == 0) {
  5709.  
  5710. if ((mclp.clearList || 0).length === 0) {
  5711. (_flag0281_ & 0x2) == 0 && assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  5712. mclp.clearList66 = mclp.clearList;
  5713. mclp.clearList = function () {
  5714. myk = (myk & 1073741823) + 1;
  5715. mlf = (mlf & 1073741823) + 1;
  5716. myw = (myw & 1073741823) + 1;
  5717. mzt = (mzt & 1073741823) + 1;
  5718. mlg = (mlg & 1073741823) + 1;
  5719. zarr = null;
  5720. this.__intermediate_delay__ = null;
  5721. this.clearList66();
  5722. };
  5723. console1.log("clearList", "OK");
  5724. } else {
  5725. console1.log("clearList", "NG");
  5726. }
  5727.  
  5728. }
  5729.  
  5730.  
  5731.  
  5732. let onListRendererAttachedDone = false;
  5733.  
  5734. function setList(itemOffset, items) {
  5735.  
  5736. const isFirstTime = onListRendererAttachedDone === false;
  5737.  
  5738. if (isFirstTime) {
  5739. onListRendererAttachedDone = true;
  5740. Promise.resolve().then(watchUserCSS);
  5741. addCssManaged();
  5742.  
  5743. const isBoostChatEnabled = (window._flag0281_ & 0x40000) === 0x40000;
  5744. if (!isBoostChatEnabled) setupEvents();
  5745. }
  5746.  
  5747. setupStyle(itemOffset, items);
  5748.  
  5749. setupMutObserver(items);
  5750.  
  5751. console.log('[yt-chat] setupMutObserver DONE')
  5752. }
  5753.  
  5754. mclp.attached419 = async function () {
  5755.  
  5756. if (!this.isAttached) return;
  5757.  
  5758. let maxTrial = 16;
  5759. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  5760. if (--maxTrial < 0 || !this.isAttached) return;
  5761. await iAFP(this.hostElement).then();
  5762. // await new Promise(requestAnimationFrame);
  5763. }
  5764.  
  5765. if (this.isAttached !== true) return;
  5766.  
  5767. if (!this.$) {
  5768. console.warn("!this.$");
  5769. return;
  5770. }
  5771. if (!this.$) return;
  5772. /** @type {HTMLElement | null} */
  5773. const itemScroller = this.$['item-scroller'];
  5774. /** @type {HTMLElement | null} */
  5775. const itemOffset = this.$['item-offset'];
  5776. /** @type {HTMLElement | null} */
  5777. const items = this.$['items'];
  5778.  
  5779. if (!itemScroller || !itemOffset || !items) {
  5780. console.warn("items.parentNode !== itemOffset");
  5781. return;
  5782. }
  5783.  
  5784. if (nodeParent(items) !== itemOffset) {
  5785.  
  5786. console.warn("items.parentNode !== itemOffset");
  5787. return;
  5788. }
  5789.  
  5790.  
  5791. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  5792.  
  5793. console.warn("id incorrect");
  5794. return;
  5795. }
  5796.  
  5797. 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')
  5798.  
  5799. if (!isTargetItems) {
  5800. console.warn("!isTargetItems");
  5801. return;
  5802. }
  5803.  
  5804. setList(itemOffset, items);
  5805.  
  5806. }
  5807.  
  5808. mclp.attached331 = mclp.attached;
  5809. mclp.attached = function () {
  5810. this.attached419 && this.attached419();
  5811. return this.attached331();
  5812. }
  5813.  
  5814. mclp.detached331 = mclp.detached;
  5815.  
  5816. mclp.detached = function () {
  5817. setupMutObserver();
  5818. return this.detached331();
  5819. }
  5820.  
  5821. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  5822. for (const t29 of t29s) {
  5823. if (insp(t29).isAttached === true) {
  5824. t29.attached419();
  5825. }
  5826. }
  5827.  
  5828. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  5829.  
  5830. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  5831. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  5832.  
  5833. /** @type {Map<number, any>} */
  5834. const aMap = new Map();
  5835. let count = 6150;
  5836. mclp.async66 = mclp.async;
  5837. mclp.async = function (e, f) {
  5838. // ensure the previous operation is done
  5839. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  5840. const hasF = arguments.length === 2;
  5841. const stack = new Error().stack;
  5842. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  5843. if (count > 1e9) count = 6159;
  5844. const resId = ++count;
  5845. aMap.set(resId, e);
  5846. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  5847. const rp = aMap.get(resId);
  5848. if (typeof rp !== 'function') {
  5849. return;
  5850. }
  5851. let cancelCall = false;
  5852. if (isFlushAsync) {
  5853. if (rk < 0) {
  5854. cancelCall = true;
  5855. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  5856. cancelCall = true;
  5857. }
  5858. }
  5859. if (cancelCall) {
  5860. aMap.delete(resId);
  5861. } else {
  5862. const asyncEn = function () {
  5863. aMap.delete(resId);
  5864. return rp.apply(this, arguments);
  5865. };
  5866. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  5867. }
  5868. });
  5869.  
  5870. return resId;
  5871. }
  5872.  
  5873. mclp.cancelAsync66 = mclp.cancelAsync;
  5874. mclp.cancelAsync = function (resId) {
  5875. if (resId <= 6150) {
  5876. this.cancelAsync66(resId);
  5877. } else if (aMap.has(resId)) {
  5878. const rp = aMap.get(resId);
  5879. aMap.delete(resId);
  5880. if (typeof rp !== 'function') {
  5881. this.cancelAsync66(rp);
  5882. }
  5883. }
  5884. }
  5885.  
  5886. console1.log("async", "OK");
  5887. } else {
  5888. console1.log("async", "NG");
  5889. }
  5890.  
  5891.  
  5892. if ((_flag0281_ & 0x2) == 0) {
  5893. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  5894.  
  5895. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  5896. mclp.showNewItems66_ = mclp.showNewItems_;
  5897.  
  5898. mclp.showNewItems77_ = async function () {
  5899. let tid = myk = (myk & 1073741823) + 1;
  5900.  
  5901. await iAFP(this.hostElement).then();
  5902. // await new Promise(requestAnimationFrame);
  5903.  
  5904. if (tid !== myk) {
  5905. return;
  5906. }
  5907.  
  5908. const cnt = this;
  5909.  
  5910. await Promise.resolve();
  5911. cnt.showNewItems66_();
  5912.  
  5913. await Promise.resolve();
  5914.  
  5915. }
  5916.  
  5917. mclp.showNewItems_ = function () {
  5918.  
  5919. const cnt = this;
  5920. cnt.__intermediate_delay__ = new Promise(resolve => {
  5921. cnt.showNewItems77_().then(() => {
  5922. resolve();
  5923. });
  5924. });
  5925. }
  5926.  
  5927. console1.log("showNewItems_", "OK");
  5928. } else {
  5929. console1.log("showNewItems_", "NG");
  5930. }
  5931.  
  5932. }
  5933.  
  5934. if ((_flag0281_ & 0x2000) == 0) {
  5935. if ((mclp.flushActiveItems_ || 0).length === 0) {
  5936.  
  5937. if ((_flag0281_ & 0x2) == 0) {
  5938.  
  5939. const sfi = fnIntegrity(mclp.flushActiveItems_);
  5940. if(sfi === '0.158.86'){
  5941.  
  5942. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  5943.  
  5944.  
  5945. // f.flushActiveItems_ = function() {
  5946. // var a = this;
  5947. // if (this.activeItems_.length > 0)
  5948. // if (this.canScrollToBottom_()) {
  5949. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  5950. // b && this.splice("visibleItems", 0, b);
  5951. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  5952. // this.preinsertHeight_ = this.items.clientHeight;
  5953. // this.activeItems_.unshift("visibleItems");
  5954. // try {
  5955. // this.push.apply(this, this.activeItems_)
  5956. // } catch (c) {
  5957. // Tm(c)
  5958. // }
  5959. // this.activeItems_ = [];
  5960. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && $u(function() {
  5961. // a.showNewItems_()
  5962. // }) : $u(function() {
  5963. // a.refreshOffsetContainerHeight_();
  5964. // a.maybeScrollToBottom_()
  5965. // })
  5966. // } else
  5967. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  5968. // }
  5969.  
  5970. } else if (sfi === '0.156.86') {
  5971. // https://www.youtube.com/s/desktop/f61c8d85/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  5972.  
  5973. // added "refreshOffsetContainerHeight_"
  5974.  
  5975. // f.flushActiveItems_ = function() {
  5976. // var a = this;
  5977. // if (0 < this.activeItems_.length)
  5978. // if (this.canScrollToBottom_()) {
  5979. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  5980. // b && this.splice("visibleItems", 0, b);
  5981. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  5982. // this.preinsertHeight_ = this.items.clientHeight;
  5983. // this.activeItems_.unshift("visibleItems");
  5984. // try {
  5985. // this.push.apply(this, this.activeItems_)
  5986. // } catch (c) {
  5987. // fm(c)
  5988. // }
  5989. // this.activeItems_ = [];
  5990. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && Mw(function() {
  5991. // a.showNewItems_()
  5992. // }) : Mw(function() {
  5993. // a.refreshOffsetContainerHeight_();
  5994. // a.maybeScrollToBottom_()
  5995. // })
  5996. // } else
  5997. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  5998. // }
  5999. // ;
  6000.  
  6001. } else if (sfi === '0.150.84') {
  6002. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6003. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6004. // b && this.splice("visibleItems", 0, b);
  6005. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6006. // this.preinsertHeight_ = this.items.clientHeight;
  6007. // this.activeItems_.unshift("visibleItems");
  6008. // try {
  6009. // this.push.apply(this, this.activeItems_)
  6010. // } catch (c) {
  6011. // nm(c)
  6012. // }
  6013. // this.activeItems_ = [];
  6014. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && zQ(function() {
  6015. // a.showNewItems_()
  6016. // }) : zQ(function() {
  6017. // a.maybeScrollToBottom_()
  6018. // })
  6019. } else if (sfi === '0.137.81' || sfi === '0.138.81') {
  6020. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  6021. } else {
  6022. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.158.86'))
  6023. || logFn('mclp.flushActiveItems_', mclp.flushActiveItems_)();
  6024. }
  6025. }
  6026.  
  6027. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  6028.  
  6029. mclp.flushActiveItems66a_ = mclp.flushActiveItems_;
  6030. let lastLastRow = null;
  6031. mclp.flushActiveItems66_ = function () {
  6032. const visibleItemsA = (this || 0).visibleItems;
  6033. const lastVisibleItemA = visibleItemsA ? visibleItemsA[visibleItemsA.length - 1] : null;
  6034. const r = this.flushActiveItems66a_();
  6035.  
  6036. const visibleItemsB = (this || 0).visibleItems;
  6037. const lastVisibleItemB = visibleItemsB ? visibleItemsB[visibleItemsB.length - 1] : null;
  6038.  
  6039. if (lastVisibleItemA !== lastVisibleItemB) {
  6040.  
  6041. try {
  6042. const lastRow = kRef(lastLastRow);
  6043.  
  6044. const keyB = lastVisibleItemB ? firstObjectKey(lastVisibleItemB) : '';
  6045. const idB = keyB ? (lastVisibleItemB[keyB].id || null) : null;
  6046.  
  6047. if (idB) {
  6048.  
  6049. let elm = this.$.items.lastElementChild;
  6050.  
  6051. while (elm instanceof HTMLElement) {
  6052. if (elm.id === idB) break;
  6053. elm = ('__shady_native_previousElementSibling' in elm) ? elm.__shady_native_previousElementSibling : elm.previousElementSibling;
  6054. }
  6055.  
  6056. lastRow && lastRow.classList.remove('cyt-chat-last-message');
  6057. if (elm) {
  6058. elm.classList.add('cyt-chat-last-message');
  6059. lastLastRow = mWeakRef(elm);
  6060. }
  6061.  
  6062. }
  6063.  
  6064. } catch (e) { }
  6065.  
  6066.  
  6067. }
  6068.  
  6069. return r;
  6070. };
  6071.  
  6072. const preloadFn = (acItems) => {
  6073. let waitFor = [];
  6074. /** @type {Set<string>} */
  6075. const imageLinks = new Set();
  6076.  
  6077. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  6078. for (const item of acItems) {
  6079. fixLiveChatItem(item, imageLinks);
  6080. }
  6081. }
  6082. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  6083.  
  6084. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  6085. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  6086. // preload performs the high priority fetching.
  6087. // prefetch delays the chat display if the video resoruce is demanding.
  6088.  
  6089. if (rel) {
  6090.  
  6091. imageLinks.forEach(imageLink => {
  6092. let d = false;
  6093. if (SKIP_PRELOAD_EMOJI && imageLink.includes('.ggpht.com/')) return;
  6094. const isEmoji = imageLink.includes('/emoji/');
  6095. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  6096. if (!pretechedSet.has(imageLink)) {
  6097. pretechedSet.add(imageLink);
  6098. d = true;
  6099. }
  6100. if (d) {
  6101. waitFor.push(linker(null, rel, imageLink, 'image'));
  6102.  
  6103. }
  6104. })
  6105.  
  6106. }
  6107.  
  6108. }
  6109.  
  6110. return async () => {
  6111. if (waitFor.length > 0) {
  6112. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  6113. }
  6114. waitFor.length = 0;
  6115. waitFor = null;
  6116. };
  6117.  
  6118. };
  6119.  
  6120. mclp.flushActiveItems78_ = async function (tid) {
  6121. try {
  6122.  
  6123. if (tid !== mlf) return;
  6124. if ((this._flag0281_ & 0x4) == 0x4) {
  6125. const cnt = this;
  6126.  
  6127. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6128. const acItems = cnt.activeItems_;
  6129. if (!acItems || acItems.length === 0) return;
  6130.  
  6131. mlf = (mlf & 1073741823) + 1;
  6132. mlg = (mlg & 1073741823) + 1;
  6133. if (acItems.length < MAX_ITEMS_FOR_FULL_FLUSH) {
  6134. const pn = preloadFn(acItems);
  6135. await pn();
  6136. }
  6137. cnt.flushActiveItems66_();
  6138.  
  6139. return 1;
  6140.  
  6141. }
  6142. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  6143. let logger = false;
  6144. const cnt = this;
  6145. let immd = cnt.__intermediate_delay__;
  6146. await iAFP(this.hostElement).then();
  6147. // await new Promise(requestAnimationFrame);
  6148.  
  6149. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6150. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  6151.  
  6152. mlf = (mlf & 1073741823) + 1;
  6153. mlg = (mlg & 1073741823) + 1;
  6154.  
  6155. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  6156. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  6157. let changeMaxItemsToDisplay = false;
  6158. const activeItemsLen = this.activeItems_.length;
  6159. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  6160. logger = true;
  6161.  
  6162. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  6163.  
  6164. console1.log('[Begin]')
  6165.  
  6166. console1.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  6167. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  6168. console1.log('reduce maxitems');
  6169. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  6170. // as all the rendered chats are already "outdated"
  6171. // all old chats shall remove and reduced number of few chats will be rendered
  6172. // then restore to the original number
  6173. changeMaxItemsToDisplay = true;
  6174. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  6175. console1.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  6176. }
  6177. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  6178. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  6179.  
  6180. console1.log('new this.activeItems_.length > N', this.activeItems_.length);
  6181. } else {
  6182. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  6183.  
  6184. console1.log('new this.activeItems_.length > N', this.activeItems_.length);
  6185. }
  6186.  
  6187. }
  6188. // it is found that it will render all stacked chats after switching back from background
  6189. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  6190. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  6191.  
  6192. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  6193. await Promise.resolve();
  6194. const acItems = cnt.activeItems_;
  6195. const len1 = acItems.length;
  6196. if (!len1) console.warn('cnt.activeItems_.length = 0');
  6197.  
  6198. const pn = preloadFn(acItems);
  6199. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  6200. // skipDontRender = noVisibleItem1;
  6201. await pn();
  6202. // console.log('ss2', Date.now())
  6203. cnt.flushActiveItems66_();
  6204. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  6205. // skipDontRender = noVisibleItem2;
  6206. await Promise.resolve();
  6207. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  6208. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  6209.  
  6210. logger && console1.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  6211. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  6212. } else if (changeMaxItemsToDisplay) {
  6213.  
  6214. logger && console1.log(`'maxItemsToDisplay' cannot be restored`, {
  6215. maxItemsToDisplay: this.data.maxItemsToDisplay,
  6216. reducedMaxItemsToDisplay,
  6217. originalMaxItemsToDisplay: tmpMaxItemsCount
  6218. });
  6219. }
  6220. logger && console1.log('[End]');
  6221.  
  6222. logger && groupEnd();
  6223.  
  6224. if (noVisibleItem1 && !noVisibleItem2) {
  6225. // fix possible no auto scroll issue.
  6226. !((cnt.__notRequired__ || 0) & 256) && setTimeout(() => cnt.setAtBottom(), 1);
  6227. }
  6228.  
  6229. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  6230.  
  6231.  
  6232. const ff = () => {
  6233.  
  6234. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6235. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6236. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  6237.  
  6238. if (typeof nextBrowserTick !== 'function') {
  6239. cnt.scrollToBottom_();
  6240. Promise.resolve().then(() => {
  6241. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6242. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  6243. });
  6244. } else {
  6245. nextBrowserTick(() => {
  6246. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6247. cnt.scrollToBottom_();
  6248. });
  6249. }
  6250.  
  6251. }
  6252. }
  6253.  
  6254. ff();
  6255.  
  6256.  
  6257. Promise.resolve().then(ff);
  6258.  
  6259. // requestAnimationFrame(ff);
  6260. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  6261.  
  6262. const knt = cnt;
  6263. if (!scrollChatFn) {
  6264. const cnt = knt;
  6265. const f = () => {
  6266. const itemScroller = cnt.itemScroller;
  6267. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  6268. if (!cnt.atBottom) {
  6269. cnt.scrollToBottom_();
  6270. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  6271. itemScroller.scrollTop = itemScroller.scrollHeight;
  6272. }
  6273. };
  6274. if (typeof nextBrowserTick !== 'function') {
  6275. scrollChatFn = () => Promise.resolve().then(f).then(f);
  6276. } else {
  6277. scrollChatFn = () => nextBrowserTick(f);
  6278. }
  6279. }
  6280.  
  6281. scrollChatFn();
  6282. }
  6283.  
  6284. return 1;
  6285.  
  6286.  
  6287. } catch (e) {
  6288. console.warn(e);
  6289. }
  6290. };
  6291.  
  6292. mclp.flushActiveItems77_ = function () {
  6293.  
  6294. return new Promise(resResolve => {
  6295. try {
  6296. const cnt = this;
  6297. let tid = mlf = (mlf & 1073741823) + 1;
  6298. const hostElement = cnt.hostElement || cnt;
  6299. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  6300. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  6301.  
  6302. // 4 times to maxItems to avoid frequent trimming.
  6303. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  6304.  
  6305. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  6306. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  6307. if (cnt.canScrollToBottom_()) {
  6308. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  6309. .then(() => cnt.flushActiveItems78_(tid)) // async function
  6310. .then((asyncResult) => {
  6311. resResolve(asyncResult); // either undefined or 1
  6312. resResolve = null;
  6313. }).catch((e) => {
  6314. console.warn(e);
  6315. if (resResolve) resResolve();
  6316. });
  6317. } else {
  6318. resResolve(2);
  6319. resResolve = null;
  6320. }
  6321. } catch (e) {
  6322. console.warn(e);
  6323. if (resResolve) resResolve();
  6324. }
  6325.  
  6326.  
  6327. });
  6328.  
  6329. };
  6330.  
  6331. mclp.flushActiveItems_ = function () {
  6332. const cnt = this;
  6333.  
  6334. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  6335.  
  6336. if (cnt.activeItems_.length === 0) {
  6337. cnt.__intermediate_delay__ = null;
  6338. return;
  6339. }
  6340.  
  6341. const cntData = ((cnt || 0).data || 0);
  6342. if (cntData.maxItemsToDisplay944 === undefined) {
  6343. cntData.maxItemsToDisplay944 = null;
  6344. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  6345. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  6346. }
  6347.  
  6348. // ignore previous __intermediate_delay__ and create a new one
  6349. cnt.__intermediate_delay__ = new Promise(resolve => {
  6350. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  6351. if (rt === 1) {
  6352. resolve(1); // success, scroll to bottom
  6353. if (hasMoreMessageState === 1) {
  6354. hasMoreMessageState = 0;
  6355. const showMore = (cnt.$ || 0)['show-more'];
  6356. if (showMore) {
  6357. showMore.classList.remove('has-new-messages-miuzp');
  6358. }
  6359. }
  6360. }
  6361. else if (rt === 2) {
  6362. resolve(2); // success, trim
  6363. if (hasMoreMessageState === 0) {
  6364. hasMoreMessageState = 1;
  6365. const showMore = cnt.$['show-more'];
  6366. if (showMore) {
  6367. showMore.classList.add('has-new-messages-miuzp');
  6368. }
  6369. }
  6370. }
  6371. else resolve(-1); // skip
  6372. }).catch(e => {
  6373. console.warn(e);
  6374. });
  6375. });
  6376.  
  6377. };
  6378. console1.log("flushActiveItems_", "OK");
  6379. } else {
  6380. console1.log("flushActiveItems_", "NG");
  6381. }
  6382. }
  6383.  
  6384. if ((_flag0281_ & 0x40) == 0) {
  6385.  
  6386. if (ENABLE_NO_SMOOTH_TRANSFORM && SUPPRESS_refreshOffsetContainerHeight_ && typeof mclp.refreshOffsetContainerHeight_ === 'function' && !mclp.refreshOffsetContainerHeight26_ && mclp.refreshOffsetContainerHeight_.length === 0) {
  6387. assertor(() => fnIntegrity(mclp.refreshOffsetContainerHeight_, '0.31.21'));
  6388. mclp.refreshOffsetContainerHeight26_ = mclp.refreshOffsetContainerHeight_;
  6389. mclp.refreshOffsetContainerHeight_ = function () {
  6390. // var a = this.itemScroller.clientHeight;
  6391. // this.itemOffset.style.height = this.items.clientHeight + "px";
  6392. // this.bottomAlignMessages && (this.itemOffset.style.minHeight = a + "px")
  6393. }
  6394. console1.log("refreshOffsetContainerHeight_", "OK");
  6395. } else {
  6396. console1.log("refreshOffsetContainerHeight_", "NG");
  6397. }
  6398.  
  6399. }
  6400.  
  6401. if ((_flag0281_ & 0x80) == 0) {
  6402. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  6403. try {
  6404. const tid = mlg = (mlg & 1073741823) + 1;
  6405. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  6406. const runCond = () => this.canScrollToBottom_();
  6407. if (!keepTrialCond()) return;
  6408. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  6409. await new Promise(r => setTimeout(r, 80));
  6410. if (!keepTrialCond()) return;
  6411. if (runCond()) return this.flushActiveItems_() | 1;
  6412. await iAFP(this.hostElement).then();
  6413. // await new Promise(requestAnimationFrame);
  6414. if (runCond()) return this.flushActiveItems_() | 1;
  6415. } catch (e) {
  6416. console.warn(e);
  6417. }
  6418. }
  6419. }
  6420.  
  6421. if ((_flag0281_ & 0x40) == 0 ) {
  6422.  
  6423. if( (mclp.atBottomChanged_ || 0).length === 0) {
  6424. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  6425.  
  6426. const sfi = fnIntegrity(mclp.atBottomChanged_);
  6427.  
  6428. if(sfi === '0.75.37'){
  6429. // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6430.  
  6431.  
  6432. // Dec 2024.
  6433.  
  6434. /**
  6435. *
  6436. *
  6437.  
  6438. f.atBottomChanged_ = function() {
  6439. var a = this;
  6440. this.atBottom ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = Zu(function() {
  6441. R(a.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6442. }, 200)) : (this.hideShowMoreAsync_ && $u(this.hideShowMoreAsync_),
  6443. this.hideShowMoreAsync_ = null,
  6444. R(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6445. }
  6446. *
  6447. */
  6448.  
  6449. } else {
  6450. assertor(() => fnIntegrity(mclp.atBottomChanged_, '0.75.37'));
  6451. }
  6452.  
  6453.  
  6454. const querySelector = HTMLElement.prototype.querySelector;
  6455. const U = (element) => ({
  6456. querySelector: (selector) => querySelector.call(element, selector)
  6457. });
  6458.  
  6459. let qid = 0;
  6460. mclp.__updateButtonVisibility371__ = function (button) {
  6461. Promise.resolve(this).then((cnt) => {
  6462. button.style.visibility = cnt.__buttonVisibility371__;
  6463. });
  6464. }
  6465. const fixButtonOnClick = function (cnt, button) {
  6466. button.addEventListener('click', (evt) => {
  6467. evt.stopImmediatePropagation();
  6468. evt.stopPropagation();
  6469. evt.preventDefault();
  6470. Promise.resolve(cnt).then((cnt) => {
  6471. cnt.scrollToBottom_();
  6472. });
  6473. }, true);
  6474. // button.addEventListener('pointerup', (evt)=>{
  6475. // evt.stopImmediatePropagation();
  6476. // evt.stopPropagation();
  6477. // }, true);
  6478. // button.addEventListener('mouseup', (evt)=>{
  6479. // evt.stopImmediatePropagation();
  6480. // evt.stopPropagation();
  6481. // }, true);
  6482. }
  6483. mclp.atBottomChanged_ = function () {
  6484. let a = this.atBottom;
  6485. const button = (this.$ || 0)['show-more'];
  6486. if (button) {
  6487. // primary execution
  6488. if (a) {
  6489. if (this.__buttonVisibility371__ !== "hidden") {
  6490. this.__buttonVisibility371__ = "hidden";
  6491. if (!this.hideShowMoreAsync_) {
  6492. const tid = ++qid;
  6493. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  6494. if (tid !== qid) {
  6495. return;
  6496. }
  6497. this.__updateButtonVisibility371__(button);
  6498. });
  6499. }
  6500. }
  6501. } else {
  6502. if (this.__buttonVisibility371__ !== "visible") {
  6503. this.__buttonVisibility371__ = "visible";
  6504. if (this.hideShowMoreAsync_) {
  6505. qid++;
  6506. }
  6507. this.hideShowMoreAsync_ = null;
  6508. if (!button.__fix_onclick__) {
  6509. button.__fix_onclick__ = true;
  6510. fixButtonOnClick(this, button);
  6511. }
  6512. this.__updateButtonVisibility371__(button);
  6513. }
  6514. }
  6515. } else {
  6516. // fallback
  6517. let tid = ++qid;
  6518. let b = this;
  6519. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  6520. if (tid !== qid) return;
  6521. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6522. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  6523. this.hideShowMoreAsync_ = null,
  6524. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6525. }
  6526. }
  6527.  
  6528. console1.log("atBottomChanged_", "OK");
  6529.  
  6530. } else if ((mclp.atBottomChanged_ || 0).length === 1) {
  6531. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  6532.  
  6533. const sfi = fnIntegrity(mclp.atBottomChanged_);
  6534. if (sfi === '1.73.37') {
  6535. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6536.  
  6537. /**
  6538. *
  6539. *
  6540. *
  6541.  
  6542. f.atBottomChanged_ = function(a) {
  6543. var b = this;
  6544. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = zQ(function() {
  6545. T(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6546. }, 200)) : (this.hideShowMoreAsync_ && AQ(this.hideShowMoreAsync_),
  6547. this.hideShowMoreAsync_ = null,
  6548. T(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6549. };
  6550.  
  6551. *
  6552. *
  6553. */
  6554.  
  6555.  
  6556. } else if (sfi === '1.75.39') {
  6557. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  6558. } else {
  6559. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.73.37'));
  6560. }
  6561.  
  6562. const querySelector = HTMLElement.prototype.querySelector;
  6563. const U = (element) => ({
  6564. querySelector: (selector) => querySelector.call(element, selector)
  6565. });
  6566.  
  6567. let qid = 0;
  6568. mclp.__updateButtonVisibility371__ = function (button) {
  6569. Promise.resolve(this).then((cnt) => {
  6570. button.style.visibility = cnt.__buttonVisibility371__;
  6571. });
  6572. }
  6573. const fixButtonOnClick = function (cnt, button) {
  6574. button.addEventListener('click', (evt) => {
  6575. evt.stopImmediatePropagation();
  6576. evt.stopPropagation();
  6577. evt.preventDefault();
  6578. Promise.resolve(cnt).then((cnt) => {
  6579. cnt.scrollToBottom_();
  6580. });
  6581. }, true);
  6582. // button.addEventListener('pointerup', (evt)=>{
  6583. // evt.stopImmediatePropagation();
  6584. // evt.stopPropagation();
  6585. // }, true);
  6586. // button.addEventListener('mouseup', (evt)=>{
  6587. // evt.stopImmediatePropagation();
  6588. // evt.stopPropagation();
  6589. // }, true);
  6590. }
  6591. mclp.atBottomChanged_ = function (a) {
  6592. const button = (this.$ || 0)['show-more'];
  6593. if (button) {
  6594. // primary execution
  6595. if (a) {
  6596. if (this.__buttonVisibility371__ !== "hidden") {
  6597. this.__buttonVisibility371__ = "hidden";
  6598. if (!this.hideShowMoreAsync_) {
  6599. const tid = ++qid;
  6600. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  6601. if (tid !== qid) {
  6602. return;
  6603. }
  6604. this.__updateButtonVisibility371__(button);
  6605. });
  6606. }
  6607. }
  6608. } else {
  6609. if (this.__buttonVisibility371__ !== "visible") {
  6610. this.__buttonVisibility371__ = "visible";
  6611. if (this.hideShowMoreAsync_) {
  6612. qid++;
  6613. }
  6614. this.hideShowMoreAsync_ = null;
  6615. if (!button.__fix_onclick__) {
  6616. button.__fix_onclick__ = true;
  6617. fixButtonOnClick(this, button);
  6618. }
  6619. this.__updateButtonVisibility371__(button);
  6620. }
  6621. }
  6622. } else {
  6623. // fallback
  6624. let tid = ++qid;
  6625. let b = this;
  6626. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  6627. if (tid !== qid) return;
  6628. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6629. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  6630. this.hideShowMoreAsync_ = null,
  6631. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6632. }
  6633. }
  6634.  
  6635. console1.log("atBottomChanged_", "OK");
  6636. } else {
  6637. console1.log("atBottomChanged_", "NG");
  6638. }
  6639. }
  6640.  
  6641.  
  6642. if ((_flag0281_ & 0x2) == 0) {
  6643. if ((mclp.onScrollItems_ || 0).length === 1) {
  6644.  
  6645. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  6646. mclp.onScrollItems66_ = mclp.onScrollItems_;
  6647. mclp.onScrollItems77_ = async function (evt) {
  6648. let tid = myw = (myw & 1073741823) + 1;
  6649.  
  6650. await iAFP(this.hostElement).then();
  6651. // await new Promise(requestAnimationFrame);
  6652.  
  6653. if (tid !== myw) {
  6654. return;
  6655. }
  6656.  
  6657. const cnt = this;
  6658.  
  6659. await Promise.resolve();
  6660. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  6661. const onScrollItemsBasicOnly_ = !!((cnt.__notRequired__ || 0) & 512);
  6662. await Promise.resolve().then(() => {
  6663. this.ytRendererBehavior.onScroll(evt);
  6664. }).then(() => {
  6665. if (onScrollItemsBasicOnly_) return;
  6666. if (this.canScrollToBottom_()) {
  6667. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  6668. if (hasUserJustInteracted) {
  6669. // only when there is an user action
  6670. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6671. return 1;
  6672. }
  6673. } else {
  6674. // no message inserting
  6675. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6676. return 1;
  6677. }
  6678. }).then((r) => {
  6679.  
  6680. if (onScrollItemsBasicOnly_) return;
  6681. if (this.activeItems_.length) {
  6682.  
  6683. if (this.canScrollToBottom_()) {
  6684. this.flushActiveItems_();
  6685. return 1 && r;
  6686. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  6687. // delayed due to user action
  6688. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  6689. return 0;
  6690. }
  6691. }
  6692. }).then((r) => {
  6693. if (onScrollItemsBasicOnly_) return;
  6694. if (r) {
  6695. // ensure setAtBottom is correctly set
  6696. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6697. }
  6698. });
  6699. } else {
  6700. cnt.onScrollItems66_(evt);
  6701. }
  6702.  
  6703. await Promise.resolve();
  6704.  
  6705. }
  6706.  
  6707. mclp.onScrollItems_ = function (evt) {
  6708.  
  6709. const cnt = this;
  6710. cnt.__intermediate_delay__ = new Promise(resolve => {
  6711. cnt.onScrollItems77_(evt).then(() => {
  6712. resolve();
  6713. });
  6714. });
  6715. }
  6716. console1.log("onScrollItems_", "OK");
  6717. } else {
  6718. console1.log("onScrollItems_", "NG");
  6719. }
  6720. }
  6721.  
  6722. if ((_flag0281_ & 0x2) == 0) {
  6723. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  6724.  
  6725. const sfi = fnIntegrity(mclp.handleLiveChatActions_);
  6726. // handleLiveChatActions66_
  6727. if (sfi === '1.40.20') {
  6728. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6729.  
  6730.  
  6731. // f.handleLiveChatActions_ = function(a) {
  6732. // var b = this;
  6733. // a.length && (a.forEach(this.handleLiveChatAction_, this),
  6734. // this.maybeResizeScrollContainer_(a),
  6735. // this.flushActiveItems_(),
  6736. // $u(function() {
  6737. // b.maybeScrollToBottom_()
  6738. // }))
  6739. // }
  6740.  
  6741. } else if (sfi === '1.39.20') {
  6742. // TBC
  6743. } else if (sfi === '1.31.17') {
  6744. // original
  6745. } else {
  6746. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.40.20'))
  6747. || logFn('mclp.handleLiveChatActions_', mclp.handleLiveChatActions_)();
  6748. }
  6749.  
  6750. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  6751.  
  6752. mclp.handleLiveChatActions77_ = async function (arr) {
  6753. if (typeof (arr || 0).length !== 'number') {
  6754. this.handleLiveChatActions66_(arr);
  6755. return;
  6756. }
  6757. let tid = mzt = (mzt & 1073741823) + 1;
  6758.  
  6759. if (zarr === null) zarr = arr;
  6760. else Array.prototype.push.apply(zarr, arr);
  6761. arr = null;
  6762.  
  6763. await iAFP(this.hostElement).then();
  6764. // await new Promise(requestAnimationFrame);
  6765.  
  6766. if (tid !== mzt || zarr === null) {
  6767. return;
  6768. }
  6769.  
  6770. const carr = zarr;
  6771. zarr = null;
  6772.  
  6773. await Promise.resolve();
  6774. this.handleLiveChatActions66_(carr);
  6775. await Promise.resolve();
  6776.  
  6777. }
  6778.  
  6779. mclp.handleLiveChatActions_ = function (arr) {
  6780.  
  6781.  
  6782. try {
  6783. preprocessChatLiveActions(arr);
  6784. } catch (e) {
  6785. console.warn(e);
  6786. }
  6787.  
  6788.  
  6789.  
  6790. // console.log(1929, cnt.activeItems_)
  6791. // console.log(9487, arr);
  6792.  
  6793. const cnt = this;
  6794. cnt.__intermediate_delay__ = new Promise(resolve => {
  6795. cnt.handleLiveChatActions77_(arr).then(() => {
  6796. resolve();
  6797. });
  6798. });
  6799.  
  6800. resistanceUpdateFn_();
  6801. }
  6802. console1.log("handleLiveChatActions_", "OK");
  6803. } else {
  6804. console1.log("handleLiveChatActions_", "NG");
  6805. }
  6806. }
  6807.  
  6808. // we do not need to do user interaction check for Boost Chat (0x40000)
  6809. const noScrollToBottomCheckForBoostChat = (_flag0281_ & 0x40000) === 0x40000;
  6810.  
  6811. if (noScrollToBottomCheckForBoostChat === false) {
  6812.  
  6813. mclp.hasUserJustInteracted11_ = () => {
  6814. const t = dateNow();
  6815. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  6816. }
  6817.  
  6818. if ((mclp.canScrollToBottom_ || 0).length === 0 && !mclp.canScrollToBottom157_) {
  6819.  
  6820. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  6821.  
  6822. mclp.canScrollToBottom157_ = mclp.canScrollToBottom_;
  6823. mclp.canScrollToBottom_ = function () {
  6824. return this.canScrollToBottom157_() && !this.hasUserJustInteracted11_();
  6825. }
  6826.  
  6827. console1.log("canScrollToBottom_", "OK");
  6828.  
  6829.  
  6830. } else {
  6831. console1.log("canScrollToBottom_", "NG");
  6832. }
  6833.  
  6834. }
  6835.  
  6836. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  6837.  
  6838. mclp.isSmoothScrollEnabled_ = function () {
  6839. return false;
  6840. }
  6841.  
  6842. mclp.maybeResizeScrollContainer_ = function () {
  6843. //
  6844. }
  6845.  
  6846. mclp.refreshOffsetContainerHeight_ = function () {
  6847. //
  6848. }
  6849.  
  6850. mclp.smoothScroll_ = function () {
  6851. //
  6852. }
  6853.  
  6854. mclp.resetSmoothScroll_ = function () {
  6855. //
  6856. }
  6857. console1.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  6858. } else {
  6859. console1.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  6860. }
  6861.  
  6862. if ((_flag0281_ & 0x8) == 0) {
  6863.  
  6864.  
  6865. if (typeof mclp.forEachItem_ === 'function' && !mclp.forEachItem66_ && skipErrorForhandleAddChatItemAction_ && mclp.forEachItem_.length === 1) {
  6866.  
  6867. mclp.forEachItem66_ = mclp.forEachItem_;
  6868. mclp.forEachItem_ = function (a) {
  6869.  
  6870. if ((this._flag0281_ & 0x8) == 0x8) return this.forEachItem66_(a);
  6871.  
  6872. // ƒ (a){this.visibleItems.forEach(a.bind(this,"visibleItems"));this.activeItems_.forEach(a.bind(this,"activeItems_"))}
  6873.  
  6874. try {
  6875.  
  6876. let items801 = false;
  6877. if (typeof a === 'function') {
  6878. const items = this.items;
  6879. if (items instanceof HTMLDivElement) {
  6880. const ev = this.visibleItems;
  6881. const ea = this.activeItems_;
  6882. if (ev && ea && ev.length >= 0 && ea.length >= 0) {
  6883. items801 = items;
  6884. }
  6885. }
  6886. }
  6887.  
  6888. if (items801) {
  6889. items801.__children801__ = 1;
  6890. const res = this.forEachItem66_(a);
  6891. items801.__children801__ = 0;
  6892. return res;
  6893. }
  6894.  
  6895. } catch (e) { }
  6896. return this.forEachItem66_(a);
  6897.  
  6898.  
  6899. // this.visibleItems.forEach((val, idx, arr)=>{
  6900. // a.call(this, 'visibleItems', val, idx, arr);
  6901. // });
  6902.  
  6903. // this.activeItems_.forEach((val, idx, arr)=>{
  6904. // a.call(this, 'activeItems_', val, idx, arr);
  6905. // });
  6906.  
  6907.  
  6908.  
  6909. }
  6910.  
  6911.  
  6912. }
  6913.  
  6914. }
  6915.  
  6916. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  6917.  
  6918. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  6919. mclp.handleAddChatItemAction_ = function (a) {
  6920. try {
  6921. if (a && typeof a === 'object' && !('length' in a)) {
  6922. fixLiveChatItem(a.item, null);
  6923. console.assert(arguments[0] === a);
  6924. }
  6925. } catch (e) { console.warn(e) }
  6926. let res;
  6927. if (skipErrorForhandleAddChatItemAction_) { // YouTube Native Engine Issue
  6928. try {
  6929. res = this.handleAddChatItemAction66_.apply(this, arguments);
  6930. } catch (e) {
  6931. if (e && (e.message || '').includes('.querySelector(')) {
  6932. console.log("skipErrorForhandleAddChatItemAction_", e.message);
  6933. } else {
  6934. throw e;
  6935. }
  6936. }
  6937. } else {
  6938. res = this.handleAddChatItemAction66_.apply(this, arguments);
  6939. }
  6940. return res;
  6941. }
  6942.  
  6943. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console1.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  6944. } else {
  6945.  
  6946. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console1.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  6947. }
  6948.  
  6949.  
  6950. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  6951.  
  6952. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  6953. mclp.handleReplaceChatItemAction_ = function (a) {
  6954. try {
  6955. if (a && typeof a === 'object' && !('length' in a)) {
  6956. fixLiveChatItem(a.replacementItem, null);
  6957. console.assert(arguments[0] === a);
  6958. }
  6959. } catch (e) { console.warn(e) }
  6960. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  6961. }
  6962.  
  6963. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console1.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  6964. } else {
  6965.  
  6966. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console1.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  6967. }
  6968.  
  6969. console1.log("[End]");
  6970. groupEnd();
  6971.  
  6972. }).catch(console.warn);
  6973.  
  6974.  
  6975. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  6976.  
  6977. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  6978.  
  6979. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  6980.  
  6981. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  6982. let v = `${attrValue}`;
  6983. // conside a ticker is 101px width
  6984. // 1% = 1.01px
  6985. // 0.2% = 0.202px
  6986.  
  6987.  
  6988. const ratio1 = (yd.ratio * 100);
  6989. if (ratio1 > -1) { // avoid NaN
  6990.  
  6991. // countdownDurationMs
  6992. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  6993. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  6994. // 150000 - 1% <1% = 1.5s>
  6995. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  6996. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  6997.  
  6998. // 99px * 5% = 4.95px
  6999.  
  7000. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  7001.  
  7002.  
  7003. // 1% Duration
  7004.  
  7005. let ratio2 = ratio1;
  7006.  
  7007. const ydd = yd.data;
  7008. if (ydd) {
  7009.  
  7010. const d1 = ydd.durationSec;
  7011. const d2 = ydd.fullDurationSec;
  7012.  
  7013. // @ step timing [min. 0.2%]
  7014. let numOfSteps = 500;
  7015. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  7016. if (d2 > 400) numOfSteps = 500; // 0.2%
  7017. else if (d2 > 200) numOfSteps = 200; // 0.5%
  7018. else if (d2 > 100) numOfSteps = 100; // 1%
  7019. else if (d2 > 50) numOfSteps = 50; // 2%
  7020. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  7021. else numOfSteps = 20;
  7022. }
  7023. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  7024. if (numOfSteps < 5) numOfSteps = 5;
  7025.  
  7026. const rd = numOfSteps / 100.0;
  7027.  
  7028. ratio2 = Math.round(ratio2 * rd) / rd;
  7029.  
  7030. // ratio2 = Math.round(ratio2 * 5) / 5;
  7031. ratio2 = ratio2.toFixed(1);
  7032. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  7033.  
  7034. if (yd.__style_last__ === v) return;
  7035. yd.__style_last__ = v;
  7036. // do not consider any delay here.
  7037. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  7038.  
  7039. }
  7040. }
  7041.  
  7042. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  7043.  
  7044.  
  7045. } else {
  7046. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  7047. }
  7048.  
  7049. };
  7050.  
  7051.  
  7052. const fpTicker = (renderer) => {
  7053. const cnt = insp(renderer);
  7054. assertor(() => typeof (cnt || 0).is === 'string');
  7055. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  7056. const container = (cnt.$ || 0).container;
  7057. if (container) {
  7058. assertor(() => (container || 0).nodeType === 1);
  7059. assertor(() => typeof container.setAttribute === 'function');
  7060. container.setAttribute = tickerContainerSetAttribute;
  7061. } else {
  7062. console.warn(`"container" does not exist in ${cnt.is}`);
  7063. }
  7064. };
  7065.  
  7066.  
  7067. const tags = [
  7068. "yt-live-chat-ticker-renderer",
  7069. "yt-live-chat-ticker-paid-message-item-renderer",
  7070. "yt-live-chat-ticker-paid-sticker-item-renderer",
  7071. "yt-live-chat-ticker-sponsor-item-renderer"
  7072. ];
  7073.  
  7074. const tagsItemRenderer = [
  7075. "yt-live-chat-ticker-renderer",
  7076. "yt-live-chat-ticker-paid-message-item-renderer",
  7077. "yt-live-chat-ticker-paid-sticker-item-renderer",
  7078. "yt-live-chat-ticker-sponsor-item-renderer"
  7079. ];
  7080.  
  7081. // const wmList = new Set;
  7082.  
  7083.  
  7084. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  7085.  
  7086. mightFirstCheckOnYtInit();
  7087. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  7088. console1.log("[Begin]");
  7089.  
  7090.  
  7091. let tickerAttachmentId = 0;
  7092.  
  7093.  
  7094. const __requestRemoval__ = function (cnt) {
  7095. if (cnt.hostElement && typeof cnt.requestRemoval === 'function') {
  7096. try {
  7097. const id = (cnt.data || 0).id;
  7098. if (!id) cnt.data = { id: 1 };
  7099. } catch (e) { }
  7100. try {
  7101. cnt.requestRemoval();
  7102. return true;
  7103. } catch (e) { }
  7104. }
  7105. return false;
  7106. }
  7107.  
  7108. const widthIORes = new WeakMap();
  7109. const widthIO = new IntersectionObserver((mutations) => {
  7110. for (const mutation of mutations) {
  7111. const elm = mutation.target;
  7112. widthIO.unobserve(elm);
  7113. const {promise, values} =widthIORes.get(elm) || {};
  7114. if(promise && values){
  7115.  
  7116.  
  7117. widthIORes.delete(elm);
  7118. values.width= mutation.boundingClientRect.width;
  7119. promise.resolve(values);
  7120. }
  7121. }
  7122. });
  7123. const widthReq = (elm)=>{
  7124.  
  7125. {
  7126.  
  7127. const {promise, values} =widthIORes.get(elm) || {};
  7128. if(promise) return promise;
  7129. }
  7130.  
  7131. const promise = new PromiseExternal();
  7132. widthIORes.set(elm, {promise, values: {}});
  7133. widthIO.unobserve(elm);
  7134. widthIO.observe(elm);
  7135.  
  7136. return promise;
  7137.  
  7138. }
  7139.  
  7140.  
  7141. const overlayBgMap = new WeakMap();
  7142.  
  7143. const dProto = {
  7144.  
  7145.  
  7146. /**
  7147. *
  7148.  
  7149. f.updateStatsBarAndMaybeShowAnimation = function(a, b, c) {
  7150. var d = this;
  7151. a || c();
  7152. a && this.statsBar && this.username && this.textContent && (this.isMouseOver ? (b(),
  7153. c()) : (a = this.animateShowStats(),
  7154. this.data.animationOrigin && this.data.trackingParams && aB().stateChanged(this.data.trackingParams, {
  7155. animationEventData: {
  7156. origin: this.data.animationOrigin
  7157. }
  7158. }),
  7159. a.finished.then(function() {
  7160. var e;
  7161. setTimeout(function() {
  7162. b();
  7163. c();
  7164. if (!d.isMouseOver) {
  7165. var g, k;
  7166. d.animateHideStats(((g = d.data) == null ? void 0 : g.dynamicStateData.stateSlideDurationMs) || 0, ((k = d.data) == null ? void 0 : k.dynamicStateData.stateUpdateDelayAfterMs) || 0)
  7167. }
  7168. }, ((e = d.data) == null ? void 0 : e.dynamicStateData.stateUpdateDelayBeforeMs) || 0)
  7169. })))
  7170. }
  7171.  
  7172. *
  7173. */
  7174.  
  7175.  
  7176.  
  7177. /**
  7178. *
  7179. *
  7180.  
  7181. f.animateShowStats = function() {
  7182. var a = this.textContent.animate({
  7183. transform: "translateY(-30px)"
  7184. }, {
  7185. duration: this.data.dynamicStateData.stateSlideDurationMs,
  7186. fill: "forwards"
  7187. });
  7188. this.username.animate({
  7189. opacity: 0
  7190. }, {
  7191. duration: 500,
  7192. fill: "forwards"
  7193. });
  7194. this.statsBar.animate({
  7195. opacity: 1
  7196. }, {
  7197. duration: 500,
  7198. fill: "forwards"
  7199. });
  7200. return a
  7201. }
  7202. ;
  7203. f.animateHideStats = function(a, b) {
  7204. this.textContent.animate({
  7205. transform: "translateY(0)"
  7206. }, {
  7207. duration: a,
  7208. fill: "forwards",
  7209. delay: b
  7210. });
  7211. this.username.animate({
  7212. opacity: 1
  7213. }, {
  7214. duration: 300,
  7215. fill: "forwards",
  7216. delay: b
  7217. });
  7218. this.statsBar.animate({
  7219. opacity: 0
  7220. }, {
  7221. duration: 300,
  7222. fill: "forwards",
  7223. delay: b
  7224. })
  7225. }
  7226. *
  7227. */
  7228.  
  7229. updateStatsBarAndMaybeShowAnimationRevised: function (a, b, c) {
  7230. // prevent memory leakage due to d.data was asked in a.finished.then
  7231. try{
  7232. // console.log('updateStatsBarAndMaybeShowAnimation called', this.is)
  7233. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7234. return this.updateStatsBarAndMaybeShowAnimation38.call(this.__proxySelf0__, a, b, c);
  7235. }catch(e){
  7236. console.log('updateStatsBarAndMaybeShowAnimationRevised ERROR');
  7237. console.error(e);
  7238. }
  7239. },
  7240.  
  7241. detachedForMemoryLeakage: function () {
  7242.  
  7243. try{
  7244.  
  7245. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  7246.  
  7247. // this.behaviorActionMap = 0;
  7248. // this.isVisibilityRoot = 0;
  7249.  
  7250.  
  7251. }catch(e){}
  7252.  
  7253. return this.detached582MemoryLeak();
  7254. },
  7255.  
  7256. detachedForTickerInit: function () {
  7257.  
  7258. Promise.resolve(this).then((cnt) => {
  7259. if (cnt.isAttached) return;
  7260. cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false && __requestRemoval__(cnt);
  7261. cnt.rafId > 1 && rafHub.cancel(cnt.rafId);
  7262. }).catch(console.warn);
  7263.  
  7264.  
  7265. const hostElement = (this || 0).hostElement;
  7266. if (USE_ADVANCED_TICKING && (this || 0).__isTickerItem58__ && hostElement instanceof HTMLElement) {
  7267. // otherwise the startCountDown not working
  7268. hostElement.style.removeProperty('--ticker-start-time');
  7269. hostElement.style.removeProperty('--ticker-duration-time');
  7270.  
  7271. if (kRef(qWidthAdjustable) === hostElement) {
  7272.  
  7273. // need to update the first ticker
  7274. const q = document.querySelector('.r6-width-adjustable');
  7275. if (q instanceof HTMLElement && q.classList.contains('r6-width-adjustable-f')) {
  7276. q.classList.remove('r6-width-adjustable-f');
  7277. }
  7278. qWidthAdjustable = mWeakRef(q);
  7279.  
  7280. }
  7281. }
  7282.  
  7283. let r;
  7284. try {
  7285. r = this.detached77();
  7286. } catch (e) {
  7287. console.warn(e);
  7288. }
  7289. this.__ticker_attachmentId__ = 0;
  7290. return r;
  7291. },
  7292.  
  7293. attachedForTickerInit: function () {
  7294. this.__ticker_attachmentId__ = tickerAttachmentId = (tickerAttachmentId & 1073741823) + 1;
  7295.  
  7296. const hostElement = (this || 0).hostElement;
  7297. if (USE_ADVANCED_TICKING && (this || 0).__isTickerItem58__ && hostElement instanceof HTMLElement) {
  7298. const prevElement = kRef(qWidthAdjustable);
  7299. if (prevElement instanceof HTMLElement) {
  7300. prevElement.classList.add('r6-width-adjustable-f');
  7301. }
  7302. if (hostElement.__fgvm573__) {
  7303. hostElement.classList.remove('r6-closing-ticker');
  7304. hostElement.classList.remove('r6-width-adjustable-f');
  7305. } else {
  7306. hostElement.__fgvm573__ = 1;
  7307. hostElement.classList.add('r6-width-adjustable');
  7308. }
  7309. qWidthAdjustable = mWeakRef(hostElement);
  7310. }
  7311.  
  7312.  
  7313. fpTicker(hostElement || this);
  7314. return this.attached77();
  7315.  
  7316. },
  7317.  
  7318.  
  7319.  
  7320. setContainerWidthNoSelfLeakage: function(){
  7321. // prevent memory leakage due ot delay function
  7322. try{
  7323. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7324. return this.setContainerWidth55.call(this.__proxySelf0__);
  7325. }catch(e){
  7326. console.log('setContainerWidthNoSelfLeakage ERROR');
  7327. console.error(e);
  7328. }
  7329.  
  7330. },
  7331.  
  7332. slideDownNoSelfLeakage: function(){
  7333. // prevent memory leakage due ot delay function
  7334. try{
  7335. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7336. return this.slideDown55.call(this.__proxySelf0__);
  7337. }catch(e){
  7338. console.log('slideDownNoSelfLeakage ERROR');
  7339. console.error(e);
  7340. }
  7341.  
  7342. },
  7343.  
  7344. collapseNoSelfLeakage: function(){
  7345. // prevent memory leakage due ot delay function
  7346. try{
  7347. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7348. return this.collapse55.call(this.__proxySelf0__);
  7349. }catch(e){
  7350. console.log('collapseNoSelfLeakage ERROR');
  7351. console.error(e);
  7352. }
  7353. },
  7354.  
  7355. deletedChangedNoSelfLeakage: function(){
  7356. // prevent memory leakage due ot delay function
  7357. try{
  7358. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7359. return this.deletedChanged55.call(this.__proxySelf0__);
  7360. }catch(e){
  7361. console.log('deletedChangedNoSelfLeakage ERROR');
  7362. console.error(e);
  7363. }
  7364.  
  7365. },
  7366.  
  7367.  
  7368.  
  7369.  
  7370. /** @type {()} */
  7371. handlePauseReplayForPlaybackProgressState: function () {
  7372. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  7373.  
  7374. const attachementId = this.__ticker_attachmentId__;
  7375. if(!attachementId) return;
  7376.  
  7377. const jr = mWeakRef(this);
  7378.  
  7379. if (onPlayStateChangePromise) {
  7380.  
  7381. const tid = this._Y7rtu = (this._Y7rtu & 1073741823) + 1;
  7382.  
  7383. onPlayStateChangePromise.then(() => {
  7384. const cnt = kRef(jr) || 0;
  7385. if (attachementId !== cnt.__ticker_attachmentId__) return;
  7386. if (cnt.isAttached) {
  7387. if (tid === cnt._Y7rtu && !onPlayStateChangePromise && typeof cnt.handlePauseReplay === 'function' && cnt.hostElement) cnt.handlePauseReplay.apply(cnt, arguments);
  7388. // this.handlePauseReplay can be undefined if it is memory cleaned
  7389. }
  7390. });
  7391.  
  7392. return;
  7393. }
  7394.  
  7395. if (playerState !== 2) return;
  7396. if (this.isAttached) {
  7397. const tid = this._Y7rtk = (this._Y7rtk & 1073741823) + 1;
  7398. const tc = relayCount;
  7399. foregroundPromiseFn().then(() => {
  7400. const cnt = kRef(jr);
  7401. if (attachementId !== (cnt || 0).__ticker_attachmentId__) return;
  7402. if (cnt.isAttached) {
  7403. if (tid === cnt._Y7rtk && tc === relayCount && playerState === 2 && _playerState === playerState && cnt.hostElement) {
  7404. cnt.handlePauseReplay66();
  7405. }
  7406. }
  7407. })
  7408. }
  7409. },
  7410.  
  7411. /** @type {()} */
  7412. handleResumeReplayForPlaybackProgressState: function () {
  7413. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  7414.  
  7415. const attachementId = this.__ticker_attachmentId__;
  7416. if(!attachementId) return;
  7417.  
  7418. const jr = mWeakRef(this);
  7419. if (onPlayStateChangePromise) {
  7420.  
  7421. const tid = this._Y7rtv = (this._Y7rtv & 1073741823) + 1;
  7422.  
  7423. onPlayStateChangePromise.then(() => {
  7424. const cnt = kRef(jr);
  7425. if(attachementId !== (cnt || 0).__ticker_attachmentId__) return;
  7426. if (tid === cnt._Y7rtv && !onPlayStateChangePromise && typeof cnt.handleResumeReplay === 'function' && cnt.hostElement) cnt.handleResumeReplay.apply(cnt, arguments);
  7427. // this.handleResumeReplay can be undefined if it is memory cleaned
  7428. });
  7429.  
  7430. return;
  7431. }
  7432.  
  7433.  
  7434. if (playerState !== 1) return;
  7435. if (this.isAttached) {
  7436. const tc = relayCount;
  7437.  
  7438. relayPromise = relayPromise || new PromiseExternal();
  7439. relayPromise.then(() => {
  7440. const cnt = kRef(jr);
  7441. if(attachementId !== (cnt || 0).__ticker_attachmentId__) return;
  7442. if (relayCount > tc && playerState === 1 && _playerState === playerState && cnt.hostElement) {
  7443. cnt.handleResumeReplay66();
  7444. }
  7445. });
  7446. }
  7447. },
  7448.  
  7449. /** @type {(a,)} */
  7450. handleReplayProgressForPlaybackProgressState: function (a) {
  7451. if (this.isAttached) {
  7452. const attachementId = this.__ticker_attachmentId__;
  7453. if(!attachementId) return;
  7454. const tid = this._Y7rtk = (this._Y7rtk & 1073741823) + 1;
  7455. const jr = mWeakRef(kRef(this));
  7456. foregroundPromiseFn().then(() => {
  7457. const cnt = kRef(jr);
  7458. if(attachementId !== (cnt || 0).__ticker_attachmentId__) return;
  7459. if (cnt.isAttached) {
  7460. if (tid === cnt._Y7rtk && cnt.hostElement) {
  7461. cnt.handleReplayProgress66(a);
  7462. }
  7463. }
  7464. })
  7465. }
  7466. }
  7467.  
  7468.  
  7469. }
  7470.  
  7471.  
  7472. let tagI = 0;
  7473. for (const tag of tagsItemRenderer) { // ##tag##
  7474.  
  7475. tagI++;
  7476.  
  7477. const dummy = document.createElement(tag);
  7478.  
  7479. const cProto = getProto(dummy);
  7480. if (!cProto || !cProto.attached) {
  7481. console1.warn(`proto.attached for ${tag} is unavailable.`);
  7482. continue;
  7483. }
  7484.  
  7485. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  7486. cProto.detached582MemoryLeak = cProto.detached;
  7487. cProto.detached = dProto.detachedForMemoryLeakage;
  7488. }
  7489.  
  7490. cProto.detached77 = cProto.detached;
  7491. cProto.detached = dProto.detachedForTickerInit;
  7492.  
  7493. cProto.attached77 = cProto.attached;
  7494.  
  7495. cProto.attached = dProto.attachedForTickerInit;
  7496.  
  7497. let flgLeakageFixApplied = 0;
  7498.  
  7499. if (FIX_MEMORY_LEAKAGE_TICKER_STATSBAR && typeof cProto.updateStatsBarAndMaybeShowAnimation === 'function' && !cProto.updateStatsBarAndMaybeShowAnimation38 && cProto.updateStatsBarAndMaybeShowAnimation.length === 3) {
  7500.  
  7501. cProto.updateStatsBarAndMaybeShowAnimation38 = cProto.updateStatsBarAndMaybeShowAnimation;
  7502. cProto.updateStatsBarAndMaybeShowAnimation = dProto.updateStatsBarAndMaybeShowAnimationRevised;
  7503.  
  7504. flgLeakageFixApplied |= 2;
  7505. } else {
  7506. // the function is only in yt-live-chat-ticker-paid-message-item-renderer
  7507. }
  7508.  
  7509.  
  7510. // ------------- withTimerFn_ -------------
  7511.  
  7512. let withTimerFn_ = 0;
  7513. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  7514.  
  7515. // console.log('startCountdown', typeof cProto.startCountdown)
  7516. // console.log('updateTimeout', typeof cProto.updateTimeout)
  7517. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  7518.  
  7519. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  7520. const isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  7521. if (!isTimingFunctionHackable) console1.log('isTimingFunctionHackable = false');
  7522. withTimerFn_ = isTimingFunctionHackable ? 2 : 1;
  7523. } else {
  7524. let flag = 0;
  7525. if (typeof cProto.startCountdown === 'function') flag |= 1;
  7526. if (typeof cProto.updateTimeout === 'function') flag |= 2;
  7527. if (typeof cProto.isAnimationPausedChanged === 'function') flag |= 4;
  7528.  
  7529. console1.log(`Skip Timing Function Modification[#${tagI}]: ${flag} / ${1 + 2 + 4}`, ` ${tag}`);
  7530. // console.log(Object.getOwnPropertyNames(cProto))
  7531. // continue;
  7532. }
  7533.  
  7534. // ------------- withTimerFn_ -------------
  7535.  
  7536. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7537.  
  7538. let urt = 0;
  7539.  
  7540. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  7541.  
  7542.  
  7543. /**
  7544. *
  7545. f.handlePauseReplay = function() {
  7546. this.isAnimationPaused = !0;
  7547. this.detlaSincePausedSecs = 0
  7548. }
  7549. */
  7550.  
  7551. /**
  7552. *
  7553.  
  7554. f.handlePauseReplay = function() {
  7555. this.isReplayPaused = !0
  7556. }
  7557. *
  7558. */
  7559.  
  7560. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  7561. const fi = fnIntegrity(cProto.handlePauseReplay);
  7562. urt++;
  7563. if (fi === '0.8.2' || fi === '0.12.4') {
  7564. } else {
  7565. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  7566. }
  7567. } else {
  7568. if (withTimerFn_ > 0) console1.log('Error for setting cProto.handlePauseReplay', tag)
  7569. }
  7570.  
  7571. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handleResumeReplay.length === 0) {
  7572. urt++;
  7573. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  7574. } else {
  7575. if (withTimerFn_ > 0) console1.log('Error for setting cProto.handleResumeReplay', tag)
  7576. }
  7577.  
  7578. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  7579. urt++;
  7580. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  7581. } else {
  7582. if (withTimerFn_ > 0) console1.log('Error for setting cProto.handleReplayProgress', tag)
  7583. }
  7584.  
  7585.  
  7586.  
  7587. }
  7588.  
  7589. 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);
  7590. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  7591.  
  7592. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  7593.  
  7594. cProto._Y7rtk = 0;
  7595. cProto._Y7rtu = 0;
  7596. cProto._Y7rtv = 0;
  7597.  
  7598. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  7599. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  7600.  
  7601. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  7602. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  7603.  
  7604. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  7605. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  7606.  
  7607. }
  7608.  
  7609. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7610.  
  7611. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7612.  
  7613. if (FIX_MEMORY_LEAKAGE_TICKER_TIMER) {
  7614. if (!USE_ADVANCED_TICKING && typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth55 && cProto.setContainerWidth.length === 0) {
  7615. cProto.setContainerWidth55 = cProto.setContainerWidth;
  7616. cProto.setContainerWidth = dProto.setContainerWidthNoSelfLeakage;
  7617. flgLeakageFixApplied |= 4;
  7618. }
  7619. if (!USE_ADVANCED_TICKING && typeof cProto.slideDown === 'function' && !cProto.slideDown55 && cProto.slideDown.length === 0) {
  7620. cProto.slideDown55 = cProto.slideDown;
  7621. cProto.slideDown = dProto.slideDownNoSelfLeakage;
  7622. flgLeakageFixApplied |= 8;
  7623. }
  7624. if (!USE_ADVANCED_TICKING && typeof cProto.collapse === 'function' && !cProto.collapse55 && cProto.collapse.length === 0) {
  7625. cProto.collapse55 = cProto.collapse;
  7626. cProto.collapse = dProto.collapseNoSelfLeakage;
  7627. flgLeakageFixApplied |= 16;
  7628. }
  7629. if (typeof cProto.deletedChanged === 'function' && !cProto.deletedChanged55 && cProto.deletedChanged.length === 0) {
  7630.  
  7631. cProto.deletedChanged55 = cProto.deletedChanged;
  7632. cProto.deletedChanged = dProto.deletedChangedNoSelfLeakage;
  7633. flgLeakageFixApplied |= 32;
  7634. }
  7635.  
  7636. }
  7637.  
  7638. const flgTotal = USE_ADVANCED_TICKING ? 1 + 2 + 32 : 1 + 2 + 4 + 8 + 16 + 32;
  7639.  
  7640. console1.log(`FIX_MEMORY_LEAKAGE_TICKER_[#${tagI}]: ${flgLeakageFixApplied} / ${flgTotal}`, cProto.is);
  7641.  
  7642. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7643.  
  7644.  
  7645.  
  7646. const canDoAdvancedTicking = 1 &&
  7647. ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION &&
  7648. typeof cProto.startCountdown === 'function' && !cProto.startCountdown49 && cProto.startCountdown.length === 2 &&
  7649. typeof cProto.updateTimeout === 'function' && !cProto.updateTimeout49 && cProto.updateTimeout.length === 1 &&
  7650. typeof cProto.isAnimationPausedChanged === 'function' && !cProto.isAnimationPausedChanged49 && cProto.isAnimationPausedChanged.length === 2 &&
  7651. typeof cProto.setContainerWidth === 'function' && cProto.setContainerWidth.length === 0 &&
  7652. typeof cProto.requestRemoval === 'function' && !cProto.requestRemoval49 && cProto.requestRemoval.length === 0
  7653. CSS.supports("left","clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)");
  7654.  
  7655.  
  7656.  
  7657. if (USE_ADVANCED_TICKING && canDoAdvancedTicking) {
  7658. // startResistanceUpdater();
  7659. // live replay video -> 48117005 -> 48117006 keep fire. ->48117007 0 -> 48117007 {...}
  7660. // live stream video -> 48117007 0 -> 48117007 YES
  7661.  
  7662. document.documentElement.setAttribute('r6-advanced-ticking', '');
  7663. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::START`)
  7664.  
  7665. const wio2 = dProto.wio2 || (dProto.wio2 = new IntersectionObserver((mutations) => {
  7666.  
  7667. for (const mutation of mutations) {
  7668. if (mutation.isIntersecting) {
  7669.  
  7670. const marker = mutation.target;
  7671. let endId = marker.id
  7672. if (!endId) continue;
  7673. let tid = endId.substring(0, endId.length - 2);
  7674. if (!tid) continue;
  7675. // let bId = `${tid}-b`;
  7676. const bgElm = document.querySelector(`#${tid}-b`);
  7677. if (!bgElm) continue;
  7678. const overlay = bgElm;
  7679.  
  7680. wio2.unobserve(marker);
  7681. marker.remove();
  7682. let p = overlay || 0;
  7683. let cn = 4;
  7684. while ((p = p.parentElement) instanceof HTMLElement) {
  7685. if (p instanceof HTMLElement) {
  7686. const cnt = insp(p);
  7687. if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1) {
  7688.  
  7689. cnt.__advancedTicking038__ = 2;
  7690.  
  7691. let deletionMode = false;
  7692. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7693. if (timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__timestampActionRequest__ > 0) {
  7694.  
  7695. // time choose - 0.2s for transition (slideDown sliding-down)
  7696. // 60hz = 17ms
  7697. // choose 0.28s
  7698. const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  7699. // check whether the targetFutureTime is already the past
  7700. if (targetFutureTime + 280 < Date.now()) {
  7701. // just dispose
  7702. deletionMode = true;
  7703. }
  7704. } else if (__LCRInjection__ && !timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__progressAt__ > 0) {
  7705.  
  7706. const targetFutureTime = (cntData.__progressAt__ + cntData.durationSec);
  7707. // check whether the targetFutureTime is already the past
  7708. if (targetFutureTime + 0.28 < playerProgressChangedArg1) {
  7709. // just dispose
  7710. deletionMode = true;
  7711. }
  7712.  
  7713.  
  7714. }
  7715.  
  7716.  
  7717. if (deletionMode) {
  7718. __requestRemoval__(cnt);
  7719. } else {
  7720.  
  7721. const w = cnt.hostElement.style.width;
  7722. if (w === "auto" || w === "") cnt.setContainerWidth();
  7723. cnt.slideDown();
  7724. }
  7725.  
  7726. break;
  7727. }
  7728. }
  7729. cn--;
  7730. if (!cn) {
  7731. console.log('cnt not found for ticker-bg-overlay');
  7732. break;
  7733. }
  7734. }
  7735.  
  7736.  
  7737. }
  7738. }
  7739.  
  7740. // console.log(mutations);
  7741. }, {
  7742.  
  7743. rootMargin: '0px',
  7744. threshold: [1]
  7745.  
  7746. }));
  7747.  
  7748.  
  7749.  
  7750. const u37fn = dProto.u37fn || (dProto.u37fn = function (cnt) {
  7751.  
  7752. if(cnt.__dataEnabled === false || cnt.__dataInvalid === true) return;
  7753.  
  7754. if (!__LCRInjection__) {
  7755. console.error('[yt-chat] USE_ADVANCED_TICKING fails because of no __LCRInjection__');
  7756. }
  7757.  
  7758. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7759. if (!cntData) return;
  7760. const cntElement = cnt.hostElement;
  7761. if (!(cntElement instanceof HTMLElement)) return;
  7762.  
  7763. const duration = (cntData.fullDurationSec || cntData.durationSec || 0);
  7764.  
  7765. let ct;
  7766.  
  7767. if (__LCRInjection__ && cntData && duration > 0 && !('__progressAt__' in cntData)) {
  7768. ct = Date.now();
  7769. cntData.__liveTimestamp__ = (cntData.__timestampActionRequest__ || ct) / 1000 - timeOriginDT / 1000;
  7770. timestampUnderLiveMode = true;
  7771. } else if (__LCRInjection__ && cntData && duration > 0 && cntData.__progressAt__ > 0) {
  7772. timestampUnderLiveMode = false;
  7773. }
  7774. // console.log(48117007, cntData)
  7775.  
  7776. let tk = cntData.__progressAt__ || cntData.__liveTimestamp__;
  7777.  
  7778. if (!tk) {
  7779. console.log('time property is not found');
  7780. return;
  7781. }
  7782.  
  7783.  
  7784.  
  7785. const liveOffsetMs = ct > 0 && cntData.__timestampActionRequest__ > 0 ? ct - cntData.__timestampActionRequest__ : 0;
  7786.  
  7787. // console.log(1237, liveOffsetMs, cntData.durationSec)
  7788.  
  7789. if (liveOffsetMs > 0) {
  7790. cntData.durationSec -= Math.floor(liveOffsetMs / 1000);
  7791. if (cntData.durationSec < 0) cntData.durationSec = 0;
  7792. // console.log(1238, liveOffsetMs, cntData.durationSec)
  7793. if (!cntData.durationSec) {
  7794. try {
  7795. cnt.requestRemoval();
  7796. } catch (e) { }
  7797. return;
  7798. }
  7799. }
  7800.  
  7801.  
  7802. let offset = cntData.fullDurationSec - cntData.durationSec; // consider this is live replay video, offset can be > 0
  7803. if (offset > 0) tk -= offset;
  7804. // in livestreaming. tk can be negative as we use performance.timeOrigin for t=0s time frame
  7805.  
  7806.  
  7807.  
  7808. const existingOverlaySelector = `ticker-bg-overlay[ticker-id="${cnt.__ticker_attachmentId__}"]`;
  7809.  
  7810. const q = kRef(overlayBgMap.get(cnt));
  7811.  
  7812. let r = valAssign(cntElement, '--ticker-start-time', tk);
  7813.  
  7814. if ((r || !q || q.isConnected === false) && duration > 0) {
  7815.  
  7816. // t0 ...... 1 ... fullDurationSec
  7817. // tk ...... k ... fullDurationSec-durationSec
  7818. // t0-fullDurationSec ...... 0 ... 0
  7819.  
  7820. // now - (fullDurationSec-durationSec)
  7821.  
  7822.  
  7823. // update dntElementWeak
  7824. const dnt = cnt.parentComponent;
  7825. const dntElement = dnt ? dnt.hostElement || dnt : 0;
  7826. if (dntElement) {
  7827. dntElementWeak = mWeakRef(dntElement);
  7828. resistanceUpdateBusy = false;
  7829. if (!startResistanceUpdaterStarted) startResistanceUpdater();
  7830. else updateTickerCurrentTime();
  7831. }
  7832.  
  7833.  
  7834. // create overlay if needed
  7835. if (!cntElement.querySelector(existingOverlaySelector)) {
  7836.  
  7837. // remove if any
  7838. const oldElement = cntElement.querySelector('ticker-bg-overlay');
  7839. if (oldElement) oldElement.remove();
  7840.  
  7841. // use advancedTicking, ticker enabled
  7842. cnt.__advancedTicking038__ = 1;
  7843.  
  7844. const em = q || document.createElement('ticker-bg-overlay');
  7845.  
  7846. overlayBgMap.set(cnt, mWeakRef(em));
  7847. // const ey = document.createElement('ticker-bg-overlay-end');
  7848. const wy = document.createElement('ticker-bg-overlay-end2');
  7849.  
  7850. const cr1 = cnt.colorFromDecimal(cntData.startBackgroundColor);
  7851. const cr2 = cnt.colorFromDecimal(cntData.endBackgroundColor);
  7852.  
  7853. const container = cnt.$.container;
  7854.  
  7855. em.setAttribute('ticker-id', `${cnt.__ticker_attachmentId__}`);
  7856.  
  7857. const tid = `ticker-${cnt.__ticker_attachmentId__}-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  7858.  
  7859. em.id = `${tid}-b`;
  7860. em.style.background = `linear-gradient(90deg, ${cr1},${cr1} 50%,${cr2} 50%,${cr2})`;
  7861.  
  7862. if (!(container instanceof HTMLElement)) {
  7863. // em.insertBefore(ey, em.firstChild);
  7864. insertBeforeNaFn(cntElement, em, cntElement.firstChild); // cntElement.insertBefore(em, cntElement.firstChild);
  7865. cntElement.style.borderRadius = '16px';
  7866. container.style.borderRadius = 'initial';
  7867. } else {
  7868. // em.insertBefore(ey, em.firstChild);
  7869. insertBeforeNaFn(container, em, container.firstChild); // container.insertBefore(em, container.firstChild);
  7870. }
  7871.  
  7872. // em.style.left = '-50%';
  7873. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  7874.  
  7875. if (container instanceof HTMLElement) {
  7876.  
  7877. container.style.background = 'transparent';
  7878. container.style.backgroundColor = 'transparent';
  7879. // container.style.zIndex = '1';
  7880. }
  7881. // em.style.zIndex = '-1';
  7882. valAssign(cntElement, '--ticker-duration-time', duration)
  7883.  
  7884. valAssign(wy, '--ticker-start-time', tk);
  7885. valAssign(wy, '--ticker-duration-time', duration);
  7886. wy.id = `${tid}-e`;
  7887.  
  7888. appendChildNaFn(dntElement, wy);
  7889.  
  7890. // if (wio instanceof IntersectionObserver) {
  7891. // wio.observe(ey);
  7892. // }
  7893.  
  7894. if (wio2 instanceof IntersectionObserver) {
  7895. wio2.observe(wy);
  7896. }
  7897.  
  7898. }
  7899. }
  7900. });
  7901.  
  7902. const timeFn = (cnt) => {
  7903.  
  7904. if (!cnt) return;
  7905. if (!cnt.hostElement) return;
  7906.  
  7907. const attachementId = cnt.__ticker_attachmentId__;
  7908. if (!attachementId) return;
  7909.  
  7910. Promise.resolve(cnt).then(u37fn);
  7911.  
  7912. }
  7913. cProto.__isTickerItem58__ = 1;
  7914. cProto.startCountdown = dProto.startCountdownAdv || (dProto.startCountdownAdv = function (a, b) {
  7915.  
  7916. timeFn(kRef(this));
  7917.  
  7918.  
  7919. });
  7920.  
  7921. cProto.updateTimeout = dProto.updateTimeoutAdv || (dProto.updateTimeoutAdv = function (a) {
  7922.  
  7923.  
  7924.  
  7925. });
  7926.  
  7927. cProto.isAnimationPausedChanged = dProto.isAnimationPausedChangedAdv || (dProto.isAnimationPausedChangedAdv = function (a, b) {
  7928.  
  7929.  
  7930.  
  7931. });
  7932.  
  7933.  
  7934. if (typeof cProto.slideDown === 'function' && !cProto.slideDown43 && cProto.slideDown.length === 0) {
  7935.  
  7936. cProto.slideDown43 = cProto.slideDown;
  7937. cProto.slideDown = dProto.slideDownAdv || (dProto.slideDownAdv = async function () {
  7938.  
  7939. // console.log('calling slideDown', Date.now())
  7940. if (this.__advancedTicking038__) {
  7941.  
  7942. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  7943.  
  7944.  
  7945. const hostElement = this.hostElement;
  7946. const container = this.$.container;
  7947.  
  7948. const parentComponentCnt = insp(this.parentComponent);
  7949. const parentComponentElm = parentComponentCnt? parentComponentCnt.hostElement : null;
  7950.  
  7951. if (hostElement instanceof HTMLElement && container instanceof HTMLElement && parentComponentElm instanceof HTMLElement) {
  7952. // const prevTransitionClosingElm = kRef(prevTransitionClosing);
  7953. // if (prevTransitionClosingElm !== hostElement) {
  7954. // prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  7955. // prevTransitionClosing = mWeakRef(hostElement);
  7956. // }
  7957. // if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  7958. hostElement.classList.add('r6-closing-ticker');
  7959.  
  7960. if (!transitionEndHooks.has(parentComponentElm)) {
  7961. transitionEndHooks.add(parentComponentElm);
  7962. document.addEventListener('transitionend', transitionEndAfterFn, passiveCapture);
  7963. }
  7964.  
  7965. const pr = new PromiseExternal();
  7966. transitionEndAfterFnSimple.set(hostElement, pr);
  7967. transitionEndAfterFnSimple.set(container, pr);
  7968. transitionEndAfterFnSimpleEnable++;
  7969. hostElement.classList.add("sliding-down");
  7970. await pr.then();
  7971. transitionEndAfterFnSimpleEnable--;
  7972. transitionEndAfterFnSimple.delete(hostElement);
  7973. transitionEndAfterFnSimple.delete(container);
  7974. if (this && this.hostElement instanceof HTMLElement) {
  7975.  
  7976. this.collapse();
  7977. }
  7978. return;
  7979. }
  7980. }
  7981. this.slideDown43();
  7982.  
  7983. });
  7984.  
  7985.  
  7986. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::slideDown - OK`)
  7987. } else {
  7988.  
  7989. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::slideDown - NG`)
  7990. }
  7991.  
  7992.  
  7993. if (typeof cProto.collapse === 'function' && !cProto.collapse43 && cProto.collapse.length === 0) {
  7994. cProto.collapse43 = cProto.collapse;
  7995. cProto.collapse = dProto.collapseAdv || (dProto.collapseAdv = async function () {
  7996.  
  7997.  
  7998. if (this.__advancedTicking038__) {
  7999.  
  8000.  
  8001. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  8002.  
  8003.  
  8004. const hostElement = this.hostElement;
  8005. const container = this.$.container;
  8006.  
  8007. const parentComponentCnt = insp(this.parentComponent);
  8008. const parentComponentElm = parentComponentCnt ? parentComponentCnt.hostElement : null;
  8009.  
  8010. if (hostElement instanceof HTMLElement && container instanceof HTMLElement && parentComponentElm instanceof HTMLElement) {
  8011. // const prevTransitionClosingElm = kRef(prevTransitionClosing);
  8012. // if (prevTransitionClosingElm !== hostElement) {
  8013. // prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  8014. // prevTransitionClosing = mWeakRef(hostElement);
  8015. // }
  8016. // if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  8017. hostElement.classList.add('r6-closing-ticker');
  8018.  
  8019. if (!transitionEndHooks.has(parentComponentElm)) {
  8020. transitionEndHooks.add(parentComponentElm);
  8021. document.addEventListener('transitionend', transitionEndAfterFn, passiveCapture);
  8022. }
  8023.  
  8024. const pr = new PromiseExternal();
  8025. transitionEndAfterFnSimple.set(hostElement, pr);
  8026. transitionEndAfterFnSimple.set(container, pr);
  8027. transitionEndAfterFnSimpleEnable++;
  8028. hostElement.classList.add("collapsing");
  8029. hostElement.style.width = "0";
  8030. await pr.then();
  8031. transitionEndAfterFnSimpleEnable--;
  8032. transitionEndAfterFnSimple.delete(hostElement);
  8033. transitionEndAfterFnSimple.delete(container);
  8034. if (this && this.hostElement instanceof HTMLElement) {
  8035.  
  8036. this.requestRemoval();
  8037. }
  8038.  
  8039. return;
  8040. }
  8041.  
  8042.  
  8043. }
  8044. this.collapse43();
  8045.  
  8046.  
  8047. });
  8048.  
  8049. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::collapse - OK`)
  8050. } else {
  8051.  
  8052. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::collapse - NG`)
  8053. }
  8054.  
  8055.  
  8056.  
  8057. if (typeof cProto.requestRemoval === 'function' && !cProto.requestRemoval49 && cProto.requestRemoval.length === 0) {
  8058. const removalList = [];
  8059. let removalRes = false;
  8060. const removalFn = () => {
  8061. if (removalList.length === 0) return;
  8062. for (const cnt of removalList) {
  8063. let r;
  8064. try {
  8065. r = cnt?.requestRemoval49();
  8066. } catch (e) { }
  8067. if (r !== undefined && removalRes === false) {
  8068. removalRes = true;
  8069. console.log(`[yt-chat-ticker] requestRemoval49 returns ${r}`);
  8070. }
  8071. }
  8072. removalList.length = 0;
  8073. };
  8074. cProto.requestRemoval49 = cProto.requestRemoval;
  8075. cProto.requestRemoval = dProto.requestRemovalAdv || (dProto.requestRemovalAdv = function () {
  8076. const hostElement = this.hostElement;
  8077. if (this.__advancedTicking038__) {
  8078. try {
  8079. const overlayBg = hostElement.querySelector('ticker-bg-overlay[id]');
  8080. if (overlayBg) {
  8081. const overlayBgId = overlayBg.id;
  8082. const tid = overlayBgId ? overlayBgId.substring(0, overlayBgId.length - 2) : '';
  8083. const endElm = tid ? document.querySelector(`#${tid}-e`) : null;
  8084. if (endElm) {
  8085. wio2.unobserve(endElm);
  8086. endElm.remove();
  8087. }
  8088. }
  8089. } catch (e) { }
  8090. this.__advancedTicking038__ = 2;
  8091. // console.log('requestRemoval!!')
  8092. if (hostElement instanceof HTMLElement) {
  8093. // otherwise the startCountDown not working
  8094. hostElement.style.removeProperty('--ticker-start-time');
  8095. hostElement.style.removeProperty('--ticker-duration-time');
  8096. }
  8097. if (REUSE_TICKER) {
  8098. const cntData = this.data;
  8099. if (hostElement instanceof HTMLElement && cntData.id && cntData.fullDurationSec && !hostElement.hasAttribute('__reuseid__')) {
  8100. hostElement.setAttribute('__reuseid__', reuseId);
  8101. hostElement.setAttribute('__nogc__', ''); // provided to leakage detection script
  8102. // this.__markReuse13__ = true;
  8103. reuseStore.set(`<${this.is}>${cntData.id}:${cntData.fullDurationSec}`, mWeakRef(this));
  8104. }
  8105. }
  8106. }
  8107. if (hostElement instanceof HTMLElement) {
  8108. // try {
  8109. // // hostElement.remove();
  8110.  
  8111. // if (!hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.add('ticker-no-transition-time');
  8112. // } catch (e) { }
  8113.  
  8114. try {
  8115.  
  8116. hostElement.classList.remove('r6-closing-ticker');
  8117. hostElement.classList.remove('r6-width-adjustable-f');
  8118. } catch (e) { }
  8119.  
  8120. // if(ADVANCED_TICKING_MEMORY_CLEAN_FOR_REMOVAL){
  8121. // const wr = mWeakRef(hostElement);
  8122. // const wf = ()=>{
  8123. // const element = kRef(wr);
  8124. // if(!element) {
  8125. // console.log('[yt-chat-removalrequest] element was memory cleaned.');
  8126. // return;
  8127. // }
  8128.  
  8129. // setTimeout(wf, 8000);
  8130. // if(element.isConnected){
  8131. // console.log('[yt-chat-removalrequest] element is still connected to DOM Tree.');
  8132. // return;
  8133. // }
  8134.  
  8135. // const cnt = insp(element)
  8136. // if(typeof cnt.requestRemoval !== 'function'){
  8137.  
  8138. // console.log('[yt-chat-removalrequest] element is not connected to cnt.');
  8139. // return;
  8140. // }
  8141. // console.log('[yt-chat-removalrequest] element is not GC.');
  8142. // try{
  8143. // cnt.data = null;
  8144. // }catch(e){}
  8145.  
  8146. // Object.setPrototypeOf(cnt, Object.prototype);
  8147. // for(const k of Object.getOwnPropertyNames(cnt)){
  8148. // try{
  8149. // cnt[k] = null;
  8150. // }catch(e){}
  8151.  
  8152. // try{
  8153. // delete cnt[k];
  8154. // }catch(e){}
  8155. // }
  8156.  
  8157.  
  8158. // for(const k of Object.getOwnPropertySymbols(cnt)){
  8159. // try{
  8160. // cnt[k] = null;
  8161. // }catch(e){}
  8162.  
  8163. // try{
  8164. // delete cnt[k];
  8165. // }catch(e){}
  8166. // }
  8167.  
  8168. // }
  8169. // setTimeout(wf, 8000);
  8170. // }
  8171.  
  8172. removalList.push(this);
  8173. timelineResolve().then(removalFn);
  8174. }
  8175. });
  8176.  
  8177.  
  8178. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::requestRemoval - OK`)
  8179. } else {
  8180.  
  8181. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::requestRemoval - NG`)
  8182. }
  8183.  
  8184.  
  8185. if (typeof cProto.computeContainerStyle === 'function' && !cProto.computeContainerStyle49 && cProto.computeContainerStyle.length === 2) {
  8186. cProto.computeContainerStyle49 = cProto.computeContainerStyle;
  8187. cProto.computeContainerStyle = dProto.computeContainerStyleAdv || (dProto.computeContainerStyleAdv = function (a, b) {
  8188. if (this.__advancedTicking038__) {
  8189. return "";
  8190. }
  8191. return this.computeContainerStyle49(a, b);
  8192. });
  8193.  
  8194.  
  8195. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::computeContainerStyle - OK`)
  8196. } else {
  8197.  
  8198. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::computeContainerStyle - NG`)
  8199. }
  8200.  
  8201.  
  8202.  
  8203. if (typeof cProto.setRevampContainerWidth === 'function' && !cProto.setRevampContainerWidth41 && cProto.setRevampContainerWidth.length === 0) {
  8204. cProto.setRevampContainerWidth41 = cProto.setRevampContainerWidth;
  8205. cProto.setRevampContainerWidth = dProto.setRevampContainerWidthAdv || (dProto.setRevampContainerWidthAdv = async function () {
  8206.  
  8207. // not sure the reason for auto instead of pixel.
  8208. // this is a new function in Dec 2024, but not mainly adopted in the coding yet
  8209.  
  8210. /*
  8211.  
  8212.  
  8213. var a = this;
  8214. (R(this.hostElement).querySelector("#container").clientWidth || 0) === 0 ? (this.hostElement.style.overflow = "visible",
  8215. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  8216. this.ytLiveChatTickerItemBehavior.shouldAnimateIn ? (this.hostElement.style.width = "0",
  8217. Zu(function() {
  8218. a.hostElement.style.width = "auto"
  8219. }, 1)) : this.hostElement.style.width = "auto")
  8220.  
  8221. */
  8222.  
  8223.  
  8224.  
  8225.  
  8226. const hostElement = (this || 0).hostElement;
  8227. const container = this.$.container;
  8228.  
  8229.  
  8230. let qw = null;
  8231.  
  8232. {
  8233.  
  8234.  
  8235. let maxC = 4;
  8236.  
  8237. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  8238.  
  8239. const ed = `${hostElement.id}`
  8240. if (!p || !p.startsWith(`${ed}::`)) {
  8241.  
  8242. const w = hostElement.style.width;
  8243. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  8244.  
  8245. const res = await widthReq(container);
  8246.  
  8247. if (res.width < 1 || !Number.isFinite(res.width)) {
  8248. // just skip due to iron-page hidden
  8249. return;
  8250. }
  8251.  
  8252. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  8253.  
  8254. } else {
  8255. qw = p.split('::');
  8256. break;
  8257. }
  8258.  
  8259. }
  8260.  
  8261. }
  8262.  
  8263. if (!qw) {
  8264.  
  8265. console.log('container width failure');
  8266. this.setRevampContainerWidth41();
  8267. return; // failure
  8268. }
  8269.  
  8270.  
  8271. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  8272. if (shouldAnimateIn) {
  8273.  
  8274.  
  8275.  
  8276. const w = hostElement.style.width;
  8277. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  8278. // hostElement.classList.remove('ticker-no-transition-time');
  8279. await widthReq(container);
  8280.  
  8281. hostElement.style.width = `${qw[1]}px`;
  8282. return;
  8283.  
  8284.  
  8285. } else {
  8286. hostElement.style.width = `${qw[1]}px`;
  8287. }
  8288.  
  8289.  
  8290. // const container = this.$.container;
  8291. // if(hostElement instanceof HTMLElement && hostElement.style.width) hostElement.style.width = '';
  8292. });
  8293.  
  8294.  
  8295. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::setRevampContainerWidth - OK`)
  8296. } else {
  8297.  
  8298. DEBUG_skipLog001 || console1.log(`USE_ADVANCED_TICKING[#${tagI}]::setRevampContainerWidth - NG (acceptable)`)
  8299. }
  8300.  
  8301.  
  8302. if (typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth41 && cProto.setContainerWidth.length === 0) {
  8303. cProto.setContainerWidth41 = cProto.setContainerWidth;
  8304. cProto.setContainerWidth = dProto.setContainerWidthAdv || (dProto.setContainerWidthAdv = async function () {
  8305.  
  8306.  
  8307.  
  8308. /*
  8309.  
  8310.  
  8311. var a = this
  8312. , b = R(this.hostElement).querySelector("#container").clientWidth || 0;
  8313. b === 0 ? (this.hostElement.style.overflow = "visible",
  8314. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  8315. this.shouldAnimateIn ? (this.hostElement.style.width = "0",
  8316. Zu(function() {
  8317. a.hostElement.style.width = b + "px"
  8318. }, 1)) : this.hostElement.style.width = b + "px")
  8319.  
  8320. */
  8321.  
  8322. const hostElement = (this || 0).hostElement;
  8323. const container = this.$.container;
  8324.  
  8325.  
  8326. let qw = null;
  8327.  
  8328. {
  8329.  
  8330.  
  8331. let maxC = 4;
  8332.  
  8333. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  8334.  
  8335. const ed = `${hostElement.id}`
  8336. if (!p || !p.startsWith(`${ed}::`)) {
  8337.  
  8338. const w = hostElement.style.width;
  8339. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  8340.  
  8341. const res = await widthReq(container);
  8342.  
  8343. if (res.width < 1 || !Number.isFinite(res.width)) {
  8344. // just skip due to iron-page hidden
  8345. return;
  8346. }
  8347.  
  8348. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  8349.  
  8350. } else {
  8351. qw = p.split('::');
  8352. break;
  8353. }
  8354.  
  8355. }
  8356.  
  8357. }
  8358.  
  8359. if (!qw) {
  8360.  
  8361. console.log('container width failure');
  8362. this.setContainerWidth41();
  8363. return; // failure
  8364. }
  8365.  
  8366.  
  8367. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  8368. if (shouldAnimateIn) {
  8369.  
  8370.  
  8371.  
  8372. const w = hostElement.style.width;
  8373. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  8374. // hostElement.classList.remove('ticker-no-transition-time');
  8375. await widthReq(container);
  8376.  
  8377. hostElement.style.width = `${qw[1]}px`;
  8378. return;
  8379.  
  8380.  
  8381. } else {
  8382. hostElement.style.width = `${qw[1]}px`;
  8383. }
  8384.  
  8385.  
  8386. });
  8387.  
  8388.  
  8389.  
  8390. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::setContainerWidth - OK`)
  8391. } else {
  8392.  
  8393.  
  8394. console1.log(`USE_ADVANCED_TICKING[#${tagI}]::setContainerWidth - NG`)
  8395. }
  8396.  
  8397.  
  8398.  
  8399.  
  8400. } else if (USE_ADVANCED_TICKING) {
  8401. console1.log(`USE_ADVANCED_TICKING[#${tagI}] is not injected.`);
  8402. }
  8403.  
  8404.  
  8405.  
  8406. }
  8407.  
  8408. const selector = tags.join(', ');
  8409. const elements = document.querySelectorAll(selector);
  8410. if (elements.length >= 1) {
  8411. for (const elm of elements) {
  8412. if (insp(elm).isAttached === true) {
  8413. fpTicker(elm);
  8414. }
  8415. }
  8416. }
  8417.  
  8418. console1.log("[End]");
  8419. groupEnd();
  8420.  
  8421.  
  8422. }).catch(console.warn);
  8423.  
  8424. if(FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth){
  8425.  
  8426. /**
  8427. *
  8428. *
  8429. *
  8430. *
  8431. cT.prototype.dataChanged = function() {
  8432. var a = this;
  8433. this.data && (Q(this.hostElement).querySelector("#content").style.color = this.ytLiveChatTickerItemBehavior.colorFromDecimal(this.data.detailTextColor),
  8434. this.hostElement.ariaLabel = this.computeAriaLabel(this.data),
  8435. this.ytLiveChatTickerItemBehavior.startCountdown(this.data.durationSec, this.data.fullDurationSec),
  8436. qw(function() {
  8437. a.ytLiveChatTickerItemBehavior.setContainerWidth()
  8438. }))
  8439. }
  8440.  
  8441.  
  8442. znb.prototype.dataChanged = function(a) {
  8443. var b = this;
  8444. a && (a.tickerThumbnails.length > 1 && Q(this.hostElement).querySelector("#content").classList.add("multiple-thumbnails"),
  8445. this.ytLiveChatTickerItemBehavior.startCountdown(a.durationSec, a.fullDurationSec),
  8446. qw(function() {
  8447. b.ytLiveChatTickerItemBehavior.setContainerWidth()
  8448. }))
  8449. }
  8450.  
  8451. *
  8452. */
  8453.  
  8454. const dProto = {
  8455. dataChanged54500: function () {
  8456. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  8457. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  8458. try {
  8459. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8460. return this.dataChanged544.call(this.__proxySelf0__);
  8461. } catch (e) {
  8462. console.log('dataChanged54500 ERROR');
  8463. console.error(e);
  8464. }
  8465. } else {
  8466. return this.dataChanged544();
  8467. }
  8468. },
  8469. dataChanged54501: function (a) {
  8470. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  8471. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  8472. try {
  8473. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8474. return this.dataChanged544.call(this.__proxySelf0__, a);
  8475. } catch (e) {
  8476. console.log('dataChanged54501 ERROR');
  8477. console.error(e);
  8478. }
  8479. } else {
  8480. return this.dataChanged544(a);
  8481. }
  8482. },
  8483. }
  8484.  
  8485. for (const sto of [
  8486. 'yt-live-chat-ticker-sponsor-item-renderer',
  8487. 'yt-live-chat-ticker-paid-sticker-item-renderer'
  8488. ].map(tag => [tag, customElements.whenDefined(tag)])) {
  8489.  
  8490. const [tag, promise] = sto;
  8491.  
  8492. promise.then(()=>{
  8493.  
  8494. const dummy = document.createElement(tag);
  8495.  
  8496. const cProto = getProto(dummy);
  8497. if (!cProto || !cProto.attached) {
  8498. console.warn(`proto.attached for ${tag} is unavailable.`);
  8499. return;
  8500. }
  8501.  
  8502. if (!cProto.dataChanged || cProto.dataChanged544 || typeof cProto.dataChanged !== 'function' || !(cProto.dataChanged.length >= 0 && cProto.dataChanged.length <= 1)) return;
  8503.  
  8504. cProto.dataChanged544 = cProto.dataChanged;
  8505.  
  8506. if (cProto.dataChanged.length === 0) cProto.dataChanged = dProto.dataChanged54500;
  8507. else if (cProto.dataChanged.length === 1) cProto.dataChanged = dProto.dataChanged54501;
  8508.  
  8509.  
  8510.  
  8511. })
  8512.  
  8513.  
  8514. }
  8515.  
  8516. }
  8517.  
  8518. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  8519.  
  8520. mightFirstCheckOnYtInit();
  8521. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  8522. console1.log("[Begin]");
  8523. (() => {
  8524.  
  8525. /* pending!!
  8526.  
  8527. handleLiveChatAction
  8528.  
  8529. removeTickerItemById
  8530.  
  8531. _itemsChanged
  8532. itemsChanged
  8533.  
  8534. handleMarkChatItemAsDeletedAction
  8535. handleMarkChatItemsByAuthorAsDeletedAction
  8536. handleRemoveChatItemByAuthorAction
  8537.  
  8538.  
  8539. */
  8540.  
  8541. const tag = "yt-live-chat-ticker-renderer"
  8542. const dummy = document.createElement(tag);
  8543.  
  8544. const cProto = getProto(dummy);
  8545. if (!cProto || !cProto.attached) {
  8546. console1.warn(`proto.attached for ${tag} is unavailable.`);
  8547. return;
  8548. }
  8549.  
  8550. if(typeof cProto.createComponent_ === 'function' && cProto.createComponent_.length === 3 && !cProto.createComponent58_ ){
  8551.  
  8552. cProto.createComponent58_ = cProto.createComponent_;
  8553. cProto.createComponent_ = function (a, b, c) {
  8554.  
  8555. const z = customCreateComponent(a, b, c);
  8556. if (z !== undefined) return z;
  8557. const r = this.createComponent58_(a, b, c);
  8558. return r;
  8559.  
  8560. }
  8561.  
  8562. }
  8563.  
  8564.  
  8565.  
  8566.  
  8567.  
  8568.  
  8569.  
  8570.  
  8571. /* Dec 2024 */
  8572.  
  8573. /*
  8574.  
  8575.  
  8576. f.handleLiveChatActions = function(a) {
  8577. a.length && (a.forEach(this.handleLiveChatAction, this),
  8578. this.updateHighlightedItem(),
  8579. this.shouldAnimateIn = !0)
  8580. }
  8581. ;
  8582. f.handleLiveChatAction = function(a) {
  8583. var b = z(a, fL)
  8584. , c = z(a, gL)
  8585. , d = z(a, eL)
  8586. , e = z(a, gdb)
  8587. , g = z(a, rdb)
  8588. , k = z(a, Deb);
  8589. a = z(a, Ceb);
  8590. 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)
  8591. }
  8592. */
  8593.  
  8594.  
  8595. if(USE_ADVANCED_TICKING && !cProto.handleLiveChatActions47 && typeof cProto.handleLiveChatActions === 'function' && cProto.handleLiveChatActions.length ===1){
  8596.  
  8597. cProto.handleLiveChatActions47 = cProto.handleLiveChatActions;
  8598.  
  8599. cProto.handleLiveChatActions = function (a) {
  8600.  
  8601. // first loading in livestream. so this is required for sorting.
  8602.  
  8603. try{
  8604. preprocessChatLiveActions(a);
  8605. }catch(e){
  8606. console.warn(e);
  8607. }
  8608. return this.handleLiveChatActions47(a);
  8609.  
  8610. }
  8611.  
  8612. console1.log("USE_ADVANCED_TICKING::handleLiveChatActions - OK");
  8613.  
  8614. }else if(USE_ADVANCED_TICKING){
  8615.  
  8616.  
  8617. console1.log("USE_ADVANCED_TICKING::handleLiveChatActions - NG");
  8618.  
  8619. }
  8620.  
  8621. // yt-live-chat-ticker-renderer hacks
  8622.  
  8623.  
  8624. if (RAF_FIX_keepScrollClamped) {
  8625.  
  8626. // to be improved
  8627.  
  8628. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  8629.  
  8630. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  8631. cProto.keepScrollClamped = function () {
  8632.  
  8633. const cnt = kRef(this);
  8634. if (!cnt) return;
  8635. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8636.  
  8637. cnt._bound_keepScrollClamped = cnt._bound_keepScrollClamped || cnt.keepScrollClamped.bind(mWeakRef(cnt));
  8638. cnt.scrollClampRaf = requestAnimationFrame(cnt._bound_keepScrollClamped);
  8639. cnt.maybeClampScroll()
  8640. }
  8641.  
  8642. console1.log('RAF_FIX: keepScrollClamped', tag, "OK")
  8643. } else {
  8644.  
  8645. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  8646. console1.log('RAF_FIX: keepScrollClamped', tag, "NG")
  8647. }
  8648.  
  8649. }
  8650.  
  8651.  
  8652. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function'
  8653. && '|1.43.31|1.44.31|'.indexOf('|' + fnIntegrity(cProto.startScrolling) + '|') >= 0
  8654. && '|1.78.45|1.82.43|1.43.31|'.indexOf('|' + fnIntegrity(cProto.scrollIncrementally) + '|') >= 0) {
  8655. // to be replaced by animator
  8656.  
  8657. cProto.startScrolling = function (a) {
  8658.  
  8659. const cnt = kRef(this);
  8660. if (!cnt) return;
  8661. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8662.  
  8663. cnt.scrollStopHandle && cnt.cancelAsync(cnt.scrollStopHandle);
  8664. cnt.asyncHandle && cancelAnimationFrame(cnt.asyncHandle);
  8665. cnt.lastFrameTimestamp = cnt.scrollStartTime = performance.now();
  8666. cnt.scrollRatePixelsPerSecond = a;
  8667. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8668. cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally)
  8669. };
  8670.  
  8671. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  8672.  
  8673. /**
  8674. *
  8675. * // 2024.12.17
  8676. * // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  8677.  
  8678. f.startScrolling = function(a) {
  8679. this.scrollStopHandle && $u(this.scrollStopHandle);
  8680. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  8681. this.scrollStartTime = performance.now();
  8682. this.lastFrameTimestamp = performance.now();
  8683. this.scrollRatePixelsPerSecond = a;
  8684. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  8685. }
  8686. ;
  8687. f.scrollIncrementally = function(a) {
  8688. var b = a - (this.lastFrameTimestamp || 0);
  8689. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  8690. this.maybeClampScroll();
  8691. this.updateArrows();
  8692. this.lastFrameTimestamp = a;
  8693. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft > 0 || this.scrollRatePixelsPerSecond && this.scrollRatePixelsPerSecond > 0 ? this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this)) : this.stopScrolling()
  8694. }
  8695. ;
  8696. *
  8697. */
  8698.  
  8699. /**
  8700. *
  8701. // 2024.12.20
  8702.  
  8703.  
  8704.  
  8705. f.startScrolling = function(a) {
  8706. this.scrollStopHandle && av(this.scrollStopHandle);
  8707. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  8708. this.scrollStartTime = performance.now();
  8709. this.lastFrameTimestamp = performance.now();
  8710. this.scrollRatePixelsPerSecond = a;
  8711. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  8712. }
  8713.  
  8714. *
  8715. *
  8716. */
  8717.  
  8718. cProto.__getTickerBarQuery__ = function () {
  8719. const tickerBarQuery = this.tickerBarQuery === '#items' ? this.$.items : this.hostElement.querySelector(this.tickerBarQuery);
  8720. return tickerBarQuery;
  8721. }
  8722.  
  8723. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  8724.  
  8725. const cnt = kRef(this);
  8726. if (!cnt) return;
  8727. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8728.  
  8729. const b = a - (cnt.lastFrameTimestamp || 0);
  8730. const rate = cnt.scrollRatePixelsPerSecond
  8731. const q = b / 1E3 * (rate || 0);
  8732.  
  8733. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8734. const sl = tickerBarQuery.scrollLeft;
  8735. // console.log(rate, sl, q)
  8736. if (cnt.lastFrameTimestamp == cnt.scrollStartTime) {
  8737.  
  8738. } else if (q > -1e-5 && q < 1e-5) {
  8739.  
  8740. } else {
  8741. let cond1 = sl > 0 && rate > 0 && q > 0;
  8742. let cond2 = sl > 0 && rate < 0 && q < 0;
  8743. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  8744. if (cond1 || cond2 || cond3) {
  8745. tickerBarQuery.scrollLeft += q;
  8746. cnt.maybeClampScroll();
  8747. cnt.updateArrows();
  8748. }
  8749. }
  8750.  
  8751. cnt.lastFrameTimestamp = a;
  8752. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8753. 0 < tickerBarQuery.scrollLeft || rate && 0 < rate ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8754. } : function (a) {
  8755.  
  8756. const cnt = kRef(this);
  8757. if (!cnt) return;
  8758. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8759.  
  8760. const b = a - (cnt.lastFrameTimestamp || 0);
  8761. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8762. tickerBarQuery.scrollLeft += b / 1E3 * (cnt.scrollRatePixelsPerSecond || 0);
  8763. cnt.maybeClampScroll();
  8764. cnt.updateArrows();
  8765. cnt.lastFrameTimestamp = a;
  8766. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8767. 0 < tickerBarQuery.scrollLeft || cnt.scrollRatePixelsPerSecond && 0 < cnt.scrollRatePixelsPerSecond ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8768. };
  8769.  
  8770. console1.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  8771. } else {
  8772. assertor(() => fnIntegrity(cProto.startScrolling, '1.43.31'))
  8773. || logFn('cProto.startScrolling', cProto.startScrolling)();
  8774. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.78.45'))
  8775. || logFn('cProto.scrollIncrementally', cProto.scrollIncrementally)();
  8776. console1.log('RAF_FIX: scrollIncrementally', tag, "NG")
  8777. }
  8778.  
  8779.  
  8780. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  8781.  
  8782. cProto.attached37 = cProto.attached;
  8783. cProto.detached37 = cProto.detached;
  8784.  
  8785. let naohzId = 0;
  8786. cProto.__naohzId__ = 0;
  8787. cProto.attached = function () {
  8788. Promise.resolve(this).then((cnt) => {
  8789.  
  8790. const hostElement = cnt.hostElement || cnt;
  8791. if (!(hostElement instanceof HTMLElement)) return;
  8792. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  8793. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  8794. // or #chat-messages
  8795. if (!ironPage) return;
  8796.  
  8797. if (cnt.__naohzId__) removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8798. cnt.__naohzId__ = naohzId = (naohzId & 1073741823) + 1;
  8799. ironPage.setAttribute('naohz', `${+cnt.__naohzId__}`);
  8800.  
  8801. addEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8802.  
  8803. cnt = null;
  8804.  
  8805. });
  8806. return this.attached37.apply(this, arguments);
  8807. };
  8808. cProto.detached = function () {
  8809. Promise.resolve(this).then((cnt) => {
  8810.  
  8811. const ironPage = document.querySelector(`iron-pages[naohz="${+cnt.__naohzId__}"]`);
  8812. if (!ironPage) return;
  8813.  
  8814. removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8815.  
  8816. cnt = null;
  8817.  
  8818. });
  8819. return this.detached37.apply(this, arguments);
  8820. };
  8821.  
  8822. const clickFade = (u) => {
  8823. u.click();
  8824. };
  8825. cProto.messageBoxClickHandlerForFade = async (evt) => {
  8826.  
  8827. const target = (evt || 0).target || 0;
  8828. if (!target) return;
  8829.  
  8830. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  8831. const is = p.is;
  8832. if (typeof is === 'string' && is) {
  8833.  
  8834. if (is === 'yt-live-chat-pinned-message-renderer') {
  8835. return;
  8836. }
  8837. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  8838. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  8839. if (fade) {
  8840. Promise.resolve(fade).then(clickFade);
  8841. evt && evt.stopPropagation();
  8842. }
  8843. return;
  8844. }
  8845. if (is !== 'yt-live-chat-ticker-renderer') {
  8846. if (is.startsWith('yt-live-chat-ticker-')) return;
  8847. if (!is.endsWith('-renderer')) return;
  8848. }
  8849.  
  8850. } else {
  8851. if ((p.nodeName || '').includes('BUTTON')) return;
  8852. }
  8853.  
  8854. }
  8855. };
  8856.  
  8857. console1.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  8858.  
  8859. } else {
  8860. console1.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  8861. }
  8862.  
  8863.  
  8864. })();
  8865.  
  8866. console1.log("[End]");
  8867.  
  8868. groupEnd();
  8869.  
  8870. }).catch(console.warn);
  8871.  
  8872.  
  8873.  
  8874. if (ENABLE_RAF_HACK_INPUT_RENDERER || DELAY_FOCUSEDCHANGED) {
  8875.  
  8876. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  8877.  
  8878. mightFirstCheckOnYtInit();
  8879. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  8880. console1.log("[Begin]");
  8881. (() => {
  8882.  
  8883.  
  8884.  
  8885. const tag = "yt-live-chat-message-input-renderer"
  8886. const dummy = document.createElement(tag);
  8887.  
  8888. const cProto = getProto(dummy);
  8889. if (!cProto || !cProto.attached) {
  8890. console1.warn(`proto.attached for ${tag} is unavailable.`);
  8891. return;
  8892. }
  8893.  
  8894.  
  8895. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  8896.  
  8897. let doHack = false;
  8898. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  8899.  
  8900. // not cancellable
  8901.  
  8902. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  8903.  
  8904. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  8905.  
  8906. if (!doHack) console1.log('doHack = false')
  8907.  
  8908. }
  8909. // doHack = false; // M55
  8910.  
  8911. if (doHack) {
  8912.  
  8913. cProto.handleTimeout = function (a) {
  8914.  
  8915. const cnt = kRef(this);
  8916. if (!cnt) return;
  8917. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8918.  
  8919. console.log('cProto.handleTimeout', tag)
  8920. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  8921. cnt.timeoutDurationMs = cnt.timeoutMs = a;
  8922. cnt.countdownRatio = 1;
  8923. 0 === cnt.lastTimeoutTimeMs && rafHub.request(cnt.boundUpdateTimeout38_)
  8924. };
  8925. cProto.updateTimeout = function (a) {
  8926.  
  8927. const cnt = kRef(this);
  8928. if (!cnt) return;
  8929. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8930.  
  8931. console.log('cProto.updateTimeout', tag)
  8932. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  8933. cnt.lastTimeoutTimeMs && (cnt.timeoutMs = Math.max(0, cnt.timeoutMs - (a - cnt.lastTimeoutTimeMs)),
  8934. cnt.countdownRatio = cnt.timeoutMs / cnt.timeoutDurationMs);
  8935. cnt.isAttached && cnt.timeoutMs ? (cnt.lastTimeoutTimeMs = a,
  8936. rafHub.request(cnt.boundUpdateTimeout38_)) : cnt.lastTimeoutTimeMs = 0
  8937. };
  8938.  
  8939. console1.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  8940. } else {
  8941.  
  8942. console1.log('typeof handleTimeout', typeof cProto.handleTimeout)
  8943. console1.log('typeof updateTimeout', typeof cProto.updateTimeout)
  8944.  
  8945. console1.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  8946. }
  8947.  
  8948.  
  8949. }
  8950.  
  8951. if (DELAY_FOCUSEDCHANGED && typeof cProto.onFocusedChanged === 'function' && cProto.onFocusedChanged.length === 1 && !cProto.onFocusedChanged372) {
  8952. cProto.onFocusedChanged372 = cProto.onFocusedChanged;
  8953. cProto.onFocusedChanged = function (a) {
  8954. Promise.resolve(this).then((cnt) => {
  8955. if (cnt.isAttached === true) cnt.onFocusedChanged372(a);
  8956. cnt = null;
  8957. }).catch(console.warn);
  8958. }
  8959. }
  8960.  
  8961. })();
  8962.  
  8963. console1.log("[End]");
  8964.  
  8965. groupEnd();
  8966.  
  8967.  
  8968. })
  8969.  
  8970. }
  8971.  
  8972.  
  8973. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  8974.  
  8975. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  8976.  
  8977. mightFirstCheckOnYtInit();
  8978. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  8979. console1.log("[Begin]");
  8980. (() => {
  8981.  
  8982. const tag = "yt-emoji-picker-renderer"
  8983. const dummy = document.createElement(tag);
  8984.  
  8985. const cProto = getProto(dummy);
  8986. if (!cProto || !cProto.attached) {
  8987. console1.warn(`proto.attached for ${tag} is unavailable.`);
  8988. return;
  8989. }
  8990.  
  8991. let doHack = false;
  8992. if (typeof cProto.animateScroll_ === 'function') {
  8993.  
  8994. // not cancellable
  8995. console1.log('animateScroll_: function - OK')
  8996.  
  8997. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  8998.  
  8999. } else {
  9000.  
  9001. console1.log('animateScroll_', typeof cProto.animateScroll_)
  9002. }
  9003.  
  9004. if (doHack) {
  9005.  
  9006. const querySelector = HTMLElement.prototype.querySelector;
  9007. const U = (element) => ({
  9008. querySelector: (selector) => querySelector.call(element, selector)
  9009. });
  9010.  
  9011. cProto.animateScroll_ = function (a) {
  9012.  
  9013. const cnt = kRef(this);
  9014. if (!cnt) return;
  9015. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9016.  
  9017. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  9018. if (!cnt.boundAnimateScroll39_) cnt.boundAnimateScroll39_ = cnt.animateScroll_.bind(mWeakRef(cnt));
  9019. cnt.lastAnimationTime_ || (cnt.lastAnimationTime_ = a);
  9020. a -= cnt.lastAnimationTime_;
  9021. 200 > a ? (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationStart_ + (cnt.animationEnd_ - cnt.animationStart_) * a / 200,
  9022. rafHub.request(cnt.boundAnimateScroll39_)) : (null != cnt.animationEnd_ && (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationEnd_),
  9023. cnt.animationEnd_ = cnt.animationStart_ = null,
  9024. cnt.lastAnimationTime_ = 0);
  9025. cnt.updateButtons_()
  9026. }
  9027.  
  9028. console1.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  9029. } else {
  9030.  
  9031. console1.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  9032. }
  9033.  
  9034. })();
  9035.  
  9036. console1.log("[End]");
  9037.  
  9038. groupEnd();
  9039. });
  9040. }
  9041.  
  9042. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  9043.  
  9044. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  9045.  
  9046. mightFirstCheckOnYtInit();
  9047. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  9048. console1.log("[Begin]");
  9049. (() => {
  9050.  
  9051. const tag = "yt-live-chat-docked-message"
  9052. const dummy = document.createElement(tag);
  9053.  
  9054. const cProto = getProto(dummy);
  9055. if (!cProto || !cProto.attached) {
  9056. console1.warn(`proto.attached for ${tag} is unavailable.`);
  9057. return;
  9058. }
  9059.  
  9060. let doHack = false;
  9061. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  9062.  
  9063. // cancelable - this.intersectRAF <detached>
  9064. // yt-live-chat-docked-message
  9065. // boundCheckIntersections <-> checkIntersections
  9066. // onDockableMessagesChanged
  9067. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  9068.  
  9069. console1.log(`detached: function - OK`)
  9070. console1.log('checkIntersections: function - OK')
  9071. console1.log('onDockableMessagesChanged: function - OK')
  9072.  
  9073. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  9074.  
  9075. } else {
  9076.  
  9077. console1.log('detached', typeof cProto.detached, 'NG')
  9078. console1.log('checkIntersections', typeof cProto.checkIntersections, 'NG')
  9079. console1.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged, 'NG')
  9080. }
  9081.  
  9082. if (doHack) {
  9083.  
  9084. cProto.__boundCheckIntersectionsSubstitutionFn__ = function () {
  9085. const cnt = this;
  9086. if (!cnt.i5zmk && typeof cnt.boundCheckIntersections === 'function' && typeof cnt.checkIntersections === 'function') {
  9087. cnt.i5zmk = 1
  9088. cnt.boundCheckIntersections = cnt.checkIntersections.bind(mWeakRef(cnt));
  9089. }
  9090. }
  9091.  
  9092. cProto.checkIntersections = function () {
  9093.  
  9094. const cnt = kRef(this);
  9095. if (!cnt) return;
  9096. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9097.  
  9098. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  9099.  
  9100. // console.log('cProto.checkIntersections', tag)
  9101. if (cnt.dockableMessages.length) {
  9102. cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections);
  9103. let a = cnt.dockableMessages[0]
  9104. , b = cnt.hostElement.getBoundingClientRect();
  9105. a = a.getBoundingClientRect();
  9106. let c = a.top - b.top
  9107. , d = 8 >= c;
  9108. c = 8 >= c - cnt.hostElement.clientHeight;
  9109. if (d) {
  9110. let e;
  9111. for (; d;) {
  9112. e = cnt.dockableMessages.shift();
  9113. d = cnt.dockableMessages[0];
  9114. if (!d)
  9115. break;
  9116. d = d.getBoundingClientRect();
  9117. c = d.top - b.top;
  9118. let f = 8 >= c;
  9119. if (8 >= c - a.height)
  9120. if (f)
  9121. a = d;
  9122. else
  9123. return;
  9124. d = f
  9125. }
  9126. cnt.dock(e)
  9127. } else
  9128. c && cnt.dockedItem && cnt.clear()
  9129. } else
  9130. cnt.intersectRAF = 0
  9131. }
  9132.  
  9133. cProto.onDockableMessagesChanged = function () {
  9134. const cnt = this;
  9135. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  9136. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  9137. cnt.dockableMessages.length && !cnt.intersectRAF && (cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections))
  9138. }
  9139.  
  9140. cProto.detached = function () {
  9141. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  9142. }
  9143.  
  9144. console1.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  9145. } else {
  9146.  
  9147. console1.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  9148. }
  9149.  
  9150. })();
  9151.  
  9152. console1.log("[End]");
  9153.  
  9154. groupEnd();
  9155.  
  9156. }).catch(console.warn);
  9157.  
  9158. }
  9159.  
  9160. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  9161.  
  9162. customElements.whenDefined("yt-img-shadow").then(() => {
  9163.  
  9164. mightFirstCheckOnYtInit();
  9165. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  9166. console1.log("[Begin]");
  9167. (() => {
  9168.  
  9169. const tag = "yt-img-shadow"
  9170. const dummy = document.createElement(tag);
  9171.  
  9172. const cProto = getProto(dummy);
  9173. if (!cProto || !cProto.attached) {
  9174. console1.warn(`proto.attached for ${tag} is unavailable.`);
  9175. return;
  9176. }
  9177.  
  9178. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  9179.  
  9180. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  9181. cProto.thumbnailChanged_ = function (a) {
  9182.  
  9183. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  9184. if (!this.oldThumbnail_ && !this.thumbnail) return;
  9185.  
  9186. return this.thumbnailChanged66_.apply(this, arguments)
  9187.  
  9188. }
  9189. console1.log("cProto.thumbnailChanged_ - OK");
  9190.  
  9191. } else {
  9192. console1.log("cProto.thumbnailChanged_ - NG");
  9193.  
  9194. }
  9195. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  9196.  
  9197. cProto.setSrc66_ = cProto.setSrc_;
  9198. cProto.setSrc_ = function (a) {
  9199. if ((((this || 0).$ || 0).img || 0).src === a) return;
  9200. return this.setSrc66_.apply(this, arguments)
  9201. }
  9202.  
  9203. console1.log("cProto.setSrc_ - OK");
  9204. } else {
  9205.  
  9206. console1.log("cProto.setSrc_ - NG");
  9207. }
  9208.  
  9209. })();
  9210.  
  9211. console1.log("[End]");
  9212.  
  9213. groupEnd();
  9214.  
  9215. }).catch(console.warn);
  9216.  
  9217. }
  9218.  
  9219. if (FIX_THUMBNAIL_DATACHANGED) {
  9220.  
  9221. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  9222.  
  9223. mightFirstCheckOnYtInit();
  9224. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  9225. console1.log("[Begin]");
  9226. (() => {
  9227.  
  9228. const tag = "yt-live-chat-author-badge-renderer"
  9229. const dummy = document.createElement(tag);
  9230.  
  9231. const cProto = getProto(dummy);
  9232. if (!cProto || !cProto.attached) {
  9233. console1.warn(`proto.attached for ${tag} is unavailable.`);
  9234. return;
  9235. }
  9236.  
  9237. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|0.169.106|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9238.  
  9239. cProto.dataChanged86 = cProto.dataChanged;
  9240. cProto.dataChanged = function () {
  9241.  
  9242. /* 2024.12.15 */
  9243. /*
  9244. zO.prototype.dataChanged = function() {
  9245. for (var a = Ov(R(this.hostElement).querySelector("#image")); a.firstChild; )
  9246. a.removeChild(a.firstChild);
  9247. if (this.data)
  9248. if (this.data.icon) {
  9249. var b = document.createElement("yt-icon");
  9250. this.data.icon.iconType === "MODERATOR" && this.enableNewModeratorBadge ? (b.polymerController.icon = "yt-sys-icons:shield-filled",
  9251. b.polymerController.defaultToFilled = !0) : b.polymerController.icon = "live-chat-badges:" + this.data.icon.iconType.toLowerCase();
  9252. a.appendChild(b)
  9253. } else if (this.data.customThumbnail) {
  9254. b = document.createElement("img");
  9255. var c;
  9256. (c = (c = UA(this.data.customThumbnail.thumbnails, 16)) ? Yb(kc(c)) : null) ? (b.src = c,
  9257. a.appendChild(b),
  9258. b.setAttribute("alt", this.hostElement.ariaLabel || "")) : Fq(new Zn("Could not compute URL for thumbnail",this.data.customThumbnail))
  9259. }
  9260. }
  9261. */
  9262.  
  9263. const a = (this || 0).data;
  9264. const image = ((this || 0).$ || 0).image;
  9265. if (image && a && image.firstElementChild) {
  9266. const exisiting = image.firstElementChild;
  9267. if (exisiting === image.lastElementChild) {
  9268.  
  9269. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9270.  
  9271. const c = exisiting;
  9272. const t = insp(c);
  9273. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9274. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9275. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9276. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9277. } else {
  9278. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9279. if (w.icon !== p) w.icon = p;
  9280. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9281. }
  9282. return;
  9283.  
  9284.  
  9285. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9286.  
  9287. const c = exisiting;
  9288. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9289.  
  9290. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9291. return;
  9292. }
  9293. /*
  9294.  
  9295. var d;
  9296. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9297.  
  9298. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9299. */
  9300. }
  9301.  
  9302. }
  9303. }
  9304. return this.dataChanged86.apply(this, arguments)
  9305.  
  9306. }
  9307. console1.log("cProto.dataChanged - OK");
  9308.  
  9309. } else if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|1.163.100|1.162.100|1.160.97|1.159.97|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9310.  
  9311. cProto.dataChanged86 = cProto.dataChanged;
  9312. cProto.dataChanged = function (a) {
  9313.  
  9314. /*
  9315.  
  9316. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  9317. b.removeChild(b.firstChild);
  9318. if (a)
  9319. if (a.icon) {
  9320. var c = document.createElement("yt-icon");
  9321. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  9322. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9323. b.appendChild(c)
  9324. } else if (a.customThumbnail) {
  9325. c = document.createElement("img");
  9326. var d;
  9327. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9328. b.appendChild(c),
  9329. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  9330. }
  9331.  
  9332. */
  9333.  
  9334.  
  9335. /* 2024.04.20 */
  9336. /*
  9337. for (var b = Tx(N(this.hostElement).querySelector("#image")); b.firstChild; )
  9338. b.removeChild(b.firstChild);
  9339. if (a)
  9340. if (a.icon) {
  9341. var c = document.createElement("yt-icon");
  9342. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.polymerController.icon = "yt-sys-icons:shield-filled",
  9343. c.polymerController.defaultToFilled = !0) : c.polymerController.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9344. b.appendChild(c)
  9345. } else if (a.customThumbnail) {
  9346. c = document.createElement("img");
  9347. var d;
  9348. (d = (d = WD(a.customThumbnail.thumbnails, 16)) ? Sb(ec(d)) : null) ? (c.src = d,
  9349. b.appendChild(c),
  9350. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : nr(new mn("Could not compute URL for thumbnail",a.customThumbnail))
  9351. }
  9352. */
  9353.  
  9354. const image = ((this || 0).$ || 0).image
  9355. if (image && a && image.firstElementChild) {
  9356. const exisiting = image.firstElementChild;
  9357. if (exisiting === image.lastElementChild) {
  9358.  
  9359. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9360.  
  9361. const c = exisiting;
  9362. const t = insp(c);
  9363. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9364. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9365. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9366. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9367. } else {
  9368. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9369. if (w.icon !== p) w.icon = p;
  9370. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9371. }
  9372. return;
  9373.  
  9374.  
  9375. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9376.  
  9377. const c = exisiting;
  9378. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9379.  
  9380. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9381. return;
  9382. }
  9383. /*
  9384.  
  9385. var d;
  9386. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9387.  
  9388. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9389. */
  9390. }
  9391.  
  9392. }
  9393. }
  9394. return this.dataChanged86.apply(this, arguments)
  9395.  
  9396. }
  9397. console1.log("cProto.dataChanged - OK");
  9398.  
  9399. } else {
  9400. assertor(() => fnIntegrity(cProto.dataChanged, '0.169.106'));
  9401. console1.log("cProto.dataChanged - NG");
  9402.  
  9403. }
  9404.  
  9405. })();
  9406.  
  9407. console1.log("[End]");
  9408.  
  9409. groupEnd();
  9410.  
  9411. }).catch(console.warn);
  9412.  
  9413.  
  9414. }
  9415.  
  9416. if (USE_ADVANCED_TICKING) {
  9417. // leading the emoji cannot be rendered.
  9418.  
  9419. // const qz38 = lcrPromiseFn();
  9420.  
  9421. // qz38.then((lcrGet) => {
  9422.  
  9423. // const tag = "yt-live-chat-renderer"
  9424. // const dummy = lcrGet();
  9425.  
  9426. const lcrFn2 = (lcrDummy) => {
  9427.  
  9428. const tag = "yt-live-chat-renderer"
  9429. const dummy = lcrDummy;
  9430.  
  9431.  
  9432. const cProto = getProto(dummy);
  9433.  
  9434. // dummy.usePatchedLifecycles = false;
  9435. // dummy.data = null;
  9436. // dummy.__data = null;
  9437. // Object.setPrototypeOf(dummy, Object.prototype);
  9438. if (!cProto || !cProto.attached) {
  9439. console.warn(`proto.attached for ${tag} is unavailable.`);
  9440. return;
  9441. }
  9442.  
  9443. /*
  9444. <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;
  9445. */
  9446.  
  9447. if (cProto && typeof cProto.immediatelyApplyLiveChatActions === 'function' && cProto.immediatelyApplyLiveChatActions.length === 1 && !cProto.immediatelyApplyLiveChatActions82) {
  9448. cProto.immediatelyApplyLiveChatActions82 = cProto.immediatelyApplyLiveChatActions;
  9449. cProto.immediatelyApplyLiveChatActions = function (arr) {
  9450.  
  9451.  
  9452. // console.log(1237)
  9453. try {
  9454. preprocessChatLiveActions(arr);
  9455. } catch (e) {
  9456. console.warn(e);
  9457. }
  9458. return this.immediatelyApplyLiveChatActions82(arr);
  9459. };
  9460. }
  9461.  
  9462.  
  9463. if (cProto && typeof cProto.preprocessActions_ === 'function' && cProto.preprocessActions_.length === 1 && !cProto.preprocessActions82_) {
  9464. cProto.preprocessActions82_ = cProto.preprocessActions_;
  9465. cProto.preprocessActions_ = function (arr) {
  9466.  
  9467. arr = this.preprocessActions82_(arr);
  9468.  
  9469. try {
  9470. preprocessChatLiveActions(arr);
  9471. } catch (e) {
  9472. console.warn(e);
  9473. }
  9474. return arr;
  9475. };
  9476. }
  9477.  
  9478.  
  9479.  
  9480. };
  9481. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  9482. getLCRDummy().then(lcrFn2);
  9483. }
  9484.  
  9485. if (MODIFY_EMIT_MESSAGES_FOR_BOOST_CHAT) {
  9486.  
  9487. const lcrFn2 = (lcrDummy) => {
  9488.  
  9489. const tag = "yt-live-chat-renderer"
  9490. const dummy = lcrDummy;
  9491.  
  9492.  
  9493. const cProto = getProto(dummy);
  9494.  
  9495. // dummy.usePatchedLifecycles = false;
  9496. // dummy.data = null;
  9497. // dummy.__data = null;
  9498. // Object.setPrototypeOf(dummy, Object.prototype);
  9499. if (!cProto || !cProto.attached) {
  9500. console.warn(`proto.attached for ${tag} is unavailable.`);
  9501. return;
  9502. }
  9503.  
  9504. /*
  9505.  
  9506. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  9507.  
  9508.  
  9509. YP.prototype.emitSmoothedMessages = function() {
  9510. this.JSC$10797_nextUpdateId = null;
  9511. if (this.JSC$10797_messageQueue.length) {
  9512. var a = 1E4;
  9513. this.JSC$10797_estimatedUpdateInterval !== null && this.JSC$10797_lastUpdateTime !== null && (a = this.JSC$10797_estimatedUpdateInterval - Date.now() + this.JSC$10797_lastUpdateTime);
  9514. var b = this.JSC$10797_messageQueue.length < a / 80 ? 1 : Math.ceil(this.JSC$10797_messageQueue.length / (a / 80));
  9515. var c = aba(this.JSC$10797_messageQueue.splice(0, b));
  9516. this.callback && this.callback(c);
  9517. this.JSC$10797_messageQueue.length && (b === 1 ? (b = a / this.JSC$10797_messageQueue.length,
  9518. b *= Math.random() + .5,
  9519. b = Math.min(1E3, b),
  9520. b = Math.max(80, b)) : b = 80,
  9521. this.JSC$10797_nextUpdateId = window.setTimeout(this.emitSmoothedMessages.bind(this), b))
  9522. }
  9523. }
  9524. // emitSmoothedMessages: say b = 1000, 858.24, 529.49, 357.15, 194.96, 82.12, 80, 80, 80 ....
  9525.  
  9526. */
  9527.  
  9528.  
  9529. const _flag0281_ = window._flag0281_;
  9530.  
  9531.  
  9532. if ((_flag0281_ & 0x40000) === 0x40000 && cProto && typeof cProto.preprocessActions_ === 'function' && cProto.preprocessActions_.length === 1 && !cProto.preprocessActions92_) {
  9533. // we can disable smooth message emitting if boost chat is enabled (0x40000)
  9534. let byPass = false;
  9535. let q33 = false;
  9536. let key_estimatedUpdateInterval = '';
  9537. let key_lastUpdateTime = '';
  9538. let key_messageQueue = '';
  9539. const emitSmoothedMessagesInstantFn = function () {
  9540. if (byPass) return this.emitSmoothedMessages018();
  9541. byPass = true;
  9542. try {
  9543. if (!q33) {
  9544. const keys = Object.getOwnPropertyNames(this);
  9545. for (const key of keys) {
  9546. if (`${key}`.endsWith('_estimatedUpdateInterval')) key_estimatedUpdateInterval = key;
  9547. else if (`${key}`.endsWith('_lastUpdateTime')) key_lastUpdateTime = key;
  9548. else if (`${key}`.endsWith('_messageQueue')) key_messageQueue = key;
  9549. else continue;
  9550. if (key_estimatedUpdateInterval && key_lastUpdateTime && key_messageQueue) break;
  9551. }
  9552. if (key_estimatedUpdateInterval && key_lastUpdateTime && key_messageQueue) {
  9553. q33 = true;
  9554. }
  9555. }
  9556. if (key_estimatedUpdateInterval && key_lastUpdateTime) {
  9557. this[key_estimatedUpdateInterval] = 78; // 80 - 2
  9558. this[key_lastUpdateTime] = Date.now() - 1;
  9559. }
  9560. } catch (e) { }
  9561. // console.log(19893,key_estimatedUpdateInterval, key_lastUpdateTime)
  9562. // make a = this.JSC$10797_estimatedUpdateInterval - Date.now() + this.JSC$10797_lastUpdateTime small
  9563.  
  9564. // this.JSC$10797_estimatedUpdateInterval = Date.now() + 1
  9565. // this.JSC$10797_lastUpdateTime = Date.now()
  9566.  
  9567. // if (!window.setTimeout837) {
  9568. // window.setTimeout837 = window.setTimeout;
  9569. // window.setTimeout838 = function (f, d) {
  9570. // if (arguments.length !== 2) return window.setTimeout837(...arguments);
  9571. // console.log(12883, d)
  9572. // return window.setTimeout837(f, d > 80 ? 80 : d)
  9573. // }
  9574. // }
  9575. // else if (window.setTimeout837 !== window.setTimeout) {
  9576. // window.setTimeout837 = window.setTimeout;
  9577. // }
  9578. // let r;
  9579. // if (window.setTimeout837 && window.setTimeout838) {
  9580. // window.setTimeout = window.setTimeout838;
  9581. // r = this.emitSmoothedMessages018();
  9582. // window.setTimeout = window.setTimeout837;
  9583. // } else {
  9584. // r = this.emitSmoothedMessages018();
  9585. // }
  9586. let doInNextCall = false;
  9587. try {
  9588. const messageQueue = key_messageQueue ? this[key_messageQueue] : null;
  9589. if (!messageQueue || !messageQueue.length) {
  9590.  
  9591. } else if (messageQueue.length > 255) {
  9592.  
  9593. } else if (!document.hidden) {
  9594.  
  9595. } else {
  9596. doInNextCall = true;
  9597. }
  9598. } catch (e) { }
  9599.  
  9600. let r;
  9601. if (doInNextCall) {
  9602. setTimeout_(() => this.emitSmoothedMessages019(), 250);
  9603. } else {
  9604. r = this.emitSmoothedMessages018();
  9605. }
  9606. byPass = false;
  9607. return r;
  9608. };
  9609. cProto.preprocessActions92_ = cProto.preprocessActions_;
  9610. cProto.preprocessActions_ = function (arr) {
  9611.  
  9612. arr = this.preprocessActions92_(arr);
  9613.  
  9614. try {
  9615.  
  9616. const smoothedQueue_ = this.smoothedQueue_;
  9617. if (smoothedQueue_ && !smoothedQueue_.__fix018__) {
  9618. smoothedQueue_.__fix018__ = true;
  9619. if (!smoothedQueue_.emitSmoothedMessages018 && typeof smoothedQueue_.emitSmoothedMessages === 'function' && smoothedQueue_.emitSmoothedMessages.length === 0) {
  9620. smoothedQueue_.emitSmoothedMessages018 = smoothedQueue_.emitSmoothedMessages;
  9621. smoothedQueue_.emitSmoothedMessages019 = emitSmoothedMessagesInstantFn;
  9622. smoothedQueue_.emitSmoothedMessages = emitSmoothedMessagesInstantFn;
  9623. }
  9624. }
  9625. } catch (e) {
  9626. console.warn(e);
  9627. }
  9628. return arr;
  9629. };
  9630. }
  9631.  
  9632.  
  9633.  
  9634.  
  9635. };
  9636. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  9637. getLCRDummy().then(lcrFn2);
  9638. }
  9639.  
  9640.  
  9641. if (FIX_TOOLTIP_DISPLAY) {
  9642.  
  9643. // ----------------------------------------------------------------------------------------------------
  9644.  
  9645. const checkPDGet = (pd) => {
  9646. return pd && pd.get && !pd.set && pd.enumerable && pd.configurable;
  9647. }
  9648.  
  9649. const tooltipUIWM = new WeakMap();
  9650. const tooltipInitProps = {};
  9651. const createTooltipIfRequired_ = function () {
  9652. let r;
  9653. if (tooltipUIWM.get(this) === void 0) {
  9654. const w = document.createElement;
  9655. let EU = null;
  9656. tooltipUIWM.set(this, null);
  9657. document.createElement = function () {
  9658. let r = w.apply(this, arguments);
  9659. EU = r;
  9660. return r;
  9661. };
  9662. r = this.createTooltipIfRequired14_();
  9663. document.createElement = w;
  9664. if (EU instanceof HTMLElement && EU.is) {
  9665. tooltipUIWM.set(this, EU);
  9666. EU.setAttribute('__nogc__', ''); // avoid gc process script
  9667.  
  9668. if (typeof EU.offset === 'number') tooltipInitProps['offset'] = EU.offset;
  9669. if (typeof EU.fitToVisibleBounds === 'boolean') tooltipInitProps['fitToVisibleBounds'] = EU.fitToVisibleBounds;
  9670. if (typeof EU.position === 'string') tooltipInitProps['position'] = EU.position;
  9671. if (typeof EU.for === 'string') tooltipInitProps['for'] = EU.for;
  9672.  
  9673. // this.__mcT__ = EU.outerHTML;
  9674. // EU.__dataX = JSON.stringify(EU.__data);
  9675. // EU.__dataY = Object.entries(EU);
  9676.  
  9677. // <<< FOR DEBUG >>>
  9678. // let kx;
  9679. // Object.defineProperty(EU, '_target', {
  9680. // get(){
  9681. // return kx;
  9682. // },
  9683. // set(nv){
  9684. // kx= nv;
  9685. // debugger;
  9686. // return true;
  9687. // }
  9688. // });
  9689. // <<< FOR DEBUG >>>
  9690.  
  9691. if (typeof Polymer !== 'undefined' && Polymer.__fixedGetOwnerRoot__ && Polymer.__fixedQuerySelector__) {
  9692.  
  9693. } else {
  9694. let eProto = null;
  9695. const euCnt = insp(EU);
  9696. if (checkPDGet(Object.getOwnPropertyDescriptor(euCnt.constructor.prototype || {}, 'target'))) {
  9697.  
  9698. eProto = euCnt.constructor.prototype;
  9699. } else if (checkPDGet(Object.getOwnPropertyDescriptor(EU.constructor.prototype || {}, 'target'))) {
  9700.  
  9701. eProto = EU.constructor.prototype;
  9702. }
  9703. if (eProto) {
  9704. delete eProto.target;
  9705. /*
  9706.  
  9707. get target() {
  9708. var a = Pv(this).parentNode, b = Pv(this).getOwnerRoot(), c;
  9709. this.for ? c = Pv(b).querySelector("#" + this.for) : c = a.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? b.host : a;
  9710. return c
  9711. },
  9712. */
  9713. Object.defineProperty(eProto, 'target', {
  9714. get() {
  9715. const cnt = insp(this);
  9716. const hostElement = cnt.hostElement || cnt;
  9717. let a = hostElement.parentNode, b = hostElement.getRootNode();
  9718. const fr = cnt.for || hostElement.for;
  9719. return (fr ? b.querySelector("#" + fr) : a)
  9720. }
  9721. })
  9722. }
  9723. }
  9724. // setInterval(()=>EU.updatePosition(), 100)
  9725.  
  9726. } else {
  9727. tooltipUIWM.set(this, null);
  9728. }
  9729. } else {
  9730. r = this.createTooltipIfRequired14_();
  9731. }
  9732.  
  9733. const EU = tooltipUIWM.get(this);
  9734. if (EU) {
  9735. EU.remove();
  9736. if (typeof tooltipInitProps.offset === 'number') EU['offset'] = tooltipInitProps.offset;
  9737. if (typeof tooltipInitProps.fitToVisibleBounds === 'boolean') EU['fitToVisibleBounds'] = tooltipInitProps.fitToVisibleBounds;
  9738. try {
  9739. if (typeof tooltipInitProps.position === 'string') EU['position'] = tooltipInitProps.position;
  9740. if (typeof tooltipInitProps.for === 'string') EU['for'] = tooltipInitProps.for; else delete EU.for;
  9741. } catch (e) { }
  9742. }
  9743.  
  9744. // 2025.01.10 fix
  9745. const CS = EU;
  9746. if (!CS._showing && CS.__shady_parentNode && CS.__shady_parentNode !== CS.parentNode) {
  9747. if (CS.__shady_parentNode) {
  9748. try {
  9749. CS.__shady_parentNode.__shady_removeChild(CS);
  9750. } catch (e) { }
  9751. }
  9752. if (CS.__shady_parentNode) {
  9753. try {
  9754. CS.__shady_parentNode.removeChild(CS);
  9755. } catch (e) { }
  9756. }
  9757. if (CS.__shady_parentNode) {
  9758. try {
  9759. CS.__shady_parentNode.__shady_native_removeChild(CS);
  9760. } catch (e) { }
  9761. }
  9762. if (CS.__shady_parentNode) {
  9763. try {
  9764. __shady_native_removeChild.call(CS.__shady_parentNode, CS);
  9765. } catch (e) { }
  9766. }
  9767. if (CS.parentNode && !CS.__shady_parentNode) {
  9768. try {
  9769. __shady_native_removeChild.call(CS.parentNode, CS);
  9770. } catch (e) { }
  9771. }
  9772. }
  9773.  
  9774. return r;
  9775. };
  9776.  
  9777.  
  9778. // added in 2024.05.02
  9779. const lcrFn2 = (lcrDummy) => {
  9780.  
  9781. // console.log(8171, 99);
  9782. const tag = "yt-live-chat-renderer"
  9783. const dummy = lcrDummy;
  9784.  
  9785. const cProto = getProto(dummy);
  9786. if (!cProto || !cProto.attached) {
  9787. console.warn(`proto.attached for ${tag} is unavailable.`);
  9788. return;
  9789. }
  9790.  
  9791. /*
  9792. <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;
  9793. */
  9794.  
  9795. if (cProto && typeof cProto.createTooltipIfRequired_ === 'function' && cProto.createTooltipIfRequired_.length === 0 && !cProto.createTooltipIfRequired14_) {
  9796. cProto.createTooltipIfRequired14_ = cProto.createTooltipIfRequired_;
  9797. cProto.createTooltipIfRequired_ = createTooltipIfRequired_;
  9798. }
  9799.  
  9800. };
  9801. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  9802. getLCRDummy().then(lcrFn2);
  9803.  
  9804. // ----------------------------------------------------------------------------------------------------
  9805.  
  9806. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  9807.  
  9808. mightFirstCheckOnYtInit();
  9809. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  9810. console1.log("[Begin]");
  9811. (() => {
  9812.  
  9813. const tag = "tp-yt-paper-tooltip"
  9814. const dummy = document.createElement(tag);
  9815.  
  9816. const cProto = getProto(dummy);
  9817. if (!cProto || !cProto.attached) {
  9818. console1.warn(`proto.attached for ${tag} is unavailable.`);
  9819. return;
  9820. }
  9821.  
  9822. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  9823.  
  9824. cProto._readyClients43 = cProto._readyClients;
  9825. cProto._readyClients = function () {
  9826. // console.log(1238)
  9827.  
  9828. let r = cProto._readyClients43.apply(this, arguments);
  9829. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  9830. return r;
  9831. }
  9832.  
  9833. console1.log("_readyClients - OK");
  9834.  
  9835. } else {
  9836. console1.log("_readyClients - NG");
  9837.  
  9838. }
  9839.  
  9840. if (typeof cProto.show === 'function' && !cProto.show17) {
  9841. cProto.show17 = cProto.show;
  9842. cProto.show = function () {
  9843.  
  9844. let r = this.show17.apply(this, arguments);
  9845. this._showing === true && Promise.resolve(this).then((cnt) => {
  9846. const tooltip = (cnt.$ || 0).tooltip;
  9847.  
  9848. if (tooltip && tooltip.firstElementChild === null) {
  9849. let text = tooltip.textContent;
  9850. if (typeof text === 'string' && text.length >= 2) {
  9851. tooltip.textContent = text.trim();
  9852. }
  9853. }
  9854. cnt = null;
  9855. }).catch(console.warn)
  9856. return r;
  9857. }
  9858.  
  9859. console1.log("trim tooltip content - OK");
  9860.  
  9861. } else {
  9862. console1.log("trim tooltip content - NG");
  9863.  
  9864. }
  9865.  
  9866.  
  9867. })();
  9868.  
  9869. console1.log("[End]");
  9870.  
  9871. groupEnd();
  9872.  
  9873. }).catch(console.warn);
  9874.  
  9875. }
  9876.  
  9877.  
  9878. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  9879.  
  9880. const hookDocumentMouseDownSetupFn = () => {
  9881.  
  9882. let muzTimestamp = 0;
  9883. let nszDropdown = null;
  9884.  
  9885. const handlerObject = {
  9886.  
  9887. muHandler282: function (evt) {
  9888. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  9889. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9890. const dropdown = nszDropdown;
  9891. muzTimestamp = 0;
  9892. nszDropdown = null;
  9893.  
  9894. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9895. const hostElement = kurMPCe.hostElement || kurMPCe; // should be always hostElement === kurMPCe ?
  9896. if (!hostElement.hasAttribute('menu-visible')) return;
  9897.  
  9898. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  9899. if (chatBanner) return;
  9900.  
  9901. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  9902. muzTimestamp = Date.now();
  9903. evt.stopImmediatePropagation();
  9904. evt.stopPropagation();
  9905. Promise.resolve(dropdown).then((dropdown) => {
  9906. dropdown.cancel();
  9907. dropdown = null;
  9908. });
  9909. }
  9910.  
  9911. },
  9912.  
  9913. mlHandler282: function (evt) {
  9914. muzTimestamp = 0;
  9915. nszDropdown = null;
  9916. },
  9917.  
  9918. ckHandler282: function (evt) {
  9919. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9920. if (Date.now() - muzTimestamp < 40) {
  9921. muzTimestamp = Date.now();
  9922. evt.stopImmediatePropagation();
  9923. evt.stopPropagation();
  9924. }
  9925. },
  9926.  
  9927. tapHandler282: function (evt) {
  9928. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9929. if (Date.now() - muzTimestamp < 40) {
  9930. muzTimestamp = Date.now();
  9931. evt.stopImmediatePropagation();
  9932. evt.stopPropagation();
  9933. }
  9934. },
  9935.  
  9936. handleEvent(evt) {
  9937. if (evt) {
  9938. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9939. const kurMPCc = insp(kurMPCe);
  9940. const hostElement = kurMPCc.hostElement || kurMPCc;
  9941. if (!kurMPCc || kurMPCc.isAttached !== true || hostElement.isConnected !== true) return;
  9942. switch (evt.type) {
  9943. case 'mouseup':
  9944. return this.muHandler282(evt);
  9945. case 'mouseleave':
  9946. return this.mlHandler282(evt);
  9947. case 'tap':
  9948. return this.tapHandler282(evt);
  9949. case 'click':
  9950. return this.ckHandler282(evt);
  9951. }
  9952. }
  9953. }
  9954.  
  9955. }
  9956.  
  9957. document.addEventListener('mousedown', function (evt) {
  9958.  
  9959. if (!evt || !evt.isTrusted || !evt.target) return;
  9960.  
  9961. muzTimestamp = 0;
  9962. nszDropdown = null;
  9963.  
  9964. /** @type {HTMLElement | null} */
  9965. const kurMP = kRef(currentMenuPivotWR);
  9966. if (!kurMP) return;
  9967. const kurMPCe = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0; // element
  9968.  
  9969. if (!kurMPCe || !kurMPCe.hasAttribute('whole-message-clickable')) return;
  9970.  
  9971. const kurMPCc = insp(kurMPCe); // controller
  9972.  
  9973. if (!kurMPCc.isClickableChatRow111 || !kurMPCc.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPCe, evt.target)) return;
  9974.  
  9975. const chatBanner = HTMLElement.prototype.closest.call(kurMPCe, 'yt-live-chat-banner-renderer') || 0;
  9976. if (chatBanner) return;
  9977.  
  9978. let targetDropDown = null;
  9979. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  9980. if (dropdown && dropdown.positionTarget === kurMP) {
  9981. targetDropDown = dropdown;
  9982. }
  9983. }
  9984.  
  9985. if (!targetDropDown) return;
  9986.  
  9987. if ((nszDropdown = targetDropDown)) {
  9988. muzTimestamp = Date.now();
  9989. evt.stopImmediatePropagation();
  9990. evt.stopPropagation();
  9991. currentMenuPivotWR = mWeakRef(kurMPCe);
  9992.  
  9993. const listenOpts = { capture: true, passive: false, once: true };
  9994.  
  9995. // remove unexcecuted eventHandler
  9996. document.removeEventListener('mouseup', handlerObject, listenOpts);
  9997. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  9998. document.removeEventListener('tap', handlerObject, listenOpts);
  9999. document.removeEventListener('click', handlerObject, listenOpts);
  10000.  
  10001. // inject one time eventHandler to by pass events
  10002. document.addEventListener('mouseup', handlerObject, listenOpts);
  10003. document.addEventListener('mouseleave', handlerObject, listenOpts);
  10004. document.addEventListener('tap', handlerObject, listenOpts);
  10005. document.addEventListener('click', handlerObject, listenOpts);
  10006.  
  10007. }
  10008.  
  10009. }, true);
  10010.  
  10011. }
  10012.  
  10013.  
  10014. // yt-live-chat-paid-message-renderer ??
  10015.  
  10016. /*
  10017.  
  10018. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  10019.  
  10020.  
  10021. "yt-live-chat-ticker-paid-message-item-renderer"
  10022. "yt-live-chat-ticker-paid-sticker-item-renderer"
  10023. "yt-live-chat-paid-message-renderer"
  10024. "yt-live-chat-text-message-renderer"
  10025. "yt-live-chat-paid-sticker-renderer"
  10026.  
  10027. */
  10028.  
  10029.  
  10030. whenDefinedMultiple([
  10031.  
  10032. "yt-live-chat-paid-message-renderer",
  10033. "yt-live-chat-membership-item-renderer",
  10034. "yt-live-chat-paid-sticker-renderer",
  10035. "yt-live-chat-text-message-renderer",
  10036. "yt-live-chat-auto-mod-message-renderer",
  10037.  
  10038. /*
  10039. "yt-live-chat-ticker-paid-message-item-renderer",
  10040. "yt-live-chat-ticker-paid-sticker-item-renderer",
  10041. "yt-live-chat-paid-message-renderer",
  10042. "yt-live-chat-text-message-renderer",
  10043. "yt-live-chat-paid-sticker-renderer",
  10044.  
  10045. "yt-live-chat-ticker-sponsor-item-renderer",
  10046. "yt-live-chat-banner-header-renderer",
  10047. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  10048. "ytd-sponsorships-live-chat-header-renderer",
  10049. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  10050.  
  10051.  
  10052.  
  10053.  
  10054. "yt-live-chat-auto-mod-message-renderer",
  10055. "yt-live-chat-text-message-renderer",
  10056. "yt-live-chat-paid-message-renderer",
  10057.  
  10058. "yt-live-chat-legacy-paid-message-renderer",
  10059. "yt-live-chat-membership-item-renderer",
  10060. "yt-live-chat-paid-sticker-renderer",
  10061. "yt-live-chat-donation-announcement-renderer",
  10062. "yt-live-chat-moderation-message-renderer",
  10063. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  10064. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  10065. "yt-live-chat-viewer-engagement-message-renderer",
  10066.  
  10067. */
  10068.  
  10069.  
  10070. ]).then(sTags => {
  10071. // return; // M33
  10072.  
  10073. mightFirstCheckOnYtInit();
  10074. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  10075. console1.log("[Begin]");
  10076. let doMouseHook = false;
  10077.  
  10078. const dProto = {
  10079. isClickableChatRow111: function () {
  10080. return (
  10081. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  10082. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  10083. ); // follow .onItemTap(a)
  10084. }
  10085. };
  10086.  
  10087. for (const sTag of sTags) { // ##tag##
  10088.  
  10089.  
  10090. (() => {
  10091.  
  10092. const tag = sTag;
  10093. const dummy = document.createElement(tag);
  10094.  
  10095. const cProto = getProto(dummy);
  10096. if (!cProto || !cProto.attached) {
  10097. console1.warn(`proto.attached for ${tag} is unavailable.`);
  10098. return;
  10099. }
  10100.  
  10101. const dCnt = insp(dummy);
  10102. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  10103.  
  10104. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  10105.  
  10106. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  10107.  
  10108. if (toHookDocumentMouseDown) {
  10109. doMouseHook = true;
  10110. }
  10111.  
  10112. console1.log("shouldSupportWholeItemClick - OK", tag);
  10113.  
  10114. } else {
  10115.  
  10116. console1.log("shouldSupportWholeItemClick - NG", tag);
  10117. }
  10118.  
  10119.  
  10120. })();
  10121.  
  10122. }
  10123.  
  10124.  
  10125. if (doMouseHook) {
  10126.  
  10127. hookDocumentMouseDownSetupFn();
  10128.  
  10129. console1.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  10130. }
  10131.  
  10132. console1.log("[End]");
  10133.  
  10134. groupEnd();
  10135.  
  10136.  
  10137. }).catch(console.warn);
  10138.  
  10139.  
  10140. // https://www.youtube.com/watch?v=oQzFi1NO7io
  10141.  
  10142.  
  10143. }
  10144.  
  10145. if (NO_ITEM_TAP_FOR_NON_STATIONARY_TAP) {
  10146. let targetElementCntWR = null;
  10147. let _e0 = null;
  10148. document.addEventListener('mousedown', (e) => {
  10149. if (!e || !e.isTrusted) return;
  10150. let element = e.target;
  10151. for (; element instanceof HTMLElement; element = element.parentNode) {
  10152. if (element.is) break;
  10153. }
  10154. if (!element || !element.is) return;
  10155. const cnt = insp(element);
  10156. if (typeof cnt.onItemTap === 'function') {
  10157. cnt._onItemTap_isNonStationary = 0;
  10158. const cProto = getProto(element);
  10159. if (!cProto.onItemTap366 && typeof cProto.onItemTap === 'function' && cProto.onItemTap.length === 1) {
  10160. cProto.onItemTap366 = cProto.onItemTap; // note: [onItemTap] .some(function(){...})
  10161. cProto.onItemTap = function (a) {
  10162. const t = this._onItemTap_isNonStationary;
  10163. this._onItemTap_isNonStationary = 0;
  10164. if (t > Date.now()) return;
  10165. return this.onItemTap366.apply(this, arguments)
  10166. }
  10167. }
  10168. _e0 = e;
  10169. targetElementCntWR = mWeakRef(cnt);
  10170. } else {
  10171. _e0 = null;
  10172. targetElementCntWR = null;
  10173. }
  10174. }, { capture: true, passive: true });
  10175.  
  10176. document.addEventListener('mouseup', (e) => {
  10177. if (!e || !e.isTrusted) return;
  10178. const e0 = _e0;
  10179. _e0 = null;
  10180. if (!e0) return;
  10181. const cnt = kRef(targetElementCntWR);
  10182. targetElementCntWR = null;
  10183. if (!cnt) return;
  10184. if (e.timeStamp - e0.timeStamp > TAP_ACTION_DURATION) {
  10185. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10186. } else if (`${window.getSelection()}`.trim().replace(/[\u2000-\u200a\u202f\u2800\u200B\u200C\u200D\uFEFF]+/g, '').length >= 1) {
  10187. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10188. } else {
  10189. const dx = e.clientX - e0.clientX;
  10190. const dy = e.clientY - e0.clientY;
  10191. const dd = Math.sqrt(dx * dx + dy * dy);
  10192. const ddmm = px2mm(dd);
  10193. if (ddmm > 1.0) {
  10194. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10195. } else {
  10196. cnt._onItemTap_isNonStationary = 0;
  10197. }
  10198. }
  10199. }, { capture: true, passive: true });
  10200.  
  10201. }
  10202.  
  10203.  
  10204. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  10205.  
  10206. let rr = null;
  10207. const p1 = new Promise(resolve => {
  10208. rr = resolve;
  10209. });
  10210.  
  10211. const p1unlock = () => {
  10212. const f = rr;
  10213. if (f) {
  10214. rr = null;
  10215. f();
  10216. }
  10217. }
  10218.  
  10219. return {
  10220. p1,
  10221. p1unlock,
  10222. assignLock: (targetCnt, timeout) => {
  10223. targetCnt.__showContextMenu_assign_lock__(p1);
  10224. if (timeout) setTimeout(p1unlock, timeout);
  10225. }
  10226. }
  10227.  
  10228. }
  10229.  
  10230. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  10231.  
  10232. document.addEventListener('mousedown', function (evt) {
  10233.  
  10234. const maxloopDOMTreeElements = 4;
  10235. const maxloopYtCompontents = 4;
  10236. let j1 = 0;
  10237. let j2 = 0;
  10238. let target = (evt || 0).target || 0;
  10239. if (!target) return;
  10240. if (target.closest('ytd-menu-popup-renderer')) return;
  10241.  
  10242. while (target instanceof HTMLElement) {
  10243. if (++j1 > maxloopDOMTreeElements) break;
  10244. if (typeof (target.is || insp(target).is || null) === 'string') break;
  10245. target = nodeParent(target);
  10246. }
  10247. const components = [];
  10248. while (target instanceof HTMLElement) {
  10249. if (++j2 > maxloopYtCompontents) break;
  10250. const cnt = insp(target);
  10251. if (typeof (target.is || cnt.is || null) === 'string') {
  10252. components.push(target);
  10253. }
  10254. if (typeof cnt.showContextMenu === 'function') break;
  10255. target = target.parentComponent || cnt.parentComponent || null;
  10256. }
  10257. if (!(target instanceof HTMLElement)) return;
  10258. const targetCnt = insp(target);
  10259. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  10260. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  10261. return;
  10262. }
  10263.  
  10264. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  10265. if (!endpoint) return;
  10266. if (targetCnt.opened || !targetCnt.isAttached) return;
  10267.  
  10268. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  10269. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  10270. }
  10271.  
  10272. const targetDollar = indr(target);
  10273.  
  10274. let doPreRequest = false;
  10275. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  10276. doPreRequest = true;
  10277. } else if (components.length === 1 && components[0] === target) {
  10278. doPreRequest = true;
  10279. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  10280. doPreRequest = true;
  10281. }
  10282. if (doPreRequest === false) {
  10283. console.log('doPreRequest = fasle on showContextMenu', components);
  10284. return;
  10285. }
  10286.  
  10287. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  10288.  
  10289. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  10290. console.log('preRequest on showContextMenu aborted due to stacked network request');
  10291. return;
  10292. }
  10293.  
  10294.  
  10295. const onSuccess = (a) => {
  10296. /*
  10297.  
  10298. dQ() && (a = a.response);
  10299. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  10300. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  10301.  
  10302. */
  10303.  
  10304. a = a.response || a;
  10305.  
  10306. if (!a) {
  10307. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  10308. return;
  10309. }
  10310.  
  10311. let z = null;
  10312. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  10313.  
  10314. if (z) {
  10315. a = z;
  10316. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  10317. }
  10318.  
  10319. };
  10320. const onFailure = (a) => {
  10321.  
  10322. /*
  10323.  
  10324. if (a instanceof Error || a instanceof Object || a instanceof String)
  10325. var b = a;
  10326. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  10327.  
  10328. */
  10329.  
  10330. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  10331. // console.log('onFailure', a)
  10332.  
  10333. };
  10334.  
  10335. if (doPreRequest) {
  10336.  
  10337. let propertyCounter = 0;
  10338. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  10339. const p1Timeout = 800;
  10340. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  10341.  
  10342. try {
  10343.  
  10344. const onSuccessHelperFn = function () {
  10345. pm1.p1unlock();
  10346. if (propertyCounter !== 5) {
  10347. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  10348. return;
  10349. }
  10350. if (this[proxyKey] !== targetCnt) {
  10351. console.log('Error in prerequest for showContextMenu.this');
  10352. return;
  10353. }
  10354. onSuccess(...arguments);
  10355. };
  10356. const onFailureHelperFn = function () {
  10357. pm1.p1unlock();
  10358. if (propertyCounter !== 5) {
  10359. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  10360. return;
  10361. }
  10362. if (this[proxyKey] !== targetCnt) {
  10363. console.log('Error in prerequest for showContextMenu.this');
  10364. return;
  10365. }
  10366. onFailure(...arguments);
  10367.  
  10368. }
  10369. const fakeTargetCnt = new Proxy({
  10370. __showContextMenu_forceNativeRequest__: 1,
  10371. get handleGetContextMenuResponse_() {
  10372. propertyCounter += 2;
  10373. return onSuccessHelperFn;
  10374. },
  10375. get handleGetContextMenuError() {
  10376. propertyCounter += 3;
  10377. return onFailureHelperFn;
  10378. }
  10379. }, {
  10380. get(_, key, receiver) {
  10381. if (key in _) return _[key];
  10382. if (key === proxyKey) return targetCnt;
  10383.  
  10384. let giveNative = false;
  10385. if (key in targetCnt) {
  10386. if (key === 'data') giveNative = true;
  10387. else if (typeof targetCnt[key] === 'function') giveNative = true;
  10388. }
  10389. if (giveNative) return targetCnt[key];
  10390. }
  10391. });
  10392.  
  10393. const fakeEvent = (() => {
  10394. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  10395. const nf = function () { }
  10396. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  10397.  
  10398. return {
  10399. type: 'tap',
  10400. eventPhase: 0,
  10401. isTrusted: false,
  10402. __composed: true,
  10403. bubbles, cancelable, cancelBubble, timeStamp,
  10404. target, srcElement, defaultPrevented, currentTarget, composed,
  10405. stopPropagation, stopImmediatePropagation, preventDefault
  10406. };
  10407. })(evt);
  10408. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  10409.  
  10410.  
  10411. } catch (e) {
  10412. console.warn(e);
  10413. propertyCounter = 7;
  10414.  
  10415. }
  10416. if (propertyCounter !== 5) {
  10417. console.log('Error in prerequest for showContextMenu', propertyCounter);
  10418. return;
  10419. }
  10420.  
  10421. pm1.assignLock(targetCnt, p1Timeout);
  10422.  
  10423. }
  10424.  
  10425.  
  10426.  
  10427.  
  10428.  
  10429.  
  10430. }, true);
  10431.  
  10432.  
  10433. }
  10434.  
  10435.  
  10436.  
  10437. /*
  10438.  
  10439. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  10440.  
  10441. */
  10442.  
  10443. whenDefinedMultiple([
  10444. "yt-live-chat-ticker-sponsor-item-renderer",
  10445. "yt-live-chat-ticker-paid-message-item-renderer",
  10446.  
  10447. "yt-live-chat-banner-header-renderer",
  10448. "yt-live-chat-text-message-renderer",
  10449. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  10450. "ytd-sponsorships-live-chat-header-renderer",
  10451. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  10452.  
  10453. "yt-live-chat-paid-sticker-renderer",
  10454. "yt-live-chat-viewer-engagement-message-renderer",
  10455. "yt-live-chat-paid-message-renderer"
  10456.  
  10457.  
  10458.  
  10459.  
  10460. ]).then(sTags => {
  10461.  
  10462. mightFirstCheckOnYtInit();
  10463. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  10464. console1.log("[Begin]");
  10465.  
  10466.  
  10467. const __showContextMenu_mutex__ = new Mutex();
  10468. let __showContextMenu_mutex_unlock__ = null;
  10469. let lastShowMenuTarget = null;
  10470.  
  10471.  
  10472.  
  10473.  
  10474. const wm37 = new WeakMap();
  10475.  
  10476. const dProto = {
  10477.  
  10478.  
  10479. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  10480.  
  10481. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  10482. if (a) {
  10483. if (doDeepCopy) a = deepCopy(a);
  10484. wm37.set(endpoint, a);
  10485. } else {
  10486. wm37.remove(endpoint);
  10487. }
  10488. },
  10489. __getCachedEndpointData__: function (endpoint) {
  10490. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  10491. if (endpoint) return wm37.get(endpoint);
  10492. return null;
  10493. },
  10494. /** @type {(resolvedEndpoint: any) => void 0} */
  10495. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  10496.  
  10497. resolvedEndpoint = deepCopy(resolvedEndpoint);
  10498. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  10499. Promise.resolve(resolvedEndpoint).then((resolvedEndpoint) => {
  10500. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  10501. this.showContextMenu_(resolvedEndpoint);
  10502. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  10503. resolvedEndpoint = null;
  10504. });
  10505.  
  10506.  
  10507. },
  10508.  
  10509.  
  10510.  
  10511. showContextMenuForCacheReopen: function (a) {
  10512. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37(a);
  10513. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10514. if (!this.__showContextMenu_forceNativeRequest__) {
  10515. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10516. if (endpoint) {
  10517. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  10518. if (resolvedEndpoint) {
  10519. this.__showCachedContextMenu__(resolvedEndpoint);
  10520. a && a.stopPropagation()
  10521. return;
  10522. }
  10523. }
  10524. }
  10525. return this.showContextMenu37(a);
  10526. },
  10527.  
  10528. showContextMenuForCacheReopen_: function (a) {
  10529. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37_(a);
  10530. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10531. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  10532. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10533. if (endpoint) {
  10534. const f = this.__cacheResolvedEndpointData__;
  10535. if (typeof f === 'function') f(endpoint, a, true);
  10536. }
  10537. }
  10538. return this.showContextMenu37_(a);
  10539. },
  10540.  
  10541. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  10542.  
  10543. showContextMenuWithDisableScroll: function (a) {
  10544.  
  10545. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10546. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  10547.  
  10548. const parentComponent = this.parentComponent;
  10549. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  10550. parentComponent.contextMenuOpen = true; // computeAllowScroll_(contextMenuOpen, moderationModeEnabled): allowScroll = !(contextMenuOpen || moderationModeEnabled)
  10551. }
  10552. }
  10553.  
  10554. return this.showContextMenu48.apply(this, arguments);
  10555.  
  10556. },
  10557.  
  10558. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  10559.  
  10560. __showContextMenu_mutex_unlock_isEmpty__: () => {
  10561. return __showContextMenu_mutex_unlock__ === null;
  10562. },
  10563.  
  10564. __showContextMenu_assign_lock__: function (p) {
  10565.  
  10566. const mutex = __showContextMenu_mutex__;
  10567.  
  10568. mutex.lockWith(unlock => {
  10569. p.then(unlock);
  10570. p = null;
  10571. unlock = null;
  10572. });
  10573.  
  10574. },
  10575.  
  10576. showContextMenuWithMutex: function (a) {
  10577. if (this.__showContextMenu_forceNativeRequest__) return this.showContextMenu47(a);
  10578. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10579. lastShowMenuTarget = this;
  10580. const wNode = mWeakRef(this);
  10581.  
  10582.  
  10583. const mutex = __showContextMenu_mutex__;
  10584.  
  10585. mutex.lockWith(unlock => {
  10586. const cnt = kRef(wNode);
  10587. if (lastShowMenuTarget !== cnt || !cnt) {
  10588. unlock();
  10589. return;
  10590. }
  10591.  
  10592. setTimeout(unlock, 800); // in case network failure
  10593. __showContextMenu_mutex_unlock__ = unlock;
  10594. try {
  10595. cnt.showContextMenu47(a);
  10596. } catch (e) {
  10597. console.warn(e);
  10598. unlock(); // in case function script error
  10599. }
  10600.  
  10601. });
  10602.  
  10603.  
  10604. },
  10605.  
  10606. showContextMenuWithMutex_: function (a) {
  10607.  
  10608. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  10609. __showContextMenu_mutex_unlock__();
  10610. __showContextMenu_mutex_unlock__ = null;
  10611. }
  10612. return this.showContextMenu47_(a);
  10613.  
  10614. }
  10615.  
  10616. }
  10617.  
  10618. for (const tag of sTags) { // ##tag##
  10619.  
  10620. (() => {
  10621.  
  10622. const dummy = document.createElement(tag);
  10623.  
  10624. const cProto = getProto(dummy);
  10625. if (!cProto || !cProto.attached) {
  10626. console1.warn(`proto.attached for ${tag} is unavailable.`);
  10627. return;
  10628. }
  10629.  
  10630.  
  10631. 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) {
  10632. cProto.showContextMenu37_ = cProto.showContextMenu_;
  10633. cProto.showContextMenu37 = cProto.showContextMenu;
  10634. cProto.__showContextMenu_forceNativeRequest__ = 0;
  10635. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  10636. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  10637. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  10638. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  10639. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  10640. console1.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  10641. } else {
  10642. console1.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  10643. }
  10644.  
  10645. 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) {
  10646. cProto.showContextMenu48 = cProto.showContextMenu;
  10647. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  10648. console1.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10649. } else if (!ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU) {
  10650. DEBUG_skipLog001 || console1.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - N/A", tag);
  10651. } else {
  10652. console1.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10653. }
  10654.  
  10655.  
  10656. 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) {
  10657. cProto.showContextMenu47_ = cProto.showContextMenu_;
  10658. cProto.showContextMenu47 = cProto.showContextMenu;
  10659. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  10660. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  10661. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  10662. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  10663. console1.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10664. } else {
  10665. console1.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10666. }
  10667.  
  10668. })();
  10669.  
  10670. }
  10671.  
  10672. console1.log("[End]");
  10673.  
  10674. groupEnd();
  10675.  
  10676. }).catch(console.warn);
  10677.  
  10678.  
  10679.  
  10680. if (FIX_UNKNOWN_BUG_FOR_OVERLAY) {
  10681. // this is to fix " TypeError: this.backdropElement.prepare is not a function "
  10682.  
  10683. customElements.whenDefined('tp-yt-paper-dialog').then(() => {
  10684.  
  10685.  
  10686. mightFirstCheckOnYtInit();
  10687. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-dialog hacks");
  10688. console1.log("[Begin]");
  10689. (() => {
  10690.  
  10691. const tag = "tp-yt-paper-dialog";
  10692. const dummy = document.createElement(tag);
  10693.  
  10694. const cProto = getProto(dummy);
  10695. if (!cProto || !cProto.attached) {
  10696. console1.warn(`proto.attached for ${tag} is unavailable.`);
  10697. return;
  10698. }
  10699.  
  10700. if (typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged49 && cProto.__openedChanged.length === 0) {
  10701.  
  10702.  
  10703. cProto.__openedChanged49 = cProto.__openedChanged;
  10704.  
  10705. cProto.__openedChanged = function () {
  10706. const manager = (this || 0)._manager || 0;
  10707. if (manager && !manager.trackBackdrop49 && manager.trackBackdrop) {
  10708. manager.trackBackdrop49 = manager.trackBackdrop;
  10709. if (manager.trackBackdrop.length === 0) {
  10710. manager.trackBackdrop = function () {
  10711. try {
  10712. return this.trackBackdrop49();
  10713. } catch (e) {
  10714. let showMessage = true;
  10715. if (e instanceof TypeError && e.message === 'this.backdropElement.prepare is not a function') {
  10716. // this is well known issue.
  10717. showMessage = false;
  10718. }
  10719. showMessage && console.log('manager.trackBackdrop', e);
  10720. }
  10721. }
  10722. }
  10723. }
  10724. return this.__openedChanged49();
  10725. };
  10726.  
  10727.  
  10728. }
  10729.  
  10730.  
  10731. })();
  10732.  
  10733.  
  10734. console1.log("[End]");
  10735.  
  10736. groupEnd();
  10737.  
  10738.  
  10739. }).catch(console.warn);
  10740.  
  10741. }
  10742.  
  10743.  
  10744. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  10745.  
  10746. mightFirstCheckOnYtInit();
  10747. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  10748. console1.log("[Begin]");
  10749. (() => {
  10750.  
  10751. const tag = "tp-yt-iron-dropdown";
  10752. const dummy = document.createElement(tag);
  10753.  
  10754. const cProto = getProto(dummy);
  10755. if (!cProto || !cProto.attached) {
  10756. console1.warn(`proto.attached for ${tag} is unavailable.`);
  10757. return;
  10758. }
  10759.  
  10760. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  10761. cProto.__deraf_hn__ = function (sId, fn) {
  10762. const rhKey = `_rafHandler_${sId}`;
  10763. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  10764. if (m.has(fn)) return m.get(fn);
  10765. const resFn = () => {
  10766. this.__rafs[sId] = null;
  10767. fn.call(this)
  10768. };
  10769. m.set(fn, resFn);
  10770. m.set(resFn, resFn);
  10771. return resFn;
  10772. };
  10773. cProto.__deraf34 = cProto.__deraf;
  10774. cProto.__deraf = function (a, b) { // sId, fn
  10775. let c = this.__rafs;
  10776. null !== c[a] && cancelAnimationFrame(c[a]);
  10777. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  10778. };
  10779. console1.log("USE_VANILLA_DEREF - OK");
  10780. } else {
  10781. console1.log("USE_VANILLA_DEREF - NG");
  10782. }
  10783.  
  10784. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  10785. cProto.__deraf66 = cProto.__deraf;
  10786. cProto.__deraf = function (sId, fn) {
  10787. if (this.__byPassRAF__) {
  10788. Promise.resolve(this).then((cnt) => {
  10789. fn.call(cnt);
  10790. cnt = null;
  10791. });
  10792. }
  10793. let r = this.__deraf66.apply(this, arguments);
  10794. return r;
  10795. }
  10796. console1.log("FIX_DROPDOWN_DERAF - OK");
  10797. } else {
  10798. console1.log("FIX_DROPDOWN_DERAF - NG");
  10799. }
  10800.  
  10801.  
  10802. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  10803.  
  10804. let lastClose = null;
  10805. let lastOpen = null;
  10806. let cid = 0;
  10807.  
  10808. cProto.__mtChanged__ = function (b) {
  10809.  
  10810. Promise.resolve(this).then((cnt) => {
  10811. cnt._applyFocus();
  10812. return cnt;
  10813. }).then((cnt) => {
  10814. b ? cnt._renderOpened() : cnt._renderClosed();
  10815. cnt = null;
  10816. }).catch(console.warn);
  10817.  
  10818. };
  10819.  
  10820. const __moChanged__ = () => {
  10821. if (!cid) return;
  10822. // console.log(553, !!lastOpen, !!lastClose);
  10823. cid = 0;
  10824. if (lastOpen && !lastClose && lastOpen.isAttached) {
  10825. lastOpen.__mtChanged__(1)
  10826. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  10827. lastClose.__mtChanged__(0);
  10828. }
  10829. lastOpen = null;
  10830. lastClose = null;
  10831. };
  10832.  
  10833.  
  10834. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  10835. cProto._openedChanged66 = cProto._openedChanged;
  10836. cProto._openedChanged = function () {
  10837. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  10838. this.__byPassRAF__ = true;
  10839. let r = this._openedChanged66.apply(this, arguments);
  10840. this.__byPassRAF__ = false;
  10841. return r;
  10842. }
  10843. }
  10844.  
  10845. const pSetGet = (key, pdThis, pdBase) => {
  10846. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  10847. return {
  10848. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  10849. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  10850. };
  10851. };
  10852.  
  10853. cProto.__modifiedMenuPropsFn__ = function () {
  10854. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  10855. const pdBase = Object.getOwnPropertyDescriptors(this)
  10856.  
  10857. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  10858. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  10859. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  10860.  
  10861. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  10862. console.warn('there is setter/getter for autoFitOnAttach');
  10863. return;
  10864. }
  10865. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  10866. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  10867. return;
  10868. }
  10869. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  10870. console.warn('there is NO setter-getter for allowOutsideScroll');
  10871. return;
  10872. }
  10873.  
  10874. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  10875.  
  10876. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  10877.  
  10878. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  10879.  
  10880. Object.defineProperties(this, {
  10881. autoFitOnAttach: {
  10882. get() {
  10883. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10884. return autoFitOnAttach;
  10885. },
  10886. set(nv) {
  10887. autoFitOnAttach = nv;
  10888. return true;
  10889. },
  10890. enumerable: true,
  10891. configurable: true
  10892. }, expandSizingTargetForScrollbars: {
  10893. get() {
  10894. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10895. return expandSizingTargetForScrollbars;
  10896. },
  10897. set(nv) {
  10898. expandSizingTargetForScrollbars = nv;
  10899. return true;
  10900. },
  10901. enumerable: true,
  10902. configurable: true
  10903. }, allowOutsideScroll: {
  10904. get() {
  10905. if (this._modifiedMenuPropOn062__) return true;
  10906. return allowOutsideScroll;
  10907. },
  10908. set(nv) {
  10909. allowOutsideScroll = nv;
  10910. this.__AllowOutsideScrollPD__.set.call(this, nv);
  10911. return true;
  10912. },
  10913. enumerable: true,
  10914. configurable: true
  10915. }
  10916. })
  10917. };
  10918.  
  10919. /*
  10920. // ***** position() to be changed. *****
  10921. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  10922.  
  10923. overflow: visible !important;
  10924. min-width: max-content !important;
  10925. max-width: max-content !important;
  10926. max-height: max-content !important;
  10927. min-height: max-content !important;
  10928. white-space: nowrap;
  10929. }
  10930.  
  10931. */
  10932. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  10933.  
  10934. let m34 = 0;
  10935. cProto.__refitByPosition__ = function () {
  10936. m34++;
  10937. if (m34 <= 0) m34 = 0;
  10938. if (m34 !== 1) return;
  10939. const hostElement = this.hostElement || this;
  10940. if (document.visibilityState === 'visible') {
  10941. const sizingTarget = this.sizingTarget;
  10942. if (!sizingTarget) {
  10943. m34 = 0;
  10944. return;
  10945. }
  10946. hostElement.setAttribute('rNgzQ', '');
  10947. sizingTarget.setAttribute('rNgzQ', '');
  10948.  
  10949. const gn = () => {
  10950. hostElement.removeAttribute('rNgzQ');
  10951. sizingTarget.removeAttribute('rNgzQ');
  10952. }
  10953.  
  10954. const an = async () => {
  10955. while (m34 >= 1) {
  10956. await renderReadyPn(sizingTarget);
  10957. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  10958. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  10959. }
  10960. m34--;
  10961. }
  10962. m34 = 0;
  10963. Promise.resolve().then(gn);
  10964. }
  10965. setTimeout(an, 4); // wait those resizing function calls
  10966.  
  10967.  
  10968. } else {
  10969. m34 = 0;
  10970. }
  10971. }
  10972. cProto.position34 = cProto.position
  10973. cProto.position = function () {
  10974. if (this._positionInitialize_) {
  10975. this._positionInitialize_ = 0;
  10976. this.__refitByPosition__();
  10977. }
  10978. let r = cProto.position34.apply(this, arguments);
  10979. return r;
  10980. }
  10981. console1.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  10982.  
  10983. } else {
  10984.  
  10985. console1.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  10986.  
  10987. }
  10988.  
  10989.  
  10990.  
  10991. cProto.__openedChanged = function () {
  10992. // console.log(123445)
  10993. this._positionInitialize_ = 1;
  10994. // this.removeAttribute('horizontal-align')
  10995. // this.removeAttribute('vertical-align')
  10996. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  10997. this.__menuTypeCheck__ = true;
  10998. if (CHAT_MENU_SCROLL_UNLOCKING) {
  10999. this._modifiedMenuPropOn062__ = false;
  11000. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  11001. // this.autoFitOnAttach = true;
  11002. // this.expandSizingTargetForScrollbars = true;
  11003. // this.allowOutsideScroll = true;
  11004. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  11005. this.__modifiedMenuPropsFn__();
  11006. // this.constrain= function(){}
  11007. // this.position= function(){}
  11008.  
  11009. // this.autoFitOnAttach = true;
  11010. // this.expandSizingTargetForScrollbars = true;
  11011. // this.allowOutsideScroll = true;
  11012. }
  11013. }
  11014. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  11015. let newValue = null;
  11016. const positionTarget = this.positionTarget;
  11017. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  11018. if (this._modifiedMenuPropOn062__ === false) {
  11019. newValue = true;
  11020. }
  11021. } else if (this._modifiedMenuPropOn062__ === true) {
  11022. newValue = false;
  11023. }
  11024. if (newValue !== null) {
  11025. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  11026. this._modifiedMenuPropOn062__ = newValue;
  11027. const afterAllowOutsideScroll = this.allowOutsideScroll;
  11028. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  11029. }
  11030. }
  11031.  
  11032. if (this.opened) {
  11033.  
  11034. Promise.resolve().then(() => {
  11035.  
  11036. this._prepareRenderOpened();
  11037. }).then(() => {
  11038. // console.log('[yt-chat-dialog]', this._manager)
  11039. try{
  11040. this._manager.addOverlay(this);
  11041. }catch(e){
  11042. console.log('this._manager.addOverlay(this) fails.')
  11043. }
  11044. if (this._manager._overlays.length === 1) {
  11045. lastOpen = this;
  11046. lastClose = null;
  11047. } else {
  11048. return 1;
  11049. }
  11050. // if (cid) {
  11051. // clearTimeout(cid);
  11052. // cid = -1;
  11053. // this.__moChanged__();
  11054. // cid = 0;
  11055. // } else {
  11056. // cid = -1;
  11057. // this.__moChanged__();
  11058. // cid = 0;
  11059. // }
  11060. // cid = cid > 0 ? clearTimeout(cid) : 0;
  11061. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  11062. // cid = cid || setTimeout(__moChanged__, delay1);
  11063. cid = cid || requestAnimationFrame(__moChanged__);
  11064. }).then((r) => {
  11065.  
  11066. if (r) this.__mtChanged__(1);
  11067. }).catch(console.warn);
  11068.  
  11069. } else {
  11070. Promise.resolve().then(() => {
  11071. // console.log('[yt-chat-dialog]', this._manager)
  11072. try{
  11073. this._manager.removeOverlay(this);
  11074. }catch(e){
  11075. console.log('this._manager.removeOverlay(this) fails.')
  11076. }
  11077. if (this._manager._overlays.length === 0) {
  11078. lastClose = this;
  11079. lastOpen = null;
  11080. } else {
  11081. return 1;
  11082. }
  11083. // cid = cid > 0 ? clearTimeout(cid) : 0;
  11084. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  11085. // cid = cid || setTimeout(__moChanged__, delay1);
  11086. cid = cid || requestAnimationFrame(__moChanged__);
  11087. }).then((r) => {
  11088. if (r) this.__mtChanged__(0);
  11089. }).catch(console.warn);
  11090.  
  11091. }
  11092.  
  11093. }
  11094. console1.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  11095.  
  11096. } else {
  11097.  
  11098. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  11099. console1.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  11100.  
  11101. }
  11102.  
  11103.  
  11104. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  11105.  
  11106. cProto.__openedChanged82 = cProto.__openedChanged;
  11107.  
  11108.  
  11109. cProto.__openedChanged = function () {
  11110. const positionTarget = this.positionTarget;
  11111. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  11112. return this.__openedChanged82.apply(this, arguments);
  11113. }
  11114. }
  11115.  
  11116.  
  11117. })();
  11118.  
  11119. console1.log("[End]");
  11120.  
  11121. groupEnd();
  11122.  
  11123. }).catch(console.warn);
  11124.  
  11125.  
  11126.  
  11127. FIX_ToggleRenderPolymerControllerExtractionBug && customElements.whenDefined('yt-live-chat-toggle-renderer').then(() => {
  11128.  
  11129. mightFirstCheckOnYtInit();
  11130. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-toggle-renderer hacks");
  11131. console1.log("[Begin]");
  11132. (() => {
  11133.  
  11134. const tag = "yt-live-chat-toggle-renderer";
  11135. const dummy = document.createElement(tag);
  11136.  
  11137. const cProto = getProto(dummy);
  11138. if (!cProto || !cProto.attached) {
  11139. console1.warn(`proto.attached for ${tag} is unavailable.`);
  11140. return;
  11141. }
  11142.  
  11143. })();
  11144.  
  11145. console1.log("[End]");
  11146. groupEnd();
  11147.  
  11148. });
  11149.  
  11150. FIX_MOUSEOVER_FN && (() => {
  11151.  
  11152. // this is to show tooltip for emoji
  11153.  
  11154.  
  11155. let lastShow = 0;
  11156.  
  11157. const wm = new WeakSet();
  11158. const mo1 = new MutationObserver((mutations) => {
  11159.  
  11160. for (const p of document.querySelectorAll('[shared-tooltip-text]:not([__a6cwm__])')) {
  11161. p.setAttribute('__a6cwm__', '');
  11162. }
  11163.  
  11164. });
  11165. mo1.observe(document, { subtree: true, attributes: true, attributeFilter: ['shared-tooltip-text'], childList: true });
  11166.  
  11167. const mo2 = new MutationObserver((mutations) => {
  11168.  
  11169. for (const mutation of mutations) {
  11170. const p = mutation.target;
  11171. if (mutation.attributeName) {
  11172. if (p.getAttribute('shared-tooltip-text')) { // allow hack
  11173. wm.add(p);
  11174. for (const e of p.getElementsByTagName('*')) {
  11175. wm.add(e);
  11176. }
  11177. } else {
  11178. if (wm.has(p)) {
  11179. wm.remove(p);
  11180. for (const e of p.getElementsByTagName('*')) {
  11181. wm.remove(e);
  11182. }
  11183. }
  11184. }
  11185. }
  11186. }
  11187. });
  11188. mo2.observe(document, { subtree: true, attributes: true, attributeFilter: ['__a6cwm__', 'shared-tooltip-text'], childList: false });
  11189.  
  11190.  
  11191. let done = 0;
  11192. // lcrFn2 will run twice to ensure the method is successfully injected.
  11193. const lcrFn2 = (lcrDummy) => {
  11194. // make minimal function overhead by pre-defining all possible outside.
  11195.  
  11196. const tag = "yt-live-chat-renderer"
  11197. const dummy = lcrDummy;
  11198.  
  11199. const cProto = getProto(dummy);
  11200. if (!cProto || !cProto.attached) {
  11201. console.warn(`proto.attached for ${tag} is unavailable.`);
  11202. return;
  11203. }
  11204.  
  11205. // mightFirstCheckOnYtInit();
  11206. // groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  11207. // console.log("[Begin]");
  11208.  
  11209.  
  11210.  
  11211. if (done !== 1 && typeof cProto.onMouseOver_ === 'function' && !cProto.onMouseOver37_ && typeof cProto.createTooltipIfRequired_ === 'function' && cProto.createTooltipIfRequired_.length === 0) {
  11212.  
  11213. done = 1;
  11214. const onMouseOver37_ = cProto.onMouseOver37_ = cProto.onMouseOver_;
  11215.  
  11216. const checkMatch = (() => {
  11217.  
  11218.  
  11219. let accessList = [];
  11220. let withError = false;
  11221. try {
  11222.  
  11223. onMouseOver37_.call(lcrDummy, {
  11224. type: 'mouseover',
  11225. target: new Proxy({
  11226. nodeName: 'DIV',
  11227. tagName: 'DIV',
  11228. getAttribute: function () { },
  11229. parentNode: null
  11230. }, {
  11231. get(target, p) {
  11232. accessList.push(`getter:${p}`);
  11233. if (!(p in target)) throw Error(`getter ${p} is not found`);
  11234. },
  11235. set(target, p, v) {
  11236. accessList.push(`setter:${p}`);
  11237. throw Error(`setter ${p} is not found`);
  11238. }
  11239. })
  11240. });
  11241. } catch (e) {
  11242. withError = true;
  11243. // console.warn(e);
  11244. }
  11245.  
  11246. if (withError) return false;
  11247.  
  11248. if (accessList.join(',') !== 'getter:getAttribute,getter:parentNode') return false;
  11249.  
  11250. accessList.length = 0;
  11251.  
  11252. let parent;
  11253. try {
  11254.  
  11255. parent = new Proxy({
  11256. nodeName: 'DIV',
  11257. tagName: 'DIV',
  11258. getAttribute: function (e) {
  11259.  
  11260. accessList.push(`getter:getAttribute(${e})`);
  11261. return e === 'shared-tooltip-text' ? ':cherry_blossom:' : null;
  11262.  
  11263. },
  11264. parentNode: null
  11265. }, {
  11266. get(target, p) {
  11267. accessList.push(`getter:${p}`);
  11268. if (!(p in target)) throw Error(`getter ${p} is not found`);
  11269. return target[p]
  11270. },
  11271. set(target, p, v) {
  11272. accessList.push(`setter:${p}`);
  11273. throw Error(`setter ${p} is not found`);
  11274. }
  11275. });
  11276.  
  11277. onMouseOver37_.call(lcrDummy, {
  11278. type: 'mouseover',
  11279. target: new Proxy({
  11280. nodeName: 'IMG',
  11281. tagName: 'IMG',
  11282. id: 'img',
  11283. getAttribute: function (e) {
  11284.  
  11285. accessList.push(`getter:getAttribute(${e})`);
  11286. return e === 'shared-tooltip-text' ? ':cherry_blossom:' : null;
  11287.  
  11288. },
  11289. get parentNode() {
  11290. return parent
  11291. },
  11292. get parentElement() {
  11293. return parent
  11294. }
  11295. }, {
  11296. get(target, p) {
  11297. accessList.push(`getter:${p}`);
  11298. if (!(p in target)) throw Error(`getter ${p} is not found`);
  11299. return target[p]
  11300. },
  11301. set(target, p, v) {
  11302. accessList.push(`setter:${p}`);
  11303. throw Error(`setter ${p} is not found`);
  11304. }
  11305. })
  11306. });
  11307. } catch (e) {
  11308. withError = true;
  11309. // console.warn(e);
  11310. }
  11311. parent = null;
  11312.  
  11313. if (withError && accessList.join(',') === 'getter:getAttribute,getter:getAttribute,getter:getAttribute(shared-tooltip-text),getter:getAttribute,getter:getAttribute(shared-tooltip-text),getter:tagName,getter:parentElement,getter:id,getter:id,getter:$$') {
  11314. return true;
  11315. }
  11316.  
  11317.  
  11318.  
  11319. })();
  11320. if (checkMatch) {
  11321.  
  11322. cProto.onMouseOver_ = function (evt) {
  11323. const p = (evt || 0).target || 0;
  11324. if (p.nodeType === 1 && wm.has(p)) {
  11325. const ct = Date.now();
  11326. if (lastShow + 18 > ct) return;
  11327. const cnt = insp(this);
  11328. lastShow = ct;
  11329. try {
  11330. cnt.onMouseOver37_.call(this, evt);
  11331. } catch (e) {
  11332. console.warn(e);
  11333. }
  11334. }
  11335. };
  11336.  
  11337. const lcrs = [...new Set([lcrDummy, ...document.querySelectorAll('yt-live-chat-renderer')])];
  11338. for (const lcr of lcrs) {
  11339. const cnt = insp(lcr);
  11340. const hostElement = cnt.hostElement;
  11341. if (hostElement && cnt.isAttached === true && cnt.onMouseOver37_ === cProto.onMouseOver37_ && typeof cProto.onMouseOver_ === 'function' && cProto.onMouseOver_ !== cProto.onMouseOver37_ && cnt.onMouseOver_ === cProto.onMouseOver_) {
  11342. hostElement.removeEventListener("mouseover", cProto.onMouseOver37_, !0)
  11343. hostElement.addEventListener("mouseover", cProto.onMouseOver_, !0)
  11344. }
  11345. }
  11346.  
  11347. console.log('[yt-chat-lcr] FIX_MOUSEOVER_FN - OK')
  11348.  
  11349. } else {
  11350.  
  11351. console.log('[yt-chat-lcr] FIX_MOUSEOVER_FN - NG')
  11352.  
  11353. }
  11354.  
  11355. } else if (done !== 1) {
  11356. done = 2;
  11357. console.log('[yt-chat-lcr] FIX_MOUSEOVER_FN - NG')
  11358. }
  11359.  
  11360. // console.log("[End]");
  11361. // groupEnd();
  11362.  
  11363.  
  11364. };
  11365. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  11366. // getLCRDummy() must be called for injection
  11367. getLCRDummy().then(lcrFn2);
  11368.  
  11369. })();
  11370.  
  11371.  
  11372. /*
  11373.  
  11374.  
  11375.  
  11376.  
  11377.  
  11378. var FU = function() {
  11379. var a = this;
  11380. this.nextHandle_ = 1;
  11381. this.clients_ = {};
  11382. this.JSC$10323_callbacks_ = {};
  11383. this.unsubscribeAsyncHandles_ = {};
  11384. this.subscribe = vl(function(b, c, d) {
  11385. var e = Geb(b);
  11386. if (e in a.clients_)
  11387. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  11388. else {
  11389. a: {
  11390. var h = Geb(b), l;
  11391. for (l in a.unsubscribeAsyncHandles_) {
  11392. var m = a.clients_[l];
  11393. if (m instanceof KO) {
  11394. delete a.clients_[l];
  11395. delete a.JSC$10323_callbacks_[l];
  11396. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  11397. delete a.unsubscribeAsyncHandles_[l];
  11398. i6a(m);
  11399. m.objectId_ = new FQa(h);
  11400. m.register();
  11401. d = m;
  11402. break a
  11403. }
  11404. }
  11405. d.objectSource = b.invalidationId.objectSource;
  11406. d.objectId = h;
  11407. if (b = b.webAuthConfigurationData)
  11408. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  11409. b.pageId && (d.pageId = b.pageId);
  11410. d = new KO(d,a.handleInvalidationData_.bind(a));
  11411. d.register()
  11412. }
  11413. a.clients_[e] = d;
  11414. a.JSC$10323_callbacks_[e] = {}
  11415. }
  11416. d = a.nextHandle_++;
  11417. a.JSC$10323_callbacks_[e][d] = c;
  11418. return d
  11419. })
  11420. };
  11421. FU.prototype.unsubscribe = function(a, b) {
  11422. var c = Geb(a);
  11423. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  11424. !this.JSC$10323_callbacks_[c].length)) {
  11425. var d = this.clients_[c];
  11426. b = Jq.run(function() {
  11427. ei(d);
  11428. delete this.clients_[c];
  11429. delete this.unsubscribeAsyncHandles_[c]
  11430. }
  11431. .bind(this));
  11432. this.unsubscribeAsyncHandles_[c] = b
  11433. }
  11434. }
  11435. ;
  11436.  
  11437.  
  11438. */
  11439.  
  11440.  
  11441. const onManagerFound = (dummyManager) => {
  11442. if (!dummyManager || typeof dummyManager !== 'object') return;
  11443.  
  11444. const mgrProto = dummyManager.constructor.prototype;
  11445.  
  11446. let keyCallbackStore = '';
  11447. for (const [key, v] of Object.entries(dummyManager)) {
  11448. if (key.includes('_callbacks_')) keyCallbackStore = key;
  11449. }
  11450.  
  11451. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  11452.  
  11453. if (mgrProto.unsubscribe16) return;
  11454.  
  11455. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  11456.  
  11457. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  11458. console1.log("[Begin]");
  11459.  
  11460. const idMapper = new Map();
  11461.  
  11462. const convertId = function (objectId) {
  11463. if (!objectId || typeof objectId !== 'string') return null;
  11464.  
  11465. let result = idMapper.get(objectId)
  11466. if (result) return result;
  11467. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  11468. idMapper.set(objectId, result)
  11469. return result;
  11470. }
  11471.  
  11472.  
  11473. const rafHandleHolder = [];
  11474.  
  11475. let pzw = 0;
  11476. let lza = 0;
  11477. const rafHandlerFn = () => {
  11478. pzw = 0;
  11479. if (rafHandleHolder.length === 1) {
  11480. const f = rafHandleHolder[0];
  11481. rafHandleHolder.length = 0;
  11482. f();
  11483. } else if (rafHandleHolder.length > 1) {
  11484. const arr = rafHandleHolder.slice(0);
  11485. rafHandleHolder.length = 0;
  11486. for (const fn of arr) fn();
  11487. }
  11488. };
  11489.  
  11490.  
  11491. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  11492.  
  11493. const checkIntegrityForSubscribe = (mgr) => {
  11494. if (mgr
  11495. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  11496. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  11497.  
  11498. const ns = new Set(Object.keys(mgr));
  11499. const ms = new Set(Object.keys(mgr.constructor.prototype));
  11500.  
  11501. if (ns.size >= 6 && ms.size >= 4) {
  11502. // including 'subscribe18'
  11503. // 'unsubscribe16', 'subscribe19'
  11504.  
  11505. let r = 0;
  11506. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  11507. r += ns.has(k) ? 1 : 0;
  11508. }
  11509. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  11510. r += ms.has(k) ? 1 : 0;
  11511. }
  11512. if (r === 10) {
  11513. const isObject = (c) => (c || 0).constructor === Object;
  11514.  
  11515. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  11516.  
  11517. return true;
  11518. }
  11519.  
  11520.  
  11521. }
  11522.  
  11523. }
  11524.  
  11525.  
  11526. }
  11527. return false;
  11528. }
  11529.  
  11530. mgrProto.subscribe19 = function (o, f, opts) {
  11531.  
  11532. const ct_clients_ = this.clients_ || 0;
  11533. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  11534.  
  11535. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  11536.  
  11537. let objectId = ((o || 0).invalidationId || 0).objectId;
  11538. if (!objectId) return this.subscribe18.apply(this, arguments);
  11539. objectId = convertId(objectId);
  11540.  
  11541. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  11542.  
  11543. if (ct_clients_[objectId]) {
  11544. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  11545. }
  11546.  
  11547. return this.subscribe18.apply(this, arguments);
  11548. }
  11549.  
  11550. mgrProto.unsubscribe = function (o, d) {
  11551. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  11552. this.subscribe18 = this.subscribe;
  11553. this.subscribe = this.subscribe19;
  11554. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  11555. }
  11556. const ct_clients_ = this.clients_;
  11557. const ct_handles_ = this.unsubscribeAsyncHandles_;
  11558. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  11559.  
  11560. let objectId = ((o || 0).invalidationId || 0).objectId;
  11561. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  11562.  
  11563. objectId = convertId(objectId);
  11564.  
  11565.  
  11566. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  11567.  
  11568. const callbacks = this[keyCallbackStore] || 0;
  11569. const callbackObj = callbacks[objectId] || 0;
  11570.  
  11571.  
  11572. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  11573. const w = ct_clients_[objectId];
  11574. lza = (lza & 1073741823) + 1;
  11575. const qta = -lza;
  11576. rafHandleHolder.push(() => {
  11577. if (qta === ct_handles_[objectId]) {
  11578. const o = {
  11579. callbacks, callbackObj,
  11580. client: ct_clients_[objectId],
  11581. handle: ct_handles_[objectId]
  11582. };
  11583. let p = 0;
  11584. try {
  11585. if (ct_clients_[objectId] === w) {
  11586. w && "function" === typeof w.dispose && w.dispose();
  11587. delete ct_clients_[objectId];
  11588. delete ct_handles_[objectId];
  11589. p = 1;
  11590. } else {
  11591. // w && "function" === typeof w.dispose && w.dispose();
  11592. // delete ct_clients_[objectId];
  11593. // delete ct_handles_[objectId];
  11594. p = 2;
  11595. }
  11596. } catch (e) {
  11597. console.warn(e);
  11598. }
  11599. console.log(`unsubscribed: ${p}`, this, o);
  11600. }
  11601. });
  11602. ct_handles_[objectId] = qta;
  11603. if (pzw === 0) {
  11604. pzw = requestAnimationFrame(rafHandlerFn);
  11605. }
  11606. }
  11607. }
  11608.  
  11609.  
  11610. console1.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  11611.  
  11612. } else {
  11613.  
  11614. console1.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  11615. }
  11616.  
  11617. console1.log("[End]");
  11618.  
  11619. groupEnd();
  11620.  
  11621. }
  11622.  
  11623.  
  11624.  
  11625. /*
  11626.  
  11627.  
  11628. a.prototype.async = function(e, h) {
  11629. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  11630. }
  11631. ;
  11632. a.prototype.cancelAsync = function(e) {
  11633. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  11634. }
  11635.  
  11636. */
  11637.  
  11638.  
  11639. (FASTER_ICON_RENDERING && Promise.all(
  11640. [
  11641. customElements.whenDefined("yt-icon-shape"),
  11642. customElements.whenDefined("yt-icon")
  11643. // document.createElement('icon-shape'),
  11644. ]
  11645. )).then(() => {
  11646. let cq = 0;
  11647. let dummys = [document.createElement('yt-icon-shape'), document.createElement('yt-icon')]
  11648. for (const dummy of dummys) {
  11649. let cProto = getProto(dummy);
  11650. if (cProto && typeof cProto.shouldRenderIconShape === 'function' && !cProto.shouldRenderIconShape571 && cProto.shouldRenderIconShape.length === 1) {
  11651. assertor(() => fnIntegrity(cProto.shouldRenderIconShape, '1.70.38'));
  11652. cq++;
  11653. cProto.shouldRenderIconShape571 = cProto.shouldRenderIconShape;
  11654. cProto.shouldRenderIconShape = function (a) {
  11655. if (this.isAnimatedIcon) return this.shouldRenderIconShape571(a);
  11656. if (!this.iconType || !this.iconShapeData) return this.shouldRenderIconShape571(a);
  11657. if (!this.iconName) return this.shouldRenderIconShape571(a);
  11658. return false;
  11659. // console.log(1051, this.iconType)
  11660. // console.log(1052, this.iconShapeData)
  11661. // console.log(1053, this.isAnimatedIcon)
  11662. }
  11663. }
  11664. // if(cProto && cProto.switchTemplateAtRegistration){
  11665. // cProto.switchTemplateAtRegistration = false;
  11666. // }
  11667. }
  11668. if (cq === 1) {
  11669. console.log("modified shouldRenderIconShape - Y")
  11670. } else {
  11671. console.log("modified shouldRenderIconShape - N", cq)
  11672. }
  11673. });
  11674.  
  11675. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  11676.  
  11677. let __dummyManager__ = null;
  11678.  
  11679. mightFirstCheckOnYtInit();
  11680. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  11681. console1.log("[Begin]");
  11682. (() => {
  11683.  
  11684. const tag = "yt-invalidation-continuation"
  11685. const dummy = document.createElement(tag);
  11686.  
  11687. const cProto = getProto(dummy);
  11688. if (!cProto || !cProto.attached) {
  11689. console1.warn(`proto.attached for ${tag} is unavailable.`);
  11690. return;
  11691. }
  11692.  
  11693. const dummyManager = insp(dummy).manager_ || 0;
  11694. __dummyManager__ = dummyManager;
  11695.  
  11696.  
  11697. })();
  11698.  
  11699. console1.log("[End]");
  11700.  
  11701. groupEnd();
  11702.  
  11703.  
  11704.  
  11705. onManagerFound(__dummyManager__);
  11706.  
  11707. }).catch(console.warn);
  11708.  
  11709.  
  11710. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  11711.  
  11712. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  11713.  
  11714. mightFirstCheckOnYtInit();
  11715. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  11716. console1.log("[Begin]");
  11717. (() => {
  11718.  
  11719. const tag = "yt-live-interactivity-component-background"
  11720. const dummy = document.createElement(tag);
  11721.  
  11722. const cProto = getProto(dummy);
  11723. if (!cProto || !cProto.attached) {
  11724. console1.warn(`proto.attached for ${tag} is unavailable.`);
  11725. return;
  11726. }
  11727.  
  11728. cProto.__toStopAfterRun__ = function (hostElement) {
  11729. let mo = new MutationObserver(() => {
  11730. mo.disconnect();
  11731. mo.takeRecords();
  11732. mo = null;
  11733. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  11734. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  11735. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  11736. });
  11737. });
  11738. mo.observe(hostElement, { subtree: true, childList: true });
  11739. }
  11740.  
  11741. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  11742.  
  11743. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  11744. cProto.maybeLoadAnimationBackground = function () {
  11745. let toRun = true;
  11746. let stopAfterRun = false;
  11747. if (!this.__bypassDisableAnimationBackground__) {
  11748. let doFix = false;
  11749. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  11750. if (!this.lottieAnimation) {
  11751. doFix = true;
  11752. }
  11753. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  11754. doFix = true;
  11755. }
  11756. if (doFix) {
  11757. if (this.useAnimationBackground === true) {
  11758. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  11759. }
  11760. toRun = true;
  11761. stopAfterRun = true;
  11762. }
  11763. }
  11764. if (toRun) {
  11765. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  11766. this.__toStopAfterRun__(this.hostElement); // primary
  11767. }
  11768. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  11769. if (stopAfterRun && this.lottieAnimation) {
  11770. this.lottieAnimation.stop(); // fallback if no mutation
  11771. }
  11772. return r;
  11773. }
  11774. }
  11775.  
  11776. console1.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - OK`);
  11777.  
  11778. } else {
  11779. console1.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - NG`);
  11780.  
  11781. }
  11782.  
  11783. })();
  11784.  
  11785. console1.log("[End]");
  11786.  
  11787. groupEnd();
  11788.  
  11789.  
  11790. }).catch(console.warn);
  11791.  
  11792. }
  11793.  
  11794.  
  11795. if (DELAY_FOCUSEDCHANGED) {
  11796.  
  11797. customElements.whenDefined("yt-live-chat-text-input-field-renderer").then(() => {
  11798.  
  11799.  
  11800. mightFirstCheckOnYtInit();
  11801. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-input-field-renderer hacks");
  11802. console1.log("[Begin]");
  11803. (() => {
  11804.  
  11805. const tag = "yt-live-chat-text-input-field-renderer"
  11806. const dummy = document.createElement(tag);
  11807.  
  11808. const cProto = getProto(dummy);
  11809. if (!cProto || !cProto.attached) {
  11810. console1.warn(`proto.attached for ${tag} is unavailable.`);
  11811. return;
  11812. }
  11813.  
  11814. if (DELAY_FOCUSEDCHANGED && typeof cProto.focusedChanged === 'function' && cProto.focusedChanged.length === 0 && !cProto.focusedChanged372) {
  11815. cProto.focusedChanged372 = cProto.focusedChanged;
  11816. cProto.focusedChanged = function () {
  11817. Promise.resolve(this).then((cnt) => {
  11818. if (cnt.isAttached === true) cnt.focusedChanged372();
  11819. });
  11820. }
  11821. }
  11822.  
  11823. })();
  11824.  
  11825. console1.log("[End]");
  11826.  
  11827. groupEnd();
  11828.  
  11829. });
  11830.  
  11831. }
  11832.  
  11833. if (USE_RM_ON_FOUNTAIN_MODEL) {
  11834.  
  11835.  
  11836. customElements.whenDefined("yt-emoji-fountain-view-model").then(() => {
  11837.  
  11838.  
  11839. mightFirstCheckOnYtInit();
  11840. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-fountain-view-model hacks");
  11841. console1.log("[Begin]");
  11842. (() => {
  11843.  
  11844. const tag = "yt-emoji-fountain-view-model"
  11845. const dummy = document.createElement(tag);
  11846.  
  11847. const cProto = getProto(dummy);
  11848. if (!cProto || !cProto.attached) {
  11849. console1.warn(`proto.attached for ${tag} is unavailable.`);
  11850. return;
  11851. }
  11852.  
  11853. if (typeof cProto.createEmojiAnimation === 'function' && !cProto.createEmojiAnimation037 && cProto.createEmojiAnimation.length === 4) {
  11854. cProto.createEmojiAnimation037 = cProto.createEmojiAnimation;
  11855.  
  11856. const heartEmoji = {
  11857. "emojiId": "❤",
  11858. "image": {
  11859. "thumbnails": [
  11860. {
  11861. "url": "https://fonts.gstatic.com/s/e/notoemoji/15.1/2764/72.png"
  11862. }
  11863. ]
  11864. },
  11865. "searchTerms": [
  11866. "red",
  11867. "heart"
  11868. ],
  11869. "shortcuts": [
  11870. ":red_heart:",
  11871. ":heart:",
  11872. "<3"
  11873. ],
  11874. "index": 318
  11875. };
  11876. const $this = {
  11877. reactionBuckets: [
  11878. {
  11879. "totalReactions": 1,
  11880. "duration": {
  11881. "seconds": "1"
  11882. },
  11883. "intensityScore": 0.75,
  11884. "reactionsData": [
  11885. {
  11886. "unicodeEmojiId": "❤",
  11887. "reactionCount": 1
  11888. }
  11889. ]
  11890. }
  11891. ],
  11892. noEmojiIdentifier: "NO_EMOJI",
  11893. "emojiBucketTimerId": 155,
  11894. "lastEmojiRequestedForTesting": "❤",
  11895. "emojiAnimationTimerId": 338,
  11896. emojiManager: new Proxy(dummy.emojiManager, {
  11897. get(target, p) {
  11898. if (p === 'emojiMap') {
  11899. const o = target[p] || {};
  11900. if (!o["❤"]) o["❤"] = heartEmoji;
  11901. return o;
  11902. }
  11903. }
  11904. }),
  11905. emojiContainer: null
  11906. };
  11907.  
  11908. const tracelist = new Set();
  11909. try {
  11910. createElement_fountain_model_enabled = true;
  11911. createElement_fountain_model_fn = function (a) {
  11912. tracelist.add(a);
  11913. return false;
  11914. }
  11915. cProto.createEmojiAnimation037.call($this, '❤', false, undefined, undefined);
  11916. } catch (e) { }
  11917. createElement_fountain_model_enabled = false;
  11918.  
  11919. const tracelistLen = tracelist.size;
  11920. tracelist.clear();
  11921.  
  11922. if (tracelistLen > 0) {
  11923.  
  11924. const elementList = new Set();
  11925. // const classList = new Set();
  11926.  
  11927. const fountainMap = new WeakMap();
  11928.  
  11929. const listOfRemove = [];
  11930.  
  11931. const listOfRemoveFn = () => {
  11932. if (listOfRemove.length === 0) return;
  11933. for (const elm of listOfRemove) elm.parentNode && elm.remove();
  11934. listOfRemove.length = 0;
  11935. }
  11936. const animationendListener = (evt) => {
  11937. const p = evt.target;
  11938. if (p instanceof HTMLElement && p.nodeName === 'EMOJI' && p.__removeOnAnimationEnd381__) {
  11939. p.__removeOnAnimationEnd381__ = false;
  11940. listOfRemove.push(p);
  11941. Promise.resolve().then(listOfRemoveFn);
  11942. }
  11943. };
  11944.  
  11945. const addEventListener716 = function (a, b, c = undefined) {
  11946. // console.log(1239889, this, a,b,c)
  11947. if (a === 'animationend' && this.__emoji4818__ && typeof b === 'function' && b.length === 0 && c === undefined && (this || 0).nodeName === "EMOJI" && /^function\s*\(\s*\)\s*\{\s*[$a-wA-Z_-\d]+\.remove\(\);?\s*}$/.test(`${b}`)) {
  11948. const cnt = kRef(fountainMap.get(this));
  11949. const hostElement = cnt ? cnt.hostElement : null;
  11950. if (cnt && hostElement instanceof HTMLElement) {
  11951. if (!cnt.__addedAnimationEnd381__) {
  11952. cnt.__addedAnimationEnd381__ = true;
  11953. hostElement.addEventListener('animationend', animationendListener, passiveCapture);
  11954. }
  11955. this.__removeOnAnimationEnd381__ = true; // set on addEventListener; unset on execution; (to be re-set in createEmojiAnimation)
  11956. return;
  11957. }
  11958. }
  11959. // console.log(477, a,b,c)
  11960. return this.addEventListener717(...arguments)
  11961. }
  11962.  
  11963. let __weakRef9592__;
  11964. DEBUG_RM_ON_FOUNTAIN_MODEL && (window.__elementList183__ = elementList); // around 30 ~ 60 elements when dt = 1600ms
  11965.  
  11966. const updateElementList = function (cntWR) {
  11967.  
  11968. try {
  11969.  
  11970. const cnt = kRef(cntWR);
  11971. if (!cnt) return;
  11972.  
  11973.  
  11974. const ct = Date.now();
  11975. for (const entry of elementList) {
  11976. const [elementW, creationTime, addTime, removeTime] = entry;
  11977.  
  11978. const element = kRef(elementW);
  11979. if (!element) {
  11980. elementList.delete(entry);
  11981. continue;
  11982. }
  11983.  
  11984. // addTime removeTime
  11985. // 0 0 -> element.isConnected === true
  11986. // 0 1 -> element.isConnected === true
  11987. // 1 0 -> element.isConnected === false
  11988. // 1 1 X
  11989.  
  11990. if (!addTime) {
  11991. if (element.isConnected === true) {
  11992. entry[2] = ct;
  11993. entry[3] = 0;
  11994. // arrange the entry to the iteration end
  11995. elementList.delete(entry);
  11996. elementList.add(entry);
  11997. }
  11998. } else if (!removeTime) {
  11999. if (element.isConnected === false) {
  12000. entry[2] = 0;
  12001. entry[3] = ct;
  12002. // arrange the entry to the iteration end
  12003. // elementList.delete(entry);
  12004. // elementList.add(entry);
  12005. }
  12006. }
  12007.  
  12008.  
  12009.  
  12010. }
  12011. } catch (e) {
  12012. console.warn(e);
  12013. }
  12014.  
  12015.  
  12016. }
  12017.  
  12018. createElement_fountain_model_fn = function (a) {
  12019. if (typeof a !== 'string') return;
  12020. const ct = Date.now();
  12021. const timeRef = ct - FOUNTAIN_MODEL_TIME_CONFIRM;
  12022. const tagNameLower = a.toLowerCase();
  12023. try {
  12024. for (const entry of elementList) {
  12025. const [elementW, creationTime, addTime, removeTime] = entry;
  12026. if (!removeTime || removeTime > timeRef) continue;
  12027. const element = kRef(elementW);
  12028. if (!element) { // play safe
  12029. elementList.delete(entry);
  12030. continue;
  12031. }
  12032.  
  12033. const bool = element.__tagNameLower584__ === tagNameLower && element.isConnected === false;
  12034.  
  12035. // if (element.isConnected === true) { // play safe
  12036. // continue;
  12037. // }
  12038.  
  12039.  
  12040.  
  12041. if (bool) {
  12042. // const qq = true;
  12043. // console.log(1838, p === a.toLowerCase() , entry[3] > 0 , entry[3] < targetCreationTime)
  12044. // if ( qq && p === a.toLowerCase() && removeTime > 0 && removeTime < targetCreationTime ) {
  12045. // console.log(123992, element , element.isConnected)
  12046.  
  12047. elementList.delete(entry);
  12048. entry[1] = ct;
  12049. entry[2] = 0;
  12050. entry[3] = 0;
  12051. elementList.add(entry);
  12052.  
  12053. element.className = '';
  12054. element.style = '';
  12055. if (tagNameLower === 'img') {
  12056. element.src = '';
  12057. element.alt = '';
  12058. }
  12059.  
  12060.  
  12061.  
  12062. if (!onPageContainer) {
  12063. let p = document.createElement('noscript');
  12064. p.style.all = 'unset';
  12065. document.body.prepend(p);
  12066. onPageContainer = p;
  12067. }
  12068.  
  12069. const cnt = insp(element);
  12070. const hostElement = cnt.hostElement;
  12071. if(hostElement === element && !cnt.__dataInvalid && cnt.__dataEnabled && cnt.__dataReady){
  12072.  
  12073. // console.log(1238);
  12074. onPageContainer.appendChild(hostElement); // to fix some issues for the rendered elements
  12075. cnt.__dataInvalid = false;
  12076. cnt.__dataEnabled = true;
  12077. cnt.__dataReady = true;
  12078. // cnt._initializeProtoProperties(cnt.data)
  12079. // window.meaa = cnt.$.container;
  12080.  
  12081. if (cnt.__data) cnt.__data = Object.assign({}, cnt.__data);
  12082. cnt.__dataPending = {};
  12083. cnt.__dataOld = {}
  12084. try{
  12085. cnt.markDirty();
  12086. }catch(e){}
  12087. try{
  12088. cnt.markDirtyVisibilityObserver();
  12089. }catch(e){}
  12090. try{
  12091. cnt.wasPrescan = cnt.wasVisible = !1
  12092. }catch(e){}
  12093.  
  12094.  
  12095. }
  12096.  
  12097. element.__reuseCount918__ = (element.__reuseCount918__ || 0) + 1;
  12098.  
  12099.  
  12100.  
  12101. // console.log(2183, element);
  12102. // emoji -> div -> img
  12103. return element;
  12104. }
  12105.  
  12106. // console.log(element, element.nodeName);
  12107. // continue;
  12108. /*
  12109. const p = (element.nodeName || '').toLowerCase();
  12110. if (p === a.toLowerCase()) {
  12111. elementList.delete(entry);
  12112. entry[1] = ct;
  12113. entry[2] = 0;
  12114. elementList.add(entry);
  12115. element.className = '';
  12116. element.style = '';
  12117. if (p === 'img') {
  12118. element.src = '';
  12119. element.alt = '';
  12120. }
  12121. // console.log(2183, element);
  12122. // emoji -> div -> img
  12123. return element;
  12124. }
  12125. */
  12126.  
  12127.  
  12128.  
  12129. }
  12130.  
  12131. } catch (e) {
  12132. console.warn(e);
  12133. }
  12134. const elm = document.createElement4719(a)
  12135.  
  12136. try {
  12137.  
  12138. const elmW = mWeakRef(elm);
  12139. const entry = [elmW, ct, 0, 0];
  12140. elementList.add(entry);
  12141. elm.__tagNameLower584__ = tagNameLower;
  12142. // elm.__entry428__ = mWeakRef(entry);
  12143. if (!elm.addEventListener717) {
  12144. elm.addEventListener717 = elm.addEventListener;
  12145. elm.addEventListener = addEventListener716;
  12146. if (elm.nodeName.toLowerCase() === 'emoji') elm.__emoji4818__ = true;
  12147. }
  12148. if (__weakRef9592__) {
  12149. const cnt = kRef(__weakRef9592__);
  12150. cnt && fountainMap.set(elm, __weakRef9592__);
  12151. }
  12152. } catch (e) {
  12153. console.warn(e);
  12154. }
  12155.  
  12156. return elm;
  12157. };
  12158.  
  12159. cProto.createEmojiAnimation = function (a, b, c, d) {
  12160. createElement_fountain_model_enabled = true;
  12161. if (!this.__weakRef9591__) {
  12162. this.__weakRef9591__ = new WeakRef(this);
  12163. const q = this.__weakRef9591__;
  12164. const hostElement = this.hostElement;
  12165. const mo = new MutationObserver(() => {
  12166. Promise.resolve(q).then(updateElementList);
  12167. }).observe(hostElement, { subtree: true, childList: true });
  12168. }
  12169. __weakRef9592__ = this.__weakRef9591__;
  12170. let r = this.createEmojiAnimation037(a, b, c, d);
  12171. __weakRef9592__ = null;
  12172. createElement_fountain_model_enabled = false;
  12173. return r;
  12174. }
  12175. console1.log('USE_RM_ON_FOUNTAIN_MODEL - OK');
  12176. } else {
  12177.  
  12178. console1.log('USE_RM_ON_FOUNTAIN_MODEL - NG');
  12179. }
  12180.  
  12181. } else {
  12182.  
  12183. console1.log('USE_RM_ON_FOUNTAIN_MODEL - NG');
  12184. }
  12185.  
  12186.  
  12187. })();
  12188.  
  12189. console1.log("[End]");
  12190.  
  12191. groupEnd();
  12192.  
  12193.  
  12194. }).catch(console.warn);
  12195.  
  12196. }
  12197.  
  12198. }
  12199.  
  12200.  
  12201.  
  12202.  
  12203. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  12204.  
  12205. const fixJsonParse = () => {
  12206.  
  12207. let p1 = window.onerror;
  12208.  
  12209. try {
  12210. JSON.parse("{}");
  12211. } catch (e) {
  12212. console.warn(e);
  12213. }
  12214.  
  12215. let p2 = window.onerror;
  12216.  
  12217. if (p1 !== p2) {
  12218.  
  12219.  
  12220. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  12221. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  12222. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  12223. );
  12224.  
  12225. 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");
  12226.  
  12227. console.groupEnd();
  12228.  
  12229. }
  12230.  
  12231. }
  12232.  
  12233. if (CHECK_JSONPRUNE) {
  12234. promiseForCustomYtElementsReady.then(fixJsonParse);
  12235. }
  12236.  
  12237. });
  12238.  
  12239.  
  12240.  
  12241. })({ IntersectionObserver });

QingJ © 2025

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