From 2e16923336fe51a8b7b13cafd01bc3b1c16df91f Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 28 Jan 2016 00:49:30 -0800 Subject: [PATCH] Better handling of blocked URL exception. --- src/General/$.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/General/$.coffee b/src/General/$.coffee index a0b68d7ec..7df9eda92 100644 --- a/src/General/$.coffee +++ b/src/General/$.coffee @@ -42,6 +42,7 @@ $.ajax = do -> # With the `If-Modified-Since` header we only receive the HTTP headers and no body for 304 responses. # This saves a lot of bandwidth and CPU time for both the users and the servers. lastModified = {} + blockedURLs = {} blockedError = (url) -> return if blockedURLs[url] @@ -52,7 +53,8 @@ $.ajax = do -> '[More info]' ) %> $('span', message).textContent = (if /^\/\//.test url then location.protocol else '') + url - new Notice 'error', message, 30, -> delete blockedURLs[url] + new Notice 'warning', message, 30, -> delete blockedURLs[url] + (url, options={}, extra={}) -> {type, whenModified, upCallbacks, form} = extra # XXX https://forums.lanik.us/viewtopic.php?f=64&t=24173&p=78310 @@ -62,8 +64,11 @@ $.ajax = do -> try r.open type, url, true catch err + # XXX Some content blockers in Firefox (e.g. Adblock Plus) throw an exception here instead of dispatching an error event. blockedError url - options.onerror?() + for event in ['error', 'loadend'] + r["on#{event}"] = options["on#{event}"] + $.queueTask $.event, event, null, r return if whenModified r.setRequestHeader 'If-Modified-Since', lastModified[whenModified][url] if lastModified[whenModified]?[url]?