Request permission to access captcha service. #2375
This commit is contained in:
parent
f430164b8c
commit
473a59258c
@ -24,6 +24,9 @@ Captcha.service =
|
||||
@pending = true
|
||||
@aborted = false
|
||||
e.preventDefault()
|
||||
CrossOrigin.permission @requestCaptcha2.bind(@), @noCaptcha.bind(@, 'Permission denied'), ["#{Conf['captchaServiceDomain']}/*"]
|
||||
|
||||
requestCaptcha2: ->
|
||||
key = Conf['captchaServiceKey'][Conf['captchaServiceDomain']]
|
||||
return @noCaptcha 'API key not set' unless key and /\S/.test(key)
|
||||
url = "#{Conf['captchaServiceDomain']}/in.php?key=#{encodeURIComponent key}&method=userrecaptcha&googlekey=<%= meta.recaptchaKey %>&pageurl=https://boards.4channel.org/v/"
|
||||
@ -60,7 +63,7 @@ Captcha.service =
|
||||
noCaptcha: (error) ->
|
||||
@pending = false
|
||||
return if @aborted
|
||||
error = if @req.status is 200
|
||||
error or= if @req.status is 200
|
||||
@req.response
|
||||
else if @req.status
|
||||
"#{@req.statusText} (#{@req.status})"
|
||||
|
||||
@ -9,16 +9,16 @@ chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
|
||||
|
||||
handlers =
|
||||
permission: (request, cb) ->
|
||||
chrome.permissions.contains
|
||||
origins: ['*://*/']
|
||||
, (result) ->
|
||||
origins = request.origins or ['*://*/']
|
||||
chrome.permissions.contains {origins}, (result) ->
|
||||
if result
|
||||
cb()
|
||||
cb result
|
||||
else
|
||||
chrome.permissions.request
|
||||
origins: ['*://*/']
|
||||
, ->
|
||||
cb()
|
||||
chrome.permissions.request {origins}, (result) ->
|
||||
if chrome.runtime.lastError
|
||||
cb false
|
||||
else
|
||||
cb result
|
||||
|
||||
ajax: (request, cb) ->
|
||||
xhr = new XMLHttpRequest()
|
||||
|
||||
@ -168,10 +168,15 @@ CrossOrigin =
|
||||
$.cache url, cb,
|
||||
ajax: CrossOrigin.ajax
|
||||
|
||||
<% if (type === 'crx') { %>
|
||||
permission: (cb, cbFail, origins) ->
|
||||
eventPageRequest {type: 'permission', origins}, (result) ->
|
||||
if result
|
||||
cb()
|
||||
else
|
||||
cbFail()
|
||||
<% } %>
|
||||
<% if (type === 'userscript') { %>
|
||||
permission: (cb) ->
|
||||
<% if (type === 'crx') { %>
|
||||
eventPageRequest {type: 'permission'}, -> cb()
|
||||
<% } %>
|
||||
<% if (type === 'userscript') { %>
|
||||
cb()
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user