Yet another filter improvements, use superior array manipulations.

This commit is contained in:
Nicolas Stepien 2011-10-10 14:21:00 +02:00
parent 99d5f8b1a9
commit 5fe0d4db22
2 changed files with 23 additions and 44 deletions

View File

@ -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;

View File

@ -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