Add option to set captcha language.

This commit is contained in:
ccd0 2015-06-20 16:56:53 -07:00
parent a50eb04ccc
commit fc90b895ef
8 changed files with 46 additions and 10 deletions

View File

@ -25,7 +25,7 @@
"*://www.4chan.org/feedback", "*://www.4chan.org/feedback",
"https://www.google.com/recaptcha/api2/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "https://www.google.com/recaptcha/api2/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*",
"https://www.google.com/recaptcha/api2/frame?*&k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "https://www.google.com/recaptcha/api2/frame?*&k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*",
"*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc" "*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*"
], ],
"suffix": { "suffix": {
"stable": "", "stable": "",

View File

@ -741,6 +741,8 @@ Config =
#options:"sage";boards:jp;always #options:"sage";boards:jp;always
""" """
captchaLanguage: ''
time: '%m/%d/%y(%a)%H:%M:%S' time: '%m/%d/%y(%a)%H:%M:%S'
backlink: '>>%id' backlink: '>>%id'

View File

@ -10,6 +10,10 @@ Main =
if location.hostname is 'www.4chan.org' if location.hostname is 'www.4chan.org'
$.onExists d.documentElement, 'body', false, -> $.addStyle Main.cssWWW $.onExists d.documentElement, 'body', false, -> $.addStyle Main.cssWWW
Conf = {'captchaLanguage': Config.captchaLanguage}
$.get Conf, (items) ->
$.extend Conf, items
Captcha.language.fixPage()
return return
g.threads = new SimpleDict() g.threads = new SimpleDict()
@ -310,6 +314,7 @@ Main =
features: [ features: [
['Polyfill', Polyfill] ['Polyfill', Polyfill]
['Captcha Language', Captcha.language]
['Redirect', Redirect] ['Redirect', Redirect]
['Header', Header] ['Header', Header]
['Catalog Links', CatalogLinks] ['Catalog Links', CatalogLinks]

View File

@ -315,7 +315,7 @@ Settings =
items = {} items = {}
inputs = {} inputs = {}
for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss', 'customCooldown'] for name in ['captchaLanguage', 'boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss', 'customCooldown']
input = $ "[name='#{name}']", section input = $ "[name='#{name}']", section
items[name] = Conf[name] items[name] = Conf[name]
inputs[name] = input inputs[name] = input
@ -324,9 +324,9 @@ Settings =
else if name is 'favicon' else if name is 'favicon'
$.on input, 'change', $.cb.value $.on input, 'change', $.cb.value
$.on input, 'change', Settings[name] $.on input, 'change', Settings[name]
else else
$.on input, 'input', $.cb.value $.on input, 'input', $.cb.value
$.on input, 'input', Settings[name] $.on input, 'input', Settings[name] if name of Settings
# Quick Reply Personas # Quick Reply Personas
ta = $ '.personafield', section ta = $ '.personafield', section
@ -339,8 +339,8 @@ Settings =
for key, val of items for key, val of items
input = inputs[key] input = inputs[key]
input.value = val input.value = val
continue if key in ['usercss', 'customCooldown'] if key of Settings and key isnt 'usercss'
Settings[key].call input Settings[key].call input
return return
interval = $ 'input[name="Interval"]', section interval = $ 'input[name="Interval"]', section

View File

@ -12,6 +12,12 @@
</table> </table>
</fieldset> </fieldset>
<fieldset>
<legend>Captcha Language</legend>
<div>Choose from <a href="https://developers.google.com/recaptcha/docs/language">list of language codes</a>. Leave blank to autoselect.</div>
<div><input name="captchaLanguage" class="field" spellcheck="false"></div>
</fieldset>
<fieldset> <fieldset>
<legend>Custom Board Navigation</legend> <legend>Custom Board Navigation</legend>
<div><textarea name="boardnav" class="field" spellcheck="false"></textarea></div> <div><textarea name="boardnav" class="field" spellcheck="false"></textarea></div>

View File

@ -3,6 +3,7 @@ Report =
init: -> init: ->
return unless /\bmode=report\b/.test(location.search) and match = location.search.match /\bno=(\d+)/ return unless /\bmode=report\b/.test(location.search) and match = location.search.match /\bno=(\d+)/
Captcha.language.fixPage()
@postID = +match[1] @postID = +match[1]
$.ready @ready $.ready @ready

View File

@ -0,0 +1,17 @@
Captcha.language =
init: ->
return unless Conf['captchaLanguage'].trim() and d.cookie.indexOf('pass_enabled=1') < 0 and !Conf['Hide Original Post Form']
$.onExists doc, '#captchaFormPart', true, (node) ->
$.onExists node, 'iframe', true, Captcha.language.fixIframe
fixPage: ->
return unless Conf['captchaLanguage'].trim() and d.cookie.indexOf('pass_enabled=1') < 0
$.onExists doc, 'iframe', true, Captcha.language.fixIframe
fixIframe: (el) ->
return unless lang = Conf['captchaLanguage'].trim()
src = if /[?&]hl=/.test el.src
el.src.replace(/([?&]hl=)[^&]*/, '$1' + encodeURIComponent lang)
else
el.src + "&hl=#{encodeURIComponent lang}"
el.src = src unless el.src is src

View File

@ -1,6 +1,5 @@
Captcha.v2 = Captcha.v2 =
lifetime: 2 * $.MINUTE lifetime: 2 * $.MINUTE
noscriptURL: '//www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>'
init: -> init: ->
return if d.cookie.indexOf('pass_enabled=1') >= 0 return if d.cookie.indexOf('pass_enabled=1') >= 0
@ -34,6 +33,12 @@ Captcha.v2 =
timeouts: {} timeouts: {}
postsCount: 0 postsCount: 0
noscriptURL: ->
url = '//www.google.com/recaptcha/api/fallback?k=<%= meta.recaptchaKey %>'
if lang = Conf['captchaLanguage'].trim()
url += "&hl=#{encodeURIComponent lang}"
url
needed: -> needed: ->
captchaCount = @captchas.length captchaCount = @captchas.length
captchaCount++ if QR.req captchaCount++ if QR.req
@ -83,7 +88,7 @@ Captcha.v2 =
setupNoscript: -> setupNoscript: ->
iframe = $.el 'iframe', iframe = $.el 'iframe',
id: 'qr-captcha-iframe' id: 'qr-captcha-iframe'
src: @noscriptURL src: @noscriptURL()
$.add @nodes.container, iframe $.add @nodes.container, iframe
@conn.target = iframe.contentWindow @conn.target = iframe.contentWindow
@ -120,7 +125,7 @@ Captcha.v2 =
return return
setupIFrame: (iframe) -> setupIFrame: (iframe) ->
@setupTime = Date.now() Captcha.language.fixIframe iframe
$.addClass QR.nodes.el, 'captcha-open' $.addClass QR.nodes.el, 'captcha-open'
if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight
QR.nodes.el.style.top = null QR.nodes.el.style.top = null
@ -202,7 +207,7 @@ Captcha.v2 =
reload: -> reload: ->
if @noscript if @noscript
$('iframe', @nodes.container).src = @noscriptURL $('iframe', @nodes.container).src = @noscriptURL()
else else
$.globalEval ''' $.globalEval '''
(function() { (function() {