Skip to content

Commit

Permalink
updater: fix dumb ff57 shit
Browse files Browse the repository at this point in the history
They finally did it. They broke my 2-year-old shit script.
xhr no longer takes relative "//" urls anymore i guess,
so https everywhere. I'm kind of surprised my sharedworker
shit still works. I remember how terrible it all seemed when
I wrote it. It probably still sux. javascript life.
  • Loading branch information
qqueue committed Nov 18, 2017
1 parent 792ef19 commit 5a6d82d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/features/postpreviews.co
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fetch-new-post = !(no) ->

# TODO guard against multiple requests in short time period
xhr = new XMLHttpRequest
&open \GET "//api.4chan.org/#board-name/thread/#thread.json"
&open \GET "https://api.4chan.org/#board-name/thread/#thread.json"
&onload = !->
# TODO handle 404 -> archive
if @status is 200
Expand Down
21 changes: 15 additions & 6 deletions src/unfortunate/updater.co
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ worker-code = !->
->
if active-requests.has url
active-requests.delete url
cb "xhr timeout", void
cb "xhr timeout for url #url", void
5000

self.onconnect = !->
Expand Down Expand Up @@ -130,7 +130,7 @@ worker-code = !->
for let board-name, thread-states in to-poll
return if throttled.has board-name
throttled.add board-name
url = "//a.4cdn.org/#{board-name}/threads.json"
url = "https://a.4cdn.org/#{board-name}/threads.json"
ims = board-lm[board-name].toISOString()
make-xhr url, ims, !(err, res) ->
log err if err
Expand Down Expand Up @@ -183,7 +183,7 @@ worker-code = !->
return if active.has key
active.add key

url = "//a.4cdn.org/#{board-name}/res/#{thread-no}.json"
url = "https://a.4cdn.org/#{board-name}/res/#{thread-no}.json"
ims = thread-states[thread-no]last-modified.toISOString!
make-xhr url, ims, !(err, res) ->
log err if err
Expand Down Expand Up @@ -227,8 +227,12 @@ subscriptions = new Map # callback -> "#board#tno"
var worker

!function initialize-worker
worker := new SharedWorker do
"data:application/javascript,#{encodeURIComponent "(#worker-code)()"}"
try
worker := new SharedWorker do
"data:application/javascript,#{encodeURIComponent "(#worker-code)()"}"
catch
console.error "couldn't make sharedworker"
console.error e

worker.port.add-event-listener \message ->
switch it.data.type
Expand Down Expand Up @@ -264,7 +268,12 @@ var worker
if k is key
try
console.log "found sub for #{it.data.type} #key"
sub it.data
console.log "sending data: ", it.data
# XXX need to cloneInto for some wack Xraywrapper reason
# or rather, need to somehow cleanse it.data of whatever
# cross-origin attachment it has. this works, apparently
cleaned-data = JSON.parse(JSON.stringify(it.data))

This comment has been minimized.

Copy link
@vendethiel

vendethiel Nov 18, 2017

Contributor

So many parens

sub cleaned-data
catch
console.error e
case \log
Expand Down

0 comments on commit 5a6d82d

Please # to comment.