Merge pull request #320 from MayhemYDG/master

Improvements
This commit is contained in:
James Campos 2011-10-09 16:12:49 -07:00
commit 3f8e45cd18
2 changed files with 64 additions and 104 deletions

View File

@ -662,7 +662,7 @@
} }
} }
} }
_ref2 = $$('a.quotelink', bq); _ref2 = $$('.quotelink', bq);
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
quote = _ref2[_j]; quote = _ref2[_j];
if (quote.getAttribute('href') === quote.hash) { if (quote.getAttribute('href') === quote.hash) {
@ -710,7 +710,7 @@
var a, backlink, num, prev, table, threadID, _i, _len, _ref, _ref2, _results; var a, backlink, num, prev, table, threadID, _i, _len, _ref, _ref2, _results;
threadID = thread.firstChild.id; threadID = thread.firstChild.id;
pathname = "/" + g.BOARD + "/res/" + threadID; pathname = "/" + g.BOARD + "/res/" + threadID;
a = $('a.omittedposts', thread); a = $('.omittedposts', thread);
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
if ((_ref = $('.op .container', thread)) != null) { if ((_ref = $('.op .container', thread)) != null) {
@ -766,7 +766,7 @@
_ref = $$('td[id]', body); _ref = $$('td[id]', body);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reply = _ref[_i]; reply = _ref[_i];
_ref2 = $$('a.quotelink', reply); _ref2 = $$('.quotelink', reply);
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
quote = _ref2[_j]; quote = _ref2[_j];
if ((href = quote.getAttribute('href')) === quote.hash) { if ((href = quote.getAttribute('href')) === quote.hash) {
@ -775,7 +775,7 @@
quote.href = "res/" + href; quote.href = "res/" + href;
} }
} }
link = $('a.quotejs', reply); link = $('.quotejs', reply);
link.href = "res/" + thread.firstChild.id + "#" + reply.id; link.href = "res/" + thread.firstChild.id + "#" + reply.id;
link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id; link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id;
} }
@ -1056,7 +1056,7 @@
}, },
qr: function(thread, quote) { qr: function(thread, quote) {
if (quote) { if (quote) {
return QR.quote.call($('a.quotejs + a', $('td.replyhl', thread) || thread)); return QR.quote.call($('.quotejs + a', $('.replyhl', thread) || thread));
} else { } else {
if (QR.qr) { if (QR.qr) {
return $('textarea', QR.qr).focus(); return $('textarea', QR.qr).focus();
@ -1408,7 +1408,7 @@
} }
g.callbacks.push(function(root) { g.callbacks.push(function(root) {
var quote; var quote;
quote = $('a.quotejs + a', root); quote = $('.quotejs + a', root);
return $.bind(quote, 'click', QR.quote); return $.bind(quote, 'click', QR.quote);
}); });
$.add(d.body, $.el('iframe', { $.add(d.body, $.el('iframe', {
@ -2174,49 +2174,28 @@
}; };
sauce = { sauce = {
init: function() { init: function() {
var prefix, s; sauce.prefixes = conf['flavors'].match(/^[^#].+$/gm);
sauce.prefixes = (function() { sauce.names = sauce.prefixes.map(function(s) {
var _i, _len, _ref, _results; return s.match(/\w+(?=\.)/)[0];
_ref = conf['flavors'].split('\n'); });
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
s = _ref[_i];
if (s && s[0] !== '#') {
_results.push(s);
}
}
return _results;
})();
sauce.names = (function() {
var _i, _len, _ref, _results;
_ref = sauce.prefixes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
prefix = _ref[_i];
_results.push(prefix.match(/(\w+)\./)[1]);
}
return _results;
})();
return g.callbacks.push(function(root) { return g.callbacks.push(function(root) {
var i, link, prefix, span, suffix, _len, _ref, _results; var i, link, prefix, span, suffix, _len, _ref, _results;
if (root.className === 'inline') { if (root.className === 'inline' || !(span = $('.filesize', root))) {
return; return;
} }
if (span = $('.filesize', root)) { suffix = $('a', span).href;
suffix = $('a', span).href; _ref = sauce.prefixes;
_ref = sauce.prefixes; _results = [];
_results = []; for (i = 0, _len = _ref.length; i < _len; i++) {
for (i = 0, _len = _ref.length; i < _len; i++) { prefix = _ref[i];
prefix = _ref[i]; link = $.el('a', {
link = $.el('a', { textContent: sauce.names[i],
textContent: sauce.names[i], href: prefix + suffix,
href: prefix + suffix, target: '_blank'
target: '_blank' });
}); _results.push($.add(span, $.tn(' '), link));
_results.push($.add(span, $.tn(' '), link));
}
return _results;
} }
return _results;
}); });
} }
}; };
@ -2362,7 +2341,7 @@
} }
id = root.id || $('td[id]', root).id; id = root.id || $('td[id]', root).id;
quotes = {}; quotes = {};
_ref = $$('a.quotelink', root); _ref = $$('.quotelink', root);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
if (!(qid = quote.hash.slice(1))) { if (!(qid = quote.hash.slice(1))) {
@ -2408,7 +2387,7 @@
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(function(root) {
var quote, _i, _len, _ref, _results; var quote, _i, _len, _ref, _results;
_ref = $$('a.quotelink, a.backlink', root); _ref = $$('.quotelink, .backlink', root);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
@ -2501,7 +2480,7 @@
} }
} }
newInline = quoteInline.table(id, html); newInline = quoteInline.table(id, html);
_ref2 = $$('a.quotelink', newInline); _ref2 = $$('.quotelink', newInline);
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
quote = _ref2[_j]; quote = _ref2[_j];
if ((href = quote.getAttribute('href')) === quote.hash) { if ((href = quote.getAttribute('href')) === quote.hash) {
@ -2510,7 +2489,7 @@
quote.href = "res/" + href; quote.href = "res/" + href;
} }
} }
link = $('a.quotejs', newInline); link = $('.quotejs', newInline);
link.href = "" + pathname + "#" + id; link.href = "" + pathname + "#" + id;
link.nextSibling.href = "" + pathname + "#q" + id; link.nextSibling.href = "" + pathname + "#q" + id;
$.addClass(newInline, 'crossquote'); $.addClass(newInline, 'crossquote');
@ -2528,7 +2507,7 @@
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(function(root) {
var quote, _i, _len, _ref, _results; var quote, _i, _len, _ref, _results;
_ref = $$('a.quotelink, a.backlink', root); _ref = $$('.quotelink, .backlink', root);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
@ -2557,7 +2536,7 @@
} }
if (/backlink/.test(this.className)) { if (/backlink/.test(this.className)) {
replyID = $.x('ancestor::*[@id][1]', this).id.match(/\d+/)[0]; replyID = $.x('ancestor::*[@id][1]', this).id.match(/\d+/)[0];
_ref = $$('a.quotelink', qp); _ref = $$('.quotelink', qp);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
@ -2594,7 +2573,7 @@
innerHTML: req.responseText innerHTML: req.responseText
}); });
if (id === threadID) { if (id === threadID) {
op = threading.op($('form[name=delform] > *', body)); op = threading.op($('body > form', body).firstChild);
html = op.innerHTML; html = op.innerHTML;
} else { } else {
_ref = $$('td.reply', body); _ref = $$('td.reply', body);
@ -2618,7 +2597,7 @@
return; return;
} }
tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id;
_ref = $$('a.quotelink', root); _ref = $$('.quotelink', root);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
@ -2632,7 +2611,7 @@
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(function(root) {
var a, span; var a, span;
if (!(a = $('a.reportbutton', root))) { if (!(a = $('.reportbutton', root))) {
span = $('span[id^=no]', root); span = $('span[id^=no]', root);
a = $.el('a', { a = $.el('a', {
className: 'reportbutton', className: 'reportbutton',
@ -3023,7 +3002,7 @@
}; };
Main = { Main = {
init: function() { init: function() {
var callback, cutoff, hiddenThreads, id, lastChecked, now, op, table, timestamp, tzOffset, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _ref5; var cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, tzOffset, _ref;
$.unbind(document, 'DOMContentLoaded', Main.init); $.unbind(document, 'DOMContentLoaded', Main.init);
if (location.hostname === 'sys.4chan.org') { if (location.hostname === 'sys.4chan.org') {
QR.sys(); QR.sys();
@ -3152,24 +3131,10 @@
expandComment.init(); expandComment.init();
} }
} }
_ref2 = $$('div.op'); nodes = $$('.op').concat($$('a + table'));
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { g.callbacks.forEach(function(callback) {
op = _ref2[_i]; return nodes.forEach(callback);
_ref3 = g.callbacks; });
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
callback = _ref3[_j];
callback(op);
}
}
_ref4 = $$('a + table');
for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
table = _ref4[_k];
_ref5 = g.callbacks;
for (_l = 0, _len4 = _ref5.length; _l < _len4; _l++) {
callback = _ref5[_l];
callback(table);
}
}
$.bind($('form[name=delform]'), 'DOMNodeInserted', nodeInserted); $.bind($('form[name=delform]'), 'DOMNodeInserted', nodeInserted);
options.init(); options.init();
if (!$.get('firstrun')) { if (!$.get('firstrun')) {

View File

@ -462,7 +462,7 @@ expandComment =
if reply.id == replyID if reply.id == replyID
bq = $ 'blockquote', reply bq = $ 'blockquote', reply
break break
for quote in $$ 'a.quotelink', bq for quote in $$ '.quotelink', bq
if quote.getAttribute('href') is quote.hash if quote.getAttribute('href') is quote.hash
quote.pathname = "/#{g.BOARD}/res/#{threadID}" quote.pathname = "/#{g.BOARD}/res/#{threadID}"
if quote.hash[1..] is threadID if quote.hash[1..] is threadID
@ -492,7 +492,7 @@ expandThread =
toggle: (thread) -> toggle: (thread) ->
threadID = thread.firstChild.id threadID = thread.firstChild.id
pathname = "/#{g.BOARD}/res/#{threadID}" pathname = "/#{g.BOARD}/res/#{threadID}"
a = $ 'a.omittedposts', thread a = $ '.omittedposts', thread
switch a.textContent[0] switch a.textContent[0]
when '+' when '+'
@ -536,12 +536,12 @@ expandThread =
innerHTML: req.responseText innerHTML: req.responseText
for reply in $$ 'td[id]', body for reply in $$ 'td[id]', body
for quote in $$ 'a.quotelink', reply for quote in $$ '.quotelink', reply
if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes
quote.pathname = pathname quote.pathname = pathname
else if href isnt quote.href #fix x-thread links, not x-board ones else if href isnt quote.href #fix x-thread links, not x-board ones
quote.href = "res/#{href}" quote.href = "res/#{href}"
link = $ 'a.quotejs', reply link = $ '.quotejs', reply
link.href = "res/#{thread.firstChild.id}##{reply.id}" link.href = "res/#{thread.firstChild.id}##{reply.id}"
link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}" link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}"
tables = $$ 'form[name=delform] table', body tables = $$ 'form[name=delform] table', body
@ -720,7 +720,7 @@ keybinds =
qr: (thread, quote) -> qr: (thread, quote) ->
if quote if quote
QR.quote.call $ 'a.quotejs + a', $('td.replyhl', thread) or thread QR.quote.call $ '.quotejs + a', $('.replyhl', thread) or thread
else else
if QR.qr if QR.qr
$('textarea', QR.qr).focus() $('textarea', QR.qr).focus()
@ -1026,7 +1026,7 @@ QR =
#can't reply in some stickies, recaptcha may be blocked, eg by noscript #can't reply in some stickies, recaptcha may be blocked, eg by noscript
return unless $('form[name=post]') and $('#recaptcha_response_field') return unless $('form[name=post]') and $('#recaptcha_response_field')
g.callbacks.push (root) -> g.callbacks.push (root) ->
quote = $ 'a.quotejs + a', root quote = $ '.quotejs + a', root
$.bind quote, 'click', QR.quote $.bind quote, 'click', QR.quote
$.add d.body, $.el 'iframe', $.add d.body, $.el 'iframe',
name: 'iframe' name: 'iframe'
@ -1646,18 +1646,17 @@ anonymize =
sauce = sauce =
init: -> init: ->
sauce.prefixes = (s for s in (conf['flavors'].split '\n') when s and s[0] != '#') sauce.prefixes = conf['flavors'].match /^[^#].+$/gm
sauce.names = (prefix.match(/(\w+)\./)[1] for prefix in sauce.prefixes) sauce.names = sauce.prefixes.map (s) -> s.match(/\w+(?=\.)/)[0]
g.callbacks.push (root) -> g.callbacks.push (root) ->
return if root.className is 'inline' return if root.className is 'inline' or not span = $ '.filesize', root
if span = $ '.filesize', root suffix = $('a', span).href
suffix = $('a', span).href for prefix, i in sauce.prefixes
for prefix, i in sauce.prefixes link = $.el 'a',
link = $.el 'a', textContent: sauce.names[i]
textContent: sauce.names[i] href: prefix + suffix
href: prefix + suffix target: '_blank'
target: '_blank' $.add span, $.tn(' '), link
$.add span, $.tn(' '), link
revealSpoilers = revealSpoilers =
init: -> init: ->
@ -1756,7 +1755,7 @@ quoteBacklink =
# op or reply # op or reply
id = root.id or $('td[id]', root).id id = root.id or $('td[id]', root).id
quotes = {} quotes = {}
for quote in $$ 'a.quotelink', root for quote in $$ '.quotelink', root
#don't process >>>/b/ #don't process >>>/b/
continue unless qid = quote.hash[1..] continue unless qid = quote.hash[1..]
#duplicate quotes get overwritten #duplicate quotes get overwritten
@ -1784,7 +1783,7 @@ quoteBacklink =
quoteInline = quoteInline =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push (root) ->
for quote in $$ 'a.quotelink, a.backlink', root for quote in $$ '.quotelink, .backlink', root
continue unless quote.hash continue unless quote.hash
quote.removeAttribute 'onclick' quote.removeAttribute 'onclick'
$.bind quote, 'click', quoteInline.toggle $.bind quote, 'click', quoteInline.toggle
@ -1844,12 +1843,12 @@ quoteInline =
html = reply.innerHTML html = reply.innerHTML
break break
newInline = quoteInline.table id, html newInline = quoteInline.table id, html
for quote in $$ 'a.quotelink', newInline for quote in $$ '.quotelink', newInline
if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes
quote.pathname = pathname quote.pathname = pathname
else if !g.REPLY and href isnt quote.href #fix x-thread links, not x-board ones else if !g.REPLY and href isnt quote.href #fix x-thread links, not x-board ones
quote.href = "res/#{href}" quote.href = "res/#{href}"
link = $ 'a.quotejs', newInline link = $ '.quotejs', newInline
link.href = "#{pathname}##{id}" link.href = "#{pathname}##{id}"
link.nextSibling.href = "#{pathname}#q#{id}" link.nextSibling.href = "#{pathname}#q#{id}"
$.addClass newInline, 'crossquote' $.addClass newInline, 'crossquote'
@ -1863,7 +1862,7 @@ quoteInline =
quotePreview = quotePreview =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push (root) ->
for quote in $$ 'a.quotelink, a.backlink', root for quote in $$ '.quotelink, .backlink', root
continue unless quote.hash continue unless quote.hash
$.bind quote, 'mouseover', quotePreview.mouseover $.bind quote, 'mouseover', quotePreview.mouseover
$.bind quote, 'mousemove', ui.hover $.bind quote, 'mousemove', ui.hover
@ -1880,7 +1879,7 @@ quotePreview =
$.addClass el, 'qphl' if conf['Quote Highlighting'] $.addClass el, 'qphl' if conf['Quote Highlighting']
if /backlink/.test @className if /backlink/.test @className
replyID = $.x('ancestor::*[@id][1]', @).id.match(/\d+/)[0] replyID = $.x('ancestor::*[@id][1]', @).id.match(/\d+/)[0]
for quote in $$ 'a.quotelink', qp for quote in $$ '.quotelink', qp
if quote.hash[1..] is replyID if quote.hash[1..] is replyID
quote.className = 'forwardlink' quote.className = 'forwardlink'
else else
@ -1901,7 +1900,7 @@ quotePreview =
body = $.el 'body', body = $.el 'body',
innerHTML: req.responseText innerHTML: req.responseText
if id == threadID #OP if id == threadID #OP
op = threading.op $ 'form[name=delform] > *', body op = threading.op $('body > form', body).firstChild
html = op.innerHTML html = op.innerHTML
else else
for reply in $$ 'td.reply', body for reply in $$ 'td.reply', body
@ -1916,14 +1915,14 @@ quoteOP =
g.callbacks.push (root) -> g.callbacks.push (root) ->
return if root.className is 'inline' return if root.className is 'inline'
tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id
for quote in $$ 'a.quotelink', root for quote in $$ '.quotelink', root
if quote.hash[1..] is tid if quote.hash[1..] is tid
quote.innerHTML += '&nbsp;(OP)' quote.innerHTML += '&nbsp;(OP)'
reportButton = reportButton =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push (root) ->
if not a = $ 'a.reportbutton', root if not a = $ '.reportbutton', root
span = $ 'span[id^=no]', root span = $ 'span[id^=no]', root
a = $.el 'a', a = $.el 'a',
className: 'reportbutton' className: 'reportbutton'
@ -2370,12 +2369,8 @@ Main =
if conf['Comment Expansion'] if conf['Comment Expansion']
expandComment.init() expandComment.init()
for op in $$ 'div.op' nodes = $$('.op').concat $$ 'a + table'
for callback in g.callbacks g.callbacks.forEach (callback) -> nodes.forEach callback
callback op
for table in $$ 'a + table'
for callback in g.callbacks
callback table
$.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted $.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted
options.init() options.init()