Add post labelling.

This commit is contained in:
Mayhem 2014-02-17 20:53:39 +01:00
parent d052bfc186
commit ce2b9ee170
8 changed files with 78 additions and 46 deletions

View File

@ -1,6 +1,6 @@
- Post hiding rewrite: - The posts' menu now has a label entry listing the reasons why a post got hidden or highlighted.
- `Thread Hiding` and `Reply Hiding` settings are merged into one: `Post Hiding`. - `Thread Hiding` and `Reply Hiding` settings are merged into one: `Post Hiding`.
- `Thread Hiding Link` and `Reply Hiding Link` settings are merged into one: `Post Hiding Link`. - `Thread Hiding Link` and `Reply Hiding Link` settings are merged into one: `Post Hiding Link`.
### 3.18.1 - *2014-02-20* ### 3.18.1 - *2014-02-20*

View File

@ -57,7 +57,18 @@ Filter =
top = filter.match(/top:(yes|no)/)?[1] or 'yes' top = filter.match(/top:(yes|no)/)?[1] or 'yes'
top = top is 'yes' # Turn it into a boolean top = top is 'yes' # Turn it into a boolean
@filters[key].push @createFilter regexp, op, stub, hl, top @filters[key].push {
hide: !hl
op: op
stub: stub
class: hl
top: top
match: regexp
test: if typeof regexp is 'string'
Filter.stringTest # MD5 checking
else
Filter.regexpTest
}
# Only execute filter types that contain valid filters. # Only execute filter types that contain valid filters.
unless @filters[key].length unless @filters[key].length
@ -68,25 +79,6 @@ Filter =
name: 'Filter' name: 'Filter'
cb: @node cb: @node
createFilter: (regexp, op, stub, hl, top) ->
test =
if typeof regexp is 'string'
# MD5 checking
(value) -> regexp is value
else
(value) -> regexp.test value
settings =
hide: !hl
stub: stub
class: hl
top: top
(value, isReply) ->
if isReply and op is 'only' or !isReply and op is 'no'
return false
unless test value
return false
settings
node: -> node: ->
return if @isClone return if @isClone
for key of Filter.filters for key of Filter.filters
@ -94,23 +86,29 @@ Filter =
# Continue if there's nothing to filter (no tripcode for example). # Continue if there's nothing to filter (no tripcode for example).
continue if value is false continue if value is false
for filter in Filter.filters[key] for obj in Filter.filters[key]
unless result = filter value, @isReply unless Filter.test obj, value, @isReply
continue continue
# Hide # Hide
if result.hide if obj.hide
continue unless @isReply or g.VIEW is 'index' continue unless @isReply or g.VIEW is 'index'
@hide result.stub @hide "Hidden by filtering the #{key}: #{obj.match}", obj.stub
return return
# Highlight # Highlight
$.addClass @nodes.root, result.class @highlight "Highlighted by filtering the #{key}: #{obj.match}", obj.class, obj.top
unless @highlights and result.class in @highlights
(@highlights or= []).push result.class
if !@isReply and result.top
@thread.isOnTop = true
stringTest: (string, value) ->
regexp is value
regexpTest: (regexp, value) ->
regexp.test value
test: ({test, match, op}, value, isReply) ->
if isReply and op is 'only' or !isReply and op is 'no'
return false
unless test match, value
return false
true
name: (post) -> name: (post) ->
if 'name' of post.info if 'name' of post.info
return post.info.name return post.info.name

View File

@ -28,10 +28,11 @@ PostHiding =
if data = PostHiding.db.get {boardID: @board.ID, threadID: @thread.ID, postID: @ID} if data = PostHiding.db.get {boardID: @board.ID, threadID: @thread.ID, postID: @ID}
if data.thisPost is false if data.thisPost is false
Recursive.apply 'hide', @, data.makeStub, true label = "Recursively hidden for quoting No.#{@}"
Recursive.add 'hide', @, data.makeStub, true Recursive.apply 'hide', @, label, data.makeStub, true
Recursive.add 'hide', @, label, data.makeStub, true
else else
@hide data.makeStub, data.hideRecursively @hide 'Manually hidden', data.makeStub, data.hideRecursively
return unless Conf['Post Hiding'] return unless Conf['Post Hiding']
a = PostHiding.makeButton true a = PostHiding.makeButton true
@ -54,7 +55,7 @@ PostHiding =
if post.isHidden if post.isHidden
post.show() post.show()
else else
post.hide() post.hide 'Manually hidden'
PostHiding.saveHiddenState post PostHiding.saveHiddenState post
saveHiddenState: (post, val) -> saveHiddenState: (post, val) ->
@ -137,13 +138,14 @@ PostHiding =
thisPost = $('input[name=thisPost]', parent).checked if post.isReply thisPost = $('input[name=thisPost]', parent).checked if post.isReply
replies = $('input[name=replies]', parent).checked if post.isReply replies = $('input[name=replies]', parent).checked if post.isReply
makeStub = $('input[name=makeStub]', parent).checked makeStub = $('input[name=makeStub]', parent).checked
label = 'Manually hidden'
if !post.isReply if !post.isReply
post.hide makeStub post.hide label, makeStub
else if thisPost else if thisPost
post.hide makeStub, replies post.hide label, makeStub, replies
else if replies else if replies
Recursive.apply 'hide', post, makeStub, true Recursive.apply 'hide', post, label, makeStub, true
Recursive.add 'hide', post, makeStub, true Recursive.add 'hide', post, label, makeStub, true
else else
return return
val = if post.isReply val = if post.isReply

View File

@ -281,7 +281,7 @@ Build =
root.dataset.fullID = thread.fullID root.dataset.fullID = thread.fullID
$.addClass root, 'pinned' if thread.isPinned $.addClass root, 'pinned' if thread.isPinned
$.addClass root, thread.OP.highlights... if thread.OP.highlights $.addClass root, thread.OP.highlights... if thread.OP.highlights.length
thumb = root.firstElementChild thumb = root.firstElementChild
if data.spoiler and !Conf['Reveal Spoilers'] if data.spoiler and !Conf['Reveal Spoilers']

View File

@ -90,6 +90,7 @@ Main =
initFeature 'Delete Link', DeleteLink initFeature 'Delete Link', DeleteLink
initFeature 'Filter (Menu)', Filter.menu initFeature 'Filter (Menu)', Filter.menu
initFeature 'Download Link', DownloadLink initFeature 'Download Link', DownloadLink
initFeature 'Labels list', Labels
initFeature 'Archive Link', ArchiveLink initFeature 'Archive Link', ArchiveLink
initFeature 'Quote Inlining', QuoteInline initFeature 'Quote Inlining', QuoteInline
initFeature 'Quote Previewing', QuotePreview initFeature 'Quote Previewing', QuotePreview

View File

@ -52,6 +52,8 @@ class Post
@parseQuotes() @parseQuotes()
@parseFile that @parseFile that
@labels = []
@highlights = []
@isDead = false @isDead = false
@isHidden = false @isHidden = false
@ -106,7 +108,7 @@ class Post
# ES6 Set when? # ES6 Set when?
fullID = "#{match[1]}.#{match[2]}" fullID = "#{match[1]}.#{match[2]}"
@quotes.push fullID if @quotes.indexOf(fullID) is -1 @quotes.push fullID unless fullID in @quotes
parseFile: (that) -> parseFile: (that) ->
return unless (fileEl = $ '.file', @nodes.post) and thumb = $ 'img[data-md5]', fileEl return unless (fileEl = $ '.file', @nodes.post) and thumb = $ 'img[data-md5]', fileEl
@ -151,7 +153,8 @@ class Post
$.rmClass node, 'desktop' $.rmClass node, 'desktop'
return return
hide: (makeStub=Conf['Stubs'], hideRecursively=Conf['Recursive Hiding']) -> hide: (label, makeStub=Conf['Stubs'], hideRecursively=Conf['Recursive Hiding']) ->
@labels.push label unless label in @labels
return if @isHidden return if @isHidden
@isHidden = true @isHidden = true
if !@isReply if !@isReply
@ -159,8 +162,9 @@ class Post
return return
if hideRecursively if hideRecursively
Recursive.apply 'hide', @, makeStub, true label = "Recursively hidden for quoting No.#{@}"
Recursive.add 'hide', @, makeStub, true Recursive.apply 'hide', @, label, makeStub, true
Recursive.add 'hide', @, label, makeStub, true
for quotelink in Get.allQuotelinksLinkingTo @ for quotelink in Get.allQuotelinksLinkingTo @
$.addClass quotelink, 'filtered' $.addClass quotelink, 'filtered'
@ -183,6 +187,9 @@ class Post
show: (showRecursively=Conf['Recursive Hiding']) -> show: (showRecursively=Conf['Recursive Hiding']) ->
return if !@isHidden return if !@isHidden
@isHidden = false @isHidden = false
@labels = @labels.filter (label) ->
# This is lame.
!/^(Manually hidden|Recursively hidden|Hidden by)/.test label
if !@isReply if !@isReply
@thread.show() @thread.show()
return return
@ -199,6 +206,13 @@ class Post
delete @nodes.stub delete @nodes.stub
else else
@nodes.root.hidden = false @nodes.root.hidden = false
highlight: (label, highlight, top) ->
@labels.push label
unless highlight in @highlights
@highlights.push highlight
$.addClass @nodes.root, highlight
if !@isReply and top
@thread.isOnTop = true
kill: (file) -> kill: (file) ->
if file if file

View File

@ -84,7 +84,9 @@ UI = do ->
insertEntry: (entry, parent, data) -> insertEntry: (entry, parent, data) ->
if typeof entry.open is 'function' if typeof entry.open is 'function'
return unless entry.open data return unless entry.open data, (subEntry) =>
@parseEntry subEntry
entry.subEntries.push subEntry
$.add parent, entry.el $.add parent, entry.el
return unless entry.subEntries return unless entry.subEntries

15
src/Menu/Labels.coffee Normal file
View File

@ -0,0 +1,15 @@
Labels =
init: ->
return if !Conf['Menu']
$.event 'AddMenuEntry',
type: 'post'
el: $.el 'div', textContent: 'Labels'
order: 60
open: ({labels}, addSubEntry) ->
return false unless labels.length
@subEntries.length = 0
for label in labels
addSubEntry el: $.el 'div', textContent: label
true
subEntries: []