From c2fa9098b9ab88a268d78127e872413a38a05608 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 9 Oct 2011 20:39:58 +0200 Subject: [PATCH 1/6] Shorter selectors. --- 4chan_x.user.js | 28 ++++++++++++++-------------- script.coffee | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 52c6005a4..b1047a087 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -662,7 +662,7 @@ } } } - _ref2 = $$('a.quotelink', bq); + _ref2 = $$('.quotelink', bq); for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { quote = _ref2[_j]; if (quote.getAttribute('href') === quote.hash) { @@ -710,7 +710,7 @@ var a, backlink, num, prev, table, threadID, _i, _len, _ref, _ref2, _results; threadID = thread.firstChild.id; pathname = "/" + g.BOARD + "/res/" + threadID; - a = $('a.omittedposts', thread); + a = $('.omittedposts', thread); switch (a.textContent[0]) { case '+': if ((_ref = $('.op .container', thread)) != null) { @@ -766,7 +766,7 @@ _ref = $$('td[id]', body); for (_i = 0, _len = _ref.length; _i < _len; _i++) { reply = _ref[_i]; - _ref2 = $$('a.quotelink', reply); + _ref2 = $$('.quotelink', reply); for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { quote = _ref2[_j]; if ((href = quote.getAttribute('href')) === quote.hash) { @@ -775,7 +775,7 @@ quote.href = "res/" + href; } } - link = $('a.quotejs', reply); + link = $('.quotejs', reply); link.href = "res/" + thread.firstChild.id + "#" + reply.id; link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id; } @@ -1056,7 +1056,7 @@ }, qr: function(thread, quote) { if (quote) { - return QR.quote.call($('a.quotejs + a', $('td.replyhl', thread) || thread)); + return QR.quote.call($('.quotejs + a', $('.replyhl', thread) || thread)); } else { if (QR.qr) { return $('textarea', QR.qr).focus(); @@ -1408,7 +1408,7 @@ } g.callbacks.push(function(root) { var quote; - quote = $('a.quotejs + a', root); + quote = $('.quotejs + a', root); return $.bind(quote, 'click', QR.quote); }); $.add(d.body, $.el('iframe', { @@ -2362,7 +2362,7 @@ } id = root.id || $('td[id]', root).id; quotes = {}; - _ref = $$('a.quotelink', root); + _ref = $$('.quotelink', root); for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; if (!(qid = quote.hash.slice(1))) { @@ -2408,7 +2408,7 @@ init: function() { return g.callbacks.push(function(root) { var quote, _i, _len, _ref, _results; - _ref = $$('a.quotelink, a.backlink', root); + _ref = $$('.quotelink, .backlink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; @@ -2501,7 +2501,7 @@ } } newInline = quoteInline.table(id, html); - _ref2 = $$('a.quotelink', newInline); + _ref2 = $$('.quotelink', newInline); for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { quote = _ref2[_j]; if ((href = quote.getAttribute('href')) === quote.hash) { @@ -2510,7 +2510,7 @@ quote.href = "res/" + href; } } - link = $('a.quotejs', newInline); + link = $('.quotejs', newInline); link.href = "" + pathname + "#" + id; link.nextSibling.href = "" + pathname + "#q" + id; $.addClass(newInline, 'crossquote'); @@ -2528,7 +2528,7 @@ init: function() { return g.callbacks.push(function(root) { var quote, _i, _len, _ref, _results; - _ref = $$('a.quotelink, a.backlink', root); + _ref = $$('.quotelink, .backlink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; @@ -2557,7 +2557,7 @@ } if (/backlink/.test(this.className)) { replyID = $.x('ancestor::*[@id][1]', this).id.match(/\d+/)[0]; - _ref = $$('a.quotelink', qp); + _ref = $$('.quotelink', qp); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; @@ -2618,7 +2618,7 @@ return; } tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; - _ref = $$('a.quotelink', root); + _ref = $$('.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; @@ -2632,7 +2632,7 @@ init: function() { return g.callbacks.push(function(root) { var a, span; - if (!(a = $('a.reportbutton', root))) { + if (!(a = $('.reportbutton', root))) { span = $('span[id^=no]', root); a = $.el('a', { className: 'reportbutton', diff --git a/script.coffee b/script.coffee index 3054a3f97..cebee1a10 100644 --- a/script.coffee +++ b/script.coffee @@ -462,7 +462,7 @@ expandComment = if reply.id == replyID bq = $ 'blockquote', reply break - for quote in $$ 'a.quotelink', bq + for quote in $$ '.quotelink', bq if quote.getAttribute('href') is quote.hash quote.pathname = "/#{g.BOARD}/res/#{threadID}" if quote.hash[1..] is threadID @@ -492,7 +492,7 @@ expandThread = toggle: (thread) -> threadID = thread.firstChild.id pathname = "/#{g.BOARD}/res/#{threadID}" - a = $ 'a.omittedposts', thread + a = $ '.omittedposts', thread switch a.textContent[0] when '+' @@ -536,12 +536,12 @@ expandThread = innerHTML: req.responseText 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 quote.pathname = pathname else if href isnt quote.href #fix x-thread links, not x-board ones quote.href = "res/#{href}" - link = $ 'a.quotejs', reply + link = $ '.quotejs', reply link.href = "res/#{thread.firstChild.id}##{reply.id}" link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}" tables = $$ 'form[name=delform] table', body @@ -720,7 +720,7 @@ keybinds = qr: (thread, quote) -> if quote - QR.quote.call $ 'a.quotejs + a', $('td.replyhl', thread) or thread + QR.quote.call $ '.quotejs + a', $('.replyhl', thread) or thread else if QR.qr $('textarea', QR.qr).focus() @@ -1026,7 +1026,7 @@ QR = #can't reply in some stickies, recaptcha may be blocked, eg by noscript return unless $('form[name=post]') and $('#recaptcha_response_field') g.callbacks.push (root) -> - quote = $ 'a.quotejs + a', root + quote = $ '.quotejs + a', root $.bind quote, 'click', QR.quote $.add d.body, $.el 'iframe', name: 'iframe' @@ -1756,7 +1756,7 @@ quoteBacklink = # op or reply id = root.id or $('td[id]', root).id quotes = {} - for quote in $$ 'a.quotelink', root + for quote in $$ '.quotelink', root #don't process >>>/b/ continue unless qid = quote.hash[1..] #duplicate quotes get overwritten @@ -1784,7 +1784,7 @@ quoteBacklink = quoteInline = init: -> g.callbacks.push (root) -> - for quote in $$ 'a.quotelink, a.backlink', root + for quote in $$ '.quotelink, .backlink', root continue unless quote.hash quote.removeAttribute 'onclick' $.bind quote, 'click', quoteInline.toggle @@ -1844,12 +1844,12 @@ quoteInline = html = reply.innerHTML break 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 quote.pathname = pathname else if !g.REPLY and href isnt quote.href #fix x-thread links, not x-board ones quote.href = "res/#{href}" - link = $ 'a.quotejs', newInline + link = $ '.quotejs', newInline link.href = "#{pathname}##{id}" link.nextSibling.href = "#{pathname}#q#{id}" $.addClass newInline, 'crossquote' @@ -1863,7 +1863,7 @@ quoteInline = quotePreview = init: -> g.callbacks.push (root) -> - for quote in $$ 'a.quotelink, a.backlink', root + for quote in $$ '.quotelink, .backlink', root continue unless quote.hash $.bind quote, 'mouseover', quotePreview.mouseover $.bind quote, 'mousemove', ui.hover @@ -1880,7 +1880,7 @@ quotePreview = $.addClass el, 'qphl' if conf['Quote Highlighting'] if /backlink/.test @className 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 quote.className = 'forwardlink' else @@ -1916,14 +1916,14 @@ quoteOP = g.callbacks.push (root) -> return if root.className is 'inline' 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 quote.innerHTML += ' (OP)' reportButton = init: -> g.callbacks.push (root) -> - if not a = $ 'a.reportbutton', root + if not a = $ '.reportbutton', root span = $ 'span[id^=no]', root a = $.el 'a', className: 'reportbutton' From 659d54a6aaf83bac64c32bf4a1c45edd8a00d863 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 9 Oct 2011 21:57:28 +0200 Subject: [PATCH 2/6] Cuter Sauce. --- 4chan_x.user.js | 55 +++++++++++++++---------------------------------- script.coffee | 21 +++++++++---------- 2 files changed, 27 insertions(+), 49 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b1047a087..a39c87c70 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2174,49 +2174,28 @@ }; sauce = { init: function() { - var prefix, s; - sauce.prefixes = (function() { - var _i, _len, _ref, _results; - _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; - })(); + sauce.prefixes = conf['flavors'].match(/^[^#].+$/gm); + sauce.names = sauce.prefixes.map(function(s) { + return s.match(/\w+(?=\.)/)[0]; + }); return g.callbacks.push(function(root) { var i, link, prefix, span, suffix, _len, _ref, _results; - if (root.className === 'inline') { + if (root.className === 'inline' || !(span = $('.filesize', root))) { return; } - if (span = $('.filesize', root)) { - suffix = $('a', span).href; - _ref = sauce.prefixes; - _results = []; - for (i = 0, _len = _ref.length; i < _len; i++) { - prefix = _ref[i]; - link = $.el('a', { - textContent: sauce.names[i], - href: prefix + suffix, - target: '_blank' - }); - _results.push($.add(span, $.tn(' '), link)); - } - return _results; + suffix = $('a', span).href; + _ref = sauce.prefixes; + _results = []; + for (i = 0, _len = _ref.length; i < _len; i++) { + prefix = _ref[i]; + link = $.el('a', { + textContent: sauce.names[i], + href: prefix + suffix, + target: '_blank' + }); + _results.push($.add(span, $.tn(' '), link)); } + return _results; }); } }; diff --git a/script.coffee b/script.coffee index cebee1a10..b72438ec2 100644 --- a/script.coffee +++ b/script.coffee @@ -1646,18 +1646,17 @@ anonymize = sauce = init: -> - sauce.prefixes = (s for s in (conf['flavors'].split '\n') when s and s[0] != '#') - sauce.names = (prefix.match(/(\w+)\./)[1] for prefix in sauce.prefixes) + sauce.prefixes = conf['flavors'].match /^[^#].+$/gm + sauce.names = sauce.prefixes.map (s) -> s.match(/\w+(?=\.)/)[0] g.callbacks.push (root) -> - return if root.className is 'inline' - if span = $ '.filesize', root - suffix = $('a', span).href - for prefix, i in sauce.prefixes - link = $.el 'a', - textContent: sauce.names[i] - href: prefix + suffix - target: '_blank' - $.add span, $.tn(' '), link + return if root.className is 'inline' or not span = $ '.filesize', root + suffix = $('a', span).href + for prefix, i in sauce.prefixes + link = $.el 'a', + textContent: sauce.names[i] + href: prefix + suffix + target: '_blank' + $.add span, $.tn(' '), link revealSpoilers = init: -> From 2490b9c7d24941e869bb5c2dc0128ddb28dd9a90 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 9 Oct 2011 23:06:36 +0200 Subject: [PATCH 3/6] Don't use the universal selector. --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a39c87c70..2bcda0c2a 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2573,7 +2573,7 @@ innerHTML: req.responseText }); if (id === threadID) { - op = threading.op($('form[name=delform] > *', body)); + op = threading.op($('body > form', body).firstChild); html = op.innerHTML; } else { _ref = $$('td.reply', body); diff --git a/script.coffee b/script.coffee index b72438ec2..f435e1110 100644 --- a/script.coffee +++ b/script.coffee @@ -1900,7 +1900,7 @@ quotePreview = body = $.el 'body', innerHTML: req.responseText if id == threadID #OP - op = threading.op $ 'form[name=delform] > *', body + op = threading.op $('body > form', body).firstChild html = op.innerHTML else for reply in $$ 'td.reply', body From 5ed6057b501ba0391edea066b1f04242bf6ed9ab Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 9 Oct 2011 23:32:33 +0200 Subject: [PATCH 4/6] Haha oh woaw, -1 for. --- 4chan_x.user.js | 20 ++++++++------------ script.coffee | 7 +++---- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 2bcda0c2a..9f08a38c5 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3002,7 +3002,7 @@ }; Main = { 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 callback, cutoff, hiddenThreads, id, lastChecked, now, op, table, timestamp, tzOffset, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; $.unbind(document, 'DOMContentLoaded', Main.init); if (location.hostname === 'sys.4chan.org') { QR.sys(); @@ -3131,21 +3131,17 @@ expandComment.init(); } } - _ref2 = $$('div.op'); + _ref2 = g.callbacks; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - op = _ref2[_i]; - _ref3 = g.callbacks; + callback = _ref2[_i]; + _ref3 = $$('.op'); for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { - callback = _ref3[_j]; + op = _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]; + _ref4 = $$('a + table'); + for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) { + table = _ref4[_k]; callback(table); } } diff --git a/script.coffee b/script.coffee index f435e1110..c341edc46 100644 --- a/script.coffee +++ b/script.coffee @@ -2369,11 +2369,10 @@ Main = if conf['Comment Expansion'] expandComment.init() - for op in $$ 'div.op' - for callback in g.callbacks + for callback in g.callbacks + for op in $$ '.op' callback op - for table in $$ 'a + table' - for callback in g.callbacks + for table in $$ 'a + table' callback table $.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted options.init() From c5bc77c401eb5dc46d5f830872edf4dafaeb46b8 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 00:10:18 +0200 Subject: [PATCH 5/6] Derp, select once. --- 4chan_x.user.js | 14 +++----------- script.coffee | 6 ++---- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9f08a38c5..4aa856304 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3002,7 +3002,7 @@ }; Main = { init: function() { - var callback, cutoff, hiddenThreads, id, lastChecked, now, op, table, timestamp, tzOffset, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; + var callback, cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, tzOffset, _i, _len, _ref, _ref2; $.unbind(document, 'DOMContentLoaded', Main.init); if (location.hostname === 'sys.4chan.org') { QR.sys(); @@ -3131,19 +3131,11 @@ expandComment.init(); } } + nodes = $$('.op').concat($$('a + table')); _ref2 = g.callbacks; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { callback = _ref2[_i]; - _ref3 = $$('.op'); - for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { - op = _ref3[_j]; - callback(op); - } - _ref4 = $$('a + table'); - for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) { - table = _ref4[_k]; - callback(table); - } + nodes.forEach(callback); } $.bind($('form[name=delform]'), 'DOMNodeInserted', nodeInserted); options.init(); diff --git a/script.coffee b/script.coffee index c341edc46..e627049ce 100644 --- a/script.coffee +++ b/script.coffee @@ -2369,11 +2369,9 @@ Main = if conf['Comment Expansion'] expandComment.init() + nodes = $$('.op').concat $$ 'a + table' for callback in g.callbacks - for op in $$ '.op' - callback op - for table in $$ 'a + table' - callback table + nodes.forEach callback $.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted options.init() From 0d98ff469c3423a6fe6d12aa96464d08ec2d5caf Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 01:10:13 +0200 Subject: [PATCH 6/6] forEach inception --- 4chan_x.user.js | 10 ++++------ script.coffee | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4aa856304..2fde6b1af 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3002,7 +3002,7 @@ }; Main = { init: function() { - var callback, cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, tzOffset, _i, _len, _ref, _ref2; + var cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, tzOffset, _ref; $.unbind(document, 'DOMContentLoaded', Main.init); if (location.hostname === 'sys.4chan.org') { QR.sys(); @@ -3132,11 +3132,9 @@ } } nodes = $$('.op').concat($$('a + table')); - _ref2 = g.callbacks; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - callback = _ref2[_i]; - nodes.forEach(callback); - } + g.callbacks.forEach(function(callback) { + return nodes.forEach(callback); + }); $.bind($('form[name=delform]'), 'DOMNodeInserted', nodeInserted); options.init(); if (!$.get('firstrun')) { diff --git a/script.coffee b/script.coffee index e627049ce..4432f81a9 100644 --- a/script.coffee +++ b/script.coffee @@ -2370,8 +2370,7 @@ Main = expandComment.init() nodes = $$('.op').concat $$ 'a + table' - for callback in g.callbacks - nodes.forEach callback + g.callbacks.forEach (callback) -> nodes.forEach callback $.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted options.init()