Random fixes and tweaks.

This commit is contained in:
Nicolas Stepien 2012-05-07 09:46:15 +02:00
parent fec14cfb16
commit f6bb81cfcd
2 changed files with 59 additions and 56 deletions

View File

@ -646,7 +646,7 @@
if (isOP && result[1] && !g.REPLY) { if (isOP && result[1] && !g.REPLY) {
thisThread = root.parentNode; thisThread = root.parentNode;
if (firstThread = $('div[class=thread]')) { if (firstThread = $('div[class=thread]')) {
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]); $.before(firstThread, [thisThread, thisThread.nextElementSibling]);
} }
} }
} }
@ -833,21 +833,20 @@
return _results; return _results;
}, },
toggle: function(thread) { toggle: function(thread) {
var a, backlink, container, num, pathname, replies, reply, _i, _j, _len, _len1, _ref, _results; var a, backlink, num, pathname, replies, reply, _i, _j, _len, _len1, _ref;
pathname = "/" + g.BOARD + "/res/" + thread.id.slice(1); pathname = "/" + g.BOARD + "/res/" + thread.id.slice(1);
a = $('.summary', thread); a = $('.summary', thread);
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
if (container = $('.container', a.previousElementSibling)) {
$.rm(container);
}
a.textContent = a.textContent.replace('+', '\u00d7 Loading...'); a.textContent = a.textContent.replace('+', '\u00d7 Loading...');
return $.cache(pathname, function() { $.cache(pathname, function() {
return ExpandThread.parse(this, pathname, thread, a); return ExpandThread.parse(this, thread, a);
}); });
break;
case '\u00d7': case '\u00d7':
a.textContent = a.textContent.replace('\u00d7 Loading...', '+'); a.textContent = a.textContent.replace('\u00d7 Loading...', '+');
return $.cache.requests[pathname].abort(); $.cache.requests[pathname].abort();
break;
case '-': case '-':
a.textContent = a.textContent.replace('-', '+'); a.textContent = a.textContent.replace('-', '+');
num = (function() { num = (function() {
@ -868,20 +867,16 @@
$.rm(reply); $.rm(reply);
} }
_ref = $$('.backlink', a.previousElementSibling); _ref = $$('.backlink', a.previousElementSibling);
_results = [];
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
backlink = _ref[_j]; backlink = _ref[_j];
if (!$.id(backlink.hash.slice(1))) { if (!$.id(backlink.hash.slice(1))) {
_results.push($.rm(backlink)); $.rm(backlink);
} else {
_results.push(void 0);
} }
} }
return _results;
} }
}, },
parse: function(req, pathname, thread, a) { parse: function(req, thread, a) {
var doc, href, id, link, next, nodes, quote, reply, threadID, _i, _j, _len, _len1, _ref, _ref1; var backlink, doc, href, id, link, nodes, post, quote, reply, threadID, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3;
if (req.status !== 200) { if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText; a.textContent = "" + req.status + " " + req.statusText;
$.off(a, 'click', ExpandThread.cb.toggle); $.off(a, 'click', ExpandThread.cb.toggle);
@ -911,8 +906,17 @@
link.nextSibling.href = "res/" + threadID + "#q" + id; link.nextSibling.href = "res/" + threadID + "#q" + id;
nodes.push(reply); nodes.push(reply);
} }
while (next = a.nextSibling) { _ref2 = $$('.summary ~ .replyContainer', a.parentNode);
$.rm(next); for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
post = _ref2[_k];
$.rm(post);
}
_ref3 = $$('.backlink', a.previousElementSibling);
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
backlink = _ref3[_l];
if (!$.id(backlink.hash.slice(1))) {
$.rm(backlink);
}
} }
return $.after(a, nodes); return $.after(a, nodes);
} }
@ -1485,15 +1489,15 @@
if (data == null) { if (data == null) {
data = {}; data = {};
} }
if (!QR.el) {
return;
}
if (g.dead) { if (g.dead) {
value = 404; value = 404;
disabled = true; disabled = true;
QR.cooldown.auto = false; QR.cooldown.auto = false;
} }
value = QR.cooldown.seconds || data.progress || value; value = QR.cooldown.seconds || data.progress || value;
if (!QR.el) {
return;
}
input = QR.status.input; input = QR.status.input;
input.value = QR.cooldown.auto && Conf['Cooldown'] ? value ? "Auto " + value : 'Auto' : value || 'Submit'; input.value = QR.cooldown.auto && Conf['Cooldown'] ? value ? "Auto " + value : 'Auto' : value || 'Submit';
return input.disabled = disabled || false; return input.disabled = disabled || false;
@ -1542,10 +1546,10 @@
if (!g.REPLY) { if (!g.REPLY) {
$('select', QR.el).value = $.x('ancestor::div[@class="thread"]', this).id.slice(1); $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', this).id.slice(1);
} }
id = this.parentNode.parentNode.id.slice(2); id = this.previousSibling.hash.slice(2);
text = ">>" + id + "\n"; text = ">>" + id + "\n";
sel = window.getSelection(); sel = window.getSelection();
if ((s = sel.toString()) && id === ((_ref = $.x('ancestor-or-self::blockquote', sel.anchorNode)) != null ? _ref.id.slice(1) : void 0)) { if ((s = sel.toString()) && id === ((_ref = $.x('ancestor-or-self::blockquote', sel.anchorNode)) != null ? _ref.id.match(/\d+$/)[0] : void 0)) {
s = s.replace(/\n/g, '\n>'); s = s.replace(/\n/g, '\n>');
text += ">" + s + "\n"; text += ">" + s + "\n";
} }
@ -1553,7 +1557,6 @@
caretPos = ta.selectionStart; caretPos = ta.selectionStart;
QR.selected.el.lastChild.textContent = QR.selected.com = ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd); QR.selected.el.lastChild.textContent = QR.selected.com = ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd);
ta.focus(); ta.focus();
ta.selectionEnd = ta.selectionStart = caretPos + text.length;
range = caretPos + text.length; range = caretPos + text.length;
return ta.setSelectionRange(range, range); return ta.setSelectionRange(range, range);
}, },
@ -1839,7 +1842,7 @@
this.timeout = Date.now() + 26 * $.MINUTE; this.timeout = Date.now() + 26 * $.MINUTE;
challenge = this.challenge.firstChild.value; challenge = this.challenge.firstChild.value;
this.img.alt = challenge; this.img.alt = challenge;
this.img.src = "http://www.google.com/recaptcha/api/image?c=" + challenge; this.img.src = "//www.google.com/recaptcha/api/image?c=" + challenge;
return this.input.value = null; return this.input.value = null;
}, },
count: function(count) { count: function(count) {
@ -1909,10 +1912,10 @@
}); });
QR.mimeTypes = mimeTypes.split(', '); QR.mimeTypes = mimeTypes.split(', ');
QR.mimeTypes.push(''); QR.mimeTypes.push('');
fileInput = $('[type=file]', QR.el); fileInput = $('input[type=file]', QR.el);
fileInput.max = $('[name=MAX_FILE_SIZE]').value; fileInput.max = $('input[name=MAX_FILE_SIZE]').value;
fileInput.accept = mimeTypes; fileInput.accept = mimeTypes;
QR.spoiler = !!$('#com_submit + label'); QR.spoiler = !!$('input[name=spoiler]');
spoiler = $('#spoilerLabel', QR.el); spoiler = $('#spoilerLabel', QR.el);
spoiler.hidden = !QR.spoiler; spoiler.hidden = !QR.spoiler;
if (!g.REPLY) { if (!g.REPLY) {
@ -1958,8 +1961,9 @@
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
name = _ref1[_j]; name = _ref1[_j];
$.on($("[name=" + name + "]", QR.el), 'input keyup change paste', function() { $.on($("[name=" + name + "]", QR.el), 'input keyup change paste', function() {
var _ref2;
QR.selected[this.name] = this.value; QR.selected[this.name] = this.value;
if (QR.cooldown.auto && QR.selected === QR.replies[0] && parseInt(QR.status.input.value.match(/\d+/)) < 6) { if (QR.cooldown.auto && QR.selected === QR.replies[0] && (0 < (_ref2 = QR.cooldown.seconds) && _ref2 < 6)) {
return QR.cooldown.auto = false; return QR.cooldown.auto = false;
} }
}); });
@ -1977,7 +1981,7 @@
} }
return _results; return _results;
}); });
QR.status.input = $('[type=submit]', QR.el); QR.status.input = $('input[type=submit]', QR.el);
QR.status(); QR.status();
QR.cooldown.init(); QR.cooldown.init();
QR.captcha.init(); QR.captcha.init();
@ -2050,7 +2054,7 @@
upfile: reply.file, upfile: reply.file,
spoiler: reply.spoiler, spoiler: reply.spoiler,
mode: 'regist', mode: 'regist',
pwd: (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('[name=pwd]').value, pwd: (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('input[name=pwd]').value,
recaptcha_challenge_field: challenge, recaptcha_challenge_field: challenge,
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
}; };
@ -2089,7 +2093,7 @@
} }
} }
}; };
return QR.ajax = $.ajax($('form[name=post]').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 b, doc, err, node, persona, postNumber, reply, thread, _, _ref;
@ -4179,7 +4183,7 @@
_ref = mutation.addedNodes; _ref = mutation.addedNodes;
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
addedNode = _ref[_j]; addedNode = _ref[_j];
if (addedNode.nodeName === 'DIV' && /\bpostContainer\b/.test(addedNode.className)) { if (/\bpostContainer\b/.test(addedNode.className)) {
nodes.push(Main.preParse(addedNode)); nodes.push(Main.preParse(addedNode));
} }
} }
@ -4191,7 +4195,7 @@
listener: function(e) { listener: function(e) {
var target; var target;
target = e.target; target = e.target;
if (target.nodeName === 'DIV' && /\bpostContainer\b/.test(addedNode.className)) { if (/\bpostContainer\b/.test(addedNode.className)) {
return Main.node([Main.preParse(target)]); return Main.node([Main.preParse(target)]);
} }
}, },

View File

@ -533,11 +533,11 @@ Filter =
# Highlight # Highlight
$.addClass (if isOP then root.parentNode else root), result[0] $.addClass (if isOP then root.parentNode else root), result[0]
if isOP and result[1] and not g.REPLY if isOP and result[1] and not g.REPLY
# Put the highlighted OPs' threads on top of the board pages... # Put the highlighted OPs' thread on top of the board page...
thisThread = root.parentNode thisThread = root.parentNode
# ...before the first non highlighted thread. # ...before the first non highlighted thread.
if firstThread = $ 'div[class=thread]' if firstThread = $ 'div[class=thread]'
$.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling] $.before firstThread, [thisThread, thisThread.nextElementSibling]
name: (post) -> name: (post) ->
$('.name', post.el).textContent $('.name', post.el).textContent
@ -662,10 +662,8 @@ ExpandThread =
switch a.textContent[0] switch a.textContent[0]
when '+' when '+'
if container = $ '.container', a.previousElementSibling
$.rm container
a.textContent = a.textContent.replace '+', '\u00d7 Loading...' a.textContent = a.textContent.replace '+', '\u00d7 Loading...'
$.cache pathname, -> ExpandThread.parse @, pathname, thread, a $.cache pathname, -> ExpandThread.parse @, thread, a
when '\u00d7' when '\u00d7'
a.textContent = a.textContent.replace '\u00d7 Loading...', '+' a.textContent = a.textContent.replace '\u00d7 Loading...', '+'
@ -684,8 +682,9 @@ ExpandThread =
$.rm reply $.rm reply
for backlink in $$ '.backlink', a.previousElementSibling for backlink in $$ '.backlink', a.previousElementSibling
$.rm backlink unless $.id backlink.hash[1..] $.rm backlink unless $.id backlink.hash[1..]
return
parse: (req, pathname, thread, a) -> parse: (req, thread, a) ->
if req.status isnt 200 if req.status isnt 200
a.textContent = "#{req.status} #{req.statusText}" a.textContent = "#{req.status} #{req.statusText}"
$.off a, 'click', ExpandThread.cb.toggle $.off a, 'click', ExpandThread.cb.toggle
@ -710,8 +709,10 @@ ExpandThread =
link.nextSibling.href = "res/#{threadID}#q#{id}" link.nextSibling.href = "res/#{threadID}#q#{id}"
nodes.push reply nodes.push reply
# eat everything, then replace with fresh full posts # eat everything, then replace with fresh full posts
while next = a.nextSibling for post in $$ '.summary ~ .replyContainer', a.parentNode
$.rm next $.rm post
for backlink in $$ '.backlink', a.previousElementSibling
$.rm backlink unless $.id backlink.hash[1..]
$.after a, nodes $.after a, nodes
ThreadHiding = ThreadHiding =
@ -1123,12 +1124,12 @@ QR =
$('.warning', QR.el).textContent = null $('.warning', QR.el).textContent = null
status: (data={}) -> status: (data={}) ->
return unless QR.el
if g.dead if g.dead
value = 404 value = 404
disabled = true disabled = true
QR.cooldown.auto = false QR.cooldown.auto = false
value = QR.cooldown.seconds or data.progress or value value = QR.cooldown.seconds or data.progress or value
return unless QR.el
{input} = QR.status {input} = QR.status
input.value = input.value =
if QR.cooldown.auto and Conf['Cooldown'] if QR.cooldown.auto and Conf['Cooldown']
@ -1163,13 +1164,12 @@ QR =
QR.open() QR.open()
unless g.REPLY unless g.REPLY
$('select', QR.el).value = $.x('ancestor::div[@class="thread"]', @).id[1..] $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', @).id[1..]
# Make sure we get the correct number, even with XXX censors # Make sure we get the correct number, even with XXX censors
id = @parentNode.parentNode.id[2..] id = @previousSibling.hash[2..]
text = ">>#{id}\n" text = ">>#{id}\n"
sel = window.getSelection() sel = window.getSelection()
if (s = sel.toString()) and id is $.x('ancestor-or-self::blockquote', sel.anchorNode)?.id[1..] if (s = sel.toString()) and id is $.x('ancestor-or-self::blockquote', sel.anchorNode)?.id.match(/\d+$/)[0]
s = s.replace /\n/g, '\n>' s = s.replace /\n/g, '\n>'
text += ">#{s}\n" text += ">#{s}\n"
@ -1183,7 +1183,6 @@ QR =
ta.value[...caretPos] + text + ta.value[ta.selectionEnd..] ta.value[...caretPos] + text + ta.value[ta.selectionEnd..]
ta.focus() ta.focus()
# Move the caret to the end of the new quote. # Move the caret to the end of the new quote.
ta.selectionEnd = ta.selectionStart = caretPos + text.length
range = caretPos + text.length range = caretPos + text.length
ta.setSelectionRange range, range ta.setSelectionRange range, range
@ -1404,7 +1403,7 @@ QR =
@timeout = Date.now() + 26*$.MINUTE @timeout = Date.now() + 26*$.MINUTE
challenge = @challenge.firstChild.value challenge = @challenge.firstChild.value
@img.alt = challenge @img.alt = challenge
@img.src = "http://www.google.com/recaptcha/api/image?c=#{challenge}" @img.src = "//www.google.com/recaptcha/api/image?c=#{challenge}"
@input.value = null @input.value = null
count: (count) -> count: (count) ->
@input.placeholder = switch count @input.placeholder = switch count
@ -1463,11 +1462,11 @@ QR =
QR.mimeTypes = mimeTypes.split ', ' QR.mimeTypes = mimeTypes.split ', '
# Add empty mimeType to avoid errors with URLs selected in Window's file dialog. # Add empty mimeType to avoid errors with URLs selected in Window's file dialog.
QR.mimeTypes.push '' QR.mimeTypes.push ''
fileInput = $ '[type=file]', QR.el fileInput = $ 'input[type=file]', QR.el
fileInput.max = $('[name=MAX_FILE_SIZE]').value fileInput.max = $('input[name=MAX_FILE_SIZE]').value
fileInput.accept = mimeTypes fileInput.accept = mimeTypes
QR.spoiler = !!$ '#com_submit + label' QR.spoiler = !!$ 'input[name=spoiler]'
spoiler = $ '#spoilerLabel', QR.el spoiler = $ '#spoilerLabel', QR.el
spoiler.hidden = !QR.spoiler spoiler.hidden = !QR.spoiler
@ -1502,7 +1501,7 @@ QR =
QR.selected[@name] = @value QR.selected[@name] = @value
# Disable auto-posting if you're typing in the first reply # Disable auto-posting if you're typing in the first reply
# during the last 5 seconds of the cooldown. # during the last 5 seconds of the cooldown.
if QR.cooldown.auto and QR.selected is QR.replies[0] and parseInt(QR.status.input.value.match /\d+/) < 6 if QR.cooldown.auto and QR.selected is QR.replies[0] and 0 < QR.cooldown.seconds < 6
QR.cooldown.auto = false QR.cooldown.auto = false
# sync between tabs # sync between tabs
$.sync 'QR.persona', (persona) -> $.sync 'QR.persona', (persona) ->
@ -1511,7 +1510,7 @@ QR =
QR.selected[key] = val QR.selected[key] = val
$("[name=#{key}]", QR.el).value = val $("[name=#{key}]", QR.el).value = val
QR.status.input = $ '[type=submit]', QR.el QR.status.input = $ 'input[type=submit]', QR.el
QR.status() QR.status()
QR.cooldown.init() QR.cooldown.init()
QR.captcha.init() QR.captcha.init()
@ -1585,7 +1584,7 @@ QR =
upfile: reply.file upfile: reply.file
spoiler: reply.spoiler spoiler: reply.spoiler
mode: 'regist' mode: 'regist'
pwd: if m = d.cookie.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('[name=pwd]').value pwd: if m = d.cookie.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value
recaptcha_challenge_field: challenge recaptcha_challenge_field: challenge
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
@ -1614,7 +1613,7 @@ QR =
# Uploading... # Uploading...
QR.status progress: "#{Math.round e.loaded / e.total * 100}%" QR.status progress: "#{Math.round e.loaded / e.total * 100}%"
QR.ajax = $.ajax $('form[name=post]').action, callbacks, opts QR.ajax = $.ajax $.id('postForm').parentNode.action, callbacks, opts
response: (html) -> response: (html) ->
doc = d.implementation.createHTMLDocument '' doc = d.implementation.createHTMLDocument ''
@ -3192,12 +3191,12 @@ Main =
nodes = [] nodes = []
for mutation in mutations for mutation in mutations
for addedNode in mutation.addedNodes for addedNode in mutation.addedNodes
if addedNode.nodeName is 'DIV' and /\bpostContainer\b/.test addedNode.className if /\bpostContainer\b/.test addedNode.className
nodes.push Main.preParse addedNode nodes.push Main.preParse addedNode
Main.node nodes if nodes.length Main.node nodes if nodes.length
listener: (e) -> listener: (e) ->
{target} = e {target} = e
if target.nodeName is 'DIV' and /\bpostContainer\b/.test addedNode.className if /\bpostContainer\b/.test addedNode.className
Main.node [Main.preParse target] Main.node [Main.preParse target]
namespace: '4chan_x.' namespace: '4chan_x.'