@@ -2,10 +2,7 @@ import React from 'react';
22import ReactDOM from 'react-dom/client' ;
33import './index.css' ;
44import App from './App' ;
5- import reportWebVitals from './reportWebVitals' ;
65
7- // Application initialization timestamp
8- const startTime = performance . now ( ) ;
96// Configure console styling
107const logStyles = {
118 startup : 'color: #4CAF50; font-weight: bold' ,
@@ -15,6 +12,185 @@ const logStyles = {
1512} ;
1613
1714
15+ // Application initialization timestamp
16+ const startTime = performance . now ( ) ;
17+ console . log ( '%c[Chat App] Application initialization started at:' , logStyles . info , new Date ( ) . toISOString ( ) ) ;
18+
19+ // Function to load and execute tab_fallback.js
20+ function loadTabFallback ( ) {
21+ console . log ( '%c[Chat App] Loading tab fallback functionality...' , logStyles . info ) ;
22+ console . log ( '%c[Chat App] Current DOM state:' , logStyles . info , {
23+ tabButtons : document . querySelectorAll ( '.tab-button' ) . length ,
24+ tabContainers : document . querySelectorAll ( '.tabs-container' ) . length ,
25+ timestamp : new Date ( ) . toISOString ( )
26+ } ) ;
27+
28+ function updateTabs ( ) {
29+ try {
30+ document . querySelectorAll ( '.tab-button' ) . forEach ( button => {
31+ const tabId = button . getAttribute ( 'data-for-tab' ) ;
32+ console . log ( '%c[Chat App] Adding click listener to tab:' , logStyles . info , {
33+ tabId,
34+ buttonElement : button ,
35+ containerElement : button . closest ( '.tabs-container' ) ,
36+ timestamp : new Date ( ) . toISOString ( )
37+ } ) ;
38+ button . addEventListener ( 'click' , ( event ) => {
39+ try {
40+ console . log ( '%c[Chat App] Tab clicked:' , logStyles . info , {
41+ tab : button . getAttribute ( 'data-for-tab' ) ,
42+ element : button ,
43+ container : button . closest ( '.tabs-container' ) . id ,
44+ timestamp : new Date ( ) . toISOString ( )
45+ } ) ;
46+ event . stopPropagation ( ) ;
47+ const forTab = button . getAttribute ( 'data-for-tab' ) ;
48+ const tabsContainerId = button . closest ( '.tabs-container' ) . id ;
49+ console . log ( '%c[Chat App] Saving tab state:' , logStyles . info , {
50+ containerId : tabsContainerId ,
51+ selectedTab : forTab ,
52+ previousTab : localStorage . getItem ( `selectedTab_${ tabsContainerId } ` ) ,
53+ timestamp : new Date ( ) . toISOString ( )
54+ } ) ;
55+ localStorage . setItem ( `selectedTab_${ tabsContainerId } ` , forTab ) ;
56+ let tabsParent = button . closest ( '.tabs-container' ) ;
57+ const activeButtons = Array . from ( tabsParent . querySelectorAll ( '.tab-button.active' ) )
58+ . map ( btn => btn . getAttribute ( 'data-for-tab' ) ) ;
59+ console . log ( '%c[Chat App] Currently active buttons:' , logStyles . info , activeButtons ) ;
60+
61+ tabsParent . querySelectorAll ( '.tab-button' ) . forEach ( tabButton => {
62+ if ( tabButton . closest ( '.tabs-container' ) === tabsParent ) tabButton . classList . remove ( 'active' ) ;
63+ } ) ;
64+ button . classList . add ( 'active' ) ;
65+ console . log ( '%c[Chat App] Tab activated:' , logStyles . info , {
66+ tab : forTab ,
67+ container : tabsContainerId ,
68+ timestamp : new Date ( ) . toISOString ( )
69+ } ) ;
70+ let selectedContent = null ;
71+ tabsParent . querySelectorAll ( '.tab-content' ) . forEach ( content => {
72+ if ( content . closest ( '.tabs-container' ) === tabsParent ) {
73+ if ( content . getAttribute ( 'data-tab' ) === forTab ) {
74+ content . classList . add ( 'active' ) ;
75+ content . style . display = 'block' ; // Ensure the content is displayed
76+ console . log ( '%c[Chat App] Tab content displayed:' , logStyles . info , {
77+ tab : forTab ,
78+ content : content . innerHTML . substring ( 0 , 100 ) + '...' ,
79+ timestamp : new Date ( ) . toISOString ( )
80+ } ) ;
81+ selectedContent = content ;
82+ } else {
83+ content . classList . remove ( 'active' ) ;
84+ content . style . display = 'none' ; // Ensure the content is hidden
85+ console . log ( '%c[Chat App] Tab content hidden:' , logStyles . info , {
86+ tab : content . getAttribute ( 'data-tab' ) ,
87+ timestamp : new Date ( ) . toISOString ( )
88+ } ) ;
89+ }
90+ }
91+ } ) ;
92+ if ( selectedContent !== null ) updateNestedTabs ( selectedContent ) ;
93+ } catch ( error ) {
94+ console . error ( '%c[Chat App] Error in tab click handler:' , logStyles . error , {
95+ error : error . message ,
96+ stack : error . stack ,
97+ tab : button . getAttribute ( 'data-for-tab' ) ,
98+ container : button . closest ( '.tabs-container' ) ?. id
99+ } ) ;
100+ }
101+ } ) ;
102+ // Check if the current button should be activated based on localStorage
103+ const savedTab = localStorage . getItem ( `selectedTab_${ button . closest ( '.tabs-container' ) . id } ` ) ;
104+ console . log ( '%c[Chat App] Checking saved tab state:' , logStyles . info , {
105+ container : button . closest ( '.tabs-container' ) . id ,
106+ savedTab : savedTab ,
107+ buttonTab : button . getAttribute ( 'data-for-tab' ) ,
108+ timestamp : new Date ( ) . toISOString ( )
109+ } ) ;
110+ if ( button . getAttribute ( 'data-for-tab' ) === savedTab ) {
111+ button . dispatchEvent ( new Event ( 'click' ) ) ;
112+ }
113+ } ) ;
114+ } catch ( error ) {
115+ console . error ( '%c[Chat App] Fatal error in updateTabs:' , logStyles . error , {
116+ error : error . message ,
117+ stack : error . stack ,
118+ timestamp : new Date ( ) . toISOString ( )
119+ } ) ;
120+ }
121+ }
122+
123+ function updateNestedTabs ( element ) {
124+ console . log ( '%c[Chat App] Updating nested tabs for element:' , logStyles . info , element ) ;
125+ element . querySelectorAll ( '.tabs-container' ) . forEach ( tabsContainer => {
126+ try {
127+ console . log ( '%c[Chat App] Processing nested tab container:' , logStyles . info , tabsContainer . id ) ;
128+ let hasActiveButton = false ;
129+ tabsContainer . querySelectorAll ( '.tab-button' ) . forEach ( nestedButton => {
130+ if ( nestedButton . classList . contains ( 'active' ) ) {
131+ hasActiveButton = true ;
132+ console . log ( '%c[Chat App] Found active nested button:' , logStyles . info , nestedButton . getAttribute ( 'data-for-tab' ) ) ;
133+ }
134+ } ) ;
135+ if ( ! hasActiveButton ) {
136+ /* Determine if a tab-content element in this tabs-container has the active class. If so, use its data-tab value to find the matching button and ensure it is marked active */
137+ const activeContent = tabsContainer . querySelector ( '.tab-content.active' ) ;
138+ if ( activeContent ) {
139+ const activeTab = activeContent . getAttribute ( 'data-tab' ) ;
140+ const activeButton = tabsContainer . querySelector ( `.tab-button[data-for-tab="${ activeTab } "]` ) ;
141+ if ( activeButton !== null ) {
142+ activeButton . classList . add ( 'active' ) ;
143+ console . log ( '%c[Chat App] Activated nested button:' , logStyles . info , activeTab ) ;
144+ }
145+ } else {
146+ /* Add 'active' to the class list of the first button */
147+ const firstButton = tabsContainer . querySelector ( '.tab-button' ) ;
148+ if ( firstButton !== null ) {
149+ firstButton . classList . add ( 'active' ) ;
150+ console . log ( '%c[Chat App] Activated first nested button:' , logStyles . info , firstButton . getAttribute ( 'data-for-tab' ) ) ;
151+ }
152+ }
153+ }
154+ const savedTab = localStorage . getItem ( `selectedTab_${ tabsContainer . id } ` ) ;
155+ // console.log(`Retrieved saved tab from localStorage: selectedTab_${tabsContainer.id} = ${savedTab}`);
156+ if ( savedTab ) {
157+ const savedButton = tabsContainer . querySelector ( `.tab-button[data-for-tab="${ savedTab } "]` ) ;
158+ if ( savedButton ) {
159+ savedButton . classList . add ( 'active' ) ;
160+ const forTab = savedButton . getAttribute ( 'data-for-tab' ) ;
161+ const selectedContent = tabsContainer . querySelector ( `.tab-content[data-tab="${ forTab } "]` ) ;
162+ if ( selectedContent ) {
163+ selectedContent . classList . add ( 'active' ) ;
164+ selectedContent . style . display = 'block' ;
165+ }
166+ // console.log(`Restored saved tab: ${savedTab}`);
167+ }
168+ }
169+ } catch ( e ) {
170+ console . error ( '%c[Chat App] Error updating nested tabs:' , logStyles . error , {
171+ error : e . message ,
172+ stack : e . stack ,
173+ container : tabsContainer . id
174+ } ) ;
175+ }
176+ } ) ;
177+ }
178+
179+ try {
180+ console . log ( '%c[Chat App] Initializing tabs...' , logStyles . info , {
181+ timestamp : new Date ( ) . toISOString ( ) ,
182+ documentReady : document . readyState
183+ } ) ;
184+ updateTabs ( ) ;
185+ } catch ( error ) {
186+ console . error ( '%c[Chat App] Failed to initialize tabs:' , logStyles . error , {
187+ error : error . message ,
188+ stack : error . stack ,
189+ timestamp : new Date ( ) . toISOString ( )
190+ } ) ;
191+ }
192+ }
193+
18194
19195// Check if we're loading from an archive based on current document length
20196const isArchive = document . documentElement . outerHTML . length > 60000 ;
@@ -23,6 +199,7 @@ if (!isArchive) {
23199 console . log ( '%c[Chat App] Starting application...' , logStyles . startup ) ;
24200} else {
25201 console . log ( '%c[Chat App] Starting application in archive mode...' , logStyles . startup ) ;
202+ loadTabFallback ( ) ;
26203}
27204
28205
@@ -56,4 +233,4 @@ if (typeof document !== 'undefined') {
56233 '%c[Chat App] Document is undefined - application may be running in a non-browser environment' ,
57234 logStyles . warning
58235 ) ;
59- }
236+ }
0 commit comments