From 909466b756231edfaabd22b7a59c0d28b3d00d71 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 01:14:00 +0200 Subject: [PATCH 1/6] document -> d --- 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 2fde6b1af..6e6054ff2 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3408,6 +3408,6 @@ if (d.body) { Main.init(); } else { - $.bind(document, 'DOMContentLoaded', Main.init); + $.bind(d, 'DOMContentLoaded', Main.init); } }).call(this); diff --git a/script.coffee b/script.coffee index 4432f81a9..787716f27 100644 --- a/script.coffee +++ b/script.coffee @@ -2642,4 +2642,4 @@ Main = if d.body Main.init() else - $.bind document, 'DOMContentLoaded', Main.init + $.bind d, 'DOMContentLoaded', Main.init From 6ffcf008711559adf64a8a5d5b71c217f20d2470 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 13:21:30 +0200 Subject: [PATCH 2/6] Single selector, less durfing. --- 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 6e6054ff2..86d0a3638 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3131,7 +3131,7 @@ expandComment.init(); } } - nodes = $$('.op').concat($$('a + table')); + nodes = $$('.op, a + table'); g.callbacks.forEach(function(callback) { return nodes.forEach(callback); }); diff --git a/script.coffee b/script.coffee index 787716f27..bf14dd630 100644 --- a/script.coffee +++ b/script.coffee @@ -2369,7 +2369,7 @@ Main = if conf['Comment Expansion'] expandComment.init() - nodes = $$('.op').concat $$ 'a + table' + nodes = $$ '.op, a + table' g.callbacks.forEach (callback) -> nodes.forEach callback $.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted options.init() From 99d5f8b1a932f1dbe3bbd3b0596bf22733b116a3 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 13:33:35 +0200 Subject: [PATCH 3/6] Use forEach in nodeInserted too. --- 4chan_x.user.js | 12 ++++-------- script.coffee | 3 +-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 86d0a3638..636418b4f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2779,16 +2779,12 @@ return location.href = url; }; nodeInserted = function(e) { - var callback, target, _i, _len, _ref, _results; + var target; target = e.target; if (target.nodeName === 'TABLE') { - _ref = g.callbacks; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - callback = _ref[_i]; - _results.push(callback(target)); - } - return _results; + return g.callbacks.forEach(function(callback) { + return callback(target); + }); } }; imgHover = { diff --git a/script.coffee b/script.coffee index bf14dd630..c129fdff2 100644 --- a/script.coffee +++ b/script.coffee @@ -2034,8 +2034,7 @@ redirect = -> nodeInserted = (e) -> {target} = e if target.nodeName is 'TABLE' - for callback in g.callbacks - callback target + g.callbacks.forEach (callback) -> callback target imgHover = init: -> From 5fe0d4db22425be8c862777260300b69f3d94c41 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 14:21:00 +0200 Subject: [PATCH 4/6] Yet another filter improvements, use superior array manipulations. --- 4chan_x.user.js | 44 ++++++++++++++------------------------------ script.coffee | 23 +++++++++-------------- 2 files changed, 23 insertions(+), 44 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 636418b4f..897cb7668 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -539,45 +539,29 @@ f = filter.match(/^\/(.+)\/(\w*)$/); this.regexps[key].push(RegExp(f[1], f[2])); } - if (this.regexps[key].length) { - this.callbacks.push(this[key]); - } + this.callbacks.push(this[key]); } return g.callbacks.push(this.node); }, node: function(root) { - var callback, _i, _j, _len, _len2, _ref, _ref2; - if (root.className === 'op') { - if (!g.REPLY && conf['Filter OPs']) { - _ref = filter.callbacks; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - callback = _ref[_i]; - if (callback(root)) { - threadHiding.hideHide(root.parentNode); - return; - } - } + if (!root.className) { + if (filter.callbacks.some(function(callback) { + return callback(root); + })) { + return replyHiding.hideHide($('td:not([nowrap])', root)); } - } else if (!root.classList.contains('inline')) { - _ref2 = filter.callbacks; - for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { - callback = _ref2[_j]; - if (callback(root)) { - replyHiding.hideHide($('td:not([nowrap])', root)); - return; - } + } else if (root.className === 'op' && !g.REPLY && conf['Filter OPs']) { + if (filter.callbacks.some(function(callback) { + return callback(root); + })) { + return threadHiding.hideHide(root.parentNode); } } }, test: function(key, value) { - var regexp, _i, _len, _ref; - _ref = filter.regexps[key]; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - regexp = _ref[_i]; - if (regexp.test(value)) { - return true; - } - } + return filter.regexps[key].some(function(regexp) { + return regexp.test(value); + }); }, name: function(root) { var name; diff --git a/script.coffee b/script.coffee index c129fdff2..49088534c 100644 --- a/script.coffee +++ b/script.coffee @@ -393,25 +393,20 @@ filter = f = filter.match /^\/(.+)\/(\w*)$/ @regexps[key].push RegExp f[1], f[2] #only execute what's filterable - @callbacks.push @[key] if @regexps[key].length + @callbacks.push @[key] g.callbacks.push @node node: (root) -> - if root.className is 'op' - if !g.REPLY and conf['Filter OPs'] - for callback in filter.callbacks - if callback root - threadHiding.hideHide root.parentNode - return - else unless root.classList.contains 'inline' - for callback in filter.callbacks - if callback root - replyHiding.hideHide $ 'td:not([nowrap])', root - return + unless root.className + if filter.callbacks.some((callback) -> callback root) + replyHiding.hideHide $ 'td:not([nowrap])', root + else if root.className is 'op' and not g.REPLY and conf['Filter OPs'] + if filter.callbacks.some((callback) -> callback root) + threadHiding.hideHide root.parentNode + test: (key, value) -> - for regexp in filter.regexps[key] - return true if regexp.test value + filter.regexps[key].some (regexp) -> regexp.test value name: (root) -> name = if root.className is 'op' then $ '.postername', root else $ '.commentpostername', root From 676d952c453f253d141d6a2bf43db88d659f42be Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 20:42:33 +0200 Subject: [PATCH 5/6] Tad simpler Favicon.update() --- 4chan_x.user.js | 17 ++--------------- script.coffee | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 897cb7668..5560803f3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2696,24 +2696,11 @@ unreadSFW: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAN9JREFUOMtj+P//PwMlmIEqBkDBfxie2NdVVVFaMikzPXsuCIPYIDFkNWANSAb815t+GI5B/Jj8iQfjapafBWEQG5saDBegK0ja8Ok9EH/AJofXBTBFlUf+/wPi/7jkcYYBCLef/v9/9pX//+cAMYiNLo/uAgZQYMVVLzsLcnYF0GaQ5otv/v+/9BpiEEgMJAdSA1JLlAGXgAZcfoNswGfcBpQDowoW2vi8AFIDUothwOQJvVXIgYUrEEFsqFoGYqLxA7HRiNUAWEIiyQBkGpaUsclhMwCWFpBpvHJUyY0AmdYZKFRtAsoAAAAASUVORK5CYII%3D', unreadNSFW: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAOBJREFUOMtj+P//PwMlmIEqBkDBfxie2DWxqqykYlJ6dtZcEAaxQWLIasAakAz4n3bGGI5B/JiJ8QfjlsefBWEQG5saDBegKyj5lPQeiD9gk8PrApiinv+V/4D4Py55nGEAwrP+t/9f/X82EM8Bs9Hl0V3AAAqsuGXxZ0HO7vlf8Q+k+eb/i0B8CWwQSAwkB1IDUkuUAbeAmm/9v4ww4DMeA8pKyifBQhufF0BqQGoxDJjcO7kKObBwBSKIDVXLQEw0fiA2GrEaAEtIJBmATMOSMjY5bAbA0gIyjVeOKrkRAMefDK/b7ecEAAAAAElFTkSuQmCC', update: function() { - var clone, favicon, href, l; + var clone, favicon, l; l = unread.replies.length; - if (g.dead) { - if (l > 0) { - href = Favicon.unreadDead; - } else { - href = Favicon.dead; - } - } else { - if (l > 0) { - href = Favicon.unread; - } else { - href = Favicon["default"]; - } - } favicon = $('link[rel="shortcut icon"]', d.head); + favicon.href = g.dead ? l ? Favicon.unreadDead : Favicon.dead : l ? Favicon.unread : Favicon["default"]; clone = favicon.cloneNode(true); - clone.href = href; return $.replace(favicon, clone); } }; diff --git a/script.coffee b/script.coffee index 49088534c..10317a696 100644 --- a/script.coffee +++ b/script.coffee @@ -1987,6 +1987,7 @@ Favicon = {href} = favicon Favicon.default = href Favicon.unread = if /ws/.test href then Favicon.unreadSFW else Favicon.unreadNSFW + dead: 'data:image/gif;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAIALAAAAAAQABAAAAIvlI+pq+D9DAgUoFkPDlbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==' empty: 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==' unreadDead: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANhJREFUOMutU0EKwjAQzEPFgyBFei209gOKINh6tL3qO3yAB9OHWPTeMZsmJaRpiNjAkE1mMt1stgwA+wdsFgM1oHE4FXmSpWUcRzWBYtozNfKAYdCHCrQuosX9tlk+CBS7NKMMbMF7vXoJtC7Om8HwhXzbCWCSn6qBJHd74FIBVS1jm7czYFSsq7gvpY0s6+ThJwc4743EHnGkIW2YAW+AphkMPj6DJE1LXW3fFUhD2pHBsTznLKCIFCstC3nGNvQZnQa6kX4yMGfdyi7OZaB7wZy93Cx/4xfgv/s+XYFMrAAAAABJRU5ErkJggg%3D%3D' @@ -1995,21 +1996,22 @@ Favicon = update: -> l = unread.replies.length - if g.dead - if l > 0 - href = Favicon.unreadDead + + favicon = $ 'link[rel="shortcut icon"]', d.head + favicon.href = + if g.dead + if l + Favicon.unreadDead + else + Favicon.dead else - href = Favicon.dead - else - if l > 0 - href = Favicon.unread - else - href = Favicon.default + if l + Favicon.unread + else + Favicon.default #XXX `favicon.href = href` doesn't work on Firefox - favicon = $ 'link[rel="shortcut icon"]', d.head clone = favicon.cloneNode true - clone.href = href $.replace favicon, clone redirect = -> From 661c2871cbe8c39edd202d2dbea0cd78158edec3 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 10 Oct 2011 21:04:58 +0200 Subject: [PATCH 6/6] Fix, OPs do not have ancestor tables. --- 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 5560803f3..1f4abe1d4 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2432,7 +2432,7 @@ _ref = $$('input', table); for (_i = 0, _len = _ref.length; _i < _len; _i++) { inlined = _ref[_i]; - if (hidden = $.id(inlined.name)) { + if (!(hidden = $.id(inlined.name)).classList.contains('op')) { $.x('ancestor::table[1]', hidden).hidden = false; } } diff --git a/script.coffee b/script.coffee index 10317a696..e2b717301 100644 --- a/script.coffee +++ b/script.coffee @@ -1816,7 +1816,7 @@ quoteInline = #select the corresponding table or loading td table = $.x "following::*[@id='i#{id}']", q for inlined in $$ 'input', table - if hidden = $.id inlined.name + unless (hidden = $.id inlined.name).classList.contains 'op' $.x('ancestor::table[1]', hidden).hidden = false $.rm table