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