Support specifying the sites that filters apply to. #2171
This commit is contained in:
parent
edc8cf6d35
commit
f3ed76f32f
@ -7,9 +7,6 @@ Filter =
|
|||||||
unless Conf['Filtered Backlinks']
|
unless Conf['Filtered Backlinks']
|
||||||
$.addClass doc, 'hide-backlinks'
|
$.addClass doc, 'hide-backlinks'
|
||||||
|
|
||||||
nsfwBoards = BoardConfig.sfwBoards(false).join(',')
|
|
||||||
sfwBoards = BoardConfig.sfwBoards(true).join(',')
|
|
||||||
|
|
||||||
for key of Config.filter
|
for key of Config.filter
|
||||||
for line in Conf[key].split '\n'
|
for line in Conf[key].split '\n'
|
||||||
continue if line[0] is '#'
|
continue if line[0] is '#'
|
||||||
@ -20,26 +17,11 @@ Filter =
|
|||||||
# Don't mix up filter flags with the regular expression.
|
# Don't mix up filter flags with the regular expression.
|
||||||
filter = line.replace regexp[0], ''
|
filter = line.replace regexp[0], ''
|
||||||
|
|
||||||
# Comma-separated list of the boards this filter applies to.
|
# List of the boards this filter applies to.
|
||||||
# Defaults to global.
|
boards = @parseBoards filter.match(/boards:([^;]+)/)?[1]
|
||||||
boardsRaw = filter.match(/boards:([^;]+)/)?[1].toLowerCase()
|
|
||||||
if boardsRaw
|
|
||||||
boards = {}
|
|
||||||
for board in boardsRaw.replace('nsfw', nsfwBoards).replace('sfw', sfwBoards).split(',')
|
|
||||||
boards[board] = true
|
|
||||||
else
|
|
||||||
boards = false
|
|
||||||
|
|
||||||
# boards to exclude from an otherwise global rule
|
# Boards to exclude from an otherwise global rule.
|
||||||
# due to the sfw and nsfw keywords, also works on all filters
|
excludes = @parseBoards filter.match(/exclude:([^;]+)/)?[1]
|
||||||
# replaces 'nsfw' and 'sfw' for consistency
|
|
||||||
excludesRaw = filter.match(/exclude:([^;]+)/)?[1].toLowerCase()
|
|
||||||
if excludesRaw
|
|
||||||
excludes = {}
|
|
||||||
for board in excludesRaw.replace('nsfw', nsfwBoards).replace('sfw', sfwBoards).split(',')
|
|
||||||
excludes[board] = true
|
|
||||||
else
|
|
||||||
excludes = false
|
|
||||||
|
|
||||||
if (isstring = (key in ['uniqueID', 'MD5']))
|
if (isstring = (key in ['uniqueID', 'MD5']))
|
||||||
# MD5 filter will use strings instead of regular expressions.
|
# MD5 filter will use strings instead of regular expressions.
|
||||||
@ -111,6 +93,25 @@ Filter =
|
|||||||
name: 'Filter'
|
name: 'Filter'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
|
# Parse comma-separated list of boards.
|
||||||
|
# Sites can be specified by a beginning part of the site domain followed by a colon.
|
||||||
|
parseBoards: (boardsRaw) ->
|
||||||
|
return false unless boardsRaw
|
||||||
|
boardsRaw = boardsRaw.toLowerCase()
|
||||||
|
boards = {}
|
||||||
|
siteFilter = ''
|
||||||
|
for boardID in boardsRaw.split(',')
|
||||||
|
if ':' in boardID
|
||||||
|
[siteFilter, boardID] = boardID.split(':')[-2..]
|
||||||
|
for siteID, siteProperties of Conf['siteProperties']
|
||||||
|
continue if siteProperties.canonical or siteID[...siteFilter.length] isnt siteFilter
|
||||||
|
if boardID in ['nsfw', 'sfw']
|
||||||
|
for boardID2 of SW[siteProperties.software]?.sfwBoards?(boardID is 'sfw') or []
|
||||||
|
boards["#{siteID}/#{boardID2}"] = true
|
||||||
|
else
|
||||||
|
boards["#{siteID}/#{boardID}"] = true
|
||||||
|
boards
|
||||||
|
|
||||||
test: (post, hideable=true) ->
|
test: (post, hideable=true) ->
|
||||||
return post.filterResults if post.filterResults
|
return post.filterResults if post.filterResults
|
||||||
hide = false
|
hide = false
|
||||||
@ -122,12 +123,14 @@ Filter =
|
|||||||
hideable = false
|
hideable = false
|
||||||
mask = (if post.isReply then 2 else 1)
|
mask = (if post.isReply then 2 else 1)
|
||||||
mask = (mask | (if post.file then 4 else 8))
|
mask = (mask | (if post.file then 4 else 8))
|
||||||
|
board = "#{post.siteID}/#{post.boardID}"
|
||||||
|
site = "#{post.siteID}/*"
|
||||||
for key of Filter.filters when ((value = Filter.value key, post)?)
|
for key of Filter.filters when ((value = Filter.value key, post)?)
|
||||||
# Continue if there's nothing to filter (no tripcode for example).
|
# Continue if there's nothing to filter (no tripcode for example).
|
||||||
for filter in Filter.filters[key]
|
for filter in Filter.filters[key]
|
||||||
continue if (
|
continue if (
|
||||||
(filter.boards and !filter.boards[post.boardID]) or
|
(filter.boards and !(filter.boards[board] or filter.boards[site] )) or
|
||||||
(filter.excludes and filter.excludes[post.boardID]) or
|
(filter.excludes and (filter.excludes[board] or filter.excludes[site])) or
|
||||||
(filter.mask & mask) or
|
(filter.mask & mask) or
|
||||||
(if filter.isstring then (filter.regexp isnt value) else !filter.regexp.test(value))
|
(if filter.isstring then (filter.regexp isnt value) else !filter.regexp.test(value))
|
||||||
)
|
)
|
||||||
|
|||||||
@ -31,12 +31,13 @@ Build =
|
|||||||
else
|
else
|
||||||
"/#{boardID}/thread/#{threadID}#p#{postID}"
|
"/#{boardID}/thread/#{threadID}#p#{postID}"
|
||||||
|
|
||||||
parseJSON: (data, boardID) ->
|
parseJSON: (data, boardID, siteID) ->
|
||||||
o =
|
o =
|
||||||
# id
|
# id
|
||||||
ID: data.no
|
ID: data.no
|
||||||
threadID: data.resto or data.no
|
threadID: data.resto or data.no
|
||||||
boardID: boardID
|
boardID: boardID
|
||||||
|
siteID: siteID or Site.hostname
|
||||||
isReply: !!data.resto
|
isReply: !!data.resto
|
||||||
# thread status
|
# thread status
|
||||||
isSticky: !!data.sticky
|
isSticky: !!data.sticky
|
||||||
|
|||||||
@ -9,9 +9,14 @@
|
|||||||
<li>
|
<li>
|
||||||
Per boards, separate them with commas. It is global if not specified. Use <code>sfw</code> and <code>nsfw</code> to reference all worksafe or not-worksafe boards.<br>
|
Per boards, separate them with commas. It is global if not specified. Use <code>sfw</code> and <code>nsfw</code> to reference all worksafe or not-worksafe boards.<br>
|
||||||
For example: <code>boards:a,jp;</code>.<br>
|
For example: <code>boards:a,jp;</code>.<br>
|
||||||
|
To specify boards on a particular site, put the beginning of the domain and a slash character before the list.<br>
|
||||||
|
Any initial <code>www.</code> should not be included, and all 4chan domains are considered <code>4chan.org</code>.<br>
|
||||||
|
For example: <code>boards:4:a,jp,sama:a,z;</code>.<br>
|
||||||
|
An asterisk can be used to specify all boards on a site.<br>
|
||||||
|
For example: <code>boards:4:*;</code>.<br>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
In case of a global rule or one that uses <code>sfw</code>/<code>nsfw</code>, select boards to be excluded from the filter.<br>
|
Select boards to be excluded from the filter. The syntax is the same as for the <code>boards:</code> option above.<br>
|
||||||
For example: <code>exclude:vg,v;</code>.
|
For example: <code>exclude:vg,v;</code>.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@ -349,7 +349,7 @@ ThreadWatcher =
|
|||||||
|
|
||||||
unread++
|
unread++
|
||||||
|
|
||||||
if !quotingYou and !Conf['Require OP Quote Link'] and youOP and not Filter.isHidden(Build.parseJSON postObj, boardID)
|
if !quotingYou and !Conf['Require OP Quote Link'] and youOP and not Filter.isHidden(Build.parseJSON postObj, boardID, siteID)
|
||||||
quotingYou = true
|
quotingYou = true
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -367,7 +367,7 @@ ThreadWatcher =
|
|||||||
}
|
}
|
||||||
quotesYou = true
|
quotesYou = true
|
||||||
break
|
break
|
||||||
if quotesYou and not Filter.isHidden(Build.parseJSON postObj, boardID)
|
if quotesYou and not Filter.isHidden(Build.parseJSON postObj, boardID, siteID)
|
||||||
quotingYou = true
|
quotingYou = true
|
||||||
|
|
||||||
ThreadWatcher.update siteID, boardID, threadID, {last, replies, isDead, unread, quotingYou}
|
ThreadWatcher.update siteID, boardID, threadID, {last, replies, isDead, unread, quotingYou}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ class Post
|
|||||||
@ID = +root.id.match(/\d*$/)[0]
|
@ID = +root.id.match(/\d*$/)[0]
|
||||||
@threadID = @thread.ID
|
@threadID = @thread.ID
|
||||||
@boardID = @board.ID
|
@boardID = @board.ID
|
||||||
|
@siteID = Site.hostname
|
||||||
@fullID = "#{@board}.#{@ID}"
|
@fullID = "#{@board}.#{@ID}"
|
||||||
@context = @
|
@context = @
|
||||||
@isReply = (@ID isnt @threadID)
|
@isReply = (@ID isnt @threadID)
|
||||||
|
|||||||
@ -151,3 +151,6 @@ SW.yotsuba =
|
|||||||
|
|
||||||
hasCORS: (url) ->
|
hasCORS: (url) ->
|
||||||
url.split('/')[...3].join('/') is location.protocol + '//a.4cdn.org'
|
url.split('/')[...3].join('/') is location.protocol + '//a.4cdn.org'
|
||||||
|
|
||||||
|
sfwBoards: (sfw) ->
|
||||||
|
BoardConfig.sfwBoards(sfw)
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
Site =
|
Site =
|
||||||
defaultProperties:
|
defaultProperties:
|
||||||
'4chan.org': {software: 'yotsuba'}
|
'4chan.org': {software: 'yotsuba'}
|
||||||
'4channel.org': {software: 'yotsuba'}
|
'4channel.org': {canonical: '4chan.org'}
|
||||||
'4cdn.org': {software: 'yotsuba'}
|
'4cdn.org': {canonical: '4chan.org'}
|
||||||
|
|
||||||
init: (cb) ->
|
init: (cb) ->
|
||||||
$.extend Conf['siteProperties'], Site.defaultProperties
|
$.extend Conf['siteProperties'], Site.defaultProperties
|
||||||
{hostname} = location
|
{hostname} = location
|
||||||
while hostname and hostname not of Conf['siteProperties']
|
while hostname and hostname not of Conf['siteProperties']
|
||||||
hostname = hostname.replace(/^[^.]*\.?/, '')
|
hostname = hostname.replace(/^[^.]*\.?/, '')
|
||||||
if hostname and Conf['siteProperties'][hostname].software of SW
|
if hostname
|
||||||
@set hostname
|
hostname = canonical if (canonical = Conf['siteProperties'][hostname].canonical)
|
||||||
cb()
|
if Conf['siteProperties'][hostname].software of SW
|
||||||
|
@set hostname
|
||||||
|
cb()
|
||||||
$.onExists doc, 'body', =>
|
$.onExists doc, 'body', =>
|
||||||
for software of SW when (changes = SW[software].detect?())
|
for software of SW when (changes = SW[software].detect?())
|
||||||
changes.software = software
|
changes.software = software
|
||||||
@ -32,5 +34,4 @@ Site =
|
|||||||
set: (@hostname) ->
|
set: (@hostname) ->
|
||||||
@properties = Conf['siteProperties'][@hostname]
|
@properties = Conf['siteProperties'][@hostname]
|
||||||
@software = @properties.software
|
@software = @properties.software
|
||||||
@hostname = '4chan.org' if @software is 'yotsuba'
|
|
||||||
$.extend @, SW[@software]
|
$.extend @, SW[@software]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user