Offer cross-origin abort in userscripts if available.

This commit is contained in:
ccd0 2019-03-20 19:08:46 -07:00
parent e98fed9e5f
commit 6ea1d4ca13
2 changed files with 4 additions and 2 deletions

View File

@ -177,6 +177,7 @@ ThreadWatcher =
ajax = if (siteID is Site.hostname) then $.ajax else CrossOrigin.ajax
req = ajax url,
onloadend: ->
@finished = true
ThreadWatcher.fetched++
if ThreadWatcher.fetched is ThreadWatcher.requests.length
ThreadWatcher.requests = []
@ -192,7 +193,7 @@ ThreadWatcher =
ThreadWatcher.requests.push req
abort: ->
for req in ThreadWatcher.requests when req.readyState isnt 4 # DONE
for req in ThreadWatcher.requests when !req.finished
req.abort?()
return

View File

@ -87,7 +87,7 @@ CrossOrigin =
response: null
<% if (type === 'userscript') { %>
(GM?.xmlHttpRequest or GM_xmlhttpRequest)
gmReq = (GM?.xmlHttpRequest or GM_xmlhttpRequest)
method: "GET"
url: url+''
timeout: timeout
@ -99,6 +99,7 @@ CrossOrigin =
onerror: -> onloadend.call(req)
onabort: -> onloadend.call(req)
ontimeout: -> onloadend.call(req)
req.abort = gmReq.abort
<% } %>
<% if (type === 'crx') { %>