diff --git a/4chan_x.user.js b/4chan_x.user.js index 1a590ea26..6901d407c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -78,6 +78,7 @@ Filtering: { 'Anonymize': [false, 'Make everybody anonymous'], 'Filter': [false, 'Self-moderation placebo'], + 'Filter OPs': [false, 'Filter OPs along with their threads'], 'Reply Hiding': [true, 'Hide single replies'], 'Thread Hiding': [true, 'Hide entire threads'], 'Show Stubs': [true, 'Of hidden threads / replies'] @@ -528,14 +529,14 @@ }; filter = { regexps: {}, + callbacks: [], init: function() { - var filter, key, m, regx, _i, _len, _results; + var filter, key, m, regx, _i, _len; HTMLBlockquoteElement.prototype.toString = function() { return ($.el('a', { innerHTML: this.innerHTML.replace(/
/g, '\n') })).textContent; }; - _results = []; for (key in config.filter) { if (!(m = conf[key].match(/(.+)/g))) { continue; @@ -549,9 +550,35 @@ } } catch (_e) {} } - _results.push(this.regexps[key].length ? g.callbacks.push(this[key]) : void 0); + if (this.regexps[key].length) { + 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; + } + } + } + } 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; + } + } } - return _results; }, test: function(key, value) { var regexp, _i, _len, _ref; @@ -565,52 +592,45 @@ }, name: function(root) { var name; - if (!(name = root.className === 'op' ? $('.postername', root).textContent : $('.commentpostername', root).textContent)) { - return; + if ((name = root.className === 'op' ? $('.postername', root).textContent : $('.commentpostername', root).textContent)) { + return filter.test('name', name); } - return filter.test('name', name); }, trip: function(root) { var trip; - if (!(trip = $('.postertrip', root))) { - return; + if (trip = $('.postertrip', root)) { + return filter.test('trip', trip.textContent); } - return filter.test('trip', trip.textContent); }, mail: function(root) { var mail; - if (!(mail = $('.linkmail', root))) { - return; + if (mail = $('.linkmail', root)) { + return filter.test('mail', mail.href); } - return filter.test('mail', mail.href); }, sub: function(root) { var sub; - if (!(sub = root.className === 'op' ? $('.filetitle', root).textContent : $('.replytitle', root).textContent)) { - return; + if ((sub = root.className === 'op' ? $('.filetitle', root).textContent : $('.replytitle', root).textContent)) { + return filter.test('sub', sub); } - return filter.test('sub', sub); }, com: function(root) { var com; - if (!(com = $('blockquote', root).toString())) { - return; + if (com = $('blockquote', root).toString()) { + return filter.test('com', com); } - return filter.test('com', com); }, file: function(root) { var file; - if (!(file = $('.filesize span', root))) { - return; + if (file = $('.filesize span', root)) { + return filter.test('file', file.title); } - return filter.test('file', file.title); }, md5: function(root) { var img; - if (!(img = $('img[md5]', root))) { - return; + if (img = $('img[md5]', root)) { + return filter.test('md5', img.getAttribute('md5')); } - return filter.test('md5', img.getAttribute('md5')); } }; expandComment = { @@ -818,7 +838,14 @@ } }, hide: function(reply) { - var a, div, id, name, table, trip, _ref; + var id; + replyHiding.hideHide(reply); + id = reply.id; + g.hiddenReplies[id] = Date.now(); + return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); + }, + hideHide: function(reply) { + var a, div, name, table, trip, _ref; table = reply.parentNode.parentNode.parentNode; table.hidden = true; if (conf['Show Stubs']) { @@ -832,11 +859,8 @@ className: 'stub' }); $.add(div, a); - $.before(table, div); + return $.before(table, div); } - id = reply.id; - g.hiddenReplies[id] = Date.now(); - return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); }, show: function(table) { var id; diff --git a/script.coffee b/script.coffee index a01f9e74d..7db6ee694 100644 --- a/script.coffee +++ b/script.coffee @@ -12,6 +12,7 @@ config = Filtering: 'Anonymize': [false, 'Make everybody anonymous'] 'Filter': [false, 'Self-moderation placebo'] + 'Filter OPs': [false, 'Filter OPs along with their threads'] 'Reply Hiding': [true, 'Hide single replies'] 'Thread Hiding': [true, 'Hide entire threads'] 'Show Stubs': [true, 'Of hidden threads / replies'] @@ -385,6 +386,7 @@ $$ = (selector, root=d.body) -> filter = regexps: {} + callbacks: [] init: -> HTMLBlockquoteElement.prototype.toString = -> return ($.el 'a', innerHTML: @innerHTML.replace /
/g, '\n').textContent @@ -397,40 +399,47 @@ filter = try if (regx = eval filter).constructor is RegExp @regexps[key].push regx #only execute what's filterable - g.callbacks.push @[key] if @regexps[key].length + @callbacks.push @[key] if @regexps[key].length + 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 test: (key, value) -> for regexp in filter.regexps[key] return true if regexp.test value name: (root) -> - unless (name = if root.className is 'op' then $('.postername', root).textContent else $('.commentpostername', root).textContent) - return - filter.test 'name', name + if (name = if root.className is 'op' then $('.postername', root).textContent else $('.commentpostername', root).textContent) + filter.test 'name', name trip: (root) -> - unless trip = $('.postertrip', root) - return - filter.test 'trip', trip.textContent + if trip = $('.postertrip', root) + filter.test 'trip', trip.textContent mail: (root) -> - unless mail = $('.linkmail', root) - return - filter.test 'mail', mail.href + if mail = $('.linkmail', root) + filter.test 'mail', mail.href sub: (root) -> - unless(sub = if root.className is 'op' then $('.filetitle', root).textContent else $('.replytitle', root).textContent) - return - filter.test 'sub', sub + if (sub = if root.className is 'op' then $('.filetitle', root).textContent else $('.replytitle', root).textContent) + filter.test 'sub', sub com: (root) -> - unless com = $('blockquote', root).toString() - return - filter.test 'com', com + if com = $('blockquote', root).toString() + filter.test 'com', com file: (root) -> - unless file = $ '.filesize span', root - return - filter.test 'file', file.title + if file = $ '.filesize span', root + filter.test 'file', file.title md5: (root) -> - unless img = $ 'img[md5]', root - return - filter.test 'md5', img.getAttribute('md5') + if img = $ 'img[md5]', root + filter.test 'md5', img.getAttribute('md5') expandComment = init: -> @@ -575,6 +584,13 @@ replyHiding = $.rm div hide: (reply) -> + replyHiding.hideHide reply + + id = reply.id + g.hiddenReplies[id] = Date.now() + $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies + + hideHide: (reply) -> table = reply.parentNode.parentNode.parentNode table.hidden = true @@ -590,10 +606,6 @@ replyHiding = $.add div, a $.before table, div - id = reply.id - g.hiddenReplies[id] = Date.now() - $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies - show: (table) -> table.hidden = false