Update QR error handling to use some HTML changes. Ban/warn error checking similar to 4chan's QR.
This commit is contained in:
parent
895206730b
commit
1712549f62
@ -1458,19 +1458,21 @@
|
|||||||
toggleHide: function() {
|
toggleHide: function() {
|
||||||
return this.checked && QR.hide() || QR.unhide();
|
return this.checked && QR.hide() || QR.unhide();
|
||||||
},
|
},
|
||||||
error: function(err, node) {
|
error: function(err) {
|
||||||
var el;
|
var el;
|
||||||
el = $('.warning', QR.el);
|
el = $('.warning', QR.el);
|
||||||
el.textContent = err;
|
if (typeof err === 'string') {
|
||||||
if (node) {
|
el.textContent = err;
|
||||||
$.replace(el.firstChild, node);
|
} else {
|
||||||
|
el.innerHTML = null;
|
||||||
|
$.add(el, err);
|
||||||
}
|
}
|
||||||
QR.open();
|
QR.open();
|
||||||
if (/captcha|verification/i.test(err)) {
|
if (/captcha|verification/i.test(el.textContent)) {
|
||||||
$('[autocomplete]', QR.el).focus();
|
$('[autocomplete]', QR.el).focus();
|
||||||
}
|
}
|
||||||
if (d.hidden || d.oHidden || d.mozHidden || d.webkitHidden) {
|
if (d.hidden || d.oHidden || d.mozHidden || d.webkitHidden) {
|
||||||
return alert(err);
|
return alert(el.textContent);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cleanError: function() {
|
cleanError: function() {
|
||||||
@ -2062,7 +2064,7 @@
|
|||||||
return QR.response(this.response);
|
return QR.response(this.response);
|
||||||
},
|
},
|
||||||
onerror: function() {
|
onerror: function() {
|
||||||
return QR.error('_', $.el('a', {
|
return QR.error($.el('a', {
|
||||||
href: '//www.4chan.org/banned',
|
href: '//www.4chan.org/banned',
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
textContent: 'Connection error, or you are banned.'
|
textContent: 'Connection error, or you are banned.'
|
||||||
@ -2088,25 +2090,22 @@
|
|||||||
return QR.ajax = $.ajax($.id('postForm').parentNode.action, callbacks, opts);
|
return QR.ajax = $.ajax($.id('postForm').parentNode.action, callbacks, opts);
|
||||||
},
|
},
|
||||||
response: function(html) {
|
response: function(html) {
|
||||||
var b, doc, err, node, persona, postNumber, reply, thread, _, _ref;
|
var bs, doc, err, msg, persona, postNumber, reply, thread, _, _ref;
|
||||||
doc = d.implementation.createHTMLDocument('');
|
doc = d.implementation.createHTMLDocument('');
|
||||||
doc.documentElement.innerHTML = html;
|
doc.documentElement.innerHTML = html;
|
||||||
if (doc.title === '4chan - Banned') {
|
if (doc.title === '4chan - Banned') {
|
||||||
QR.error('_', $.el('a', {
|
bs = $$('b', doc);
|
||||||
href: '//www.4chan.org/banned',
|
err = $.el('span', {
|
||||||
target: '_blank',
|
innerHTML: /^You were issued a warning/.test($('.boxcontent', doc).textContent.trim()) ? "You were issued a warning on " + bs[0].innerHTML + " as " + bs[3].innerHTML + ".<br>Warning reason: " + bs[1].innerHTML : "You are banned! ;_;<br>Please click <a href=//www.4chan.org/banned target=_blank>HERE</a> to see the reason."
|
||||||
textContent: 'You are banned.'
|
});
|
||||||
}));
|
} else if (msg = doc.getElementById('errmsg')) {
|
||||||
return;
|
err = msg.textContent;
|
||||||
}
|
if (msg.firstChild.tagName) {
|
||||||
if (!(b = $('td b', doc))) {
|
err = msg.firstChild;
|
||||||
err = 'Connection error with sys.4chan.org.';
|
err.target = '_blank';
|
||||||
} else if (b.childElementCount) {
|
|
||||||
if (b.firstChild.tagName) {
|
|
||||||
node = b.firstChild;
|
|
||||||
node.target = '_blank';
|
|
||||||
}
|
}
|
||||||
err = b.firstChild.textContent;
|
} else if (!(msg = $('b', doc))) {
|
||||||
|
err = 'Connection error with sys.4chan.org.';
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
if (/captcha|verification/i.test(err) || err === 'Connection error with sys.4chan.org.') {
|
if (/captcha|verification/i.test(err) || err === 'Connection error with sys.4chan.org.') {
|
||||||
@ -2116,7 +2115,7 @@
|
|||||||
QR.cooldown.auto = false;
|
QR.cooldown.auto = false;
|
||||||
}
|
}
|
||||||
QR.status();
|
QR.status();
|
||||||
QR.error(err, node);
|
QR.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reply = QR.replies[0];
|
reply = QR.replies[0];
|
||||||
@ -2127,7 +2126,7 @@
|
|||||||
sub: Conf['Remember Subject'] ? reply.sub : null
|
sub: Conf['Remember Subject'] ? reply.sub : null
|
||||||
};
|
};
|
||||||
$.set('QR.persona', persona);
|
$.set('QR.persona', persona);
|
||||||
_ref = b.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], postNumber = _ref[2];
|
_ref = msg.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], postNumber = _ref[2];
|
||||||
if (thread === '0') {
|
if (thread === '0') {
|
||||||
if (Conf['Thread Watcher'] && Conf['Auto Watch']) {
|
if (Conf['Thread Watcher'] && Conf['Auto Watch']) {
|
||||||
$.set('autoWatch', postNumber);
|
$.set('autoWatch', postNumber);
|
||||||
|
|||||||
@ -1074,15 +1074,18 @@ QR =
|
|||||||
toggleHide: ->
|
toggleHide: ->
|
||||||
@checked and QR.hide() or QR.unhide()
|
@checked and QR.hide() or QR.unhide()
|
||||||
|
|
||||||
error: (err, node) ->
|
error: (err) ->
|
||||||
el = $ '.warning', QR.el
|
el = $ '.warning', QR.el
|
||||||
el.textContent = err
|
if typeof err is 'string'
|
||||||
$.replace el.firstChild, node if node
|
el.textContent = err
|
||||||
|
else
|
||||||
|
el.innerHTML = null
|
||||||
|
$.add el, err
|
||||||
QR.open()
|
QR.open()
|
||||||
if /captcha|verification/i.test err
|
if /captcha|verification/i.test el.textContent
|
||||||
# Focus the captcha input on captcha error.
|
# Focus the captcha input on captcha error.
|
||||||
$('[autocomplete]', QR.el).focus()
|
$('[autocomplete]', QR.el).focus()
|
||||||
alert err if d.hidden or d.oHidden or d.mozHidden or d.webkitHidden
|
alert el.textContent if d.hidden or d.oHidden or d.mozHidden or d.webkitHidden
|
||||||
cleanError: ->
|
cleanError: ->
|
||||||
$('.warning', QR.el).textContent = null
|
$('.warning', QR.el).textContent = null
|
||||||
|
|
||||||
@ -1561,7 +1564,7 @@ QR =
|
|||||||
onerror: ->
|
onerror: ->
|
||||||
# Connection error, or
|
# Connection error, or
|
||||||
# CORS disabled error on www.4chan.org/banned
|
# CORS disabled error on www.4chan.org/banned
|
||||||
QR.error '_', $.el 'a',
|
QR.error $.el 'a',
|
||||||
href: '//www.4chan.org/banned'
|
href: '//www.4chan.org/banned'
|
||||||
target: '_blank'
|
target: '_blank'
|
||||||
textContent: 'Connection error, or you are banned.'
|
textContent: 'Connection error, or you are banned.'
|
||||||
@ -1581,20 +1584,21 @@ QR =
|
|||||||
response: (html) ->
|
response: (html) ->
|
||||||
doc = d.implementation.createHTMLDocument ''
|
doc = d.implementation.createHTMLDocument ''
|
||||||
doc.documentElement.innerHTML = html
|
doc.documentElement.innerHTML = html
|
||||||
# Check for ban.
|
if doc.title is '4chan - Banned' # Ban/warn check
|
||||||
if doc.title is '4chan - Banned'
|
bs = $$ 'b', doc
|
||||||
QR.error '_', $.el 'a',
|
err = $.el 'span',
|
||||||
href: '//www.4chan.org/banned'
|
innerHTML:
|
||||||
target: '_blank'
|
if /^You were issued a warning/.test $('.boxcontent', doc).textContent.trim()
|
||||||
textContent: 'You are banned.'
|
"You were issued a warning on #{bs[0].innerHTML} as #{bs[3].innerHTML}.<br>Warning reason: #{bs[1].innerHTML}"
|
||||||
return
|
else
|
||||||
unless b = $ 'td b', doc
|
"You are banned! ;_;<br>Please click <a href=//www.4chan.org/banned target=_blank>HERE</a> to see the reason."
|
||||||
|
else if msg = doc.getElementById 'errmsg' # error!
|
||||||
|
err = msg.textContent
|
||||||
|
if msg.firstChild.tagName # duplicate image link
|
||||||
|
err = msg.firstChild
|
||||||
|
err.target = '_blank'
|
||||||
|
else unless msg = $ 'b', doc
|
||||||
err = 'Connection error with sys.4chan.org.'
|
err = 'Connection error with sys.4chan.org.'
|
||||||
else if b.childElementCount # error!
|
|
||||||
if b.firstChild.tagName # duplicate image link
|
|
||||||
node = b.firstChild
|
|
||||||
node.target = '_blank'
|
|
||||||
err = b.firstChild.textContent
|
|
||||||
|
|
||||||
if err
|
if err
|
||||||
if /captcha|verification/i.test(err) or err is 'Connection error with sys.4chan.org.'
|
if /captcha|verification/i.test(err) or err is 'Connection error with sys.4chan.org.'
|
||||||
@ -1606,7 +1610,7 @@ QR =
|
|||||||
else # stop auto-posting
|
else # stop auto-posting
|
||||||
QR.cooldown.auto = false
|
QR.cooldown.auto = false
|
||||||
QR.status()
|
QR.status()
|
||||||
QR.error err, node
|
QR.error err
|
||||||
return
|
return
|
||||||
|
|
||||||
reply = QR.replies[0]
|
reply = QR.replies[0]
|
||||||
@ -1618,7 +1622,7 @@ QR =
|
|||||||
sub: if Conf['Remember Subject'] then reply.sub else null
|
sub: if Conf['Remember Subject'] then reply.sub else null
|
||||||
$.set 'QR.persona', persona
|
$.set 'QR.persona', persona
|
||||||
|
|
||||||
[_, thread, postNumber] = b.lastChild.textContent.match /thread:(\d+),no:(\d+)/
|
[_, thread, postNumber] = msg.lastChild.textContent.match /thread:(\d+),no:(\d+)/
|
||||||
if thread is '0' # new thread
|
if thread is '0' # new thread
|
||||||
if Conf['Thread Watcher'] and Conf['Auto Watch']
|
if Conf['Thread Watcher'] and Conf['Auto Watch']
|
||||||
$.set 'autoWatch', postNumber
|
$.set 'autoWatch', postNumber
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user