From 41ea3beab8147e9e9207561647e1a041ad2042d3 Mon Sep 17 00:00:00 2001
From: dzamie
Date: Tue, 5 Jul 2016 17:41:24 -0400
Subject: [PATCH] Add sfw/nsfw to Filters
Addresses #944
Allows users to include "sfw" and "nsfw" as boards to reference all
worksafe and not-worksafe boards.
Checks for exclusions on all filters to allow for things like
"boards:nsfw;exclude:gif"
---
src/Filtering/Filter.coffee | 12 ++++++++----
src/General/Settings/Filter-guide.html | 6 +++---
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee
index 079243745..af732192e 100644
--- a/src/Filtering/Filter.coffee
+++ b/src/Filtering/Filter.coffee
@@ -6,6 +6,9 @@ Filter =
unless Conf['Filtered Backlinks']
$.addClass doc, 'hide-backlinks'
+ nsfwBoards = 'aco,b,d,e,f,gif,h,hc,hm,hr,i,ic,pol,r,r9k,s,s4s,soc,t,trash,u,wg,y'
+ sfwBoards = '3,a,adv,an,asp,biz,c,cgl,ck,cm,co,diy,fa,fit,g,gd,his,int,jp,k,lgbt,lit,m,mlp,mu,n,news,o,out,p,po,qa,qst,sci,sp,tg,toy,trv,tv,v,vg,vp,vr,w,wsg,wsr,x'
+
for key of Config.filter
@filters[key] = []
for line in Conf[key].split '\n'
@@ -20,13 +23,14 @@ Filter =
# Comma-separated list of the boards this filter applies to.
# Defaults to global.
boards = filter.match(/boards:([^;]+)/)?[1].toLowerCase() or 'global'
+ boards = boards.replace('nsfw', nsfwBoards).replace('sfw', sfwBoards)
boards = if boards is 'global' then null else boards.split(',')
# boards to exclude from an otherwise global rule
- excludes = if boards is null
- filter.match(/exclude:([^;]+)/)?[1].toLowerCase().split(',') or null
- else
- null
+ # due to the sfw and nsfw keywords, also works on all filters
+ # replaces 'nsfw' and 'sfw' for consistency
+ excludes = filter.match(/exclude:([^;]+)/)?[1].toLowerCase() or null
+ excludes = if excludes is null then null else excludes.replace('nsfw', nsfwBoards).replace('sfw', sfwBoards).split(',')
if key in ['uniqueID', 'MD5']
# MD5 filter will use strings instead of regular expressions.
diff --git a/src/General/Settings/Filter-guide.html b/src/General/Settings/Filter-guide.html
index 50ffaf0af..22cf5a5a9 100644
--- a/src/General/Settings/Filter-guide.html
+++ b/src/General/Settings/Filter-guide.html
@@ -7,11 +7,11 @@
You can use these settings with each regular expression, separate them with semicolons:
-
- Per boards, separate them with commas. It is global if not specified.
- For example: boards:a,jp;.
+ Per boards, separate them with commas. It is global if not specified. Use sfw and nsfw to reference all worksafe or not-worksafe boards.
+ For example: boards:a,jp;.
-
- In case of a global rule, select boards to be excluded from the filter.
+ In case of a global rule or one that uses sfw/nsfw, select boards to be excluded from the filter.
For example: exclude:vg,v;.
-