@@ -244,62 +244,42 @@ chrome.runtime.onMessage.addListener(
244
244
let submissionURI
245
245
let data = { }
246
246
let method = 'GET'
247
+ console . log ( `sending request to ${ request . archive } ` )
247
248
if ( request . archive === 'ia' ) {
248
249
submissionURI = `http://web.archive.org/save/${ request . urir } `
249
250
method = 'GET'
250
251
} else if ( request . archive === 'ais' ) {
251
252
// TODO: get value of submitted from AIS interface
252
253
submissionURI = 'https://archive.is/submit/'
253
- method = 'post '
254
+ method = 'get '
254
255
fetchArchiveIsSubmitID ( ) . then ( submitidExtracted => {
255
256
console . log ( `Submitted to archive.is with url ${ request . urir } and submitid ${ submitidExtracted } ` )
256
- const data = new FormData ( )
257
- data . append ( 'submitid' , submitidExtracted )
258
- data . append ( 'url' , request . urir )
259
-
260
- for ( let pair of data . entries ( ) ) {
261
- console . log ( `${ pair [ 0 ] } : ${ pair [ 1 ] } ` )
262
- }
263
- fetch ( submissionURI , {
264
- method : 'POST' ,
265
- body : data
266
- } ) . then (
267
- response => response . text ( )
268
- ) . then (
269
- html => console . log ( html )
257
+ submissionURI = `${ submissionURI } ?url=${ request . urir } &submitid=${ submitidExtracted } `
258
+
259
+ window . fetch ( submissionURI ) . then (
260
+ response => {
261
+ // e.g., https://archive.ph/C2NCh/again?url=https://weiglemc.github.io/
262
+ // TODO: trim off everything before /again?
263
+ // ?again might only occur when a URL is newly minted, to research
264
+ console . log ( response . url . split ( '/again' ) . pop ( ) )
265
+ // TODO: the call below does not have a properly formed response object
266
+ changeArchiveIcon ( request , response )
267
+
268
+ }
270
269
)
271
- return
272
-
273
- // xhr used instead of fetch bc we need the Content-Location response header
274
- let xhr = new XMLHttpRequest ( )
275
- xhr . addEventListener ( 'load' , readArchiveIsResponse )
276
- xhr . open ( method , submissionURI )
277
- xhr . setRequestHeader ( 'Content-type' , 'application/x-www-form-urlencoded' )
278
-
279
- xhr . send ( data )
280
- console . log ( xhr )
281
- return
282
-
283
- chrome . tabs . query ( {
284
- active : true ,
285
- currentWindow : true
286
- } , function ( tabs ) {
287
- chrome . tabs . sendMessage ( tabs [ 0 ] . id , {
288
- method : 'archiveDone' ,
289
- data : xhr . getResponseHeader ( 'Content-Location' ) ,
290
- imgId : request . imgId ,
291
- imgURI : request . imgURI ,
292
- callback : request . cb ,
293
- newTab : request . newTab
294
- } )
295
- } )
296
-
297
- return
298
270
} )
271
+ return
299
272
}
273
+ // NOTE THAT ARCHIVE.IS changed back from POST to GET but the below still returns a 404 for invalid URI
274
+ // maybe escape it?
275
+
276
+
300
277
301
278
window . fetch ( submissionURI ) . then (
302
279
response => {
280
+ console . log ( 'xxx' )
281
+ console . log ( request )
282
+ console . log ( response )
303
283
changeArchiveIcon ( request , response )
304
284
}
305
285
)
0 commit comments