diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae8059731..7e50dca54 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
**MayhemYDG**:
-- Fix captcha not refreshing.
+- Fix captcha submission:
+ Captchas were reloaded the instant a post was submitted to 4chan. Unfortunately, a recent change to reCAPTCHA made it so reloading captchas invalidates the ones that loaded but not yet used. This is now fixed by only unloading the captcha, and only load new ones after the post is submitted.
+ This also kills captcha caching, so the feature was removed.
- Thread and post hiding changes:
- The posts' menu now has a label entry listing the reasons why a post got hidden or highlighted.
- `Thread Hiding` and `Reply Hiding` settings are merged into one: `Post Hiding`.
diff --git a/LICENSE b/LICENSE
index d59212551..160826428 100755
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
/*
-* 4chan X - Version 1.4.1 - 2014-03-30
+* 4chan X - Version 1.4.1 - 2014-04-02
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js
index 8e58d25f6..5da9402c1 100644
--- a/builds/4chan-X.user.js
+++ b/builds/4chan-X.user.js
@@ -24,7 +24,7 @@
// ==/UserScript==
/*
-* 4chan X - Version 1.4.1 - 2014-03-30
+* 4chan X - Version 1.4.1 - 2014-04-02
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@@ -6686,6 +6686,10 @@
onload: QR.response,
onerror: function() {
delete QR.req;
+ if (QR.captcha.isEnabled) {
+ QR.captcha.destroy();
+ QR.captcha.setup();
+ }
post.unlock();
QR.cooldown.auto = false;
QR.status();
@@ -6715,9 +6719,12 @@
return QR.status();
},
response: function() {
- var URL, ban, board, captchasCount, err, h1, isReply, m, notif, post, postID, postsCount, req, resDoc, threadID, _, _ref, _ref1;
+ var URL, ban, board, err, h1, isReply, m, post, postID, postsCount, req, resDoc, threadID, _, _ref, _ref1;
req = QR.req;
delete QR.req;
+ if (QR.captcha.isEnabled) {
+ QR.captcha.destroy();
+ }
post = QR.posts[0];
post.unlock();
resDoc = req.response;
@@ -6739,15 +6746,13 @@
if (/captcha|verification/i.test(err.textContent) || err === 'Connection error with sys.4chan.org.') {
if (/mistyped/i.test(err.textContent)) {
err = 'You seem to have mistyped the CAPTCHA.';
- } else if (/expired/i.test(err.textContent)) {
- err = 'This CAPTCHA is no longer valid because it has expired.';
}
- QR.cooldown.auto = QR.captcha.isEnabled ? !!QR.captcha.captchas.length : err === 'Connection error with sys.4chan.org.' ? true : false;
+ QR.cooldown.auto = false;
QR.cooldown.set({
delay: 2
});
} else if (err.textContent && (m = err.textContent.match(/wait\s+(\d+)\s+second/i))) {
- QR.cooldown.auto = QR.captcha.isEnabled ? !!QR.captcha.captchas.length : true;
+ QR.cooldown.auto = !QR.captcha.isEnabled;
QR.cooldown.set({
delay: m[1]
});
@@ -6786,22 +6791,6 @@
});
postsCount = QR.posts.length - 1;
QR.cooldown.auto = postsCount && isReply;
- if (QR.cooldown.auto && QR.captcha.isEnabled && (captchasCount = QR.captcha.captchas.length) < 3 && captchasCount < postsCount) {
- notif = new Notification('Quick reply warning', {
- body: "You are running low on cached captchas. Cache count: " + captchasCount + ".",
- icon: Favicon.logo
- });
- notif.onclick = function() {
- QR.open();
- QR.captcha.nodes.input.focus();
- return window.focus();
- };
- notif.onshow = function() {
- return setTimeout(function() {
- return notif.close();
- }, 7 * $.SECOND);
- };
- }
if (!(Conf['Persistent QR'] || QR.cooldown.auto)) {
QR.close();
} else {
@@ -6837,12 +6826,11 @@
QR.captcha = {
init: function() {
- var container, imgContainer, input;
+ var imgContainer, input;
if (d.cookie.indexOf('pass_enabled=1') >= 0) {
return;
}
- container = $.id('captchaContainer');
- if (!(this.isEnabled = !!container)) {
+ if (!(this.isEnabled = !!$.id('captchaContainer'))) {
return;
}
if (Conf['Auto-load captcha']) {
@@ -6851,13 +6839,11 @@
imgContainer = $.el('div', {
className: 'captcha-img',
title: 'Reload reCAPTCHA',
- innerHTML: '
',
- hidden: true
+ innerHTML: '
'
});
input = $.el('input', {
className: 'captcha-input field',
title: 'Verification',
- placeholder: 'Focus to load reCAPTCHA',
autocomplete: 'off',
spellcheck: false,
tabIndex: 45
@@ -6866,44 +6852,41 @@
img: imgContainer.firstChild,
input: input
};
- $.on(input, 'focus', this.setup);
$.on(input, 'blur', QR.focusout);
$.on(input, 'focus', QR.focusin);
$.addClass(QR.nodes.el, 'has-captcha');
$.after(QR.nodes.com.parentNode, [imgContainer, input]);
+ this.beforeSetup();
+ return this.afterSetup();
+ },
+ beforeSetup: function() {
+ var img, input, _ref;
+ _ref = this.nodes, img = _ref.img, input = _ref.input;
+ img.parentNode.hidden = true;
+ input.value = '';
+ input.placeholder = 'Focus to load reCAPTCHA';
+ $.on(input, 'focus', this.setup);
this.setupObserver = new MutationObserver(this.afterSetup);
- this.setupObserver.observe(container, {
+ return this.setupObserver.observe($.id('captchaContainer'), {
childList: true
});
- return this.afterSetup();
},
setup: function() {
return $.globalEval('loadRecaptcha()');
},
afterSetup: function() {
- var challenge, img, input, setLifetime, _ref;
+ var challenge, img, input, _ref;
if (!(challenge = $.id('recaptcha_challenge_field_holder'))) {
return;
}
QR.captcha.setupObserver.disconnect();
delete QR.captcha.setupObserver;
- setLifetime = function(e) {
- return QR.captcha.lifetime = e.detail;
- };
- $.on(window, 'captcha:timeout', setLifetime);
- $.globalEval('window.dispatchEvent(new CustomEvent("captcha:timeout", {detail: RecaptchaState.timeout}))');
- $.off(window, 'captcha:timeout', setLifetime);
_ref = QR.captcha.nodes, img = _ref.img, input = _ref.input;
img.parentNode.hidden = false;
+ input.placeholder = 'Verification';
$.off(input, 'focus', QR.captcha.setup);
$.on(input, 'keydown', QR.captcha.keydown.bind(QR.captcha));
$.on(img.parentNode, 'click', QR.captcha.reload.bind(QR.captcha));
- $.get('captchas', [], function(_arg) {
- var captchas;
- captchas = _arg.captchas;
- return QR.captcha.sync(captchas);
- });
- $.sync('captchas', QR.captcha.sync);
QR.captcha.nodes.challenge = challenge;
new MutationObserver(QR.captcha.load.bind(QR.captcha)).observe(challenge, {
childList: true,
@@ -6912,94 +6895,31 @@
});
return QR.captcha.load();
},
- sync: function(captchas) {
- QR.captcha.captchas = captchas;
- return QR.captcha.count();
+ destroy: function() {
+ $.globalEval('Recaptcha.destroy()');
+ return this.beforeSetup();
},
getOne: function() {
- var captcha, challenge, response;
- this.clear();
- if (captcha = this.captchas.shift()) {
- challenge = captcha.challenge, response = captcha.response;
- this.count();
- $.set('captchas', this.captchas);
- } else {
- challenge = this.nodes.img.alt;
- if (response = this.nodes.input.value) {
- this.reload();
- }
- }
- if (response) {
- response = response.trim();
- if (!/\s/.test(response)) {
- response = "" + response + " " + response;
- }
+ var challenge, response;
+ challenge = this.nodes.img.alt;
+ response = this.nodes.input.value.trim();
+ if (response && !/\s/.test(response)) {
+ response = "" + response + " " + response;
}
return {
challenge: challenge,
response: response
};
},
- save: function() {
- var response;
- if (!(response = this.nodes.input.value.trim())) {
- return;
- }
- this.captchas.push({
- challenge: this.nodes.img.alt,
- response: response,
- timeout: this.timeout
- });
- this.count();
- this.reload();
- return $.set('captchas', this.captchas);
- },
- clear: function() {
- var captcha, i, now, _i, _len, _ref;
- if (!this.captchas) {
- return;
- }
- now = Date.now();
- _ref = this.captchas;
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
- captcha = _ref[i];
- if (captcha.timeout > now) {
- break;
- }
- }
- if (!i) {
- return;
- }
- this.captchas = this.captchas.slice(i);
- this.count();
- return $.set('captchas', this.captchas);
- },
load: function() {
var challenge;
if (!this.nodes.challenge.firstChild) {
return;
}
- this.timeout = Date.now() + this.lifetime * $.SECOND - $.MINUTE;
challenge = this.nodes.challenge.firstChild.value;
this.nodes.img.alt = challenge;
this.nodes.img.src = "//www.google.com/recaptcha/api/image?c=" + challenge;
- this.nodes.input.value = null;
- return this.clear();
- },
- count: function() {
- var count;
- count = this.captchas ? this.captchas.length : 0;
- this.nodes.input.placeholder = (function() {
- switch (count) {
- case 0:
- return 'Verification (Shift + Enter to cache)';
- case 1:
- return 'Verification (1 cached captcha)';
- default:
- return "Verification (" + count + " cached captchas)";
- }
- })();
- return this.nodes.input.alt = count;
+ return this.nodes.input.value = null;
},
reload: function(focus) {
$.globalEval('Recaptcha.reload("t")');
@@ -7010,8 +6930,6 @@
keydown: function(e) {
if (e.keyCode === 8 && !this.nodes.input.value) {
this.reload();
- } else if (e.keyCode === 13 && e.shiftKey) {
- this.save();
} else {
return;
}
@@ -7343,6 +7261,9 @@
node.disabled = lock;
}
}
+ if (QR.captcha.isEnabled) {
+ QR.captcha.nodes.input.disabled = lock;
+ }
this.nodes.rm.style.visibility = lock ? 'hidden' : '';
(lock ? $.off : $.on)(QR.nodes.filename.previousElementSibling, 'click', QR.openFileInput);
this.nodes.spoiler.disabled = lock;
diff --git a/builds/crx/script.js b/builds/crx/script.js
index ed5b198c7..9b63ae070 100644
--- a/builds/crx/script.js
+++ b/builds/crx/script.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
-* 4chan X - Version 1.4.1 - 2014-03-30
+* 4chan X - Version 1.4.1 - 2014-04-02
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@@ -6731,6 +6731,10 @@
onload: QR.response,
onerror: function() {
delete QR.req;
+ if (QR.captcha.isEnabled) {
+ QR.captcha.destroy();
+ QR.captcha.setup();
+ }
post.unlock();
QR.cooldown.auto = false;
QR.status();
@@ -6760,9 +6764,12 @@
return QR.status();
},
response: function() {
- var URL, ban, board, captchasCount, err, h1, isReply, m, notif, post, postID, postsCount, req, resDoc, threadID, _, _ref, _ref1;
+ var URL, ban, board, err, h1, isReply, m, post, postID, postsCount, req, resDoc, threadID, _, _ref, _ref1;
req = QR.req;
delete QR.req;
+ if (QR.captcha.isEnabled) {
+ QR.captcha.destroy();
+ }
post = QR.posts[0];
post.unlock();
resDoc = req.response;
@@ -6784,15 +6791,13 @@
if (/captcha|verification/i.test(err.textContent) || err === 'Connection error with sys.4chan.org.') {
if (/mistyped/i.test(err.textContent)) {
err = 'You seem to have mistyped the CAPTCHA.';
- } else if (/expired/i.test(err.textContent)) {
- err = 'This CAPTCHA is no longer valid because it has expired.';
}
- QR.cooldown.auto = QR.captcha.isEnabled ? !!QR.captcha.captchas.length : err === 'Connection error with sys.4chan.org.' ? true : false;
+ QR.cooldown.auto = false;
QR.cooldown.set({
delay: 2
});
} else if (err.textContent && (m = err.textContent.match(/wait\s+(\d+)\s+second/i))) {
- QR.cooldown.auto = QR.captcha.isEnabled ? !!QR.captcha.captchas.length : true;
+ QR.cooldown.auto = !QR.captcha.isEnabled;
QR.cooldown.set({
delay: m[1]
});
@@ -6831,22 +6836,6 @@
});
postsCount = QR.posts.length - 1;
QR.cooldown.auto = postsCount && isReply;
- if (QR.cooldown.auto && QR.captcha.isEnabled && (captchasCount = QR.captcha.captchas.length) < 3 && captchasCount < postsCount) {
- notif = new Notification('Quick reply warning', {
- body: "You are running low on cached captchas. Cache count: " + captchasCount + ".",
- icon: Favicon.logo
- });
- notif.onclick = function() {
- QR.open();
- QR.captcha.nodes.input.focus();
- return window.focus();
- };
- notif.onshow = function() {
- return setTimeout(function() {
- return notif.close();
- }, 7 * $.SECOND);
- };
- }
if (!(Conf['Persistent QR'] || QR.cooldown.auto)) {
QR.close();
} else {
@@ -6882,12 +6871,11 @@
QR.captcha = {
init: function() {
- var container, imgContainer, input;
+ var imgContainer, input;
if (d.cookie.indexOf('pass_enabled=1') >= 0) {
return;
}
- container = $.id('captchaContainer');
- if (!(this.isEnabled = !!container)) {
+ if (!(this.isEnabled = !!$.id('captchaContainer'))) {
return;
}
if (Conf['Auto-load captcha']) {
@@ -6896,13 +6884,11 @@
imgContainer = $.el('div', {
className: 'captcha-img',
title: 'Reload reCAPTCHA',
- innerHTML: '
',
- hidden: true
+ innerHTML: '
'
});
input = $.el('input', {
className: 'captcha-input field',
title: 'Verification',
- placeholder: 'Focus to load reCAPTCHA',
autocomplete: 'off',
spellcheck: false,
tabIndex: 45
@@ -6911,44 +6897,41 @@
img: imgContainer.firstChild,
input: input
};
- $.on(input, 'focus', this.setup);
$.on(input, 'blur', QR.focusout);
$.on(input, 'focus', QR.focusin);
$.addClass(QR.nodes.el, 'has-captcha');
$.after(QR.nodes.com.parentNode, [imgContainer, input]);
+ this.beforeSetup();
+ return this.afterSetup();
+ },
+ beforeSetup: function() {
+ var img, input, _ref;
+ _ref = this.nodes, img = _ref.img, input = _ref.input;
+ img.parentNode.hidden = true;
+ input.value = '';
+ input.placeholder = 'Focus to load reCAPTCHA';
+ $.on(input, 'focus', this.setup);
this.setupObserver = new MutationObserver(this.afterSetup);
- this.setupObserver.observe(container, {
+ return this.setupObserver.observe($.id('captchaContainer'), {
childList: true
});
- return this.afterSetup();
},
setup: function() {
return $.globalEval('loadRecaptcha()');
},
afterSetup: function() {
- var challenge, img, input, setLifetime, _ref;
+ var challenge, img, input, _ref;
if (!(challenge = $.id('recaptcha_challenge_field_holder'))) {
return;
}
QR.captcha.setupObserver.disconnect();
delete QR.captcha.setupObserver;
- setLifetime = function(e) {
- return QR.captcha.lifetime = e.detail;
- };
- $.on(window, 'captcha:timeout', setLifetime);
- $.globalEval('window.dispatchEvent(new CustomEvent("captcha:timeout", {detail: RecaptchaState.timeout}))');
- $.off(window, 'captcha:timeout', setLifetime);
_ref = QR.captcha.nodes, img = _ref.img, input = _ref.input;
img.parentNode.hidden = false;
+ input.placeholder = 'Verification';
$.off(input, 'focus', QR.captcha.setup);
$.on(input, 'keydown', QR.captcha.keydown.bind(QR.captcha));
$.on(img.parentNode, 'click', QR.captcha.reload.bind(QR.captcha));
- $.get('captchas', [], function(_arg) {
- var captchas;
- captchas = _arg.captchas;
- return QR.captcha.sync(captchas);
- });
- $.sync('captchas', QR.captcha.sync);
QR.captcha.nodes.challenge = challenge;
new MutationObserver(QR.captcha.load.bind(QR.captcha)).observe(challenge, {
childList: true,
@@ -6957,94 +6940,31 @@
});
return QR.captcha.load();
},
- sync: function(captchas) {
- QR.captcha.captchas = captchas;
- return QR.captcha.count();
+ destroy: function() {
+ $.globalEval('Recaptcha.destroy()');
+ return this.beforeSetup();
},
getOne: function() {
- var captcha, challenge, response;
- this.clear();
- if (captcha = this.captchas.shift()) {
- challenge = captcha.challenge, response = captcha.response;
- this.count();
- $.set('captchas', this.captchas);
- } else {
- challenge = this.nodes.img.alt;
- if (response = this.nodes.input.value) {
- this.reload();
- }
- }
- if (response) {
- response = response.trim();
- if (!/\s/.test(response)) {
- response = "" + response + " " + response;
- }
+ var challenge, response;
+ challenge = this.nodes.img.alt;
+ response = this.nodes.input.value.trim();
+ if (response && !/\s/.test(response)) {
+ response = "" + response + " " + response;
}
return {
challenge: challenge,
response: response
};
},
- save: function() {
- var response;
- if (!(response = this.nodes.input.value.trim())) {
- return;
- }
- this.captchas.push({
- challenge: this.nodes.img.alt,
- response: response,
- timeout: this.timeout
- });
- this.count();
- this.reload();
- return $.set('captchas', this.captchas);
- },
- clear: function() {
- var captcha, i, now, _i, _len, _ref;
- if (!this.captchas) {
- return;
- }
- now = Date.now();
- _ref = this.captchas;
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
- captcha = _ref[i];
- if (captcha.timeout > now) {
- break;
- }
- }
- if (!i) {
- return;
- }
- this.captchas = this.captchas.slice(i);
- this.count();
- return $.set('captchas', this.captchas);
- },
load: function() {
var challenge;
if (!this.nodes.challenge.firstChild) {
return;
}
- this.timeout = Date.now() + this.lifetime * $.SECOND - $.MINUTE;
challenge = this.nodes.challenge.firstChild.value;
this.nodes.img.alt = challenge;
this.nodes.img.src = "//www.google.com/recaptcha/api/image?c=" + challenge;
- this.nodes.input.value = null;
- return this.clear();
- },
- count: function() {
- var count;
- count = this.captchas ? this.captchas.length : 0;
- this.nodes.input.placeholder = (function() {
- switch (count) {
- case 0:
- return 'Verification (Shift + Enter to cache)';
- case 1:
- return 'Verification (1 cached captcha)';
- default:
- return "Verification (" + count + " cached captchas)";
- }
- })();
- return this.nodes.input.alt = count;
+ return this.nodes.input.value = null;
},
reload: function(focus) {
$.globalEval('Recaptcha.reload("t")');
@@ -7055,8 +6975,6 @@
keydown: function(e) {
if (e.keyCode === 8 && !this.nodes.input.value) {
this.reload();
- } else if (e.keyCode === 13 && e.shiftKey) {
- this.save();
} else {
return;
}
@@ -7382,6 +7300,9 @@
node.disabled = lock;
}
}
+ if (QR.captcha.isEnabled) {
+ QR.captcha.nodes.input.disabled = lock;
+ }
this.nodes.rm.style.visibility = lock ? 'hidden' : '';
(lock ? $.off : $.on)(QR.nodes.filename.previousElementSibling, 'click', QR.openFileInput);
this.nodes.spoiler.disabled = lock;
diff --git a/src/Posting/QR.captcha.coffee b/src/Posting/QR.captcha.coffee
index 7900535c6..0a182b017 100644
--- a/src/Posting/QR.captcha.coffee
+++ b/src/Posting/QR.captcha.coffee
@@ -1,8 +1,7 @@
QR.captcha =
init: ->
return if d.cookie.indexOf('pass_enabled=1') >= 0
- container = $.id 'captchaContainer'
- return unless @isEnabled = !!container
+ return unless @isEnabled = !!$.id 'captchaContainer'
$.globalEval 'loadRecaptcha()' if Conf['Auto-load captcha']
@@ -10,11 +9,9 @@ QR.captcha =
className: 'captcha-img'
title: 'Reload reCAPTCHA'
innerHTML: '
'
- hidden: true
input = $.el 'input',
className: 'captcha-input field'
title: 'Verification'
- placeholder: 'Focus to load reCAPTCHA'
autocomplete: 'off'
spellcheck: false
tabIndex: 45
@@ -22,18 +19,24 @@ QR.captcha =
img: imgContainer.firstChild
input: input
- $.on input, 'focus', @setup
-
$.on input, 'blur', QR.focusout
$.on input, 'focus', QR.focusin
$.addClass QR.nodes.el, 'has-captcha'
$.after QR.nodes.com.parentNode, [imgContainer, input]
- @setupObserver = new MutationObserver @afterSetup
- @setupObserver.observe container, childList: true
+ @beforeSetup()
@afterSetup() # reCAPTCHA might have loaded before the QR.
+ beforeSetup: ->
+ {img, input} = @nodes
+ img.parentNode.hidden = true
+ input.value = ''
+ input.placeholder = 'Focus to load reCAPTCHA'
+ $.on input, 'focus', @setup
+ @setupObserver = new MutationObserver @afterSetup
+ @setupObserver.observe $.id('captchaContainer'), childList: true
+
setup: ->
$.globalEval 'loadRecaptcha()'
@@ -42,21 +45,13 @@ QR.captcha =
QR.captcha.setupObserver.disconnect()
delete QR.captcha.setupObserver
- setLifetime = (e) -> QR.captcha.lifetime = e.detail
- $.on window, 'captcha:timeout', setLifetime
- $.globalEval 'window.dispatchEvent(new CustomEvent("captcha:timeout", {detail: RecaptchaState.timeout}))'
- $.off window, 'captcha:timeout', setLifetime
-
{img, input} = QR.captcha.nodes
img.parentNode.hidden = false
+ input.placeholder = 'Verification'
$.off input, 'focus', QR.captcha.setup
$.on input, 'keydown', QR.captcha.keydown.bind QR.captcha
$.on img.parentNode, 'click', QR.captcha.reload.bind QR.captcha
- $.get 'captchas', [], ({captchas}) ->
- QR.captcha.sync captchas
- $.sync 'captchas', QR.captcha.sync
-
QR.captcha.nodes.challenge = challenge
new MutationObserver(QR.captcha.load.bind QR.captcha).observe challenge,
childList: true
@@ -64,67 +59,26 @@ QR.captcha =
attributes: true
QR.captcha.load()
- sync: (captchas) ->
- QR.captcha.captchas = captchas
- QR.captcha.count()
+ destroy: ->
+ $.globalEval 'Recaptcha.destroy()'
+ @beforeSetup()
getOne: ->
- @clear()
- if captcha = @captchas.shift()
- {challenge, response} = captcha
- @count()
- $.set 'captchas', @captchas
- else
- challenge = @nodes.img.alt
- if response = @nodes.input.value then @reload()
- if response
- response = response.trim()
+ challenge = @nodes.img.alt
+ response = @nodes.input.value.trim()
+ if response and !/\s/.test response
# one-word-captcha:
# If there's only one word, duplicate it.
- response = "#{response} #{response}" unless /\s/.test response
+ response = "#{response} #{response}"
{challenge, response}
- save: ->
- return unless response = @nodes.input.value.trim()
- @captchas.push
- challenge: @nodes.img.alt
- response: response
- timeout: @timeout
- @count()
- @reload()
- $.set 'captchas', @captchas
-
- clear: ->
- return unless @captchas # not loaded yet.
-
- now = Date.now()
- for captcha, i in @captchas
- break if captcha.timeout > now
- return unless i
- @captchas = @captchas[i..]
- @count()
- $.set 'captchas', @captchas
-
load: ->
return unless @nodes.challenge.firstChild
# -1 minute to give upload some time.
- @timeout = Date.now() + @lifetime * $.SECOND - $.MINUTE
challenge = @nodes.challenge.firstChild.value
@nodes.img.alt = challenge
@nodes.img.src = "//www.google.com/recaptcha/api/image?c=#{challenge}"
@nodes.input.value = null
- @clear()
-
- count: ->
- count = if @captchas then @captchas.length else 0
- @nodes.input.placeholder = switch count
- when 0
- 'Verification (Shift + Enter to cache)'
- when 1
- 'Verification (1 cached captcha)'
- else
- "Verification (#{count} cached captchas)"
- @nodes.input.alt = count # For XTRM RICE.
reload: (focus) ->
# the 't' argument prevents the input from being focused
@@ -135,8 +89,6 @@ QR.captcha =
keydown: (e) ->
if e.keyCode is 8 and not @nodes.input.value
@reload()
- else if e.keyCode is 13 and e.shiftKey
- @save()
else
return
e.preventDefault()
diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee
index fe02c945c..40bc1d30e 100644
--- a/src/Posting/QR.coffee
+++ b/src/Posting/QR.coffee
@@ -678,6 +678,9 @@ QR =
onerror: ->
# Connection error, or www.4chan.org/banned
delete QR.req
+ if QR.captcha.isEnabled
+ QR.captcha.destroy()
+ QR.captcha.setup()
post.unlock()
QR.cooldown.auto = false
QR.status()
@@ -711,6 +714,7 @@ QR =
{req} = QR
delete QR.req
+ QR.captcha.destroy() if QR.captcha.isEnabled
post = QR.posts[0]
post.unlock()
@@ -740,25 +744,12 @@ QR =
# Remove the obnoxious 4chan Pass ad.
if /mistyped/i.test err.textContent
err = 'You seem to have mistyped the CAPTCHA.'
- else if /expired/i.test err.textContent
- err = 'This CAPTCHA is no longer valid because it has expired.'
- # Enable auto-post if we have some cached captchas.
- QR.cooldown.auto = if QR.captcha.isEnabled
- !!QR.captcha.captchas.length
- else if err is 'Connection error with sys.4chan.org.'
- true
- else
- # Something must've gone terribly wrong if you get captcha errors without captchas.
- # Don't auto-post indefinitely in that case.
- false
+ QR.cooldown.auto = false
# Too many frequent mistyped captchas will auto-ban you!
# On connection error, the post most likely didn't go through.
QR.cooldown.set delay: 2
else if err.textContent and m = err.textContent.match /wait\s+(\d+)\s+second/i
- QR.cooldown.auto = if QR.captcha.isEnabled
- !!QR.captcha.captchas.length
- else
- true
+ QR.cooldown.auto = !QR.captcha.isEnabled
QR.cooldown.set delay: m[1]
else # stop auto-posting
QR.cooldown.auto = false
@@ -798,18 +789,6 @@ QR =
# Enable auto-posting if we have stuff left to post, disable it otherwise.
postsCount = QR.posts.length - 1
QR.cooldown.auto = postsCount and isReply
- if QR.cooldown.auto and QR.captcha.isEnabled and (captchasCount = QR.captcha.captchas.length) < 3 and captchasCount < postsCount
- notif = new Notification 'Quick reply warning',
- body: "You are running low on cached captchas. Cache count: #{captchasCount}."
- icon: Favicon.logo
- notif.onclick = ->
- QR.open()
- QR.captcha.nodes.input.focus()
- window.focus()
- notif.onshow = ->
- setTimeout ->
- notif.close()
- , 7 * $.SECOND
unless Conf['Persistent QR'] or QR.cooldown.auto
QR.close()
diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee
index 09705e73a..795922cd2 100644
--- a/src/Posting/QR.post.coffee
+++ b/src/Posting/QR.post.coffee
@@ -91,6 +91,8 @@ QR.post = class
return unless @ is QR.selected
for name in ['thread', 'name', 'email', 'sub', 'com', 'fileButton', 'filename', 'spoiler', 'flag'] when node = QR.nodes[name]
node.disabled = lock
+ if QR.captcha.isEnabled
+ QR.captcha.nodes.input.disabled = lock
@nodes.rm.style.visibility = if lock then 'hidden' else ''
(if lock then $.off else $.on) QR.nodes.filename.previousElementSibling, 'click', QR.openFileInput
@nodes.spoiler.disabled = lock