YouTube 超快聊天

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

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

  1. // ==UserScript==
  2. // @name YouTube Super Fast Chat
  3. // @version 0.66.16
  4. // @license MIT
  5. // @name:ja YouTube スーパーファーストチャット
  6. // @name:zh-TW YouTube 超快聊天
  7. // @name:zh-CN YouTube 超快聊天
  8. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/super-fast-chat.png
  9. // @namespace UserScript
  10. // @match https://www.youtube.com/live_chat*
  11. // @match https://www.youtube.com/live_chat_replay*
  12. // @author CY Fung
  13. // @run-at document-start
  14. // @grant none
  15. // @unwrap
  16. // @allFrames true
  17. // @inject-into page
  18. // @require https://update.greasyfork.org/scripts/475632/1361351/ytConfigHacks.js
  19. //
  20. // @compatible firefox Violentmonkey
  21. // @compatible firefox Tampermonkey
  22. // @compatible firefox FireMonkey
  23. // @compatible chrome Violentmonkey
  24. // @compatible chrome Tampermonkey
  25. // @compatible opera Violentmonkey
  26. // @compatible opera Tampermonkey
  27. // @compatible safari Stay
  28. // @compatible edge Violentmonkey
  29. // @compatible edge Tampermonkey
  30. // @compatible brave Violentmonkey
  31. // @compatible brave Tampermonkey
  32. //
  33. // @description Ultimate Performance Boost for YouTube Live Chats
  34. // @description:ja YouTubeのライブチャットの究極のパフォーマンスブースト
  35. // @description:zh-TW YouTube直播聊天的終極性能提升
  36. // @description:zh-CN YouTube直播聊天的终极性能提升
  37. //
  38. // ==/UserScript==
  39.  
  40. ((__CONTEXT__) => {
  41. 'use strict';
  42.  
  43. /** @type {WeakMapConstructor} */
  44. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  45.  
  46. const DEBUG_LOG_GROUP_EXPAND = !!localStorage.__debugSuperFastChat__;
  47. const DEBUG_customCreateComponent = false;
  48.  
  49. // *********** DON'T REPORT NOT WORKING DUE TO THE CHANGED SETTINGS ********************
  50. // 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
  51.  
  52. 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
  53. 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)
  54. 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)
  55.  
  56. const ENABLE_NO_SMOOTH_TRANSFORM = true; // Depends on whether you want the animation effect for new chat messages <<< DON'T CHANGE >>>
  57. const USE_OPTIMIZED_ON_SCROLL_ITEMS = true; // TRUE for the majority
  58. const ENABLE_OVERFLOW_ANCHOR_PREFERRED = true; // Enable `overflow-anchor: auto` to lock the scroll list at the bottom for no smooth transform.
  59.  
  60. const FIX_SHOW_MORE_BUTTON_LOCATION = true; // When there are voting options (bottom panel), move the "show more" button to the top.
  61. const FIX_INPUT_PANEL_OVERFLOW_ISSUE = true; // When the super chat button is flicking with color, the scrollbar might come out.
  62. const FIX_INPUT_PANEL_BORDER_ISSUE = true; // No border should be allowed if there is an empty input panel.
  63. const SET_CONTAIN_FOR_CHATROOM = true; // Rendering hacks (`contain`) for chatroom elements. [ General ]
  64.  
  65. const FORCE_CONTENT_VISIBILITY_UNSET = true; // Content-visibility should be always VISIBLE for high performance and great rendering.
  66. const FORCE_WILL_CHANGE_UNSET = true; // Will-change should be always UNSET (auto) for high performance and low energy impact.
  67.  
  68. // Replace requestAnimationFrame timers with custom implementation
  69. const ENABLE_RAF_HACK_TICKERS = true; // When there is a ticker
  70. const ENABLE_RAF_HACK_DOCKED_MESSAGE = true; // To be confirmed
  71. const ENABLE_RAF_HACK_INPUT_RENDERER = true; // To be confirmed
  72. const ENABLE_RAF_HACK_EMOJI_PICKER = true; // When changing the page of the emoji picker
  73.  
  74. // Force rendering all the character subsets of the designated font(s) before messages come (Pre-Rendering of Text)
  75. const ENABLE_FONT_PRE_RENDERING_PREFERRED = 1 | 2 | 4 | 8 | 16;
  76.  
  77. // Backdrop `filter: blur(4px)` inside the iframe can extend to the whole page, causing a negative visual impact on the video you are watching.
  78. const NO_BACKDROP_FILTER_WHEN_MENU_SHOWN = true;
  79.  
  80. // Data Manipulation for Participants (Participant List)
  81. // << if DO_PARTICIPANT_LIST_HACKS >>
  82. const DO_PARTICIPANT_LIST_HACKS = true; // TRUE for the majority
  83. const SHOW_PARTICIPANT_CHANGES_IN_CONSOLE = false; // Just too annoying to show them all in popular chat
  84. const CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = true; // Only consider changes in renderable content (not concerned with the last chat message of the participants)
  85. const PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED = true;
  86. // << end >>
  87.  
  88. // show more button
  89. const ENABLE_SHOW_MORE_BLINKER = true; // BLINK WHEN NEW MESSAGES COME
  90.  
  91. // faster stampDomArray_ for participants list creation
  92. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL = 1; // 0 - OFF; 1 - ON; 2 - ON(PARTICIPANTS_LIST ONLY)
  93. const USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET = false;
  94.  
  95. // reuse yt components
  96. const ENABLE_FLAGS_REUSE_COMPONENTS = true;
  97.  
  98. // ShadyDom Free is buggy
  99. const DISABLE_FLAGS_SHADYDOM_FREE = true;
  100.  
  101. // images <Group#I01>
  102. const AUTHOR_PHOTO_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  103. const EMOJI_IMAGE_SINGLE_THUMBNAIL = 1; // 0 - disable; 1- smallest; 2- largest
  104. const LEAST_IMAGE_SIZE = 48; // minium size = 48px
  105.  
  106. const DO_LINK_PREFETCH = true; // DO NOT CHANGE
  107. // << if DO_LINK_PREFETCH >>
  108. const ENABLE_BASE_PREFETCHING = true; // (SUB-)DOMAIN | dns-prefetch & preconnect
  109. const ENABLE_PRELOAD_THUMBNAIL = true; // subresource (prefetch) [LINK for Images]
  110. const SKIP_PRELOAD_EMOJI = true;
  111. const PREFETCH_LIMITED_SIZE_EMOJI = 512; // DO NOT CHANGE THIS
  112. const PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO = 68; // DO NOT CHANGE THIS
  113. // << end >>
  114.  
  115. const FIX_SETSRC_AND_THUMBNAILCHANGE_ = true; // Function Replacement for yt-img-shadow....
  116. const FIX_THUMBNAIL_DATACHANGED = true; // Function Replacement for yt-live-chat-author-badge-renderer..dataChanged
  117. // const REMOVE_PRELOADAVATARFORADDACTION = false; // Function Replacement for yt-live-chat-renderer..preloadAvatarForAddAction
  118.  
  119. const FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION = true; // important [depends on <Group#I01>]
  120. const FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT = true; // [depends on <Group#I01>]
  121.  
  122. // BROWSER SUPPORT: Chrome 75+, Edge 79+, Safari 13.1+, Firefox 63+, Opera 62+
  123. const TICKER_MAX_STEPS_LIMIT = 500; // NOT LESS THAN 5 STEPS!!
  124. // (( KEEP AS ALTERNATIVE IF USE_ADVANCED_TICKING NOT WORKING ))
  125. // [limiting 500 max steps] is recommended for "confortable visual change"
  126. // min. step increment 0.2% => max steps: 500 => 800ms per each update
  127. // min. step increment 0.5% => max steps: 200 => 1000ms per each update
  128. // min. step increment 1.0% => max steps: 100 => 1000ms per each update
  129. // min. step increment 2.5% => max steps: 40 => 1000ms per each update
  130. // min. step increment 5.0% => max steps: 20 => 1250ms per each update
  131. const ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX = true; // for video playback's ticker issue. [ Playback Replay - Pause at Middle - Backwards Seeking ]
  132. 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
  133. // << end >>
  134.  
  135. const FIX_TOOLTIP_DISPLAY = true; // changed in 2024.05.02
  136. const USE_VANILLA_DEREF = true;
  137. const FIX_DROPDOWN_DERAF = true; // DONT CHANGE
  138.  
  139.  
  140. const CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true; // cache the menu data and used for the next reopen
  141. const ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU = false; // pause auto scroll faster when the context menu is about to show
  142. const ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU = true; // avoid multiple requests on the same time
  143.  
  144. const BOOST_MENU_OPENCHANGED_RENDERING = true;
  145. const FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK = true; // click again = close
  146. const NO_ITEM_TAP_FOR_NON_STATIONARY_TAP = true; // dont open the menu (e.g. text message) if cursor is moved or long press
  147. const TAP_ACTION_DURATION = 280; // exceeding 280ms would not consider as a tap action
  148. const PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN = true; // require CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN = true
  149. // const FIX_MENU_CAPTURE_SCROLL = true;
  150. const CHAT_MENU_REFIT_ALONG_SCROLLING = 0; // 0 for locking / default; 1 for unlocking only; 2 for unlocking and refit
  151.  
  152. const RAF_FIX_keepScrollClamped = true;
  153. const RAF_FIX_scrollIncrementally = 2; // 0: no action; 1: basic fix; 2: also fix scroll position
  154.  
  155. // << if BOOST_MENU_OPENCHANGED_RENDERING >>
  156. const FIX_MENU_POSITION_N_SIZING_ON_SHOWN = 1; // correct size and position when the menu dropdown opens
  157.  
  158. const CHECK_JSONPRUNE = true; // This is a bug in Brave
  159. // << end >>
  160.  
  161. // const LIVE_CHAT_FLUSH_ON_FOREGROUND_ONLY = false;
  162.  
  163. const CHANGE_DATA_FLUSH_ASYNC = false;
  164. // CHANGE_DATA_FLUSH_ASYNC is disabled due to bug report: https://greasyfork.org/scripts/469878/discussions/199479
  165. // to be further investigated
  166.  
  167. const CHANGE_MANAGER_UNSUBSCRIBE = true;
  168.  
  169. const INTERACTIVITY_BACKGROUND_ANIMATION = 1; // mostly for pinned message
  170. // 0 = default Yt animation background [= no fix];
  171. // 1 = disable default animation background [= keep special animation];
  172. // 2 = disable all animation backgrounds [= no animation backbround]
  173.  
  174. const CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED = true;
  175.  
  176. const MAX_TOOLTIP_NO_WRAP_WIDTH = '72vw'; // '' for disable; accept values like '60px', '25vw'
  177.  
  178.  
  179.  
  180. 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
  181. // << if USE_ADVANCED_TICKING >>
  182. const FIX_TIMESTAMP_FOR_REPLAY = true;
  183. const ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION = true; // MUST BE true
  184. const REUSE_TICKER = true; // for better memory control; currently it is only available in ADVANCED_TICKING; to be further reviewed
  185. // << end >>
  186.  
  187. const DISABLE_Translation_By_Google = true;
  188.  
  189. const FASTER_ICON_RENDERING = true;
  190.  
  191. const DELAY_FOCUSEDCHANGED = true;
  192.  
  193. const skipErrorForhandleAddChatItemAction_ = true; // currently depends on ENABLE_NO_SMOOTH_TRANSFORM
  194. const fixChildrenIssue801 = true; // if __children801__ is set [fix polymer controller method extration for `.set()`]
  195.  
  196. const SUPPRESS_refreshOffsetContainerHeight_ = true; // added in FEB 2024; true for default layout options; no effect if ENABLE_NO_SMOOTH_TRANSFORM is false
  197.  
  198. const NO_FILTER_DROPDOWN_BORDER = true; // added in 2024.03.02
  199.  
  200. const FIX_ANIMATION_TICKER_TEXT_POSITION = true; // CSS fix; experimental; added in 2024.04.07
  201. const FIX_AUTHOR_CHIP_BADGE_POSITION = true;
  202.  
  203. const FIX_ToggleRenderPolymerControllerExtractionBug = false; // to be reviewed
  204.  
  205. const REACTION_ANIMATION_PANEL_CSS_FIX = true;
  206.  
  207. const FIX_UNKNOWN_BUG_FOR_OVERLAY = true; // no .prepare() in backdrop element. reason is unknown.
  208.  
  209. // -------------------------------
  210.  
  211. const USE_OBTAIN_LCR_BY_BOTH_METHODS = false; // true for play safe
  212.  
  213. const FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP = true; // To fix Memory Leakage in yt-live-chat-ticker-...-item-renderer
  214. const FIX_MEMORY_LEAKAGE_TICKER_STATSBAR = true; // To fix Memory Leakage in updateStatsBarAndMaybeShowAnimation
  215. const FIX_MEMORY_LEAKAGE_TICKER_TIMER = true; // To fix Memory Leakage in setContainerWidth, slideDown, collapse // Dec 2024 fix in advance tickering
  216. const FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth = true; // To fix Memory Leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth()
  217.  
  218. // leakage in ytd-sponsorships-live-chat-gift-purchase-announcement-renderer - to be confirmed
  219.  
  220. // <<<<< FOR MEMORY LEAKAGE >>>>
  221. const DEBUG_wmList = false;
  222. let DEBUG_wmList_started = false;
  223. // const FLAG_001 = true;
  224. const FLAG_001a = false;
  225. const FLAG_001b = false;
  226. const FLAG_001c = false;
  227. const FLAG_001d = false;
  228. const FLAG_001e = false;
  229. const FLAG_001f = false;
  230. // const FLAG_001g = true;
  231.  
  232.  
  233.  
  234. /**
  235. *
  236. *
  237. *
  238. *
  239. *
  240. rendererStamperObserver_: function(a, b, c) {
  241. if (c.path == a) {
  242. if (c.value === void 0 && !this.hasDataPath_[a])
  243. return;
  244. this.hasDataPath_[a] = c.value !== void 0
  245. }
  246. this.rendererStamperApplyChangeRecord_(a, b, c)
  247. },
  248.  
  249.  
  250. addStampDomObserverFns_: function() {
  251. for (var a in this.stampDom) {
  252. var b = this.stampDom[a];
  253. b.id ? (this[SQa(b.id)] = this.rendererStamperObserver_.bind(this, a, b.id),
  254. this.hasDataPath_[a] = !1) : Er(new Dn("Bad rendererstamper config",this.is + ":" + a))
  255. }
  256. },
  257. *
  258. *
  259. *
  260. *
  261. *
  262. */
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269. // <<<<< FOR MEMORY LEAKAGE >>>>
  270.  
  271. // ========= EXPLANTION FOR 0.2% @ step timing [min. 0.2%] ===========
  272. /*
  273.  
  274. ### Time Approach
  275.  
  276. // all below values can make the time interval > 250ms
  277. // 250ms (practical value) refers to the minimum frequency for timeupdate in most browsers (typically, shorter timeupdate interval in modern browsers)
  278. if (totalDuration > 400000) stepInterval = 0.2; // 400000ms with 0.2% increment => 800ms
  279. else if (totalDuration > 200000) stepInterval = 0.5; // 200000ms with 0.5% increment => 1000ms
  280. else if (totalDuration > 100000) stepInterval = 1; // 100000ms with 1% increment => 1000ms
  281. else if (totalDuration > 50000) stepInterval = 2; // 50000ms with 2% increment => 1000ms
  282. else if (totalDuration > 25000) stepInterval = 5; // 25000ms with 5% increment => 1250ms
  283.  
  284. ### Pixel Check
  285. // Target Max Pixel Increment < 5px for Short Period Ticker (Rapid Background Change)
  286. // Assume total width <= 99px for short period ticker, like small donation & member welcome
  287. 99px * 5% = 4.95px < 5px [Condition Fulfilled]
  288.  
  289. ### Example - totalDuration = 280000
  290. totalDuration 280000
  291. stepInterval 0.5
  292. numOfSteps = Math.round(100 / stepInterval) = 200
  293. time interval = 280000 / 200 = 1400ms <acceptable>
  294.  
  295. ### Example - totalDuration = 18000
  296. totalDuration 18000
  297. stepInterval 5
  298. numOfSteps = Math.round(100 / stepInterval) = 20
  299. time interval = 18000 / 20 = 900ms <acceptable>
  300.  
  301. ### Example - totalDuration = 5000
  302. totalDuration 5000
  303. stepInterval 5
  304. numOfSteps = Math.round(100 / stepInterval) = 20
  305. time interval = 5000 / 20 = 250ms <threshold value>
  306.  
  307. ### Example - totalDuration = 3600
  308. totalDuration 3600
  309. stepInterval 5
  310. numOfSteps = Math.round(100 / stepInterval) = 20
  311. time interval = 3600 / 20 = 180ms <reasonable for 3600ms ticker>
  312.  
  313. */
  314.  
  315. // =======================================================================================================
  316.  
  317. // AUTOMAICALLY DETERMINED
  318. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL === 1;
  319. const ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST = ENABLE_FLAGS_MAINTAIN_STABLE_LIST_VAL >= 1;
  320. const CHAT_MENU_SCROLL_UNLOCKING = CHAT_MENU_REFIT_ALONG_SCROLLING >= 1;
  321.  
  322.  
  323. // image sizing code
  324. // (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null)
  325.  
  326.  
  327. // function KC(a, b, c, d) {
  328. // d = void 0 === d ? "width" : d;
  329. // if (!a || !a.length)
  330. // return null;
  331. // if (z("kevlar_tuner_should_always_use_device_pixel_ratio")) {
  332. // var e = window.devicePixelRatio;
  333. // 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"));
  334. // HC = e
  335. // } else
  336. // HC || (HC = window.devicePixelRatio);
  337. // e = HC;
  338. // z("kevlar_tuner_should_always_use_device_pixel_ratio") ? b *= e : 1 < e && (b *= e);
  339. // if (z("kevlar_tuner_min_thumbnail_quality"))
  340. // return a[0].url || null;
  341. // e = a.length;
  342. // if (z("kevlar_tuner_max_thumbnail_quality"))
  343. // return a[e - 1].url || null;
  344. // if (c)
  345. // for (var h = 0; h < e; h++)
  346. // if (0 <= a[h].url.indexOf(c))
  347. // return a[h].url || null;
  348. // for (c = 0; c < e; c++)
  349. // if (a[c][d] >= b)
  350. // return a[c].url || null;
  351. // for (b = e - 1; 0 < b; b--)
  352. // if (a[b][d])
  353. // return a[b].url || null;
  354. // return a[0].url || null
  355. // }
  356.  
  357.  
  358. /// ------
  359.  
  360. // https://www.youtube.com/watch?v=byyvH5t0hKc
  361. // yt-live-chat-ticker-creator-goal-view-model
  362. // no ticker effect on timing
  363.  
  364. /*
  365.  
  366.  
  367. {
  368. "id": "ChwKGkNQS0pyNV9NdG9vREZVYlB6Z2FkRHWFUv2E",
  369. "initialTickerText": {
  370. "content": "Goal",
  371. "styleRuns": [
  372. {
  373. "startIndex": 0,
  374. "length": 4
  375. }
  376. ]
  377. },
  378. "tickerIcon": {
  379. "sources": [
  380. {
  381. "clientResource": {
  382. "imageName": "TARGET_ADD"
  383. }
  384. }
  385. ]
  386. },
  387. "showGoalStatusCommand": {
  388. "innertubeCommand": {
  389. "clickTrackingParams": "CCQQ7NANIhMI58DT_ef5rhMVxMW1Cx4qBzTz",
  390. "showEngagementPanelEndpoint": {
  391. "engagementPanel": {
  392. "engagementPanelSectionListRenderer": {
  393. "header": {
  394. "engagementPanelTitleHeaderRenderer": {
  395. "actionButton": {
  396. "buttonRenderer": {
  397. "icon": {
  398. "iconType": "QUESTION_CIRCLE"
  399. },
  400. "trackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  401. "command": {
  402. "clickTrackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  403. "commandExecutorCommand": {
  404. "commands": [
  405. {
  406. "clickTrackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  407. "liveChatDialogEndpoint": {
  408. "content": {
  409. "liveChatDialogRenderer": {
  410. "trackingParams": "CCkQzS8iEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  411. "title": {
  412. "runs": [
  413. {
  414. "text": "Super Chat Goal"
  415. }
  416. ]
  417. },
  418. "dialogMessages": [
  419. {
  420. "runs": [
  421. {
  422. "text": "Join the fun by participating in the goal! "
  423. },
  424. {
  425. "text": "Learn more.\n",
  426. "navigationEndpoint": {
  427. "clickTrackingParams": "CCkQzS8iEwjm0Iz72rbKBxXT1EQBJekHNQM="
  428. }
  429. }
  430. ]
  431. },
  432. {
  433. "runs": [
  434. {
  435. "text": "How to participate",
  436. "bold": true,
  437. "textColor": 4294967295
  438. },
  439. {
  440. "text": "\n"
  441. },
  442. {
  443. "text": "1. Press \"Continue\"\n2. Purchase a Super Chat \n3. Watch the progress towards the goal\n4. Celebrate achieving it with the community!",
  444. "textColor": 4294967295
  445. }
  446. ]
  447. }
  448. ],
  449. "confirmButton": {
  450. "buttonRenderer": {
  451. "style": "STYLE_MONO_FILLED",
  452. "size": "SIZE_DEFAULT",
  453. "isDisabled": false,
  454. "text": {
  455. "simpleText": "Got it"
  456. },
  457. "trackingParams": "CCoQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  458. "accessibilityData": {
  459. "accessibilityData": {
  460. "label": "Got it"
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. }
  468. },
  469. {
  470. "clickTrackingParams": "CCgQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  471. "hideEngagementPanelEndpoint": {
  472. "identifier": {
  473. "surface": "ENGAGEMENT_PANEL_SURFACE_LIVE_CHAT",
  474. "tag": "creator_goal_progress_engagement_panel"
  475. }
  476. }
  477. }
  478. ]
  479. }
  480. }
  481. }
  482. },
  483. "trackingParams": "CCUQ040EIhMI58DT_ef5rhMVxMW1Cx4qBzTz"
  484. }
  485. },
  486. "content": {
  487. "sectionListRenderer": {
  488. "contents": [
  489. {
  490. "creatorGoalProgressFlowViewModel": {
  491. "creatorGoalEntityKey": "EgtieXl2SDV0MGhLYyG7BzhF",
  492. "progressFlowButton": {
  493. "buttonViewModel": {
  494. "onTap": {
  495. "innertubeCommand": {
  496. "clickTrackingParams": "CCcQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  497. "commandMetadata": {
  498. "webCommandMetadata": {
  499. "ignoreNavigation": true
  500. }
  501. },
  502. "liveChatPurchaseMessageEndpoint": {
  503. "params": "Q2lrcUp3b1lWVU14ZFdObmIwTmZjMGQzZDE5RmRYVTFhVTF4Y0ZGM0VndGllWGwyU0RWME1HaExZeEFCSUFFNEFFSUNDQUUlM0Q="
  504. }
  505. }
  506. },
  507. "style": "BUTTON_VIEW_MODEL_STYLE_MONO",
  508. "trackingParams": "CCcQ8FsiEwjm0Iz72rbKBxXT1EQBJekHNQM=",
  509. "type": "BUTTON_VIEW_MODEL_TYPE_FILLED",
  510. "titleFormatted": {
  511. "content": "Continue",
  512. "styleRuns": [
  513. {
  514. "startIndex": 0,
  515. "length": 8
  516. }
  517. ]
  518. }
  519. }
  520. },
  521. "progressCountA11yLabel": "Super Chat goal progress: $0 out of $1"
  522. }
  523. }
  524. ],
  525. "trackingParams": "CCYQui8iEwjm0Iz72rbKBxXT1EQBJekHNQM="
  526. }
  527. },
  528. "identifier": {
  529. "surface": "ENGAGEMENT_PANEL_SURFACE_LIVE_CHAT",
  530. "tag": "creator_goal_progress_engagement_panel"
  531. }
  532. }
  533. },
  534. "identifier": {
  535. "surface": "ENGAGEMENT_PANEL_SURFACE_LIVE_CHAT",
  536. "tag": "creator_goal_progress_engagement_panel"
  537. },
  538. "engagementPanelPresentationConfigs": {
  539. "engagementPanelPopupPresentationConfig": {
  540. "popupType": "PANEL_POPUP_TYPE_DIALOG"
  541. }
  542. }
  543. }
  544. }
  545. },
  546. "creatorGoalEntityKey": "EgtieXl2SDV0MGhLYyG7BzhF",
  547. "shouldShowSetUpFlowOnMobile": true,
  548. "a11yLabel": "See Super Chat goal",
  549. "loggingDirectives": {
  550. "trackingParams": "CCQQ7NANIhMI58DT_ef5rhMVxMW1Cx4qBzTz",
  551. "visibility": {
  552. "types": "12"
  553. }
  554. }
  555. }
  556.  
  557.  
  558. */
  559.  
  560.  
  561. // ------
  562.  
  563.  
  564. // document.createElement4521 = document.createElement;
  565.  
  566. // document.createElement = function(){
  567. // if(arguments[0]==='yt-live-chat-ticker-paid-message-item-renderer' || arguments[0]==='yt-live-chat-ticker-paid-sticker-item-renderer' || arguments[0]==='yt-live-chat-ticker-sponsor-item-renderer'){
  568. // console.log(8123, [...arguments]);
  569. // debugger;
  570.  
  571. // }
  572. // // if(`${arguments[0]}`.indexOf('-')>=0) console.log(8123, [...arguments]);
  573. // return document.createElement4521(...arguments);
  574. // };
  575.  
  576. const { IntersectionObserver } = __CONTEXT__;
  577. let _x69;
  578. try {
  579. _x69 = document.createAttributeNS("http://www.w3.org/2000/svg", "nil").addEventListener;
  580. } catch (e) { }
  581. const pureAddEventListener = _x69;
  582. if (!pureAddEventListener) return console.warn("pureAddEventListener cannot be obtained.");
  583.  
  584. /** @type {globalThis.PromiseConstructor} */
  585. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  586.  
  587. // let jsonParseFix = null;
  588.  
  589. if (!IntersectionObserver) return console.warn("Your browser does not support IntersectionObserver.\nPlease upgrade to the latest version.");
  590. if (typeof WebAssembly !== 'object') return console.warn("Your browser is too old.\nPlease upgrade to the latest version."); // for passive and once
  591.  
  592. // necessity of cssText3_smooth_transform_position to be checked.
  593. const cssText3_smooth_transform_position = ENABLE_NO_SMOOTH_TRANSFORM ? `
  594.  
  595. #item-offset.style-scope.yt-live-chat-item-list-renderer > #items.style-scope.yt-live-chat-item-list-renderer {
  596. position: static !important;
  597. }
  598.  
  599. `: '';
  600.  
  601. // fallback if dummy style fn fails
  602. const cssText4_smooth_transform_forced_props = ENABLE_NO_SMOOTH_TRANSFORM ? `
  603.  
  604. /* optional */
  605. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  606. height: auto !important;
  607. min-height: unset !important;
  608. }
  609.  
  610. #items.style-scope.yt-live-chat-item-list-renderer {
  611. transform: translateY(0px) !important;
  612. }
  613.  
  614. /* optional */
  615.  
  616. `: '';
  617.  
  618. const cssText5 = SET_CONTAIN_FOR_CHATROOM ? `
  619.  
  620. /* ------------------------------------------------------------------------------------------------------------- */
  621.  
  622. 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 {
  623. contain: layout style;
  624. }
  625.  
  626. #items.style-scope.yt-live-chat-item-list-renderer {
  627. contain: layout paint style;
  628. }
  629.  
  630. #item-offset.style-scope.yt-live-chat-item-list-renderer {
  631. contain: style;
  632. }
  633.  
  634. #item-scroller.style-scope.yt-live-chat-item-list-renderer {
  635. contain: size style;
  636. }
  637.  
  638. #contents.style-scope.yt-live-chat-item-list-renderer, #chat.style-scope.yt-live-chat-renderer, img.style-scope.yt-img-shadow[width][height] {
  639. contain: size layout paint style;
  640. }
  641.  
  642. .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label], .style-scope.yt-live-chat-ticker-renderer[role="button"][aria-label] > #container {
  643. contain: layout paint style;
  644. }
  645.  
  646. 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 {
  647. contain: layout style;
  648. }
  649.  
  650. tp-yt-paper-tooltip[style*="inset"][role="tooltip"] {
  651. contain: layout paint style;
  652. }
  653.  
  654. /* ------------------------------------------------------------------------------------------------------------- */
  655.  
  656. ` : '';
  657.  
  658. const cssText6b_show_more_button = FIX_SHOW_MORE_BUTTON_LOCATION ? `
  659.  
  660. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer{
  661. top: 4px;
  662. transition-property: top;
  663. bottom: unset;
  664. }
  665.  
  666. yt-live-chat-renderer[has-action-panel-renderer] #show-more.yt-live-chat-item-list-renderer[disabled]{
  667. top: -42px;
  668. }
  669.  
  670. `: '';
  671.  
  672. const cssText6c_input_panel_overflow = FIX_INPUT_PANEL_OVERFLOW_ISSUE ? `
  673.  
  674. #input-panel #picker-buttons yt-live-chat-icon-toggle-button-renderer#product-picker {
  675. contain: layout style;
  676. }
  677.  
  678. #chat.yt-live-chat-renderer ~ #panel-pages.yt-live-chat-renderer {
  679. overflow: visible;
  680. }
  681.  
  682. `: '';
  683.  
  684. const cssText6d_input_panel_border = FIX_INPUT_PANEL_BORDER_ISSUE ? `
  685.  
  686. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer:not(:empty) {
  687. --yt-live-chat-action-panel-top-border: none;
  688. }
  689.  
  690. html #panel-pages.yt-live-chat-renderer > #input-panel.yt-live-chat-renderer.iron-selected > *:first-child {
  691. border-top: 1px solid var(--yt-live-chat-panel-pages-border-color);
  692. }
  693.  
  694. html #panel-pages.yt-live-chat-renderer {
  695. border-top: 0;
  696. border-bottom: 0;
  697. }
  698.  
  699. `: '';
  700.  
  701. const cssText7b_content_visibility_unset = FORCE_CONTENT_VISIBILITY_UNSET ? `
  702.  
  703. img,
  704. yt-img-shadow[height][width],
  705. yt-img-shadow {
  706. content-visibility: visible !important;
  707. }
  708.  
  709. ` : '';
  710.  
  711. const cssText7c_will_change_unset = FORCE_WILL_CHANGE_UNSET ? `
  712.  
  713. /* remove YouTube constant will-change */
  714. /* constant value will slow down the performance; default auto */
  715.  
  716. /* www-player.css */
  717. html .ytp-contextmenu,
  718. html .ytp-settings-menu {
  719. will-change: unset;
  720. }
  721.  
  722. /* frequently matched elements */
  723. html .fill.yt-interaction,
  724. html .stroke.yt-interaction,
  725. html .yt-spec-touch-feedback-shape__fill,
  726. html .yt-spec-touch-feedback-shape__stroke {
  727. will-change: unset;
  728. }
  729.  
  730. /* live_chat_polymer.js */
  731. /*
  732. html .toggle-button.tp-yt-paper-toggle-button,
  733. html #primaryProgress.tp-yt-paper-progress,
  734. html #secondaryProgress.tp-yt-paper-progress,
  735. html #onRadio.tp-yt-paper-radio-button,
  736. html .fill.yt-interaction,
  737. html .stroke.yt-interaction,
  738. html .yt-spec-touch-feedback-shape__fill,
  739. html .yt-spec-touch-feedback-shape__stroke {
  740. will-change: unset;
  741. }
  742. */
  743.  
  744. /* desktop_polymer_enable_wil_icons.js */
  745. /* html .fill.yt-interaction,
  746. html .stroke.yt-interaction, */
  747. html tp-yt-app-header::before,
  748. html tp-yt-iron-list,
  749. html #items.tp-yt-iron-list > *,
  750. html #onRadio.tp-yt-paper-radio-button,
  751. html .toggle-button.tp-yt-paper-toggle-button,
  752. html ytd-thumbnail-overlay-toggle-button-renderer[use-expandable-tooltip] #label.ytd-thumbnail-overlay-toggle-button-renderer,
  753. html #items.ytd-post-multi-image-renderer,
  754. html #items.ytd-horizontal-card-list-renderer,
  755. html #items.yt-horizontal-list-renderer,
  756. html #left-arrow.yt-horizontal-list-renderer,
  757. html #right-arrow.yt-horizontal-list-renderer,
  758. html #items.ytd-video-description-infocards-section-renderer,
  759. html #items.ytd-video-description-music-section-renderer,
  760. html #chips.ytd-feed-filter-chip-bar-renderer,
  761. html #chips.yt-chip-cloud-renderer,
  762. html #items.ytd-merch-shelf-renderer,
  763. html #items.ytd-product-details-image-carousel-renderer,
  764. html ytd-video-preview,
  765. html #player-container.ytd-video-preview,
  766. html #primaryProgress.tp-yt-paper-progress,
  767. html #secondaryProgress.tp-yt-paper-progress,
  768. html ytd-miniplayer[enabled] /* ,
  769. html .yt-spec-touch-feedback-shape__fill,
  770. html .yt-spec-touch-feedback-shape__stroke */ {
  771. will-change: unset;
  772. }
  773.  
  774. /* other */
  775. .ytp-videowall-still-info-content[class],
  776. .ytp-suggestion-image[class] {
  777. will-change: unset !important;
  778. }
  779.  
  780. ` : '';
  781.  
  782. const ENABLE_FONT_PRE_RENDERING = typeof HTMLElement.prototype.append === 'function' ? (ENABLE_FONT_PRE_RENDERING_PREFERRED || 0) : 0;
  783. const cssText8_fonts_pre_render = ENABLE_FONT_PRE_RENDERING ? `
  784.  
  785. elzm-fonts {
  786. visibility: collapse;
  787. position: fixed;
  788. top: -10px;
  789. left: -10px;
  790. font-size: 10pt;
  791. line-height: 100%;
  792. width: 100px;
  793. height: 100px;
  794. transform: scale(0.1);
  795. transform: scale(0.01);
  796. transform: scale(0.001);
  797. transform-origin: 0 0;
  798. contain: strict;
  799. display: block;
  800.  
  801. pointer-events: none !important;
  802. user-select: none !important;
  803. }
  804.  
  805. elzm-fonts[id]#elzm-fonts-yk75g {
  806. user-select: none !important;
  807. pointer-events: none !important;
  808. }
  809.  
  810. elzm-font {
  811. visibility: collapse;
  812. position: absolute;
  813. line-height: 100%;
  814. width: 100px;
  815. height: 100px;
  816. contain: strict;
  817. display: block;
  818.  
  819. user-select: none !important;
  820. pointer-events: none !important;
  821. }
  822.  
  823. elzm-font::before {
  824. visibility: collapse;
  825. position: absolute;
  826. line-height: 100%;
  827. width: 100px;
  828. height: 100px;
  829. contain: strict;
  830. display: block;
  831.  
  832. 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';
  833.  
  834. user-select: none !important;
  835. pointer-events: none !important;
  836. }
  837.  
  838. `: '';
  839.  
  840. const cssText9_no_backdrop_filter_when_menu_shown = NO_BACKDROP_FILTER_WHEN_MENU_SHOWN ? `
  841. tp-yt-iron-dropdown.yt-live-chat-app ytd-menu-popup-renderer {
  842. -webkit-backdrop-filter: none;
  843. backdrop-filter: none;
  844. }
  845. `: '';
  846.  
  847. const cssText10_show_more_blinker = ENABLE_SHOW_MORE_BLINKER ? `
  848.  
  849. @keyframes blinker-miuzp {
  850. 0%, 60%, 100% {
  851. opacity: 1;
  852. }
  853. 30% {
  854. opacity: 0.6;
  855. }
  856. }
  857.  
  858. yt-icon-button#show-more.has-new-messages-miuzp {
  859. animation: blinker-miuzp 1.74s linear infinite;
  860. }
  861.  
  862. `: '';
  863.  
  864. const cssText11_entire_message_clickable = FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK ? `
  865.  
  866. yt-live-chat-paid-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  867. pointer-events: none !important;
  868. }
  869.  
  870. yt-live-chat-membership-item-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  871. pointer-events: none !important;
  872. }
  873.  
  874. yt-live-chat-paid-sticker-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  875. pointer-events: none !important;
  876. }
  877.  
  878. yt-live-chat-text-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  879. pointer-events: none !important; /* TO_BE_REVIEWED */
  880. }
  881.  
  882. yt-live-chat-auto-mod-message-renderer.yt-live-chat-item-list-renderer[whole-message-clickable] #menu.style-scope[class] {
  883. pointer-events: none !important;
  884. }
  885.  
  886. `: '';
  887.  
  888. const cssText12_nowrap_tooltip = MAX_TOOLTIP_NO_WRAP_WIDTH && typeof MAX_TOOLTIP_NO_WRAP_WIDTH === 'string' ? `
  889.  
  890.  
  891. tp-yt-paper-tooltip[role="tooltip"] {
  892. box-sizing: content-box !important;
  893. margin: 0px !important;
  894. padding: 0px !important;
  895. contain: none !important;
  896. }
  897.  
  898. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"] {
  899. box-sizing: content-box !important;
  900. display: inline-block;
  901. contain: none !important;
  902. }
  903.  
  904.  
  905. tp-yt-paper-tooltip[role="tooltip"] #tooltip[style-target="tooltip"]{
  906. max-width: ${MAX_TOOLTIP_NO_WRAP_WIDTH};
  907. width: max-content;
  908. text-overflow: ellipsis;
  909. overflow: hidden;
  910. white-space: nowrap;
  911. }
  912.  
  913.  
  914. `: '';
  915.  
  916.  
  917. const cssText13_no_text_select_when_menu_visible = `
  918. [menu-visible] {
  919. --sfc47-text-select: none;
  920. }
  921. [menu-visible] #header[id][class],
  922. [menu-visible] #content[id][class],
  923. [menu-visible] #header[id][class] *,
  924. [menu-visible] #content[id][class] * {
  925. user-select: var(--sfc47-text-select) !important;
  926. }
  927. [menu-visible] #menu {
  928. --sfc47-text-select: inherit;
  929. }
  930. `;
  931.  
  932. const cssText14_NO_FILTER_DROPDOWN_BORDER = NO_FILTER_DROPDOWN_BORDER ? `
  933. yt-live-chat-header-renderer.yt-live-chat-renderer #label.yt-dropdown-menu::before {
  934. border:0;
  935. }
  936. ` : '';
  937.  
  938. const cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION = FIX_ANIMATION_TICKER_TEXT_POSITION ? `
  939. .style-scope.yt-live-chat-ticker-renderer #animation-container[id][class] {
  940. position: relative;
  941. display: grid;
  942. grid-auto-columns: 1fr;
  943. grid-auto-rows: 1fr;
  944. grid-template-columns: repeat(1, 1fr);
  945. gap: 7px;
  946. padding-bottom: 0;
  947. margin-bottom: 0;
  948. padding-top: 0;
  949. align-self: flex-start;
  950. flex-wrap: nowrap;
  951. margin-top: 1px;
  952. }
  953.  
  954. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class] {
  955. margin-top: 0px;
  956. margin-bottom: 0px;
  957. flex-direction: row;
  958. flex-wrap: nowrap;
  959. align-items: center;
  960. justify-content: flex-start;
  961. }
  962.  
  963. .style-scope.yt-live-chat-ticker-renderer #animation-container > [id][class]:first-child::after {
  964. content: '補';
  965. visibility: collapse;
  966. display: inline-block;
  967. position: relative;
  968. width: 0;
  969. line-height: 22px;
  970. }
  971.  
  972. ` : '';
  973.  
  974. const cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION = FIX_AUTHOR_CHIP_BADGE_POSITION ? `
  975. #card #author-name-chip > yt-live-chat-author-chip[single-line] {
  976. flex-wrap: nowrap;
  977. white-space: nowrap;
  978. display: inline-flex;
  979. flex-direction: row;
  980. text-wrap: nowrap;
  981. flex-shrink: 0;
  982. align-items: center;
  983. }
  984.  
  985. #card #author-name-chip {
  986. display: inline-flex;
  987. flex-direction: row;
  988. align-items: flex-start;
  989. }
  990. `: '';
  991.  
  992.  
  993. // Example: https://www.youtube.com/watch?v=Xfytz-igsuc
  994. const cssText17_FIX_overwidth_banner_message = `
  995. yt-live-chat-banner-manager#live-chat-banner.style-scope.yt-live-chat-item-list-renderer {
  996. max-width: 100%;
  997. box-sizing: border-box;
  998. }
  999. `;
  1000.  
  1001.  
  1002. const cssText18_REACTION_ANIMATION_PANEL_CSS_FIX = REACTION_ANIMATION_PANEL_CSS_FIX ? `
  1003. #reaction-control-panel-overlay[class] {
  1004. contain: strict;
  1005. margin: 0;
  1006. padding: 0;
  1007. border: 0;
  1008. box-sizing: border-box;
  1009. will-change: initial;
  1010. }
  1011. #reaction-control-panel-overlay[class] *[class] {
  1012. will-change: initial;
  1013. }
  1014. `: '';
  1015.  
  1016. const cssText19_FOR_ADVANCED_TICKING = USE_ADVANCED_TICKING ? `
  1017.  
  1018. ticker-bg-overlay {
  1019. display: block;
  1020. position: absolute;
  1021. z-index: -1;
  1022. box-sizing: border-box;
  1023. border: 0;
  1024. padding: 0;
  1025. margin: 0;
  1026. width: 200%;
  1027. top: 0;
  1028. bottom: 0;
  1029. left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  1030. contain: strict;
  1031. }
  1032. ticker-bg-overlay-end2 {
  1033.  
  1034. all:unset;
  1035. position: fixed;
  1036. display: block;
  1037. margin-left: -0.5px;
  1038. top: 8px;
  1039. left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  1040.  
  1041. width: 1px;
  1042. height: 1px;
  1043. opacity: 0;
  1044. pointer-events: none;
  1045. box-sizing: border-box;
  1046. border: 0;
  1047. padding: 0;
  1048. margin: 0;
  1049. contain: strict;
  1050. z-index: -1;
  1051. visibility: collapse;
  1052.  
  1053.  
  1054. }
  1055.  
  1056.  
  1057. /* .r6-closing-ticker is provided in ADVANCED_TICKING */
  1058. /* so .r6-width-adjustable is only available for ADVANCED_TICKING too */
  1059.  
  1060. /* DO NOT use .r6-width-adjustable ~ .r6-width-adjustable => very laggy */
  1061.  
  1062. /*
  1063. yt-live-chat-ticker-renderer {
  1064. --r6-transition-duration: 0.2s;
  1065. }
  1066.  
  1067. .r6-width-adjustable {
  1068. --r6-transition-duration-v: var(--r6-transition-duration);
  1069. transition: var(--r6-transition-duration-v);
  1070. }
  1071.  
  1072. .r6-width-adjustable-f {
  1073. --r6-transition-duration-v: 0s;
  1074. }
  1075.  
  1076. .r6-closing-ticker[class] {
  1077. --r6-transition-duration-v: var(--r6-transition-duration);
  1078. }
  1079. */
  1080.  
  1081.  
  1082.  
  1083. .r6-width-adjustable {
  1084. --r6-min-width: 0;
  1085. min-width: var(--r6-min-width);
  1086. }
  1087.  
  1088. .r6-width-adjustable-f {
  1089. --r6-min-width: max-content;
  1090. }
  1091.  
  1092. .r6-closing-ticker[class] {
  1093. --r6-min-width: 0;
  1094. }
  1095.  
  1096. ` : '';
  1097. // const cssText19_FOR_ADVANCED_TICKING = `
  1098.  
  1099. // ticker-bg-overlay {
  1100. // display: block;
  1101. // position: absolute;
  1102. // z-index: -1;
  1103. // box-sizing: border-box;
  1104. // border: 0;
  1105. // padding: 0;
  1106. // margin: 0;
  1107. // width: 200%;
  1108. // top: 0;
  1109. // bottom: 0;
  1110. // left: clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%);
  1111. // contain: strict;
  1112. // }
  1113. // /*
  1114. // ticker-bg-overlay-end {
  1115. // position: absolute;
  1116. // right: 0px;
  1117. // top: 50%;
  1118. // display: block;
  1119. // width: 1px;
  1120. // height: 1px;
  1121. // opacity: 0;
  1122. // pointer-events: none;
  1123. // box-sizing: border-box;
  1124. // border: 0;
  1125. // padding: 0;
  1126. // margin: 0;
  1127. // contain: strict;
  1128. // }
  1129. // */
  1130.  
  1131. // ticker-bg-overlay-end2 {
  1132.  
  1133. // all:unset;
  1134. // position: fixed;
  1135. // display: block;
  1136. // margin-left: -0.5px;
  1137. // top: 8px;
  1138. // left: clamp(-250px, calc( 250px * ( ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) - 1 ) ), 2px);
  1139.  
  1140. // width: 1px;
  1141. // height: 1px;
  1142. // opacity: 0;
  1143. // pointer-events: none;
  1144. // box-sizing: border-box;
  1145. // border: 0;
  1146. // padding: 0;
  1147. // margin: 0;
  1148. // contain: strict;
  1149. // z-index: -1;
  1150. // visibility: collapse;
  1151.  
  1152.  
  1153. // }
  1154.  
  1155. // /* USE_ADVANCED_TICKING */
  1156.  
  1157. // /*
  1158.  
  1159. // .ticker-no-transition-time, .ticker-no-transition-time [id] {
  1160. // transition-duration: 0s !important;
  1161. // }
  1162.  
  1163. // [r6-advanced-ticking] .style-scope.yt-live-chat-ticker-renderer ~ .style-scope.yt-live-chat-ticker-renderer:not(.r6-closing-ticker) {
  1164. // transition-duration: 0s !important;
  1165. // }
  1166.  
  1167. // */
  1168.  
  1169. // .r6-width-adjustable ~ .r6-width-adjustable {
  1170. // --r6-min-width: max-content;
  1171. // }
  1172.  
  1173. // .r6-closing-ticker[class] {
  1174. // --r6-min-width: 0px;
  1175. // }
  1176.  
  1177. // .r6-width-adjustable {
  1178. // min-width: var(--r6-min-width, 0px);
  1179. // }
  1180.  
  1181.  
  1182. // /*
  1183.  
  1184.  
  1185. // .r6-width-adjustable {
  1186. // transition-duration: var(--r6-transition-duration, 0s) !important;
  1187. // }
  1188.  
  1189. // .r6-width-adjustable-first {
  1190. // --r6-transition-duration: 0.2s;
  1191. // }
  1192.  
  1193. // .r6-width-adjustable ~ .r6-width-adjustable-first {
  1194. // --r6-transition-duration: 0s;
  1195. // }
  1196.  
  1197. // .r6-closing-ticker {
  1198. // --r6-transition-duration: 0.2s;
  1199. // }
  1200. // */
  1201.  
  1202. // /*
  1203.  
  1204.  
  1205. // ey.style.position = 'absolute';
  1206. // ey.style.right = '0px';
  1207. // ey.style.top = '50%';
  1208. // ey.style.display='block';
  1209. // ey.style.width='1px';
  1210. // ey.style.height='1px';
  1211. // ey.style.opacity = '0';
  1212.  
  1213. // em.style.display = 'block';
  1214. // em.style.position = 'absolute';
  1215. // em.style.boxSizing = 'border-box';
  1216. // em.style.width = '200%';
  1217. // em.style.top = '0';
  1218. // em.style.bottom = '0';
  1219. // // em.style.height = '100%';
  1220.  
  1221.  
  1222. // // em.style.left = '-50%';
  1223. // // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  1224.  
  1225. // */
  1226.  
  1227. // `;
  1228.  
  1229. const addCss = () => `
  1230.  
  1231. @property --ticker-rtime {
  1232. syntax: "<percentage>";
  1233. inherits: false;
  1234. initial-value: 0%;
  1235. }
  1236.  
  1237. .run-ticker {
  1238. --ticker-bg:linear-gradient(90deg, var(--ticker-c1),var(--ticker-c1) var(--ticker-rtime),var(--ticker-c2) var(--ticker-rtime),var(--ticker-c2));
  1239. }
  1240.  
  1241. .run-ticker,
  1242. yt-live-chat-ticker-renderer #items > * > #container.run-ticker,
  1243. yt-live-chat-ticker-renderer[class] #items[class] > *[class] > #container.run-ticker[class]
  1244. {
  1245. background: var(--ticker-bg) !important;
  1246. }
  1247.  
  1248. yt-live-chat-ticker-dummy777-item-renderer {
  1249. background: #00000001;
  1250. }
  1251.  
  1252. yt-live-chat-ticker-dummy777-item-renderer[dummy777] {
  1253. position: fixed !important;
  1254. top: -1000px !important;
  1255. left: -1000px !important;
  1256. font-size: 1px !important;
  1257. color: transparent !important;
  1258. pointer-events: none !important;
  1259. z-index: -1 !important;
  1260. contain: strict !important;
  1261. box-sizing: border-box !important;
  1262. pointer-events: none !important;
  1263. user-select: none !important;
  1264. max-width: 1px !important;
  1265. max-height: 1px !important;
  1266. overflow: hidden !important;
  1267. visibility: collapse !important;
  1268. display: none !important;
  1269. }
  1270.  
  1271. yt-live-chat-ticker-dummy777-item-renderer #container {
  1272. background: inherit;
  1273. }
  1274.  
  1275.  
  1276. ${cssText8_fonts_pre_render}
  1277.  
  1278. ${cssText9_no_backdrop_filter_when_menu_shown}
  1279.  
  1280. @supports (contain: layout paint style) {
  1281.  
  1282. ${cssText5}
  1283.  
  1284. }
  1285.  
  1286. @supports (color: var(--general)) {
  1287.  
  1288. html {
  1289. --yt-live-chat-item-list-renderer-padding: 0px 0px;
  1290. }
  1291.  
  1292. ${cssText3_smooth_transform_position}
  1293.  
  1294. ${cssText7c_will_change_unset}
  1295.  
  1296. ${cssText7b_content_visibility_unset}
  1297.  
  1298. yt-live-chat-item-list-renderer:not([allow-scroll]) #item-scroller.yt-live-chat-item-list-renderer {
  1299. overflow-y: scroll;
  1300. padding-right: 0;
  1301. }
  1302.  
  1303. ${cssText4_smooth_transform_forced_props}
  1304.  
  1305. yt-icon[icon="down_arrow"] > *, yt-icon-button#show-more > * {
  1306. pointer-events: none !important;
  1307. }
  1308.  
  1309. #continuations, #continuations * {
  1310. contain: strict;
  1311. position: fixed;
  1312. top: 2px;
  1313. height: 1px;
  1314. width: 2px;
  1315. height: 1px;
  1316. visibility: collapse;
  1317. }
  1318.  
  1319. ${cssText6b_show_more_button}
  1320.  
  1321. ${cssText6d_input_panel_border}
  1322.  
  1323. ${cssText6c_input_panel_overflow}
  1324.  
  1325. }
  1326.  
  1327.  
  1328. @supports (overflow-anchor: auto) {
  1329.  
  1330. .no-anchor * {
  1331. overflow-anchor: none;
  1332. }
  1333. .no-anchor > item-anchor {
  1334. overflow-anchor: auto;
  1335. }
  1336.  
  1337. item-anchor {
  1338.  
  1339. height:1px;
  1340. width: 100%;
  1341. transform: scaleY(0.00001);
  1342. transform-origin:0 0;
  1343. contain: strict;
  1344. opacity:0;
  1345. display:flex;
  1346. position:relative;
  1347. flex-shrink:0;
  1348. flex-grow:0;
  1349. margin-bottom:0;
  1350. overflow:hidden;
  1351. box-sizing:border-box;
  1352. visibility: visible;
  1353. content-visibility: visible;
  1354. contain-intrinsic-size: auto 1px;
  1355. pointer-events:none !important;
  1356.  
  1357. }
  1358.  
  1359. #item-scroller.style-scope.yt-live-chat-item-list-renderer[class] {
  1360. overflow-anchor: initial !important; /* whenever ENABLE_OVERFLOW_ANCHOR or not */
  1361. }
  1362.  
  1363. html item-anchor {
  1364.  
  1365. height: 1px;
  1366. width: 1px;
  1367. top: auto;
  1368. left: auto;
  1369. right: auto;
  1370. bottom: auto;
  1371. transform: translateY(-1px);
  1372. position: absolute;
  1373. z-index: -1;
  1374.  
  1375. }
  1376.  
  1377. }
  1378.  
  1379. @supports (color: var(--pre-rendering)) {
  1380.  
  1381. @keyframes dontRenderAnimation {
  1382. 0% {
  1383. background-position-x: 3px;
  1384. }
  1385. 100% {
  1386. background-position-x: 4px;
  1387. }
  1388. }
  1389.  
  1390. .dont-render[class] {
  1391. /* visibility: collapse !important; */
  1392. /* visibility: collapse will make innerText become "" which conflicts with BetterStreamChat; see https://greasyfork.org/scripts/469878/discussions/197267 */
  1393.  
  1394. transform: scale(0.01) !important;
  1395. transform: scale(0.00001) !important;
  1396. transform: scale(0.0000001) !important;
  1397. transform-origin: 0 0 !important;
  1398. z-index: -1 !important;
  1399. contain: strict !important;
  1400. box-sizing: border-box !important;
  1401.  
  1402. height: 1px !important;
  1403. height: 0.1px !important;
  1404. height: 0.01px !important;
  1405. height: 0.0001px !important;
  1406. height: 0.000001px !important;
  1407.  
  1408. animation: dontRenderAnimation 1ms linear 80ms 1 normal forwards !important;
  1409.  
  1410. pointer-events: none !important;
  1411. user-select: none !important;
  1412.  
  1413. }
  1414.  
  1415. #sk35z {
  1416. display: block !important;
  1417.  
  1418. visibility: collapse !important;
  1419.  
  1420. transform: scale(0.01) !important;
  1421. transform: scale(0.00001) !important;
  1422. transform: scale(0.0000001) !important;
  1423. transform-origin: 0 0 !important;
  1424. z-index: -1 !important;
  1425. contain: strict !important;
  1426. box-sizing: border-box !important;
  1427.  
  1428. height: 1px !important;
  1429. height: 0.1px !important;
  1430. height: 0.01px !important;
  1431. height: 0.0001px !important;
  1432. height: 0.000001px !important;
  1433.  
  1434. position: absolute !important;
  1435. top: -1000px !important;
  1436. left: -1000px !important;
  1437.  
  1438. }
  1439.  
  1440. }
  1441.  
  1442. [rNgzQ] {
  1443. opacity: 0 !important;
  1444. pointer-events: none !important;
  1445. }
  1446.  
  1447.  
  1448. ${cssText10_show_more_blinker}
  1449.  
  1450. ${cssText11_entire_message_clickable}
  1451.  
  1452. ${cssText12_nowrap_tooltip}
  1453.  
  1454. ${cssText13_no_text_select_when_menu_visible}
  1455.  
  1456. ${cssText14_NO_FILTER_DROPDOWN_BORDER}
  1457.  
  1458. ${cssText15_FIX_ANIMATION_TICKER_TEXT_POSITION}
  1459.  
  1460. ${cssText16_FIX_AUTHOR_CHIP_BADGE_POSITION}
  1461.  
  1462. ${cssText17_FIX_overwidth_banner_message}
  1463.  
  1464. ${cssText18_REACTION_ANIMATION_PANEL_CSS_FIX}
  1465.  
  1466. ${cssText19_FOR_ADVANCED_TICKING}
  1467.  
  1468. `;
  1469.  
  1470.  
  1471. const konsole = {
  1472. nil: Symbol(),
  1473. logs: [],
  1474. style: '',
  1475. log(...args) {
  1476. konsole.logs.push({
  1477. type: 'log',
  1478. msg: [konsole.tag || konsole.nil, ...args, konsole.style || konsole.nil].filter(e => e !== konsole.nil)
  1479. });
  1480. },
  1481. setTag(tag) {
  1482. konsole.tag = tag;
  1483. },
  1484. setStyle(style) {
  1485. konsole.style = style;
  1486. },
  1487. groupCollapsed(...args) {
  1488.  
  1489. konsole.logs.push({
  1490. type: 'groupCollapsed',
  1491. msg: [...args].filter(e => e !== konsole.nil)
  1492. });
  1493. },
  1494. groupEnd() {
  1495.  
  1496. konsole.logs.push({
  1497. type: 'groupEnd'
  1498. })
  1499. },
  1500. print() {
  1501. const copy = konsole.logs.slice(0);
  1502. konsole.logs.length = 0;
  1503. for (const { type, msg } of copy) {
  1504. if (type === 'log') {
  1505. console.log(...msg)
  1506. } else if (type === 'groupCollapsed') {
  1507.  
  1508. console.groupCollapsed(...msg)
  1509. } else if (type === 'groupEnd') {
  1510. console.groupEnd();
  1511. }
  1512.  
  1513. }
  1514.  
  1515. }
  1516. };
  1517.  
  1518. /*
  1519. konsole.groupCollapsedX = (text1, text2) => {
  1520.  
  1521. if(!text2){
  1522.  
  1523. konsole.groupCollapsed(`%c${text1}`,
  1524. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;"
  1525. );
  1526. }else{
  1527.  
  1528. konsole.groupCollapsed(`%c${text1}%c${text2}`,
  1529. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  1530. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  1531. );
  1532. }
  1533. }
  1534.  
  1535. konsole.groupCollapsedX('YouTube Super Fast Chat');
  1536.  
  1537. setTimeout(()=>{
  1538.  
  1539. konsole.setTag('[[Fonts Pre-Rendering]]');
  1540. konsole.log(123);
  1541. konsole.log('wsd',332, 'ssa');
  1542. konsole.setTag('');
  1543. }, 100);
  1544.  
  1545. setTimeout(()=>{
  1546.  
  1547. konsole.setTag('[[Fonts Pre-Rendering 2]]');
  1548. konsole.log(123);
  1549. konsole.log('wsd',332, 'ssa');
  1550. konsole.setTag('');
  1551. }, 300);
  1552.  
  1553. setTimeout(()=>{
  1554.  
  1555. konsole.groupEnd();
  1556. konsole.print();
  1557. }, 1000);
  1558.  
  1559. */
  1560.  
  1561. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : (this instanceof Window ? this : window);
  1562.  
  1563. // Create a unique key for the script and check if it is already running
  1564. const hkey_script = 'mchbwnoasqph';
  1565. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  1566. win[hkey_script] = true;
  1567.  
  1568. const setTimeoutX0 = setTimeout;
  1569. const clearTimeoutX0 = clearTimeout;
  1570. const setIntervalX0 = setInterval;
  1571. const clearIntervalX0 = clearInterval;
  1572.  
  1573. const isEmptyObject = (obj) => {
  1574. for (const key in obj) {
  1575. if (obj.hasOwnProperty(key)) return false;
  1576. }
  1577. return true;
  1578. }
  1579.  
  1580. const firstObjectKey = (obj) => {
  1581. for (const key in obj) {
  1582. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1583. }
  1584. return null;
  1585. }
  1586.  
  1587.  
  1588. class LimitedSizeSet extends Set {
  1589. constructor(n) {
  1590. super();
  1591. this.limit = n;
  1592. }
  1593.  
  1594. add(key) {
  1595. if (!super.has(key)) {
  1596. super.add(key);
  1597. let n = super.size - this.limit;
  1598. if (n > 0) {
  1599. const iterator = super.values();
  1600. do {
  1601. const firstKey = iterator.next().value; // Get the first (oldest) key
  1602. super.delete(firstKey); // Delete the oldest key
  1603. } while (--n > 0)
  1604. }
  1605. }
  1606. }
  1607.  
  1608. removeAdd(key) {
  1609. super.delete(key);
  1610. this.add(key);
  1611. }
  1612.  
  1613. }
  1614.  
  1615.  
  1616. function deepCopy(obj, skipKeys) {
  1617. skipKeys = skipKeys || [];
  1618. if (!obj || typeof obj !== 'object') return obj;
  1619. if (Array.isArray(obj)) {
  1620. return obj.map(item => deepCopy(item, skipKeys));
  1621. }
  1622. const copy = {};
  1623. for (let key in obj) {
  1624. if (!skipKeys.includes(key)) {
  1625. copy[key] = deepCopy(obj[key], skipKeys);
  1626. }
  1627. }
  1628. return copy;
  1629. }
  1630.  
  1631. class Mutex {
  1632.  
  1633. constructor() {
  1634. this.p = Promise.resolve()
  1635. }
  1636.  
  1637. /**
  1638. * @param {(lockResolve: () => void)} f
  1639. */
  1640. lockWith(f) {
  1641. this.p = this.p.then(() => new Promise(f).catch(console.warn))
  1642. }
  1643.  
  1644. }
  1645.  
  1646. const PromiseExternal = ((resolve_, reject_) => {
  1647. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  1648. return class PromiseExternal extends Promise {
  1649. constructor(cb = h) {
  1650. super(cb);
  1651. if (cb === h) {
  1652. /** @type {(value: any) => void} */
  1653. this.resolve = resolve_;
  1654. /** @type {(reason?: any) => void} */
  1655. this.reject = reject_;
  1656. }
  1657. }
  1658. };
  1659. })();
  1660.  
  1661.  
  1662. const createPipeline = () => {
  1663. let pipelineMutex = Promise.resolve();
  1664. const pipelineExecution = fn => {
  1665. return new Promise((resolve, reject) => {
  1666. pipelineMutex = pipelineMutex.then(async () => {
  1667. let res;
  1668. try {
  1669. res = await fn();
  1670. } catch (e) {
  1671. console.log('error_F1', e);
  1672. reject(e);
  1673. }
  1674. resolve(res);
  1675. }).catch(console.warn);
  1676. });
  1677. };
  1678. return pipelineExecution;
  1679. };
  1680.  
  1681. let qWidthAdjustable = null;
  1682.  
  1683. /** @type {typeof PromiseExternal.prototype | null} */
  1684. let relayPromise = null;
  1685.  
  1686.  
  1687. /** @type {typeof PromiseExternal.prototype | null} */
  1688. let onPlayStateChangePromise = null;
  1689.  
  1690.  
  1691. const reuseId = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1692.  
  1693. const reuseStore = new Map();
  1694.  
  1695. const customCreateComponent = (component, data, bool)=>{
  1696.  
  1697. const componentTag = typeof component === 'string' ? component : typeof (component||0).component === 'string' ? (component||0).component : '';
  1698. if(componentTag){
  1699.  
  1700. if(REUSE_TICKER && data.id && data.fullDurationSec){
  1701. // bool (param c) is true by default; just force it to reuse no matter true or false
  1702.  
  1703. if (!bool) {
  1704. // show a warning if it is false.
  1705. console.warn('[yt-chat] REUSE_TICKER: reuse bool is false');
  1706. }
  1707.  
  1708. const record = reuseStore.get(`<${componentTag}>${data.id}:${data.fullDurationSec}`);
  1709.  
  1710. const cnt = kRef(record);
  1711.  
  1712.  
  1713. if(cnt && cnt.isAttached === false){
  1714.  
  1715. const hostElement = cnt.hostElement;
  1716.  
  1717. if(hostElement instanceof HTMLElement && hostElement.isConnected === false && hostElement.parentNode === null && hostElement.getAttribute('__reuseid__')===reuseId ){
  1718.  
  1719. // console.log(952, cnt.hostElement.parentNode)
  1720. // debugger;
  1721. if (hostElement.hasAttribute('__nogc__')) {
  1722.  
  1723. Promise.resolve(hostElement).then((hostElement) => {
  1724. // microtask to provide some time for DOM attachment.
  1725. hostElement.isConnected && hostElement.removeAttribute('__nogc__');
  1726. });
  1727.  
  1728. }
  1729.  
  1730. // ------- follow rm3 -------
  1731.  
  1732. // a.prototype._initializeProtoProperties = function(c) {
  1733. // this.__data = Object.create(c);
  1734. // this.__dataPending = Object.create(c);
  1735. // this.__dataOld = {}
  1736. // }
  1737. // a.prototype._initializeProperties = function() {
  1738. // this.__dataProto && (this._initializeProtoProperties(this.__dataProto),
  1739. // this.__dataProto = null);
  1740. // b.prototype._initializeProperties.call(this)
  1741. // }
  1742. // ;
  1743.  
  1744. cnt.__dataInvalid = false;
  1745. // cnt._initializeProtoProperties(cnt.data)
  1746.  
  1747. // window.meaa = cnt.$.container;
  1748. const cntData = cnt.data;
  1749. cnt.__data = Object.create(cntData);
  1750. cnt.__dataPending = Object.create(cntData);
  1751. cnt.__dataOld = {}
  1752.  
  1753. // console.log(12323)
  1754.  
  1755. // setTimeoutX0(()=>{
  1756. // console.log(window.meaa.parentNode)
  1757. // }, 1000)
  1758.  
  1759.  
  1760. // ------------ commented ------------
  1761. // cnt.__dataInvalid = false;
  1762. // cnt.__dataEnabled = false;
  1763. // if (cnt.__dataPending && typeof cnt.__dataPending === 'object') cnt.__dataPending = null;
  1764. // if (cnt.__dataOld && typeof cnt.__dataOld === 'object') cnt.__dataOld = null;
  1765. // if (cnt.__dataCounter && typeof cnt.__dataCounter === 'number') cnt.__dataCounter = 0;
  1766. // if ('__dataClientsInitialized' in cnt || '__dataClientsReady' in cnt) {
  1767. // cnt.__dataClientsReady = !1;
  1768. // cnt.__dataLinkedPaths = cnt.__dataToNotify = cnt.__dataPendingClients = null;
  1769. // cnt.__dataHasPaths = !1;
  1770. // cnt.__dataCompoundStorage = null; // cnt.__dataCompoundStorage = cnt.__dataCompoundStorage || null;
  1771. // cnt.__dataHost = null; // cnt.__dataHost = cnt.__dataHost || null;
  1772. // if (!cnt.__dataTemp) cnt.__dataTemp = {}; // cnt.__dataTemp = {};
  1773. // cnt.__dataClientsInitialized = !1;
  1774. // }
  1775. // try{
  1776. // cnt._flushProperties();
  1777. // }catch(e){
  1778. // console.warn(e)
  1779. // }
  1780. // for (const elm of cnt.hostElement.getElementsByTagName('*')) {
  1781. // if (elm.is) {
  1782. // const cnt = insp(elm);
  1783. // cnt.__dataInvalid = false;
  1784. // cnt.__dataEnabled = false;
  1785. // if (cnt.__dataPending && typeof cnt.__dataPending === 'object') cnt.__dataPending = null;
  1786. // if (cnt.__dataOld && typeof cnt.__dataOld === 'object') cnt.__dataOld = null;
  1787. // if (cnt.__dataCounter && typeof cnt.__dataCounter === 'number') cnt.__dataCounter = 0;
  1788. // if ('__dataClientsInitialized' in cnt || '__dataClientsReady' in cnt) {
  1789. // cnt.__dataClientsReady = !1;
  1790. // cnt.__dataLinkedPaths = cnt.__dataToNotify = cnt.__dataPendingClients = null;
  1791. // cnt.__dataHasPaths = !1;
  1792. // cnt.__dataCompoundStorage = null; // cnt.__dataCompoundStorage = cnt.__dataCompoundStorage || null;
  1793. // cnt.__dataHost = null; // cnt.__dataHost = cnt.__dataHost || null;
  1794. // if (!cnt.__dataTemp) cnt.__dataTemp = {}; // cnt.__dataTemp = {};
  1795. // cnt.__dataClientsInitialized = !1;
  1796. // }
  1797. // try {
  1798. // cnt._flushProperties();
  1799. // } catch (e) {
  1800. // console.warn(e)
  1801. // }
  1802. // if (elm.nodeName === 'YT-ICON') {
  1803. // // console.log(2133, JSON.stringify( cnt.__data))
  1804. // const qq = Object.assign({}, cnt.__data)
  1805. // console.log(1232466)
  1806. // const _qww = cnt;
  1807. // cnt.__data = new Proxy(Object.assign({}, qq), {
  1808. // get(target, p) {
  1809. // console.log(12838, p)
  1810. // if (p === 'icon') {
  1811. // window.wmk = _qww.hostElement;
  1812. // // debugger;
  1813. // }
  1814. // return target[p]
  1815. // },
  1816. // set(target, p, v) {
  1817. // console.log(12839, p)
  1818. // target[p] = v;
  1819. // if (p === 'icon') debugger;
  1820. // return true;
  1821. // }
  1822. // });
  1823. // Promise.resolve(cnt).then((cnt) => {
  1824. // cnt.__data = Object.assign({}, qq);
  1825. // });
  1826. // }
  1827. // // let q = elm.nextSibling;
  1828. // // let h = elm.parentNode;
  1829. // // elm.remove();
  1830. // // h.insertBefore(elm, q);
  1831. // // console.log(2233, elm)
  1832. // }
  1833. // }
  1834. // ------------ commented ------------
  1835.  
  1836. // ------- follow rm3 -------
  1837.  
  1838. // console.log('[yt-chat] reuse')
  1839.  
  1840.  
  1841. return hostElement;
  1842.  
  1843.  
  1844. }
  1845.  
  1846. }
  1847.  
  1848. }
  1849.  
  1850. }
  1851. DEBUG_customCreateComponent && console.log(component, data, bool);
  1852. /*
  1853.  
  1854. const cntData = this.data;
  1855. reuseStore.set(`${cntData.id}:${cntData.fullDurationSec}`, mWeakRef(this));
  1856. */
  1857.  
  1858. }
  1859.  
  1860. const valAssign = (elm, attr, val) => {
  1861. if (typeof val === 'number') val = val.toFixed(3);
  1862. if (!(Math.abs(elm.style.getPropertyValue(attr) - val) < 1e-5)) {
  1863. elm.style.setProperty(attr, val);
  1864. return true;
  1865. }
  1866. return false;
  1867. };
  1868.  
  1869. let playEventsStack = Promise.resolve();
  1870.  
  1871.  
  1872. let playerProgressChangedArg1 = null;
  1873. let playerProgressChangedArg2 = null;
  1874. let playerProgressChangedArg3 = null;
  1875.  
  1876. let dntElementWeak = null;
  1877.  
  1878.  
  1879. let timestampUnderLiveMode = false;
  1880.  
  1881. const updateTickerCurrentTime = () => {
  1882.  
  1883. if (resistanceUpdateDebugMode) {
  1884. console.log('updateTickerCurrentTime')
  1885.  
  1886. if (!dntElementWeak || !kRef(dntElementWeak)) dntElementWeak = mWeakRef(document.querySelector('yt-live-chat-ticker-renderer'));
  1887. timestampUnderLiveMode = true;
  1888. }
  1889.  
  1890. const dntElement = kRef(dntElementWeak);
  1891. const v = timestampUnderLiveMode ? (Date.now() / 1000 - timeOriginDT / 1000) : playerProgressChangedArg1;
  1892. if (dntElement instanceof HTMLElement && v >= 0) {
  1893. valAssign(dntElement, '--ticker-current-time', v);
  1894. }
  1895. }
  1896.  
  1897. // ================== FOR USE_ADVANCED_TICKING ================
  1898.  
  1899. const timeOriginDT = +new Date(performance.timeOrigin);
  1900. let startResistanceUpdaterStarted = false;
  1901.  
  1902. const RESISTANCE_UPDATE_OPT = 3;
  1903. let resistanceUpdateLast = 0;
  1904. let resistanceUpdateBusy = false;
  1905. const resistanceUpdateDebugMode = false;
  1906. const allBackgroundOverLays = document.getElementsByTagName('ticker-bg-overlay');
  1907. const rgFlag = {};
  1908. const resistanceUpdateFn = (b) => {
  1909. if (!resistanceUpdateDebugMode && allBackgroundOverLays.length === 0) return;
  1910. resistanceUpdateBusy = false;
  1911. const t = Date.now();
  1912. const d = t - resistanceUpdateLast;
  1913. if (d > 375) {
  1914. resistanceUpdateLast = t;
  1915. updateTickerCurrentTime();
  1916. }
  1917. }
  1918. const resistanceUpdateFn_ = () => {
  1919. if (!resistanceUpdateBusy) {
  1920. resistanceUpdateBusy = true;
  1921. Promise.resolve().then(resistanceUpdateFn);
  1922. }
  1923. }
  1924. const startResistanceUpdater = () => {
  1925.  
  1926. if (startResistanceUpdaterStarted) return;
  1927. startResistanceUpdaterStarted = true;
  1928.  
  1929.  
  1930. if (RESISTANCE_UPDATE_OPT & 1)
  1931. document.addEventListener('yt-action', () => {
  1932. resistanceUpdateFn_();
  1933. }, true)
  1934.  
  1935. resistanceUpdateFn_();
  1936. setIntervalX0(resistanceUpdateFn_, 400);
  1937. }
  1938.  
  1939. if(resistanceUpdateDebugMode) startResistanceUpdater();
  1940.  
  1941.  
  1942. function dr(s) {
  1943. // reserved for future use
  1944. return s;
  1945. // return window.deWeakJS ? window.deWeakJS(s) : s;
  1946. }
  1947.  
  1948. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1949. const indr = o => insp(o).$ || o.$ || 0;
  1950.  
  1951. const getProto = (element) => {
  1952. if (element) {
  1953. const cnt = insp(element);
  1954. return cnt.constructor.prototype || null;
  1955. }
  1956. return null;
  1957. }
  1958.  
  1959.  
  1960.  
  1961. const logFn = (key, f) => {
  1962. return Function.prototype.bind.call(console.log, console, `%c ${key}`, 'background: #222; color: #bada55', f);
  1963. }
  1964.  
  1965.  
  1966.  
  1967. const assertor = (f) => f() || (console.assert(false, f + ""), false);
  1968.  
  1969. const fnIntegrity = (f, d) => {
  1970.  
  1971.  
  1972. if (!f || typeof f !== 'function') {
  1973. console.warn('f is not a function', f);
  1974. return;
  1975. }
  1976. // return; // M44
  1977. let p = `${f}`, s = 0, j = -1, w = 0;
  1978. // return; // M44
  1979. for (let i = 0, l = p.length; i < l; i++) {
  1980. const t = p[i];
  1981. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1982. if (j < i - 1) w++;
  1983. j = i;
  1984. } else {
  1985. s++;
  1986. }
  1987. }
  1988. // if(p.length > 44 && p.length < 50){
  1989.  
  1990. // (window.skam|| (window.skam=[])).push(p);
  1991. // return false;
  1992. // }
  1993.  
  1994. // if(p.length > 405 && p.length < 415 ){ //350 450
  1995.  
  1996.  
  1997. // //  [353, 411, 411, 411]
  1998.  
  1999. // // if(p.length >= 350 && p.length<=450){
  2000.  
  2001. // // (window.skam|| (window.skam=[])).push(p.length);
  2002. // // }
  2003. // (window.skam|| (window.skam=[])).push(p);
  2004. // return false;
  2005. // }
  2006.  
  2007. // if(p.length < 50) return true; else return false;
  2008. // return; // M44
  2009. let itz = `${f.length}.${s}.${w}`;
  2010. if (!d) {
  2011. return itz;
  2012. } else if (itz !== d) {
  2013. console.warn('fnIntegrity=false', itz);
  2014. return false;
  2015. } else {
  2016. return true;
  2017. }
  2018. }
  2019.  
  2020. const px2cm = (px) => px * window.devicePixelRatio * 0.026458333;
  2021. const px2mm = (px) => px * window.devicePixelRatio * 0.26458333;
  2022.  
  2023.  
  2024. ; (ENABLE_FLAGS_MAINTAIN_STABLE_LIST || ENABLE_FLAGS_REUSE_COMPONENTS || DISABLE_FLAGS_SHADYDOM_FREE) && (() => {
  2025.  
  2026. const _config_ = () => {
  2027. try {
  2028. return ytcfg.data_;
  2029. } catch (e) { }
  2030. return null;
  2031. };
  2032.  
  2033. const flagsFn = (EXPERIMENT_FLAGS) => {
  2034.  
  2035. // console.log(700)
  2036.  
  2037. if (!EXPERIMENT_FLAGS) return;
  2038.  
  2039. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST) {
  2040. if (USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true : true) {
  2041. // EXPERIMENT_FLAGS.kevlar_tuner_should_test_maintain_stable_list = true; // timestamp toggle issue
  2042. EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list = true;
  2043. // console.log(701)
  2044. }
  2045. }
  2046.  
  2047. if (ENABLE_FLAGS_REUSE_COMPONENTS) {
  2048. EXPERIMENT_FLAGS.kevlar_tuner_should_test_reuse_components = true;
  2049. EXPERIMENT_FLAGS.kevlar_tuner_should_reuse_components = true;
  2050. // console.log(702);
  2051. }
  2052.  
  2053. if (DISABLE_FLAGS_SHADYDOM_FREE) {
  2054. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_node_methods = false;
  2055. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_query_methods = false;
  2056. EXPERIMENT_FLAGS.enable_shadydom_free_scoped_readonly_properties_batch_one = false;
  2057. EXPERIMENT_FLAGS.enable_shadydom_free_parent_node = false;
  2058. EXPERIMENT_FLAGS.enable_shadydom_free_children = false;
  2059. EXPERIMENT_FLAGS.enable_shadydom_free_last_child = false;
  2060. }
  2061.  
  2062. // EXPERIMENT_FLAGS.enable_button_behavior_reuse = false;
  2063.  
  2064. };
  2065.  
  2066. const uf = (config_) => {
  2067. config_ = config_ || _config_();
  2068. if (config_) {
  2069. const { EXPERIMENT_FLAGS, EXPERIMENTS_FORCED_FLAGS } = config_;
  2070. if (EXPERIMENT_FLAGS) {
  2071. flagsFn(EXPERIMENT_FLAGS);
  2072. if (EXPERIMENTS_FORCED_FLAGS) flagsFn(EXPERIMENTS_FORCED_FLAGS);
  2073. }
  2074. }
  2075. }
  2076.  
  2077. window._ytConfigHacks.add((config_) => {
  2078. uf(config_);
  2079. });
  2080.  
  2081. uf();
  2082.  
  2083. })();
  2084.  
  2085. if (DISABLE_Translation_By_Google) {
  2086.  
  2087. let mo = new MutationObserver(() => {
  2088.  
  2089. if (!mo) return;
  2090. let h = document.head;
  2091. if (!h) return;
  2092. mo.disconnect();
  2093. mo.takeRecords();
  2094. mo = null;
  2095.  
  2096. let meta = document.createElement('meta');
  2097. meta.setAttribute('name', 'google');
  2098. meta.setAttribute('content', 'notranslate');
  2099. h.appendChild(meta);
  2100.  
  2101.  
  2102. });
  2103. mo.observe(document, { subtree: true, childList: true });
  2104. }
  2105.  
  2106.  
  2107. console.assert(MAX_ITEMS_FOR_TOTAL_DISPLAY > 0 && MAX_ITEMS_FOR_FULL_FLUSH > 0 && MAX_ITEMS_FOR_TOTAL_DISPLAY > MAX_ITEMS_FOR_FULL_FLUSH)
  2108.  
  2109. const isContainSupport = CSS.supports('contain', 'layout paint style');
  2110. if (!isContainSupport) {
  2111. console.warn("Your browser does not support css property 'contain'.\nPlease upgrade to the latest version.".trim());
  2112. }
  2113.  
  2114. const isOverflowAnchorSupport = CSS.supports('overflow-anchor', 'auto');
  2115. if (!isOverflowAnchorSupport) {
  2116. console.warn("Your browser does not support css property 'overflow-anchor'.\nPlease upgrade to the latest version.".trim());
  2117. }
  2118.  
  2119. const ENABLE_OVERFLOW_ANCHOR = ENABLE_OVERFLOW_ANCHOR_PREFERRED && isOverflowAnchorSupport && ENABLE_NO_SMOOTH_TRANSFORM;
  2120.  
  2121.  
  2122. const fxOperator = (proto, propertyName) => {
  2123. let propertyDescriptorGetter = null;
  2124. try {
  2125. propertyDescriptorGetter = Object.getOwnPropertyDescriptor(proto, propertyName).get;
  2126. } catch (e) { }
  2127. return typeof propertyDescriptorGetter === 'function' ? (e) => {
  2128. try {
  2129.  
  2130. return propertyDescriptorGetter.call(dr(e));
  2131. } catch (e) { }
  2132. return e[propertyName];
  2133. } : (e) => e[propertyName];
  2134. };
  2135.  
  2136. const nodeParent = fxOperator(Node.prototype, 'parentNode');
  2137. // const nFirstElem = fxOperator(HTMLElement.prototype, 'firstElementChild');
  2138. const nPrevElem = fxOperator(HTMLElement.prototype, 'previousElementSibling');
  2139. const nNextElem = fxOperator(HTMLElement.prototype, 'nextElementSibling');
  2140. const nLastElem = fxOperator(HTMLElement.prototype, 'lastElementChild');
  2141.  
  2142. const groupCollapsed = (text1, text2) => {
  2143.  
  2144. let w = 'groupCollapsed';
  2145. if (DEBUG_LOG_GROUP_EXPAND) w = 'group';
  2146. console[w](`%c${text1}%c${text2}`,
  2147. "background-color: #010502; color: #6acafe; font-weight: 700; padding: 2px;",
  2148. "background-color: #010502; color: #6ad9fe; font-weight: 300; padding: 2px;"
  2149. );
  2150. }
  2151.  
  2152. // const microNow = () => performance.now() + (performance.timeOrigin || performance.timing.navigationStart);
  2153.  
  2154.  
  2155. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  2156. const onRegistryReady = (callback) => {
  2157. if (typeof customElements === 'undefined') {
  2158. if (!('__CE_registry' in document)) {
  2159. // https://github.com/webcomponents/polyfills/
  2160. Object.defineProperty(document, '__CE_registry', {
  2161. get() {
  2162. // return undefined
  2163. },
  2164. set(nv) {
  2165. if (typeof nv == 'object') {
  2166. delete this.__CE_registry;
  2167. this.__CE_registry = nv;
  2168. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2169. }
  2170. return true;
  2171. },
  2172. enumerable: false,
  2173. configurable: true
  2174. })
  2175. }
  2176. let eventHandler = (evt) => {
  2177. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2178. const f = callback;
  2179. callback = null;
  2180. eventHandler = null;
  2181. f();
  2182. };
  2183. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2184. } else {
  2185. callback();
  2186. }
  2187. };
  2188.  
  2189. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  2190.  
  2191. const renderReadyPn = typeof ResizeObserver !== 'undefined' ? (sizingTarget) => {
  2192.  
  2193. return new Promise(resolve => {
  2194.  
  2195. let ro = new ResizeObserver(entries => {
  2196. if (entries && entries.length >= 1) {
  2197. resolve();
  2198. ro.disconnect();
  2199. ro = null;
  2200. }
  2201. });
  2202. ro.observe(sizingTarget);
  2203.  
  2204.  
  2205.  
  2206. });
  2207.  
  2208. } : (sizingTarget) => {
  2209.  
  2210.  
  2211. return new Promise(resolve => {
  2212.  
  2213. let io = new IntersectionObserver(entries => {
  2214. if (entries && entries.length >= 1) {
  2215. resolve();
  2216. io.disconnect();
  2217. io = null;
  2218. }
  2219. });
  2220. io.observe(sizingTarget);
  2221.  
  2222.  
  2223.  
  2224. });
  2225.  
  2226. };
  2227.  
  2228. /* globals WeakRef:false */
  2229.  
  2230. /** @type {(o: Object | null) => WeakRef | null} */
  2231. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  2232.  
  2233. /** @type {(wr: Object | null) => Object | null} */
  2234. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  2235.  
  2236. const { insertBeforeNaFn, appendChildNaFn } = (() => {
  2237. // native methods
  2238.  
  2239. const dummyElement = document.createElement('dummy-388');
  2240. const HTMLElement = dummyElement.constructor;
  2241.  
  2242. const insertBefore = HTMLElement.prototype.insertBefore;
  2243. const appendChild = HTMLElement.prototype.appendChild;
  2244.  
  2245. return {
  2246. insertBeforeNaFn: (parent, node, child) => {
  2247. insertBefore.call(parent, node, child);
  2248. },
  2249. appendChildNaFn: (parent, node) => {
  2250. appendChild.call(parent, node);
  2251. }
  2252. };
  2253.  
  2254. /*
  2255. const insertBeforeFn = (parent, node, child) => {
  2256. if ('__shady_native_insertBefore' in parent) parent.__shady_native_insertBefore(node, child);
  2257. else parent.insertBefore(node, child);
  2258. }
  2259.  
  2260. const appendChildFn = (parent, node) =>{
  2261. if('__shady_native_appendChild' in parent) parent.__shady_native_appendChild(node);
  2262. else parent.appendChild(node);
  2263. }
  2264. */
  2265.  
  2266. })();
  2267.  
  2268.  
  2269.  
  2270. let __LCRInjection__ = 0; // 0 for no injection
  2271. const LCRImmedidates = []; // array of sync. func
  2272.  
  2273. let getLCRDummyP_ = null;
  2274. // lcrPromiseFn
  2275. const getLCRDummy = () => {
  2276. // direct createElement or createComponent_ will make the emoji rendering crashed. reason TBC
  2277.  
  2278. return getLCRDummyP_ || (getLCRDummyP_ = Promise.all([customElements.whenDefined('yt-live-chat-app'), customElements.whenDefined('yt-live-chat-renderer')]).then(async () => {
  2279.  
  2280. const tag = "yt-live-chat-renderer"
  2281. let dummy = document.querySelector(tag);
  2282. if (!dummy) {
  2283.  
  2284. let mo = null;
  2285.  
  2286. const ytLiveChatApp = document.querySelector('yt-live-chat-app') || document.createElement('yt-live-chat-app');
  2287.  
  2288. const lcaProto = getProto(ytLiveChatApp);
  2289. let fz38;
  2290.  
  2291. let qt38=0;
  2292. let bypass = false;
  2293.  
  2294.  
  2295. dummy = await new Promise(resolve => {
  2296.  
  2297.  
  2298. if (typeof lcaProto.createComponent_ === 'function' && !lcaProto.createComponent99_ && lcaProto.createComponent_.length === 3) {
  2299. console.log('[yt-chat-lcr] lcaProto.createComponent_ is found');
  2300.  
  2301. lcaProto.createComponent99_ = lcaProto.createComponent_;
  2302. lcaProto.createComponent98_ = function (a, b, c) {
  2303. const z = customCreateComponent(a,b,c);
  2304. if(z !== undefined) return z;
  2305. // (3) ['yt-live-chat-renderer', {…}, true]
  2306. const r = this.createComponent99_(a, b,c);
  2307. const componentTag = (typeof a === 'string' ? a : (a||0).component) || `${(r||0).nodeName}`.toLowerCase();
  2308. if ( componentTag === 'yt-live-chat-renderer' && !bypass) {
  2309. qt38 = 1;
  2310.  
  2311. __LCRInjection__ = __LCRInjection__ | 1;
  2312.  
  2313. // r.polymerController.__proto__.handleLiveChatActions471_ = r.polymerController.__proto__.handleLiveChatActions_;
  2314. // r.polymerController.__proto__.handleLiveChatActions_ = function (arr) {
  2315.  
  2316.  
  2317. // preprocessChatLiveActions(arr);
  2318.  
  2319. // return this.handleLiveChatActions471_(arr);
  2320.  
  2321.  
  2322. // }
  2323.  
  2324. for (const f of LCRImmedidates) {
  2325. f(r);
  2326. }
  2327. LCRImmedidates.length = 0;
  2328.  
  2329. resolve(r); // note: this dom is not yet adopted, but promise resolve is later than ops.
  2330. console.log('[yt-chat-lcr] element found by method 1');
  2331. }
  2332. return r;
  2333. };
  2334. lcaProto.createComponent_ = lcaProto.createComponent98_;
  2335.  
  2336. if (!USE_OBTAIN_LCR_BY_BOTH_METHODS) return;
  2337.  
  2338. }
  2339.  
  2340. // console.log('[yt-chat] lcaProto traditional');
  2341.  
  2342. const pz38 = document.getElementsByTagName(tag);
  2343. fz38 = () => {
  2344. const t = pz38[0]
  2345. if (t) {
  2346. qt38 = 2;
  2347.  
  2348. __LCRInjection__ = __LCRInjection__ | 2;
  2349. resolve(t);
  2350. console.log('[yt-chat-lcr] element found by method 2');
  2351. }
  2352. };
  2353. mo = new MutationObserver(fz38);
  2354. mo.observe(document, { subtree: true, childList: true, attributes: true });
  2355. document.addEventListener('yt-action', fz38, true);
  2356. fz38();
  2357.  
  2358. });
  2359.  
  2360. bypass = true;
  2361.  
  2362. if (mo) {
  2363. mo.disconnect();
  2364. mo.takeRecords();
  2365. mo = null;
  2366. }
  2367. if (fz38) {
  2368. document.removeEventListener('yt-action', fz38, true);
  2369. fz38 = null;
  2370. }
  2371. console.log(`[yt-chat-lcr] lcr appears, dom = ${document.getElementsByTagName(tag).length}, method = ${qt38}`);
  2372.  
  2373.  
  2374. // if (lcaProto.createComponent99_ && lcaProto.createComponent_ && lcaProto.createComponent98_ === lcaProto.createComponent_) {
  2375. // lcaProto.createComponent_ = lcaProto.createComponent99_;
  2376. // lcaProto.createComponent99_ = null;
  2377. // lcaProto.createComponent98_ = null;
  2378. // }
  2379.  
  2380. } else {
  2381. console.log('[yt-chat-lcr] lcr exists');
  2382. }
  2383. return dummy;
  2384.  
  2385. }));
  2386. }
  2387.  
  2388. const { addCssManaged } = (() => {
  2389.  
  2390. const addFontPreRendering = () => {
  2391.  
  2392. groupCollapsed("YouTube Super Fast Chat", " | Fonts Pre-Rendering");
  2393.  
  2394. let efsContainer = document.createElement('elzm-fonts');
  2395. efsContainer.id = 'elzm-fonts-yk75g'
  2396.  
  2397. const arr = [];
  2398. let p = document.createElement('elzm-font');
  2399. arr.push(p);
  2400.  
  2401. if (ENABLE_FONT_PRE_RENDERING & 1) {
  2402. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2403.  
  2404. p = document.createElement('elzm-font');
  2405. p.style.fontWeight = size;
  2406. arr.push(p);
  2407. }
  2408. }
  2409.  
  2410. if (ENABLE_FONT_PRE_RENDERING & 2) {
  2411. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2412.  
  2413. p = document.createElement('elzm-font');
  2414. p.style.fontFamily = 'Roboto';
  2415. p.style.fontWeight = size;
  2416. arr.push(p);
  2417. }
  2418. }
  2419.  
  2420. if (ENABLE_FONT_PRE_RENDERING & 4) {
  2421. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2422.  
  2423. p = document.createElement('elzm-font');
  2424. p.style.fontFamily = '"YouTube Noto",Roboto,Arial,Helvetica,sans-serif';
  2425. p.style.fontWeight = size;
  2426. arr.push(p);
  2427. }
  2428. }
  2429.  
  2430.  
  2431. if (ENABLE_FONT_PRE_RENDERING & 8) {
  2432. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2433.  
  2434. p = document.createElement('elzm-font');
  2435. p.style.fontFamily = '"Noto",Roboto,Arial,Helvetica,sans-serif';
  2436. p.style.fontWeight = size;
  2437. arr.push(p);
  2438. }
  2439. }
  2440.  
  2441.  
  2442. if (ENABLE_FONT_PRE_RENDERING & 16) {
  2443. for (const size of [100, 200, 300, 400, 500, 600, 700, 800, 900]) {
  2444.  
  2445. p = document.createElement('elzm-font');
  2446. p.style.fontFamily = 'sans-serif';
  2447. p.style.fontWeight = size;
  2448. arr.push(p);
  2449. }
  2450. }
  2451.  
  2452. console.log('number of elzm-font elements', arr.length);
  2453.  
  2454. HTMLElement.prototype.append.apply(efsContainer, arr);
  2455.  
  2456. (document.body || document.documentElement).appendChild(efsContainer);
  2457.  
  2458.  
  2459. console.log('elzm-font elements have been added to the page for rendering.');
  2460.  
  2461. console.groupEnd();
  2462.  
  2463. }
  2464.  
  2465. let isCssAdded = false;
  2466.  
  2467. function addCssElement() {
  2468. let s = document.createElement('style');
  2469. s.id = 'ewRvC';
  2470. return s;
  2471. }
  2472.  
  2473. const addCssManaged = () => {
  2474. if (!isCssAdded && document.documentElement && document.head) {
  2475. isCssAdded = true;
  2476. document.head.appendChild(dr(addCssElement())).textContent = addCss();
  2477. if (ENABLE_FONT_PRE_RENDERING) {
  2478. Promise.resolve().then(addFontPreRendering)
  2479. }
  2480. }
  2481. }
  2482.  
  2483. return { addCssManaged };
  2484. })();
  2485.  
  2486.  
  2487. const { setupStyle } = (() => {
  2488.  
  2489. const sp7 = Symbol();
  2490.  
  2491. const proxyHelperFn = (dummy) => ({
  2492.  
  2493. get(target, prop) {
  2494. return (prop in dummy) ? dummy[prop] : prop === sp7 ? target : target[prop];
  2495. },
  2496. set(target, prop, value) {
  2497. if (!(prop in dummy)) {
  2498. target[prop] = value;
  2499. }
  2500. return true;
  2501. },
  2502. has(target, prop) {
  2503. return (prop in target);
  2504. },
  2505. deleteProperty(target, prop) {
  2506. return true;
  2507. },
  2508. ownKeys(target) {
  2509. return Object.keys(target);
  2510. },
  2511. defineProperty(target, key, descriptor) {
  2512. return Object.defineProperty(target, key, descriptor);
  2513. },
  2514. getOwnPropertyDescriptor(target, key) {
  2515. return Object.getOwnPropertyDescriptor(target, key);
  2516. },
  2517.  
  2518. });
  2519.  
  2520. const setupStyle = (m1, m2) => {
  2521. if (!ENABLE_NO_SMOOTH_TRANSFORM) return;
  2522.  
  2523. const dummy1v = {
  2524. transform: '',
  2525. height: '',
  2526. minHeight: '',
  2527. paddingBottom: '',
  2528. paddingTop: ''
  2529. };
  2530.  
  2531. const dummyStyleFn = (k) => (function () { const style = this[sp7]; return style[k](...arguments); });
  2532. for (const k of ['toString', 'getPropertyPriority', 'getPropertyValue', 'item', 'removeProperty', 'setProperty']) {
  2533. dummy1v[k] = dummyStyleFn(k);
  2534. }
  2535.  
  2536. const dummy1p = proxyHelperFn(dummy1v);
  2537. const sp1v = new Proxy(m1.style, dummy1p);
  2538. const sp2v = new Proxy(m2.style, dummy1p);
  2539. Object.defineProperty(m1, 'style', { get() { return sp1v }, set() { }, enumerable: true, configurable: true });
  2540. Object.defineProperty(m2, 'style', { get() { return sp2v }, set() { }, enumerable: true, configurable: true });
  2541. m1.removeAttribute("style");
  2542. m2.removeAttribute("style");
  2543.  
  2544. }
  2545.  
  2546. return { setupStyle };
  2547.  
  2548. })();
  2549.  
  2550.  
  2551.  
  2552. function setThumbnails(config) {
  2553.  
  2554. const { baseObject, thumbnails, flag0, imageLinks } = config;
  2555.  
  2556. if (flag0 || (ENABLE_PRELOAD_THUMBNAIL && imageLinks)) {
  2557.  
  2558.  
  2559. if (thumbnails && thumbnails.length > 0) {
  2560. if (flag0 > 0 && thumbnails.length > 1) {
  2561. let pSize = 0;
  2562. let newThumbnails = [];
  2563. for (const thumbnail of thumbnails) {
  2564. if (!thumbnail || !thumbnail.url) continue;
  2565. const squarePhoto = thumbnail.width === thumbnail.height && typeof thumbnail.width === 'number';
  2566. const condSize = pSize <= 0 || (flag0 === 1 ? pSize > thumbnail.width : pSize < thumbnail.width);
  2567. const leastSizeFulfilled = squarePhoto ? thumbnail.width >= LEAST_IMAGE_SIZE : true;
  2568. if ((!squarePhoto || condSize) && leastSizeFulfilled) {
  2569. newThumbnails.push(thumbnail);
  2570. if (imageLinks) imageLinks.add(thumbnail.url);
  2571. }
  2572. if (squarePhoto && condSize && leastSizeFulfilled) {
  2573. pSize = thumbnail.width;
  2574. }
  2575. }
  2576. if (thumbnails.length !== newThumbnails.length && thumbnails === baseObject.thumbnails && newThumbnails.length > 0) {
  2577. baseObject.thumbnails = newThumbnails;
  2578. } else {
  2579. newThumbnails.length = 0;
  2580. }
  2581. newThumbnails = null;
  2582. } else {
  2583. for (const thumbnail of thumbnails) {
  2584. if (thumbnail && thumbnail.url) {
  2585. if (imageLinks) imageLinks.add(thumbnail.url);
  2586. }
  2587. }
  2588. }
  2589. }
  2590.  
  2591. }
  2592. }
  2593.  
  2594. function fixLiveChatItem(item, imageLinks) {
  2595. const liveChatTextMessageRenderer = (item || 0).liveChatTextMessageRenderer || 0;
  2596. if (liveChatTextMessageRenderer) {
  2597. const messageRuns = (liveChatTextMessageRenderer.message || 0).runs || 0;
  2598. if (messageRuns && messageRuns.length > 0) {
  2599. for (const run of messageRuns) {
  2600. const emojiImage = (((run || 0).emoji || 0).image || 0);
  2601. setThumbnails({
  2602. baseObject: emojiImage,
  2603. thumbnails: emojiImage.thumbnails,
  2604. flag0: EMOJI_IMAGE_SINGLE_THUMBNAIL,
  2605. imageLinks
  2606. });
  2607. }
  2608. }
  2609. const authorPhoto = liveChatTextMessageRenderer.authorPhoto || 0;
  2610. setThumbnails({
  2611. baseObject: authorPhoto,
  2612. thumbnails: authorPhoto.thumbnails,
  2613. flag0: AUTHOR_PHOTO_SINGLE_THUMBNAIL,
  2614. imageLinks
  2615. });
  2616. }
  2617. }
  2618.  
  2619.  
  2620.  
  2621. let kptPF = null;
  2622. const emojiPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_EMOJI);
  2623. const authorPhotoPrefetched = new LimitedSizeSet(PREFETCH_LIMITED_SIZE_AUTHOR_PHOTO);
  2624.  
  2625. function linker(link, rel, href, _as) {
  2626. return new Promise(resolve => {
  2627. if (!link) link = document.createElement('link');
  2628. link.rel = rel;
  2629. if (_as) link.setAttribute('as', _as);
  2630. link.onload = function () {
  2631. resolve({
  2632. link: this,
  2633. success: true
  2634. })
  2635. this.remove();
  2636. };
  2637. link.onerror = function () {
  2638. resolve({
  2639. link: this,
  2640. success: false
  2641. });
  2642. this.remove();
  2643. };
  2644. link.href = href;
  2645. document.head.appendChild(link);
  2646. link = null;
  2647. });
  2648. }
  2649.  
  2650.  
  2651.  
  2652. const cleanContext = async (win) => {
  2653. const waitFn = requestAnimationFrame; // shall have been binded to window
  2654. try {
  2655. let mx = 16; // MAX TRIAL
  2656. const frameId = 'vanillajs-iframe-v1';
  2657. /** @type {HTMLIFrameElement | null} */
  2658. let frame = document.getElementById(frameId);
  2659. let removeIframeFn = null;
  2660. if (!frame) {
  2661. frame = document.createElement('iframe');
  2662. frame.id = frameId;
  2663. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2664. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2665. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2666. n.appendChild(frame);
  2667. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2668. const root = document.documentElement;
  2669. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2670. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2671.  
  2672. removeIframeFn = (setTimeout) => {
  2673. const removeIframeOnDocumentReady = (e) => {
  2674. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2675. e = n;
  2676. n = win = removeIframeFn = 0;
  2677. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2678. }
  2679. if (!setTimeout || document.readyState !== 'loading') {
  2680. removeIframeOnDocumentReady();
  2681. } else {
  2682. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2683. }
  2684. }
  2685. }
  2686. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2687. const fc = frame.contentWindow;
  2688. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2689. try {
  2690. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle } = fc;
  2691. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, getComputedStyle };
  2692. for (let k in res) res[k] = res[k].bind(win); // necessary
  2693. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2694.  
  2695. /** @type {HTMLElement} */
  2696. const HTMLElementProto = fc.HTMLElement.prototype;
  2697. /** @type {EventTarget} */
  2698. const EventTargetProto = fc.EventTarget.prototype;
  2699. // jsonParseFix = {
  2700. // _JSON: fc.JSON, _parse: fc.JSON.parse
  2701. // }
  2702. return {
  2703. ...res,
  2704. animate: HTMLElementProto.animate,
  2705. addEventListener: EventTargetProto.addEventListener,
  2706. removeEventListener: EventTargetProto.removeEventListener
  2707. };
  2708. } catch (e) {
  2709. if (removeIframeFn) removeIframeFn();
  2710. return null;
  2711. }
  2712. } catch (e) {
  2713. console.warn(e);
  2714. return null;
  2715. }
  2716. };
  2717.  
  2718.  
  2719. let xoIcjPr = null;
  2720. window.addEventListener('message', (evt) => {
  2721. if ((evt || 0).data === 'xoIcj' && xoIcjPr !== null) xoIcjPr.resolve();
  2722. });
  2723. const timelineResolve = async () => {
  2724. if (xoIcjPr !== null) {
  2725. await xoIcjPr.then();
  2726. return;
  2727. }
  2728. xoIcjPr = new PromiseExternal();
  2729. window.postMessage('xoIcj');
  2730. await xoIcjPr.then();
  2731. xoIcjPr = null;
  2732. }
  2733.  
  2734. cleanContext(win).then(__CONTEXT__ => {
  2735. if (!__CONTEXT__) return null;
  2736.  
  2737. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, getComputedStyle, addEventListener, removeEventListener } = __CONTEXT__;
  2738.  
  2739. const wmComputedStyle = new WeakMap();
  2740. const getComputedStyleCached = (elem) => {
  2741. let cs = wmComputedStyle.get(elem);
  2742. if (!cs) {
  2743. cs = getComputedStyle(elem);
  2744. wmComputedStyle.set(elem, cs);
  2745. }
  2746. return cs;
  2747. }
  2748.  
  2749.  
  2750. const isGPUAccelerationAvailable = (() => {
  2751. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  2752. try {
  2753. const canvas = document.createElement('canvas');
  2754. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  2755. } catch (e) {
  2756. return false;
  2757. }
  2758. })();
  2759.  
  2760. const foregroundPromiseFn_noGPU = (() => {
  2761.  
  2762. if (isGPUAccelerationAvailable) return null;
  2763.  
  2764. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  2765. if (!pd || typeof pd.get !== 'function') return null;
  2766. const pdGet = pd.get;
  2767.  
  2768. let pr = null;
  2769.  
  2770. let hState = pdGet.call(document) === 'hidden';
  2771. // let cid = 0;
  2772. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  2773. const newHState = pdGet.call(document) === 'hidden';
  2774. if (hState !== newHState) {
  2775. // if (cid > 0) cid = clearInterval(cid);
  2776. hState = newHState;
  2777. if (!hState && pr) pr = pr.resolve();
  2778. }
  2779. });
  2780.  
  2781. // cid = setInterval(() => {
  2782. // const newHState = document.visibilityState === 'hidden';
  2783. // if (hState !== newHState) {
  2784. // hState = newHState;
  2785. // if (!hState && pr) pr = pr.resolve();
  2786. // }
  2787. // }, 100);
  2788.  
  2789.  
  2790. return (() => {
  2791. if (pr) return pr;
  2792. const w = ((!hState && setTimeout(() => {
  2793. if (!hState && pr === w) pr = pr.resolve();
  2794. })), (pr = new PromiseExternal()));
  2795. return w;
  2796. });
  2797.  
  2798. })();
  2799.  
  2800. // window.foregroundPromiseFn_noGPU = foregroundPromiseFn_noGPU;
  2801.  
  2802. let rafPromise = null;
  2803. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2804. requestAnimationFrame(hRes => {
  2805. rafPromise = null;
  2806. resolve(hRes);
  2807. });
  2808. }));
  2809. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  2810.  
  2811. const iAFP = foregroundPromiseFn_noGPU ? foregroundPromiseFn_noGPU : typeof IntersectionObserver === 'undefined' ? getRafPromise : (() => {
  2812.  
  2813. const ioWM = new WeakMap();
  2814. const ek = Symbol();
  2815. /** @type {IntersectionObserverCallback} */
  2816. const ioCb = (entries, observer) => {
  2817. /** @type {PromiseExternal} */
  2818. const pr = observer[ek];
  2819. const resolve = pr.resolve;
  2820. let target;
  2821. if (resolve && (target = ((entries ? entries[0] : 0) || 0).target) instanceof Element) {
  2822. pr.resolve = null;
  2823. observer.unobserve(target);
  2824. resolve();
  2825. }
  2826. };
  2827. /**
  2828. *
  2829. * @param {Element} elm
  2830. * @returns {Promise<void>}
  2831. */
  2832. const iAFP = (elm) => {
  2833. let io = ioWM.get(elm);
  2834. if (!io) {
  2835. io = new IntersectionObserver(ioCb);
  2836. ioWM.set(elm, io); // strong reference
  2837. }
  2838. let pr = io[ek];
  2839. if (!pr) {
  2840. pr = io[ek] = new PromiseExternal();
  2841. io.observe(elm);
  2842. }
  2843. return pr;
  2844. }
  2845.  
  2846. return iAFP;
  2847.  
  2848. })();
  2849.  
  2850. let playerState = null;
  2851. let _playerState = null;
  2852. let lastPlayerProgress = null;
  2853. let relayCount = 0;
  2854. let playerEventsByIframeRelay = false;
  2855. let isPlayProgressTriggered = false;
  2856. let waitForInitialDataCompletion = 0;
  2857.  
  2858.  
  2859.  
  2860. let aeConstructor = null;
  2861.  
  2862. // << __openedChanged82 >>
  2863. let currentMenuPivotWR = null;
  2864.  
  2865. // << if DO_PARTICIPANT_LIST_HACKS >>
  2866. const beforeParticipantsMap = new WeakMap();
  2867. // << end >>
  2868.  
  2869.  
  2870.  
  2871. // << if onRegistryReadyForDOMOperations >>
  2872.  
  2873. let dt0 = Date.now() - 2000;
  2874. const dateNow = () => Date.now() - dt0;
  2875. // let lastScroll = 0;
  2876. // let lastLShow = 0;
  2877. let lastWheel = 0;
  2878. let lastMouseDown = 0;
  2879. let lastMouseUp = 0;
  2880. let currentMouseDown = false;
  2881. let lastTouchDown = 0;
  2882. let lastTouchUp = 0;
  2883. let currentTouchDown = false;
  2884. let lastUserInteraction = 0;
  2885.  
  2886. let scrollChatFn = null;
  2887.  
  2888. let skipDontRender = true; // true first; false by flushActiveItems_
  2889. let allowDontRender = null;
  2890.  
  2891. // ---- #items mutation ----
  2892. let sk35zResolveFn = null;
  2893. let firstList = true;
  2894.  
  2895. // << end >>
  2896.  
  2897. class RAFHub {
  2898. constructor() {
  2899. /** @type {number} */
  2900. this.startAt = 8170;
  2901. /** @type {number} */
  2902. this.counter = 0;
  2903. /** @type {number} */
  2904. this.rid = 0;
  2905. /** @type {Map<number, FrameRequestCallback>} */
  2906. this.funcs = new Map();
  2907. const funcs = this.funcs;
  2908. /** @type {FrameRequestCallback} */
  2909. this.bCallback = this.mCallback.bind(this);
  2910. this.pClear = () => funcs.clear();
  2911. this.keepRAF = false;
  2912. }
  2913. /** @param {DOMHighResTimeStamp} highResTime */
  2914. mCallback(highResTime) {
  2915. this.rid = 0;
  2916. Promise.resolve().then(this.pClear);
  2917. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2918. }
  2919. /** @param {FrameRequestCallback} f */
  2920. request(f) {
  2921. if (this.counter > 1e9) this.counter = 9;
  2922. let cid = this.startAt + (++this.counter);
  2923. this.funcs.set(cid, f);
  2924. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  2925. return cid;
  2926. }
  2927. /** @param {number} cid */
  2928. cancel(cid) {
  2929. cid = +cid;
  2930. if (cid > 0) {
  2931. if (cid <= this.startAt) {
  2932. return cancelAnimationFrame(cid);
  2933. }
  2934. if (this.rid > 0) {
  2935. this.funcs.delete(cid);
  2936. if (this.funcs.size === 0 && !this.keepRAF) {
  2937. cancelAnimationFrame(this.rid);
  2938. this.rid = 0;
  2939. }
  2940. }
  2941. }
  2942. }
  2943. }
  2944.  
  2945. function basePrefetching() {
  2946.  
  2947. new Promise(resolve => {
  2948.  
  2949. if (document.readyState !== 'loading') {
  2950. resolve();
  2951. } else {
  2952. win.addEventListener("DOMContentLoaded", resolve, false);
  2953. }
  2954.  
  2955. }).then(() => {
  2956. const hostL1 = [
  2957. 'https://www.youtube.com', 'https://googlevideo.com',
  2958. 'https://googleapis.com', 'https://accounts.youtube.com',
  2959. 'https://www.gstatic.com', 'https://ggpht.com',
  2960. 'https://yt3.ggpht.com', 'https://yt4.ggpht.com'
  2961. ];
  2962.  
  2963. const hostL2 = [
  2964. 'https://youtube.com',
  2965. 'https://fonts.googleapis.com', 'https://fonts.gstatic.com'
  2966. ];
  2967.  
  2968. let link = null;
  2969.  
  2970. function kn() {
  2971.  
  2972. link = document.createElement('link');
  2973. if (link.relList && link.relList.supports) {
  2974. 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)
  2975. } else {
  2976. kptPF = 0;
  2977. }
  2978.  
  2979. groupCollapsed("YouTube Super Fast Chat", " | PREFETCH SUPPORTS");
  2980. if (ENABLE_BASE_PREFETCHING) console.log('dns-prefetch', (kptPF & 1) ? 'OK' : 'NG');
  2981. if (ENABLE_BASE_PREFETCHING) console.log('preconnect', (kptPF & 2) ? 'OK' : 'NG');
  2982. if (ENABLE_PRELOAD_THUMBNAIL) console.log('prefetch', (kptPF & 4) ? 'OK' : 'NG');
  2983. // console.log('subresource', (kptPF & 8) ? 'OK' : 'NG');
  2984. if (ENABLE_PRELOAD_THUMBNAIL) console.log('preload', (kptPF & 16) ? 'OK' : 'NG');
  2985. console.groupEnd();
  2986.  
  2987. }
  2988.  
  2989. for (const h of hostL1) {
  2990.  
  2991. if (kptPF === null) kn();
  2992. if (ENABLE_BASE_PREFETCHING) {
  2993. // if (kptPF & 1) {
  2994. // linker(link, 'dns-prefetch', h);
  2995. // link = null;
  2996. // }
  2997. if (kptPF & 2) {
  2998. linker(link, 'preconnect', h);
  2999. link = null;
  3000. }
  3001. }
  3002. }
  3003.  
  3004. for (const h of hostL2) {
  3005. if (kptPF === null) kn();
  3006. if (ENABLE_BASE_PREFETCHING) {
  3007. if (kptPF & 1) {
  3008. linker(link, 'dns-prefetch', h);
  3009. link = null;
  3010. }
  3011. }
  3012. }
  3013.  
  3014. })
  3015.  
  3016.  
  3017. }
  3018.  
  3019. if (DO_LINK_PREFETCH) basePrefetching();
  3020.  
  3021. const { notifyPath7081 } = (() => {
  3022. // DO_PARTICIPANT_LIST_HACKS
  3023.  
  3024. const mutexParticipants = new Mutex();
  3025.  
  3026. let uvid = 0;
  3027. let r95dm = 0;
  3028. let c95dm = -1;
  3029.  
  3030. const foundMap = (base, content) => {
  3031. /*
  3032. let lastSearch = 0;
  3033. let founds = base.map(baseEntry => {
  3034. let search = content.indexOf(baseEntry, lastSearch);
  3035. if (search < 0) return false;
  3036. lastSearch = search + 1;
  3037. return true;
  3038. });
  3039. return founds;
  3040. */
  3041. const contentSet = new Set(content);
  3042. return base.map(baseEntry => contentSet.has(baseEntry));
  3043.  
  3044. }
  3045.  
  3046.  
  3047.  
  3048. let participantsForSpliceWR = null;
  3049.  
  3050. class IndexSpliceEntry {
  3051. /**
  3052. *
  3053. * @param {number} _index
  3054. * @param {number} _addedCount
  3055. * @param {any[]} _removed
  3056. */
  3057. constructor(_index, _addedCount, _removed) {
  3058. this.index = _index;
  3059. this.addedCount = _addedCount;
  3060. this.removed = _removed;
  3061. }
  3062. get __proxy312__() {
  3063. return 1
  3064. }
  3065. get type() {
  3066. return 'splice'
  3067. }
  3068. get object() {
  3069. return kRef(participantsForSpliceWR); // avoid memory leakage
  3070. }
  3071. }
  3072.  
  3073. const spliceIndicesFunc = (beforeParticipants, participants, idsBefore, idsAfter) => {
  3074.  
  3075. let foundsForAfter = foundMap(idsAfter, idsBefore);
  3076. let foundsForBefore = foundMap(idsBefore, idsAfter);
  3077.  
  3078. const nAfter = foundsForAfter.length;
  3079. const nBefore = foundsForBefore.length;
  3080.  
  3081. const indexSplices = [];
  3082. const contentUpdates = [];
  3083. participantsForSpliceWR = null;
  3084. for (let i = 0, j = 0; i < nBefore || j < nAfter;) {
  3085. if (beforeParticipants[i] === participants[j]) {
  3086. i++; j++;
  3087. } else if (idsBefore[i] === idsAfter[j]) {
  3088. // content changed
  3089. contentUpdates.push({ indexI: i, indexJ: j })
  3090. i++; j++;
  3091. } else {
  3092. let addedCount = 0;
  3093. for (let q = j; q < nAfter; q++) {
  3094. if (foundsForAfter[q] === false) addedCount++;
  3095. else break;
  3096. }
  3097. let removedCount = 0;
  3098. for (let q = i; q < nBefore; q++) {
  3099. if (foundsForBefore[q] === false) removedCount++;
  3100. else break;
  3101. }
  3102. if (!addedCount && !removedCount) {
  3103. throw 'ERROR(0xFF32): spliceIndicesFunc';
  3104. }
  3105. const entry = new IndexSpliceEntry(
  3106. j,
  3107. addedCount,
  3108. removedCount >= 1 ? beforeParticipants.slice(i, i + removedCount) : []
  3109. );
  3110. indexSplices.push(entry);
  3111. i += removedCount;
  3112. j += addedCount;
  3113. }
  3114. }
  3115. foundsForBefore = null;
  3116. foundsForAfter = null;
  3117. idsBefore = null;
  3118. idsAfter = null;
  3119. beforeParticipants = null;
  3120. participantsForSpliceWR = indexSplices.length > 0 ? mWeakRef(participants) : null;
  3121. participants = null;
  3122. return { indexSplices, contentUpdates };
  3123.  
  3124. }
  3125.  
  3126. /*
  3127.  
  3128. customElements.get("yt-live-chat-participant-renderer").prototype.notifyPath=function(){ console.log(123); console.log(new Error().stack)}
  3129.  
  3130. VM63631:1 Error
  3131. at customElements.get.notifyPath (<anonymous>:1:122)
  3132. at e.forwardRendererStamperChanges_ (live_chat_polymer.js:4453:35)
  3133. at e.rendererStamperApplyChangeRecord_ (live_chat_polymer.js:4451:12)
  3134. at e.rendererStamperObserver_ (live_chat_polymer.js:4448:149)
  3135. at Object.pu [as fn] (live_chat_polymer.js:1692:118)
  3136. at ju (live_chat_polymer.js:1674:217)
  3137. at a._propertiesChanged (live_chat_polymer.js:1726:122)
  3138. at b._flushProperties (live_chat_polymer.js:1597:200)
  3139. at a._invalidateProperties (live_chat_polymer.js:1718:69)
  3140. at a.notifyPath (live_chat_polymer.js:1741:182)
  3141.  
  3142. */
  3143.  
  3144. function convertToIds(participants) {
  3145. return participants.map(participant => {
  3146. if (!participant || typeof participant !== 'object') {
  3147. console.warn('Error(0xFA41): convertToIds', participant);
  3148. return participant; // just in case
  3149. }
  3150. let keys = Object.keys(participant);
  3151. // liveChatTextMessageRenderer
  3152. // liveChatParticipantRenderer - livestream channel owner [no authorExternalChannelId]
  3153. // liveChatPaidMessageRenderer
  3154. /*
  3155.  
  3156. 'yt-live-chat-participant-renderer' utilizes the following:
  3157. authorName.simpleText: string
  3158. authorPhoto.thumbnails: Object{url:string, width:int, height:int} []
  3159. authorBadges[].liveChatAuthorBadgeRenderer.icon.iconType: string
  3160. authorBadges[].liveChatAuthorBadgeRenderer.tooltip: string
  3161. authorBadges[].liveChatAuthorBadgeRenderer.accessibility.accessibilityData: Object{label:string}
  3162.  
  3163. */
  3164. if (keys.length !== 1) {
  3165. console.warn('Error(0xFA42): convertToIds', participant);
  3166. return participant; // just in case
  3167. }
  3168. let key = keys[0];
  3169. let renderer = (participant[key] || 0);
  3170. let authorName = (renderer.authorName || 0);
  3171. let text = `${authorName.simpleText || authorName.text}`
  3172. let res = participant; // fallback if it is not a vaild entry
  3173. if (typeof text !== 'string') {
  3174. console.warn('Error(0xFA53): convertToIds', participant);
  3175. } else {
  3176. text = `${renderer.authorExternalChannelId || 'null'}|${text || ''}`;
  3177. if (text.length > 1) res = text;
  3178. }
  3179. return res;
  3180. // return renderer?`${renderer.id}|${renderer.authorExternalChannelId}`: '';
  3181. // note: renderer.id will be changed if the user typed something to trigger the update of the participants' record.
  3182. });
  3183. }
  3184.  
  3185. const checkChangeToParticipantRendererContent = CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT ? (p1, p2) => {
  3186. // just update when content is changed.
  3187. if (p1.authorName !== p2.authorName) return true;
  3188. if (p1.authorPhoto !== p2.authorPhoto) return true;
  3189. if (p1.authorBadges !== p2.authorBadges) return true;
  3190. return false;
  3191. } : (p1, p2) => {
  3192. // keep integrity all the time.
  3193. return p1 !== p2; // always true
  3194. }
  3195.  
  3196. function notifyPath7081(path) { // cnt "yt-live-chat-participant-list-renderer"
  3197.  
  3198. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  3199. if (path !== "participantsManager.participants") {
  3200. return this.__notifyPath5036__.apply(this, arguments);
  3201. }
  3202. if (c95dm === r95dm) return;
  3203. } else {
  3204. const stack = new Error().stack;
  3205. if (path !== "participantsManager.participants" || stack.indexOf('.onParticipantsChanged') < 0) {
  3206. return this.__notifyPath5036__.apply(this, arguments);
  3207. }
  3208. }
  3209.  
  3210. if (uvid > 1e8) uvid = uvid % 100;
  3211. let tid = ++uvid;
  3212.  
  3213.  
  3214. // const cnt = this; // "yt-live-chat-participant-list-renderer"
  3215.  
  3216. const wNode = mWeakRef(this);
  3217.  
  3218. mutexParticipants.lockWith(lockResolve => {
  3219.  
  3220. const cnt = kRef(wNode);
  3221.  
  3222. const participants00 = (((cnt || 0).participantsManager || 0).participants || 0);
  3223.  
  3224. if (tid !== uvid || !cnt || typeof (participants00 || 0).splice !== 'function') {
  3225. lockResolve();
  3226. return;
  3227. }
  3228.  
  3229. let doUpdate = false;
  3230.  
  3231. if (PARTICIPANT_UPDATE_ONLY_ONLY_IF_MODIFICATION_DETECTED) {
  3232.  
  3233. if (!participants00.r94dm) {
  3234. participants00.r94dm = 1;
  3235. if (++r95dm > 1e9) r95dm = 9;
  3236. participants00.push = function () {
  3237. if (++r95dm > 1e9) r95dm = 9;
  3238. return Array.prototype.push.apply(this, arguments);
  3239. }
  3240. participants00.pop = function () {
  3241. if (++r95dm > 1e9) r95dm = 9;
  3242. return Array.prototype.pop.apply(this, arguments);
  3243. }
  3244. participants00.shift = function () {
  3245. if (++r95dm > 1e9) r95dm = 9;
  3246. return Array.prototype.shift.apply(this, arguments);
  3247. }
  3248. participants00.unshift = function () {
  3249. if (++r95dm > 1e9) r95dm = 9;
  3250. return Array.prototype.unshift.apply(this, arguments);
  3251. }
  3252. participants00.splice = function () {
  3253. if (++r95dm > 1e9) r95dm = 9;
  3254. return Array.prototype.splice.apply(this, arguments);
  3255. }
  3256. participants00.sort = function () {
  3257. if (++r95dm > 1e9) r95dm = 9;
  3258. return Array.prototype.sort.apply(this, arguments);
  3259. }
  3260. participants00.reverse = function () {
  3261. if (++r95dm > 1e9) r95dm = 9;
  3262. return Array.prototype.reverse.apply(this, arguments);
  3263. }
  3264. }
  3265.  
  3266. if (c95dm !== r95dm) {
  3267. c95dm = r95dm;
  3268. doUpdate = true;
  3269. }
  3270.  
  3271. } else {
  3272. doUpdate = true;
  3273. }
  3274.  
  3275. if (!doUpdate) {
  3276. lockResolve();
  3277. return;
  3278. }
  3279.  
  3280. const participants = participants00.slice(0);
  3281. const beforeParticipants = beforeParticipantsMap.get(cnt) || [];
  3282. beforeParticipantsMap.set(cnt, participants);
  3283.  
  3284. const resPromise = (async () => {
  3285.  
  3286. if (beforeParticipants.length === 0) {
  3287. // not error
  3288. return 0;
  3289. }
  3290.  
  3291. let countOfElements = cnt.__getAllParticipantsDOMRenderedLength__()
  3292.  
  3293. // console.log(participants.length, doms.length) // different if no requestAnimationFrame
  3294. if (beforeParticipants.length !== countOfElements) {
  3295. // there is somewrong for the cache. - sometimes happen
  3296. return 0;
  3297. }
  3298.  
  3299. const idsBefore = convertToIds(beforeParticipants);
  3300. const idsAfter = convertToIds(participants);
  3301.  
  3302. let { indexSplices, contentUpdates } = spliceIndicesFunc(beforeParticipants, participants, idsBefore, idsAfter);
  3303.  
  3304. let res = 1; // default 1 for no update
  3305.  
  3306. if (indexSplices.length >= 1) {
  3307.  
  3308.  
  3309. // let p2 = participants.slice(indexSplices[0].index, indexSplices[0].index+indexSplices[0].addedCount);
  3310. // let p1 = indexSplices[0].removed;
  3311. // console.log(indexSplices.length, indexSplices ,p1,p2, convertToIds(p1),convertToIds(p2))
  3312.  
  3313. /* folllow
  3314. a.notifyPath(c + ".splices", d);
  3315. a.notifyPath(c + ".length", b.length);
  3316. */
  3317. // stampDomArraySplices_
  3318.  
  3319.  
  3320. await new Promise(resolve => {
  3321. cnt.resolveForDOMRendering781 = resolve;
  3322.  
  3323. cnt.__notifyPath5036__("participantsManager.participants.splices", {
  3324. indexSplices
  3325. });
  3326. indexSplices = null;
  3327. participantsForSpliceWR = null;
  3328. cnt.__notifyPath5036__("participantsManager.participants.length",
  3329. participants.length
  3330. );
  3331.  
  3332. });
  3333.  
  3334. // play safe for the change of 'length'
  3335. if (typeof nextBrowserTick !== 'function') {
  3336. await Promise.resolve(0);
  3337. } else {
  3338. await new Promise(resolve => nextBrowserTick(resolve)).then();
  3339. }
  3340.  
  3341. countOfElements = cnt.__getAllParticipantsDOMRenderedLength__();
  3342.  
  3343. const wrongSize = participants.length !== countOfElements
  3344. if (wrongSize) {
  3345. console.warn("ERROR(0xE2C3): notifyPath7081", beforeParticipants.length, participants.length, doms.length)
  3346. return 0;
  3347. }
  3348.  
  3349. res = 2 | 4;
  3350.  
  3351. } else {
  3352.  
  3353. indexSplices = null;
  3354. participantsForSpliceWR = null;
  3355.  
  3356. if (participants.length !== countOfElements) {
  3357. // other unhandled cases
  3358. return 0;
  3359. }
  3360.  
  3361. }
  3362.  
  3363. // participants.length === countOfElements before contentUpdates
  3364. if (contentUpdates.length >= 1) {
  3365. for (const contentUpdate of contentUpdates) {
  3366. let isChanged = checkChangeToParticipantRendererContent(beforeParticipants[contentUpdate.indexI], participants[contentUpdate.indexJ]);
  3367. if (isChanged) {
  3368. cnt.__notifyPath5036__(`participantsManager.participants[${contentUpdate.indexJ}]`);
  3369. res |= 4 | 8;
  3370. }
  3371. }
  3372. }
  3373. contentUpdates = null;
  3374.  
  3375. return res;
  3376.  
  3377.  
  3378. })();
  3379.  
  3380.  
  3381. resPromise.then(resValue => {
  3382.  
  3383. const isLogRequired = SHOW_PARTICIPANT_CHANGES_IN_CONSOLE && ((resValue === 0) || ((resValue & 4) === 4));
  3384. isLogRequired && groupCollapsed("Participant List Change", `tid = ${tid}; res = ${resValue}`);
  3385. if (resValue === 0) {
  3386. new Promise(resolve => {
  3387. cnt.resolveForDOMRendering781 = resolve;
  3388. isLogRequired && console.log("Full Refresh begins");
  3389. cnt.__notifyPath5036__("participantsManager.participants"); // full refresh
  3390. }).then(() => {
  3391. isLogRequired && console.log("Full Refresh ends");
  3392. console.groupEnd();
  3393. }).then(lockResolve);
  3394. return;
  3395. }
  3396.  
  3397. const delayLockResolve = (resValue & 4) === 4;
  3398.  
  3399. if (delayLockResolve) {
  3400. isLogRequired && console.log(`Number of participants (before): ${beforeParticipants.length}`);
  3401. isLogRequired && console.log(`Number of participants (after): ${participants.length}`);
  3402. isLogRequired && console.log(`Total number of rendered participants: ${cnt.__getAllParticipantsDOMRenderedLength__()}`);
  3403. isLogRequired && console.log(`Participant Renderer Content Updated: ${(resValue & 8) === 8}`);
  3404. isLogRequired && console.groupEnd();
  3405. // requestAnimationFrame is required to avoid particiant update during DOM changing (stampDomArraySplices_)
  3406. // mutex lock with requestAnimationFrame can also disable participants update in background
  3407. requestAnimationFrame(lockResolve);
  3408. } else {
  3409. lockResolve();
  3410. }
  3411.  
  3412. });
  3413.  
  3414. });
  3415.  
  3416. }
  3417.  
  3418. return { notifyPath7081 };
  3419.  
  3420. })();
  3421.  
  3422. const whenDefinedMultiple = async (tags) => {
  3423.  
  3424. const sTags = [...new Set(tags)];
  3425. const len = sTags.length;
  3426.  
  3427. const pTags = new Array(len);
  3428. for (let i = 0; i < len; i++) {
  3429. pTags[i] = customElements.whenDefined(sTags[i]);
  3430. }
  3431.  
  3432. await Promise.all(pTags);
  3433. pTags.length = 0;
  3434.  
  3435. return sTags;
  3436.  
  3437. }
  3438.  
  3439. const onRegistryReadyForDataManipulation = () => {
  3440.  
  3441. function dummy5035(a, b, c) { }
  3442. function dummy411(a, b, c) { }
  3443.  
  3444.  
  3445.  
  3446. customElements.whenDefined("yt-live-chat-participant-list-renderer").then(() => {
  3447.  
  3448. if (!DO_PARTICIPANT_LIST_HACKS) return;
  3449.  
  3450. const tag = "yt-live-chat-participant-list-renderer";
  3451. const cProto = getProto(document.createElement(tag));
  3452. if (!cProto || typeof cProto.attached !== 'function') {
  3453. // for _registered, proto.attached shall exist when the element is defined.
  3454. // for controller extraction, attached shall exist when instance creates.
  3455. console.warn(`proto.attached for ${tag} is unavailable.`);
  3456. return;
  3457. }
  3458.  
  3459.  
  3460. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-participant-list-renderer hacks");
  3461.  
  3462. 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'];
  3463. const fgs = {};
  3464. for (const key of fgsArr) fgs[key] = undefined;
  3465.  
  3466. try {
  3467. const EXPERIMENT_FLAGS = ytcfg.data_.EXPERIMENT_FLAGS;
  3468. for (const key of fgsArr) fgs[key] = EXPERIMENT_FLAGS[key];
  3469. } catch (e) { }
  3470. console.log(`EXPERIMENT_FLAGS: ${JSON.stringify(fgs, null, 2)}`);
  3471.  
  3472. const canDoReplacement = (() => {
  3473. if (typeof cProto.__notifyPath5035__ === 'function' && cProto.__notifyPath5035__.name !== 'dummy5035') {
  3474. console.warn('YouTube Live Chat Tamer is running.');
  3475. return;
  3476. }
  3477.  
  3478. if (typeof cProto.__attached411__ === 'function' && cProto.__attached411__.name !== 'dummy411') {
  3479. console.warn('YouTube Live Chat Tamer is running.');
  3480. return;
  3481. }
  3482.  
  3483. cProto.__notifyPath5035__ = dummy5035 // just to against Live Chat Tamer
  3484. cProto.__attached411__ = dummy411 // just to against Live Chat Tamer
  3485.  
  3486. if (typeof cProto.flushRenderStamperComponentBindings_ !== 'function' || cProto.flushRenderStamperComponentBindings_.length !== 0) {
  3487. console.warn("ERROR(0xE355): cProto.flushRenderStamperComponentBindings_ not found");
  3488. return;
  3489. }
  3490.  
  3491. if (typeof cProto.flushRenderStamperComponentBindings66_ === 'function') {
  3492. console.warn("ERROR(0xE356): cProto.flushRenderStamperComponentBindings66_");
  3493. return;
  3494. }
  3495.  
  3496. if (typeof cProto.__getAllParticipantsDOMRenderedLength__ === 'function') {
  3497. console.warn("ERROR(0xE357): cProto.__getAllParticipantsDOMRenderedLength__");
  3498. return;
  3499. }
  3500. return true;
  3501. })();
  3502.  
  3503. console.log(`Data Manipulation Boost = ${canDoReplacement}`);
  3504.  
  3505. assertor(() => fnIntegrity(cProto.attached, '0.32.22')) // just warning
  3506. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3507. const fiRSCB = fnIntegrity(cProto.flushRenderStamperComponentBindings_);
  3508. // const s = fiRSCB.split('.');
  3509. // Feb 2024: 0.403.247 => NG
  3510. // if (s[0] === '0' && +s[1] > 381 && +s[1] < 391 && +s[2] > 228 && +s[2] < 238) {
  3511. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - OK`);
  3512. // } else {
  3513. // console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ### - NG`);
  3514. // }
  3515. console.log(`flushRenderStamperComponentBindings_ ### ${fiRSCB} ###`);
  3516. } else {
  3517. console.log("flushRenderStamperComponentBindings_ - not found");
  3518. }
  3519. // assertor(() => fnIntegrity(cProto.flushRenderStamperComponentBindings_, '0.386.233')) // just warning
  3520.  
  3521. if (typeof cProto.flushRenderStamperComponentBindings_ === 'function') {
  3522. cProto.flushRenderStamperComponentBindings66_ = cProto.flushRenderStamperComponentBindings_;
  3523. cProto.flushRenderStamperComponentBindings_ = function () {
  3524. // console.log('flushRenderStamperComponentBindings_')
  3525. this.flushRenderStamperComponentBindings66_();
  3526. if (this.resolveForDOMRendering781) {
  3527. this.resolveForDOMRendering781();
  3528. this.resolveForDOMRendering781 = null;
  3529. }
  3530. };
  3531. }
  3532.  
  3533. cProto.__getAllParticipantsDOMRenderedLength__ = function () {
  3534. const container = ((this || 0).$ || 0).participants;
  3535. if (!container) return 0;
  3536. return HTMLElement.prototype.querySelectorAll.call(container, 'yt-live-chat-participant-renderer').length;
  3537. }
  3538.  
  3539. const onPageElements = [...document.querySelectorAll('yt-live-chat-participant-list-renderer:not(.n9fJ3)')];
  3540.  
  3541. cProto.__attached412__ = cProto.attached;
  3542. const fpPList = function (hostElement) {
  3543. const cnt = insp(hostElement);
  3544. if (beforeParticipantsMap.has(cnt)) return;
  3545. hostElement.classList.add('n9fJ3');
  3546.  
  3547. assertor(() => (cnt.__dataEnabled === true && cnt.__dataReady === true));
  3548. if (typeof cnt.notifyPath !== 'function' || typeof cnt.__notifyPath5036__ !== 'undefined') {
  3549. console.warn("ERROR(0xE318): yt-live-chat-participant-list-renderer")
  3550. return;
  3551. }
  3552.  
  3553. groupCollapsed("Participant List attached", "");
  3554. // cnt.$.participants.appendChild = cnt.$.participants.__shady_native_appendChild = function(){
  3555. // console.log(123, 'appendChild');
  3556. // return HTMLElement.prototype.appendChild.apply(this, arguments)
  3557. // }
  3558.  
  3559. // cnt.$.participants.insertBefore =cnt.$.participants.__shady_native_insertBefore = function(){
  3560. // console.log(123, 'insertBefore');
  3561. // return HTMLElement.prototype.insertBefore.apply(this, arguments)
  3562. // }
  3563.  
  3564. cnt.__notifyPath5036__ = cnt.notifyPath
  3565. const participants = ((cnt.participantsManager || 0).participants || 0);
  3566. assertor(() => (participants.length > -1 && typeof participants.slice === 'function'));
  3567. console.log(`initial number of participants: ${participants.length}`);
  3568. const newParticipants = (participants.length >= 1 && typeof participants.slice === 'function') ? participants.slice(0) : [];
  3569. beforeParticipantsMap.set(cnt, newParticipants);
  3570. cnt.notifyPath = notifyPath7081;
  3571. console.log(`CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT = ${CHECK_CHANGE_TO_PARTICIPANT_RENDERER_CONTENT}`);
  3572. console.groupEnd();
  3573. }
  3574. cProto.attached = function () {
  3575. fpPList(this.hostElement || this);
  3576. this.__attached412__.apply(this, arguments);
  3577. };
  3578.  
  3579.  
  3580. if (ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST) {
  3581.  
  3582. /** @type {boolean | (()=>boolean)} */
  3583. let toUseMaintainStableList = USE_MAINTAIN_STABLE_LIST_ONLY_WHEN_KS_FLAG_IS_SET ? (() => ytcfg.data_.EXPERIMENT_FLAGS.kevlar_should_maintain_stable_list === true) : true;
  3584. if (typeof cProto.stampDomArray_ === 'function' && cProto.stampDomArray_.length === 6 && !cProto.stampDomArray_.nIegT && !cProto.stampDomArray66_) {
  3585.  
  3586. let lastMessageDate = 0;
  3587. cProto.stampDomArray66_ = cProto.stampDomArray_;
  3588.  
  3589. cProto.stampDomArray_ = function (...args) {
  3590. if (args[0] && args[0].length > 0 && args[1] === "participants" && args[2] && args[3] === true && !args[5]) {
  3591. if (typeof toUseMaintainStableList === 'function') {
  3592. toUseMaintainStableList = toUseMaintainStableList();
  3593. }
  3594. args[5] = toUseMaintainStableList;
  3595. let currentDate = Date.now();
  3596. if (currentDate - lastMessageDate > 440) {
  3597. lastMessageDate = currentDate;
  3598. console.log('maintain_stable_list for participants list', toUseMaintainStableList);
  3599. }
  3600. }
  3601. return this.stampDomArray66_.apply(this, args);
  3602. }
  3603.  
  3604. cProto.stampDomArray_.nIegT = 1;
  3605.  
  3606. }
  3607. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - YES`);
  3608. } else {
  3609. console.log(`ENABLE_FLAGS_MAINTAIN_STABLE_LIST_FOR_PARTICIPANTS_LIST - NO`);
  3610. }
  3611.  
  3612. console.groupEnd();
  3613.  
  3614. if (onPageElements.length >= 1) {
  3615. for (const s of onPageElements) {
  3616. if (insp(s).isAttached === true) {
  3617. fpPList(s);
  3618. }
  3619. }
  3620. }
  3621.  
  3622. }).catch(console.warn);
  3623.  
  3624. };
  3625.  
  3626. if (DO_PARTICIPANT_LIST_HACKS) {
  3627. promiseForCustomYtElementsReady.then(onRegistryReadyForDataManipulation);
  3628. }
  3629.  
  3630.  
  3631.  
  3632. const rafHub = (ENABLE_RAF_HACK_TICKERS || ENABLE_RAF_HACK_DOCKED_MESSAGE || ENABLE_RAF_HACK_INPUT_RENDERER || ENABLE_RAF_HACK_EMOJI_PICKER) ? new RAFHub() : null;
  3633.  
  3634. const transitionEndHooks = new WeakSet();
  3635. const transitionEndAfterFnSimple = new WeakMap();
  3636. let transitionEndAfterFnSimpleEnable = 0;
  3637. // let prevTransitionClosing = null;
  3638.  
  3639. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  3640.  
  3641.  
  3642. const transitionEndAfterFn = (evt) => {
  3643. if (transitionEndAfterFnSimpleEnable > 0 && evt.propertyName && !evt.pseudoElement) {
  3644. const elm = evt.target;
  3645. const f = transitionEndAfterFnSimple.get(elm);
  3646. if (f) {
  3647. transitionEndAfterFnSimple.delete(elm);
  3648. f.resolve(evt.propertyName);
  3649. }
  3650. }
  3651. };
  3652.  
  3653. const fixChildrenIssue = !!fixChildrenIssue801;
  3654. if (fixChildrenIssue && typeof Object.getOwnPropertyDescriptor === 'function' && typeof Proxy !== 'undefined') {
  3655. const divProto = HTMLDivElement.prototype;
  3656. const polymerControllerSetData3 = function (c, d, e) {
  3657. return insp(this).set(c, d, e);
  3658. }
  3659. const polymerControllerSetData2 = function (c, d) {
  3660. return insp(this).set(c, d);
  3661. }
  3662. const dummyFn = function () {
  3663. console.log('dummyFn', ...arguments);
  3664. };
  3665.  
  3666. const wm44 = new Map();
  3667. function unPolymerSet(elem) {
  3668. const is = elem.is;
  3669. if (is && !elem.set) {
  3670. let rt = wm44.get(is);
  3671. if (!rt) {
  3672. rt = 1;
  3673. const cnt = insp(elem);
  3674. if (cnt !== elem && cnt && typeof cnt.set === 'function') {
  3675. const pcSet = cnt.constructor.prototype.set;
  3676. if (pcSet && typeof pcSet === 'function' && pcSet.length === 3) {
  3677. rt = polymerControllerSetData3;
  3678. } else if (pcSet && typeof pcSet === 'function' && pcSet.length === 2) {
  3679. rt = polymerControllerSetData2;
  3680. }
  3681. }
  3682. wm44.set(is, rt);
  3683. }
  3684. if (typeof rt === 'function') {
  3685. elem.set = rt;
  3686. } else {
  3687. elem.set = dummyFn;
  3688. }
  3689. }
  3690. }
  3691. if (!divProto.__children577__ && !divProto.__children578__) {
  3692.  
  3693. const dp = Object.getOwnPropertyDescriptor(Element.prototype, 'children');
  3694. const dp2 = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'children');
  3695. const dp3 = Object.getOwnPropertyDescriptor(divProto, 'children');
  3696.  
  3697. if (dp && dp.configurable === true && dp.enumerable === true && typeof dp.get === 'function' && !dp2 && !dp3) {
  3698.  
  3699. if (divProto instanceof HTMLElement && divProto instanceof Element) {
  3700.  
  3701. let m = Object.assign({}, dp);
  3702. divProto.__children577__ = dp.get;
  3703. divProto.__children578__ = function () {
  3704. if (this.__children803__) return this.__children803__;
  3705. if (this.__children801__) {
  3706. let arr = [];
  3707. for (let elem = this.firstElementChild; elem !== null; elem = elem.nextElementSibling) {
  3708. if (elem.is) {
  3709. unPolymerSet(elem);
  3710. arr.push(elem);
  3711. }
  3712. }
  3713. if (this.__children801__ === 2) this.__children803__ = arr;
  3714. return arr;
  3715. }
  3716. return 577;
  3717. };
  3718. m.get = function () {
  3719. const r = this.__children578__();
  3720. if (r !== 577) return r;
  3721. return this.__children577__();
  3722. };
  3723. Object.defineProperty(divProto, 'children', m);
  3724.  
  3725. console.log('fixChildrenIssue - set OK')
  3726.  
  3727. }
  3728. }
  3729.  
  3730. }
  3731.  
  3732.  
  3733. }
  3734.  
  3735.  
  3736. // const bnForDelayChatOccurrence = () => {
  3737.  
  3738. // document.addEventListener('animationstart', (evt) => {
  3739.  
  3740. // if (evt.animationName === 'dontRenderAnimation') {
  3741. // evt.target.classList.remove('dont-render');
  3742. // if (scrollChatFn) scrollChatFn();
  3743. // }
  3744.  
  3745. // }, true);
  3746.  
  3747. // const f = (elm) => {
  3748. // if (elm && elm.nodeType === 1) {
  3749. // if (!skipDontRender && allowDontRender === true) {
  3750. // // innerTextFixFn();
  3751. // elm.classList.add('dont-render');
  3752. // }
  3753. // }
  3754. // }
  3755.  
  3756. // Node.prototype.__appendChild931__ = function (a) {
  3757. // a = dr(a);
  3758. // if (this.id === 'items' && this.classList.contains('yt-live-chat-item-list-renderer')) {
  3759. // if (a && a.nodeType === 1) f(a);
  3760. // else if (a instanceof DocumentFragment) {
  3761. // for (let n = a.firstChild; n; n = n.nextSibling) {
  3762. // f(n);
  3763. // }
  3764. // }
  3765. // }
  3766. // }
  3767.  
  3768. // Node.prototype.__appendChild932__ = function () {
  3769. // this.__appendChild931__.apply(this, arguments);
  3770. // return Node.prototype.appendChild.apply(this, arguments);
  3771. // }
  3772.  
  3773.  
  3774. // };
  3775.  
  3776. const watchUserCSS = () => {
  3777.  
  3778. // if (!CSS.supports('contain-intrinsic-size', 'auto var(--wsr94)')) return;
  3779.  
  3780. const getElemFromWR = (nr) => {
  3781. const n = kRef(nr);
  3782. if (n && n.isConnected) return n;
  3783. return null;
  3784. }
  3785.  
  3786. const clearContentVisibilitySizing = () => {
  3787. Promise.resolve().then(() => {
  3788.  
  3789. const e = document.querySelector('#show-more[disabled]');
  3790. let btnShowMoreWR = e ? mWeakRef(e) : null;
  3791.  
  3792. let lastVisibleItemWR = null;
  3793. for (const elm of document.querySelectorAll('[wSr93]')) {
  3794. if (elm.getAttribute('wSr93') === 'visible') lastVisibleItemWR = mWeakRef(elm);
  3795. elm.setAttribute('wSr93', '');
  3796. // custom CSS property --wsr94 not working when attribute wSr93 removed
  3797. }
  3798. foregroundPromiseFn().then(() => {
  3799. const btnShowMore = getElemFromWR(btnShowMoreWR); btnShowMoreWR = null;
  3800. if (btnShowMore) btnShowMore.click();
  3801. else {
  3802. // would not work if switch it frequently
  3803. const lastVisibleItem = getElemFromWR(lastVisibleItemWR); lastVisibleItemWR = null;
  3804. if (lastVisibleItem) {
  3805.  
  3806. Promise.resolve()
  3807. .then(() => lastVisibleItem.scrollIntoView())
  3808. .then(() => lastVisibleItem.scrollIntoView(false))
  3809. .then(() => lastVisibleItem.scrollIntoView({ behavior: "instant", block: "end", inline: "nearest" }))
  3810. .catch(e => { }) // break the chain when method not callable
  3811.  
  3812. }
  3813. }
  3814. });
  3815.  
  3816. });
  3817.  
  3818. }
  3819.  
  3820. const mutObserver = new MutationObserver((mutations) => {
  3821. for (const mutation of mutations) {
  3822. if ((mutation.addedNodes || 0).length >= 1) {
  3823. for (const addedNode of mutation.addedNodes) {
  3824. if (addedNode.nodeName === 'STYLE') {
  3825. clearContentVisibilitySizing();
  3826. return;
  3827. }
  3828. }
  3829. }
  3830. if ((mutation.removedNodes || 0).length >= 1) {
  3831. for (const removedNode of mutation.removedNodes) {
  3832. if (removedNode.nodeName === 'STYLE') {
  3833. clearContentVisibilitySizing();
  3834. return;
  3835. }
  3836. }
  3837. }
  3838. }
  3839. });
  3840.  
  3841. mutObserver.observe(document.documentElement, {
  3842. childList: true,
  3843. subtree: false
  3844. });
  3845. mutObserver.observe(document.head, {
  3846. childList: true,
  3847. subtree: false
  3848. });
  3849. mutObserver.observe(document.body, {
  3850. childList: true,
  3851. subtree: false
  3852. });
  3853.  
  3854. }
  3855.  
  3856.  
  3857. // class WillChangeController {
  3858. // constructor(itemScroller, willChangeValue) {
  3859. // this.element = itemScroller;
  3860. // this.counter = 0;
  3861. // this.active = false;
  3862. // this.willChangeValue = willChangeValue;
  3863. // }
  3864.  
  3865. // beforeOper() {
  3866. // if (!this.active) {
  3867. // this.active = true;
  3868. // this.element.style.willChange = this.willChangeValue;
  3869. // }
  3870. // this.counter++;
  3871. // }
  3872.  
  3873. // afterOper() {
  3874. // const c = this.counter;
  3875. // foregroundPromiseFn().then(() => {
  3876. // if (c === this.counter) {
  3877. // this.active = false;
  3878. // this.element.style.willChange = '';
  3879. // }
  3880. // });
  3881. // }
  3882.  
  3883. // release() {
  3884. // const element = this.element;
  3885. // this.element = null;
  3886. // this.counter = 1e16;
  3887. // this.active = false;
  3888. // try {
  3889. // element.style.willChange = '';
  3890. // } catch (e) { }
  3891. // }
  3892.  
  3893. // }
  3894.  
  3895.  
  3896. // const skzData = (skz) => skz.data = {
  3897. // "message": {
  3898. // "runs": [
  3899. // {
  3900. // "text": "em2o"
  3901. // },
  3902. // {
  3903. // "emoji": {
  3904. // "emojiId": "cm35z",
  3905. // "shortcuts": [
  3906. // ":_s:",
  3907. // ":s:"
  3908. // ],
  3909. // "searchTerms": [
  3910. // "_s",
  3911. // "s"
  3912. // ],
  3913. // "image": {
  3914. // "thumbnails": [
  3915. // {
  3916. // "url": dummyImgURL,
  3917. // "width": 48,
  3918. // "height": 48
  3919. // }
  3920. // ],
  3921. // "accessibility": {
  3922. // "accessibilityData": {
  3923. // "label": "s"
  3924. // }
  3925. // }
  3926. // },
  3927. // "isCustomEmoji": true
  3928. // }
  3929. // },
  3930. // {
  3931. // "text": "ji"
  3932. // }
  3933. // ]
  3934. // },
  3935. // "authorName": {
  3936. // "simpleText": "N"
  3937. // },
  3938. // "authorPhoto": {
  3939. // "thumbnails": [
  3940. // {
  3941. // "url": dummyImgURL,
  3942. // "width": 64,
  3943. // "height": 64
  3944. // }
  3945. // ]
  3946. // },
  3947. // "contextMenuEndpoint": {
  3948. // "commandMetadata": {
  3949. // "webCommandMetadata": {
  3950. // "ignoreNavigation": true
  3951. // }
  3952. // },
  3953. // "liveChatItemContextMenuEndpoint": {
  3954. // "params": "123=="
  3955. // }
  3956. // },
  3957. // "id": "sk35z",
  3958. // "timestampUsec": "1232302352350000",
  3959. // "authorBadges": [
  3960. // {
  3961. // "liveChatAuthorBadgeRenderer": {
  3962. // "customThumbnail": {
  3963. // "thumbnails": [
  3964. // {
  3965. // "url": dummyImgURL,
  3966. // "width": 16,
  3967. // "height": 16
  3968. // },
  3969. // {
  3970. // "url": dummyImgURL,
  3971. // "width": 32,
  3972. // "height": 32
  3973. // }
  3974. // ]
  3975. // },
  3976. // "tooltip": "T",
  3977. // "accessibility": {
  3978. // "accessibilityData": {
  3979. // "label": "E"
  3980. // }
  3981. // }
  3982. // }
  3983. // }
  3984. // ],
  3985. // "authorExternalChannelId": "A",
  3986. // "contextMenuAccessibility": {
  3987. // "accessibilityData": {
  3988. // "label": "E"
  3989. // }
  3990. // },
  3991. // "timestampText": {
  3992. // "simpleText": "0:43"
  3993. // }
  3994. // };
  3995.  
  3996.  
  3997.  
  3998. const { lcRendererElm, visObserver } = (() => {
  3999.  
  4000.  
  4001.  
  4002. let lcRendererWR = null;
  4003.  
  4004. const lcRendererElm = () => {
  4005. let lcRenderer = kRef(lcRendererWR);
  4006. if (!lcRenderer || !lcRenderer.isConnected) {
  4007. lcRenderer = document.querySelector('yt-live-chat-item-list-renderer.yt-live-chat-renderer');
  4008. lcRendererWR = lcRenderer ? mWeakRef(lcRenderer) : null;
  4009. }
  4010. return lcRenderer;
  4011. };
  4012.  
  4013.  
  4014. let hasFirstShowMore = false;
  4015.  
  4016. const visObserverFn = (entry) => {
  4017.  
  4018. const target = entry.target;
  4019. if (!target) return;
  4020. // if(target.classList.contains('dont-render')) return;
  4021. let isVisible = entry.isIntersecting === true && entry.intersectionRatio > 0.5;
  4022. // const h = entry.boundingClientRect.height;
  4023. /*
  4024. if (h < 16) { // wrong: 8 (padding/margin); standard: 32; test: 16 or 20
  4025. // e.g. under fullscreen. the element created but not rendered.
  4026. target.setAttribute('wSr93', '');
  4027. return;
  4028. }
  4029. */
  4030. if (isVisible) {
  4031. // target.style.setProperty('--wsr94', h + 'px');
  4032. target.setAttribute('wSr93', 'visible');
  4033. if (nNextElem(target) === null) {
  4034.  
  4035. // firstVisibleItemDetected = true;
  4036. /*
  4037. if (dateNow() - lastScroll < 80) {
  4038. lastLShow = 0;
  4039. lastScroll = 0;
  4040. Promise.resolve().then(clickShowMore);
  4041. } else {
  4042. lastLShow = dateNow();
  4043. }
  4044. */
  4045. // lastLShow = dateNow();
  4046. } else if (!hasFirstShowMore) { // should more than one item being visible
  4047. // implement inside visObserver to ensure there is sufficient delay
  4048. hasFirstShowMore = true;
  4049. foregroundPromiseFn().then(() => {
  4050. // foreground page
  4051. // page visibly ready -> load the latest comments at initial loading
  4052. const lcRenderer = lcRendererElm();
  4053. if (lcRenderer) {
  4054. if (typeof nextBrowserTick !== 'function') {
  4055. insp(lcRenderer).scrollToBottom_();
  4056. } else {
  4057. nextBrowserTick(() => {
  4058. const cnt = insp(lcRenderer);
  4059. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  4060. cnt.scrollToBottom_();
  4061. });
  4062. }
  4063. }
  4064. });
  4065. }
  4066. }
  4067. else if (target.getAttribute('wSr93') === 'visible') { // ignore target.getAttribute('wSr93') === '' to avoid wrong sizing
  4068.  
  4069. // target.style.setProperty('--wsr94', h + 'px');
  4070. target.setAttribute('wSr93', 'hidden');
  4071. } // note: might consider 0 < entry.intersectionRatio < 0.5 and target.getAttribute('wSr93') === '' <new last item>
  4072.  
  4073. }
  4074.  
  4075.  
  4076.  
  4077. const visObserver = new IntersectionObserver((entries) => {
  4078.  
  4079. for (const entry of entries) {
  4080.  
  4081. Promise.resolve(entry).then(visObserverFn);
  4082.  
  4083. }
  4084.  
  4085. }, {
  4086. // root: HTMLElement.prototype.closest.call(m2, '#item-scroller.yt-live-chat-item-list-renderer'), // nullable
  4087. rootMargin: "0px",
  4088. threshold: [0.05, 0.95],
  4089. });
  4090.  
  4091.  
  4092. return { lcRendererElm, visObserver }
  4093.  
  4094.  
  4095. })();
  4096.  
  4097. const { setupMutObserver } = (() => {
  4098.  
  4099.  
  4100. const mutFn = (items) => {
  4101. let seqIndex = -1;
  4102. const elementSet = new Set();
  4103. for (let node = nLastElem(items); node !== null; node = nPrevElem(node)) {
  4104. if (node.hasAttribute('wSr93')) {
  4105. seqIndex = parseInt(node.getAttribute('yt-chat-item-seq'), 10);
  4106. break;
  4107. }
  4108. node.setAttribute('wSr93', '');
  4109. visObserver.observe(node);
  4110. elementSet.add(node);
  4111. }
  4112. let iter = elementSet.values();
  4113. let i = seqIndex + elementSet.size;
  4114. for (let curr; curr = iter.next().value;) {
  4115. curr.setAttribute('yt-chat-item-seq', i % 60);
  4116. curr.classList.add('yt-chat-item-' + ((i % 2) ? 'odd' : 'even'));
  4117. i--;
  4118. }
  4119. iter = null;
  4120. elementSet.clear();
  4121. }
  4122.  
  4123. const mutObserver = new MutationObserver((mutations) => {
  4124. const items = (mutations[0] || 0).target;
  4125. if (!items) return;
  4126. if (sk35zResolveFn) {
  4127. sk35zResolveFn();
  4128. sk35zResolveFn = null;
  4129. }
  4130. mutFn(items);
  4131. });
  4132.  
  4133. const setupMutObserver = (m2) => {
  4134. scrollChatFn = null;
  4135. mutObserver.disconnect();
  4136. mutObserver.takeRecords();
  4137. if (m2) {
  4138. if (typeof m2.__appendChild932__ === 'function') {
  4139. if (typeof m2.appendChild === 'function') m2.appendChild = m2.__appendChild932__;
  4140. if (typeof m2.__shady_native_appendChild === 'function') m2.__shady_native_appendChild = m2.__appendChild932__;
  4141. }
  4142. mutObserver.observe(m2, {
  4143. childList: true,
  4144. subtree: false
  4145. });
  4146. mutFn(m2);
  4147.  
  4148. const isFirstList = firstList;
  4149. firstList = false;
  4150.  
  4151. if (ENABLE_OVERFLOW_ANCHOR) {
  4152.  
  4153. let items = m2;
  4154. let addedAnchor = false;
  4155. if (items) {
  4156. if (items.nextElementSibling === null) {
  4157. items.classList.add('no-anchor');
  4158. addedAnchor = true;
  4159. items.parentNode.appendChild(dr(document.createElement('item-anchor')));
  4160. }
  4161. }
  4162.  
  4163.  
  4164.  
  4165. if (addedAnchor) {
  4166. nodeParent(m2).classList.add('no-anchor'); // required
  4167. }
  4168.  
  4169. }
  4170.  
  4171.  
  4172.  
  4173. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  4174.  
  4175. (() => {
  4176.  
  4177. const tag = 'yt-iframed-player-events-relay'
  4178. const dummy = document.createElement(tag);
  4179.  
  4180. const cProto = getProto(dummy);
  4181. if (!cProto || !cProto.handlePostMessage_) {
  4182. console.warn(`proto.handlePostMessage_ for ${tag} is unavailable.`);
  4183. return;
  4184. }
  4185.  
  4186. if (typeof cProto.handlePostMessage_ === 'function' && !cProto.handlePostMessage66_ && !cProto.handlePostMessage67_ ) {
  4187.  
  4188. cProto.handlePostMessage66_ = cProto.handlePostMessage_;
  4189.  
  4190. const handlePostMessageAfterPromiseA = (da) => {
  4191.  
  4192. if (!da || typeof da !== 'object') return;
  4193.  
  4194. if ('yt-player-state-change' in da) {
  4195.  
  4196. const qc = da['yt-player-state-change'];
  4197.  
  4198.  
  4199. let isQcChanged = false;
  4200.  
  4201. if (qc === 2) { isQcChanged = qc !== _playerState; _playerState = 2; relayCount = 0; } // paused
  4202. else if (qc === 3) { isQcChanged = qc !== _playerState; _playerState = 3; } // playing
  4203. else if (qc === 1) { isQcChanged = qc !== _playerState; _playerState = 1; } // playing
  4204.  
  4205.  
  4206. if ((isQcChanged) && playerState !== _playerState) {
  4207. playerEventsByIframeRelay = true;
  4208. onPlayStateChangePromise = new Promise((resolve) => {
  4209. const k = _playerState;
  4210. foregroundPromiseFn().then(() => {
  4211. if (k === _playerState && playerState !== _playerState) playerState = _playerState;
  4212. onPlayStateChangePromise = null;
  4213. resolve();
  4214. })
  4215. }).catch(console.warn);
  4216.  
  4217. }
  4218.  
  4219. } else if ('yt-player-video-progress' in da) {
  4220. const vp = da['yt-player-video-progress'];
  4221.  
  4222.  
  4223. relayCount++;
  4224. lastPlayerProgress = vp > 0 ? vp : 0;
  4225.  
  4226.  
  4227. if (relayPromise && vp > 0 && relayCount >= 2) {
  4228. if (onPlayStateChangePromise) {
  4229. onPlayStateChangePromise.then(() => {
  4230. relayPromise && relayPromise.resolve();
  4231. relayPromise = null;
  4232. })
  4233. } else {
  4234. relayPromise.resolve();
  4235. relayPromise = null;
  4236. }
  4237. }
  4238.  
  4239. }
  4240.  
  4241. };
  4242.  
  4243. cProto.handlePostMessage67_ = function (a) {
  4244.  
  4245. let da = a.data;
  4246. const wNode = mWeakRef(this);
  4247. // const wData = mWeakRef(da);
  4248.  
  4249. playEventsStack = playEventsStack.then(() => {
  4250.  
  4251. const cnt = kRef(wNode);
  4252. // const da = kRef(wData);
  4253.  
  4254. if (!cnt || !a || !da) return;
  4255. handlePostMessageAfterPromiseA(da);
  4256. da = null;
  4257.  
  4258. const r = cnt.handlePostMessage66_(a);
  4259. a = null;
  4260.  
  4261. }).catch(console.warn);
  4262.  
  4263. }
  4264.  
  4265. const handlePostMessageAfterPromiseB = (da) => {
  4266.  
  4267. const lcr = document.querySelector('yt-live-chat-renderer');
  4268. const psc = document.querySelector("yt-player-seek-continuation");
  4269. if (lcr && psc && lcr.replayBuffer_) {
  4270.  
  4271. const rbProgress = lcr.replayBuffer_.lastVideoOffsetTimeMsec;
  4272. const daProgress = da['yt-player-video-progress'] * 1000
  4273. // document.querySelector('yt-live-chat-renderer').playerProgressChanged_(1e-5);
  4274.  
  4275. const front_ = (lcr.replayBuffer_.replayQueue || 0).front_;
  4276. const back_ = (lcr.replayBuffer_.replayQueue || 0).back_;
  4277.  
  4278. // console.log(deepCopy( front_))
  4279. // console.log(deepCopy( back_))
  4280. // console.log(rbProgress, daProgress, )
  4281. if (front_ && back_ && rbProgress > daProgress && back_.length > 2 && back_.some(e => e && +e.videoOffsetTimeMsec > daProgress) && back_.some(e => e && +e.videoOffsetTimeMsec < daProgress)) {
  4282. // no action
  4283. // console.log('ss1')
  4284. } else if (rbProgress < daProgress + 3400 && rbProgress > daProgress - 1200) {
  4285. // daProgress - 1200 < rbProgress < daProgress + 3400
  4286. // console.log('ss2')
  4287. } else {
  4288.  
  4289. lcr.previousProgressSec = 1E-5;
  4290. // lcr._setIsSeeking(!0),
  4291. lcr.replayBuffer_.clear()
  4292. psc.fireSeekContinuation_(da['yt-player-video-progress']);
  4293. }
  4294.  
  4295. }
  4296.  
  4297.  
  4298. };
  4299.  
  4300. cProto.handlePostMessage_ = function (a) {
  4301.  
  4302. let da = (a || 0).data || 0;
  4303. const wNode = mWeakRef(this);
  4304.  
  4305. if (typeof da !== 'object') return;
  4306.  
  4307. if (waitForInitialDataCompletion === 1) return;
  4308.  
  4309. if (!isPlayProgressTriggered) {
  4310. isPlayProgressTriggered = true; // set once
  4311.  
  4312. if ('yt-player-video-progress' in da) {
  4313. waitForInitialDataCompletion = 1;
  4314.  
  4315. const wrapWith = (data) => {
  4316. const { origin } = a;
  4317. return {
  4318. origin,
  4319. data
  4320. };
  4321. }
  4322.  
  4323. this.handlePostMessage67_(wrapWith({
  4324. "yt-iframed-parent-ready": true
  4325. }));
  4326.  
  4327.  
  4328. playEventsStack = playEventsStack.then(() => {
  4329.  
  4330. const cnt = kRef(wNode);
  4331.  
  4332. if (!cnt || !a || !da) return;
  4333.  
  4334. handlePostMessageAfterPromiseB(da);
  4335. da = null;
  4336.  
  4337. waitForInitialDataCompletion = 2;
  4338.  
  4339. const r = cnt.handlePostMessage_(a); // isPlayProgressTriggered is set
  4340. a = null;
  4341.  
  4342. }).catch(console.warn);
  4343.  
  4344. return;
  4345.  
  4346. }
  4347.  
  4348. }
  4349.  
  4350. this.handlePostMessage67_(a);
  4351.  
  4352. }
  4353.  
  4354. }
  4355.  
  4356.  
  4357. })();
  4358.  
  4359. }
  4360.  
  4361.  
  4362. }
  4363. }
  4364.  
  4365. return { setupMutObserver };
  4366.  
  4367.  
  4368.  
  4369. })();
  4370.  
  4371. const setupEvents = () => {
  4372.  
  4373.  
  4374. let scrollCount = 0;
  4375.  
  4376. const passiveCapture = typeof IntersectionObserver === 'function' ? { capture: true, passive: true } : true;
  4377.  
  4378.  
  4379. const delayFlushActiveItemsAfterUserActionK_ = () => {
  4380.  
  4381. const lcRenderer = lcRendererElm();
  4382. if (lcRenderer) {
  4383. const cnt = insp(lcRenderer);
  4384. if (!cnt.hasUserJustInteracted11_) return;
  4385. if (cnt.atBottom && cnt.allowScroll && cnt.activeItems_.length >= 1 && cnt.hasUserJustInteracted11_()) {
  4386. cnt.delayFlushActiveItemsAfterUserAction11_ && cnt.delayFlushActiveItemsAfterUserAction11_();
  4387. }
  4388. }
  4389.  
  4390. }
  4391.  
  4392. document.addEventListener('scroll', (evt) => {
  4393. if (!evt || !evt.isTrusted) return;
  4394. // lastScroll = dateNow();
  4395. if (++scrollCount > 1e9) scrollCount = 9;
  4396. }, passiveCapture); // support contain => support passive
  4397.  
  4398. let lastScrollCount = -1;
  4399. document.addEventListener('wheel', (evt) => {
  4400. if (!evt || !evt.isTrusted) return;
  4401. if (lastScrollCount === scrollCount) return;
  4402. lastScrollCount = scrollCount;
  4403. lastWheel = dateNow();
  4404. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4405. }, passiveCapture); // support contain => support passive
  4406.  
  4407. document.addEventListener('mousedown', (evt) => {
  4408. if (!evt || !evt.isTrusted) return;
  4409. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4410. lastMouseDown = dateNow();
  4411. currentMouseDown = true;
  4412. lastUserInteraction = lastMouseDown;
  4413. }, passiveCapture);
  4414.  
  4415. document.addEventListener('pointerdown', (evt) => {
  4416. if (!evt || !evt.isTrusted) return;
  4417. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4418. lastMouseDown = dateNow();
  4419. currentMouseDown = true;
  4420. lastUserInteraction = lastMouseDown;
  4421. }, passiveCapture);
  4422.  
  4423. document.addEventListener('click', (evt) => {
  4424. if (!evt || !evt.isTrusted) return;
  4425. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4426. lastMouseDown = lastMouseUp = dateNow();
  4427. currentMouseDown = false;
  4428. lastUserInteraction = lastMouseDown;
  4429. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4430. }, passiveCapture);
  4431.  
  4432. document.addEventListener('tap', (evt) => {
  4433. if (!evt || !evt.isTrusted) return;
  4434. if (((evt || 0).target || 0).id !== 'item-scroller') return;
  4435. lastMouseDown = lastMouseUp = dateNow();
  4436. currentMouseDown = false;
  4437. lastUserInteraction = lastMouseDown;
  4438. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4439. }, passiveCapture);
  4440.  
  4441.  
  4442. document.addEventListener('mouseup', (evt) => {
  4443. if (!evt || !evt.isTrusted) return;
  4444. if (currentMouseDown) {
  4445. lastMouseUp = dateNow();
  4446. currentMouseDown = false;
  4447. lastUserInteraction = lastMouseUp;
  4448. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4449. }
  4450. }, passiveCapture);
  4451.  
  4452.  
  4453. document.addEventListener('pointerup', (evt) => {
  4454. if (!evt || !evt.isTrusted) return;
  4455. if (currentMouseDown) {
  4456. lastMouseUp = dateNow();
  4457. currentMouseDown = false;
  4458. lastUserInteraction = lastMouseUp;
  4459. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4460. }
  4461. }, passiveCapture);
  4462.  
  4463. document.addEventListener('touchstart', (evt) => {
  4464. if (!evt || !evt.isTrusted) return;
  4465. lastTouchDown = dateNow();
  4466. currentTouchDown = true;
  4467. lastUserInteraction = lastTouchDown;
  4468. }, passiveCapture);
  4469.  
  4470. document.addEventListener('touchmove', (evt) => {
  4471. if (!evt || !evt.isTrusted) return;
  4472. lastTouchDown = dateNow();
  4473. currentTouchDown = true;
  4474. lastUserInteraction = lastTouchDown;
  4475. }, passiveCapture);
  4476.  
  4477. document.addEventListener('touchend', (evt) => {
  4478. if (!evt || !evt.isTrusted) return;
  4479. if (currentTouchDown) {
  4480. lastTouchUp = dateNow();
  4481. currentTouchDown = false;
  4482. lastUserInteraction = lastTouchUp;
  4483. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4484. }
  4485. }, passiveCapture);
  4486.  
  4487. document.addEventListener('touchcancel', (evt) => {
  4488. if (!evt || !evt.isTrusted) return;
  4489. if (currentTouchDown) {
  4490. lastTouchUp = dateNow();
  4491. currentTouchDown = false;
  4492. lastUserInteraction = lastTouchUp;
  4493. delayFlushActiveItemsAfterUserActionK_ && delayFlushActiveItemsAfterUserActionK_();
  4494. }
  4495. }, passiveCapture);
  4496.  
  4497.  
  4498. }
  4499.  
  4500. const getTimestampUsec = (itemRenderer) => {
  4501. if (itemRenderer && 'timestampUsec' in itemRenderer) {
  4502. return itemRenderer.timestampUsec
  4503. } else if (itemRenderer && itemRenderer.showItemEndpoint) {
  4504. const messageRenderer = ((itemRenderer.showItemEndpoint.showLiveChatItemEndpoint || 0).renderer || 0);
  4505. if (messageRenderer) {
  4506.  
  4507. const messageRendererKey = firstObjectKey(messageRenderer);
  4508. if (messageRendererKey && messageRenderer[messageRendererKey]) {
  4509. const messageRendererData = messageRenderer[messageRendererKey];
  4510. if (messageRendererData && 'timestampUsec' in messageRendererData) {
  4511. return messageRendererData.timestampUsec
  4512. }
  4513. }
  4514. }
  4515. }
  4516. return null;
  4517. }
  4518.  
  4519. const onRegistryReadyForDOMOperations = () => {
  4520.  
  4521. let firstCheckedOnYtInit = false;
  4522.  
  4523. const assertorURL = () => assertor(() => location.pathname.startsWith('/live_chat') && (location.search.indexOf('continuation=') > 0 || location.search.indexOf('v=') > 0));
  4524.  
  4525. const mightFirstCheckOnYtInit = () => {
  4526. if (firstCheckedOnYtInit) return;
  4527. firstCheckedOnYtInit = true;
  4528.  
  4529. if (!document.body || !document.head) return;
  4530. if (!assertorURL()) return;
  4531.  
  4532. addCssManaged();
  4533.  
  4534. let efsContainer = document.getElementById('elzm-fonts-yk75g');
  4535. if (efsContainer && efsContainer.parentNode !== document.body) {
  4536. document.body.appendChild(efsContainer);
  4537. }
  4538.  
  4539. };
  4540.  
  4541. if (!assertorURL()) return;
  4542. // if (!assertor(() => document.getElementById('yt-masthead') === null)) return;
  4543.  
  4544.  
  4545. const { weakWrap } = (() => {
  4546.  
  4547.  
  4548. // const tickerFuncProps = new Set([
  4549. // 'animateShowStats', 'animateHideStats', // updateStatsBarAndMaybeShowAnimationRevised
  4550. // 'collapse', // slideDownNoSelfLeakage
  4551. // 'requestRemoval', // collapseNoSelfLeakage
  4552. // 'setContainerWidth', 'get', 'set', // deletedChangedNoSelfLeakage
  4553. // 'computeAriaLabel', //dataChanged
  4554. // 'startCountdown', // dataChanged [in case]
  4555. // ]);
  4556.  
  4557. // const tickerTags = new Set([
  4558. // "yt-live-chat-ticker-renderer",
  4559. // "yt-live-chat-ticker-paid-message-item-renderer",
  4560. // "yt-live-chat-ticker-paid-sticker-item-renderer",
  4561. // "yt-live-chat-ticker-sponsor-item-renderer"
  4562. // ]);
  4563.  
  4564. // const emptySet = new Set();
  4565.  
  4566.  
  4567.  
  4568. // const tickerFuncPropsFn = (cnt) => {
  4569.  
  4570. // const is = `${cnt.is}`;
  4571.  
  4572. // if (tickerTags.has(is)) {
  4573. // let flg = 0;
  4574. // if (cnt.get && cnt.set) flg |= 1;
  4575. // if (cnt.setContainerWidth && cnt.collapse && cnt.requestRemoval) flg |= 2;
  4576. // if (cnt.animateShowStats && cnt.animateHideStats) flg |= 4;
  4577. // if (cnt.startCountdown) flg |= 8;
  4578. // console.log(`DEBUG flag_6877 = ${flg}`, is);
  4579. // // DEBUG flag_6877 = 15 yt-live-chat-ticker-paid-message-item-renderer
  4580. // // DEBUG flag_6877 = 11 yt-live-chat-ticker-sponsor-item-renderer
  4581. // return tickerFuncProps;
  4582. // }
  4583.  
  4584. // return emptySet;
  4585.  
  4586.  
  4587. // }
  4588.  
  4589.  
  4590. // const smb = Symbol();
  4591. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  4592. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  4593. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  4594.  
  4595.  
  4596.  
  4597.  
  4598. const thisConversionFn = (thisArg) => {
  4599. if (!thisArg) return null;
  4600. const kThis = thisArg[vmb];
  4601. if (kThis) {
  4602. const ref = kThis.ref;
  4603. return (ref ? kRef(ref) : null) || null;
  4604. }
  4605. return thisArg;
  4606. }
  4607.  
  4608. const pFnHandler2 = {
  4609. get(target, prop) {
  4610. if (prop === vmc) return target;
  4611. return Reflect.get(target, prop);
  4612. },
  4613. apply(target, thisArg, argumentsList) {
  4614. thisArg = thisConversionFn(thisArg);
  4615. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  4616. }
  4617. }
  4618.  
  4619.  
  4620. const proxySelfHandler = {
  4621. get(target, prop) {
  4622. if(prop === vmb) return target;
  4623. const ref = target.ref;
  4624. const cnt = kRef(ref);
  4625. if (!cnt) return;
  4626. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  4627. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  4628. return cnt[prop][vmd];
  4629. }
  4630. return cnt[prop];
  4631. },
  4632. set(target, prop, value) {
  4633. const cnt = kRef(target.ref);
  4634. if (!cnt) return true;
  4635. if(value && (value[vmc] || value[vmb])){
  4636. cnt[prop] = value[vmc] || thisConversionFn(value);
  4637. return true;
  4638. }
  4639. cnt[prop] = value;
  4640. return true;
  4641. }
  4642. };
  4643.  
  4644. const weakWrap = (thisArg) => {
  4645. thisArg = thisConversionFn(thisArg);
  4646. if (!thisArg) {
  4647. console.error('thisArg is not found');
  4648. return null;
  4649. }
  4650. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  4651. }
  4652.  
  4653.  
  4654.  
  4655.  
  4656.  
  4657.  
  4658. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  4659. window.getComputedStyle533 = window.getComputedStyle;
  4660. window.getComputedStyle = function (a, ...args) {
  4661. a = thisConversionFn(a);
  4662. if (a) {
  4663. return getComputedStyle533(a, ...args);
  4664. }
  4665. return null;
  4666. }
  4667. }
  4668.  
  4669.  
  4670.  
  4671.  
  4672.  
  4673.  
  4674.  
  4675. // const fnProxySelf = function (...args) {
  4676. // const cnt = kRef(this.ref);
  4677. // if (cnt) {
  4678. // return cnt[this.prop](...args); // might throw error
  4679. // }
  4680. // }
  4681. // const proxySelfHandler = {
  4682. // get(target, prop) {
  4683. // const ref = target.ref;
  4684. // const cnt = kRef(ref);
  4685. // if (!cnt) return;
  4686. // if (prop === 'dtz06') return 1;
  4687. // if (typeof cnt[prop] === 'function') {
  4688. // if (!target.funcs.has(prop)) {
  4689. // console.warn(`proxy get to function | prop: ${prop} | is: ${cnt.is}`);
  4690. // }
  4691. // if (!target[`$$${prop}$$`]) target[`$$${prop}$$`] = fnProxySelf.bind({ prop, ref });
  4692. // return target[`$$${prop}$$`];
  4693. // }
  4694. // return cnt[prop];
  4695. // },
  4696. // set(target, prop, value) {
  4697. // const cnt = kRef(target.ref);
  4698. // if (!cnt) return true;
  4699. // if (typeof value === 'function') {
  4700. // console.warn(`proxy set to function | prop: ${prop} | is: ${cnt.is}`);
  4701. // cnt[prop] = value;
  4702. // return true;
  4703. // }
  4704. // cnt[prop] = value;
  4705. // return true;
  4706. // }
  4707. // };
  4708.  
  4709. // return { tickerFuncPropsFn, proxySelfHandler }
  4710.  
  4711. return {weakWrap}
  4712. })();
  4713.  
  4714.  
  4715.  
  4716. if (document.documentElement && document.head) {
  4717. addCssManaged();
  4718. }
  4719. // console.log(document.body===null)
  4720.  
  4721. const preprocessChatLiveActionsMap = new WeakSet();
  4722.  
  4723. const toLAObj=(aItem)=>{
  4724.  
  4725. if (!aItem || typeof aItem !== 'object') return false;
  4726. const key = firstObjectKey(aItem); // addLiveChatTickerItemAction
  4727. if (!key) return false;
  4728. let obj = aItem[key];
  4729. if (!obj || typeof obj !== 'object') return false;
  4730.  
  4731. if (typeof (obj.item || 0) == 'object' && firstObjectKey(obj) === 'item') {
  4732. obj = obj.item;
  4733. const key = firstObjectKey(obj);
  4734. if (key) {
  4735. obj = obj[key];
  4736. }
  4737. }
  4738.  
  4739. return obj;
  4740.  
  4741. };
  4742.  
  4743. const groupsK38=[];
  4744.  
  4745.  
  4746. function intervalsOverlap(a1, a2, b1, b2) {
  4747. // Order the intervals without using Math functions
  4748. var startA = a1 <= a2 ? a1 : a2;
  4749. var endA = a1 <= a2 ? a2 : a1;
  4750.  
  4751. var startB = b1 <= b2 ? b1 : b2;
  4752. var endB = b1 <= b2 ? b2 : b1;
  4753.  
  4754. // Check for overlap
  4755. return endA >= startB && endB >= startA;
  4756. }
  4757.  
  4758.  
  4759.  
  4760. const insertIntoSortedArrayA28 = (arr, val) => {
  4761. let left = 0;
  4762. const n = arr.length;
  4763. let right = n;
  4764.  
  4765. // Binary search to find the correct insertion index:
  4766. // We want the first index where arr[index][2] >= val[2].
  4767. while (left < right) {
  4768. const mid = (left + right) >>> 1;
  4769. if (arr[mid][0] < val[0]) {
  4770. left = mid + 1;
  4771. } else {
  4772. right = mid;
  4773. }
  4774. }
  4775.  
  4776. // 'left' is now the insertion index
  4777. left === n ? arr.push(val): arr.splice(left, 0, val);
  4778. };
  4779.  
  4780. function removeNullsInPlace(arr, startI = 0) {
  4781. let insertPos = startI;
  4782. for (let i = startI; i < arr.length; i++) {
  4783. if (arr[i] !== null) {
  4784. insertPos !== i && (arr[insertPos] = arr[i]);
  4785. insertPos++;
  4786. }
  4787. }
  4788. arr.length = insertPos; // Remove the trailing nulls.
  4789. }
  4790.  
  4791. let fir = 0;
  4792.  
  4793. const limitAddition = (a, b) => {
  4794. // Number.MAX_SAFE_INTEGER = 9007199254740991
  4795. // k^2 = 9007199254740991 => k = 94906265.62425154
  4796. // Choose k = 2^26 = 67108864 < 94906265.62425154
  4797. // Consider x - x/sqrt(1+x^2/k^2) = 0.4 |x=w => w = 153302.9412
  4798. // Choose w = 2^17 = 131072 < 153302.9412
  4799.  
  4800. const k = 67108864;
  4801. const w = 131072;
  4802. if (a < w && b < w) return a + b;
  4803. return Math.round((a + b) / (1 + a * b / k / k));
  4804. }
  4805.  
  4806. const preprocessChatLiveActions = (arr) =>{
  4807.  
  4808. if (!__LCRInjection__) {
  4809. console.error('[yt-chat] preprocessChatLiveActions might fail because of no __LCRInjection__');
  4810. }
  4811.  
  4812. if (!fir) {
  4813.  
  4814.  
  4815. console.log('[yt-chat-debug] 5990', 'preprocessChatLiveActions', arr)
  4816.  
  4817. console.log('[yt-chat-debug] 5991', document.querySelectorAll('yt-live-chat-ticker-renderer #ticker-items [class]').length)
  4818.  
  4819. fir = 1;
  4820. // debugger;
  4821. }
  4822.  
  4823. if(!arr || !arr.length) return arr;
  4824.  
  4825. if(preprocessChatLiveActionsMap.has(arr)) return arr;
  4826. preprocessChatLiveActionsMap.add(arr);
  4827.  
  4828.  
  4829.  
  4830. const ct = Date.now();
  4831.  
  4832. let groups_ = null;
  4833.  
  4834. // console.log(1237005);
  4835. // const conversionMap = new WeakMap();
  4836.  
  4837. const additionalInfo = new WeakMap();
  4838.  
  4839. // const adjustmentMap = new Map();
  4840.  
  4841. if (FIX_TIMESTAMP_FOR_REPLAY) {
  4842.  
  4843. // console.log('group02331')
  4844. // console.time('FIX_TIMESTAMP_FOR_REPLAY')
  4845.  
  4846. // const stack = new Array(arr.length);
  4847. // let stackL = 0;
  4848.  
  4849. // const arrHash = new Array(arr.length);
  4850.  
  4851.  
  4852. const groups = groupsK38;
  4853. // const delta = 2.0; // head-to-tail + 0.5 + 0.5 = 1.0 -> symmetric -> 1.0 * 2 = 2.0
  4854. // (2)
  4855. // (1.5, 2.5)
  4856. // (1.51, 2.49)
  4857. // -> (1.01, 2.01) , (1.99, 2.99)
  4858. // 2.99 - 1.01 = 1.98 -> 2
  4859.  
  4860.  
  4861.  
  4862. const pushToGroup = (t0mu)=>{
  4863.  
  4864. const t0auDv = t0mu - 1e6; // t0buDv - t0auDv = 2e6
  4865. const t0buDv = t0mu + 1e6;
  4866. // const t0auEv = t0mu - 2e6;
  4867. // const t0buEv = t0mu + 2e6;
  4868.  
  4869. let groupK = false;
  4870. // let m = -1;
  4871. // let q= 0;
  4872. //const qq =true;
  4873. //qq && console.log('-------')
  4874.  
  4875. let lastRight = null;
  4876. let lastK = null;
  4877. let deletedStartIndex = -1;
  4878.  
  4879. for (let k = 0, kl = groups.length; k < kl; k++) {
  4880.  
  4881. const group = groups[k];
  4882. const [groupStart, groupEnd, gCount] = group;
  4883. //qq && console.log(`-- ${k} ----- ${groupMid} : [${groupStart},${groupEnd}] || C1 = ${t0buEv < groupMid} || C2 = ${t0auEv > groupMid}`);
  4884.  
  4885. // if (t0bsEv < groupMid) continue; // if(t0m + 1.0 < groupMid - 1.0) continue;
  4886. // if (m < 0) m = k;
  4887. // if (t0asEv > groupMid){
  4888. // continue; // if(t0m - 1.0 > groupMid + 1.0) break;
  4889. // }
  4890.  
  4891.  
  4892. // if (m < 0) m = k;
  4893.  
  4894. if (lastRight > groupStart) {
  4895. if (!groupK) {
  4896. // just in case sth wrong
  4897. console.warn('logic ERROR');
  4898. groups[k] = null;
  4899. if(deletedStartIndex < 0) deletedStartIndex = k;
  4900. break;
  4901. } else {
  4902.  
  4903.  
  4904. // GroupA: N_a' = N_a + n_e{1} ; Note n_e is the only way to shift right to cause " (lastRight > groupStart) "
  4905. // GroupB: N_b
  4906. // Merge Group (A) = N_a' + N_b
  4907.  
  4908. // without entry moditification, no overlap
  4909. // this must be due to entry moditifcation
  4910. // entry is already count. so can be skipped after merging
  4911.  
  4912. // for merging, groupA will move to right side but left than groupB, so no overlap to groupC
  4913.  
  4914. const group = groups[lastK];
  4915. const newN = limitAddition(group[2], gCount);
  4916.  
  4917. group[0] = (group[0] * group[2] + groupStart * gCount) / (group[2] + gCount)
  4918.  
  4919. group[1] = lastRight = (group[1] * group[2] + groupEnd * gCount) / (group[2] + gCount)
  4920.  
  4921. group[2] = newN;
  4922. // no change of lastK
  4923. groups[k] = null;
  4924. if(deletedStartIndex < 0) deletedStartIndex = k;
  4925. continue;
  4926. }
  4927. }
  4928.  
  4929. const minGroupStart = lastRight; // all groupStart, groupEnd >= minGroupStart for k, k+1, ...
  4930. if (t0buDv < minGroupStart) {
  4931. // no overlapping could be possible
  4932. break;
  4933. }
  4934.  
  4935. if (intervalsOverlap(t0auDv, t0buDv, groupStart, groupEnd)) {
  4936.  
  4937. groupK = true;
  4938.  
  4939. // if (t0auDv > groupStart) group[0] = t0auDv;
  4940. // else if (t0buDv < groupEnd) group[1] = t0buDv;
  4941.  
  4942. const newStart = (groupStart * gCount + t0auDv) / (gCount + 1);
  4943.  
  4944. if (newStart < lastRight) {
  4945. // n_e{1} will make N_b shift left
  4946.  
  4947. // GroupA: N_a
  4948. // GroupB: N_b
  4949. // Merge Group (A) = N_a + N_b + n_e{1}
  4950.  
  4951. const group = groups[lastK];
  4952. const newN = limitAddition(limitAddition(group[2], gCount), 1);
  4953.  
  4954. group[0] = (group[0] * group[2] + groupStart * gCount + t0auDv) / (group[2] + gCount + 1)
  4955.  
  4956. group[1] = lastRight = (group[1] * group[2] + groupEnd * gCount + t0buDv) / (group[2] + gCount + 1)
  4957.  
  4958. group[2] = newN;
  4959. // no change of lastK
  4960. groups[k] = null;
  4961. if(deletedStartIndex < 0) deletedStartIndex = k;
  4962. continue;
  4963.  
  4964. } else {
  4965. // n_e{1} will make N_b shift either left or right
  4966.  
  4967. // GroupT: N_t
  4968. // Group (T) = N_t + n_e{1}
  4969.  
  4970. const newN = limitAddition(gCount, 1);
  4971.  
  4972. group[0] = newStart;
  4973. group[1] = lastRight = (groupEnd * gCount + t0buDv) / (gCount + 1);
  4974. group[2] = newN;
  4975.  
  4976. lastK = k;
  4977.  
  4978. // (t0asDv > groupStart) && (t0bsDv < groupEnd) means full containement
  4979. // however, group size is smaller than or equal to t0width
  4980. }
  4981.  
  4982.  
  4983. } else {
  4984. // just update record for next iteration
  4985.  
  4986. lastRight = groupEnd;
  4987. lastK = k;
  4988. }
  4989.  
  4990.  
  4991.  
  4992. }
  4993.  
  4994. if (deletedStartIndex >= 0) {
  4995. // rarely used
  4996.  
  4997. removeNullsInPlace(groups, deletedStartIndex);
  4998.  
  4999. }
  5000. if (!groupK) {
  5001. // groups.push([t0auDv, t0buDv, 1]);
  5002. insertIntoSortedArrayA28(groups, [t0auDv, t0buDv, 1]);
  5003. // insertIntoSortedArrayA27(groups, [t0auDv, t0buDv, t0mu]);
  5004. }
  5005.  
  5006.  
  5007. }
  5008.  
  5009. let autoTimeStampFrameChoose = 0;
  5010.  
  5011. // console.log('group02332')
  5012. for (let j = 0, l = arr.length; j < l; j++) {
  5013. const aItem = arr[j];
  5014.  
  5015. const obj = toLAObj(aItem);
  5016. if (obj === false) continue;
  5017.  
  5018. let p = obj.timestampText;
  5019. let p2, p3=null, p4a=null, p4b=null;
  5020. if(p&&p.simpleText ) p2 = p.simpleText;
  5021.  
  5022. let q = obj.timestampUsec ;
  5023. let q2;
  5024.  
  5025. if(q && +q > 1110553200000000) q2 = +q;
  5026. if (q2 > 0 && !autoTimeStampFrameChoose) {
  5027. const q2cc = Math.round(q2 / 1e6);
  5028. autoTimeStampFrameChoose = q2cc - (q2cc % 10000000);
  5029. if (q2cc - autoTimeStampFrameChoose < 2000000) autoTimeStampFrameChoose -= 10000000;
  5030. // around 10day range
  5031. // exceeded ~10day -> above 10000000
  5032. }
  5033.  
  5034. // console.log('group02333', p2, q2)
  5035. // console.log(3775, q2/1e6, autoTimeStampFrameChoose)
  5036.  
  5037. if(p2 && q2){
  5038.  
  5039. let m;
  5040.  
  5041. if (m = /^\s*(-?)(\d+):(\d+)\s*$/.exec(p2)) {
  5042. let c0z = m[1] ? -1 : 1;
  5043. let c1 = (+m[2]);
  5044. let c2 = (+m[3]);
  5045. if (c0z > 0 && c1 >= 0 && c2 >= 0) {
  5046.  
  5047. p3 = c1 * 60 + c2;
  5048. } else if (c0z < 0 && c1 >= 0 && c2 >= 0) {
  5049. // -4:43 -> -4:42 -> -4:41 ... -> -4:01 -> -4:00 -> -3:59 -> -3:58
  5050. // -> ... -1:01 -> -1:00 -> -0:59 -> ... -> -0:02 -> -0:01 -> -0:00 -> 0:00 -> ...
  5051.  
  5052. p3 = (-c1 * 60) + (-c2);
  5053.  
  5054. }
  5055. if (p3 !== null) {
  5056. // 0:14 -> 13.5s ~ 14.4999s -> [13.5, 14.5)
  5057. p4a = p3 - 0.5;
  5058. p4b = p3 + 0.5;
  5059. }
  5060. } else if (m = /^\s*(-?)(\d+):(\d+):(\d+)\s*$/.exec(p2)) {
  5061.  
  5062. let c0z = m[1] ? -1 : 1;
  5063. let c1 = (+m[2]);
  5064. let c2 = (+m[3]);
  5065. let c3 = (+m[4]);
  5066.  
  5067.  
  5068.  
  5069. if (c0z > 0 && c1 >= 0 && c2 >= 0 && c3 >= 0) {
  5070.  
  5071. p3 = c1 * 60 * 60 + c2 * 60 + c3;
  5072. } else if (c0z < 0 && c1 >= 0 && c2 >= 0 && c3>=0) {
  5073. // -4:43 -> -4:42 -> -4:41 ... -> -4:01 -> -4:00 -> -3:59 -> -3:58
  5074. // -> ... -1:01 -> -1:00 -> -0:59 -> ... -> -0:02 -> -0:01 -> -0:00 -> 0:00 -> ...
  5075.  
  5076. p3 = (-c1 * 60 * 60) + (-c2 * 60) + (-c3);
  5077.  
  5078. }
  5079. if (p3 !== null) {
  5080. // 0:14 -> 13.5s ~ 14.4999s -> [13.5, 14.5)
  5081. p4a = p3 - 0.5;
  5082. p4b = p3 + 0.5;
  5083. }
  5084.  
  5085.  
  5086. }
  5087.  
  5088. }
  5089.  
  5090. if(p4a !== null && p4b !== null && q2 > 0){
  5091.  
  5092. // q2_us = t0_us + dt_us
  5093. // p4a_us <= dt_us < p4b_us
  5094. let p4au = p4a * 1e6;
  5095. let p4bu = p4b * 1e6;
  5096.  
  5097. // p4a_us <= q2_us - t0_us < p4b_us
  5098.  
  5099.  
  5100. // p4a_us - q2_us <= - t0_us < p4b_us - q2_us
  5101.  
  5102. // -p4a_us + q2_us >= t0_us > -p4b_us + q2_us
  5103.  
  5104.  
  5105. let t0au = q2 - p4bu; // q2_us - p4b_us
  5106. let t0bu = q2 - p4au; // q2_us - p4a_us
  5107.  
  5108. // t0 (t0au, t0bu]
  5109.  
  5110. const t0mu = (t0au+t0bu)/2;
  5111.  
  5112. // stack[stackL++]=({
  5113. // id: obj.id,
  5114. // idx: j,
  5115. // p2,
  5116. // // q2s : (q2/ 1e6 - autoTimeStampFrameChoose).toFixed(2),
  5117. // p3,
  5118. // /*
  5119. // timestampText: obj.timestampText,
  5120. // timestampUsec: obj.timestampUsec, // us = 1/1000 ms
  5121. // q2,
  5122. // p4a,
  5123. // p4b,
  5124. // */
  5125. // q2s: +(q2 / 1e6 - autoTimeStampFrameChoose).toFixed(2),
  5126. // t0as: +(t0au / 1e6 - autoTimeStampFrameChoose).toFixed(2),
  5127. // t0bs: +(t0bu /1e6 - autoTimeStampFrameChoose).toFixed(2),
  5128.  
  5129. // t0au,
  5130. // t0bu,
  5131. // t0mu
  5132. // });
  5133.  
  5134. // console.log('group02334')
  5135. let wobj = additionalInfo.get(obj);
  5136. if(!wobj) additionalInfo.set(obj, wobj = {});
  5137.  
  5138. wobj.timestampUsecOriginal = q2;
  5139. // wobj.timestampUsecAdjusted = q2;
  5140. wobj.t0au = t0au;
  5141. wobj.t0bu = t0bu;
  5142. wobj.t0mu = t0mu;
  5143.  
  5144. // arrHash[j] = {
  5145. // index: j,
  5146. // id: obj.id,
  5147. // timestampUsec: q2,
  5148. // t0au,
  5149. // t0bu,
  5150. // t0mu
  5151. // };
  5152.  
  5153. pushToGroup(t0mu);
  5154.  
  5155. // console.log('group02335')
  5156. // console.log('grouping', `${obj.id}.${obj.timestampUsec}`);
  5157.  
  5158. // timestamp (q2) can be incorrect.
  5159.  
  5160. // https://www.youtube.com/watch?v=IKKar5SS29E
  5161. // ChwKGkNQZUxfXzZxLS04Q0ZXNGxyUVlkODZrQzNR
  5162.  
  5163. /*
  5164.  
  5165.  
  5166. [
  5167. {
  5168. "id": "ChwKGkNNWHZqXy1xLS04Q0ZXNGxyUVlkODZrQzNR",
  5169. "p2": "2:04",
  5170. "p3": 124,
  5171. "t0as": 8320733.78,
  5172. "t0bs": 8320734.78
  5173. },
  5174. {
  5175. "id": "ChwKGkNQZUxfXzZxLS04Q0ZXNGxyUVlkODZrQzNR",
  5176. "p2": "2:04",
  5177. "p3": 124,
  5178. "t0as": 8320898.89, // incorrect
  5179. "t0bs": 8320899.89
  5180. }
  5181. ]
  5182.  
  5183.  
  5184. */
  5185.  
  5186. }
  5187.  
  5188.  
  5189.  
  5190.  
  5191. }
  5192.  
  5193. // stack.length = stackL;
  5194.  
  5195.  
  5196. groups_ = groups;
  5197. // console.log('groups', groups)
  5198.  
  5199. }
  5200.  
  5201. // console.log(1237006);
  5202.  
  5203. // console.log(5592,1)
  5204. const groupMids = FIX_TIMESTAMP_FOR_REPLAY ? groups_.map(group=>{
  5205.  
  5206. const [groupStart, groupEnd ] = group;
  5207. const groupMid = (groupStart+groupEnd)/2;
  5208. return groupMid;
  5209. }): null;
  5210. // console.log('groupMids', groupMids)
  5211.  
  5212.  
  5213. // console.log(1237007);
  5214.  
  5215. const adjustTimestampFn = (obj) => {
  5216.  
  5217. const groupCount = groupMids.length;
  5218.  
  5219. if (groupCount < 1) return null;
  5220.  
  5221. // const obj = toLAObj(aItem);
  5222. if (obj === false) return null;
  5223.  
  5224. const wobj = additionalInfo.get(obj);
  5225. if (!wobj) return null;
  5226.  
  5227. const { t0mu } = wobj;
  5228.  
  5229.  
  5230. let i0 = 0;
  5231.  
  5232. if (groupCount >= 3) {
  5233. // For larger arrays, use binary search.
  5234. let low = 0;
  5235. let high = groupCount - 1;
  5236.  
  5237. while (high - low > 1) {
  5238. const mid = (low + high) >>> 1;
  5239. if (groupMids[mid] >= t0mu) {
  5240. high = mid;
  5241. } else {
  5242. low = mid;
  5243. }
  5244. }
  5245. i0 = low;
  5246.  
  5247. }
  5248.  
  5249. let upperDiff = -1;
  5250. let lowerDiff = -1;
  5251. for (let i = i0; i < groupCount; i++) {
  5252. const y = groupMids[i] - t0mu;
  5253. if (y >= 0) {
  5254. upperDiff = y; // >=0, entry > value is found
  5255. break;
  5256. }
  5257. lowerDiff = -y; // >0, cache
  5258. }
  5259.  
  5260.  
  5261. const d1 = upperDiff;
  5262. const d2 = lowerDiff;
  5263.  
  5264.  
  5265. // console.log(5381, index1 ,d1, index2 , d2);
  5266.  
  5267. if (d1 >= 0 && ((d2 < 0) || (d1 <= d2))) {
  5268. wobj.chosenT0 = t0mu + d1; // groupMids[index1];
  5269. } else if (d2 >= 0 && ((d1 < 0) || (d2 <= d1))) {
  5270. wobj.chosenT0 = t0mu - d2; // groupMids[index2];
  5271. } else {
  5272. console.warn('logic error');
  5273. return null;
  5274. }
  5275.  
  5276. const adjusted = wobj.timestampUsecOriginal - wobj.chosenT0;
  5277.  
  5278. wobj.timestampUsecAdjusted = adjusted + 1110553200000000;
  5279.  
  5280. // console.log('adjusted', `${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5281.  
  5282. // adjustmentMap.set(`${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5283.  
  5284. return adjusted;
  5285.  
  5286.  
  5287.  
  5288. };
  5289.  
  5290.  
  5291. // console.log(5592,2)
  5292. // console.log(1237008);
  5293. // if (FIX_TIMESTAMP_FOR_REPLAY) {
  5294.  
  5295.  
  5296. // try{
  5297.  
  5298. // // console.log('groupmid',groupMids, groups);
  5299.  
  5300. // for(let j = 0; j< arr.length;j++){
  5301. // if(groupMids.length<1) break;
  5302.  
  5303. // const aItem = arr[j];
  5304. // const obj = toLAObj(aItem);
  5305. // if (obj === false) continue;
  5306.  
  5307. // const wobj = additionalInfo.get(obj);
  5308. // if(!wobj) continue;
  5309.  
  5310. // // wobj.timestampUsecOriginal = q2;
  5311. // // wobj.timestampUsecAdjusted = q2;
  5312. // // wobj.t0au = t0au;
  5313. // // wobj.t0bu = t0bu;
  5314. // // wobj.t0mu = t0mu;
  5315.  
  5316. // const {t0au, t0bu, t0mu} = wobj;
  5317.  
  5318. // let upper = -1;
  5319.  
  5320. // for(let i = 0; i <groupMids.length;i++){
  5321. // const groupMid = groupMids[i];
  5322. // if(groupMid>= t0mu){
  5323. // upper = i;
  5324. // break;
  5325. // }
  5326. // }
  5327. // let index1, index2;
  5328. // if(upper>-1){
  5329. // index1 = upper-1;
  5330. // index2 = upper;
  5331. // }else{
  5332. // index1 = groups.length-1;
  5333. // index2 = -1;
  5334. // }
  5335. // let d1 = null;
  5336. // if(index1 >=0){
  5337. // d1 = Math.abs(groupMids[index1] - t0mu);
  5338. // }
  5339.  
  5340. // let d2 = null;
  5341. // if(index2 >=0){
  5342. // d2 = Math.abs(groupMids[index2] - t0mu);
  5343. // }
  5344. // // console.log(5381, index1 ,d1, index2 , d2);
  5345. // if(d1 >= 0 && ((d1 <= d2) || (d2 === null)) ){
  5346.  
  5347. // wobj.chosenT0 = groupMids[index1];
  5348. // } else if(d2 >= 0 && ((d2 <= d1) || (d1 === null))){
  5349. // wobj.chosenT0 = groupMids[index2];
  5350. // } else {
  5351. // console.warn('logic error');
  5352. // continue;
  5353. // }
  5354.  
  5355. // wobj.timestampUsecAdjusted = wobj.timestampUsecOriginal - wobj.chosenT0 + 1110553200000000;
  5356.  
  5357. // console.log('adjusted', `${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5358.  
  5359. // adjustmentMap.set(`${obj.id}.${obj.timestampUsec}`, wobj.timestampUsecOriginal - wobj.chosenT0);
  5360. // // conversionMap.set(obj, arrHash[j].adjustedTime);
  5361.  
  5362. // // console.log(5382, index, id, t0mu, arrHash[j].adjustedT0, arrHash[j].timestampUsec, arrHash[j].adjustedTime);
  5363.  
  5364. // }
  5365.  
  5366.  
  5367. // }catch(e){
  5368. // console.warn(e);
  5369. // }
  5370.  
  5371.  
  5372.  
  5373.  
  5374.  
  5375. // // if(stack.length > 1){
  5376. // // stack.sort((a,b)=>{
  5377. // // return a.t0mu - b.t0mu
  5378. // // });
  5379. // // // small to large
  5380. // // // console.log(34588, stack.map(e=>e.t0as))
  5381. // // }
  5382.  
  5383. // // grouping
  5384.  
  5385.  
  5386.  
  5387.  
  5388. // // if (stack.length > 0) {
  5389.  
  5390. // // try {
  5391.  
  5392. // // for (let j = 0, l = stack.length; j < l; j++) {
  5393. // // pushToGroup(stack[j].t0mu);
  5394.  
  5395. // // }
  5396.  
  5397. // // }catch(e){
  5398.  
  5399. // // console.warn(e)
  5400. // // }
  5401.  
  5402. // // // console.log(4882, groups.map(e=>e.slice()), stack.slice())
  5403.  
  5404. // // }
  5405.  
  5406.  
  5407.  
  5408.  
  5409. // // console.log(376, 'group', groups);
  5410.  
  5411.  
  5412. // // consolidated group
  5413. // // const consolidatedGroups = doConsolidation(groups);
  5414.  
  5415.  
  5416.  
  5417.  
  5418.  
  5419.  
  5420. // // if(stack.length > 1){
  5421.  
  5422.  
  5423. // // // // console.log(341, 'consolidatedGroups', consolidatedGroups ,groups.map(e=>{
  5424. // // // // return e.map(noTransform);
  5425. // // // // // return e.map(prettyNum);
  5426. // // // // }))
  5427.  
  5428.  
  5429. // // // console.log(344, 'groups', groups.map(e=>{
  5430. // // // return e.map(noTransform);
  5431. // // // // return e.map(prettyNum);
  5432. // // // }))
  5433.  
  5434. // // // // for(const s of stack){
  5435. // // // // for(const g of consolidatedGroups){
  5436. // // // // if(s.t0as<=g.cen && s.t0bs >=g.cen ){
  5437. // // // // s.cen = g.cen;
  5438. // // // // break;
  5439. // // // // }
  5440. // // // // }
  5441.  
  5442. // // // // }
  5443.  
  5444. // // // console.log(377, stack) // Ms
  5445.  
  5446. // // }
  5447.  
  5448.  
  5449. // // console.timeEnd('FIX_TIMESTAMP_FOR_REPLAY')
  5450.  
  5451. // }
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461. // console.log(5592,5)
  5462.  
  5463.  
  5464. // console.log('preprocessChatLiveActions', arr)
  5465.  
  5466.  
  5467. const mapper = new Map();
  5468.  
  5469. // without delaying. get the time of request
  5470. // (both streaming and replay, but replay relys on progress update so background operation is suppressed)
  5471.  
  5472. for (let j = 0, l = arr.length; j < l; j++) {
  5473. const aItem = arr[j];
  5474.  
  5475. const obj = toLAObj(aItem);
  5476. if(obj === false) continue;
  5477.  
  5478. if (obj.id && !obj.__timestampActionRequest__) {
  5479. // for all item entries
  5480. obj.__timestampActionRequest__ = ct;
  5481. }
  5482.  
  5483. if (obj.id && obj.__timestampActionRequest__ > 0 && obj.durationSec > 0 && obj.fullDurationSec) {
  5484.  
  5485. // console.log(948700, obj , obj.id, (obj.fullDurationSec - obj.durationSec) * 1000)
  5486. const m = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  5487.  
  5488. // obj.__t374__ = (obj.fullDurationSec - obj.durationSec) * 1000;
  5489. // obj.__t375__ = obj.__timestampActionRequest__ - (obj.fullDurationSec - obj.durationSec) * 1000;
  5490. // console.log(5993, obj)
  5491. // obj.__orderTime__ = m;
  5492. mapper.set(aItem, m);
  5493.  
  5494.  
  5495. }
  5496.  
  5497. }
  5498.  
  5499. if (mapper.size > 1) {
  5500.  
  5501. const idxices = [];
  5502.  
  5503. // sort ticker
  5504. let mArr1 = arr.filter((aItem,idx) => {
  5505.  
  5506. if (mapper.has(aItem)) {
  5507. idxices.push(idx);
  5508. return true;
  5509. }
  5510. return false;
  5511.  
  5512. });
  5513.  
  5514.  
  5515. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  5516. return mapper.get(a) - mapper.get(b);
  5517. // low index = oldest = smallest timestamp
  5518. });
  5519.  
  5520.  
  5521.  
  5522. // console.log(948701, arr.slice(0));
  5523. for(let j = 0, l=mArr1.length;j <l;j++){
  5524.  
  5525. const idx = idxices[j];
  5526. // arr[idx] = mArr1[j]
  5527. arr[idx] = mArr2[j];
  5528.  
  5529. // const obj1 = toObj(mArr1[j]);
  5530. // const obj2 = toObj(mArr2[j]);
  5531.  
  5532. // console.log(948705, idx, obj1 , obj1.id, (obj1.fullDurationSec - obj1.durationSec) * 1000, obj1.__orderTime__)
  5533.  
  5534. // console.log(948706, idx, obj2 , obj2.id, (obj2.fullDurationSec - obj2.durationSec) * 1000, obj2.__orderTime__)
  5535.  
  5536. }
  5537.  
  5538. // console.log(5994,arr)
  5539.  
  5540. // console.log(948702, arr.slice(0));
  5541. // console.log(948701, arr);
  5542. // arr = arr.map(aItem => {
  5543. // const idx = mArr1.indexOf(aItem);
  5544. // if (idx < 0) return aItem;
  5545. // return mArr2[idx];
  5546. // });
  5547. // console.log(948702, arr);
  5548.  
  5549. // mostly in order, but some not in order
  5550.  
  5551.  
  5552. // eg
  5553.  
  5554. /*
  5555.  
  5556.  
  5557. 948711 68 '1734488590715474'
  5558. 948711 69 '1734488590909853'
  5559. 948711 70 '1734488594763719'
  5560. 948711 71 '1734488602334615' <
  5561. 948711 72 '1734488602267214' <
  5562. 948711 73 '1734488602751771'
  5563. */
  5564.  
  5565. // arr.filter(aItem=>{
  5566.  
  5567. // const p = toObj(aItem);
  5568. // if(p.timestampUsec) return true;
  5569.  
  5570. // }).forEach((aItem,idx)=>{
  5571.  
  5572. // const p = toObj(aItem);
  5573. // console.log(948711, idx, p.timestampUsec);
  5574. // })
  5575.  
  5576. // return arr;
  5577.  
  5578. }
  5579.  
  5580. // console.log(1237001);
  5581.  
  5582. {
  5583.  
  5584.  
  5585. const mapper = new Map();
  5586.  
  5587.  
  5588. const idxices = [];
  5589.  
  5590.  
  5591. let mArr1 = arr.filter((aItem,idx) => {
  5592.  
  5593. const obj = toLAObj(aItem);
  5594. if (!obj) return false;
  5595.  
  5596. const baseText = obj.timestampText;
  5597. const baseTime = +obj.timestampUsec;
  5598. if (!baseTime || !baseText) return false;
  5599. // const timestampUsec = +toLAObj(aItem).timestampUsec; // +false.x = NaN
  5600. // const timestampUsec = +toLAObj(aItem).adjustedTime;
  5601.  
  5602. let timestampUsec;
  5603.  
  5604. // console.log(1237002)
  5605. if (FIX_TIMESTAMP_FOR_REPLAY) {
  5606.  
  5607. // const adjustmentTime = adjustmentMap.get(`${obj.id}.${obj.timestampUsec}`);
  5608.  
  5609. // // const wobj = additionalInfo.get(obj);
  5610.  
  5611. // // if(!wobj){
  5612. // // console.warn('FIX_TIMESTAMP_FOR_REPLAY - no wobj', obj)
  5613. // // return false;
  5614. // // }
  5615.  
  5616. // // timestampUsec = +wobj.timestampUsecAdjusted;
  5617. // if (!Number.isFinite(adjustmentTime)) {
  5618. // console.warn(`FIX_TIMESTAMP_FOR_REPLAY - no adjustmentTime for ${obj.id}.${obj.timestampUsec}`, obj, [...adjustmentMap])
  5619. // return false;
  5620. // }
  5621. // timestampUsec = adjustmentTime;
  5622.  
  5623.  
  5624. const adjustmentTime = adjustTimestampFn(obj);
  5625.  
  5626. if (!Number.isFinite(adjustmentTime)) {
  5627.  
  5628. console.warn(`FIX_TIMESTAMP_FOR_REPLAY - no adjustmentTime for ${obj.id}.${obj.timestampUsec}`, obj);
  5629. return false;
  5630. }
  5631. timestampUsec = adjustmentTime;
  5632.  
  5633.  
  5634. } else {
  5635.  
  5636. if (!Number.isFinite(baseTime)) {
  5637. console.warn(`no baseTime for ${obj.id}.${obj.timestampUsec}`, obj);
  5638.  
  5639. return false;
  5640. }
  5641. timestampUsec = baseTime;
  5642.  
  5643. }
  5644.  
  5645. // if(timestampUsec > 0){
  5646. idxices.push(idx);
  5647. mapper.set(aItem, timestampUsec)
  5648. return true;
  5649. // }
  5650. // return false;
  5651.  
  5652. });
  5653.  
  5654. if(mapper.size > 1){
  5655.  
  5656.  
  5657. // console.log(1237004)
  5658. let mArr2 = mArr1/*.slice(0)*/.sort((a, b) => {
  5659. return mapper.get(a) - mapper.get(b);
  5660. // low index = oldest = smallest timestamp
  5661. });
  5662.  
  5663.  
  5664.  
  5665. // console.log(948701, arr.slice(0));
  5666. for(let j = 0, l=mArr1.length;j <l;j++){
  5667.  
  5668. const idx = idxices[j];
  5669. arr[idx] = mArr2[j];
  5670.  
  5671. // const obj1 = toObj(mArr1[j]);
  5672. // const obj2 = toObj(mArr2[j]);
  5673.  
  5674.  
  5675. // console.log(948711, idx, obj1 === obj2, obj1, obj1.timestampUsec);
  5676. // console.log(948712, idx, obj1 === obj2, obj2, obj2.timestampUsec);
  5677. }
  5678.  
  5679. }
  5680.  
  5681.  
  5682. }
  5683.  
  5684. // console.log(1237005)
  5685.  
  5686. // console.log(378, arr);
  5687.  
  5688. return arr;
  5689.  
  5690.  
  5691. }
  5692.  
  5693. if (ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION) {
  5694.  
  5695. console.log('ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION is used.')
  5696.  
  5697. // console.log('ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION 0001')
  5698.  
  5699. const pop078 = function () {
  5700. const r = this.pop78();
  5701.  
  5702. if (r && (r.actions || 0).length >= 1 && r.videoOffsetTimeMsec) {
  5703. for (const action of r.actions) {
  5704.  
  5705. const itemActionKey = !action ? null : 'addChatItemAction' in action ? 'addChatItemAction' : 'addLiveChatTickerItemAction' in action ? 'addLiveChatTickerItemAction' : null;
  5706. if (itemActionKey) {
  5707.  
  5708. const itemAction = action[itemActionKey];
  5709. const item = (itemAction || 0).item;
  5710. if (typeof item === 'object') {
  5711.  
  5712. const rendererKey = firstObjectKey(item);
  5713. if (rendererKey) {
  5714. const renderer = item[rendererKey];
  5715. if (renderer && typeof renderer === 'object') {
  5716. renderer.__videoOffsetTimeMsec__ = r.videoOffsetTimeMsec;
  5717. renderer.__progressAt__ = playerProgressChangedArg1;
  5718.  
  5719. // console.log(48117006)
  5720. }
  5721.  
  5722. }
  5723.  
  5724. }
  5725. }
  5726. }
  5727. }
  5728. return r;
  5729. }
  5730.  
  5731.  
  5732.  
  5733. const replayQueueProxyHandler = {
  5734. get(target, prop, receiver) {
  5735. if (prop === 'qe3') return 1;
  5736. const v = target[prop];
  5737. if (prop === 'front_') {
  5738. if (v && typeof v.length === 'number') {
  5739. if (!v.pop78) {
  5740. v.pop78 = v.pop;
  5741. v.pop = pop078;
  5742. }
  5743. }
  5744. }
  5745. return v;
  5746. }
  5747. };
  5748.  
  5749. // lcrFn2 will run twice to ensure the method is successfully injected.
  5750. const lcrFn2 = (lcrDummy)=>{
  5751. // make minimal function overhead by pre-defining all possible outside.
  5752.  
  5753. const tag = "yt-live-chat-renderer"
  5754. const dummy = lcrDummy;
  5755.  
  5756. const cProto = getProto(dummy);
  5757. if (!cProto || !cProto.attached) {
  5758. console.warn(`proto.attached for ${tag} is unavailable.`);
  5759. return;
  5760. }
  5761.  
  5762. // mightFirstCheckOnYtInit();
  5763. // groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-renderer hacks");
  5764. // console.log("[Begin]");
  5765.  
  5766.  
  5767. if (typeof cProto.playerProgressChanged_ === 'function' && !cProto.playerProgressChanged32_) {
  5768.  
  5769. cProto.playerProgressChanged32_ = cProto.playerProgressChanged_;
  5770.  
  5771.  
  5772. cProto.playerProgressChanged_ = function (a, b, c) {
  5773. // console.log(48117005)
  5774. playerProgressChangedArg1 = a;
  5775. playerProgressChangedArg2 = b;
  5776. playerProgressChangedArg3 = c;
  5777. const replayBuffer_ = this.replayBuffer_;
  5778. if (replayBuffer_) {
  5779. const replayQueue = replayBuffer_.replayQueue
  5780. if (replayQueue && typeof replayQueue === 'object' && !replayQueue.qe3) {
  5781. replayBuffer_.replayQueue = new Proxy(replayBuffer_.replayQueue, replayQueueProxyHandler);
  5782. }
  5783. }
  5784. Promise.resolve().then(updateTickerCurrentTime);
  5785. return this.playerProgressChanged32_.apply(this, arguments);
  5786. };
  5787.  
  5788. }
  5789.  
  5790. // console.log("[End]");
  5791. // console.groupEnd();
  5792.  
  5793.  
  5794. };
  5795. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  5796.  
  5797.  
  5798. // console.log('ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION 0002')
  5799.  
  5800. // getLCRDummy() must be called for injection
  5801. getLCRDummy().then(lcrFn2);
  5802.  
  5803. }
  5804.  
  5805.  
  5806.  
  5807. customElements.whenDefined('yt-live-chat-item-list-renderer').then(() => {
  5808.  
  5809.  
  5810. const tag = "yt-live-chat-item-list-renderer"
  5811. const dummy = document.createElement(tag);
  5812.  
  5813. const cProto = getProto(dummy);
  5814. if (!cProto || !cProto.attached) {
  5815. console.warn(`proto.attached for ${tag} is unavailable.`);
  5816. return;
  5817. }
  5818.  
  5819. mightFirstCheckOnYtInit();
  5820. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-item-list-renderer hacks");
  5821. console.log("[Begin]");
  5822.  
  5823. const mclp = cProto;
  5824. const _flag0281_ = window._flag0281_ || mclp._flag0281_;
  5825.  
  5826. try {
  5827. assertor(() => typeof mclp.scrollToBottom_ === 'function');
  5828. assertor(() => typeof mclp.flushActiveItems_ === 'function');
  5829. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  5830. assertor(() => typeof mclp.setAtBottom === 'function');
  5831. assertor(() => typeof mclp.scrollToBottom66_ === 'undefined');
  5832. assertor(() => typeof mclp.flushActiveItems66_ === 'undefined');
  5833. } catch (e) { }
  5834.  
  5835.  
  5836. try {
  5837. assertor(() => typeof mclp.attached === 'function');
  5838. assertor(() => typeof mclp.detached === 'function');
  5839. assertor(() => typeof mclp.canScrollToBottom_ === 'function');
  5840. assertor(() => typeof mclp.isSmoothScrollEnabled_ === 'function');
  5841. assertor(() => typeof mclp.maybeResizeScrollContainer_ === 'function');
  5842. assertor(() => typeof mclp.refreshOffsetContainerHeight_ === 'function');
  5843. assertor(() => typeof mclp.smoothScroll_ === 'function');
  5844. assertor(() => typeof mclp.resetSmoothScroll_ === 'function');
  5845. } catch (e) { }
  5846.  
  5847. mclp.__intermediate_delay__ = null;
  5848.  
  5849. let myk = 0;
  5850. let mlf = 0;
  5851. let myw = 0;
  5852. let mzt = 0;
  5853. let zarr = null;
  5854. let mlg = 0;
  5855.  
  5856. if ((_flag0281_ & 0x2000) == 0) {
  5857.  
  5858. if ((mclp.clearList || 0).length === 0) {
  5859. (_flag0281_ & 0x2) == 0 && assertor(() => fnIntegrity(mclp.clearList, '0.106.50'));
  5860. mclp.clearList66 = mclp.clearList;
  5861. mclp.clearList = function () {
  5862. myk++;
  5863. mlf++;
  5864. myw++;
  5865. mzt++;
  5866. mlg++;
  5867. zarr = null;
  5868. this.__intermediate_delay__ = null;
  5869. this.clearList66();
  5870. };
  5871. console.log("clearList", "OK");
  5872. } else {
  5873. console.log("clearList", "NG");
  5874. }
  5875.  
  5876. }
  5877.  
  5878.  
  5879.  
  5880. let onListRendererAttachedDone = false;
  5881.  
  5882. function setList(itemOffset, items) {
  5883.  
  5884. const isFirstTime = onListRendererAttachedDone === false;
  5885.  
  5886. if (isFirstTime) {
  5887. onListRendererAttachedDone = true;
  5888. Promise.resolve().then(watchUserCSS);
  5889. addCssManaged();
  5890. setupEvents();
  5891. }
  5892.  
  5893. setupStyle(itemOffset, items);
  5894.  
  5895. setupMutObserver(items);
  5896. }
  5897.  
  5898. mclp.attached419 = async function () {
  5899.  
  5900. if (!this.isAttached) return;
  5901.  
  5902. let maxTrial = 16;
  5903. while (!this.$ || !this.$['item-scroller'] || !this.$['item-offset'] || !this.$['items']) {
  5904. if (--maxTrial < 0 || !this.isAttached) return;
  5905. await iAFP(this.hostElement).then();
  5906. // await new Promise(requestAnimationFrame);
  5907. }
  5908.  
  5909. if (this.isAttached !== true) return;
  5910.  
  5911. if (!this.$) {
  5912. console.warn("!this.$");
  5913. return;
  5914. }
  5915. if (!this.$) return;
  5916. /** @type {HTMLElement | null} */
  5917. const itemScroller = this.$['item-scroller'];
  5918. /** @type {HTMLElement | null} */
  5919. const itemOffset = this.$['item-offset'];
  5920. /** @type {HTMLElement | null} */
  5921. const items = this.$['items'];
  5922.  
  5923. if (!itemScroller || !itemOffset || !items) {
  5924. console.warn("items.parentNode !== itemOffset");
  5925. return;
  5926. }
  5927.  
  5928. if (nodeParent(items) !== itemOffset) {
  5929.  
  5930. console.warn("items.parentNode !== itemOffset");
  5931. return;
  5932. }
  5933.  
  5934.  
  5935. if (items.id !== 'items' || itemOffset.id !== "item-offset") {
  5936.  
  5937. console.warn("id incorrect");
  5938. return;
  5939. }
  5940.  
  5941. 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')
  5942.  
  5943. if (!isTargetItems) {
  5944. console.warn("!isTargetItems");
  5945. return;
  5946. }
  5947.  
  5948. setList(itemOffset, items);
  5949.  
  5950. }
  5951.  
  5952. mclp.attached331 = mclp.attached;
  5953. mclp.attached = function () {
  5954. this.attached419 && this.attached419();
  5955. return this.attached331();
  5956. }
  5957.  
  5958. mclp.detached331 = mclp.detached;
  5959.  
  5960. mclp.detached = function () {
  5961. setupMutObserver();
  5962. return this.detached331();
  5963. }
  5964.  
  5965. const t29s = document.querySelectorAll("yt-live-chat-item-list-renderer");
  5966. for (const t29 of t29s) {
  5967. if (insp(t29).isAttached === true) {
  5968. t29.attached419();
  5969. }
  5970. }
  5971.  
  5972. if ((mclp.async || 0).length === 2 && (mclp.cancelAsync || 0).length === 1) {
  5973.  
  5974. assertor(() => fnIntegrity(mclp.async, '2.24.15'));
  5975. assertor(() => fnIntegrity(mclp.cancelAsync, '1.15.8'));
  5976.  
  5977. /** @type {Map<number, any>} */
  5978. const aMap = new Map();
  5979. let count = 6150;
  5980. mclp.async66 = mclp.async;
  5981. mclp.async = function (e, f) {
  5982. // ensure the previous operation is done
  5983. // .async is usually after the time consuming functions like flushActiveItems_ and scrollToBottom_
  5984. const hasF = arguments.length === 2;
  5985. const stack = new Error().stack;
  5986. const isFlushAsync = stack.indexOf('flushActiveItems_') >= 0;
  5987. if (count > 1e9) count = 6159;
  5988. const resId = ++count;
  5989. aMap.set(resId, e);
  5990. (this.__intermediate_delay__ || Promise.resolve()).then(rk => {
  5991. const rp = aMap.get(resId);
  5992. if (typeof rp !== 'function') {
  5993. return;
  5994. }
  5995. let cancelCall = false;
  5996. if (isFlushAsync) {
  5997. if (rk < 0) {
  5998. cancelCall = true;
  5999. } else if (rk === 2 && arguments[0] === this.maybeScrollToBottom_) {
  6000. cancelCall = true;
  6001. }
  6002. }
  6003. if (cancelCall) {
  6004. aMap.delete(resId);
  6005. } else {
  6006. const asyncEn = function () {
  6007. aMap.delete(resId);
  6008. return rp.apply(this, arguments);
  6009. };
  6010. aMap.set(resId, hasF ? this.async66(asyncEn, f) : this.async66(asyncEn));
  6011. }
  6012. });
  6013.  
  6014. return resId;
  6015. }
  6016.  
  6017. mclp.cancelAsync66 = mclp.cancelAsync;
  6018. mclp.cancelAsync = function (resId) {
  6019. if (resId <= 6150) {
  6020. this.cancelAsync66(resId);
  6021. } else if (aMap.has(resId)) {
  6022. const rp = aMap.get(resId);
  6023. aMap.delete(resId);
  6024. if (typeof rp !== 'function') {
  6025. this.cancelAsync66(rp);
  6026. }
  6027. }
  6028. }
  6029.  
  6030. console.log("async", "OK");
  6031. } else {
  6032. console.log("async", "NG");
  6033. }
  6034.  
  6035.  
  6036. if ((_flag0281_ & 0x2) == 0) {
  6037. if ((mclp.showNewItems_ || 0).length === 0 && ENABLE_NO_SMOOTH_TRANSFORM) {
  6038.  
  6039. assertor(() => fnIntegrity(mclp.showNewItems_, '0.170.79'));
  6040. mclp.showNewItems66_ = mclp.showNewItems_;
  6041.  
  6042. mclp.showNewItems77_ = async function () {
  6043. if (myk > 1e9) myk = 9;
  6044. let tid = ++myk;
  6045.  
  6046. await iAFP(this.hostElement).then();
  6047. // await new Promise(requestAnimationFrame);
  6048.  
  6049. if (tid !== myk) {
  6050. return;
  6051. }
  6052.  
  6053. const cnt = this;
  6054.  
  6055. await Promise.resolve();
  6056. cnt.showNewItems66_();
  6057.  
  6058. await Promise.resolve();
  6059.  
  6060. }
  6061.  
  6062. mclp.showNewItems_ = function () {
  6063.  
  6064. const cnt = this;
  6065. cnt.__intermediate_delay__ = new Promise(resolve => {
  6066. cnt.showNewItems77_().then(() => {
  6067. resolve();
  6068. });
  6069. });
  6070. }
  6071.  
  6072. console.log("showNewItems_", "OK");
  6073. } else {
  6074. console.log("showNewItems_", "NG");
  6075. }
  6076.  
  6077. }
  6078.  
  6079. if ((_flag0281_ & 0x2000) == 0) {
  6080. if ((mclp.flushActiveItems_ || 0).length === 0) {
  6081.  
  6082. if ((_flag0281_ & 0x2) == 0) {
  6083.  
  6084. const sfi = fnIntegrity(mclp.flushActiveItems_);
  6085. if(sfi === '0.158.86'){
  6086.  
  6087. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6088.  
  6089.  
  6090. // f.flushActiveItems_ = function() {
  6091. // var a = this;
  6092. // if (this.activeItems_.length > 0)
  6093. // if (this.canScrollToBottom_()) {
  6094. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6095. // b && this.splice("visibleItems", 0, b);
  6096. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6097. // this.preinsertHeight_ = this.items.clientHeight;
  6098. // this.activeItems_.unshift("visibleItems");
  6099. // try {
  6100. // this.push.apply(this, this.activeItems_)
  6101. // } catch (c) {
  6102. // Tm(c)
  6103. // }
  6104. // this.activeItems_ = [];
  6105. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && $u(function() {
  6106. // a.showNewItems_()
  6107. // }) : $u(function() {
  6108. // a.refreshOffsetContainerHeight_();
  6109. // a.maybeScrollToBottom_()
  6110. // })
  6111. // } else
  6112. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  6113. // }
  6114.  
  6115. } else if (sfi === '0.156.86') {
  6116. // https://www.youtube.com/s/desktop/f61c8d85/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6117.  
  6118. // added "refreshOffsetContainerHeight_"
  6119.  
  6120. // f.flushActiveItems_ = function() {
  6121. // var a = this;
  6122. // if (0 < this.activeItems_.length)
  6123. // if (this.canScrollToBottom_()) {
  6124. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6125. // b && this.splice("visibleItems", 0, b);
  6126. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6127. // this.preinsertHeight_ = this.items.clientHeight;
  6128. // this.activeItems_.unshift("visibleItems");
  6129. // try {
  6130. // this.push.apply(this, this.activeItems_)
  6131. // } catch (c) {
  6132. // fm(c)
  6133. // }
  6134. // this.activeItems_ = [];
  6135. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && Mw(function() {
  6136. // a.showNewItems_()
  6137. // }) : Mw(function() {
  6138. // a.refreshOffsetContainerHeight_();
  6139. // a.maybeScrollToBottom_()
  6140. // })
  6141. // } else
  6142. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay)
  6143. // }
  6144. // ;
  6145.  
  6146. } else if (sfi === '0.150.84') {
  6147. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6148. // var b = Math.max(this.visibleItems.length + this.activeItems_.length - this.data.maxItemsToDisplay, 0);
  6149. // b && this.splice("visibleItems", 0, b);
  6150. // if (this.isSmoothScrollEnabled_() || this.dockableMessages.length)
  6151. // this.preinsertHeight_ = this.items.clientHeight;
  6152. // this.activeItems_.unshift("visibleItems");
  6153. // try {
  6154. // this.push.apply(this, this.activeItems_)
  6155. // } catch (c) {
  6156. // nm(c)
  6157. // }
  6158. // this.activeItems_ = [];
  6159. // this.isSmoothScrollEnabled_() ? this.canScrollToBottom_() && zQ(function() {
  6160. // a.showNewItems_()
  6161. // }) : zQ(function() {
  6162. // a.maybeScrollToBottom_()
  6163. // })
  6164. } else if (sfi === '0.137.81' || sfi === '0.138.81') {
  6165. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  6166. } else {
  6167. assertor(() => fnIntegrity(mclp.flushActiveItems_, '0.158.86'))
  6168. || logFn('mclp.flushActiveItems_', mclp.flushActiveItems_)();
  6169. }
  6170. }
  6171.  
  6172. let hasMoreMessageState = !ENABLE_SHOW_MORE_BLINKER ? -1 : 0;
  6173.  
  6174. mclp.flushActiveItems66_ = mclp.flushActiveItems_;
  6175.  
  6176.  
  6177. const preloadFn = (acItems) => {
  6178. let waitFor = [];
  6179. /** @type {Set<string>} */
  6180. const imageLinks = new Set();
  6181.  
  6182. if (ENABLE_PRELOAD_THUMBNAIL || EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL) {
  6183. for (const item of acItems) {
  6184. fixLiveChatItem(item, imageLinks);
  6185. }
  6186. }
  6187. if (ENABLE_PRELOAD_THUMBNAIL && kptPF !== null && (kptPF & (8 | 4)) && imageLinks.size > 0) {
  6188.  
  6189. // reference: https://github.com/Yuanfang-fe/Blog-X/issues/34
  6190. const rel = kptPF & 8 ? 'subresource' : kptPF & 16 ? 'preload' : kptPF & 4 ? 'prefetch' : '';
  6191. // preload performs the high priority fetching.
  6192. // prefetch delays the chat display if the video resoruce is demanding.
  6193.  
  6194. if (rel) {
  6195.  
  6196. imageLinks.forEach(imageLink => {
  6197. let d = false;
  6198. if (SKIP_PRELOAD_EMOJI && imageLink.includes('.ggpht.com/')) return;
  6199. const isEmoji = imageLink.includes('/emoji/');
  6200. const pretechedSet = isEmoji ? emojiPrefetched : authorPhotoPrefetched;
  6201. if (!pretechedSet.has(imageLink)) {
  6202. pretechedSet.add(imageLink);
  6203. d = true;
  6204. }
  6205. if (d) {
  6206. waitFor.push(linker(null, rel, imageLink, 'image'));
  6207.  
  6208. }
  6209. })
  6210.  
  6211. }
  6212.  
  6213. }
  6214.  
  6215. return async () => {
  6216. if (waitFor.length > 0) {
  6217. await Promise.race([new Promise(r => setTimeout(r, 250)), Promise.all(waitFor)]);
  6218. }
  6219. waitFor.length = 0;
  6220. waitFor = null;
  6221. };
  6222.  
  6223. };
  6224.  
  6225. mclp.flushActiveItems78_ = async function (tid) {
  6226. try {
  6227.  
  6228. if (tid !== mlf) return;
  6229. if ((this._flag0281_ & 0x4) == 0x4) {
  6230. const cnt = this;
  6231.  
  6232. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6233. const acItems = cnt.activeItems_;
  6234. if (!acItems || acItems.length === 0) return;
  6235.  
  6236. mlf++;
  6237. if (mlg > 1e9) mlg = 9;
  6238. ++mlg;
  6239. if (acItems.length < MAX_ITEMS_FOR_FULL_FLUSH) {
  6240. const pn = preloadFn(acItems);
  6241. await pn();
  6242. }
  6243. cnt.flushActiveItems66_();
  6244.  
  6245. return 1;
  6246.  
  6247. }
  6248. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  6249. let logger = false;
  6250. const cnt = this;
  6251. let immd = cnt.__intermediate_delay__;
  6252. await iAFP(this.hostElement).then();
  6253. // await new Promise(requestAnimationFrame);
  6254.  
  6255. if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6256. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return;
  6257.  
  6258. mlf++;
  6259. if (mlg > 1e9) mlg = 9;
  6260. ++mlg;
  6261.  
  6262. const tmpMaxItemsCount = this.data.maxItemsToDisplay;
  6263. const reducedMaxItemsToDisplay = MAX_ITEMS_FOR_FULL_FLUSH;
  6264. let changeMaxItemsToDisplay = false;
  6265. const activeItemsLen = this.activeItems_.length;
  6266. if (activeItemsLen > tmpMaxItemsCount && tmpMaxItemsCount > 0) {
  6267. logger = true;
  6268.  
  6269. groupCollapsed("YouTube Super Fast Chat", " | flushActiveItems78_");
  6270.  
  6271. logger && console.log('[Begin]')
  6272.  
  6273. console.log('this.activeItems_.length > N', activeItemsLen, tmpMaxItemsCount);
  6274. if (ENABLE_REDUCED_MAXITEMS_FOR_FLUSH && lockedMaxItemsToDisplay === tmpMaxItemsCount && lockedMaxItemsToDisplay !== reducedMaxItemsToDisplay) {
  6275. console.log('reduce maxitems');
  6276. if (tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  6277. // as all the rendered chats are already "outdated"
  6278. // all old chats shall remove and reduced number of few chats will be rendered
  6279. // then restore to the original number
  6280. changeMaxItemsToDisplay = true;
  6281. this.data.maxItemsToDisplay = reducedMaxItemsToDisplay;
  6282. console.log(`'maxItemsToDisplay' is reduced from ${tmpMaxItemsCount} to ${reducedMaxItemsToDisplay}.`)
  6283. }
  6284. this.activeItems_.splice(0, activeItemsLen - this.data.maxItemsToDisplay);
  6285. // console.log('changeMaxItemsToDisplay 01', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  6286.  
  6287. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  6288. } else {
  6289. this.activeItems_.splice(0, activeItemsLen - (tmpMaxItemsCount < 900 ? tmpMaxItemsCount : 900));
  6290.  
  6291. console.log('new this.activeItems_.length > N', this.activeItems_.length);
  6292. }
  6293. }
  6294. // it is found that it will render all stacked chats after switching back from background
  6295. // to avoid lagging in popular livestream with massive chats, trim first before rendering.
  6296. // this.activeItems_.length > this.data.maxItemsToDisplay && this.activeItems_.splice(0, this.activeItems_.length - this.data.maxItemsToDisplay);
  6297.  
  6298. cnt.__intermediate_delay__ = Promise.all([cnt.__intermediate_delay__ || null, immd || null]);
  6299. await Promise.resolve();
  6300. const acItems = cnt.activeItems_;
  6301. const len1 = acItems.length;
  6302. if (!len1) console.warn('cnt.activeItems_.length = 0');
  6303.  
  6304. const pn = preloadFn(acItems);
  6305. const noVisibleItem1 = ((cnt.visibleItems || 0).length || 0) === 0;
  6306. skipDontRender = noVisibleItem1;
  6307. await pn();
  6308. // console.log('ss2', Date.now())
  6309. cnt.flushActiveItems66_();
  6310. const noVisibleItem2 = ((cnt.visibleItems || 0).length || 0) === 0;
  6311. skipDontRender = noVisibleItem2;
  6312. await Promise.resolve();
  6313. if (changeMaxItemsToDisplay && this.data.maxItemsToDisplay === reducedMaxItemsToDisplay && tmpMaxItemsCount > reducedMaxItemsToDisplay) {
  6314. this.data.maxItemsToDisplay = tmpMaxItemsCount;
  6315.  
  6316. logger && console.log(`'maxItemsToDisplay' is restored from ${reducedMaxItemsToDisplay} to ${tmpMaxItemsCount}.`);
  6317. // console.log('changeMaxItemsToDisplay 02', this.data.maxItemsToDisplay, oMaxItemsToDisplay, reducedMaxItemsToDisplay)
  6318. } else if (changeMaxItemsToDisplay) {
  6319.  
  6320. logger && console.log(`'maxItemsToDisplay' cannot be restored`, {
  6321. maxItemsToDisplay: this.data.maxItemsToDisplay,
  6322. reducedMaxItemsToDisplay,
  6323. originalMaxItemsToDisplay: tmpMaxItemsCount
  6324. });
  6325. }
  6326. logger && console.log('[End]');
  6327.  
  6328. logger && console.groupEnd();
  6329.  
  6330. if (noVisibleItem1 && !noVisibleItem2) {
  6331. // fix possible no auto scroll issue.
  6332. !((cnt.__notRequired__ || 0) & 256) && setTimeout(() => cnt.setAtBottom(), 1);
  6333. }
  6334.  
  6335. if (!ENABLE_NO_SMOOTH_TRANSFORM) {
  6336.  
  6337.  
  6338. const ff = () => {
  6339.  
  6340. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6341. // if (tid !== mlf || cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6342. if (!cnt.atBottom && cnt.allowScroll && cnt.hasUserJustInteracted11_ && !cnt.hasUserJustInteracted11_()) {
  6343.  
  6344. if (typeof nextBrowserTick !== 'function') {
  6345. cnt.scrollToBottom_();
  6346. Promise.resolve().then(() => {
  6347. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6348. if (!cnt.canScrollToBottom_()) cnt.scrollToBottom_();
  6349. });
  6350. } else {
  6351. nextBrowserTick(() => {
  6352. if (cnt.isAttached === false || (cnt.hostElement || cnt).isConnected === false) return;
  6353. cnt.scrollToBottom_();
  6354. });
  6355. }
  6356.  
  6357. }
  6358. }
  6359.  
  6360. ff();
  6361.  
  6362.  
  6363. Promise.resolve().then(ff);
  6364.  
  6365. // requestAnimationFrame(ff);
  6366. } else if (true) { // it might not be sticky to bottom when there is a full refresh.
  6367.  
  6368. const knt = cnt;
  6369. if (!scrollChatFn) {
  6370. const cnt = knt;
  6371. const f = () => {
  6372. const itemScroller = cnt.itemScroller;
  6373. if (!itemScroller || itemScroller.isConnected === false || cnt.isAttached === false) return;
  6374. if (!cnt.atBottom) {
  6375. cnt.scrollToBottom_();
  6376. } else if (itemScroller.scrollTop === 0) { // not yet interacted by user; cannot stick to bottom
  6377. itemScroller.scrollTop = itemScroller.scrollHeight;
  6378. }
  6379. };
  6380. if (typeof nextBrowserTick !== 'function') {
  6381. scrollChatFn = () => Promise.resolve().then(f).then(f);
  6382. } else {
  6383. scrollChatFn = () => nextBrowserTick(f);
  6384. }
  6385. }
  6386.  
  6387. scrollChatFn();
  6388. }
  6389.  
  6390. return 1;
  6391.  
  6392.  
  6393. } catch (e) {
  6394. console.warn(e);
  6395. }
  6396. }
  6397.  
  6398. mclp.flushActiveItems77_ = function () {
  6399.  
  6400. return new Promise(resResolve => {
  6401. try {
  6402. const cnt = this;
  6403. if (mlf > 1e9) mlf = 9;
  6404. let tid = ++mlf;
  6405. const hostElement = cnt.hostElement || cnt;
  6406. if (tid !== mlf || cnt.isAttached === false || hostElement.isConnected === false) return resResolve();
  6407. if (!cnt.activeItems_ || cnt.activeItems_.length === 0) return resResolve();
  6408.  
  6409. // 4 times to maxItems to avoid frequent trimming.
  6410. // 1 ... 10 ... 20 ... 30 ... 40 ... 50 ... 60 => 16 ... 20 ... 30 ..... 60 ... => 16
  6411.  
  6412. const lockedMaxItemsToDisplay = this.data.maxItemsToDisplay944;
  6413. this.activeItems_.length > lockedMaxItemsToDisplay * 4 && lockedMaxItemsToDisplay > 4 && this.activeItems_.splice(0, this.activeItems_.length - lockedMaxItemsToDisplay - 1);
  6414. if (cnt.canScrollToBottom_()) {
  6415. cnt.mutexPromiseFA78 = (cnt.mutexPromiseFA78 || Promise.resolve())
  6416. .then(() => cnt.flushActiveItems78_(tid)) // async function
  6417. .then((asyncResult) => {
  6418. resResolve(asyncResult); // either undefined or 1
  6419. resResolve = null;
  6420. }).catch((e) => {
  6421. console.warn(e);
  6422. if (resResolve) resResolve();
  6423. });
  6424. } else {
  6425. resResolve(2);
  6426. resResolve = null;
  6427. }
  6428. } catch (e) {
  6429. console.warn(e);
  6430. if (resResolve) resResolve();
  6431. }
  6432.  
  6433.  
  6434. });
  6435.  
  6436. }
  6437.  
  6438. mclp.flushActiveItems_ = function () {
  6439. const cnt = this;
  6440.  
  6441. if (arguments.length !== 0 || !cnt.activeItems_ || !cnt.canScrollToBottom_) return cnt.flushActiveItems66_.apply(this, arguments);
  6442.  
  6443. if (cnt.activeItems_.length === 0) {
  6444. cnt.__intermediate_delay__ = null;
  6445. return;
  6446. }
  6447.  
  6448. const cntData = ((cnt || 0).data || 0);
  6449. if (cntData.maxItemsToDisplay944 === undefined) {
  6450. cntData.maxItemsToDisplay944 = null;
  6451. if (cntData.maxItemsToDisplay > MAX_ITEMS_FOR_TOTAL_DISPLAY) cntData.maxItemsToDisplay = MAX_ITEMS_FOR_TOTAL_DISPLAY;
  6452. cntData.maxItemsToDisplay944 = cntData.maxItemsToDisplay || null;
  6453. }
  6454.  
  6455. // ignore previous __intermediate_delay__ and create a new one
  6456. cnt.__intermediate_delay__ = new Promise(resolve => {
  6457. cnt.flushActiveItems77_().then(rt => { // either undefined or 1 or 2
  6458. if (rt === 1) {
  6459. resolve(1); // success, scroll to bottom
  6460. if (hasMoreMessageState === 1) {
  6461. hasMoreMessageState = 0;
  6462. const showMore = (cnt.$ || 0)['show-more'];
  6463. if (showMore) {
  6464. showMore.classList.remove('has-new-messages-miuzp');
  6465. }
  6466. }
  6467. }
  6468. else if (rt === 2) {
  6469. resolve(2); // success, trim
  6470. if (hasMoreMessageState === 0) {
  6471. hasMoreMessageState = 1;
  6472. const showMore = cnt.$['show-more'];
  6473. if (showMore) {
  6474. showMore.classList.add('has-new-messages-miuzp');
  6475. }
  6476. }
  6477. }
  6478. else resolve(-1); // skip
  6479. }).catch(e => {
  6480. console.warn(e);
  6481. });
  6482. });
  6483.  
  6484. }
  6485. console.log("flushActiveItems_", "OK");
  6486. } else {
  6487. console.log("flushActiveItems_", "NG");
  6488. }
  6489. }
  6490.  
  6491. if ((_flag0281_ & 0x40) == 0) {
  6492.  
  6493. if (ENABLE_NO_SMOOTH_TRANSFORM && SUPPRESS_refreshOffsetContainerHeight_ && typeof mclp.refreshOffsetContainerHeight_ === 'function' && !mclp.refreshOffsetContainerHeight26_ && mclp.refreshOffsetContainerHeight_.length === 0) {
  6494. assertor(() => fnIntegrity(mclp.refreshOffsetContainerHeight_, '0.31.21'));
  6495. mclp.refreshOffsetContainerHeight26_ = mclp.refreshOffsetContainerHeight_;
  6496. mclp.refreshOffsetContainerHeight_ = function () {
  6497. // var a = this.itemScroller.clientHeight;
  6498. // this.itemOffset.style.height = this.items.clientHeight + "px";
  6499. // this.bottomAlignMessages && (this.itemOffset.style.minHeight = a + "px")
  6500. }
  6501. console.log("refreshOffsetContainerHeight_", "OK");
  6502. } else {
  6503. console.log("refreshOffsetContainerHeight_", "NG");
  6504. }
  6505.  
  6506. }
  6507.  
  6508. if ((_flag0281_ & 0x80) == 0) {
  6509. mclp.delayFlushActiveItemsAfterUserAction11_ = async function () {
  6510. try {
  6511. if (mlg > 1e9) mlg = 9;
  6512. const tid = ++mlg;
  6513. const keepTrialCond = () => this.atBottom && this.allowScroll && (tid === mlg) && this.isAttached === true && this.activeItems_.length >= 1 && (this.hostElement || 0).isConnected === true;
  6514. const runCond = () => this.canScrollToBottom_();
  6515. if (!keepTrialCond()) return;
  6516. if (runCond()) return this.flushActiveItems_() | 1; // avoid return promise
  6517. await new Promise(r => setTimeout(r, 80));
  6518. if (!keepTrialCond()) return;
  6519. if (runCond()) return this.flushActiveItems_() | 1;
  6520. await iAFP(this.hostElement).then();
  6521. // await new Promise(requestAnimationFrame);
  6522. if (runCond()) return this.flushActiveItems_() | 1;
  6523. } catch (e) {
  6524. console.warn(e);
  6525. }
  6526. }
  6527. }
  6528.  
  6529. if ((_flag0281_ & 0x40) == 0 ) {
  6530.  
  6531. if( (mclp.atBottomChanged_ || 0).length === 0) {
  6532. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  6533.  
  6534.  
  6535.  
  6536.  
  6537.  
  6538. const sfi = fnIntegrity(mclp.atBottomChanged_);
  6539.  
  6540. if(sfi === '0.75.37'){
  6541. // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6542.  
  6543.  
  6544. // Dec 2024.
  6545.  
  6546. /**
  6547. *
  6548. *
  6549.  
  6550. f.atBottomChanged_ = function() {
  6551. var a = this;
  6552. this.atBottom ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = Zu(function() {
  6553. R(a.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6554. }, 200)) : (this.hideShowMoreAsync_ && $u(this.hideShowMoreAsync_),
  6555. this.hideShowMoreAsync_ = null,
  6556. R(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6557. }
  6558. *
  6559. */
  6560.  
  6561. } else {
  6562. assertor(() => fnIntegrity(mclp.atBottomChanged_, '0.75.37'));
  6563. }
  6564.  
  6565.  
  6566. const querySelector = HTMLElement.prototype.querySelector;
  6567. const U = (element) => ({
  6568. querySelector: (selector) => querySelector.call(element, selector)
  6569. });
  6570.  
  6571. let qid = 0;
  6572. mclp.__updateButtonVisibility371__ = function (button) {
  6573. Promise.resolve(this).then((cnt) => {
  6574. button.style.visibility = cnt.__buttonVisibility371__;
  6575. });
  6576. }
  6577. const fixButtonOnClick = function (cnt, button) {
  6578. button.addEventListener('click', (evt) => {
  6579. evt.stopImmediatePropagation();
  6580. evt.stopPropagation();
  6581. evt.preventDefault();
  6582. Promise.resolve(cnt).then((cnt) => {
  6583. cnt.scrollToBottom_();
  6584. });
  6585. }, true);
  6586. // button.addEventListener('pointerup', (evt)=>{
  6587. // evt.stopImmediatePropagation();
  6588. // evt.stopPropagation();
  6589. // }, true);
  6590. // button.addEventListener('mouseup', (evt)=>{
  6591. // evt.stopImmediatePropagation();
  6592. // evt.stopPropagation();
  6593. // }, true);
  6594. }
  6595. mclp.atBottomChanged_ = function () {
  6596. let a = this.atBottom;
  6597. const button = (this.$ || 0)['show-more'];
  6598. if (button) {
  6599. // primary execution
  6600. if (a) {
  6601. if (this.__buttonVisibility371__ !== "hidden") {
  6602. this.__buttonVisibility371__ = "hidden";
  6603. if (!this.hideShowMoreAsync_) {
  6604. const tid = ++qid;
  6605. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  6606. if (tid !== qid) {
  6607. return;
  6608. }
  6609. this.__updateButtonVisibility371__(button);
  6610. });
  6611. }
  6612. }
  6613. } else {
  6614. if (this.__buttonVisibility371__ !== "visible") {
  6615. this.__buttonVisibility371__ = "visible";
  6616. if (this.hideShowMoreAsync_) {
  6617. qid++;
  6618. }
  6619. this.hideShowMoreAsync_ = null;
  6620. if (!button.__fix_onclick__) {
  6621. button.__fix_onclick__ = true;
  6622. fixButtonOnClick(this, button);
  6623. }
  6624. this.__updateButtonVisibility371__(button);
  6625. }
  6626. }
  6627. } else {
  6628. // fallback
  6629. let tid = ++qid;
  6630. let b = this;
  6631. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  6632. if (tid !== qid) return;
  6633. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6634. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  6635. this.hideShowMoreAsync_ = null,
  6636. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6637. }
  6638. }
  6639.  
  6640. console.log("atBottomChanged_", "OK");
  6641.  
  6642. } else if ((mclp.atBottomChanged_ || 0).length === 1) {
  6643. // note: if the scrolling is too frequent, the show more visibility might get wrong.
  6644.  
  6645. const sfi = fnIntegrity(mclp.atBottomChanged_);
  6646. if (sfi === '1.73.37') {
  6647. // https://www.youtube.com/s/desktop/e4d15d2c/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6648.  
  6649. /**
  6650. *
  6651. *
  6652. *
  6653.  
  6654. f.atBottomChanged_ = function(a) {
  6655. var b = this;
  6656. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = zQ(function() {
  6657. T(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6658. }, 200)) : (this.hideShowMoreAsync_ && AQ(this.hideShowMoreAsync_),
  6659. this.hideShowMoreAsync_ = null,
  6660. T(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6661. };
  6662.  
  6663. *
  6664. *
  6665. */
  6666.  
  6667.  
  6668. } else if (sfi === '1.75.39') {
  6669. // e.g. https://www.youtube.com/yts/jsbin/live_chat_polymer-vflCyWEBP/live_chat_polymer.js
  6670. } else {
  6671. assertor(() => fnIntegrity(mclp.atBottomChanged_, '1.73.37'));
  6672. }
  6673.  
  6674. const querySelector = HTMLElement.prototype.querySelector;
  6675. const U = (element) => ({
  6676. querySelector: (selector) => querySelector.call(element, selector)
  6677. });
  6678.  
  6679. let qid = 0;
  6680. mclp.__updateButtonVisibility371__ = function (button) {
  6681. Promise.resolve(this).then((cnt) => {
  6682. button.style.visibility = cnt.__buttonVisibility371__;
  6683. });
  6684. }
  6685. const fixButtonOnClick = function (cnt, button) {
  6686. button.addEventListener('click', (evt) => {
  6687. evt.stopImmediatePropagation();
  6688. evt.stopPropagation();
  6689. evt.preventDefault();
  6690. Promise.resolve(cnt).then((cnt) => {
  6691. cnt.scrollToBottom_();
  6692. });
  6693. }, true);
  6694. // button.addEventListener('pointerup', (evt)=>{
  6695. // evt.stopImmediatePropagation();
  6696. // evt.stopPropagation();
  6697. // }, true);
  6698. // button.addEventListener('mouseup', (evt)=>{
  6699. // evt.stopImmediatePropagation();
  6700. // evt.stopPropagation();
  6701. // }, true);
  6702. }
  6703. mclp.atBottomChanged_ = function (a) {
  6704. const button = (this.$ || 0)['show-more'];
  6705. if (button) {
  6706. // primary execution
  6707. if (a) {
  6708. if (this.__buttonVisibility371__ !== "hidden") {
  6709. this.__buttonVisibility371__ = "hidden";
  6710. if (!this.hideShowMoreAsync_) {
  6711. const tid = ++qid;
  6712. this.hideShowMoreAsync_ = foregroundPromiseFn().then(() => {
  6713. if (tid !== qid) {
  6714. return;
  6715. }
  6716. this.__updateButtonVisibility371__(button);
  6717. });
  6718. }
  6719. }
  6720. } else {
  6721. if (this.__buttonVisibility371__ !== "visible") {
  6722. this.__buttonVisibility371__ = "visible";
  6723. if (this.hideShowMoreAsync_) {
  6724. qid++;
  6725. }
  6726. this.hideShowMoreAsync_ = null;
  6727. if (!button.__fix_onclick__) {
  6728. button.__fix_onclick__ = true;
  6729. fixButtonOnClick(this, button);
  6730. }
  6731. this.__updateButtonVisibility371__(button);
  6732. }
  6733. }
  6734. } else {
  6735. // fallback
  6736. let tid = ++qid;
  6737. let b = this;
  6738. a ? this.hideShowMoreAsync_ || (this.hideShowMoreAsync_ = this.async(function () {
  6739. if (tid !== qid) return;
  6740. U(b.hostElement).querySelector("#show-more").style.visibility = "hidden"
  6741. }, 200)) : (this.hideShowMoreAsync_ && this.cancelAsync(this.hideShowMoreAsync_),
  6742. this.hideShowMoreAsync_ = null,
  6743. U(this.hostElement).querySelector("#show-more").style.visibility = "visible")
  6744. }
  6745. }
  6746.  
  6747. console.log("atBottomChanged_", "OK");
  6748. } else {
  6749. console.log("atBottomChanged_", "NG");
  6750. }
  6751. }
  6752.  
  6753.  
  6754. if ((_flag0281_ & 0x2) == 0) {
  6755. if ((mclp.onScrollItems_ || 0).length === 1) {
  6756.  
  6757. assertor(() => fnIntegrity(mclp.onScrollItems_, '1.17.9'));
  6758. mclp.onScrollItems66_ = mclp.onScrollItems_;
  6759. mclp.onScrollItems77_ = async function (evt) {
  6760. if (myw > 1e9) myw = 9;
  6761. let tid = ++myw;
  6762.  
  6763. await iAFP(this.hostElement).then();
  6764. // await new Promise(requestAnimationFrame);
  6765.  
  6766. if (tid !== myw) {
  6767. return;
  6768. }
  6769.  
  6770. const cnt = this;
  6771.  
  6772. await Promise.resolve();
  6773. if (USE_OPTIMIZED_ON_SCROLL_ITEMS) {
  6774. const onScrollItemsBasicOnly_ = !!((cnt.__notRequired__ || 0) & 512);
  6775. await Promise.resolve().then(() => {
  6776. this.ytRendererBehavior.onScroll(evt);
  6777. }).then(() => {
  6778. if (onScrollItemsBasicOnly_) return;
  6779. if (this.canScrollToBottom_()) {
  6780. const hasUserJustInteracted = this.hasUserJustInteracted11_ ? this.hasUserJustInteracted11_() : true;
  6781. if (hasUserJustInteracted) {
  6782. // only when there is an user action
  6783. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6784. return 1;
  6785. }
  6786. } else {
  6787. // no message inserting
  6788. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6789. return 1;
  6790. }
  6791. }).then((r) => {
  6792.  
  6793. if (onScrollItemsBasicOnly_) return;
  6794. if (this.activeItems_.length) {
  6795.  
  6796. if (this.canScrollToBottom_()) {
  6797. this.flushActiveItems_();
  6798. return 1 && r;
  6799. } else if (this.atBottom && this.allowScroll && (this.hasUserJustInteracted11_ && this.hasUserJustInteracted11_())) {
  6800. // delayed due to user action
  6801. this.delayFlushActiveItemsAfterUserAction11_ && this.delayFlushActiveItemsAfterUserAction11_();
  6802. return 0;
  6803. }
  6804. }
  6805. }).then((r) => {
  6806. if (onScrollItemsBasicOnly_) return;
  6807. if (r) {
  6808. // ensure setAtBottom is correctly set
  6809. !((cnt.__notRequired__ || 0) & 256) && this.setAtBottom();
  6810. }
  6811. });
  6812. } else {
  6813. cnt.onScrollItems66_(evt);
  6814. }
  6815.  
  6816. await Promise.resolve();
  6817.  
  6818. }
  6819.  
  6820. mclp.onScrollItems_ = function (evt) {
  6821.  
  6822. const cnt = this;
  6823. cnt.__intermediate_delay__ = new Promise(resolve => {
  6824. cnt.onScrollItems77_(evt).then(() => {
  6825. resolve();
  6826. });
  6827. });
  6828. }
  6829. console.log("onScrollItems_", "OK");
  6830. } else {
  6831. console.log("onScrollItems_", "NG");
  6832. }
  6833. }
  6834.  
  6835. if ((_flag0281_ & 0x2) == 0) {
  6836. if ((mclp.handleLiveChatActions_ || 0).length === 1) {
  6837.  
  6838. const sfi = fnIntegrity(mclp.handleLiveChatActions_);
  6839. // handleLiveChatActions66_
  6840. if(sfi === '1.40.20') {
  6841. // https://www.youtube.com/s/desktop/c01ea7e3/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  6842.  
  6843.  
  6844. // f.handleLiveChatActions_ = function(a) {
  6845. // var b = this;
  6846. // a.length && (a.forEach(this.handleLiveChatAction_, this),
  6847. // this.maybeResizeScrollContainer_(a),
  6848. // this.flushActiveItems_(),
  6849. // $u(function() {
  6850. // b.maybeScrollToBottom_()
  6851. // }))
  6852. // }
  6853.  
  6854. } else if (sfi === '1.39.20') {
  6855. // TBC
  6856. } else if (sfi === '1.31.17') {
  6857. // original
  6858. } else {
  6859. assertor(() => fnIntegrity(mclp.handleLiveChatActions_, '1.40.20'))
  6860. || logFn('mclp.handleLiveChatActions_', mclp.handleLiveChatActions_)();
  6861. }
  6862.  
  6863. mclp.handleLiveChatActions66_ = mclp.handleLiveChatActions_;
  6864.  
  6865. mclp.handleLiveChatActions77_ = async function (arr) {
  6866. if (typeof (arr || 0).length !== 'number') {
  6867. this.handleLiveChatActions66_(arr);
  6868. return;
  6869. }
  6870. if (mzt > 1e9) mzt = 9;
  6871. let tid = ++mzt;
  6872.  
  6873. if (zarr === null) zarr = arr;
  6874. else Array.prototype.push.apply(zarr, arr);
  6875. arr = null;
  6876.  
  6877. await iAFP(this.hostElement).then();
  6878. // await new Promise(requestAnimationFrame);
  6879.  
  6880. if (tid !== mzt || zarr === null) {
  6881. return;
  6882. }
  6883.  
  6884. const carr = zarr;
  6885. zarr = null;
  6886.  
  6887. await Promise.resolve();
  6888. this.handleLiveChatActions66_(carr);
  6889. await Promise.resolve();
  6890.  
  6891. }
  6892.  
  6893. mclp.handleLiveChatActions_ = function (arr) {
  6894.  
  6895.  
  6896. try{
  6897. preprocessChatLiveActions(arr);
  6898. }catch(e){
  6899. console.warn(e);
  6900. }
  6901.  
  6902.  
  6903.  
  6904. // console.log(1929, cnt.activeItems_)
  6905. // console.log(9487, arr);
  6906.  
  6907. const cnt = this;
  6908. cnt.__intermediate_delay__ = new Promise(resolve => {
  6909. cnt.handleLiveChatActions77_(arr).then(() => {
  6910. resolve();
  6911. });
  6912. });
  6913.  
  6914. resistanceUpdateFn_();
  6915. }
  6916. console.log("handleLiveChatActions_", "OK");
  6917. } else {
  6918. console.log("handleLiveChatActions_", "NG");
  6919. }
  6920. }
  6921.  
  6922. mclp.hasUserJustInteracted11_ = () => {
  6923. const t = dateNow();
  6924. return (t - lastWheel < 80) || currentMouseDown || currentTouchDown || (t - lastUserInteraction < 80);
  6925. }
  6926.  
  6927. if ((mclp.canScrollToBottom_ || 0).length === 0) {
  6928.  
  6929. assertor(() => fnIntegrity(mclp.canScrollToBottom_, '0.9.5'));
  6930.  
  6931. mclp.canScrollToBottom_ = function () {
  6932. return this.atBottom && this.allowScroll && !this.hasUserJustInteracted11_();
  6933. }
  6934.  
  6935. console.log("canScrollToBottom_", "OK");
  6936. } else {
  6937. console.log("canScrollToBottom_", "NG");
  6938. }
  6939.  
  6940. if (ENABLE_NO_SMOOTH_TRANSFORM) {
  6941.  
  6942. mclp.isSmoothScrollEnabled_ = function () {
  6943. return false;
  6944. }
  6945.  
  6946. mclp.maybeResizeScrollContainer_ = function () {
  6947. //
  6948. }
  6949.  
  6950. mclp.refreshOffsetContainerHeight_ = function () {
  6951. //
  6952. }
  6953.  
  6954. mclp.smoothScroll_ = function () {
  6955. //
  6956. }
  6957.  
  6958. mclp.resetSmoothScroll_ = function () {
  6959. //
  6960. }
  6961. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "OK");
  6962. } else {
  6963. console.log("ENABLE_NO_SMOOTH_TRANSFORM", "NG");
  6964. }
  6965.  
  6966. if ((_flag0281_ & 0x8) == 0) {
  6967.  
  6968.  
  6969. if (typeof mclp.forEachItem_ === 'function' && !mclp.forEachItem66_ && skipErrorForhandleAddChatItemAction_ && mclp.forEachItem_.length === 1) {
  6970.  
  6971. mclp.forEachItem66_ = mclp.forEachItem_;
  6972. mclp.forEachItem_ = function (a) {
  6973.  
  6974. if ((this._flag0281_ & 0x8) == 0x8) return this.forEachItem66_(a);
  6975.  
  6976. // ƒ (a){this.visibleItems.forEach(a.bind(this,"visibleItems"));this.activeItems_.forEach(a.bind(this,"activeItems_"))}
  6977.  
  6978. try {
  6979.  
  6980. let items801 = false;
  6981. if (typeof a === 'function') {
  6982. const items = this.items;
  6983. if (items instanceof HTMLDivElement) {
  6984. const ev = this.visibleItems;
  6985. const ea = this.activeItems_;
  6986. if (ev && ea && ev.length >= 0 && ea.length >= 0) {
  6987. items801 = items;
  6988. }
  6989. }
  6990. }
  6991.  
  6992. if (items801) {
  6993. items801.__children801__ = 1;
  6994. const res = this.forEachItem66_(a);
  6995. items801.__children801__ = 0;
  6996. return res;
  6997. }
  6998.  
  6999. } catch (e) { }
  7000. return this.forEachItem66_(a);
  7001.  
  7002.  
  7003. // this.visibleItems.forEach((val, idx, arr)=>{
  7004. // a.call(this, 'visibleItems', val, idx, arr);
  7005. // });
  7006.  
  7007. // this.activeItems_.forEach((val, idx, arr)=>{
  7008. // a.call(this, 'activeItems_', val, idx, arr);
  7009. // });
  7010.  
  7011.  
  7012.  
  7013. }
  7014.  
  7015.  
  7016. }
  7017.  
  7018. }
  7019.  
  7020. if (typeof mclp.handleAddChatItemAction_ === 'function' && !mclp.handleAddChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  7021.  
  7022. mclp.handleAddChatItemAction66_ = mclp.handleAddChatItemAction_;
  7023. mclp.handleAddChatItemAction_ = function (a) {
  7024. try {
  7025. if (a && typeof a === 'object' && !('length' in a)) {
  7026. fixLiveChatItem(a.item, null);
  7027. console.assert(arguments[0] === a);
  7028. }
  7029. } catch (e) { console.warn(e) }
  7030. let res;
  7031. if (skipErrorForhandleAddChatItemAction_) { // YouTube Native Engine Issue
  7032. try {
  7033. res = this.handleAddChatItemAction66_.apply(this, arguments);
  7034. } catch (e) {
  7035. if (e && (e.message || '').includes('.querySelector(')) {
  7036. console.log("skipErrorForhandleAddChatItemAction_", e.message);
  7037. } else {
  7038. throw e;
  7039. }
  7040. }
  7041. } else {
  7042. res = this.handleAddChatItemAction66_.apply(this, arguments);
  7043. }
  7044. return res;
  7045. }
  7046.  
  7047. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  7048. } else {
  7049.  
  7050. if (FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION) console.log("handleAddChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_ADDITION ]", "OK");
  7051. }
  7052.  
  7053.  
  7054. if (typeof mclp.handleReplaceChatItemAction_ === 'function' && !mclp.handleReplaceChatItemAction66_ && FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT && (EMOJI_IMAGE_SINGLE_THUMBNAIL || AUTHOR_PHOTO_SINGLE_THUMBNAIL)) {
  7055.  
  7056. mclp.handleReplaceChatItemAction66_ = mclp.handleReplaceChatItemAction_;
  7057. mclp.handleReplaceChatItemAction_ = function (a) {
  7058. try {
  7059. if (a && typeof a === 'object' && !('length' in a)) {
  7060. fixLiveChatItem(a.replacementItem, null);
  7061. console.assert(arguments[0] === a);
  7062. }
  7063. } catch (e) { console.warn(e) }
  7064. return this.handleReplaceChatItemAction66_.apply(this, arguments);
  7065. }
  7066.  
  7067. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  7068. } else {
  7069.  
  7070. if (FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT) console.log("handleReplaceChatItemAction_ [ FIX_THUMBNAIL_SIZE_ON_ITEM_REPLACEMENT ]", "OK");
  7071. }
  7072.  
  7073. console.log("[End]");
  7074. console.groupEnd();
  7075.  
  7076. }).catch(console.warn);
  7077.  
  7078.  
  7079. const tickerContainerSetAttribute = function (attrName, attrValue) { // ensure '14.30000001%'.toFixed(1)
  7080.  
  7081. let yd = (this.__dataHost || insp(this).__dataHost || 0).__data;
  7082.  
  7083. if (arguments.length === 2 && attrName === 'style' && yd && attrValue) {
  7084.  
  7085. // let v = yd.containerStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
  7086. let v = `${attrValue}`;
  7087. // conside a ticker is 101px width
  7088. // 1% = 1.01px
  7089. // 0.2% = 0.202px
  7090.  
  7091.  
  7092. const ratio1 = (yd.ratio * 100);
  7093. if (ratio1 > -1) { // avoid NaN
  7094.  
  7095. // countdownDurationMs
  7096. // 600000 - 0.2% <1% = 6s> <0.2% = 1.2s>
  7097. // 300000 - 0.5% <1% = 3s> <0.5% = 1.5s>
  7098. // 150000 - 1% <1% = 1.5s>
  7099. // 75000 - 2% <1% =0.75s > <2% = 1.5s>
  7100. // 30000 - 5% <1% =0.3s > <5% = 1.5s>
  7101.  
  7102. // 99px * 5% = 4.95px
  7103.  
  7104. // 15000 - 10% <1% =0.15s > <10% = 1.5s>
  7105.  
  7106.  
  7107. // 1% Duration
  7108.  
  7109. let ratio2 = ratio1;
  7110.  
  7111. const ydd = yd.data;
  7112. if (ydd) {
  7113.  
  7114. const d1 = ydd.durationSec;
  7115. const d2 = ydd.fullDurationSec;
  7116.  
  7117. // @ step timing [min. 0.2%]
  7118. let numOfSteps = 500;
  7119. if ((d1 === d2 || (d1 + 1 === d2)) && d1 > 1) {
  7120. if (d2 > 400) numOfSteps = 500; // 0.2%
  7121. else if (d2 > 200) numOfSteps = 200; // 0.5%
  7122. else if (d2 > 100) numOfSteps = 100; // 1%
  7123. else if (d2 > 50) numOfSteps = 50; // 2%
  7124. else if (d2 > 25) numOfSteps = 20; // 5% (max => 99px * 5% = 4.95px)
  7125. else numOfSteps = 20;
  7126. }
  7127. if (numOfSteps > TICKER_MAX_STEPS_LIMIT) numOfSteps = TICKER_MAX_STEPS_LIMIT;
  7128. if (numOfSteps < 5) numOfSteps = 5;
  7129.  
  7130. const rd = numOfSteps / 100.0;
  7131.  
  7132. ratio2 = Math.round(ratio2 * rd) / rd;
  7133.  
  7134. // ratio2 = Math.round(ratio2 * 5) / 5;
  7135. ratio2 = ratio2.toFixed(1);
  7136. v = v.replace(`${ratio1}%`, `${ratio2}%`).replace(`${ratio1}%`, `${ratio2}%`);
  7137.  
  7138. if (yd.__style_last__ === v) return;
  7139. yd.__style_last__ = v;
  7140. // do not consider any delay here.
  7141. // it shall be inside the looping for all properties changes. all the css background ops are in the same microtask.
  7142.  
  7143. }
  7144. }
  7145.  
  7146. HTMLElement.prototype.setAttribute.call(dr(this), attrName, v);
  7147.  
  7148.  
  7149. } else {
  7150. HTMLElement.prototype.setAttribute.apply(dr(this), arguments);
  7151. }
  7152.  
  7153. };
  7154.  
  7155.  
  7156. const fpTicker = (renderer) => {
  7157. if (FLAG_001a) return;
  7158. const cnt = insp(renderer);
  7159. assertor(() => typeof (cnt || 0).is === 'string');
  7160. assertor(() => ((cnt || 0).hostElement || 0).nodeType === 1);
  7161. const container = (cnt.$ || 0).container;
  7162. if (container) {
  7163. assertor(() => (container || 0).nodeType === 1);
  7164. assertor(() => typeof container.setAttribute === 'function');
  7165. container.setAttribute = tickerContainerSetAttribute;
  7166. } else {
  7167. console.warn(`"container" does not exist in ${cnt.is}`);
  7168. }
  7169. };
  7170.  
  7171.  
  7172. const tags = [
  7173. "yt-live-chat-ticker-renderer",
  7174. "yt-live-chat-ticker-paid-message-item-renderer",
  7175. "yt-live-chat-ticker-paid-sticker-item-renderer",
  7176. "yt-live-chat-ticker-sponsor-item-renderer"
  7177. ];
  7178.  
  7179. const tagsItemRenderer = [
  7180. "yt-live-chat-ticker-renderer",
  7181. "yt-live-chat-ticker-paid-message-item-renderer",
  7182. "yt-live-chat-ticker-paid-sticker-item-renderer",
  7183. "yt-live-chat-ticker-sponsor-item-renderer"
  7184. ];
  7185.  
  7186. const wmList = new Set;
  7187. if (DEBUG_wmList) {
  7188.  
  7189. setInterval(() => {
  7190. let q = document.querySelector('#label-text');
  7191. if(!q) return;
  7192. const size = new Set([...wmList].filter(e => e?.deref()?.isConnected === false).map(e => e?.deref())).size;
  7193. q.textContent = `${48833}, ${DEBUG_wmList_started}, ${size}`;
  7194.  
  7195. // console.log(48833, )
  7196. }, 100);
  7197. }
  7198.  
  7199.  
  7200. /*
  7201. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  7202.  
  7203.  
  7204. const dProto = {
  7205.  
  7206. detachedForTickerInit: function () {
  7207.  
  7208. try {
  7209.  
  7210. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  7211.  
  7212. // this.behaviorActionMap = 0;
  7213. // this.isVisibilityRoot = 0;
  7214.  
  7215.  
  7216. } catch (e) { }
  7217.  
  7218.  
  7219. return this.detached582MemoryLeak();
  7220. },
  7221.  
  7222. attachedForTickerInit: function () {
  7223. wmList.add(new WeakRef(this))
  7224.  
  7225. // fpTicker(this.hostElement || this);
  7226. return this.attached77();
  7227.  
  7228. },
  7229.  
  7230.  
  7231. }
  7232.  
  7233.  
  7234. for (const tag of tagsItemRenderer) { // ##tag##
  7235. const dummy = document.createElement(tag);
  7236.  
  7237. const cProto = getProto(dummy);
  7238. if (!cProto || !cProto.attached) {
  7239. console.warn(`proto.attached for ${tag} is unavailable.`);
  7240. continue;
  7241. }
  7242.  
  7243. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  7244. cProto.detached582MemoryLeak = cProto.detached;
  7245. cProto.detached = cProto.detachedForTickerInit;
  7246. }
  7247.  
  7248. cProto.attached77 = cProto.attached;
  7249.  
  7250. cProto.attached = dProto.attachedForTickerInit;
  7251.  
  7252.  
  7253. }
  7254.  
  7255. });
  7256. */
  7257.  
  7258.  
  7259.  
  7260. Promise.all(tags.map(tag => customElements.whenDefined(tag))).then(() => {
  7261.  
  7262. if (FLAG_001b) return;
  7263. mightFirstCheckOnYtInit();
  7264. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-... hacks");
  7265. console.log("[Begin]");
  7266.  
  7267.  
  7268. let tickerAttachmentId = 0;
  7269.  
  7270.  
  7271. const __requestRemoval__ = function (cnt) {
  7272. if (cnt.hostElement && typeof cnt.requestRemoval === 'function') {
  7273. try {
  7274. const id = (cnt.data || 0).id;
  7275. if (!id) cnt.data = { id: 1 };
  7276. } catch (e) { }
  7277. try {
  7278. cnt.requestRemoval();
  7279. return true;
  7280. } catch (e) { }
  7281. }
  7282. return false;
  7283. }
  7284.  
  7285. const widthIORes = new WeakMap();
  7286. const widthIO = new IntersectionObserver((mutations) => {
  7287. for (const mutation of mutations) {
  7288. const elm = mutation.target;
  7289. widthIO.unobserve(elm);
  7290. const {promise, values} =widthIORes.get(elm) || {};
  7291. if(promise && values){
  7292.  
  7293.  
  7294. widthIORes.delete(elm);
  7295. values.width= mutation.boundingClientRect.width;
  7296. promise.resolve(values);
  7297. }
  7298. }
  7299. });
  7300. const widthReq = (elm)=>{
  7301.  
  7302. {
  7303.  
  7304. const {promise, values} =widthIORes.get(elm) || {};
  7305. if(promise) return promise;
  7306. }
  7307.  
  7308. const promise = new PromiseExternal();
  7309. widthIORes.set(elm, {promise, values: {}});
  7310. widthIO.unobserve(elm);
  7311. widthIO.observe(elm);
  7312.  
  7313. return promise;
  7314.  
  7315. }
  7316.  
  7317.  
  7318.  
  7319. const dProto = {
  7320.  
  7321.  
  7322. /**
  7323. *
  7324.  
  7325. f.updateStatsBarAndMaybeShowAnimation = function(a, b, c) {
  7326. var d = this;
  7327. a || c();
  7328. a && this.statsBar && this.username && this.textContent && (this.isMouseOver ? (b(),
  7329. c()) : (a = this.animateShowStats(),
  7330. this.data.animationOrigin && this.data.trackingParams && aB().stateChanged(this.data.trackingParams, {
  7331. animationEventData: {
  7332. origin: this.data.animationOrigin
  7333. }
  7334. }),
  7335. a.finished.then(function() {
  7336. var e;
  7337. setTimeout(function() {
  7338. b();
  7339. c();
  7340. if (!d.isMouseOver) {
  7341. var g, k;
  7342. d.animateHideStats(((g = d.data) == null ? void 0 : g.dynamicStateData.stateSlideDurationMs) || 0, ((k = d.data) == null ? void 0 : k.dynamicStateData.stateUpdateDelayAfterMs) || 0)
  7343. }
  7344. }, ((e = d.data) == null ? void 0 : e.dynamicStateData.stateUpdateDelayBeforeMs) || 0)
  7345. })))
  7346. }
  7347.  
  7348. *
  7349. */
  7350.  
  7351.  
  7352.  
  7353. /**
  7354. *
  7355. *
  7356.  
  7357. f.animateShowStats = function() {
  7358. var a = this.textContent.animate({
  7359. transform: "translateY(-30px)"
  7360. }, {
  7361. duration: this.data.dynamicStateData.stateSlideDurationMs,
  7362. fill: "forwards"
  7363. });
  7364. this.username.animate({
  7365. opacity: 0
  7366. }, {
  7367. duration: 500,
  7368. fill: "forwards"
  7369. });
  7370. this.statsBar.animate({
  7371. opacity: 1
  7372. }, {
  7373. duration: 500,
  7374. fill: "forwards"
  7375. });
  7376. return a
  7377. }
  7378. ;
  7379. f.animateHideStats = function(a, b) {
  7380. this.textContent.animate({
  7381. transform: "translateY(0)"
  7382. }, {
  7383. duration: a,
  7384. fill: "forwards",
  7385. delay: b
  7386. });
  7387. this.username.animate({
  7388. opacity: 1
  7389. }, {
  7390. duration: 300,
  7391. fill: "forwards",
  7392. delay: b
  7393. });
  7394. this.statsBar.animate({
  7395. opacity: 0
  7396. }, {
  7397. duration: 300,
  7398. fill: "forwards",
  7399. delay: b
  7400. })
  7401. }
  7402. *
  7403. */
  7404.  
  7405. updateStatsBarAndMaybeShowAnimationRevised: function (a, b, c) {
  7406. // prevent memory leakage due to d.data was asked in a.finished.then
  7407. try{
  7408. // console.log('updateStatsBarAndMaybeShowAnimation called', this.is)
  7409. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7410. return this.updateStatsBarAndMaybeShowAnimation38.call(this.__proxySelf0__, a, b, c);
  7411. }catch(e){
  7412. console.log('updateStatsBarAndMaybeShowAnimationRevised ERROR');
  7413. console.error(e);
  7414. }
  7415. },
  7416.  
  7417. detachedForMemoryLeakage: function () {
  7418.  
  7419. try{
  7420.  
  7421. this.actionHandlerBehavior.unregisterActionMap(this.behaviorActionMap)
  7422.  
  7423. // this.behaviorActionMap = 0;
  7424. // this.isVisibilityRoot = 0;
  7425.  
  7426.  
  7427. }catch(e){}
  7428.  
  7429. return this.detached582MemoryLeak();
  7430. },
  7431.  
  7432. detachedForTickerInit: function () {
  7433.  
  7434. Promise.resolve(this).then((cnt) => {
  7435. if (cnt.isAttached) return;
  7436. cnt.isAttached === false && ((cnt.$ || 0).container || 0).isConnected === false && __requestRemoval__(cnt);
  7437. cnt.rafId > 1 && rafHub.cancel(cnt.rafId);
  7438. }).catch(console.warn);
  7439.  
  7440. let r;
  7441. try {
  7442. r = this.detached77();
  7443. } catch (e) {
  7444. console.warn(e);
  7445. }
  7446. this.__ticker_attachmentId__ = 0;
  7447. return r;
  7448. },
  7449.  
  7450. attachedForTickerInit: function () {
  7451. if (tickerAttachmentId > 1e9) tickerAttachmentId = 9;
  7452. this.__ticker_attachmentId__ = ++tickerAttachmentId;
  7453.  
  7454. const hostElement = this.hostElement;
  7455. if (USE_ADVANCED_TICKING && this.__isTickerItem58__ && hostElement instanceof HTMLElement) {
  7456. const prevElement = kRef(qWidthAdjustable);
  7457. if (prevElement instanceof HTMLElement) {
  7458. prevElement.classList.add('r6-width-adjustable-f');
  7459. }
  7460. if (hostElement.__fgvm573__) {
  7461. hostElement.classList.remove('r6-closing-ticker');
  7462. hostElement.classList.remove('r6-width-adjustable-f');
  7463. } else {
  7464. hostElement.__fgvm573__ = 1;
  7465. hostElement.classList.add('r6-width-adjustable');
  7466. }
  7467. qWidthAdjustable = mWeakRef(hostElement);
  7468. }
  7469.  
  7470. DEBUG_wmList && wmList.add(new WeakRef(this))
  7471. if (DEBUG_wmList && !DEBUG_wmList_started) {
  7472. console.log('!!!!!!!!!!!!! DEBUG_wmList_started !!!!!!!!!')
  7473. DEBUG_wmList_started = 1;
  7474. }
  7475.  
  7476. fpTicker(hostElement || this);
  7477. return this.attached77();
  7478.  
  7479. },
  7480.  
  7481.  
  7482.  
  7483. setContainerWidthNoSelfLeakage: function(){
  7484. // prevent memory leakage due ot delay function
  7485. try{
  7486. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7487. return this.setContainerWidth55.call(this.__proxySelf0__);
  7488. }catch(e){
  7489. console.log('setContainerWidthNoSelfLeakage ERROR');
  7490. console.error(e);
  7491. }
  7492.  
  7493. },
  7494.  
  7495. slideDownNoSelfLeakage: function(){
  7496. // prevent memory leakage due ot delay function
  7497. try{
  7498. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7499. return this.slideDown55.call(this.__proxySelf0__);
  7500. }catch(e){
  7501. console.log('slideDownNoSelfLeakage ERROR');
  7502. console.error(e);
  7503. }
  7504.  
  7505. },
  7506.  
  7507. collapseNoSelfLeakage: function(){
  7508. // prevent memory leakage due ot delay function
  7509. try{
  7510. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7511. return this.collapse55.call(this.__proxySelf0__);
  7512. }catch(e){
  7513. console.log('collapseNoSelfLeakage ERROR');
  7514. console.error(e);
  7515. }
  7516. },
  7517.  
  7518. deletedChangedNoSelfLeakage: function(){
  7519. // prevent memory leakage due ot delay function
  7520. try{
  7521. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  7522. return this.deletedChanged55.call(this.__proxySelf0__);
  7523. }catch(e){
  7524. console.log('deletedChangedNoSelfLeakage ERROR');
  7525. console.error(e);
  7526. }
  7527.  
  7528. },
  7529.  
  7530.  
  7531.  
  7532.  
  7533. /** @type {()} */
  7534. handlePauseReplayForPlaybackProgressState: function () {
  7535. if (!playerEventsByIframeRelay) return this.handlePauseReplay66.apply(this, arguments);
  7536.  
  7537. const attachementId = this.__ticker_attachmentId__;
  7538. if(!attachementId) return;
  7539.  
  7540. const jr = mWeakRef(this);
  7541.  
  7542. if (onPlayStateChangePromise) {
  7543.  
  7544. if (this.rtu > 1e9) this.rtu = this.rtu % 1e4;
  7545. const tid = ++this.rtu;
  7546.  
  7547. onPlayStateChangePromise.then(() => {
  7548. const cnt = kRef(jr);
  7549. if(attachementId !== cnt.__ticker_attachmentId__) return;
  7550. if (cnt.isAttached) {
  7551. if (tid === cnt.rtu && !onPlayStateChangePromise && typeof cnt.handlePauseReplay === 'function' && cnt.hostElement) cnt.handlePauseReplay.apply(cnt, arguments);
  7552. // this.handlePauseReplay can be undefined if it is memory cleaned
  7553. }
  7554. });
  7555.  
  7556. return;
  7557. }
  7558.  
  7559. if (playerState !== 2) return;
  7560. if (this.isAttached) {
  7561. if (this.rtk > 1e9) this.rtk = this.rtk % 1e4;
  7562. const tid = ++this.rtk;
  7563. const tc = relayCount;
  7564.  
  7565. foregroundPromiseFn().then(() => {
  7566. const cnt = kRef(jr);
  7567. if (attachementId !== cnt.__ticker_attachmentId__) return;
  7568. if (cnt.isAttached) {
  7569. if (tid === cnt.rtk && tc === relayCount && playerState === 2 && _playerState === playerState && cnt.hostElement) {
  7570. cnt.handlePauseReplay66();
  7571. }
  7572. }
  7573.  
  7574. })
  7575. }
  7576. },
  7577.  
  7578. /** @type {()} */
  7579. handleResumeReplayForPlaybackProgressState: function () {
  7580. if (!playerEventsByIframeRelay) return this.handleResumeReplay66.apply(this, arguments);
  7581.  
  7582. const attachementId = this.__ticker_attachmentId__;
  7583. if(!attachementId) return;
  7584.  
  7585. const jr = mWeakRef(this);
  7586. if (onPlayStateChangePromise) {
  7587.  
  7588. if (this.rtv > 1e9) this.rtv = this.rtv % 1e4;
  7589. const tid = ++this.rtv;
  7590.  
  7591. onPlayStateChangePromise.then(() => {
  7592. const cnt = kRef(jr);
  7593. if(attachementId !== cnt.__ticker_attachmentId__) return;
  7594. if (tid === cnt.rtv && !onPlayStateChangePromise && typeof cnt.handleResumeReplay === 'function' && cnt.hostElement) cnt.handleResumeReplay.apply(cnt, arguments);
  7595. // this.handleResumeReplay can be undefined if it is memory cleaned
  7596. });
  7597.  
  7598. return;
  7599. }
  7600.  
  7601.  
  7602. if (playerState !== 1) return;
  7603. if (this.isAttached) {
  7604. const tc = relayCount;
  7605.  
  7606. relayPromise = relayPromise || new PromiseExternal();
  7607. relayPromise.then(() => {
  7608. const cnt = kRef(jr);
  7609. if(attachementId !== cnt.__ticker_attachmentId__) return;
  7610. if (relayCount > tc && playerState === 1 && _playerState === playerState && cnt.hostElement) {
  7611. cnt.handleResumeReplay66();
  7612. }
  7613. });
  7614. }
  7615. },
  7616.  
  7617. /** @type {(a,)} */
  7618. handleReplayProgressForPlaybackProgressState: function (a) {
  7619. if (this.isAttached) {
  7620. const attachementId = this.__ticker_attachmentId__;
  7621. if(!attachementId) return;
  7622. const tid = ++this.rtk;
  7623. const jr = mWeakRef(kRef(this));
  7624. foregroundPromiseFn().then(() => {
  7625. const cnt = kRef(jr);
  7626. if(attachementId !== cnt.__ticker_attachmentId__) return;
  7627. if (cnt.isAttached) {
  7628. if (tid === cnt.rtk && cnt.hostElement) {
  7629. cnt.handleReplayProgress66(a);
  7630. }
  7631. }
  7632. })
  7633. }
  7634. }
  7635.  
  7636.  
  7637. }
  7638.  
  7639.  
  7640. let tagI = 0;
  7641. for (const tag of tagsItemRenderer) { // ##tag##
  7642.  
  7643. tagI++;
  7644.  
  7645. const dummy = document.createElement(tag);
  7646.  
  7647. const cProto = getProto(dummy);
  7648. if (!cProto || !cProto.attached) {
  7649. console.warn(`proto.attached for ${tag} is unavailable.`);
  7650. continue;
  7651. }
  7652.  
  7653. if (FIX_MEMORY_LEAKAGE_TICKER_ACTIONMAP && typeof cProto.detached582MemoryLeak !== 'function' && typeof cProto.detached === 'function') {
  7654. cProto.detached582MemoryLeak = cProto.detached;
  7655. cProto.detached = dProto.detachedForMemoryLeakage;
  7656. }
  7657.  
  7658. cProto.detached77 = cProto.detached;
  7659. cProto.detached = dProto.detachedForTickerInit;
  7660.  
  7661. cProto.attached77 = cProto.attached;
  7662.  
  7663. cProto.attached = dProto.attachedForTickerInit;
  7664.  
  7665. if (FLAG_001c) continue;
  7666.  
  7667. let flgLeakageFixApplied = 0;
  7668.  
  7669. if (FIX_MEMORY_LEAKAGE_TICKER_STATSBAR && typeof cProto.updateStatsBarAndMaybeShowAnimation === 'function' && !cProto.updateStatsBarAndMaybeShowAnimation38 && cProto.updateStatsBarAndMaybeShowAnimation.length === 3) {
  7670.  
  7671. cProto.updateStatsBarAndMaybeShowAnimation38 = cProto.updateStatsBarAndMaybeShowAnimation;
  7672. cProto.updateStatsBarAndMaybeShowAnimation = dProto.updateStatsBarAndMaybeShowAnimationRevised;
  7673.  
  7674. flgLeakageFixApplied |= 2;
  7675. } else {
  7676. // the function is only in yt-live-chat-ticker-paid-message-item-renderer
  7677. }
  7678.  
  7679.  
  7680. // ------------- withTimerFn_ -------------
  7681.  
  7682. let withTimerFn_ = 0;
  7683. if (typeof cProto.startCountdown === 'function' && typeof cProto.updateTimeout === 'function' && typeof cProto.isAnimationPausedChanged === 'function') {
  7684.  
  7685. // console.log('startCountdown', typeof cProto.startCountdown)
  7686. // console.log('updateTimeout', typeof cProto.updateTimeout)
  7687. // console.log('isAnimationPausedChanged', typeof cProto.isAnimationPausedChanged)
  7688.  
  7689. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  7690. const isTimingFunctionHackable = fnIntegrity(cProto.startCountdown, '2.66.37') && fnIntegrity(cProto.updateTimeout, '1.76.45') && fnIntegrity(cProto.isAnimationPausedChanged, '2.56.30')
  7691. if (!isTimingFunctionHackable) console.log('isTimingFunctionHackable = false');
  7692. withTimerFn_ = isTimingFunctionHackable ? 2 : 1;
  7693. } else {
  7694. let flag = 0;
  7695. if (typeof cProto.startCountdown === 'function') flag |= 1;
  7696. if (typeof cProto.updateTimeout === 'function') flag |= 2;
  7697. if (typeof cProto.isAnimationPausedChanged === 'function') flag |= 4;
  7698.  
  7699. console.log(`Skip Timing Function Modification: ${flag} / ${1 + 2 + 4}`, ` ${tag}`);
  7700. // console.log(Object.getOwnPropertyNames(cProto))
  7701. // continue;
  7702. }
  7703.  
  7704. // ------------- withTimerFn_ -------------
  7705.  
  7706. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7707.  
  7708. let urt = 0;
  7709.  
  7710. if (ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX) {
  7711.  
  7712.  
  7713. /**
  7714. *
  7715. f.handlePauseReplay = function() {
  7716. this.isAnimationPaused = !0;
  7717. this.detlaSincePausedSecs = 0
  7718. }
  7719. */
  7720.  
  7721. /**
  7722. *
  7723.  
  7724. f.handlePauseReplay = function() {
  7725. this.isReplayPaused = !0
  7726. }
  7727. *
  7728. */
  7729.  
  7730. if (typeof cProto.handlePauseReplay === 'function' && !cProto.handlePauseReplay66 && cProto.handlePauseReplay.length === 0) {
  7731. const fi = fnIntegrity(cProto.handlePauseReplay);
  7732. urt++;
  7733. if (fi === '0.8.2' || fi === '0.12.4') {
  7734. } else {
  7735. assertor(() => fnIntegrity(cProto.handlePauseReplay, '0.12.4'));
  7736. }
  7737. } else {
  7738. if (withTimerFn_ > 0) console.log('Error for setting cProto.handlePauseReplay', tag)
  7739. }
  7740.  
  7741. if (typeof cProto.handleResumeReplay === 'function' && !cProto.handleResumeReplay66 && cProto.handleResumeReplay.length === 0) {
  7742. urt++;
  7743. assertor(() => fnIntegrity(cProto.handleResumeReplay, '0.8.2'));
  7744. } else {
  7745. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleResumeReplay', tag)
  7746. }
  7747.  
  7748. if (typeof cProto.handleReplayProgress === 'function' && !cProto.handleReplayProgress66 && cProto.handleReplayProgress.length === 1) {
  7749. urt++;
  7750. assertor(() => fnIntegrity(cProto.handleReplayProgress, '1.16.13'));
  7751. } else {
  7752. if (withTimerFn_ > 0) console.log('Error for setting cProto.handleReplayProgress', tag)
  7753. }
  7754.  
  7755.  
  7756.  
  7757. }
  7758.  
  7759. 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);
  7760. cProto.__ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED__ = ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED;
  7761.  
  7762. if (ENABLE_VIDEO_PROGRESS_STATE_FIX_AND_URT_PASSED) {
  7763.  
  7764. cProto.rtk = 0;
  7765. cProto.rtu = 0;
  7766. cProto.rtv = 0;
  7767.  
  7768. cProto.handlePauseReplay66 = cProto.handlePauseReplay;
  7769. cProto.handlePauseReplay = dProto.handlePauseReplayForPlaybackProgressState;
  7770.  
  7771. cProto.handleResumeReplay66 = cProto.handleResumeReplay;
  7772. cProto.handleResumeReplay = dProto.handleResumeReplayForPlaybackProgressState;
  7773.  
  7774. cProto.handleReplayProgress66 = cProto.handleReplayProgress;
  7775. cProto.handleReplayProgress = dProto.handleReplayProgressForPlaybackProgressState;
  7776.  
  7777. }
  7778.  
  7779. // ------------- ENABLE_VIDEO_PLAYBACK_PROGRESS_STATE_FIX -------------
  7780.  
  7781. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7782.  
  7783. if (FIX_MEMORY_LEAKAGE_TICKER_TIMER) {
  7784. if (!USE_ADVANCED_TICKING && typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth55 && cProto.setContainerWidth.length === 0) {
  7785. cProto.setContainerWidth55 = cProto.setContainerWidth;
  7786. cProto.setContainerWidth = dProto.setContainerWidthNoSelfLeakage;
  7787. flgLeakageFixApplied |= 4;
  7788. }
  7789. if (!USE_ADVANCED_TICKING && typeof cProto.slideDown === 'function' && !cProto.slideDown55 && cProto.slideDown.length === 0) {
  7790. cProto.slideDown55 = cProto.slideDown;
  7791. cProto.slideDown = dProto.slideDownNoSelfLeakage;
  7792. flgLeakageFixApplied |= 8;
  7793. }
  7794. if (!USE_ADVANCED_TICKING && typeof cProto.collapse === 'function' && !cProto.collapse55 && cProto.collapse.length === 0) {
  7795. cProto.collapse55 = cProto.collapse;
  7796. cProto.collapse = dProto.collapseNoSelfLeakage;
  7797. flgLeakageFixApplied |= 16;
  7798. }
  7799. if (typeof cProto.deletedChanged === 'function' && !cProto.deletedChanged55 && cProto.deletedChanged.length === 0) {
  7800.  
  7801. cProto.deletedChanged55 = cProto.deletedChanged;
  7802. cProto.deletedChanged = dProto.deletedChangedNoSelfLeakage;
  7803. flgLeakageFixApplied |= 32;
  7804. }
  7805.  
  7806. }
  7807.  
  7808. console.log(`FIX_MEMORY_LEAKAGE_TICKER_: ${flgLeakageFixApplied} / ${1 + 2 + 4 + 8 + 16 + 32}`, cProto.is);
  7809.  
  7810. // ------------- FIX_MEMORY_LEAKAGE_TICKER_TIMER -------------
  7811.  
  7812.  
  7813.  
  7814. const canDoAdvancedTicking = 1 &&
  7815. ATTEMPT_TICKER_ANIMATION_START_TIME_DETECTION &&
  7816. typeof cProto.startCountdown === 'function' && !cProto.startCountdown49 && cProto.startCountdown.length === 2 &&
  7817. typeof cProto.updateTimeout === 'function' && !cProto.updateTimeout49 && cProto.updateTimeout.length === 1 &&
  7818. typeof cProto.isAnimationPausedChanged === 'function' && !cProto.isAnimationPausedChanged49 && cProto.isAnimationPausedChanged.length === 2 &&
  7819. typeof cProto.setContainerWidth === 'function' && cProto.setContainerWidth.length === 0 &&
  7820. typeof cProto.requestRemoval === 'function' && !cProto.requestRemoval49 && cProto.requestRemoval.length === 0
  7821. CSS.supports("left","clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)");
  7822.  
  7823.  
  7824.  
  7825. if (USE_ADVANCED_TICKING && canDoAdvancedTicking) {
  7826. // startResistanceUpdater();
  7827. // live replay video -> 48117005 -> 48117006 keep fire. ->48117007 0 -> 48117007 {...}
  7828. // live stream video -> 48117007 0 -> 48117007 YES
  7829.  
  7830. document.documentElement.setAttribute('r6-advanced-ticking', '');
  7831. console.log(`USE_ADVANCED_TICKING[#${tagI}]::START`)
  7832.  
  7833. const wio2 = dProto.wio2 || (dProto.wio2 = new IntersectionObserver((mutations) => {
  7834.  
  7835. for (const mutation of mutations) {
  7836. if (mutation.isIntersecting) {
  7837.  
  7838. const marker = mutation.target;
  7839. let endId = marker.id
  7840. if (!endId) continue;
  7841. let tid = endId.substring(0, endId.length - 2);
  7842. if (!tid) continue;
  7843. // let bId = `${tid}-b`;
  7844. const bgElm = document.querySelector(`#${tid}-b`);
  7845. if (!bgElm) continue;
  7846. const overlay = bgElm;
  7847.  
  7848. wio2.unobserve(marker);
  7849. marker.remove();
  7850. let p = overlay || 0;
  7851. let cn = 4;
  7852. while ((p = p.parentElement) instanceof HTMLElement) {
  7853. if (p instanceof HTMLElement) {
  7854. const cnt = insp(p);
  7855. if (cnt && typeof cnt.slideDown === 'function' && typeof cnt.setContainerWidth === 'function' && cnt.__advancedTicking038__ === 1) {
  7856.  
  7857. cnt.__advancedTicking038__ = 2;
  7858.  
  7859. let deletionMode = false;
  7860. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7861. if (timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__timestampActionRequest__ > 0) {
  7862.  
  7863. // time choose - 0.2s for transition (slideDown sliding-down)
  7864. // 60hz = 17ms
  7865. // choose 0.28s
  7866. const targetFutureTime = cntData.__timestampActionRequest__ + cntData.durationSec * 1000;
  7867. // check whether the targetFutureTime is already the past
  7868. if (targetFutureTime + 280 < Date.now()) {
  7869. // just dispose
  7870. deletionMode = true;
  7871. }
  7872. } else if (__LCRInjection__ && !timestampUnderLiveMode && cntData && cntData.durationSec > 0 && cntData.__progressAt__ > 0) {
  7873.  
  7874. const targetFutureTime = (cntData.__progressAt__ + cntData.durationSec);
  7875. // check whether the targetFutureTime is already the past
  7876. if (targetFutureTime + 0.28 < playerProgressChangedArg1) {
  7877. // just dispose
  7878. deletionMode = true;
  7879. }
  7880.  
  7881.  
  7882. }
  7883.  
  7884.  
  7885. if (deletionMode) {
  7886. __requestRemoval__(cnt);
  7887. } else {
  7888.  
  7889. const w = cnt.hostElement.style.width;
  7890. if (w === "auto" || w === "") cnt.setContainerWidth();
  7891. cnt.slideDown();
  7892. }
  7893.  
  7894. break;
  7895. }
  7896. }
  7897. cn--;
  7898. if (!cn) {
  7899. console.log('cnt not found for ticker-bg-overlay');
  7900. break;
  7901. }
  7902. }
  7903.  
  7904.  
  7905. }
  7906. }
  7907.  
  7908. // console.log(mutations);
  7909. }, {
  7910.  
  7911. rootMargin: '0px',
  7912. threshold: [1]
  7913.  
  7914. }));
  7915.  
  7916.  
  7917.  
  7918. const u37fn = dProto.u37fn || (dProto.u37fn = function (cnt) {
  7919.  
  7920. if (!__LCRInjection__) {
  7921. console.error('[yt-chat] USE_ADVANCED_TICKING fails because of no __LCRInjection__');
  7922. }
  7923.  
  7924. const cntData = ((cnt || 0).__data || 0).data || (cnt || 0).data || 0;
  7925. if (!cntData) return;
  7926. const cntElement = cnt.hostElement;
  7927. if (!(cntElement instanceof HTMLElement)) return;
  7928.  
  7929. const duration = (cntData.fullDurationSec || cntData.durationSec || 0);
  7930.  
  7931. let ct;
  7932.  
  7933. if (__LCRInjection__ && cntData && duration > 0 && !('__progressAt__' in cntData)) {
  7934. ct = Date.now();
  7935. cntData.__liveTimestamp__ = (cntData.__timestampActionRequest__ || ct) / 1000 - timeOriginDT / 1000;
  7936. timestampUnderLiveMode = true;
  7937. } else if (__LCRInjection__ && cntData && duration > 0 && cntData.__progressAt__ > 0) {
  7938. timestampUnderLiveMode = false;
  7939. }
  7940. // console.log(48117007, cntData)
  7941.  
  7942. let tk = cntData.__progressAt__ || cntData.__liveTimestamp__;
  7943.  
  7944. if (!tk) {
  7945. console.log('time property is not found');
  7946. return;
  7947. }
  7948.  
  7949.  
  7950.  
  7951. const liveOffsetMs = ct > 0 && cntData.__timestampActionRequest__ > 0 ? ct - cntData.__timestampActionRequest__ : 0;
  7952.  
  7953. // console.log(1237, liveOffsetMs, cntData.durationSec)
  7954.  
  7955. if (liveOffsetMs > 0) {
  7956. cntData.durationSec -= Math.floor(liveOffsetMs / 1000);
  7957. if (cntData.durationSec < 0) cntData.durationSec = 0;
  7958. // console.log(1238, liveOffsetMs, cntData.durationSec)
  7959. if (!cntData.durationSec) {
  7960. try {
  7961. cnt.requestRemoval();
  7962. } catch (e) { }
  7963. return;
  7964. }
  7965. }
  7966.  
  7967.  
  7968. let offset = cntData.fullDurationSec - cntData.durationSec; // consider this is live replay video, offset can be > 0
  7969. if (offset > 0) tk -= offset;
  7970. // in livestreaming. tk can be negative as we use performance.timeOrigin for t=0s time frame
  7971.  
  7972.  
  7973.  
  7974. const existingOverlaySelector = `ticker-bg-overlay[ticker-id="${cnt.__ticker_attachmentId__}"]`;
  7975.  
  7976. if (valAssign(cntElement, '--ticker-start-time', tk) && duration > 0) {
  7977.  
  7978. // t0 ...... 1 ... fullDurationSec
  7979. // tk ...... k ... fullDurationSec-durationSec
  7980. // t0-fullDurationSec ...... 0 ... 0
  7981.  
  7982. // now - (fullDurationSec-durationSec)
  7983.  
  7984.  
  7985. // update dntElementWeak
  7986. const dnt = cnt.parentComponent;
  7987. const dntElement = dnt ? dnt.hostElement || dnt : 0;
  7988. if (dntElement) {
  7989. dntElementWeak = mWeakRef(dntElement);
  7990. resistanceUpdateBusy = false;
  7991. if (!startResistanceUpdaterStarted) startResistanceUpdater();
  7992. else updateTickerCurrentTime();
  7993. }
  7994.  
  7995. // create overlay if needed
  7996. if (!cntElement.querySelector(existingOverlaySelector)) {
  7997.  
  7998. // remove if any
  7999. const oldElement = cntElement.querySelector('ticker-bg-overlay');
  8000. if (oldElement) oldElement.remove();
  8001.  
  8002. // use advancedTicking, ticker enabled
  8003. cnt.__advancedTicking038__ = 1;
  8004.  
  8005. const em = document.createElement('ticker-bg-overlay');
  8006. // const ey = document.createElement('ticker-bg-overlay-end');
  8007. const wy = document.createElement('ticker-bg-overlay-end2');
  8008.  
  8009. const cr1 = cnt.colorFromDecimal(cntData.startBackgroundColor);
  8010. const cr2 = cnt.colorFromDecimal(cntData.endBackgroundColor);
  8011.  
  8012. const container = cnt.$.container;
  8013.  
  8014. em.setAttribute('ticker-id', `${cnt.__ticker_attachmentId__}`);
  8015.  
  8016. const tid = `ticker-${cnt.__ticker_attachmentId__}-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  8017.  
  8018. em.id = `${tid}-b`;
  8019. em.style.background = `linear-gradient(90deg, ${cr1},${cr1} 50%,${cr2} 50%,${cr2})`;
  8020.  
  8021. if (!(container instanceof HTMLElement)) {
  8022. // em.insertBefore(ey, em.firstChild);
  8023. insertBeforeNaFn(cntElement, em, cntElement.firstChild); // cntElement.insertBefore(em, cntElement.firstChild);
  8024. cntElement.style.borderRadius = '16px';
  8025. container.style.borderRadius = 'initial';
  8026. } else {
  8027. // em.insertBefore(ey, em.firstChild);
  8028. insertBeforeNaFn(container, em, container.firstChild); // container.insertBefore(em, container.firstChild);
  8029. }
  8030.  
  8031. // em.style.left = '-50%';
  8032. // em.style.left = "clamp(-100%, calc( -100% * ( var(--ticker-current-time) - var(--ticker-start-time) ) / var(--ticker-duration-time) ), 0%)";
  8033.  
  8034. if (container instanceof HTMLElement) {
  8035.  
  8036. container.style.background = 'transparent';
  8037. container.style.backgroundColor = 'transparent';
  8038. // container.style.zIndex = '1';
  8039. }
  8040. // em.style.zIndex = '-1';
  8041. valAssign(cntElement, '--ticker-duration-time', duration)
  8042.  
  8043. valAssign(wy, '--ticker-start-time', tk);
  8044. valAssign(wy, '--ticker-duration-time', duration);
  8045. wy.id = `${tid}-e`;
  8046.  
  8047. appendChildNaFn(dntElement, wy);
  8048.  
  8049. // if (wio instanceof IntersectionObserver) {
  8050. // wio.observe(ey);
  8051. // }
  8052.  
  8053. if (wio2 instanceof IntersectionObserver) {
  8054. wio2.observe(wy);
  8055. }
  8056.  
  8057. }
  8058. }
  8059. });
  8060.  
  8061. const timeFn = (cnt) => {
  8062.  
  8063. if (!cnt) return;
  8064. if (!cnt.hostElement) return;
  8065.  
  8066. const attachementId = cnt.__ticker_attachmentId__;
  8067. if (!attachementId) return;
  8068.  
  8069. Promise.resolve(cnt).then(u37fn);
  8070.  
  8071. }
  8072. cProto.__isTickerItem58__ = 1;
  8073. cProto.startCountdown = dProto.startCountdownAdv || (dProto.startCountdownAdv = function (a, b) {
  8074.  
  8075. timeFn(kRef(this));
  8076.  
  8077.  
  8078. });
  8079.  
  8080. cProto.updateTimeout = dProto.updateTimeoutAdv || (dProto.updateTimeoutAdv = function (a) {
  8081.  
  8082.  
  8083.  
  8084. });
  8085.  
  8086. cProto.isAnimationPausedChanged = dProto.isAnimationPausedChangedAdv || (dProto.isAnimationPausedChangedAdv = function (a, b) {
  8087.  
  8088.  
  8089.  
  8090. });
  8091.  
  8092.  
  8093. if (typeof cProto.slideDown === 'function' && !cProto.slideDown43 && cProto.slideDown.length === 0) {
  8094.  
  8095. cProto.slideDown43 = cProto.slideDown;
  8096. cProto.slideDown = dProto.slideDownAdv || (dProto.slideDownAdv = async function () {
  8097.  
  8098. // console.log('calling slideDown', Date.now())
  8099. if (this.__advancedTicking038__) {
  8100.  
  8101. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  8102.  
  8103.  
  8104. const hostElement = this.hostElement;
  8105. const container = this.$.container;
  8106.  
  8107. const parentComponentCnt = insp(this.parentComponent);
  8108. const parentComponentElm = parentComponentCnt? parentComponentCnt.hostElement : null;
  8109.  
  8110. if (hostElement instanceof HTMLElement && container instanceof HTMLElement && parentComponentElm instanceof HTMLElement) {
  8111. // const prevTransitionClosingElm = kRef(prevTransitionClosing);
  8112. // if (prevTransitionClosingElm !== hostElement) {
  8113. // prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  8114. // prevTransitionClosing = mWeakRef(hostElement);
  8115. // }
  8116. // if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  8117. hostElement.classList.add('r6-closing-ticker');
  8118.  
  8119. if (!transitionEndHooks.has(parentComponentElm)) {
  8120. transitionEndHooks.add(parentComponentElm);
  8121. document.addEventListener('transitionend', transitionEndAfterFn, passiveCapture);
  8122. }
  8123.  
  8124. const pr = new PromiseExternal();
  8125. transitionEndAfterFnSimple.set(hostElement, pr);
  8126. transitionEndAfterFnSimple.set(container, pr);
  8127. transitionEndAfterFnSimpleEnable++;
  8128. hostElement.classList.add("sliding-down");
  8129. await pr.then();
  8130. transitionEndAfterFnSimpleEnable--;
  8131. transitionEndAfterFnSimple.delete(hostElement);
  8132. transitionEndAfterFnSimple.delete(container);
  8133. if (this && this.hostElement instanceof HTMLElement) {
  8134.  
  8135. this.collapse();
  8136. }
  8137. return;
  8138. }
  8139. }
  8140. this.slideDown43();
  8141.  
  8142. });
  8143.  
  8144.  
  8145. console.log(`USE_ADVANCED_TICKING[#${tagI}]::slideDown - OK`)
  8146. } else {
  8147.  
  8148. console.log(`USE_ADVANCED_TICKING[#${tagI}]::slideDown - NG`)
  8149. }
  8150.  
  8151.  
  8152. if (typeof cProto.collapse === 'function' && !cProto.collapse43 && cProto.collapse.length === 0) {
  8153. cProto.collapse43 = cProto.collapse;
  8154. cProto.collapse = dProto.collapseAdv || (dProto.collapseAdv = async function () {
  8155.  
  8156.  
  8157. if (this.__advancedTicking038__) {
  8158.  
  8159.  
  8160. if (this.__advancedTicking038__ === 1) this.__advancedTicking038__ = 2; // ignore intersectionobserver detection
  8161.  
  8162.  
  8163. const hostElement = this.hostElement;
  8164. const container = this.$.container;
  8165.  
  8166. const parentComponentCnt = insp(this.parentComponent);
  8167. const parentComponentElm = parentComponentCnt ? parentComponentCnt.hostElement : null;
  8168.  
  8169. if (hostElement instanceof HTMLElement && container instanceof HTMLElement && parentComponentElm instanceof HTMLElement) {
  8170. // const prevTransitionClosingElm = kRef(prevTransitionClosing);
  8171. // if (prevTransitionClosingElm !== hostElement) {
  8172. // prevTransitionClosingElm && prevTransitionClosingElm.classList.add('ticker-no-transition-time');
  8173. // prevTransitionClosing = mWeakRef(hostElement);
  8174. // }
  8175. // if (hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.remove('ticker-no-transition-time');
  8176. hostElement.classList.add('r6-closing-ticker');
  8177.  
  8178. if (!transitionEndHooks.has(parentComponentElm)) {
  8179. transitionEndHooks.add(parentComponentElm);
  8180. document.addEventListener('transitionend', transitionEndAfterFn, passiveCapture);
  8181. }
  8182.  
  8183. const pr = new PromiseExternal();
  8184. transitionEndAfterFnSimple.set(hostElement, pr);
  8185. transitionEndAfterFnSimple.set(container, pr);
  8186. transitionEndAfterFnSimpleEnable++;
  8187. hostElement.classList.add("collapsing");
  8188. hostElement.style.width = "0";
  8189. await pr.then();
  8190. transitionEndAfterFnSimpleEnable--;
  8191. transitionEndAfterFnSimple.delete(hostElement);
  8192. transitionEndAfterFnSimple.delete(container);
  8193. if (this && this.hostElement instanceof HTMLElement) {
  8194.  
  8195. this.requestRemoval();
  8196. }
  8197.  
  8198. return;
  8199. }
  8200.  
  8201.  
  8202. }
  8203. this.collapse43();
  8204.  
  8205.  
  8206. });
  8207.  
  8208. console.log(`USE_ADVANCED_TICKING[#${tagI}]::collapse - OK`)
  8209. } else {
  8210.  
  8211. console.log(`USE_ADVANCED_TICKING[#${tagI}]::collapse - NG`)
  8212. }
  8213.  
  8214.  
  8215.  
  8216. if (typeof cProto.requestRemoval === 'function' && !cProto.requestRemoval49 && cProto.requestRemoval.length === 0) {
  8217. cProto.requestRemoval49 = cProto.requestRemoval;
  8218. cProto.requestRemoval = dProto.requestRemovalAdv || (dProto.requestRemovalAdv = function () {
  8219. if (this.__advancedTicking038__) {
  8220. try {
  8221. const overlayBg = this.hostElement.querySelector('ticker-bg-overlay[id]');
  8222. if (overlayBg) {
  8223. const overlayBgId = overlayBg.id;
  8224. const tid = overlayBgId ? overlayBgId.substring(0, overlayBgId.length - 2) : '';
  8225. const endElm = tid ? document.querySelector(`#${tid}-e`) : null;
  8226. if (endElm) {
  8227. wio2.unobserve(endElm);
  8228. endElm.remove();
  8229. }
  8230. }
  8231. } catch (e) { }
  8232. this.__advancedTicking038__ = 2;
  8233. // console.log('requestRemoval!!')
  8234. if (REUSE_TICKER) {
  8235. const hostElement = this.hostElement;
  8236. const cntData = this.data;
  8237. if (hostElement instanceof HTMLElement && cntData.id && cntData.fullDurationSec && !hostElement.hasAttribute('__reuseid__')) {
  8238. hostElement.setAttribute('__reuseid__', reuseId);
  8239. hostElement.setAttribute('__nogc__', ''); // provided to leakage detection script
  8240. // this.__markReuse13__ = true;
  8241. reuseStore.set(`<${this.is}>${cntData.id}:${cntData.fullDurationSec}`, mWeakRef(this));
  8242. }
  8243. }
  8244. }
  8245. const hostElement = this.hostElement;
  8246. if (hostElement instanceof HTMLElement) {
  8247. // try {
  8248. // // hostElement.remove();
  8249.  
  8250. // if (!hostElement.classList.contains('ticker-no-transition-time')) hostElement.classList.add('ticker-no-transition-time');
  8251. // } catch (e) { }
  8252.  
  8253. try {
  8254.  
  8255. hostElement.classList.remove('r6-closing-ticker');
  8256. hostElement.classList.remove('r6-width-adjustable-f');
  8257. } catch (e) { }
  8258.  
  8259. // if(ADVANCED_TICKING_MEMORY_CLEAN_FOR_REMOVAL){
  8260. // const wr = mWeakRef(hostElement);
  8261. // const wf = ()=>{
  8262. // const element = kRef(wr);
  8263. // if(!element) {
  8264. // console.log('[yt-chat-removalrequest] element was memory cleaned.');
  8265. // return;
  8266. // }
  8267.  
  8268. // setTimeout(wf, 8000);
  8269. // if(element.isConnected){
  8270. // console.log('[yt-chat-removalrequest] element is still connected to DOM Tree.');
  8271. // return;
  8272. // }
  8273.  
  8274. // const cnt = insp(element)
  8275. // if(typeof cnt.requestRemoval !== 'function'){
  8276.  
  8277. // console.log('[yt-chat-removalrequest] element is not connected to cnt.');
  8278. // return;
  8279. // }
  8280. // console.log('[yt-chat-removalrequest] element is not GC.');
  8281. // try{
  8282. // cnt.data = null;
  8283. // }catch(e){}
  8284.  
  8285. // Object.setPrototypeOf(cnt, Object.prototype);
  8286. // for(const k of Object.getOwnPropertyNames(cnt)){
  8287. // try{
  8288. // cnt[k] = null;
  8289. // }catch(e){}
  8290.  
  8291. // try{
  8292. // delete cnt[k];
  8293. // }catch(e){}
  8294. // }
  8295.  
  8296.  
  8297. // for(const k of Object.getOwnPropertySymbols(cnt)){
  8298. // try{
  8299. // cnt[k] = null;
  8300. // }catch(e){}
  8301.  
  8302. // try{
  8303. // delete cnt[k];
  8304. // }catch(e){}
  8305. // }
  8306.  
  8307. // }
  8308. // setTimeout(wf, 8000);
  8309. // }
  8310.  
  8311. return this.requestRemoval49();
  8312. }
  8313. });
  8314.  
  8315.  
  8316. console.log(`USE_ADVANCED_TICKING[#${tagI}]::requestRemoval - OK`)
  8317. } else {
  8318.  
  8319. console.log(`USE_ADVANCED_TICKING[#${tagI}]::requestRemoval - NG`)
  8320. }
  8321.  
  8322.  
  8323. if (typeof cProto.computeContainerStyle === 'function' && !cProto.computeContainerStyle49 && cProto.computeContainerStyle.length === 2) {
  8324. cProto.computeContainerStyle49 = cProto.computeContainerStyle;
  8325. cProto.computeContainerStyle = dProto.computeContainerStyleAdv || (dProto.computeContainerStyleAdv = function (a, b) {
  8326. if (this.__advancedTicking038__) {
  8327. return "";
  8328. }
  8329. return this.computeContainerStyle49(a, b);
  8330. });
  8331.  
  8332.  
  8333. console.log(`USE_ADVANCED_TICKING[#${tagI}]::computeContainerStyle - OK`)
  8334. } else {
  8335.  
  8336. console.log(`USE_ADVANCED_TICKING[#${tagI}]::computeContainerStyle - NG`)
  8337. }
  8338.  
  8339.  
  8340.  
  8341. if (typeof cProto.setRevampContainerWidth === 'function' && !cProto.setRevampContainerWidth41 && cProto.setRevampContainerWidth.length === 0) {
  8342. cProto.setRevampContainerWidth41 = cProto.setRevampContainerWidth;
  8343. cProto.setRevampContainerWidth = dProto.setRevampContainerWidthAdv || (dProto.setRevampContainerWidthAdv = async function () {
  8344.  
  8345. // not sure the reason for auto instead of pixel.
  8346. // this is a new function in Dec 2024, but not mainly adopted in the coding yet
  8347.  
  8348. /*
  8349.  
  8350.  
  8351. var a = this;
  8352. (R(this.hostElement).querySelector("#container").clientWidth || 0) === 0 ? (this.hostElement.style.overflow = "visible",
  8353. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  8354. this.ytLiveChatTickerItemBehavior.shouldAnimateIn ? (this.hostElement.style.width = "0",
  8355. Zu(function() {
  8356. a.hostElement.style.width = "auto"
  8357. }, 1)) : this.hostElement.style.width = "auto")
  8358.  
  8359. */
  8360.  
  8361.  
  8362.  
  8363.  
  8364. const hostElement = (this || 0).hostElement;
  8365. const container = this.$.container;
  8366.  
  8367.  
  8368. let qw = null;
  8369.  
  8370. {
  8371.  
  8372.  
  8373. let maxC = 4;
  8374.  
  8375. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  8376.  
  8377. const ed = `${hostElement.id}`
  8378. if (!p || !p.startsWith(`${ed}::`)) {
  8379.  
  8380. const w = hostElement.style.width;
  8381. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  8382.  
  8383. const res = await widthReq(container);
  8384.  
  8385. if (res.width < 1 || !Number.isFinite(res.width)) {
  8386. // just skip due to iron-page hidden
  8387. return;
  8388. }
  8389.  
  8390. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  8391.  
  8392. } else {
  8393. qw = p.split('::');
  8394. break;
  8395. }
  8396.  
  8397. }
  8398.  
  8399. }
  8400.  
  8401. if (!qw) {
  8402.  
  8403. console.log('container width failure');
  8404. this.setRevampContainerWidth41();
  8405. return; // failure
  8406. }
  8407.  
  8408.  
  8409. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  8410. if (shouldAnimateIn) {
  8411.  
  8412.  
  8413.  
  8414. const w = hostElement.style.width;
  8415. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  8416. // hostElement.classList.remove('ticker-no-transition-time');
  8417. await widthReq(container);
  8418.  
  8419. hostElement.style.width = `${qw[1]}px`;
  8420. return;
  8421.  
  8422.  
  8423. } else {
  8424. hostElement.style.width = `${qw[1]}px`;
  8425. }
  8426.  
  8427.  
  8428. // const container = this.$.container;
  8429. // if(hostElement instanceof HTMLElement && hostElement.style.width) hostElement.style.width = '';
  8430. });
  8431.  
  8432.  
  8433. console.log(`USE_ADVANCED_TICKING[#${tagI}]::setRevampContainerWidth - OK`)
  8434. } else {
  8435.  
  8436. console.log(`USE_ADVANCED_TICKING[#${tagI}]::setRevampContainerWidth - NG (acceptable)`)
  8437. }
  8438.  
  8439.  
  8440. if (typeof cProto.setContainerWidth === 'function' && !cProto.setContainerWidth41 && cProto.setContainerWidth.length === 0) {
  8441. cProto.setContainerWidth41 = cProto.setContainerWidth;
  8442. cProto.setContainerWidth = dProto.setContainerWidthAdv || (dProto.setContainerWidthAdv = async function () {
  8443.  
  8444.  
  8445.  
  8446. /*
  8447.  
  8448.  
  8449. var a = this
  8450. , b = R(this.hostElement).querySelector("#container").clientWidth || 0;
  8451. b === 0 ? (this.hostElement.style.overflow = "visible",
  8452. this.hostElement.style.width = "auto") : (this.hostElement.style.overflow = "hidden",
  8453. this.shouldAnimateIn ? (this.hostElement.style.width = "0",
  8454. Zu(function() {
  8455. a.hostElement.style.width = b + "px"
  8456. }, 1)) : this.hostElement.style.width = b + "px")
  8457.  
  8458. */
  8459.  
  8460. const hostElement = (this || 0).hostElement;
  8461. const container = this.$.container;
  8462.  
  8463.  
  8464. let qw = null;
  8465.  
  8466. {
  8467.  
  8468.  
  8469. let maxC = 4;
  8470.  
  8471. for (let p = hostElement.getAttribute('r6-ticker-width') || ''; maxC--;) {
  8472.  
  8473. const ed = `${hostElement.id}`
  8474. if (!p || !p.startsWith(`${ed}::`)) {
  8475.  
  8476. const w = hostElement.style.width;
  8477. if (w !== '' && w !== 'auto') hostElement.style.width = 'auto';
  8478.  
  8479. const res = await widthReq(container);
  8480.  
  8481. if (res.width < 1 || !Number.isFinite(res.width)) {
  8482. // just skip due to iron-page hidden
  8483. return;
  8484. }
  8485.  
  8486. hostElement.setAttribute('r6-ticker-width', p = `${ed}::${(res.width).toFixed(2)}`);
  8487.  
  8488. } else {
  8489. qw = p.split('::');
  8490. break;
  8491. }
  8492.  
  8493. }
  8494.  
  8495. }
  8496.  
  8497. if (!qw) {
  8498.  
  8499. console.log('container width failure');
  8500. this.setContainerWidth41();
  8501. return; // failure
  8502. }
  8503.  
  8504.  
  8505. const shouldAnimateIn = ((this || 0).ytLiveChatTickerItemBehavior || 0).shouldAnimateIn || (this || 0).shouldAnimateIn || false;
  8506. if (shouldAnimateIn) {
  8507.  
  8508.  
  8509.  
  8510. const w = hostElement.style.width;
  8511. if (w !== '0px' && w !== '0') hostElement.style.width = '0';
  8512. // hostElement.classList.remove('ticker-no-transition-time');
  8513. await widthReq(container);
  8514.  
  8515. hostElement.style.width = `${qw[1]}px`;
  8516. return;
  8517.  
  8518.  
  8519. } else {
  8520. hostElement.style.width = `${qw[1]}px`;
  8521. }
  8522.  
  8523.  
  8524. });
  8525.  
  8526.  
  8527.  
  8528. console.log(`USE_ADVANCED_TICKING[#${tagI}]::setContainerWidth - OK`)
  8529. } else {
  8530.  
  8531.  
  8532. console.log(`USE_ADVANCED_TICKING[#${tagI}]::setContainerWidth - NG`)
  8533. }
  8534.  
  8535.  
  8536.  
  8537.  
  8538. } else if (USE_ADVANCED_TICKING) {
  8539. console.log(`USE_ADVANCED_TICKING[#${tagI}] is not injected.`);
  8540. }
  8541.  
  8542.  
  8543.  
  8544. }
  8545.  
  8546. const selector = tags.join(', ');
  8547. const elements = document.querySelectorAll(selector);
  8548. if (elements.length >= 1) {
  8549. for (const elm of elements) {
  8550. if (insp(elm).isAttached === true) {
  8551. fpTicker(elm);
  8552. }
  8553. }
  8554. }
  8555.  
  8556. console.log("[End]");
  8557. console.groupEnd();
  8558.  
  8559.  
  8560. }).catch(console.warn);
  8561.  
  8562. if(FIX_MEMORY_LEAKAGE_TICKER_DATACHANGED_setContainerWidth){
  8563.  
  8564. /**
  8565. *
  8566. *
  8567. *
  8568. *
  8569. cT.prototype.dataChanged = function() {
  8570. var a = this;
  8571. this.data && (Q(this.hostElement).querySelector("#content").style.color = this.ytLiveChatTickerItemBehavior.colorFromDecimal(this.data.detailTextColor),
  8572. this.hostElement.ariaLabel = this.computeAriaLabel(this.data),
  8573. this.ytLiveChatTickerItemBehavior.startCountdown(this.data.durationSec, this.data.fullDurationSec),
  8574. qw(function() {
  8575. a.ytLiveChatTickerItemBehavior.setContainerWidth()
  8576. }))
  8577. }
  8578.  
  8579.  
  8580. znb.prototype.dataChanged = function(a) {
  8581. var b = this;
  8582. a && (a.tickerThumbnails.length > 1 && Q(this.hostElement).querySelector("#content").classList.add("multiple-thumbnails"),
  8583. this.ytLiveChatTickerItemBehavior.startCountdown(a.durationSec, a.fullDurationSec),
  8584. qw(function() {
  8585. b.ytLiveChatTickerItemBehavior.setContainerWidth()
  8586. }))
  8587. }
  8588.  
  8589. *
  8590. */
  8591.  
  8592. const dProto = {
  8593. dataChanged54500: function () {
  8594. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  8595. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  8596. try {
  8597. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8598. return this.dataChanged544.call(this.__proxySelf0__);
  8599. } catch (e) {
  8600. console.log('dataChanged54500 ERROR');
  8601. console.error(e);
  8602. }
  8603. } else {
  8604. return this.dataChanged544();
  8605. }
  8606. },
  8607. dataChanged54501: function (a) {
  8608. // prevent memory leakage due to _.ytLiveChatTickerItemBehavior.setContainerWidth() in _.dataChanged
  8609. if (typeof (this.ytLiveChatTickerItemBehavior || 0).setContainerWidth === 'function') {
  8610. try {
  8611. if (!this.__proxySelf0__) this.__proxySelf0__ = weakWrap(this);
  8612. return this.dataChanged544.call(this.__proxySelf0__, a);
  8613. } catch (e) {
  8614. console.log('dataChanged54501 ERROR');
  8615. console.error(e);
  8616. }
  8617. } else {
  8618. return this.dataChanged544(a);
  8619. }
  8620. },
  8621. }
  8622.  
  8623. for (const sto of [
  8624. 'yt-live-chat-ticker-sponsor-item-renderer',
  8625. 'yt-live-chat-ticker-paid-sticker-item-renderer'
  8626. ].map(tag => [tag, customElements.whenDefined(tag)])) {
  8627.  
  8628. const [tag, promise] = sto;
  8629.  
  8630. promise.then(()=>{
  8631.  
  8632. const dummy = document.createElement(tag);
  8633.  
  8634. const cProto = getProto(dummy);
  8635. if (!cProto || !cProto.attached) {
  8636. console.warn(`proto.attached for ${tag} is unavailable.`);
  8637. return;
  8638. }
  8639.  
  8640. if (!cProto.dataChanged || cProto.dataChanged544 || typeof cProto.dataChanged !== 'function' || !(cProto.dataChanged.length >= 0 && cProto.dataChanged.length <= 1)) return;
  8641.  
  8642. cProto.dataChanged544 = cProto.dataChanged;
  8643.  
  8644. if (cProto.dataChanged.length === 0) cProto.dataChanged = dProto.dataChanged54500;
  8645. else if (cProto.dataChanged.length === 1) cProto.dataChanged = dProto.dataChanged54501;
  8646.  
  8647.  
  8648.  
  8649. })
  8650.  
  8651.  
  8652. }
  8653.  
  8654. }
  8655.  
  8656. customElements.whenDefined('yt-live-chat-ticker-renderer').then(() => {
  8657.  
  8658. if (FLAG_001d) return;
  8659.  
  8660. mightFirstCheckOnYtInit();
  8661. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-ticker-renderer hacks");
  8662. console.log("[Begin]");
  8663. (() => {
  8664.  
  8665. /* pending!!
  8666.  
  8667. handleLiveChatAction
  8668.  
  8669. removeTickerItemById
  8670.  
  8671. _itemsChanged
  8672. itemsChanged
  8673.  
  8674. handleMarkChatItemAsDeletedAction
  8675. handleMarkChatItemsByAuthorAsDeletedAction
  8676. handleRemoveChatItemByAuthorAction
  8677.  
  8678.  
  8679. */
  8680.  
  8681. const tag = "yt-live-chat-ticker-renderer"
  8682. const dummy = document.createElement(tag);
  8683.  
  8684. const cProto = getProto(dummy);
  8685. if (!cProto || !cProto.attached) {
  8686. console.warn(`proto.attached for ${tag} is unavailable.`);
  8687. return;
  8688. }
  8689.  
  8690. if(typeof cProto.createComponent_ === 'function' && cProto.createComponent_.length === 3 && !cProto.createComponent58_ ){
  8691.  
  8692. cProto.createComponent58_ = cProto.createComponent_;
  8693. cProto.createComponent_ = function (a, b, c) {
  8694.  
  8695. const z = customCreateComponent(a, b, c);
  8696. if (z !== undefined) return z;
  8697. const r = this.createComponent58_(a, b, c);
  8698. return r;
  8699.  
  8700. }
  8701.  
  8702. }
  8703.  
  8704.  
  8705.  
  8706.  
  8707.  
  8708.  
  8709.  
  8710.  
  8711. /* Dec 2024 */
  8712.  
  8713. /*
  8714.  
  8715.  
  8716. f.handleLiveChatActions = function(a) {
  8717. a.length && (a.forEach(this.handleLiveChatAction, this),
  8718. this.updateHighlightedItem(),
  8719. this.shouldAnimateIn = !0)
  8720. }
  8721. ;
  8722. f.handleLiveChatAction = function(a) {
  8723. var b = z(a, fL)
  8724. , c = z(a, gL)
  8725. , d = z(a, eL)
  8726. , e = z(a, gdb)
  8727. , g = z(a, rdb)
  8728. , k = z(a, Deb);
  8729. a = z(a, Ceb);
  8730. 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)
  8731. }
  8732. */
  8733.  
  8734.  
  8735. if(USE_ADVANCED_TICKING && !cProto.handleLiveChatActions47 && typeof cProto.handleLiveChatActions === 'function' && cProto.handleLiveChatActions.length ===1){
  8736.  
  8737. cProto.handleLiveChatActions47 = cProto.handleLiveChatActions;
  8738.  
  8739. cProto.handleLiveChatActions = function (a) {
  8740.  
  8741. // first loading in livestream. so this is required for sorting.
  8742.  
  8743. try{
  8744. preprocessChatLiveActions(a);
  8745. }catch(e){
  8746. console.warn(e);
  8747. }
  8748. return this.handleLiveChatActions47(a);
  8749.  
  8750. }
  8751.  
  8752. console.log("USE_ADVANCED_TICKING::handleLiveChatActions - OK");
  8753.  
  8754. }else if(USE_ADVANCED_TICKING){
  8755.  
  8756.  
  8757. console.log("USE_ADVANCED_TICKING::handleLiveChatActions - NG");
  8758.  
  8759. }
  8760.  
  8761. // yt-live-chat-ticker-renderer hacks
  8762. // console.log('handleLiveChatActions', cProto.handleLiveChatActions, cProto.is);
  8763. // console.log('handleLiveChatAction', cProto.handleLiveChatAction, cProto.is);
  8764.  
  8765.  
  8766. if (RAF_FIX_keepScrollClamped) {
  8767.  
  8768. // to be improved
  8769.  
  8770. if (typeof cProto.keepScrollClamped === 'function' && !cProto.keepScrollClamped72 && fnIntegrity(cProto.keepScrollClamped) === '0.17.10') {
  8771.  
  8772. cProto.keepScrollClamped72 = cProto.keepScrollClamped;
  8773. cProto.keepScrollClamped = function () {
  8774.  
  8775. const cnt = kRef(this);
  8776. if (!cnt) return;
  8777. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8778.  
  8779. cnt._bound_keepScrollClamped = cnt._bound_keepScrollClamped || cnt.keepScrollClamped.bind(mWeakRef(cnt));
  8780. cnt.scrollClampRaf = requestAnimationFrame(cnt._bound_keepScrollClamped);
  8781. cnt.maybeClampScroll()
  8782. }
  8783.  
  8784. console.log('RAF_FIX: keepScrollClamped', tag, "OK")
  8785. } else {
  8786.  
  8787. assertor(() => fnIntegrity(cProto.keepScrollClamped, '0.17.10'));
  8788. console.log('RAF_FIX: keepScrollClamped', tag, "NG")
  8789. }
  8790.  
  8791. }
  8792.  
  8793.  
  8794. if (RAF_FIX_scrollIncrementally && typeof cProto.startScrolling === 'function' && typeof cProto.scrollIncrementally === 'function'
  8795. && '|1.43.31|1.44.31|'.indexOf('|' + fnIntegrity(cProto.startScrolling) + '|') >= 0
  8796. && '|1.78.45|1.82.43|1.43.31|'.indexOf('|' + fnIntegrity(cProto.scrollIncrementally) + '|') >= 0) {
  8797. // to be replaced by animator
  8798.  
  8799. cProto.startScrolling = function (a) {
  8800.  
  8801. const cnt = kRef(this);
  8802. if (!cnt) return;
  8803. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8804.  
  8805. cnt.scrollStopHandle && cnt.cancelAsync(cnt.scrollStopHandle);
  8806. cnt.asyncHandle && cancelAnimationFrame(cnt.asyncHandle);
  8807. cnt.lastFrameTimestamp = cnt.scrollStartTime = performance.now();
  8808. cnt.scrollRatePixelsPerSecond = a;
  8809. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8810. cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally)
  8811. };
  8812.  
  8813. // related functions: startScrollBack, startScrollingLeft, startScrollingRight, etc.
  8814.  
  8815. /**
  8816. *
  8817. * // 2024.12.17
  8818. * // https://www.youtube.com/s/desktop/f7495da0/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  8819.  
  8820. f.startScrolling = function(a) {
  8821. this.scrollStopHandle && $u(this.scrollStopHandle);
  8822. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  8823. this.scrollStartTime = performance.now();
  8824. this.lastFrameTimestamp = performance.now();
  8825. this.scrollRatePixelsPerSecond = a;
  8826. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  8827. }
  8828. ;
  8829. f.scrollIncrementally = function(a) {
  8830. var b = a - (this.lastFrameTimestamp || 0);
  8831. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft += b / 1E3 * (this.scrollRatePixelsPerSecond || 0);
  8832. this.maybeClampScroll();
  8833. this.updateArrows();
  8834. this.lastFrameTimestamp = a;
  8835. R(this.hostElement).querySelector(this.tickerBarQuery).scrollLeft > 0 || this.scrollRatePixelsPerSecond && this.scrollRatePixelsPerSecond > 0 ? this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this)) : this.stopScrolling()
  8836. }
  8837. ;
  8838. *
  8839. */
  8840.  
  8841. /**
  8842. *
  8843. // 2024.12.20
  8844.  
  8845.  
  8846.  
  8847. f.startScrolling = function(a) {
  8848. this.scrollStopHandle && av(this.scrollStopHandle);
  8849. this.asyncHandle && window.cancelAnimationFrame(this.asyncHandle);
  8850. this.scrollStartTime = performance.now();
  8851. this.lastFrameTimestamp = performance.now();
  8852. this.scrollRatePixelsPerSecond = a;
  8853. this.asyncHandle = window.requestAnimationFrame(this.scrollIncrementally.bind(this))
  8854. }
  8855.  
  8856. *
  8857. *
  8858. */
  8859.  
  8860. cProto.__getTickerBarQuery__ = function () {
  8861. const tickerBarQuery = this.tickerBarQuery === '#items' ? this.$.items : this.hostElement.querySelector(this.tickerBarQuery);
  8862. return tickerBarQuery;
  8863. }
  8864.  
  8865. cProto.scrollIncrementally = (RAF_FIX_scrollIncrementally === 2) ? function (a) {
  8866.  
  8867. const cnt = kRef(this);
  8868. if (!cnt) return;
  8869. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8870.  
  8871. const b = a - (cnt.lastFrameTimestamp || 0);
  8872. const rate = cnt.scrollRatePixelsPerSecond
  8873. const q = b / 1E3 * (rate || 0);
  8874.  
  8875. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8876. const sl = tickerBarQuery.scrollLeft;
  8877. // console.log(rate, sl, q)
  8878. if (cnt.lastFrameTimestamp == cnt.scrollStartTime) {
  8879.  
  8880. } else if (q > -1e-5 && q < 1e-5) {
  8881.  
  8882. } else {
  8883. let cond1 = sl > 0 && rate > 0 && q > 0;
  8884. let cond2 = sl > 0 && rate < 0 && q < 0;
  8885. let cond3 = sl < 1e-5 && sl > -1e-5 && rate > 0 && q > 0;
  8886. if (cond1 || cond2 || cond3) {
  8887. tickerBarQuery.scrollLeft += q;
  8888. cnt.maybeClampScroll();
  8889. cnt.updateArrows();
  8890. }
  8891. }
  8892.  
  8893. cnt.lastFrameTimestamp = a;
  8894. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8895. 0 < tickerBarQuery.scrollLeft || rate && 0 < rate ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8896. } : function (a) {
  8897.  
  8898. const cnt = kRef(this);
  8899. if (!cnt) return;
  8900. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  8901.  
  8902. const b = a - (cnt.lastFrameTimestamp || 0);
  8903. const tickerBarQuery = cnt.__getTickerBarQuery__();
  8904. tickerBarQuery.scrollLeft += b / 1E3 * (cnt.scrollRatePixelsPerSecond || 0);
  8905. cnt.maybeClampScroll();
  8906. cnt.updateArrows();
  8907. cnt.lastFrameTimestamp = a;
  8908. cnt._bound_scrollIncrementally = cnt._bound_scrollIncrementally || cnt.scrollIncrementally.bind(mWeakRef(cnt));
  8909. 0 < tickerBarQuery.scrollLeft || cnt.scrollRatePixelsPerSecond && 0 < cnt.scrollRatePixelsPerSecond ? cnt.asyncHandle = requestAnimationFrame(cnt._bound_scrollIncrementally) : cnt.stopScrolling()
  8910. };
  8911.  
  8912. console.log(`RAF_FIX: scrollIncrementally${RAF_FIX_scrollIncrementally}`, tag, "OK")
  8913. } else {
  8914. assertor(() => fnIntegrity(cProto.startScrolling, '1.43.31'))
  8915. || logFn('cProto.startScrolling', cProto.startScrolling)();
  8916. assertor(() => fnIntegrity(cProto.scrollIncrementally, '1.78.45'))
  8917. || logFn('cProto.scrollIncrementally', cProto.scrollIncrementally)();
  8918. console.log('RAF_FIX: scrollIncrementally', tag, "NG")
  8919. }
  8920.  
  8921.  
  8922. if (CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED && typeof cProto.attached === 'function' && !cProto.attached37 && typeof cProto.detached === 'function' && !cProto.detached37) {
  8923.  
  8924. cProto.attached37 = cProto.attached;
  8925. cProto.detached37 = cProto.detached;
  8926.  
  8927. let naohzId = 0;
  8928. cProto.__naohzId__ = 0;
  8929. cProto.attached = function () {
  8930. Promise.resolve(this).then((cnt) => {
  8931.  
  8932. const hostElement = cnt.hostElement || cnt;
  8933. if (!(hostElement instanceof HTMLElement)) return;
  8934. if (!HTMLElement.prototype.matches.call(hostElement, '.yt-live-chat-renderer')) return;
  8935. const ironPage = HTMLElement.prototype.closest.call(hostElement, 'iron-pages.yt-live-chat-renderer');
  8936. // or #chat-messages
  8937. if (!ironPage) return;
  8938.  
  8939. if (cnt.__naohzId__) removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8940. if (naohzId > 1e9) naohzId = naohzId % 1e4;
  8941. cnt.__naohzId__ = ++naohzId;
  8942. ironPage.setAttribute('naohz', `${+cnt.__naohzId__}`);
  8943.  
  8944. addEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8945.  
  8946. cnt = null;
  8947.  
  8948. });
  8949. return this.attached37.apply(this, arguments);
  8950. };
  8951. cProto.detached = function () {
  8952. Promise.resolve(this).then((cnt) => {
  8953.  
  8954. const ironPage = document.querySelector(`iron-pages[naohz="${+cnt.__naohzId__}"]`);
  8955. if (!ironPage) return;
  8956.  
  8957. removeEventListener.call(ironPage, 'click', cnt.messageBoxClickHandlerForFade, { capture: false, passive: true });
  8958.  
  8959. cnt = null;
  8960.  
  8961. });
  8962. return this.detached37.apply(this, arguments);
  8963. };
  8964.  
  8965. const clickFade = (u) => {
  8966. u.click();
  8967. };
  8968. cProto.messageBoxClickHandlerForFade = async (evt) => {
  8969.  
  8970. const target = (evt || 0).target || 0;
  8971. if (!target) return;
  8972.  
  8973. for (let p = target; p instanceof HTMLElement; p = nodeParent(p)) {
  8974. const is = p.is;
  8975. if (typeof is === 'string' && is) {
  8976.  
  8977. if (is === 'yt-live-chat-pinned-message-renderer') {
  8978. return;
  8979. }
  8980. if (is === 'iron-pages' || is === 'yt-live-chat-renderer' || is === 'yt-live-chat-app') {
  8981. const fade = HTMLElement.prototype.querySelector.call(p, 'yt-live-chat-pinned-message-renderer:not([hidden]) #fade');
  8982. if (fade) {
  8983. Promise.resolve(fade).then(clickFade);
  8984. evt && evt.stopPropagation();
  8985. }
  8986. return;
  8987. }
  8988. if (is !== 'yt-live-chat-ticker-renderer') {
  8989. if (is.startsWith('yt-live-chat-ticker-')) return;
  8990. if (!is.endsWith('-renderer')) return;
  8991. }
  8992.  
  8993. } else {
  8994. if ((p.nodeName || '').includes('BUTTON')) return;
  8995. }
  8996.  
  8997. }
  8998. };
  8999.  
  9000. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - OK")
  9001.  
  9002. } else {
  9003. console.log("CLOSE_TICKER_PINNED_MESSAGE_WHEN_HEADER_CLICKED - NG")
  9004. }
  9005.  
  9006.  
  9007. })();
  9008.  
  9009. console.log("[End]");
  9010.  
  9011. console.groupEnd();
  9012.  
  9013. }).catch(console.warn);
  9014.  
  9015.  
  9016.  
  9017. if (ENABLE_RAF_HACK_INPUT_RENDERER || DELAY_FOCUSEDCHANGED) {
  9018.  
  9019. customElements.whenDefined("yt-live-chat-message-input-renderer").then(() => {
  9020.  
  9021. mightFirstCheckOnYtInit();
  9022. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-input-renderer hacks");
  9023. console.log("[Begin]");
  9024. (() => {
  9025.  
  9026.  
  9027.  
  9028. const tag = "yt-live-chat-message-input-renderer"
  9029. const dummy = document.createElement(tag);
  9030.  
  9031. const cProto = getProto(dummy);
  9032. if (!cProto || !cProto.attached) {
  9033. console.warn(`proto.attached for ${tag} is unavailable.`);
  9034. return;
  9035. }
  9036.  
  9037.  
  9038. if (ENABLE_RAF_HACK_INPUT_RENDERER && rafHub !== null) {
  9039.  
  9040. let doHack = false;
  9041. if (typeof cProto.handleTimeout === 'function' && typeof cProto.updateTimeout === 'function') {
  9042.  
  9043. // not cancellable
  9044.  
  9045. // <<< to be reviewed cProto.updateTimeout --- isTimingFunctionHackable -- doHack >>>
  9046.  
  9047. doHack = fnIntegrity(cProto.handleTimeout, '1.27.16') && fnIntegrity(cProto.updateTimeout, '1.50.33');
  9048.  
  9049. if (!doHack) console.log('doHack = false')
  9050.  
  9051. }
  9052. // doHack = false; // M55
  9053.  
  9054. if (doHack) {
  9055.  
  9056. cProto.handleTimeout = function (a) {
  9057.  
  9058. const cnt = kRef(this);
  9059. if (!cnt) return;
  9060. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9061.  
  9062. console.log('cProto.handleTimeout', tag)
  9063. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  9064. cnt.timeoutDurationMs = cnt.timeoutMs = a;
  9065. cnt.countdownRatio = 1;
  9066. 0 === cnt.lastTimeoutTimeMs && rafHub.request(cnt.boundUpdateTimeout38_)
  9067. };
  9068. cProto.updateTimeout = function (a) {
  9069.  
  9070. const cnt = kRef(this);
  9071. if (!cnt) return;
  9072. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9073.  
  9074. console.log('cProto.updateTimeout', tag)
  9075. if (!cnt.boundUpdateTimeout38_) cnt.boundUpdateTimeout38_ = cnt.updateTimeout.bind(mWeakRef(cnt));
  9076. cnt.lastTimeoutTimeMs && (cnt.timeoutMs = Math.max(0, cnt.timeoutMs - (a - cnt.lastTimeoutTimeMs)),
  9077. cnt.countdownRatio = cnt.timeoutMs / cnt.timeoutDurationMs);
  9078. cnt.isAttached && cnt.timeoutMs ? (cnt.lastTimeoutTimeMs = a,
  9079. rafHub.request(cnt.boundUpdateTimeout38_)) : cnt.lastTimeoutTimeMs = 0
  9080. };
  9081.  
  9082. console.log('RAF_HACK_INPUT_RENDERER', tag, "OK")
  9083. } else {
  9084.  
  9085. console.log('typeof handleTimeout', typeof cProto.handleTimeout)
  9086. console.log('typeof updateTimeout', typeof cProto.updateTimeout)
  9087.  
  9088. console.log('RAF_HACK_INPUT_RENDERER', tag, "NG")
  9089. }
  9090.  
  9091.  
  9092. }
  9093.  
  9094. if (DELAY_FOCUSEDCHANGED && typeof cProto.onFocusedChanged === 'function' && cProto.onFocusedChanged.length === 1 && !cProto.onFocusedChanged372) {
  9095. cProto.onFocusedChanged372 = cProto.onFocusedChanged;
  9096. cProto.onFocusedChanged = function (a) {
  9097. Promise.resolve(this).then((cnt) => {
  9098. if (cnt.isAttached === true) cnt.onFocusedChanged372(a);
  9099. cnt = null;
  9100. }).catch(console.warn);
  9101. }
  9102. }
  9103.  
  9104. })();
  9105.  
  9106. console.log("[End]");
  9107.  
  9108. console.groupEnd();
  9109.  
  9110.  
  9111. })
  9112.  
  9113. }
  9114.  
  9115.  
  9116. if (ENABLE_RAF_HACK_EMOJI_PICKER && rafHub !== null) {
  9117.  
  9118. customElements.whenDefined("yt-emoji-picker-renderer").then(() => {
  9119.  
  9120. mightFirstCheckOnYtInit();
  9121. groupCollapsed("YouTube Super Fast Chat", " | yt-emoji-picker-renderer hacks");
  9122. console.log("[Begin]");
  9123. (() => {
  9124.  
  9125. const tag = "yt-emoji-picker-renderer"
  9126. const dummy = document.createElement(tag);
  9127.  
  9128. const cProto = getProto(dummy);
  9129. if (!cProto || !cProto.attached) {
  9130. console.warn(`proto.attached for ${tag} is unavailable.`);
  9131. return;
  9132. }
  9133.  
  9134. let doHack = false;
  9135. if (typeof cProto.animateScroll_ === 'function') {
  9136.  
  9137. // not cancellable
  9138. console.log('animateScroll_', typeof cProto.animateScroll_)
  9139.  
  9140. doHack = fnIntegrity(cProto.animateScroll_, '1.102.49')
  9141.  
  9142. }
  9143.  
  9144. if (doHack) {
  9145.  
  9146. const querySelector = HTMLElement.prototype.querySelector;
  9147. const U = (element) => ({
  9148. querySelector: (selector) => querySelector.call(element, selector)
  9149. });
  9150.  
  9151. cProto.animateScroll_ = function (a) {
  9152.  
  9153. const cnt = kRef(this);
  9154. if (!cnt) return;
  9155. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9156.  
  9157. // console.log('cProto.animateScroll_', tag) // yt-emoji-picker-renderer
  9158. if (!cnt.boundAnimateScroll39_) cnt.boundAnimateScroll39_ = cnt.animateScroll_.bind(mWeakRef(cnt));
  9159. cnt.lastAnimationTime_ || (cnt.lastAnimationTime_ = a);
  9160. a -= cnt.lastAnimationTime_;
  9161. 200 > a ? (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationStart_ + (cnt.animationEnd_ - cnt.animationStart_) * a / 200,
  9162. rafHub.request(cnt.boundAnimateScroll39_)) : (null != cnt.animationEnd_ && (U(cnt.hostElement).querySelector("#categories").scrollTop = cnt.animationEnd_),
  9163. cnt.animationEnd_ = cnt.animationStart_ = null,
  9164. cnt.lastAnimationTime_ = 0);
  9165. cnt.updateButtons_()
  9166. }
  9167.  
  9168. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "OK")
  9169. } else {
  9170.  
  9171. console.log('ENABLE_RAF_HACK_EMOJI_PICKER', tag, "NG")
  9172. }
  9173.  
  9174. })();
  9175.  
  9176. console.log("[End]");
  9177.  
  9178. console.groupEnd();
  9179. });
  9180. }
  9181.  
  9182. if (ENABLE_RAF_HACK_DOCKED_MESSAGE && rafHub !== null) {
  9183.  
  9184. customElements.whenDefined("yt-live-chat-docked-message").then(() => {
  9185.  
  9186. mightFirstCheckOnYtInit();
  9187. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-docked-message hacks");
  9188. console.log("[Begin]");
  9189. (() => {
  9190.  
  9191. const tag = "yt-live-chat-docked-message"
  9192. const dummy = document.createElement(tag);
  9193.  
  9194. const cProto = getProto(dummy);
  9195. if (!cProto || !cProto.attached) {
  9196. console.warn(`proto.attached for ${tag} is unavailable.`);
  9197. return;
  9198. }
  9199.  
  9200. let doHack = false;
  9201. if (typeof cProto.detached === 'function' && typeof cProto.checkIntersections === 'function' && typeof cProto.onDockableMessagesChanged === 'function' && typeof cProto.boundCheckIntersections === 'undefined') {
  9202.  
  9203. // cancelable - this.intersectRAF <detached>
  9204. // yt-live-chat-docked-message
  9205. // boundCheckIntersections <-> checkIntersections
  9206. // onDockableMessagesChanged
  9207. // this.intersectRAF = window.requestAnimationFrame(this.boundCheckIntersections);
  9208.  
  9209. console.log('detached', typeof cProto.detached)
  9210. console.log('checkIntersections', typeof cProto.checkIntersections)
  9211. console.log('onDockableMessagesChanged', typeof cProto.onDockableMessagesChanged)
  9212.  
  9213. doHack = fnIntegrity(cProto.detached, '0.32.22') && fnIntegrity(cProto.checkIntersections, '0.128.85') && fnIntegrity(cProto.onDockableMessagesChanged, '0.20.11')
  9214.  
  9215. }
  9216.  
  9217. if (doHack) {
  9218.  
  9219. cProto.__boundCheckIntersectionsSubstitutionFn__ = function () {
  9220. const cnt = this;
  9221. if (!cnt.i5zmk && typeof cnt.boundCheckIntersections === 'function' && typeof cnt.checkIntersections === 'function') {
  9222. cnt.i5zmk = 1
  9223. cnt.boundCheckIntersections = cnt.checkIntersections.bind(mWeakRef(cnt));
  9224. }
  9225. }
  9226.  
  9227. cProto.checkIntersections = function () {
  9228.  
  9229. const cnt = kRef(this);
  9230. if (!cnt) return;
  9231. if (!cnt.hostElement) return; // memory leakage. to be reviewed
  9232.  
  9233. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  9234.  
  9235. // console.log('cProto.checkIntersections', tag)
  9236. if (cnt.dockableMessages.length) {
  9237. cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections);
  9238. let a = cnt.dockableMessages[0]
  9239. , b = cnt.hostElement.getBoundingClientRect();
  9240. a = a.getBoundingClientRect();
  9241. let c = a.top - b.top
  9242. , d = 8 >= c;
  9243. c = 8 >= c - cnt.hostElement.clientHeight;
  9244. if (d) {
  9245. let e;
  9246. for (; d;) {
  9247. e = cnt.dockableMessages.shift();
  9248. d = cnt.dockableMessages[0];
  9249. if (!d)
  9250. break;
  9251. d = d.getBoundingClientRect();
  9252. c = d.top - b.top;
  9253. let f = 8 >= c;
  9254. if (8 >= c - a.height)
  9255. if (f)
  9256. a = d;
  9257. else
  9258. return;
  9259. d = f
  9260. }
  9261. cnt.dock(e)
  9262. } else
  9263. c && cnt.dockedItem && cnt.clear()
  9264. } else
  9265. cnt.intersectRAF = 0
  9266. }
  9267.  
  9268. cProto.onDockableMessagesChanged = function () {
  9269. const cnt = this;
  9270. if(typeof cnt.__boundCheckIntersectionsSubstitutionFn__ === 'function') cnt.__boundCheckIntersectionsSubstitutionFn__();
  9271. // console.log('cProto.onDockableMessagesChanged', tag) // yt-live-chat-docked-message
  9272. cnt.dockableMessages.length && !cnt.intersectRAF && (cnt.intersectRAF = rafHub.request(cnt.boundCheckIntersections))
  9273. }
  9274.  
  9275. cProto.detached = function () {
  9276. this.intersectRAF && rafHub.cancel(this.intersectRAF)
  9277. }
  9278.  
  9279. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "OK")
  9280. } else {
  9281.  
  9282. console.log('ENABLE_RAF_HACK_DOCKED_MESSAGE', tag, "NG")
  9283. }
  9284.  
  9285. })();
  9286.  
  9287. console.log("[End]");
  9288.  
  9289. console.groupEnd();
  9290.  
  9291. }).catch(console.warn);
  9292.  
  9293. }
  9294.  
  9295. if (FIX_SETSRC_AND_THUMBNAILCHANGE_) {
  9296.  
  9297. customElements.whenDefined("yt-img-shadow").then(() => {
  9298.  
  9299. mightFirstCheckOnYtInit();
  9300. groupCollapsed("YouTube Super Fast Chat", " | yt-img-shadow hacks");
  9301. console.log("[Begin]");
  9302. (() => {
  9303.  
  9304. const tag = "yt-img-shadow"
  9305. const dummy = document.createElement(tag);
  9306.  
  9307. const cProto = getProto(dummy);
  9308. if (!cProto || !cProto.attached) {
  9309. console.warn(`proto.attached for ${tag} is unavailable.`);
  9310. return;
  9311. }
  9312.  
  9313. if (typeof cProto.thumbnailChanged_ === 'function' && !cProto.thumbnailChanged66_) {
  9314.  
  9315. cProto.thumbnailChanged66_ = cProto.thumbnailChanged_;
  9316. cProto.thumbnailChanged_ = function (a) {
  9317.  
  9318. if (this.oldThumbnail_ && this.thumbnail && this.oldThumbnail_.thumbnails === this.thumbnail.thumbnails) return;
  9319. if (!this.oldThumbnail_ && !this.thumbnail) return;
  9320.  
  9321. return this.thumbnailChanged66_.apply(this, arguments)
  9322.  
  9323. }
  9324. console.log("cProto.thumbnailChanged_ - OK");
  9325.  
  9326. } else {
  9327. console.log("cProto.thumbnailChanged_ - NG");
  9328.  
  9329. }
  9330. if (typeof cProto.setSrc_ === 'function' && !cProto.setSrc66_) {
  9331.  
  9332. cProto.setSrc66_ = cProto.setSrc_;
  9333. cProto.setSrc_ = function (a) {
  9334. if ((((this || 0).$ || 0).img || 0).src === a) return;
  9335. return this.setSrc66_.apply(this, arguments)
  9336. }
  9337.  
  9338. console.log("cProto.setSrc_ - OK");
  9339. } else {
  9340.  
  9341. console.log("cProto.setSrc_ - NG");
  9342. }
  9343.  
  9344. })();
  9345.  
  9346. console.log("[End]");
  9347.  
  9348. console.groupEnd();
  9349.  
  9350. }).catch(console.warn);
  9351.  
  9352. }
  9353.  
  9354. if (FIX_THUMBNAIL_DATACHANGED) {
  9355.  
  9356. customElements.whenDefined("yt-live-chat-author-badge-renderer").then(() => {
  9357.  
  9358. mightFirstCheckOnYtInit();
  9359. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-author-badge-renderer hacks");
  9360. console.log("[Begin]");
  9361. (() => {
  9362.  
  9363. const tag = "yt-live-chat-author-badge-renderer"
  9364. const dummy = document.createElement(tag);
  9365.  
  9366. const cProto = getProto(dummy);
  9367. if (!cProto || !cProto.attached) {
  9368. console.warn(`proto.attached for ${tag} is unavailable.`);
  9369. return;
  9370. }
  9371.  
  9372. if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|0.169.106|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9373.  
  9374. cProto.dataChanged86 = cProto.dataChanged;
  9375. cProto.dataChanged = function () {
  9376.  
  9377. /* 2024.12.15 */
  9378. /*
  9379. zO.prototype.dataChanged = function() {
  9380. for (var a = Ov(R(this.hostElement).querySelector("#image")); a.firstChild; )
  9381. a.removeChild(a.firstChild);
  9382. if (this.data)
  9383. if (this.data.icon) {
  9384. var b = document.createElement("yt-icon");
  9385. this.data.icon.iconType === "MODERATOR" && this.enableNewModeratorBadge ? (b.polymerController.icon = "yt-sys-icons:shield-filled",
  9386. b.polymerController.defaultToFilled = !0) : b.polymerController.icon = "live-chat-badges:" + this.data.icon.iconType.toLowerCase();
  9387. a.appendChild(b)
  9388. } else if (this.data.customThumbnail) {
  9389. b = document.createElement("img");
  9390. var c;
  9391. (c = (c = UA(this.data.customThumbnail.thumbnails, 16)) ? Yb(kc(c)) : null) ? (b.src = c,
  9392. a.appendChild(b),
  9393. b.setAttribute("alt", this.hostElement.ariaLabel || "")) : Fq(new Zn("Could not compute URL for thumbnail",this.data.customThumbnail))
  9394. }
  9395. }
  9396. */
  9397.  
  9398. const a = (this || 0).data;
  9399. const image = ((this || 0).$ || 0).image;
  9400. if (image && a && image.firstElementChild) {
  9401. const exisiting = image.firstElementChild;
  9402. if (exisiting === image.lastElementChild) {
  9403.  
  9404. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9405.  
  9406. const c = exisiting;
  9407. const t = insp(c);
  9408. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9409. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9410. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9411. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9412. } else {
  9413. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9414. if (w.icon !== p) w.icon = p;
  9415. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9416. }
  9417. return;
  9418.  
  9419.  
  9420. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9421.  
  9422. const c = exisiting;
  9423. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9424.  
  9425. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9426. return;
  9427. }
  9428. /*
  9429.  
  9430. var d;
  9431. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9432.  
  9433. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9434. */
  9435. }
  9436.  
  9437. }
  9438. }
  9439. return this.dataChanged86.apply(this, arguments)
  9440.  
  9441. }
  9442. console.log("cProto.dataChanged - OK");
  9443.  
  9444. } else if (typeof cProto.dataChanged === 'function' && !cProto.dataChanged86 && '|1.163.100|1.162.100|1.160.97|1.159.97|'.includes(`|${fnIntegrity(cProto.dataChanged)}|`)) {
  9445.  
  9446. cProto.dataChanged86 = cProto.dataChanged;
  9447. cProto.dataChanged = function (a) {
  9448.  
  9449. /*
  9450.  
  9451. for (var b = xC(Z(this.hostElement).querySelector("#image")); b.firstChild; )
  9452. b.removeChild(b.firstChild);
  9453. if (a)
  9454. if (a.icon) {
  9455. var c = document.createElement("yt-icon");
  9456. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.icon = "yt-sys-icons:shield-filled",
  9457. c.defaultToFilled = !0) : c.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9458. b.appendChild(c)
  9459. } else if (a.customThumbnail) {
  9460. c = document.createElement("img");
  9461. var d;
  9462. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9463. b.appendChild(c),
  9464. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail",a.customThumbnail))
  9465. }
  9466.  
  9467. */
  9468.  
  9469.  
  9470. /* 2024.04.20 */
  9471. /*
  9472. for (var b = Tx(N(this.hostElement).querySelector("#image")); b.firstChild; )
  9473. b.removeChild(b.firstChild);
  9474. if (a)
  9475. if (a.icon) {
  9476. var c = document.createElement("yt-icon");
  9477. "MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge ? (c.polymerController.icon = "yt-sys-icons:shield-filled",
  9478. c.polymerController.defaultToFilled = !0) : c.polymerController.icon = "live-chat-badges:" + a.icon.iconType.toLowerCase();
  9479. b.appendChild(c)
  9480. } else if (a.customThumbnail) {
  9481. c = document.createElement("img");
  9482. var d;
  9483. (d = (d = WD(a.customThumbnail.thumbnails, 16)) ? Sb(ec(d)) : null) ? (c.src = d,
  9484. b.appendChild(c),
  9485. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : nr(new mn("Could not compute URL for thumbnail",a.customThumbnail))
  9486. }
  9487. */
  9488.  
  9489. const image = ((this || 0).$ || 0).image
  9490. if (image && a && image.firstElementChild) {
  9491. const exisiting = image.firstElementChild;
  9492. if (exisiting === image.lastElementChild) {
  9493.  
  9494. if (a.icon && exisiting.nodeName.toUpperCase() === 'YT-ICON') {
  9495.  
  9496. const c = exisiting;
  9497. const t = insp(c);
  9498. const w = ('icon' in t || 'defaultToFilled' in t) ? t : c;
  9499. if ("MODERATOR" === a.icon.iconType && this.enableNewModeratorBadge) {
  9500. if (w.icon !== "yt-sys-icons:shield-filled") w.icon = "yt-sys-icons:shield-filled";
  9501. if (w.defaultToFilled !== true) w.defaultToFilled = true;
  9502. } else {
  9503. const p = "live-chat-badges:" + a.icon.iconType.toLowerCase();;
  9504. if (w.icon !== p) w.icon = p;
  9505. if (w.defaultToFilled !== false) w.defaultToFilled = false;
  9506. }
  9507. return;
  9508.  
  9509.  
  9510. } else if (a.customThumbnail && exisiting.nodeName.toUpperCase() == 'IMG') {
  9511.  
  9512. const c = exisiting;
  9513. if (a.customThumbnail.thumbnails.map(e => e.url).includes(c.src)) {
  9514.  
  9515. c.setAttribute("alt", this.hostElement.ariaLabel || "");
  9516. return;
  9517. }
  9518. /*
  9519.  
  9520. var d;
  9521. (d = (d = KC(a.customThumbnail.thumbnails, 16)) ? lc(oc(d)) : null) ? (c.src = d,
  9522.  
  9523. c.setAttribute("alt", this.hostElement.ariaLabel || "")) : lq(new tm("Could not compute URL for thumbnail", a.customThumbnail))
  9524. */
  9525. }
  9526.  
  9527. }
  9528. }
  9529. return this.dataChanged86.apply(this, arguments)
  9530.  
  9531. }
  9532. console.log("cProto.dataChanged - OK");
  9533.  
  9534. } else {
  9535. assertor(() => fnIntegrity(cProto.dataChanged, '0.169.106'));
  9536. console.log("cProto.dataChanged - NG");
  9537.  
  9538. }
  9539.  
  9540. })();
  9541.  
  9542. console.log("[End]");
  9543.  
  9544. console.groupEnd();
  9545.  
  9546. }).catch(console.warn);
  9547.  
  9548.  
  9549. }
  9550.  
  9551. if (USE_ADVANCED_TICKING) {
  9552. // leading the emoji cannot be rendered.
  9553.  
  9554. // const qz38 = lcrPromiseFn();
  9555.  
  9556. // qz38.then((lcrGet) => {
  9557.  
  9558. // const tag = "yt-live-chat-renderer"
  9559. // const dummy = lcrGet();
  9560.  
  9561. const lcrFn2 = (lcrDummy) => {
  9562.  
  9563. const tag = "yt-live-chat-renderer"
  9564. const dummy = lcrDummy;
  9565.  
  9566.  
  9567. const cProto = getProto(dummy);
  9568.  
  9569. // dummy.usePatchedLifecycles = false;
  9570. // dummy.data = null;
  9571. // dummy.__data = null;
  9572. // Object.setPrototypeOf(dummy, Object.prototype);
  9573. if (!cProto || !cProto.attached) {
  9574. console.warn(`proto.attached for ${tag} is unavailable.`);
  9575. return;
  9576. }
  9577.  
  9578. /*
  9579. <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;
  9580. */
  9581.  
  9582. if (cProto && typeof cProto.immediatelyApplyLiveChatActions === 'function' && cProto.immediatelyApplyLiveChatActions.length === 1 && !cProto.immediatelyApplyLiveChatActions82) {
  9583. cProto.immediatelyApplyLiveChatActions82 = cProto.immediatelyApplyLiveChatActions;
  9584. cProto.immediatelyApplyLiveChatActions = function (arr) {
  9585.  
  9586.  
  9587. // console.log(1237)
  9588. try {
  9589. preprocessChatLiveActions(arr);
  9590. } catch (e) {
  9591. console.warn(e);
  9592. }
  9593. return this.immediatelyApplyLiveChatActions82(arr);
  9594. };
  9595. }
  9596.  
  9597.  
  9598. if (cProto && typeof cProto.preprocessActions_ === 'function' && cProto.preprocessActions_.length === 1 && !cProto.preprocessActions82_) {
  9599. cProto.preprocessActions82_ = cProto.preprocessActions_;
  9600. cProto.preprocessActions_ = function (arr) {
  9601.  
  9602. arr = this.preprocessActions82_(arr);
  9603.  
  9604. try {
  9605. preprocessChatLiveActions(arr);
  9606. } catch (e) {
  9607. console.warn(e);
  9608. }
  9609. return arr;
  9610. };
  9611. }
  9612.  
  9613.  
  9614.  
  9615. };
  9616. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  9617. getLCRDummy().then(lcrFn2);
  9618. }
  9619.  
  9620.  
  9621. if (FIX_TOOLTIP_DISPLAY) {
  9622.  
  9623. // ----------------------------------------------------------------------------------------------------
  9624.  
  9625. const checkPDGet = (pd) => {
  9626. return pd && pd.get && !pd.set && pd.enumerable && pd.configurable;
  9627. }
  9628.  
  9629. const tooltipUIWM = new WeakMap();
  9630. const tooltipInitProps = {};
  9631. const createTooltipIfRequired_ = function () {
  9632. let r;
  9633. if (tooltipUIWM.get(this) === void 0) {
  9634. const w = document.createElement;
  9635. let EU = null;
  9636. tooltipUIWM.set(this, null);
  9637. document.createElement = function () {
  9638. let r = w.apply(this, arguments);
  9639. EU = r;
  9640. return r;
  9641. };
  9642. r = this.createTooltipIfRequired14_();
  9643. document.createElement = w;
  9644. if (EU instanceof HTMLElement && EU.is) {
  9645. tooltipUIWM.set(this, EU);
  9646. EU.setAttribute('__nogc__', ''); // avoid gc process script
  9647.  
  9648. if (typeof EU.offset === 'number') tooltipInitProps['offset'] = EU.offset;
  9649. if (typeof EU.fitToVisibleBounds === 'boolean') tooltipInitProps['fitToVisibleBounds'] = EU.fitToVisibleBounds;
  9650. if (typeof EU.position === 'string') tooltipInitProps['position'] = EU.position;
  9651. if (typeof EU.for === 'string') tooltipInitProps['for'] = EU.for;
  9652.  
  9653. // this.__mcT__ = EU.outerHTML;
  9654. // EU.__dataX = JSON.stringify(EU.__data);
  9655. // EU.__dataY = Object.entries(EU);
  9656.  
  9657. // <<< FOR DEBUG >>>
  9658. // let kx;
  9659. // Object.defineProperty(EU, '_target', {
  9660. // get(){
  9661. // return kx;
  9662. // },
  9663. // set(nv){
  9664. // kx= nv;
  9665. // debugger;
  9666. // return true;
  9667. // }
  9668. // });
  9669. // <<< FOR DEBUG >>>
  9670.  
  9671. if (typeof Polymer !== 'undefined' && Polymer.__fixedGetOwnerRoot__ && Polymer.__fixedQuerySelector__) {
  9672.  
  9673. } else {
  9674. let eProto = null;
  9675. const euCnt = insp(EU);
  9676. if (checkPDGet(Object.getOwnPropertyDescriptor(euCnt.constructor.prototype || {}, 'target'))) {
  9677.  
  9678. eProto = euCnt.constructor.prototype;
  9679. } else if (checkPDGet(Object.getOwnPropertyDescriptor(EU.constructor.prototype || {}, 'target'))) {
  9680.  
  9681. eProto = EU.constructor.prototype;
  9682. }
  9683. if (eProto) {
  9684. delete eProto.target;
  9685. /*
  9686.  
  9687. get target() {
  9688. var a = Pv(this).parentNode, b = Pv(this).getOwnerRoot(), c;
  9689. this.for ? c = Pv(b).querySelector("#" + this.for) : c = a.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? b.host : a;
  9690. return c
  9691. },
  9692. */
  9693. Object.defineProperty(eProto, 'target', {
  9694. get() {
  9695. let a = this.parentNode, b = this.getRootNode();
  9696. return (this.for ? b.querySelector("#" + this.for) : a)
  9697. }
  9698. })
  9699. }
  9700. }
  9701. // setInterval(()=>EU.updatePosition(), 100)
  9702.  
  9703. } else {
  9704. tooltipUIWM.set(this, null);
  9705. }
  9706. } else {
  9707. r = this.createTooltipIfRequired14_();
  9708. }
  9709.  
  9710. const EU = tooltipUIWM.get(this);
  9711. if (EU) {
  9712. EU.remove();
  9713. if (typeof tooltipInitProps.offset === 'number') EU['offset'] = tooltipInitProps.offset;
  9714. if (typeof tooltipInitProps.fitToVisibleBounds === 'boolean') EU['fitToVisibleBounds'] = tooltipInitProps.fitToVisibleBounds;
  9715. try {
  9716. if (typeof tooltipInitProps.position === 'string') EU['position'] = tooltipInitProps.position;
  9717. if (typeof tooltipInitProps.for === 'string') EU['for'] = tooltipInitProps.for; else delete EU.for;
  9718. } catch (e) { }
  9719. }
  9720. return r;
  9721. };
  9722.  
  9723.  
  9724. // added in 2024.05.02
  9725. const lcrFn2 = (lcrDummy) => {
  9726.  
  9727. // console.log(8171, 99);
  9728. const tag = "yt-live-chat-renderer"
  9729. const dummy = lcrDummy;
  9730.  
  9731. const cProto = getProto(dummy);
  9732. if (!cProto || !cProto.attached) {
  9733. console.warn(`proto.attached for ${tag} is unavailable.`);
  9734. return;
  9735. }
  9736.  
  9737. /*
  9738. <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;
  9739. */
  9740.  
  9741. if (cProto && typeof cProto.createTooltipIfRequired_ === 'function' && cProto.createTooltipIfRequired_.length === 0 && !cProto.createTooltipIfRequired14_) {
  9742. cProto.createTooltipIfRequired14_ = cProto.createTooltipIfRequired_;
  9743. cProto.createTooltipIfRequired_ = createTooltipIfRequired_;
  9744. }
  9745.  
  9746. };
  9747. !__LCRInjection__ && LCRImmedidates.push(lcrFn2);
  9748. getLCRDummy().then(lcrFn2);
  9749.  
  9750. // ----------------------------------------------------------------------------------------------------
  9751.  
  9752. customElements.whenDefined("tp-yt-paper-tooltip").then(() => {
  9753.  
  9754. mightFirstCheckOnYtInit();
  9755. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-tooltip hacks");
  9756. console.log("[Begin]");
  9757. (() => {
  9758.  
  9759. const tag = "tp-yt-paper-tooltip"
  9760. const dummy = document.createElement(tag);
  9761.  
  9762. const cProto = getProto(dummy);
  9763. if (!cProto || !cProto.attached) {
  9764. console.warn(`proto.attached for ${tag} is unavailable.`);
  9765. return;
  9766. }
  9767.  
  9768. if (typeof cProto.attached === 'function' && typeof cProto.detached === 'function' && cProto._readyClients && cProto._attachDom && cProto.ready && !cProto._readyClients43) {
  9769.  
  9770. cProto._readyClients43 = cProto._readyClients;
  9771. cProto._readyClients = function () {
  9772. // console.log(1238)
  9773.  
  9774. let r = cProto._readyClients43.apply(this, arguments);
  9775. if (this.$ && this.$$ && this.$.tooltip) this.root = null; // fix this.root = null != (b = a.root) ? b : this.host
  9776. return r;
  9777. }
  9778.  
  9779. console.log("_readyClients - OK");
  9780.  
  9781. } else {
  9782. console.log("_readyClients - NG");
  9783.  
  9784. }
  9785.  
  9786. if (typeof cProto.show === 'function' && !cProto.show17) {
  9787. cProto.show17 = cProto.show;
  9788. cProto.show = function () {
  9789.  
  9790. let r = this.show17.apply(this, arguments);
  9791. this._showing === true && Promise.resolve(this).then((cnt) => {
  9792. const tooltip = (cnt.$ || 0).tooltip;
  9793.  
  9794. if (tooltip && tooltip.firstElementChild === null) {
  9795. let text = tooltip.textContent;
  9796. if (typeof text === 'string' && text.length >= 2) {
  9797. tooltip.textContent = text.trim();
  9798. }
  9799. }
  9800. cnt = null;
  9801. }).catch(console.warn)
  9802. return r;
  9803. }
  9804.  
  9805. console.log("trim tooltip content - OK");
  9806.  
  9807. } else {
  9808. console.log("trim tooltip content - NG");
  9809.  
  9810. }
  9811.  
  9812.  
  9813. })();
  9814.  
  9815. console.log("[End]");
  9816.  
  9817. console.groupEnd();
  9818.  
  9819. }).catch(console.warn);
  9820.  
  9821. }
  9822.  
  9823.  
  9824. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK) {
  9825.  
  9826. const hookDocumentMouseDownSetupFn = () => {
  9827.  
  9828. let muzTimestamp = 0;
  9829. let nszDropdown = null;
  9830.  
  9831. const handlerObject = {
  9832.  
  9833. muHandler282: function (evt) {
  9834. // console.log(evt, 7, document.querySelector('tp-yt-iron-dropdown[focused].style-scope.yt-live-chat-app'))
  9835. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9836. const dropdown = nszDropdown;
  9837. muzTimestamp = 0;
  9838. nszDropdown = null;
  9839.  
  9840. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9841. const hostElement = kurMPCe.hostElement || kurMPCe; // should be always hostElement === kurMPCe ?
  9842. if (!hostElement.hasAttribute('menu-visible')) return;
  9843.  
  9844. const chatBanner = HTMLElement.prototype.closest.call(hostElement, 'yt-live-chat-banner-renderer') || 0;
  9845. if (chatBanner) return;
  9846.  
  9847. if (dropdown && dropdown.positionTarget && hostElement.contains(dropdown.positionTarget)) {
  9848. muzTimestamp = Date.now();
  9849. evt.stopImmediatePropagation();
  9850. evt.stopPropagation();
  9851. Promise.resolve(dropdown).then((dropdown) => {
  9852. dropdown.cancel();
  9853. dropdown = null;
  9854. });
  9855. }
  9856.  
  9857. },
  9858.  
  9859. mlHandler282: function (evt) {
  9860. muzTimestamp = 0;
  9861. nszDropdown = null;
  9862. },
  9863.  
  9864. ckHandler282: function (evt) {
  9865. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9866. if (Date.now() - muzTimestamp < 40) {
  9867. muzTimestamp = Date.now();
  9868. evt.stopImmediatePropagation();
  9869. evt.stopPropagation();
  9870. }
  9871. },
  9872.  
  9873. tapHandler282: function (evt) {
  9874. if (!evt || !evt.isTrusted || !muzTimestamp) return;
  9875. if (Date.now() - muzTimestamp < 40) {
  9876. muzTimestamp = Date.now();
  9877. evt.stopImmediatePropagation();
  9878. evt.stopPropagation();
  9879. }
  9880. },
  9881.  
  9882. handleEvent(evt) {
  9883. if (evt) {
  9884. const kurMPCe = kRef(currentMenuPivotWR) || 0;
  9885. const kurMPCc = insp(kurMPCe);
  9886. const hostElement = kurMPCc.hostElement || kurMPCc;
  9887. if (!kurMPCc || kurMPCc.isAttached !== true || hostElement.isConnected !== true) return;
  9888. switch (evt.type) {
  9889. case 'mouseup':
  9890. return this.muHandler282(evt);
  9891. case 'mouseleave':
  9892. return this.mlHandler282(evt);
  9893. case 'tap':
  9894. return this.tapHandler282(evt);
  9895. case 'click':
  9896. return this.ckHandler282(evt);
  9897. }
  9898. }
  9899. }
  9900.  
  9901. }
  9902.  
  9903. document.addEventListener('mousedown', function (evt) {
  9904.  
  9905. if (!evt || !evt.isTrusted || !evt.target) return;
  9906.  
  9907. muzTimestamp = 0;
  9908. nszDropdown = null;
  9909.  
  9910. /** @type {HTMLElement | null} */
  9911. const kurMP = kRef(currentMenuPivotWR);
  9912. if (!kurMP) return;
  9913. const kurMPCe = HTMLElement.prototype.closest.call(kurMP, '[menu-visible]') || 0; // element
  9914.  
  9915. if (!kurMPCe || !kurMPCe.hasAttribute('whole-message-clickable')) return;
  9916.  
  9917. const kurMPCc = insp(kurMPCe); // controller
  9918.  
  9919. if (!kurMPCc.isClickableChatRow111 || !kurMPCc.isClickableChatRow111() || !HTMLElement.prototype.contains.call(kurMPCe, evt.target)) return;
  9920.  
  9921. const chatBanner = HTMLElement.prototype.closest.call(kurMPCe, 'yt-live-chat-banner-renderer') || 0;
  9922. if (chatBanner) return;
  9923.  
  9924. let targetDropDown = null;
  9925. for (const dropdown of document.querySelectorAll('tp-yt-iron-dropdown.style-scope.yt-live-chat-app')) {
  9926. if (dropdown && dropdown.positionTarget === kurMP) {
  9927. targetDropDown = dropdown;
  9928. }
  9929. }
  9930.  
  9931. if (!targetDropDown) return;
  9932.  
  9933. if ((nszDropdown = targetDropDown)) {
  9934. muzTimestamp = Date.now();
  9935. evt.stopImmediatePropagation();
  9936. evt.stopPropagation();
  9937. currentMenuPivotWR = mWeakRef(kurMPCe);
  9938.  
  9939. const listenOpts = { capture: true, passive: false, once: true };
  9940.  
  9941. // remove unexcecuted eventHandler
  9942. document.removeEventListener('mouseup', handlerObject, listenOpts);
  9943. document.removeEventListener('mouseleave', handlerObject, listenOpts);
  9944. document.removeEventListener('tap', handlerObject, listenOpts);
  9945. document.removeEventListener('click', handlerObject, listenOpts);
  9946.  
  9947. // inject one time eventHandler to by pass events
  9948. document.addEventListener('mouseup', handlerObject, listenOpts);
  9949. document.addEventListener('mouseleave', handlerObject, listenOpts);
  9950. document.addEventListener('tap', handlerObject, listenOpts);
  9951. document.addEventListener('click', handlerObject, listenOpts);
  9952.  
  9953. }
  9954.  
  9955. }, true);
  9956.  
  9957. }
  9958.  
  9959.  
  9960. // yt-live-chat-paid-message-renderer ??
  9961.  
  9962. /*
  9963.  
  9964. [...(new Set([...document.querySelectorAll('*')].filter(e=>e.is&&('shouldSupportWholeItemClick' in e)).map(e=>e.is))).keys()]
  9965.  
  9966.  
  9967. "yt-live-chat-ticker-paid-message-item-renderer"
  9968. "yt-live-chat-ticker-paid-sticker-item-renderer"
  9969. "yt-live-chat-paid-message-renderer"
  9970. "yt-live-chat-text-message-renderer"
  9971. "yt-live-chat-paid-sticker-renderer"
  9972.  
  9973. */
  9974.  
  9975.  
  9976. whenDefinedMultiple([
  9977.  
  9978. "yt-live-chat-paid-message-renderer",
  9979. "yt-live-chat-membership-item-renderer",
  9980. "yt-live-chat-paid-sticker-renderer",
  9981. "yt-live-chat-text-message-renderer",
  9982. "yt-live-chat-auto-mod-message-renderer",
  9983.  
  9984. /*
  9985. "yt-live-chat-ticker-paid-message-item-renderer",
  9986. "yt-live-chat-ticker-paid-sticker-item-renderer",
  9987. "yt-live-chat-paid-message-renderer",
  9988. "yt-live-chat-text-message-renderer",
  9989. "yt-live-chat-paid-sticker-renderer",
  9990.  
  9991. "yt-live-chat-ticker-sponsor-item-renderer",
  9992. "yt-live-chat-banner-header-renderer",
  9993. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  9994. "ytd-sponsorships-live-chat-header-renderer",
  9995. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  9996.  
  9997.  
  9998.  
  9999.  
  10000. "yt-live-chat-auto-mod-message-renderer",
  10001. "yt-live-chat-text-message-renderer",
  10002. "yt-live-chat-paid-message-renderer",
  10003.  
  10004. "yt-live-chat-legacy-paid-message-renderer",
  10005. "yt-live-chat-membership-item-renderer",
  10006. "yt-live-chat-paid-sticker-renderer",
  10007. "yt-live-chat-donation-announcement-renderer",
  10008. "yt-live-chat-moderation-message-renderer",
  10009. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  10010. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  10011. "yt-live-chat-viewer-engagement-message-renderer",
  10012.  
  10013. */
  10014.  
  10015.  
  10016. ]).then(sTags => {
  10017. // return; // M33
  10018.  
  10019. if (FLAG_001e) return;
  10020.  
  10021. mightFirstCheckOnYtInit();
  10022. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-message-renderer(s)... hacks");
  10023. console.log("[Begin]");
  10024. let doMouseHook = false;
  10025.  
  10026. const dProto = {
  10027. isClickableChatRow111: function () {
  10028. return (
  10029. this.data && typeof this.shouldSupportWholeItemClick === 'function' && typeof this.hasModerationOverlayVisible === 'function' &&
  10030. this.data.contextMenuEndpoint && this.wholeMessageClickable && this.shouldSupportWholeItemClick() && !this.hasModerationOverlayVisible()
  10031. ); // follow .onItemTap(a)
  10032. }
  10033. };
  10034.  
  10035. for (const sTag of sTags) { // ##tag##
  10036.  
  10037.  
  10038. (() => {
  10039.  
  10040. const tag = sTag;
  10041. const dummy = document.createElement(tag);
  10042.  
  10043. const cProto = getProto(dummy);
  10044. if (!cProto || !cProto.attached) {
  10045. console.warn(`proto.attached for ${tag} is unavailable.`);
  10046. return;
  10047. }
  10048.  
  10049. const dCnt = insp(dummy);
  10050. if ('wholeMessageClickable' in dCnt && typeof dCnt.hasModerationOverlayVisible === 'function' && typeof dCnt.shouldSupportWholeItemClick === 'function') {
  10051.  
  10052. cProto.isClickableChatRow111 = dProto.isClickableChatRow111;
  10053.  
  10054. const toHookDocumentMouseDown = typeof cProto.shouldSupportWholeItemClick === 'function' && typeof cProto.hasModerationOverlayVisible === 'function';
  10055.  
  10056. if (toHookDocumentMouseDown) {
  10057. doMouseHook = true;
  10058. }
  10059.  
  10060. console.log("shouldSupportWholeItemClick Y", tag);
  10061.  
  10062. } else {
  10063.  
  10064. console.log("shouldSupportWholeItemClick N", tag);
  10065. }
  10066.  
  10067.  
  10068. })();
  10069.  
  10070. }
  10071.  
  10072.  
  10073. if (doMouseHook) {
  10074.  
  10075. hookDocumentMouseDownSetupFn();
  10076.  
  10077. console.log("FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK - Doc MouseEvent OK");
  10078. }
  10079.  
  10080. console.log("[End]");
  10081.  
  10082. console.groupEnd();
  10083.  
  10084.  
  10085. }).catch(console.warn);
  10086.  
  10087.  
  10088. // https://www.youtube.com/watch?v=oQzFi1NO7io
  10089.  
  10090.  
  10091. }
  10092.  
  10093. if (NO_ITEM_TAP_FOR_NON_STATIONARY_TAP) {
  10094. let targetElementCntWR = null;
  10095. let _e0 = null;
  10096. document.addEventListener('mousedown', (e) => {
  10097. if (!e || !e.isTrusted) return;
  10098. let element = e.target;
  10099. for (; element instanceof HTMLElement; element = element.parentNode) {
  10100. if (element.is) break;
  10101. }
  10102. if (!element || !element.is) return;
  10103. const cnt = insp(element);
  10104. if (typeof cnt.onItemTap === 'function') {
  10105. cnt._onItemTap_isNonStationary = 0;
  10106. const cProto = getProto(element);
  10107. if (!cProto.onItemTap366 && typeof cProto.onItemTap === 'function' && cProto.onItemTap.length === 1) {
  10108. cProto.onItemTap366 = cProto.onItemTap; // note: [onItemTap] .some(function(){...})
  10109. cProto.onItemTap = function (a) {
  10110. const t = this._onItemTap_isNonStationary;
  10111. this._onItemTap_isNonStationary = 0;
  10112. if (t > Date.now()) return;
  10113. return this.onItemTap366.apply(this, arguments)
  10114. }
  10115. }
  10116. _e0 = e;
  10117. targetElementCntWR = mWeakRef(cnt);
  10118. } else {
  10119. _e0 = null;
  10120. targetElementCntWR = null;
  10121. }
  10122. }, { capture: true, passive: true });
  10123.  
  10124. document.addEventListener('mouseup', (e) => {
  10125. if (!e || !e.isTrusted) return;
  10126. const e0 = _e0;
  10127. _e0 = null;
  10128. if (!e0) return;
  10129. const cnt = kRef(targetElementCntWR);
  10130. targetElementCntWR = null;
  10131. if (!cnt) return;
  10132. if (e.timeStamp - e0.timeStamp > TAP_ACTION_DURATION) {
  10133. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10134. } else if ((window.getSelection() + "").trim().replace(/[\u2000-\u200a\u202f\u2800\u200B\u200C\u200D\uFEFF]+/g, '').length >= 1) {
  10135. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10136. } else {
  10137. const dx = e.clientX - e0.clientX;
  10138. const dy = e.clientY - e0.clientY;
  10139. const dd = Math.sqrt(dx * dx + dy * dy);
  10140. const ddmm = px2mm(dd);
  10141. if (ddmm > 1.0) {
  10142. cnt._onItemTap_isNonStationary = Date.now() + 40;
  10143. } else {
  10144. cnt._onItemTap_isNonStationary = 0;
  10145. }
  10146. }
  10147. }, { capture: true, passive: true });
  10148.  
  10149. }
  10150.  
  10151.  
  10152. const __showContextMenu_assign_lock_with_external_unlock_ = function (targetCnt) {
  10153.  
  10154. let rr = null;
  10155. const p1 = new Promise(resolve => {
  10156. rr = resolve;
  10157. });
  10158.  
  10159. const p1unlock = () => {
  10160. const f = rr;
  10161. if (f) {
  10162. rr = null;
  10163. f();
  10164. }
  10165. }
  10166.  
  10167. return {
  10168. p1,
  10169. p1unlock,
  10170. assignLock: (targetCnt, timeout) => {
  10171. targetCnt.__showContextMenu_assign_lock__(p1);
  10172. if (timeout) setTimeout(p1unlock, timeout);
  10173. }
  10174. }
  10175.  
  10176. }
  10177.  
  10178. if (PREREQUEST_CONTEXT_MENU_ON_MOUSE_DOWN) {
  10179.  
  10180. document.addEventListener('mousedown', function (evt) {
  10181.  
  10182. const maxloopDOMTreeElements = 4;
  10183. const maxloopYtCompontents = 4;
  10184. let j1 = 0;
  10185. let j2 = 0;
  10186. let target = (evt || 0).target || 0;
  10187. if (!target) return;
  10188.  
  10189.  
  10190. while (target instanceof HTMLElement) {
  10191. if (++j1 > maxloopDOMTreeElements) break;
  10192. if (typeof (target.is || insp(target).is || null) === 'string') break;
  10193. target = nodeParent(target);
  10194. }
  10195. const components = [];
  10196. while (target instanceof HTMLElement) {
  10197. if (++j2 > maxloopYtCompontents) break;
  10198. const cnt = insp(target);
  10199. if (typeof (target.is || cnt.is || null) === 'string') {
  10200. components.push(target);
  10201. }
  10202. if (typeof cnt.showContextMenu === 'function') break;
  10203. target = target.parentComponent || cnt.parentComponent || null;
  10204. }
  10205. if (!(target instanceof HTMLElement)) return;
  10206. const targetCnt = insp(target);
  10207. if (typeof targetCnt.handleGetContextMenuResponse_ !== 'function' || typeof targetCnt.handleGetContextMenuError !== 'function') {
  10208. console.log('Error Found: handleGetContextMenuResponse_ OR handleGetContextMenuError is not defined on a component with showContextMenu')
  10209. return;
  10210. }
  10211.  
  10212. const endpoint = (targetCnt.data || 0).contextMenuEndpoint
  10213. if (!endpoint) return;
  10214. if (targetCnt.opened || !targetCnt.isAttached) return;
  10215.  
  10216. if (typeof targetCnt.__cacheResolvedEndpointData__ !== 'function') {
  10217. console.log(`preRequest for showContextMenu in ${targetCnt.is} is not yet supported.`)
  10218. }
  10219.  
  10220. const targetDollar = indr(target);
  10221.  
  10222. let doPreRequest = false;
  10223. if (components.length >= 2 && components[0].id === 'menu-button' && (targetDollar || 0)['menu-button'] === components[0]) {
  10224. doPreRequest = true;
  10225. } else if (components.length === 1 && components[0] === target) {
  10226. doPreRequest = true;
  10227. } else if (components.length >= 2 && components[0].id === 'author-photo' && (targetDollar || 0)['author-photo'] === components[0]) {
  10228. doPreRequest = true;
  10229. }
  10230. if (doPreRequest === false) {
  10231. console.log('doPreRequest = fasle on showContextMenu', components);
  10232. return;
  10233. }
  10234.  
  10235. if (typeof targetCnt.__getCachedEndpointData__ !== 'function' || targetCnt.__getCachedEndpointData__(endpoint)) return;
  10236.  
  10237. if ((typeof targetCnt.__showContextMenu_mutex_unlock_isEmpty__ === 'function') && !targetCnt.__showContextMenu_mutex_unlock_isEmpty__()) {
  10238. console.log('preRequest on showContextMenu aborted due to stacked network request');
  10239. return;
  10240. }
  10241.  
  10242.  
  10243. const onSuccess = (a) => {
  10244. /*
  10245.  
  10246. dQ() && (a = a.response);
  10247. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && this.showContextMenu_(a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  10248. a.actions && Eu(this.hostElement, "yt-live-chat-actions", [a.actions])
  10249.  
  10250. */
  10251.  
  10252. a = a.response || a;
  10253.  
  10254. if (!a) {
  10255. console.log('unexpected error in prerequest for showContextMenu.onSuccess');
  10256. return;
  10257. }
  10258.  
  10259. let z = null;
  10260. a.liveChatItemContextMenuSupportedRenderers && a.liveChatItemContextMenuSupportedRenderers.menuRenderer && (z = a.liveChatItemContextMenuSupportedRenderers.menuRenderer);
  10261.  
  10262. if (z) {
  10263. a = z;
  10264. targetCnt.__cacheResolvedEndpointData__(endpoint, a, true);
  10265. }
  10266.  
  10267. };
  10268. const onFailure = (a) => {
  10269.  
  10270. /*
  10271.  
  10272. if (a instanceof Error || a instanceof Object || a instanceof String)
  10273. var b = a;
  10274. hq(new xm("Error encountered calling GetLiveChatItemContextMenu",b))
  10275.  
  10276. */
  10277.  
  10278. targetCnt.__cacheResolvedEndpointData__(endpoint, null);
  10279. // console.log('onFailure', a)
  10280.  
  10281. };
  10282.  
  10283. if (doPreRequest) {
  10284.  
  10285. let propertyCounter = 0;
  10286. const pm1 = __showContextMenu_assign_lock_with_external_unlock_(targetCnt);
  10287. const p1Timeout = 800;
  10288. const proxyKey = '__$$__proxy_to_this__$$__' + Date.now();
  10289.  
  10290. try {
  10291.  
  10292. const onSuccessHelperFn = function () {
  10293. pm1.p1unlock();
  10294. if (propertyCounter !== 5) {
  10295. console.log('Error in prerequest for showContextMenu.onSuccessHelperFn')
  10296. return;
  10297. }
  10298. if (this[proxyKey] !== targetCnt) {
  10299. console.log('Error in prerequest for showContextMenu.this');
  10300. return;
  10301. }
  10302. onSuccess(...arguments);
  10303. };
  10304. const onFailureHelperFn = function () {
  10305. pm1.p1unlock();
  10306. if (propertyCounter !== 5) {
  10307. console.log('Error in prerequest for showContextMenu.onFailureHelperFn')
  10308. return;
  10309. }
  10310. if (this[proxyKey] !== targetCnt) {
  10311. console.log('Error in prerequest for showContextMenu.this');
  10312. return;
  10313. }
  10314. onFailure(...arguments);
  10315.  
  10316. }
  10317. const fakeTargetCnt = new Proxy({
  10318. __showContextMenu_forceNativeRequest__: 1,
  10319. get handleGetContextMenuResponse_() {
  10320. propertyCounter += 2;
  10321. return onSuccessHelperFn;
  10322. },
  10323. get handleGetContextMenuError() {
  10324. propertyCounter += 3;
  10325. return onFailureHelperFn;
  10326. }
  10327. }, {
  10328. get(_, key, receiver) {
  10329. if (key in _) return _[key];
  10330. if (key === proxyKey) return targetCnt;
  10331.  
  10332. let giveNative = false;
  10333. if (key in targetCnt) {
  10334. if (key === 'data') giveNative = true;
  10335. else if (typeof targetCnt[key] === 'function') giveNative = true;
  10336. }
  10337. if (giveNative) return targetCnt[key];
  10338. }
  10339. });
  10340.  
  10341. const fakeEvent = (() => {
  10342. const { target, bubbles, cancelable, cancelBubble, srcElement, timeStamp, defaultPrevented, currentTarget, composed } = evt;
  10343. const nf = function () { }
  10344. const [stopPropagation, stopImmediatePropagation, preventDefault] = [nf, nf, nf];
  10345.  
  10346. return {
  10347. type: 'tap',
  10348. eventPhase: 0,
  10349. isTrusted: false,
  10350. __composed: true,
  10351. bubbles, cancelable, cancelBubble, timeStamp,
  10352. target, srcElement, defaultPrevented, currentTarget, composed,
  10353. stopPropagation, stopImmediatePropagation, preventDefault
  10354. };
  10355. })(evt);
  10356. targetCnt.showContextMenu.call(fakeTargetCnt, fakeEvent);
  10357.  
  10358.  
  10359. } catch (e) {
  10360. console.warn(e);
  10361. propertyCounter = 7;
  10362.  
  10363. }
  10364. if (propertyCounter !== 5) {
  10365. console.log('Error in prerequest for showContextMenu', propertyCounter);
  10366. return;
  10367. }
  10368.  
  10369. pm1.assignLock(targetCnt, p1Timeout);
  10370.  
  10371. }
  10372.  
  10373.  
  10374.  
  10375.  
  10376.  
  10377.  
  10378. }, true);
  10379.  
  10380.  
  10381. }
  10382.  
  10383.  
  10384.  
  10385. /*
  10386.  
  10387. const w=new Set(); for(const a of document.getElementsByTagName('*')) if(a.showContextMenu && a.showContextMenu_) w.add(a.is||''); console.log([...w.keys()])
  10388.  
  10389. */
  10390.  
  10391. whenDefinedMultiple([
  10392. "yt-live-chat-ticker-sponsor-item-renderer",
  10393. "yt-live-chat-ticker-paid-message-item-renderer",
  10394.  
  10395. "yt-live-chat-banner-header-renderer",
  10396. "yt-live-chat-text-message-renderer",
  10397. "ytd-sponsorships-live-chat-gift-purchase-announcement-renderer",
  10398. "ytd-sponsorships-live-chat-header-renderer",
  10399. "ytd-sponsorships-live-chat-gift-redemption-announcement-renderer",
  10400.  
  10401. "yt-live-chat-paid-sticker-renderer",
  10402. "yt-live-chat-viewer-engagement-message-renderer",
  10403. "yt-live-chat-paid-message-renderer"
  10404.  
  10405.  
  10406.  
  10407.  
  10408. ]).then(sTags => {
  10409.  
  10410. if (FLAG_001f) return;
  10411.  
  10412. mightFirstCheckOnYtInit();
  10413. groupCollapsed("YouTube Super Fast Chat", " | fixShowContextMenu");
  10414. console.log("[Begin]");
  10415.  
  10416.  
  10417. const __showContextMenu_mutex__ = new Mutex();
  10418. let __showContextMenu_mutex_unlock__ = null;
  10419. let lastShowMenuTarget = null;
  10420.  
  10421.  
  10422.  
  10423.  
  10424. const wm37 = new WeakMap();
  10425.  
  10426. const dProto = {
  10427.  
  10428.  
  10429. // CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN
  10430.  
  10431. __cacheResolvedEndpointData__: (endpoint, a, doDeepCopy) => {
  10432. if (a) {
  10433. if (doDeepCopy) a = deepCopy(a);
  10434. wm37.set(endpoint, a);
  10435. } else {
  10436. wm37.remove(endpoint);
  10437. }
  10438. },
  10439. __getCachedEndpointData__: function (endpoint) {
  10440. endpoint = endpoint || (this.data || 0).contextMenuEndpoint || 0;
  10441. if (endpoint) return wm37.get(endpoint);
  10442. return null;
  10443. },
  10444. /** @type {(resolvedEndpoint: any) => void 0} */
  10445. __showCachedContextMenu__: function (resolvedEndpoint) { // non-null
  10446.  
  10447. resolvedEndpoint = deepCopy(resolvedEndpoint);
  10448. // let b = deepCopy(resolvedEndpoint, ['trackingParams', 'clickTrackingParams'])
  10449. Promise.resolve(resolvedEndpoint).then((resolvedEndpoint) => {
  10450. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 1;
  10451. this.showContextMenu_(resolvedEndpoint);
  10452. this.__showContextMenu_skip_cacheResolvedEndpointData__ = 0;
  10453. resolvedEndpoint = null;
  10454. });
  10455.  
  10456.  
  10457. },
  10458.  
  10459.  
  10460.  
  10461. showContextMenuForCacheReopen: function (a) {
  10462. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37(a);
  10463. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10464. if (!this.__showContextMenu_forceNativeRequest__) {
  10465. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10466. if (endpoint) {
  10467. const resolvedEndpoint = this.__getCachedEndpointData__(endpoint);
  10468. if (resolvedEndpoint) {
  10469. this.__showCachedContextMenu__(resolvedEndpoint);
  10470. a && a.stopPropagation()
  10471. return;
  10472. }
  10473. }
  10474. }
  10475. return this.showContextMenu37(a);
  10476. },
  10477.  
  10478. showContextMenuForCacheReopen_: function (a) {
  10479. if (this && this.__showContextMenu_forceNativeRequest__) return this.showContextMenu37_(a);
  10480. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10481. if (!this.__showContextMenu_skip_cacheResolvedEndpointData__) {
  10482. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10483. if (endpoint) {
  10484. const f = this.__cacheResolvedEndpointData__;
  10485. if (typeof f === 'function') f(endpoint, a, true);
  10486. }
  10487. }
  10488. return this.showContextMenu37_(a);
  10489. },
  10490.  
  10491. // ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU
  10492.  
  10493. showContextMenuWithDisableScroll: function (a) {
  10494.  
  10495. const endpoint = (this.data || 0).contextMenuEndpoint || 0;
  10496. if (endpoint && typeof this.is === 'string' && this.menuVisible === false && this.menuOpen === false) {
  10497.  
  10498. const parentComponent = this.parentComponent;
  10499. if (parentComponent && parentComponent.is === 'yt-live-chat-item-list-renderer' && parentComponent.contextMenuOpen === false && parentComponent.allowScroll === true) {
  10500. parentComponent.contextMenuOpen = true; // computeAllowScroll_(contextMenuOpen, moderationModeEnabled): allowScroll = !(contextMenuOpen || moderationModeEnabled)
  10501. }
  10502. }
  10503.  
  10504. return this.showContextMenu48.apply(this, arguments);
  10505.  
  10506. },
  10507.  
  10508. // ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU
  10509.  
  10510. __showContextMenu_mutex_unlock_isEmpty__: () => {
  10511. return __showContextMenu_mutex_unlock__ === null;
  10512. },
  10513.  
  10514. __showContextMenu_assign_lock__: function (p) {
  10515.  
  10516. const mutex = __showContextMenu_mutex__;
  10517.  
  10518. mutex.lockWith(unlock => {
  10519. p.then(unlock);
  10520. p = null;
  10521. unlock = null;
  10522. });
  10523.  
  10524. },
  10525.  
  10526. showContextMenuWithMutex: function (a) {
  10527. if (this.__showContextMenu_forceNativeRequest__) return this.showContextMenu47(a);
  10528. if (!this || !this.isAttached) return; // in case; avoid Error: No provider for: InjectionToken(NETWORK_TOKEN) in _.showContextMenu
  10529. lastShowMenuTarget = this;
  10530. const wNode = mWeakRef(this);
  10531.  
  10532.  
  10533. const mutex = __showContextMenu_mutex__;
  10534.  
  10535. mutex.lockWith(unlock => {
  10536. const cnt = kRef(wNode);
  10537. if (lastShowMenuTarget !== cnt || !cnt) {
  10538. unlock();
  10539. return;
  10540. }
  10541.  
  10542. setTimeout(unlock, 800); // in case network failure
  10543. __showContextMenu_mutex_unlock__ = unlock;
  10544. try {
  10545. cnt.showContextMenu47(a);
  10546. } catch (e) {
  10547. console.warn(e);
  10548. unlock(); // in case function script error
  10549. }
  10550.  
  10551. });
  10552.  
  10553.  
  10554. },
  10555.  
  10556. showContextMenuWithMutex_: function (a) {
  10557.  
  10558. if (__showContextMenu_mutex_unlock__ && this === lastShowMenuTarget) {
  10559. __showContextMenu_mutex_unlock__();
  10560. __showContextMenu_mutex_unlock__ = null;
  10561. }
  10562. return this.showContextMenu47_(a);
  10563.  
  10564. }
  10565.  
  10566. }
  10567.  
  10568. for (const tag of sTags) { // ##tag##
  10569.  
  10570. (() => {
  10571.  
  10572. const dummy = document.createElement(tag);
  10573.  
  10574. const cProto = getProto(dummy);
  10575. if (!cProto || !cProto.attached) {
  10576. console.warn(`proto.attached for ${tag} is unavailable.`);
  10577. return;
  10578. }
  10579.  
  10580.  
  10581. 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) {
  10582. cProto.showContextMenu37_ = cProto.showContextMenu_;
  10583. cProto.showContextMenu37 = cProto.showContextMenu;
  10584. cProto.__showContextMenu_forceNativeRequest__ = 0;
  10585. cProto.__cacheResolvedEndpointData__ = dProto.__cacheResolvedEndpointData__
  10586. cProto.__getCachedEndpointData__ = dProto.__getCachedEndpointData__
  10587. cProto.__showCachedContextMenu__ = dProto.__showCachedContextMenu__
  10588. cProto.showContextMenu = dProto.showContextMenuForCacheReopen;
  10589. cProto.showContextMenu_ = dProto.showContextMenuForCacheReopen_;
  10590. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - OK", tag);
  10591. } else {
  10592. console.log("CACHE_SHOW_CONTEXT_MENU_FOR_REOPEN - NG", tag);
  10593. }
  10594.  
  10595. 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) {
  10596. cProto.showContextMenu48 = cProto.showContextMenu;
  10597. cProto.showContextMenu = dProto.showContextMenuWithDisableScroll;
  10598. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10599. } else if (!ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU) {
  10600. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - N/A", tag);
  10601. } else {
  10602. console.log("ADVANCED_NOT_ALLOW_SCROLL_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10603. }
  10604.  
  10605.  
  10606. 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) {
  10607. cProto.showContextMenu47_ = cProto.showContextMenu_;
  10608. cProto.showContextMenu47 = cProto.showContextMenu;
  10609. cProto.__showContextMenu_mutex_unlock_isEmpty__ = dProto.__showContextMenu_mutex_unlock_isEmpty__;
  10610. cProto.__showContextMenu_assign_lock__ = dProto.__showContextMenu_assign_lock__;
  10611. cProto.showContextMenu = dProto.showContextMenuWithMutex;
  10612. cProto.showContextMenu_ = dProto.showContextMenuWithMutex_;
  10613. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - OK", tag);
  10614. } else {
  10615. console.log("ENABLE_MUTEX_FOR_SHOW_CONTEXT_MENU - NG", tag);
  10616. }
  10617.  
  10618. })();
  10619.  
  10620. }
  10621.  
  10622. console.log("[End]");
  10623.  
  10624. console.groupEnd();
  10625.  
  10626. }).catch(console.warn);
  10627.  
  10628.  
  10629.  
  10630. if (FIX_UNKNOWN_BUG_FOR_OVERLAY) {
  10631. // this is to fix " TypeError: this.backdropElement.prepare is not a function "
  10632.  
  10633. customElements.whenDefined('tp-yt-paper-dialog').then(() => {
  10634.  
  10635.  
  10636. mightFirstCheckOnYtInit();
  10637. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-paper-dialog hacks");
  10638. console.log("[Begin]");
  10639. (() => {
  10640.  
  10641. const tag = "tp-yt-paper-dialog";
  10642. const dummy = document.createElement(tag);
  10643.  
  10644. const cProto = getProto(dummy);
  10645. if (!cProto || !cProto.attached) {
  10646. console.warn(`proto.attached for ${tag} is unavailable.`);
  10647. return;
  10648. }
  10649.  
  10650. if (typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged49 && cProto.__openedChanged.length === 0) {
  10651.  
  10652.  
  10653. cProto.__openedChanged49 = cProto.__openedChanged;
  10654.  
  10655. cProto.__openedChanged = function () {
  10656. const manager = (this || 0)._manager || 0;
  10657. if (manager && !manager.trackBackdrop49 && manager.trackBackdrop) {
  10658. manager.trackBackdrop49 = manager.trackBackdrop;
  10659. if (manager.trackBackdrop.length === 0) {
  10660. manager.trackBackdrop = function () {
  10661. try {
  10662. return this.trackBackdrop49();
  10663. } catch (e) {
  10664. let showMessage = true;
  10665. if (e instanceof TypeError && e.message === 'this.backdropElement.prepare is not a function') {
  10666. // this is well known issue.
  10667. showMessage = false;
  10668. }
  10669. showMessage && console.log('manager.trackBackdrop', e);
  10670. }
  10671. }
  10672. }
  10673. }
  10674. return this.__openedChanged49();
  10675. };
  10676.  
  10677.  
  10678. }
  10679.  
  10680.  
  10681. })();
  10682.  
  10683.  
  10684.  
  10685. });
  10686.  
  10687. }
  10688.  
  10689.  
  10690. customElements.whenDefined('tp-yt-iron-dropdown').then(() => {
  10691.  
  10692. mightFirstCheckOnYtInit();
  10693. groupCollapsed("YouTube Super Fast Chat", " | tp-yt-iron-dropdown hacks");
  10694. console.log("[Begin]");
  10695. (() => {
  10696.  
  10697. const tag = "tp-yt-iron-dropdown";
  10698. const dummy = document.createElement(tag);
  10699.  
  10700. const cProto = getProto(dummy);
  10701. if (!cProto || !cProto.attached) {
  10702. console.warn(`proto.attached for ${tag} is unavailable.`);
  10703. return;
  10704. }
  10705.  
  10706. if (USE_VANILLA_DEREF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf34 && fnIntegrity(cProto.__deraf) === '2.42.24') {
  10707. cProto.__deraf_hn__ = function (sId, fn) {
  10708. const rhKey = `_rafHandler_${sId}`;
  10709. const m = this[rhKey] || (this[rhKey] = new WeakMap());
  10710. if (m.has(fn)) return m.get(fn);
  10711. const resFn = () => {
  10712. this.__rafs[sId] = null;
  10713. fn.call(this)
  10714. };
  10715. m.set(fn, resFn);
  10716. m.set(resFn, resFn);
  10717. return resFn;
  10718. };
  10719. cProto.__deraf34 = cProto.__deraf;
  10720. cProto.__deraf = function (a, b) { // sId, fn
  10721. let c = this.__rafs;
  10722. null !== c[a] && cancelAnimationFrame(c[a]);
  10723. c[a] = requestAnimationFrame(this.__deraf_hn__(a, b));
  10724. };
  10725. console.log("USE_VANILLA_DEREF - OK");
  10726. } else {
  10727. console.log("USE_VANILLA_DEREF - NG");
  10728. }
  10729.  
  10730. if (FIX_DROPDOWN_DERAF && typeof cProto.__deraf === 'function' && cProto.__deraf.length === 2 && !cProto.__deraf66) {
  10731. cProto.__deraf66 = cProto.__deraf;
  10732. cProto.__deraf = function (sId, fn) {
  10733. if (this.__byPassRAF__) {
  10734. Promise.resolve(this).then((cnt) => {
  10735. fn.call(cnt);
  10736. cnt = null;
  10737. });
  10738. }
  10739. let r = this.__deraf66.apply(this, arguments);
  10740. return r;
  10741. }
  10742. console.log("FIX_DROPDOWN_DERAF - OK");
  10743. } else {
  10744. console.log("FIX_DROPDOWN_DERAF - NG");
  10745. }
  10746.  
  10747.  
  10748. if (BOOST_MENU_OPENCHANGED_RENDERING && typeof cProto.__openedChanged === 'function' && !cProto.__mtChanged__ && fnIntegrity(cProto.__openedChanged) === '0.46.20') {
  10749.  
  10750. let lastClose = null;
  10751. let lastOpen = null;
  10752. let cid = 0;
  10753.  
  10754. cProto.__mtChanged__ = function (b) {
  10755.  
  10756. Promise.resolve(this).then((cnt) => {
  10757. cnt._applyFocus();
  10758. return cnt;
  10759. }).then((cnt) => {
  10760. b ? cnt._renderOpened() : cnt._renderClosed();
  10761. cnt = null;
  10762. }).catch(console.warn);
  10763.  
  10764. };
  10765.  
  10766. const __moChanged__ = () => {
  10767. if (!cid) return;
  10768. // console.log(553, !!lastOpen, !!lastClose);
  10769. cid = 0;
  10770. if (lastOpen && !lastClose && lastOpen.isAttached) {
  10771. lastOpen.__mtChanged__(1)
  10772. } else if (lastClose && !lastOpen && lastClose.isAttached) {
  10773. lastClose.__mtChanged__(0);
  10774. }
  10775. lastOpen = null;
  10776. lastClose = null;
  10777. };
  10778.  
  10779.  
  10780. if (typeof cProto._openedChanged === 'function' && !cProto._openedChanged66) {
  10781. cProto._openedChanged66 = cProto._openedChanged;
  10782. cProto._openedChanged = function () {
  10783. // this.__byPassRAF__ = !lastOpen ? true : false; // or just true?
  10784. this.__byPassRAF__ = true;
  10785. let r = this._openedChanged66.apply(this, arguments);
  10786. this.__byPassRAF__ = false;
  10787. return r;
  10788. }
  10789. }
  10790.  
  10791. const pSetGet = (key, pdThis, pdBase) => {
  10792. // note: this is not really a standard way for the getOwnPropertyDescriptors; but it is sufficient to make the job done
  10793. return {
  10794. get: (pdThis[key] || 0).get || (pdBase[key] || 0).get,
  10795. set: (pdThis[key] || 0).set || (pdBase[key] || 0).set
  10796. };
  10797. };
  10798.  
  10799. cProto.__modifiedMenuPropsFn__ = function () {
  10800. const pdThis = Object.getOwnPropertyDescriptors(this.constructor.prototype)
  10801. const pdBase = Object.getOwnPropertyDescriptors(this)
  10802.  
  10803. const pdAutoFitOnAttach = pSetGet('autoFitOnAttach', pdThis, pdBase);
  10804. const pdExpandSizingTargetForScrollbars = pSetGet('expandSizingTargetForScrollbars', pdThis, pdBase);
  10805. const pdAllowOutsideScroll = pSetGet('allowOutsideScroll', pdThis, pdBase);
  10806.  
  10807. if (pdAutoFitOnAttach.get || pdAutoFitOnAttach.set) {
  10808. console.warn('there is setter/getter for autoFitOnAttach');
  10809. return;
  10810. }
  10811. if (pdExpandSizingTargetForScrollbars.get || pdExpandSizingTargetForScrollbars.set) {
  10812. console.warn('there is setter/getter for expandSizingTargetForScrollbars');
  10813. return;
  10814. }
  10815. if (!pdAllowOutsideScroll.get || !pdAllowOutsideScroll.set) {
  10816. console.warn('there is NO setter-getter for allowOutsideScroll');
  10817. return;
  10818. }
  10819.  
  10820. let { autoFitOnAttach, expandSizingTargetForScrollbars, allowOutsideScroll } = this;
  10821.  
  10822. this.__AllowOutsideScrollPD__ = pdAllowOutsideScroll;
  10823.  
  10824. const fitEnable = CHAT_MENU_REFIT_ALONG_SCROLLING === 2;
  10825.  
  10826. Object.defineProperties(this, {
  10827. autoFitOnAttach: {
  10828. get() {
  10829. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10830. return autoFitOnAttach;
  10831. },
  10832. set(nv) {
  10833. autoFitOnAttach = nv;
  10834. return true;
  10835. },
  10836. enumerable: true,
  10837. configurable: true
  10838. }, expandSizingTargetForScrollbars: {
  10839. get() {
  10840. if (fitEnable && this._modifiedMenuPropOn062__) return true;
  10841. return expandSizingTargetForScrollbars;
  10842. },
  10843. set(nv) {
  10844. expandSizingTargetForScrollbars = nv;
  10845. return true;
  10846. },
  10847. enumerable: true,
  10848. configurable: true
  10849. }, allowOutsideScroll: {
  10850. get() {
  10851. if (this._modifiedMenuPropOn062__) return true;
  10852. return allowOutsideScroll;
  10853. },
  10854. set(nv) {
  10855. allowOutsideScroll = nv;
  10856. this.__AllowOutsideScrollPD__.set.call(this, nv);
  10857. return true;
  10858. },
  10859. enumerable: true,
  10860. configurable: true
  10861. }
  10862. })
  10863. };
  10864.  
  10865. /*
  10866. // ***** position() to be changed. *****
  10867. tp-yt-iron-dropdown[class], tp-yt-iron-dropdown[class] #contentWrapper, tp-yt-iron-dropdown[class] ytd-menu-popup-renderer[class] {
  10868.  
  10869. overflow: visible !important;
  10870. min-width: max-content !important;
  10871. max-width: max-content !important;
  10872. max-height: max-content !important;
  10873. min-height: max-content !important;
  10874. white-space: nowrap;
  10875. }
  10876.  
  10877. */
  10878. if (FIX_MENU_POSITION_N_SIZING_ON_SHOWN && typeof cProto.position === 'function' && !cProto.position34 && typeof cProto.refit === 'function') {
  10879.  
  10880. let m34 = 0;
  10881. cProto.__refitByPosition__ = function () {
  10882. m34++;
  10883. if (m34 <= 0) m34 = 0;
  10884. if (m34 !== 1) return;
  10885. const hostElement = this.hostElement || this;
  10886. if (document.visibilityState === 'visible') {
  10887. const sizingTarget = this.sizingTarget;
  10888. if (!sizingTarget) {
  10889. m34 = 0;
  10890. return;
  10891. }
  10892. hostElement.setAttribute('rNgzQ', '');
  10893. sizingTarget.setAttribute('rNgzQ', '');
  10894.  
  10895. const gn = () => {
  10896. hostElement.removeAttribute('rNgzQ');
  10897. sizingTarget.removeAttribute('rNgzQ');
  10898. }
  10899.  
  10900. const an = async () => {
  10901. while (m34 >= 1) {
  10902. await renderReadyPn(sizingTarget);
  10903. if (this.opened && this.isAttached && sizingTarget.isConnected === true && sizingTarget === this.sizingTarget) {
  10904. if (sizingTarget.matches('ytd-menu-popup-renderer[slot="dropdown-content"].yt-live-chat-app')) this.refit();
  10905. }
  10906. m34--;
  10907. }
  10908. m34 = 0;
  10909. Promise.resolve().then(gn);
  10910. }
  10911. setTimeout(an, 4); // wait those resizing function calls
  10912.  
  10913.  
  10914. } else {
  10915. m34 = 0;
  10916. }
  10917. }
  10918. cProto.position34 = cProto.position
  10919. cProto.position = function () {
  10920. if (this._positionInitialize_) {
  10921. this._positionInitialize_ = 0;
  10922. this.__refitByPosition__();
  10923. }
  10924. let r = cProto.position34.apply(this, arguments);
  10925. return r;
  10926. }
  10927. console.log("FIX_MENU_POSITION_ON_SHOWN - OK");
  10928.  
  10929. } else {
  10930.  
  10931. console.log("FIX_MENU_POSITION_ON_SHOWN - NG");
  10932.  
  10933. }
  10934.  
  10935.  
  10936.  
  10937. cProto.__openedChanged = function () {
  10938. // console.log(123445)
  10939. this._positionInitialize_ = 1;
  10940. // this.removeAttribute('horizontal-align')
  10941. // this.removeAttribute('vertical-align')
  10942. if (typeof this.__menuTypeCheck__ !== 'boolean') {
  10943. this.__menuTypeCheck__ = true;
  10944. if (CHAT_MENU_SCROLL_UNLOCKING) {
  10945. this._modifiedMenuPropOn062__ = false;
  10946. // console.log(513, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  10947. // this.autoFitOnAttach = true;
  10948. // this.expandSizingTargetForScrollbars = true;
  10949. // this.allowOutsideScroll = true;
  10950. // console.log(519,Object.getOwnPropertyDescriptors(this.constructor.prototype))
  10951. this.__modifiedMenuPropsFn__();
  10952. // this.constrain= function(){}
  10953. // this.position= function(){}
  10954.  
  10955. // this.autoFitOnAttach = true;
  10956. // this.expandSizingTargetForScrollbars = true;
  10957. // this.allowOutsideScroll = true;
  10958. }
  10959. }
  10960. if (CHAT_MENU_SCROLL_UNLOCKING && this.opened) {
  10961. let newValue = null;
  10962. const positionTarget = this.positionTarget;
  10963. if (positionTarget && positionTarget.classList.contains('yt-live-chat-text-message-renderer')) {
  10964. if (this._modifiedMenuPropOn062__ === false) {
  10965. newValue = true;
  10966. }
  10967. } else if (this._modifiedMenuPropOn062__ === true) {
  10968. newValue = false;
  10969. }
  10970. if (newValue !== null) {
  10971. const beforeAllowOutsideScroll = this.allowOutsideScroll;
  10972. this._modifiedMenuPropOn062__ = newValue;
  10973. const afterAllowOutsideScroll = this.allowOutsideScroll;
  10974. if (beforeAllowOutsideScroll !== afterAllowOutsideScroll) this.__AllowOutsideScrollPD__.set.call(this, afterAllowOutsideScroll);
  10975. }
  10976. }
  10977.  
  10978. if (this.opened) {
  10979.  
  10980. Promise.resolve().then(() => {
  10981.  
  10982. this._prepareRenderOpened();
  10983. }).then(() => {
  10984. console.log('[yt-chat-dialog]', this._manager)
  10985. try{
  10986. this._manager.addOverlay(this);
  10987. }catch(e){
  10988. console.log('this._manager.addOverlay(this) fails.')
  10989. }
  10990. if (this._manager._overlays.length === 1) {
  10991. lastOpen = this;
  10992. lastClose = null;
  10993. } else {
  10994. return 1;
  10995. }
  10996. // if (cid) {
  10997. // clearTimeout(cid);
  10998. // cid = -1;
  10999. // this.__moChanged__();
  11000. // cid = 0;
  11001. // } else {
  11002. // cid = -1;
  11003. // this.__moChanged__();
  11004. // cid = 0;
  11005. // }
  11006. // cid = cid > 0 ? clearTimeout(cid) : 0;
  11007. // console.log(580, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  11008. // cid = cid || setTimeout(__moChanged__, delay1);
  11009. cid = cid || requestAnimationFrame(__moChanged__);
  11010. }).then((r) => {
  11011.  
  11012. if (r) this.__mtChanged__(1);
  11013. }).catch(console.warn);
  11014.  
  11015. } else {
  11016. Promise.resolve().then(() => {
  11017. console.log('[yt-chat-dialog]', this._manager)
  11018. try{
  11019. this._manager.removeOverlay(this);
  11020. }catch(e){
  11021. console.log('this._manager.removeOverlay(this) fails.')
  11022. }
  11023. if (this._manager._overlays.length === 0) {
  11024. lastClose = this;
  11025. lastOpen = null;
  11026. } else {
  11027. return 1;
  11028. }
  11029. // cid = cid > 0 ? clearTimeout(cid) : 0;
  11030. // console.log(581, this.positionTarget && this.positionTarget.classList.contains('yt-live-chat-text-message-renderer'))
  11031. // cid = cid || setTimeout(__moChanged__, delay1);
  11032. cid = cid || requestAnimationFrame(__moChanged__);
  11033. }).then((r) => {
  11034. if (r) this.__mtChanged__(0);
  11035. }).catch(console.warn);
  11036.  
  11037. }
  11038.  
  11039. }
  11040. console.log("BOOST_MENU_OPENCHANGED_RENDERING - OK");
  11041.  
  11042. } else {
  11043.  
  11044. assertor(() => fnIntegrity(cProto.__openedChanged, '0.46.20'));
  11045. console.log("FIX_MENU_REOPEN_RENDER_PERFORMANC_1 - NG");
  11046.  
  11047. }
  11048.  
  11049.  
  11050. if (FIX_CLICKING_MESSAGE_MENU_DISPLAY_ON_MOUSE_CLICK && typeof cProto.__openedChanged === 'function' && !cProto.__openedChanged82) {
  11051.  
  11052. cProto.__openedChanged82 = cProto.__openedChanged;
  11053.  
  11054.  
  11055. cProto.__openedChanged = function () {
  11056. const positionTarget = this.positionTarget;
  11057. currentMenuPivotWR = positionTarget ? mWeakRef(positionTarget) : null;
  11058. return this.__openedChanged82.apply(this, arguments);
  11059. }
  11060. }
  11061.  
  11062.  
  11063. })();
  11064.  
  11065. console.log("[End]");
  11066.  
  11067. console.groupEnd();
  11068.  
  11069. }).catch(console.warn);
  11070.  
  11071.  
  11072.  
  11073. FIX_ToggleRenderPolymerControllerExtractionBug && customElements.whenDefined('yt-live-chat-toggle-renderer').then(() => {
  11074.  
  11075. mightFirstCheckOnYtInit();
  11076. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-toggle-renderer hacks");
  11077. console.log("[Begin]");
  11078. (() => {
  11079.  
  11080. const tag = "yt-live-chat-toggle-renderer";
  11081. const dummy = document.createElement(tag);
  11082.  
  11083. const cProto = getProto(dummy);
  11084. if (!cProto || !cProto.attached) {
  11085. console.warn(`proto.attached for ${tag} is unavailable.`);
  11086. return;
  11087. }
  11088.  
  11089. })();
  11090.  
  11091. console.log("[End]");
  11092. console.groupEnd();
  11093.  
  11094. });
  11095.  
  11096.  
  11097.  
  11098.  
  11099. /*
  11100.  
  11101.  
  11102.  
  11103.  
  11104.  
  11105. var FU = function() {
  11106. var a = this;
  11107. this.nextHandle_ = 1;
  11108. this.clients_ = {};
  11109. this.JSC$10323_callbacks_ = {};
  11110. this.unsubscribeAsyncHandles_ = {};
  11111. this.subscribe = vl(function(b, c, d) {
  11112. var e = Geb(b);
  11113. if (e in a.clients_)
  11114. e in a.unsubscribeAsyncHandles_ && Jq.cancel(a.unsubscribeAsyncHandles_[e]);
  11115. else {
  11116. a: {
  11117. var h = Geb(b), l;
  11118. for (l in a.unsubscribeAsyncHandles_) {
  11119. var m = a.clients_[l];
  11120. if (m instanceof KO) {
  11121. delete a.clients_[l];
  11122. delete a.JSC$10323_callbacks_[l];
  11123. Jq.cancel(a.unsubscribeAsyncHandles_[l]);
  11124. delete a.unsubscribeAsyncHandles_[l];
  11125. i6a(m);
  11126. m.objectId_ = new FQa(h);
  11127. m.register();
  11128. d = m;
  11129. break a
  11130. }
  11131. }
  11132. d.objectSource = b.invalidationId.objectSource;
  11133. d.objectId = h;
  11134. if (b = b.webAuthConfigurationData)
  11135. b.multiUserSessionIndex && (d.sessionIndex = parseInt(b.multiUserSessionIndex, 10)),
  11136. b.pageId && (d.pageId = b.pageId);
  11137. d = new KO(d,a.handleInvalidationData_.bind(a));
  11138. d.register()
  11139. }
  11140. a.clients_[e] = d;
  11141. a.JSC$10323_callbacks_[e] = {}
  11142. }
  11143. d = a.nextHandle_++;
  11144. a.JSC$10323_callbacks_[e][d] = c;
  11145. return d
  11146. })
  11147. };
  11148. FU.prototype.unsubscribe = function(a, b) {
  11149. var c = Geb(a);
  11150. if (c in this.JSC$10323_callbacks_ && (delete this.JSC$10323_callbacks_[c][b],
  11151. !this.JSC$10323_callbacks_[c].length)) {
  11152. var d = this.clients_[c];
  11153. b = Jq.run(function() {
  11154. ei(d);
  11155. delete this.clients_[c];
  11156. delete this.unsubscribeAsyncHandles_[c]
  11157. }
  11158. .bind(this));
  11159. this.unsubscribeAsyncHandles_[c] = b
  11160. }
  11161. }
  11162. ;
  11163.  
  11164.  
  11165. */
  11166.  
  11167.  
  11168. const onManagerFound = (dummyManager) => {
  11169. if (!dummyManager || typeof dummyManager !== 'object') return;
  11170.  
  11171. const mgrProto = dummyManager.constructor.prototype;
  11172.  
  11173. let keyCallbackStore = '';
  11174. for (const [key, v] of Object.entries(dummyManager)) {
  11175. if (key.includes('_callbacks_')) keyCallbackStore = key;
  11176. }
  11177.  
  11178. if (!keyCallbackStore || typeof mgrProto.unsubscribe !== 'function' || mgrProto.unsubscribe.length !== 2) return;
  11179.  
  11180. if (mgrProto.unsubscribe16) return;
  11181.  
  11182. mgrProto.unsubscribe16 = mgrProto.unsubscribe;
  11183.  
  11184. groupCollapsed("YouTube Super Fast Chat", " | *live-chat-manager* hacks");
  11185. console.log("[Begin]");
  11186.  
  11187. const idMapper = new Map();
  11188.  
  11189. const convertId = function (objectId) {
  11190. if (!objectId || typeof objectId !== 'string') return null;
  11191.  
  11192. let result = idMapper.get(objectId)
  11193. if (result) return result;
  11194. result = atob(objectId.replace(/-/g, "+").replace(/_/g, "/"));
  11195. idMapper.set(objectId, result)
  11196. return result;
  11197. }
  11198.  
  11199.  
  11200. const rafHandleHolder = [];
  11201.  
  11202. let pzw = 0;
  11203. let lza = 0;
  11204. const rafHandlerFn = () => {
  11205. pzw = 0;
  11206. if (rafHandleHolder.length === 1) {
  11207. const f = rafHandleHolder[0];
  11208. rafHandleHolder.length = 0;
  11209. f();
  11210. } else if (rafHandleHolder.length > 1) {
  11211. const arr = rafHandleHolder.slice(0);
  11212. rafHandleHolder.length = 0;
  11213. for (const fn of arr) fn();
  11214. }
  11215. };
  11216.  
  11217.  
  11218. if (CHANGE_MANAGER_UNSUBSCRIBE) {
  11219.  
  11220. const checkIntegrityForSubscribe = (mgr) => {
  11221. if (mgr
  11222. && typeof mgr.unsubscribe16 === 'function' && mgr.unsubscribe16.length === 2
  11223. && typeof mgr.subscribe18 === 'function' && (mgr.subscribe18.length === 0 || mgr.subscribe18.length === 3)) {
  11224.  
  11225. const ns = new Set(Object.keys(mgr));
  11226. const ms = new Set(Object.keys(mgr.constructor.prototype));
  11227.  
  11228. if (ns.size >= 6 && ms.size >= 4) {
  11229. // including 'subscribe18'
  11230. // 'unsubscribe16', 'subscribe19'
  11231.  
  11232. let r = 0;
  11233. for (const k of ['nextHandle_', 'clients_', keyCallbackStore, 'unsubscribeAsyncHandles_', 'subscribe', 'subscribe18']) {
  11234. r += ns.has(k) ? 1 : 0;
  11235. }
  11236. for (const k of ['unsubscribe', 'handleInvalidationData_', 'unsubscribe16', 'subscribe19']) {
  11237. r += ms.has(k) ? 1 : 0;
  11238. }
  11239. if (r === 10) {
  11240. const isObject = (c) => (c || 0).constructor === Object;
  11241.  
  11242. if (isObject(mgr['clients_']) && isObject(mgr[keyCallbackStore]) && isObject(mgr['unsubscribeAsyncHandles_'])) {
  11243.  
  11244. return true;
  11245. }
  11246.  
  11247.  
  11248. }
  11249.  
  11250. }
  11251.  
  11252.  
  11253. }
  11254. return false;
  11255. }
  11256.  
  11257. mgrProto.subscribe19 = function (o, f, opts) {
  11258.  
  11259. const ct_clients_ = this.clients_ || 0;
  11260. const ct_handles_ = this.unsubscribeAsyncHandles_ || 0;
  11261.  
  11262. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.subscribe18.apply(this, arguments);
  11263.  
  11264. let objectId = ((o || 0).invalidationId || 0).objectId;
  11265. if (!objectId) return this.subscribe18.apply(this, arguments);
  11266. objectId = convertId(objectId);
  11267.  
  11268. // console.log('subscribe', objectId, ct_clients_[objectId], arguments);
  11269.  
  11270. if (ct_clients_[objectId]) {
  11271. if (ct_handles_[objectId] < 0) delete ct_handles_[objectId];
  11272. }
  11273.  
  11274. return this.subscribe18.apply(this, arguments);
  11275. }
  11276.  
  11277. mgrProto.unsubscribe = function (o, d) {
  11278. if (!this.subscribe18 && typeof this.subscribe === 'function') {
  11279. this.subscribe18 = this.subscribe;
  11280. this.subscribe = this.subscribe19;
  11281. this.__doCustomSubscribe__ = checkIntegrityForSubscribe(this);
  11282. }
  11283. const ct_clients_ = this.clients_;
  11284. const ct_handles_ = this.unsubscribeAsyncHandles_;
  11285. if (this.__doCustomSubscribe__ !== true || !ct_clients_ || !ct_handles_) return this.unsubscribe16.apply(this, arguments);
  11286.  
  11287. let objectId = ((o || 0).invalidationId || 0).objectId;
  11288. if (!objectId) return this.unsubscribe16.apply(this, arguments);
  11289.  
  11290. objectId = convertId(objectId);
  11291.  
  11292.  
  11293. // console.log('unsubscribe', objectId, ct_clients_[objectId], arguments);
  11294.  
  11295. const callbacks = this[keyCallbackStore] || 0;
  11296. const callbackObj = callbacks[objectId] || 0;
  11297.  
  11298.  
  11299. if (callbackObj && (delete callbackObj[d], isEmptyObject(callbackObj))) {
  11300. const w = ct_clients_[objectId];
  11301. --lza;
  11302. if (lza < -1e9) lza = -1;
  11303. const qta = lza;
  11304. rafHandleHolder.push(() => {
  11305. if (qta === ct_handles_[objectId]) {
  11306. const o = {
  11307. callbacks, callbackObj,
  11308. client: ct_clients_[objectId],
  11309. handle: ct_handles_[objectId]
  11310. };
  11311. let p = 0;
  11312. try {
  11313. if (ct_clients_[objectId] === w) {
  11314. w && "function" === typeof w.dispose && w.dispose();
  11315. delete ct_clients_[objectId];
  11316. delete ct_handles_[objectId];
  11317. p = 1;
  11318. } else {
  11319. // w && "function" === typeof w.dispose && w.dispose();
  11320. // delete ct_clients_[objectId];
  11321. // delete ct_handles_[objectId];
  11322. p = 2;
  11323. }
  11324. } catch (e) {
  11325. console.warn(e);
  11326. }
  11327. console.log(`unsubscribed: ${p}`, this, o);
  11328. }
  11329. });
  11330. ct_handles_[objectId] = qta;
  11331. if (pzw === 0) {
  11332. pzw = requestAnimationFrame(rafHandlerFn);
  11333. }
  11334. }
  11335. }
  11336.  
  11337.  
  11338. console.log("CHANGE_MANAGER_UNSUBSCRIBE - OK")
  11339.  
  11340. } else {
  11341.  
  11342. console.log("CHANGE_MANAGER_UNSUBSCRIBE - NG")
  11343. }
  11344.  
  11345. console.log("[End]");
  11346.  
  11347. console.groupEnd();
  11348.  
  11349. }
  11350.  
  11351.  
  11352.  
  11353. /*
  11354.  
  11355.  
  11356. a.prototype.async = function(e, h) {
  11357. return 0 < h ? Iq.run(e.bind(this), h) : ~Kq.run(e.bind(this))
  11358. }
  11359. ;
  11360. a.prototype.cancelAsync = function(e) {
  11361. 0 > e ? Kq.cancel(~e) : Iq.cancel(e)
  11362. }
  11363.  
  11364. */
  11365.  
  11366.  
  11367. (FASTER_ICON_RENDERING && Promise.all(
  11368. [
  11369. customElements.whenDefined("yt-icon-shape"),
  11370. customElements.whenDefined("yt-icon")
  11371. // document.createElement('icon-shape'),
  11372. ]
  11373. )).then(() => {
  11374. let cq = 0;
  11375. let dummys = [document.createElement('yt-icon-shape'), document.createElement('yt-icon')]
  11376. for (const dummy of dummys) {
  11377. let cProto = getProto(dummy);
  11378. if (cProto && typeof cProto.shouldRenderIconShape === 'function' && !cProto.shouldRenderIconShape571 && cProto.shouldRenderIconShape.length === 1) {
  11379. assertor(() => fnIntegrity(cProto.shouldRenderIconShape, '1.70.38'));
  11380. cq++;
  11381. cProto.shouldRenderIconShape571 = cProto.shouldRenderIconShape;
  11382. cProto.shouldRenderIconShape = function (a) {
  11383. if (this.isAnimatedIcon) return this.shouldRenderIconShape571(a);
  11384. if (!this.iconType || !this.iconShapeData) return this.shouldRenderIconShape571(a);
  11385. if (!this.iconName) return this.shouldRenderIconShape571(a);
  11386. return false;
  11387. // console.log(1051, this.iconType)
  11388. // console.log(1052, this.iconShapeData)
  11389. // console.log(1053, this.isAnimatedIcon)
  11390. }
  11391. }
  11392. // if(cProto && cProto.switchTemplateAtRegistration){
  11393. // cProto.switchTemplateAtRegistration = false;
  11394. // }
  11395. }
  11396. if (cq === 1) {
  11397. console.log("modified shouldRenderIconShape - Y")
  11398. } else {
  11399. console.log("modified shouldRenderIconShape - N", cq)
  11400. }
  11401. });
  11402.  
  11403. customElements.whenDefined("yt-invalidation-continuation").then(() => {
  11404.  
  11405. let __dummyManager__ = null;
  11406.  
  11407. mightFirstCheckOnYtInit();
  11408. groupCollapsed("YouTube Super Fast Chat", " | yt-invalidation-continuation hacks");
  11409. console.log("[Begin]");
  11410. (() => {
  11411.  
  11412. const tag = "yt-invalidation-continuation"
  11413. const dummy = document.createElement(tag);
  11414.  
  11415. const cProto = getProto(dummy);
  11416. if (!cProto || !cProto.attached) {
  11417. console.warn(`proto.attached for ${tag} is unavailable.`);
  11418. return;
  11419. }
  11420.  
  11421. const dummyManager = insp(dummy).manager_ || 0;
  11422. __dummyManager__ = dummyManager;
  11423.  
  11424. if (CHANGE_DATA_FLUSH_ASYNC && typeof cProto.async === 'function' && !cProto.async71 && cProto.async.length === 2 && typeof cProto.cancelAsync === 'function' && !cProto.cancelAsync71 && cProto.cancelAsync.length === 1) {
  11425.  
  11426.  
  11427. const rafHub = new RAFHub();
  11428.  
  11429. rafHub.keepRAF = true;
  11430. cProto.async71 = cProto.async;
  11431. cProto.cancelAsync71 = cProto.cancelAsync;
  11432.  
  11433. // mostly for subscription timeoutMs 10000ms
  11434. let mcw = 1; // 1, 3, 5, ...
  11435. let arr = new Map();
  11436.  
  11437. let __asyncInited__ = 0;
  11438. let __timeoutStartId__ = null;
  11439. const __asyncInit__ = () => {
  11440.  
  11441. if (__asyncInited__) return;
  11442. __asyncInited__ = 1;
  11443.  
  11444. __timeoutStartId__ = setTimeout(() => { });
  11445. mcw = __timeoutStartId__ * 2 + 1;
  11446.  
  11447. setInterval(() => {
  11448.  
  11449. if (!arr.length) return;
  11450.  
  11451. const p = Date.now();
  11452. let deleteKeys = [];
  11453. arr.forEach((entry, key) => {
  11454.  
  11455.  
  11456. if (entry.cid === -1) {
  11457. entry.cid = -2;
  11458. } else if (entry.cid === -2) {
  11459.  
  11460. let offset = p - entry.add
  11461. if (offset < 0) offset = 0;
  11462. let delay2 = entry.delay - offset;
  11463. if (delay2 < 0) delay2 = 0;
  11464. entry.cid = setTimeout(entry.q(), delay2);
  11465. entry.q = null;
  11466.  
  11467. } else if (entry.add + entry.delay < p) {
  11468. deleteKeys.push(key);
  11469.  
  11470. }
  11471.  
  11472. })
  11473.  
  11474. for (const key of deleteKeys) arr.delete(key);
  11475.  
  11476. }, 2000)
  11477.  
  11478. }
  11479.  
  11480.  
  11481. cProto.async = function (e, h) {
  11482.  
  11483. if (!(0 < h)) return this.async71(e, h); // unknown timing Fn
  11484.  
  11485. if (h < 8000) return this.async71(e, h) * 2; // native setTimeout
  11486.  
  11487. if (typeof h !== 'number') return this.async71(e, h); // exceptional case
  11488.  
  11489.  
  11490. if (!this.__asyncInited__) {
  11491. this.__asyncInited__ = 1;
  11492. __asyncInit__();
  11493. }
  11494. mcw += 2; // 2K+3, 2K+4, ...
  11495. if (mcw > 1e9) mcw = mcw % 1e4;
  11496. const cid = mcw;
  11497. const q = () => {
  11498. return () => {
  11499. console.log('async h > 8000');
  11500. e.call(this);
  11501. }
  11502. }
  11503. // setTimeout(q, delay)
  11504. arr.set(cid, {
  11505. cid: -1, // -1 -> -2 -> cid
  11506. add: Date.now(),
  11507. q,
  11508. delay: h
  11509. });
  11510. // console.log('cid-async', cid)
  11511. return cid;
  11512.  
  11513. }
  11514.  
  11515.  
  11516. cProto.cancelAsync = function (e) {
  11517.  
  11518. if (typeof e !== 'number') return this.cancelAsync71(e); // exceptional case
  11519.  
  11520. // console.log('cid-unasync', e)
  11521.  
  11522. if (0 > e) return this.cancelAsync71(e); // unknown timing fn
  11523.  
  11524. if (e > __timeoutStartId__ * 2) { // __timeoutStartId__ is recorded and min is 2K+1
  11525.  
  11526. if ((e % 2) === 0) return this.cancelAsync71(e / 2); // 2(K+1), 2(K+2), ...
  11527.  
  11528. if (!arr.has(e)) return; // duplciated cancel
  11529.  
  11530. const entry = arr.get(e);
  11531. if (entry.cid < 0) {
  11532. entry.cid = 0;
  11533. arr.delete(e);
  11534. } else {
  11535. clearTimeout(entry.cid); // cid >= 1
  11536. entry.cid = 0;
  11537. arr.delete(e);
  11538. }
  11539.  
  11540. } else {
  11541.  
  11542. return this.cancelAsync71(e);
  11543.  
  11544. }
  11545.  
  11546. }
  11547.  
  11548. console.log("CHANGE_DATA_FLUSH_ASYNC - OK");
  11549.  
  11550. } else if(!CHANGE_DATA_FLUSH_ASYNC){
  11551. console.log("CHANGE_DATA_FLUSH_ASYNC - N/A");
  11552. } else {
  11553. console.log("CHANGE_DATA_FLUSH_ASYNC - NG");
  11554.  
  11555. }
  11556.  
  11557. })();
  11558.  
  11559. console.log("[End]");
  11560.  
  11561. console.groupEnd();
  11562.  
  11563.  
  11564.  
  11565. onManagerFound(__dummyManager__);
  11566.  
  11567. }).catch(console.warn);
  11568.  
  11569.  
  11570. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1) {
  11571.  
  11572. customElements.whenDefined("yt-live-interactivity-component-background").then(() => {
  11573.  
  11574. mightFirstCheckOnYtInit();
  11575. groupCollapsed("YouTube Super Fast Chat", " | yt-live-interactivity-component-background hacks");
  11576. console.log("[Begin]");
  11577. (() => {
  11578.  
  11579. const tag = "yt-live-interactivity-component-background"
  11580. const dummy = document.createElement(tag);
  11581.  
  11582. const cProto = getProto(dummy);
  11583. if (!cProto || !cProto.attached) {
  11584. console.warn(`proto.attached for ${tag} is unavailable.`);
  11585. return;
  11586. }
  11587.  
  11588. cProto.__toStopAfterRun__ = function (hostElement) {
  11589. let mo = new MutationObserver(() => {
  11590. mo.disconnect();
  11591. mo.takeRecords();
  11592. mo = null;
  11593. this.lottieAnimation && this.lottieAnimation.stop(); // primary
  11594. foregroundPromiseFn().then(() => { // if the lottieAnimation is started with rAf triggering
  11595. this.lottieAnimation && this.lottieAnimation.stop(); // fallback
  11596. });
  11597. });
  11598. mo.observe(hostElement, { subtree: true, childList: true });
  11599. }
  11600.  
  11601. if (INTERACTIVITY_BACKGROUND_ANIMATION >= 1 && typeof cProto.maybeLoadAnimationBackground === 'function' && !cProto.maybeLoadAnimationBackground77 && cProto.maybeLoadAnimationBackground.length === 0) {
  11602.  
  11603. cProto.maybeLoadAnimationBackground77 = cProto.maybeLoadAnimationBackground;
  11604. cProto.maybeLoadAnimationBackground = function () {
  11605. let toRun = true;
  11606. let stopAfterRun = false;
  11607. if (!this.__bypassDisableAnimationBackground__) {
  11608. let doFix = false;
  11609. if (INTERACTIVITY_BACKGROUND_ANIMATION === 1) {
  11610. if (!this.lottieAnimation) {
  11611. doFix = true;
  11612. }
  11613. } else if (INTERACTIVITY_BACKGROUND_ANIMATION === 2) {
  11614. doFix = true;
  11615. }
  11616. if (doFix) {
  11617. if (this.useAnimationBackground === true) {
  11618. console.log('DISABLE_INTERACTIVITY_BACKGROUND_ANIMATION', this.lottieAnimation);
  11619. }
  11620. toRun = true;
  11621. stopAfterRun = true;
  11622. }
  11623. }
  11624. if (toRun) {
  11625. if (stopAfterRun && (this.hostElement instanceof HTMLElement)) {
  11626. this.__toStopAfterRun__(this.hostElement); // primary
  11627. }
  11628. const r = this.maybeLoadAnimationBackground77.apply(this, arguments);
  11629. if (stopAfterRun && this.lottieAnimation) {
  11630. this.lottieAnimation.stop(); // fallback if no mutation
  11631. }
  11632. return r;
  11633. }
  11634. }
  11635.  
  11636. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - OK`);
  11637.  
  11638. } else {
  11639. console.log(`INTERACTIVITY_BACKGROUND_ANIMATION(${INTERACTIVITY_BACKGROUND_ANIMATION}) - NG`);
  11640.  
  11641. }
  11642.  
  11643. })();
  11644.  
  11645. console.log("[End]");
  11646.  
  11647. console.groupEnd();
  11648.  
  11649.  
  11650. }).catch(console.warn);
  11651.  
  11652. }
  11653.  
  11654.  
  11655. if (DELAY_FOCUSEDCHANGED) {
  11656.  
  11657. customElements.whenDefined("yt-live-chat-text-input-field-renderer").then(() => {
  11658.  
  11659.  
  11660. mightFirstCheckOnYtInit();
  11661. groupCollapsed("YouTube Super Fast Chat", " | yt-live-chat-text-input-field-renderer hacks");
  11662. console.log("[Begin]");
  11663. (() => {
  11664.  
  11665. const tag = "yt-live-chat-text-input-field-renderer"
  11666. const dummy = document.createElement(tag);
  11667.  
  11668. const cProto = getProto(dummy);
  11669. if (!cProto || !cProto.attached) {
  11670. console.warn(`proto.attached for ${tag} is unavailable.`);
  11671. return;
  11672. }
  11673.  
  11674. if (DELAY_FOCUSEDCHANGED && typeof cProto.focusedChanged === 'function' && cProto.focusedChanged.length === 0 && !cProto.focusedChanged372) {
  11675. cProto.focusedChanged372 = cProto.focusedChanged;
  11676. cProto.focusedChanged = function () {
  11677. Promise.resolve(this).then((cnt) => {
  11678. if (cnt.isAttached === true) cnt.focusedChanged372();
  11679. });
  11680. }
  11681. }
  11682.  
  11683. })();
  11684.  
  11685. console.log("[End]");
  11686.  
  11687. console.groupEnd();
  11688.  
  11689. });
  11690.  
  11691. }
  11692.  
  11693.  
  11694. }
  11695.  
  11696.  
  11697.  
  11698.  
  11699. promiseForCustomYtElementsReady.then(onRegistryReadyForDOMOperations);
  11700.  
  11701. const fixJsonParse = () => {
  11702.  
  11703. let p1 = window.onerror;
  11704.  
  11705. try {
  11706. JSON.parse("{}");
  11707. } catch (e) {
  11708. console.warn(e);
  11709. }
  11710.  
  11711. let p2 = window.onerror;
  11712.  
  11713. if (p1 !== p2) {
  11714.  
  11715.  
  11716. console.groupCollapsed(`%c${"YouTube Super Fast Chat"}%c${" | JS Engine Issue Found"}`,
  11717. "background-color: #010502; color: #fe806a; font-weight: 700; padding: 2px;",
  11718. "background-color: #010502; color: #fe806a; font-weight: 300; padding: 2px;"
  11719. );
  11720.  
  11721. console.warn("\nJSON.parse is hacked (e.g. Brave's script injection) which causes window.onerror changes on every JSON.parse call.\nPlease install https://greasyfork.org/scripts/473972-youtube-js-engine-tamer to fix the issue.\n");
  11722.  
  11723. console.groupEnd();
  11724.  
  11725. }
  11726.  
  11727. }
  11728.  
  11729. if (CHECK_JSONPRUNE) {
  11730. promiseForCustomYtElementsReady.then(fixJsonParse);
  11731. }
  11732.  
  11733. if(USE_ADVANCED_TICKING){ // if(END_ANIMATING_TICKERS){
  11734.  
  11735.  
  11736. // let lastElmW = null;
  11737.  
  11738. // document.addEventListener('transitionstart', (evt) => {
  11739.  
  11740. // if (evt.propertyName === 'width' && !evt.pseudoElement) {
  11741.  
  11742. // const elm = evt.target;
  11743. // let act = false;
  11744. // /*
  11745. // switch(elm.nodeName.toLowerCase()){
  11746.  
  11747. // case 'yt-live-chat-ticker-creator-goal-view-model':
  11748. // case 'yt-live-chat-ticker-paid-message-item-renderer':
  11749. // case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  11750.  
  11751. // case 'yt-live-chat-ticker-sponsor-item-renderer':
  11752. // act =true;
  11753. // break;
  11754.  
  11755.  
  11756. // }
  11757. // */
  11758. // if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  11759. // act = true;
  11760. // }
  11761. // if (act) {
  11762. // const lastElm = kRef(lastElmW);
  11763. // if (elm !== lastElm) {
  11764.  
  11765. // if (lastElm instanceof HTMLElement) {
  11766. // lastElm.classList.add('ticker-no-transition-time');
  11767. // }
  11768. // lastElmW = mWeakRef(elm);
  11769.  
  11770. // }
  11771.  
  11772.  
  11773. // }
  11774. // }
  11775.  
  11776. // }, true);
  11777.  
  11778.  
  11779.  
  11780.  
  11781. /*
  11782.  
  11783. document.addEventListener('transitionend', (evt) => {
  11784.  
  11785. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  11786.  
  11787. const elm = evt.target;
  11788. let act = false;
  11789. /-*
  11790. switch(elm.nodeName.toLowerCase()){
  11791.  
  11792. case 'yt-live-chat-ticker-creator-goal-view-model':
  11793. case 'yt-live-chat-ticker-paid-message-item-renderer':
  11794. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  11795.  
  11796. case 'yt-live-chat-ticker-sponsor-item-renderer':
  11797. act =true;
  11798. break;
  11799.  
  11800.  
  11801. }
  11802. *-/
  11803. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  11804. act = true;
  11805. }
  11806. if (act) {
  11807. elm.style.transitionDuration = '0s';
  11808.  
  11809. }
  11810. }
  11811.  
  11812. }, true);
  11813.  
  11814.  
  11815. document.addEventListener('transitioncancel', (evt) => {
  11816.  
  11817. if (evt.propertyName === 'width' && !evt.pseudoElement) {
  11818.  
  11819. const elm = evt.target;
  11820. let act = false;
  11821. /-*
  11822. switch(elm.nodeName.toLowerCase()){
  11823.  
  11824. case 'yt-live-chat-ticker-creator-goal-view-model':
  11825. case 'yt-live-chat-ticker-paid-message-item-renderer':
  11826. case 'yt-live-chat-ticker-paid-sticker-item-renderer':
  11827.  
  11828. case 'yt-live-chat-ticker-sponsor-item-renderer':
  11829. act =true;
  11830. break;
  11831.  
  11832.  
  11833. }
  11834. *-/
  11835. if (elm instanceof HTMLElement && ((elm || 0).parentElement || 0).id === 'ticker-items' && elm.classList.contains('yt-live-chat-ticker-renderer')) {
  11836. act = true;
  11837. }
  11838. if (act) {
  11839. elm.style.transitionDuration = '0s';
  11840.  
  11841. }
  11842. }
  11843.  
  11844. }, true);
  11845.  
  11846. */
  11847.  
  11848.  
  11849. }
  11850.  
  11851. });
  11852.  
  11853.  
  11854.  
  11855. })({ IntersectionObserver });