Slight filter performance and memory improvement.
This commit is contained in:
parent
ad2e396d04
commit
35abc22d5c
@ -575,39 +575,21 @@
|
|||||||
if (Object.keys(this.filters).length) return g.callbacks.push(this.node);
|
if (Object.keys(this.filters).length) return g.callbacks.push(this.node);
|
||||||
},
|
},
|
||||||
createFilter: function(regexp, op, hl, top) {
|
createFilter: function(regexp, op, hl, top) {
|
||||||
return function(post, value) {
|
var test;
|
||||||
var el, firstThread, isOP, thisThread;
|
test = typeof regexp === 'string' ? function(value) {
|
||||||
el = post.el, isOP = post.isOP;
|
return regexp === value;
|
||||||
|
} : function(value) {
|
||||||
|
return regexp.test(value);
|
||||||
|
};
|
||||||
|
return function(value, isOP) {
|
||||||
if (isOP && op === 'no' || !isOP && op === 'only') return false;
|
if (isOP && op === 'no' || !isOP && op === 'only') return false;
|
||||||
if (typeof regexp === 'string') {
|
if (!test(value)) return false;
|
||||||
if (regexp !== value) return false;
|
if (hl) return [hl, top];
|
||||||
} else if (!regexp.test(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (hl) {
|
|
||||||
if (isOP) {
|
|
||||||
$.addClass(el, hl);
|
|
||||||
} else {
|
|
||||||
$.addClass(el.parentNode, hl);
|
|
||||||
}
|
|
||||||
if (isOP && top && !g.REPLY) {
|
|
||||||
thisThread = el.parentNode;
|
|
||||||
if (firstThread = $('div[class=op]')) {
|
|
||||||
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isOP) {
|
|
||||||
if (!g.REPLY) threadHiding.hideHide(el.parentNode);
|
|
||||||
} else {
|
|
||||||
replyHiding.hideHide(el);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
node: function(post) {
|
node: function(post) {
|
||||||
var Filter, key, value, _i, _len, _ref;
|
var Filter, el, firstThread, isOP, key, result, thisThread, value, _i, _len, _ref;
|
||||||
if (post.isInlined) return;
|
if (post.isInlined) return;
|
||||||
for (key in filter.filters) {
|
for (key in filter.filters) {
|
||||||
value = filter[key](post);
|
value = filter[key](post);
|
||||||
@ -615,7 +597,31 @@
|
|||||||
_ref = filter.filters[key];
|
_ref = filter.filters[key];
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
Filter = _ref[_i];
|
Filter = _ref[_i];
|
||||||
if (Filter(post, value)) return;
|
if (!(result = Filter(value, isOP))) continue;
|
||||||
|
isOP = post.isOP, el = post.el;
|
||||||
|
if (result === true) {
|
||||||
|
if (isOP) {
|
||||||
|
if (!g.REPLY) {
|
||||||
|
threadHiding.hideHide(post.el.parentNode);
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replyHiding.hideHide(post.el);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isOP) {
|
||||||
|
$.addClass(el, result[0]);
|
||||||
|
} else {
|
||||||
|
$.addClass(el.parentNode, result[0]);
|
||||||
|
}
|
||||||
|
if (isOP && result[1] && !g.REPLY) {
|
||||||
|
thisThread = el.parentNode;
|
||||||
|
if (firstThread = $('div[class=op]')) {
|
||||||
|
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -499,34 +499,19 @@ filter =
|
|||||||
g.callbacks.push @node
|
g.callbacks.push @node
|
||||||
|
|
||||||
createFilter: (regexp, op, hl, top) ->
|
createFilter: (regexp, op, hl, top) ->
|
||||||
(post, value) ->
|
test =
|
||||||
{el, isOP} = post
|
|
||||||
if isOP and op is 'no' or !isOP and op is 'only'
|
|
||||||
return false
|
|
||||||
if typeof regexp is 'string'
|
if typeof regexp is 'string'
|
||||||
# MD5 checking
|
# MD5 checking
|
||||||
if regexp isnt value
|
(value) -> regexp is value
|
||||||
return false
|
else
|
||||||
else unless regexp.test value
|
(value) -> regexp.test value
|
||||||
|
(value, isOP) ->
|
||||||
|
if isOP and op is 'no' or !isOP and op is 'only'
|
||||||
|
return false
|
||||||
|
unless test value
|
||||||
return false
|
return false
|
||||||
if hl
|
if hl
|
||||||
if isOP
|
return [hl, top]
|
||||||
$.addClass el, hl
|
|
||||||
else
|
|
||||||
$.addClass el.parentNode, hl
|
|
||||||
if isOP and top and not g.REPLY
|
|
||||||
# Put the highlighted OPs' threads on top of the board pages...
|
|
||||||
thisThread = el.parentNode
|
|
||||||
# ...before the first non highlighted thread.
|
|
||||||
if firstThread = $ 'div[class=op]'
|
|
||||||
$.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling]
|
|
||||||
# Continue the filter lookup to add more classes or hide it.
|
|
||||||
return false
|
|
||||||
if isOP
|
|
||||||
unless g.REPLY
|
|
||||||
threadHiding.hideHide el.parentNode
|
|
||||||
else
|
|
||||||
replyHiding.hideHide el
|
|
||||||
true
|
true
|
||||||
|
|
||||||
node: (post) ->
|
node: (post) ->
|
||||||
@ -537,9 +522,33 @@ filter =
|
|||||||
# Continue if there's nothing to filter (no tripcode for example).
|
# Continue if there's nothing to filter (no tripcode for example).
|
||||||
continue
|
continue
|
||||||
for Filter in filter.filters[key]
|
for Filter in filter.filters[key]
|
||||||
if Filter post, value
|
unless result = Filter value, isOP
|
||||||
|
continue
|
||||||
|
{isOP, el} = post
|
||||||
|
|
||||||
|
# Hide
|
||||||
|
if result is true
|
||||||
|
if isOP
|
||||||
|
unless g.REPLY
|
||||||
|
threadHiding.hideHide post.el.parentNode
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
replyHiding.hideHide post.el
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Highlight
|
||||||
|
if isOP
|
||||||
|
$.addClass el, result[0]
|
||||||
|
else
|
||||||
|
$.addClass el.parentNode, result[0]
|
||||||
|
if isOP and result[1] and not g.REPLY
|
||||||
|
# Put the highlighted OPs' threads on top of the board pages...
|
||||||
|
thisThread = el.parentNode
|
||||||
|
# ...before the first non highlighted thread.
|
||||||
|
if firstThread = $ 'div[class=op]'
|
||||||
|
$.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling]
|
||||||
|
|
||||||
name: (post) ->
|
name: (post) ->
|
||||||
name = if post.isOP then $ '.postername', post.el else $ '.commentpostername', post.el
|
name = if post.isOP then $ '.postername', post.el else $ '.commentpostername', post.el
|
||||||
name.textContent
|
name.textContent
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user