From f823b73a40da41d0ff400e7d769db5c1d9c81ce6 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 22 Mar 2019 02:26:57 -0700 Subject: [PATCH] Add option to filter only posts with files. --- src/Filtering/Filter.coffee | 16 +++++++++++----- src/General/Settings/Filter-guide.html | 8 ++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index 232da3cf5..a0c6a6193 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -59,9 +59,13 @@ Filter = ], 60 continue - # Filter OPs along with their threads, replies only, or both. - # Defaults to both. - op = filter.match(/[^t]op:(yes|no|only)/)?[1] or 'yes' + # Filter OPs along with their threads or replies only. + op = filter.match(/[^t]op:(no|only)/)?[1] or '' + mask = {'no': 1, 'only': 2}[op] or 0 + + # Filter only posts with/without files. + file = filter.match(/file:(no|only)/)?[1] or '' + mask = mask | ({'no': 4, 'only': 8}[file] or 0) # Overrule the `Show Stubs` setting. # Defaults to stub showing. @@ -96,7 +100,7 @@ Filter = # Hide the post (default case). hide = !(hl or noti) - filter = {isstring, regexp, boards, excludes, op, hide, stub, hl, top, noti} + filter = {isstring, regexp, boards, excludes, mask, hide, stub, hl, top, noti} if key is 'general' for type in types (@filters[type] or= []).push filter @@ -117,13 +121,15 @@ Filter = noti = false if QuoteYou.isYou(post) hideable = false + mask = (if post.isReply then 2 else 1) + mask = (mask | (if post.file then 4 else 8)) for key of Filter.filters when ((value = Filter[key] post)?) # Continue if there's nothing to filter (no tripcode for example). for filter in Filter.filters[key] continue if ( (filter.boards and !filter.boards[post.boardID]) or (filter.excludes and filter.excludes[post.boardID]) or - filter.op is (if post.isReply then 'only' else 'no') or + (filter.mask & mask) or (if filter.isstring then (filter.regexp isnt value) else !filter.regexp.test(value)) ) if filter.hide diff --git a/src/General/Settings/Filter-guide.html b/src/General/Settings/Filter-guide.html index 5dec5f533..2e47c6b31 100644 --- a/src/General/Settings/Filter-guide.html +++ b/src/General/Settings/Filter-guide.html @@ -15,8 +15,12 @@ For example: exclude:vg,v;.
  • - Filter OPs only along with their threads (`only`), replies only (`no`), or both (`yes`, this is default).
    - For example: op:only;, op:no; or op:yes;. + Filter OPs only along with their threads (`only`) or replies only (`no`).
    + For example: op:only; or op:no;. +
  • +
  • + Filter only posts with files (`only`) or only posts without files (`no`).
    + For example: file:only; or file:no;.
  • Overrule the `Show Stubs` setting if specified: create a stub (`yes`) or not (`no`).