@@ -12,8 +12,16 @@ function startAutoRefreshWorker() {
12
12
autoRefreshWorker . addEventListener ( 'message' , ( event ) => {
13
13
const data = event . data ;
14
14
if ( data . type === 'countdown' ) {
15
- const toggleText = document . querySelector ( ".toggle-text" ) ;
16
- toggleText . textContent = `Auto Refresh (${ data . timeLeft } s)` ;
15
+ const refreshInput = document . getElementById ( "refresh-time-input" ) ;
16
+ if ( isAutoRefreshEnabled && refreshInput ) {
17
+ refreshInput . value = data . timeLeft ;
18
+ refreshInput . readOnly = true ;
19
+
20
+ // Flash effect
21
+ refreshInput . classList . remove ( "flash" ) ; // Reset if already applied
22
+ void refreshInput . offsetWidth ; // Force reflow to restart the animation
23
+ refreshInput . classList . add ( "flash" ) ;
24
+ }
17
25
timeLeft = data . timeLeft ; // Update timeLeft in the main thread
18
26
} else if ( data . type === 'fetch' ) {
19
27
fetchStockData ( ) ;
@@ -35,13 +43,17 @@ function stopAutoRefreshWorker() {
35
43
// Function to toggle auto-refresh
36
44
function toggleAutoRefresh ( ) {
37
45
const autoRefreshCheckbox = document . getElementById ( "auto-refresh-checkbox" ) ;
46
+ const refreshInput = document . getElementById ( "refresh-time-input" ) ;
47
+
38
48
if ( autoRefreshCheckbox . checked ) {
39
49
isAutoRefreshEnabled = true ;
50
+ refreshInput . readOnly = true ;
40
51
if ( autoRefreshWorker ) {
41
52
autoRefreshWorker . postMessage ( { type : 'start' , duration : countdownDuration , timeLeft } ) ;
42
53
}
43
54
} else {
44
55
isAutoRefreshEnabled = false ;
56
+ refreshInput . readOnly = false ;
45
57
if ( autoRefreshWorker ) {
46
58
autoRefreshWorker . postMessage ( { type : 'stop' } ) ;
47
59
}
@@ -63,6 +75,18 @@ function handleRefreshTimeInput() {
63
75
} ) ;
64
76
}
65
77
78
+ // Function to limit user input characters
79
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
80
+ const input = document . getElementById ( 'refresh-time-input' ) ;
81
+ const maxLength = 2 ;
82
+
83
+ input . addEventListener ( 'input' , ( ) => {
84
+ if ( input . value . length > maxLength ) {
85
+ input . value = input . value . slice ( 0 , maxLength ) ;
86
+ }
87
+ } ) ;
88
+ } ) ;
89
+
66
90
// Initialize the refresh time input handler
67
91
handleRefreshTimeInput ( ) ;
68
92
0 commit comments