Remove obsolete 'Captcha Fixes' and 'Captcha Solving Service' options and related code.

This commit is contained in:
ccd0 2022-05-23 00:25:23 -07:00
parent 6e5c3faef7
commit 5dc65ebcd8
8 changed files with 6 additions and 345 deletions

View File

@ -21,20 +21,6 @@
"appidGecko": "4chan-x@4chan-x.net",
"chromeStoreID": "ohnjgmpcibpbafdlkimncjhflgedgpam",
"recaptchaKey": "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc",
"captchaServiceLinks": [
[
"captcha.guru",
"https://captcha.guru/"
],
[
"AZcaptcha",
"https://azcaptcha.com/"
],
[
"2captcha",
"https://2captcha.com/"
]
],
"distBranch": "gh-pages",
"includes_only": [
"*://boards.4chan.org/*",

View File

@ -612,7 +612,7 @@ Settings =
$.id('lastarchivecheck').textContent = 'never'
items = $.dict()
for name, input of inputs when name not in ['captchaServiceKey', 'Interval', 'Custom CSS']
for name, input of inputs when name not in ['Interval', 'Custom CSS']
items[name] = Conf[name]
event = if (
input.nodeName is 'SELECT' or
@ -635,11 +635,6 @@ Settings =
for textContent in ImageHost.suggestions
$.add listImageHost, $.el 'option', {textContent}
$.on inputs['captchaServiceKey'], 'input', Settings.captchaServiceKey
$.get 'captchaServiceKey', Conf['captchaServiceKey'], ({captchaServiceKey}) ->
Conf['captchaServiceKey'] = captchaServiceKey
Settings.captchaServiceDomainList()
interval = inputs['Interval']
customCSS = inputs['Custom CSS']
applyCSS = $ '#apply-css', section
@ -771,31 +766,6 @@ Settings =
Conf['selectedArchives'] = selectedArchives
Redirect.selectArchives()
captchaServiceDomain: ->
$.get 'captchaServiceKey', Conf['captchaServiceKey'], ({captchaServiceKey}) =>
keyInput = $('[name=captchaServiceKey]')
keyInput.value = captchaServiceKey[@value.trim()] or ''
keyInput.disabled = !@value.trim()
captchaServiceKey: ->
domain = Conf['captchaServiceDomain']
value = @value.trim()
Conf['captchaServiceKey'][domain] = value
$.get 'captchaServiceKey', Conf['captchaServiceKey'], ({captchaServiceKey}) ->
captchaServiceKey[domain] = value
delete captchaServiceKey[domain] unless value or $.hasOwn(Config['captchaServiceKey'][0], domain)
Conf['captchaServiceKey'] = captchaServiceKey
$.set 'captchaServiceKey', captchaServiceKey
Settings.captchaServiceDomainList()
captchaServiceDomainList: ->
list = $.id 'list-captchaServiceDomain'
$.rmAll list
for domain of Conf['captchaServiceKey']
$.add list, $.el 'option',
textContent: domain
return
boardnav: ->
Header.generateBoardList @value

View File

@ -42,23 +42,6 @@
<div><input name="captchaLanguage" class="field" spellcheck="false"></div>
</fieldset>
<fieldset>
<legend>Captcha Solving Service</legend>
<div>
Supported services include
<%= meta.captchaServiceLinks.map(function(x) {return '<a href="' + x[1] + '" target="_blank">' + x[0] + '</a>'}).join(', ') %>,
and any other service implementing the 2captcha API.<br>
Leave blank to disable.
<div>
Domain: <input name="captchaServiceDomain" class="field" spellcheck="false" list="list-captchaServiceDomain">
API Key: <input name="captchaServiceKey" class="field" spellcheck="false">
<datalist id="list-captchaServiceDomain"></datalist>
</div>
<div>
<label><input type="checkbox" name="Prerequest Captcha"> Request captcha when you start typing. Quicker but may result some captchas expiring and being wasted.</label>
</div>
</fieldset>
<fieldset>
<legend>Custom Board Navigation</legend>
<div><textarea hidden name="boardnav" class="field" spellcheck="false"></textarea></div>

View File

@ -1,168 +0,0 @@
Captcha.fixes =
imageKeys: '789456123uiojklm'.split('').concat(['Comma', 'Period'])
imageKeys16: '7890uiopjkl'.split('').concat(['Semicolon', 'm', 'Comma', 'Period', 'Slash'])
css: '''
.rc-imageselect-target > div:focus, .rc-image-tile-target:focus {
outline: 2px solid #4a90e2;
}
.rc-imageselect-target td:focus {
box-shadow: inset 0 0 0 2px #4a90e2;
outline: none;
}
.rc-button-default:focus {
box-shadow: inset 0 0 0 2px #0063d6;
}
'''
cssNoscript: '''
.fbc-payload-imageselect {
position: relative;
/* XXX Fixes for Google's broken CSS */
display: inline-block;
margin-left: 0;
}
.fbc-payload-imageselect > label {
position: absolute;
display: block;
height: 93.3px;
width: 93.3px;
}
label[data-row="0"] {top: 0px;}
label[data-row="1"] {top: 93.3px;}
label[data-row="2"] {top: 186.6px;}
label[data-col="0"] {left: 0px;}
label[data-col="1"] {left: 93.3px;}
label[data-col="2"] {left: 186.6px;}
.fbc-payload-imageselect > input:focus + label {
outline: 2px solid #4a90e2;
}
.fbc-button-verify input:focus {
box-shadow: inset 0 0 0 2px #0063d6;
}
body.focus .fbc {
box-shadow: inset 0 0 0 2px #4a90e2;
}
'''
init: ->
switch location.pathname.split('/')[3]
when 'anchor' then @initMain()
when 'frame', 'bframe' then @initPopup()
when 'fallback' then @initNoscript()
initMain: ->
$.onExists d.body, '#recaptcha-anchor', (checkbox) ->
focus = ->
if d.hasFocus() and d.activeElement in [d.documentElement, d.body]
checkbox.focus()
focus()
$.on window, 'focus', ->
$.queueTask focus
# Remove Privacy and Terms links from tab order.
for a in $$ '.rc-anchor-pt a'
a.tabIndex = -1
return
initPopup: ->
$.addStyle @css
@fixImages()
new MutationObserver(=> @fixImages()).observe d.body, {childList: true, subtree: true}
$.on d, 'keydown', @keybinds.bind(@)
initNoscript: ->
@noscript = true
form = $ '.fbc-imageselect-challenge > form'
data =
if (token = $('.fbc-verification-token > textarea')?.value)
{token}
else if $('.fbc-imageselect-challenge > form')
{working: true}
else if (ns = $ 'noscript') and /please enable javascript/i.test(ns.textContent)
{disabled: true}
else
null
new Connection(window.parent, '*').send data if data
d.body.classList.toggle 'focus', d.hasFocus()
$.on window, 'focus blur', -> d.body.classList.toggle 'focus', d.hasFocus()
@images = $$ '.fbc-payload-imageselect > input'
@width = 3
return unless @images.length is 9
$.addStyle @cssNoscript
@addLabels()
$.on d, 'keydown', @keybinds.bind(@)
$.on form, 'submit', @checkForm.bind(@)
fixImages: ->
@images = $$ '.rc-image-tile-target'
@images = $$ '.rc-imageselect-target > div, .rc-imageselect-target td' unless @images.length
@width = $$('.rc-imageselect-target tr:first-of-type td').length or Math.round(Math.sqrt @images.length)
for img in @images
img.tabIndex = 0
if @images.length is 9
@addTooltips @images
else
@addTooltips16 @images
addLabels: ->
imageSelect = $ '.fbc-payload-imageselect'
labels = for checkbox, i in @images
checkbox.id = "checkbox-#{i}"
label = $.el 'label',
htmlFor: checkbox.id
label.dataset.row = i // 3
label.dataset.col = i % 3
$.after checkbox, label
label
@addTooltips labels
addTooltips: (nodes) ->
for node, i in nodes
node.title = "#{@imageKeys[i]} or #{@imageKeys[i+9][0].toUpperCase()}#{@imageKeys[i+9][1..]}"
return
addTooltips16: (nodes) ->
for key, i in @imageKeys16
if i % 4 < @width and (node = nodes[nodes.length - (4 - i//4)*@width + (i % 4)])
node.title = "#{key[0].toUpperCase()}#{key[1..]}"
return
checkForm: (e) ->
n = 0
n++ for checkbox in @images when checkbox.checked
e.preventDefault() if n is 0
keybinds: (e) ->
return unless @images and doc.contains(@images[0])
n = @images.length
w = @width
last = n + w - 1
reload = $ '#recaptcha-reload-button, .fbc-button-reload'
verify = $ '#recaptcha-verify-button, .fbc-button-verify > input'
x = @images.indexOf d.activeElement
if x < 0
x = if d.activeElement is verify then last else n
key = Keybinds.keyCode e
if !@noscript and key is 'Space' and x < n
@images[x].click()
else if n is 9 and (i = @imageKeys.indexOf key) >= 0
@images[i % 9].click()
verify.focus()
else if n isnt 9 and (i = @imageKeys16.indexOf key) >= 0 and i % 4 < w and (img = @images[n - (4 - i//4)*w + (i % 4)])
img.click()
verify.focus()
else if dx = $.getOwn({'Up': n, 'Down': w, 'Left': last, 'Right': 1}, key)
x = (x + dx) % (n + w)
if n < x < last
x = if dx is last then n else last
(@images[x] or (if x is n then reload) or (if x is last then verify)).focus()
else
return
e.preventDefault()
e.stopPropagation()

View File

@ -6,7 +6,7 @@ Captcha.replace =
$.ready Captcha.replace.noscript
return
if Conf['captchaLanguage'].trim() or Conf['Captcha Fixes']
if Conf['captchaLanguage'].trim()
if location.hostname in ['boards.4chan.org', 'boards.4channel.org']
$.onExists doc, '#captchaFormPart', (node) -> $.onExists node, 'iframe[src^="https://www.google.com/recaptcha/"]', Captcha.replace.iframe
else
@ -33,21 +33,4 @@ Captcha.replace =
else
iframe.src + "&hl=#{encodeURIComponent lang}"
iframe.src = src unless iframe.src is src
Captcha.replace.autocopy iframe
autocopy: (iframe) ->
return unless Conf['Captcha Fixes'] and /^https:\/\/www\.google\.com\/recaptcha\/api\/fallback\?/.test(iframe.src)
new Connection iframe, 'https://www.google.com',
working: ->
if $.id('qr')?.contains iframe
$('#qr .captcha-container textarea')?.parentNode.hidden = true
token: (token) ->
node = iframe
while (node = node.parentNode)
break if (textarea = $ 'textarea', node)
textarea.value = token
$.event 'input', null, textarea
disabled: ->
msg = $.el 'div',
<%= html('Noscript captcha seems to be disabled on 4chan.<br>You may be able to post if you uncheck &quot;Force Noscript Captcha&quot; in your settings.<br>If you hate the Javascript version of Recaptcha, consider visiting <a href="' + meta.alternatives + '#${g.BOARD.ID}" target="_blank" rel="noopener">other imageboards</a>.') %>
new Notice 'warning', msg
return

View File

@ -1,78 +0,0 @@
Captcha.service =
init: ->
$.on d, 'LoadCaptcha', @loadCaptcha.bind(@)
$.on d, 'AbortCaptcha SaveCaptcha', @abortCaptcha.bind(@)
$.on d, 'RequestCaptcha', @requestCaptcha.bind(@)
isEnabled: ->
Conf['captchaServiceDomain'] and /\S/.test(Conf['captchaServiceDomain'])
loadCaptcha: (e) ->
return unless @isEnabled()
e.preventDefault() if !@pending or @aborted
abortCaptcha: ->
@aborted = true if @pending
requestCaptcha: (e) ->
return unless @isEnabled()
return if e.defaultPrevented
if @pending and @aborted
@aborted = false
return
return if @pending
@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/"
@req = CrossOrigin.ajax url,
responseType: 'text'
onloadend: =>
response = @req.response or ''
parts = response.split('|')
if parts[0] is 'OK'
@requestID = parts[1]
@interval = setInterval @poll.bind(@), 5 * $.SECOND
else
@noCaptcha()
poll: ->
key = Conf['captchaServiceKey'][Conf['captchaServiceDomain']]
return @noCaptcha 'API key not set' unless key and /\S/.test(key)
url = "#{Conf['captchaServiceDomain']}/res.php?key=#{encodeURIComponent key}&action=get&id=#{encodeURIComponent @requestID}"
@req = CrossOrigin.ajax url,
responseType: 'text'
onloadend: =>
return unless @req.status
response = @req.response or ''
parts = response.split('|')
if parts[0] is 'CAPCHA_NOT_READY'
# pass
else if parts[0] is 'OK'
clearInterval @interval
@saveCaptcha parts[1]
else
clearInterval @interval
@noCaptcha()
noCaptcha: (error) ->
@pending = false
return if @aborted
error or= if @req.status is 200
@req.response
else if @req.status
"#{@req.statusText} (#{@req.status})"
else
'Connection Error'
error = "Failed to retrieve captcha: #{error}"
$.event 'NoCaptcha', {error}
saveCaptcha: (response) ->
@pending = false
timeout = Date.now() + Captcha.v2.lifetime
$.event 'SaveCaptcha', {response, timeout}

View File

@ -521,10 +521,6 @@ Config =
'Submit the post immediately when the captcha is completed.'
1
]
'Captcha Fixes': [
true
'Make captcha easier to use, especially with the keyboard.'
]
'Force Noscript Captcha': [
false
'Use the non-Javascript fallback captcha even if Javascript is enabled.'
@ -1168,13 +1164,6 @@ Config =
'thread-watcher.position': 'top: 50px; left: 0px;'
'qr.position': 'top: 50px; right: 0px;'
captchaServiceDomain: ''
captchaServiceKey: [{
'https://api.captcha.guru': ''
'https://azcaptcha.com': ''
'https://2captcha.com': ''
}]
fourchanImageHost: 'i.4cdn.org'
hiddenPSAList: [{}]

View File

@ -8,12 +8,6 @@ Main =
return if '<%= meta.name %> antidup' of w
w['<%= meta.name %> antidup'] = true
if location.hostname is 'www.google.com'
$.get 'Captcha Fixes', true, ({'Captcha Fixes': enabled}) ->
if enabled
$.ready -> Captcha.fixes.init()
return
# Don't run inside ad iframes.
try
return if window.frameElement and window.frameElement.src in ['', 'about:blank']
@ -86,6 +80,9 @@ Main =
Conf['Toggleable Thread Watcher'] = true
Conf['siteSoftware'] = ''
Conf['Use Faster Image Host'] = 'true'
Conf['Captcha Fixes'] = true
Conf['captchaServiceDomain'] = ''
Conf['captchaServiceKey'] = $.dict()
# Enforce JS whitelist
if (
@ -650,7 +647,6 @@ Main =
['Reply Hiding Buttons', PostHiding]
['Recursive', Recursive]
['Strike-through Quotes', QuoteStrikeThrough]
['Captcha Solving Service', Captcha.service]
['Quick Reply Personas', QR.persona]
['Quick Reply', QR]
['Cooldown', QR.cooldown]