@@ -6,17 +6,20 @@ export async function initializeConfigTab() {
6
6
const serverUrl = document . getElementById ( 'archivebox_server_url' ) ;
7
7
const apiKey = document . getElementById ( 'archivebox_api_key' ) ;
8
8
const matchUrls = document . getElementById ( 'match_urls' ) ;
9
+ const excludeUrls = document . getElementById ( 'exclude_urls' ) ;
9
10
10
11
// Load saved values
11
12
const archivebox_server_url = await getArchiveBoxServerUrl ( ) ;
12
13
const { archivebox_api_key, match_urls } = await chrome . storage . local . get ( [
13
14
'archivebox_api_key' ,
14
- 'match_urls'
15
+ 'match_urls' ,
16
+ 'exclude_urls' ,
15
17
] ) ;
16
18
17
- serverUrl . value = archivebox_server_url ;
18
- apiKey . value = archivebox_api_key || '' ;
19
- matchUrls . value = match_urls || '' ;
19
+ serverUrl . value = savedConfig . archivebox_server_url || '' ;
20
+ apiKey . value = savedConfig . archivebox_api_key || '' ;
21
+ matchUrls . value = savedConfig . match_urls || '' ;
22
+ excludeUrls . value = savedConfig . exclude_urls || '' ;
20
23
21
24
// Server test button handler
22
25
document . getElementById ( 'testServer' ) . addEventListener ( 'click' , async ( ) => {
@@ -113,12 +116,13 @@ export async function initializeConfigTab() {
113
116
} ) ;
114
117
115
118
// Save changes when inputs change
116
- [ serverUrl , apiKey , matchUrls ] . forEach ( input => {
119
+ [ serverUrl , apiKey , matchUrls , excludeUrls ] . forEach ( input => {
117
120
input . addEventListener ( 'change' , async ( ) => {
118
121
await chrome . storage . local . set ( {
119
122
archivebox_server_url : serverUrl . value . replace ( / \/ $ / , '' ) ,
120
123
archivebox_api_key : apiKey . value ,
121
- match_urls : matchUrls . value
124
+ match_urls : matchUrls . value ,
125
+ exclude_urls : excludeUrls . value ,
122
126
} ) ;
123
127
} ) ;
124
128
} ) ;
@@ -130,19 +134,44 @@ export async function initializeConfigTab() {
130
134
131
135
testButton . addEventListener ( 'click' , async ( ) => {
132
136
const url = testUrlInput . value . trim ( ) ;
137
+
138
+ // test if the URL matches the regex match patterns
139
+ const matchPattern = matchUrls . value . length ? new RegExp ( matchUrls . value ) : / ^ $ / ;
140
+ if ( matchPattern . test ( url ) ) {
141
+ testStatus . innerHTML = `
142
+ <span class="status-indicator status-success"></span>
143
+ ➕ URL would be auto-archived when visited<br/>
144
+ ` ;
145
+ } else {
146
+ testStatus . innerHTML = `
147
+ <span class="status-indicator status-warning"></span>
148
+ ☝ URL does not match the auto-archive pattern (but it can still be saved manually)<br/>
149
+ ` ;
150
+ }
151
+
152
+ const excludePattern = excludeUrls . value . length ? new RegExp ( excludeUrls . value ) : / ^ $ / ;
153
+ if ( excludePattern . test ( url ) ) {
154
+ testStatus . innerHTML = `
155
+ <span class="status-indicator status-warning"></span>
156
+ 🚫 URL is excluded from auto-archiving (but it can still be saved manually)<br/>
157
+ ` ;
158
+ }
159
+
133
160
if ( ! url ) {
134
161
testStatus . innerHTML = `
135
162
<span class="status-indicator status-error"></span>
136
- Please enter a URL to test
163
+ ⌨️ Please enter a URL to test
137
164
` ;
138
165
return ;
139
166
}
140
167
141
168
// Show loading state
142
169
testButton . disabled = true ;
143
- testStatus . innerHTML = `
144
- <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
145
- Testing...
170
+ testStatus . innerHTML += `
171
+ <span id="inprogress-test">
172
+ <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
173
+ Submitting...
174
+ </span>
146
175
` ;
147
176
148
177
try {
@@ -154,22 +183,23 @@ export async function initializeConfigTab() {
154
183
} ;
155
184
156
185
const result = await syncToArchiveBox ( testEntry ) ;
186
+ document . getElementById ( 'inprogress-test' ) . remove ( ) ;
157
187
158
188
if ( result . ok ) {
159
- testStatus . innerHTML = `
160
- <span class="status-indicator status-success"></span>
161
- Success! URL was added to ArchiveBox
189
+ testStatus . innerHTML + = `
190
+ <span class="status-indicator status-success"></span>
191
+ 🚀 URL was submitted and <a href=" ${ serverUrl . value } /" target="_blank">✓ queued for archiving</a> on the ArchiveBox server: <a href=" ${ serverUrl . value } /archive/ ${ testEntry . url } " target="_blank">📦 <code> ${ serverUrl . value } /archive/ ${ testEntry . url } </code></a>.
162
192
` ;
163
193
// Clear the input on success
164
194
testUrlInput . value = '' ;
165
195
} else {
166
- testStatus . innerHTML = `
196
+ testStatus . innerHTML + = `
167
197
<span class="status-indicator status-error"></span>
168
198
Error: ${ result . status }
169
199
` ;
170
200
}
171
201
} catch ( error ) {
172
- testStatus . innerHTML = `
202
+ testStatus . innerHTML + = `
173
203
<span class="status-indicator status-error"></span>
174
204
Error: ${ error . message }
175
205
` ;
0 commit comments