@@ -31,9 +31,13 @@ function getCookie(cname) {
3131 return "" ;
3232}
3333
34- var scrollToBottom = false ; // Default to false, since continuous erros can overload the system
35- if ( getCookie ( "scrollToBottom" ) === "true" ) {
36- scrollToBottom = true ;
34+ var scrollToBottom = true ;
35+ if ( getCookie ( "scrollToBottom" ) === "false" ) {
36+ scrollToBottom = false ;
37+ }
38+ var addTimestamp = true ;
39+ if ( getCookie ( "addTimestamp" ) === "false" ) {
40+ addTimestamp = false ;
3741}
3842
3943function initialzeDebugConsole ( ) {
@@ -74,6 +78,28 @@ function addDebugConsoleTopBar(debugConsole, consoleDiv) {
7478 separator . classList . add ( 'separator' ) ;
7579 consoleTopBar . appendChild ( separator ) ;
7680
81+ // Add timestamp toggle
82+ var timestampButton = document . createElement ( 'button' ) ;
83+ timestampButton . classList . add ( 'timestamp-button' , 'bubble-click-indicator' ) ;
84+ timestampButton . title = 'Add timestamp to logs' ;
85+ consoleTopBar . appendChild ( timestampButton ) ;
86+
87+ var timestampIcon = document . createElement ( 'div' ) ;
88+ timestampIcon . classList . add ( 'icon' ) ;
89+ timestampButton . appendChild ( timestampIcon ) ;
90+ applyTimestamp ( timestampButton , consoleDiv ) ;
91+
92+ timestampButton . addEventListener ( 'click' , function ( ) {
93+ addTimestamp = ! addTimestamp ;
94+ setCookie ( "addTimestamp" , addTimestamp , 365 ) ;
95+ applyTimestamp ( timestampButton , consoleDiv ) ;
96+ // Show copy feedback to the user
97+ timestampButton . classList . add ( 'active' ) ;
98+ setTimeout ( function ( ) {
99+ timestampButton . classList . remove ( 'active' ) ;
100+ } , 1500 ) ;
101+ } ) ;
102+
77103 // Clear logs button
78104 var clearButton = document . createElement ( 'button' ) ;
79105 clearButton . classList . add ( 'clear-button' , 'bubble-click-indicator' ) ;
@@ -207,6 +233,18 @@ function applyScrollToBottom(toBottomButton, consoleDiv) {
207233 }
208234}
209235
236+ function applyTimestamp ( timestampButton , consoleDiv ) {
237+ timestampButton . setAttribute ( 'data-before' , addTimestamp ? 'Show' : 'Hide' ) ;
238+ var debugConsole = document . getElementById ( 'debugConsole' ) ;
239+ if ( addTimestamp ) {
240+ timestampButton . classList . add ( "show" ) ;
241+ debugConsole . classList . remove ( "hidelogtimestamps" ) ;
242+ } else {
243+ timestampButton . classList . remove ( "show" ) ;
244+ debugConsole . classList . add ( "hidelogtimestamps" ) ;
245+ }
246+ }
247+
210248function setupConsoleLogPipe ( ) {
211249 // Store actual console log functions
212250 let defaultConsoleLog = console . log ;
@@ -293,10 +331,13 @@ function htmlLog(message, className) {
293331 consoleDiv . appendChild ( entry ) ;
294332
295333 var text = document . createElement ( 'p' ) ;
296- // Remove last line break if existing
297- if ( message . endsWith ( "\n" ) ) {
298- message = message . substring ( 0 , message . length - "\n" . length ) ;
299- }
334+ var time = new Date ( ) . toLocaleTimeString ( 'en-US' , {
335+ hour12 : false ,
336+ hour : "numeric" ,
337+ minute : "numeric" ,
338+ second : "numeric" }
339+ ) ;
340+ message = "<span class='timestamplog'>[" + time + "] </span>" + message ;
300341 message = message . replaceAll ( "\n" , "<br />" ) ;
301342 text . innerHTML = message ;
302343 entry . appendChild ( text ) ;
0 commit comments