semicolon seperated filters
This commit is contained in:
parent
e15054e1af
commit
6b5d403368
@ -295,7 +295,6 @@ hideThread: (div) ->
|
|||||||
hide(div)
|
hide(div)
|
||||||
if getValue('Show Stubs')
|
if getValue('Show Stubs')
|
||||||
a: tag('a')
|
a: tag('a')
|
||||||
#n: parseInt($('span.omittedposts', div)?.textContent) || 0
|
|
||||||
if span: $('.omittedposts', div)
|
if span: $('.omittedposts', div)
|
||||||
n: Number(span.textContent.match(/\d+/)[0])
|
n: Number(span.textContent.match(/\d+/)[0])
|
||||||
else
|
else
|
||||||
|
|||||||
@ -336,7 +336,6 @@ cursor: pointer; \
|
|||||||
hide(div);
|
hide(div);
|
||||||
if (getValue('Show Stubs')) {
|
if (getValue('Show Stubs')) {
|
||||||
a = tag('a');
|
a = tag('a');
|
||||||
//n: parseInt($('span.omittedposts', div)?.textContent) || 0
|
|
||||||
(span = $('.omittedposts', div)) ? (n = Number(span.textContent.match(/\d+/)[0])) : (n = 0);
|
(span = $('.omittedposts', div)) ? (n = Number(span.textContent.match(/\d+/)[0])) : (n = 0);
|
||||||
n += $$('table', div).length;
|
n += $$('table', div).length;
|
||||||
text = n === 1 ? "1 reply" : ("" + n + " replies");
|
text = n === 1 ? "1 reply" : ("" + n + " replies");
|
||||||
|
|||||||
@ -154,8 +154,9 @@ filterThread: (thread, filter) ->
|
|||||||
s: $('blockquote', thread).textContent
|
s: $('blockquote', thread).textContent
|
||||||
when 'File'
|
when 'File'
|
||||||
s: x('./span[@class="filesize"]', thread)?.textContent || ''
|
s: x('./span[@class="filesize"]', thread)?.textContent || ''
|
||||||
if filter[field].test(s)
|
for regex in filter[field]
|
||||||
return true
|
if regex.test(s)
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
filterReply: (table, filter) ->
|
filterReply: (table, filter) ->
|
||||||
@ -175,19 +176,27 @@ filterReply: (table, filter) ->
|
|||||||
s: $('blockquote', table).textContent
|
s: $('blockquote', table).textContent
|
||||||
when 'File'
|
when 'File'
|
||||||
s: $('span.filesize', table)?.textContent || ''
|
s: $('span.filesize', table)?.textContent || ''
|
||||||
if filter[field].test(s)
|
for regex in filter[field]
|
||||||
return true
|
if regex.test(s)
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
filterAll: ->
|
filterAll: ->
|
||||||
saveFilters()
|
saveFilters()
|
||||||
|
|
||||||
#better way of doing this?
|
#better way of doing this? if we just say `compiled: filters`,
|
||||||
|
#changing a prop in one will change a prop in the other.
|
||||||
compiled: {}
|
compiled: {}
|
||||||
for filter of filters
|
for filter of filters
|
||||||
compiled[filter]: {}
|
compiled[filter]: {}
|
||||||
for field of filters[filter]
|
for field of filters[filter]
|
||||||
compiled[filter][field]: new RegExp(filters[filter][field], 'i')
|
s: filters[filter][field]
|
||||||
|
split: s.split(';')
|
||||||
|
trimmed: el.trimLeft() for el in split
|
||||||
|
filtered: trimmed.filter((el)-> el.length)
|
||||||
|
if filtered.length
|
||||||
|
regexes: new RegExp(el, 'i') for el in filtered
|
||||||
|
compiled[filter][field]: regexes
|
||||||
|
|
||||||
[replies, threads]: reset()
|
[replies, threads]: reset()
|
||||||
num: if threads.length then replies.length + threads.length else $$('blockquote', form).length
|
num: if threads.length then replies.length + threads.length else $$('blockquote', form).length
|
||||||
|
|||||||
@ -167,7 +167,7 @@ display: none; \
|
|||||||
// we could try threading the op, but that might affect other scripts.
|
// we could try threading the op, but that might affect other scripts.
|
||||||
// also, I really want to try out *gasp* eval().
|
// also, I really want to try out *gasp* eval().
|
||||||
filterThread = function filterThread(thread, filter) {
|
filterThread = function filterThread(thread, filter) {
|
||||||
var _a, _b, _c, _d, _e, field, s;
|
var _a, _b, _c, _d, _e, _f, _g, _h, field, regex, s;
|
||||||
_a = filter;
|
_a = filter;
|
||||||
for (field in _a) { if (__hasProp.call(_a, field)) {
|
for (field in _a) { if (__hasProp.call(_a, field)) {
|
||||||
if (field === 'Name') {
|
if (field === 'Name') {
|
||||||
@ -183,13 +183,17 @@ display: none; \
|
|||||||
} else if (field === 'File') {
|
} else if (field === 'File') {
|
||||||
s = ((_e = x('./span[@class="filesize"]', thread)) == undefined ? undefined : _e.textContent) || '';
|
s = ((_e = x('./span[@class="filesize"]', thread)) == undefined ? undefined : _e.textContent) || '';
|
||||||
}
|
}
|
||||||
if (filter[field].test(s)) {
|
_g = filter[field];
|
||||||
return true;
|
for (_f = 0, _h = _g.length; _f < _h; _f++) {
|
||||||
|
regex = _g[_f];
|
||||||
|
if (regex.test(s)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
};
|
};
|
||||||
filterReply = function filterReply(table, filter) {
|
filterReply = function filterReply(table, filter) {
|
||||||
var _a, _b, _c, _d, _e, field, s;
|
var _a, _b, _c, _d, _e, _f, _g, _h, field, regex, s;
|
||||||
_a = filter;
|
_a = filter;
|
||||||
for (field in _a) { if (__hasProp.call(_a, field)) {
|
for (field in _a) { if (__hasProp.call(_a, field)) {
|
||||||
if (field === 'Name') {
|
if (field === 'Name') {
|
||||||
@ -207,42 +211,77 @@ display: none; \
|
|||||||
} else if (field === 'File') {
|
} else if (field === 'File') {
|
||||||
s = ((_e = $('span.filesize', table)) == undefined ? undefined : _e.textContent) || '';
|
s = ((_e = $('span.filesize', table)) == undefined ? undefined : _e.textContent) || '';
|
||||||
}
|
}
|
||||||
if (filter[field].test(s)) {
|
_g = filter[field];
|
||||||
return true;
|
for (_f = 0, _h = _g.length; _f < _h; _f++) {
|
||||||
|
regex = _g[_f];
|
||||||
|
if (regex.test(s)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
};
|
};
|
||||||
filterAll = function filterAll() {
|
filterAll = function filterAll() {
|
||||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, compiled, field, filter, imagesCount, num, replies, reply, thread, threads;
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, compiled, filter, imagesCount, num, replies, reply, thread, threads;
|
||||||
saveFilters();
|
saveFilters();
|
||||||
//better way of doing this?
|
//better way of doing this? if we just say `compiled: filters`,
|
||||||
|
//changing a prop in one will change a prop in the other.
|
||||||
compiled = {};
|
compiled = {};
|
||||||
_a = filters;
|
_a = filters;
|
||||||
for (filter in _a) { if (__hasProp.call(_a, filter)) {
|
for (filter in _a) { if (__hasProp.call(_a, filter)) {
|
||||||
compiled[filter] = {};
|
(function() {
|
||||||
_b = filters[filter];
|
var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, el, field, filtered, regexes, s, split, trimmed;
|
||||||
for (field in _b) { if (__hasProp.call(_b, field)) {
|
compiled[filter] = {};
|
||||||
compiled[filter][field] = new RegExp(filters[filter][field], 'i');
|
_b = []; _c = filters[filter];
|
||||||
}}
|
for (field in _c) { if (__hasProp.call(_c, field)) {
|
||||||
|
_b.push((function() {
|
||||||
|
s = filters[filter][field];
|
||||||
|
split = s.split(';');
|
||||||
|
trimmed = (function() {
|
||||||
|
_d = []; _f = split;
|
||||||
|
for (_e = 0, _g = _f.length; _e < _g; _e++) {
|
||||||
|
el = _f[_e];
|
||||||
|
_d.push(el.trimLeft());
|
||||||
|
}
|
||||||
|
return _d;
|
||||||
|
})();
|
||||||
|
filtered = trimmed.filter(function(el) {
|
||||||
|
return el.length;
|
||||||
|
});
|
||||||
|
if (filtered.length) {
|
||||||
|
regexes = (function() {
|
||||||
|
_h = []; _j = filtered;
|
||||||
|
for (_i = 0, _k = _j.length; _i < _k; _i++) {
|
||||||
|
el = _j[_i];
|
||||||
|
_h.push(new RegExp(el, 'i'));
|
||||||
|
}
|
||||||
|
return _h;
|
||||||
|
})();
|
||||||
|
compiled[filter][field] = regexes;
|
||||||
|
return compiled[filter][field];
|
||||||
|
}
|
||||||
|
})());
|
||||||
|
}}
|
||||||
|
return _b;
|
||||||
|
})();
|
||||||
}}
|
}}
|
||||||
_c = reset();
|
_b = reset();
|
||||||
replies = _c[0];
|
replies = _b[0];
|
||||||
threads = _c[1];
|
threads = _b[1];
|
||||||
num = threads.length ? replies.length + threads.length : $$('blockquote', form).length;
|
num = threads.length ? replies.length + threads.length : $$('blockquote', form).length;
|
||||||
//these loops look combinable
|
//these loops look combinable
|
||||||
_e = replies;
|
_d = replies;
|
||||||
for (_d = 0, _f = _e.length; _d < _f; _d++) {
|
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||||
reply = _e[_d];
|
reply = _d[_c];
|
||||||
_g = compiled;
|
_f = compiled;
|
||||||
for (filter in _g) { if (__hasProp.call(_g, filter)) {
|
for (filter in _f) { if (__hasProp.call(_f, filter)) {
|
||||||
filterReply(reply, compiled[filter]) ? reply.className += ' ' + filter : null;
|
filterReply(reply, compiled[filter]) ? reply.className += ' ' + filter : null;
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
_i = threads;
|
_h = threads;
|
||||||
for (_h = 0, _j = _i.length; _h < _j; _h++) {
|
for (_g = 0, _i = _h.length; _g < _i; _g++) {
|
||||||
thread = _i[_h];
|
thread = _h[_g];
|
||||||
_k = compiled;
|
_j = compiled;
|
||||||
for (filter in _k) { if (__hasProp.call(_k, filter)) {
|
for (filter in _j) { if (__hasProp.call(_j, filter)) {
|
||||||
filterThread(thread, compiled[filter]) ? thread.className += ' ' + filter : null;
|
filterThread(thread, compiled[filter]) ? thread.className += ' ' + filter : null;
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user