Merge branch 'cataloghiding2'
Conflicts: src/Filtering/ThreadHiding.coffee
This commit is contained in:
commit
fd153e7241
@ -1,13 +1,36 @@
|
|||||||
ThreadHiding =
|
ThreadHiding =
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'index' or !Conf['Thread Hiding Buttons'] and !Conf['Thread Hiding Link'] and !Conf['JSON Navigation']
|
return if g.VIEW is 'thread' or !Conf['Thread Hiding Buttons'] and !Conf['Thread Hiding Link'] and !Conf['JSON Navigation']
|
||||||
|
|
||||||
@db = new DataBoard 'hiddenThreads'
|
@db = new DataBoard 'hiddenThreads'
|
||||||
@syncCatalog()
|
return @catalogHide() if g.VIEW is 'catalog'
|
||||||
Thread.callbacks.push
|
Thread.callbacks.push
|
||||||
name: 'Thread Hiding'
|
name: 'Thread Hiding'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
|
catalogHide: ->
|
||||||
|
@hiddenThreads = ThreadHiding.db.get
|
||||||
|
boardID: g.BOARD.ID
|
||||||
|
defaultValue: {}
|
||||||
|
@hiddenThreads[threadID] = true for threadID of @hiddenThreads
|
||||||
|
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify @hiddenThreads
|
||||||
|
$.ready ->
|
||||||
|
new MutationObserver(ThreadHiding.catalogSave).observe $.id('threads'),
|
||||||
|
attributes: true
|
||||||
|
subtree: true
|
||||||
|
attributeFilter: ['style']
|
||||||
|
|
||||||
|
catalogSave: ->
|
||||||
|
hiddenThreads2 = JSON.parse localStorage.getItem "4chan-hide-t-#{g.BOARD}"
|
||||||
|
for threadID of hiddenThreads2 when !(threadID of ThreadHiding.hiddenThreads)
|
||||||
|
ThreadHiding.db.set
|
||||||
|
boardID: g.BOARD.ID
|
||||||
|
threadID: threadID
|
||||||
|
val: {makeStub: Conf['Stubs']}
|
||||||
|
for threadID of ThreadHiding.hiddenThreads when !(threadID of hiddenThreads2)
|
||||||
|
ThreadHiding.db.delete
|
||||||
|
boardID: g.BOARD.ID
|
||||||
|
threadID: threadID
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
if data = ThreadHiding.db.get {boardID: @board.ID, threadID: @ID}
|
if data = ThreadHiding.db.get {boardID: @board.ID, threadID: @ID}
|
||||||
ThreadHiding.hide @, data.makeStub
|
ThreadHiding.hide @, data.makeStub
|
||||||
@ -21,47 +44,6 @@ ThreadHiding =
|
|||||||
ThreadHiding.makeStub thread, root
|
ThreadHiding.makeStub thread, root
|
||||||
return
|
return
|
||||||
|
|
||||||
syncCatalog: ->
|
|
||||||
# Sync hidden threads from the catalog into the index.
|
|
||||||
hiddenThreads = ThreadHiding.db.get
|
|
||||||
boardID: g.BOARD.ID
|
|
||||||
defaultValue: {}
|
|
||||||
hiddenThreadsOnCatalog = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
|
|
||||||
|
|
||||||
# Add threads that were hidden in the catalog.
|
|
||||||
for threadID of hiddenThreadsOnCatalog
|
|
||||||
unless threadID of hiddenThreads
|
|
||||||
hiddenThreads[threadID] = {}
|
|
||||||
|
|
||||||
# Remove threads that were un-hidden in the catalog.
|
|
||||||
for threadID of hiddenThreads
|
|
||||||
unless threadID of hiddenThreadsOnCatalog
|
|
||||||
delete hiddenThreads[threadID]
|
|
||||||
|
|
||||||
if (ThreadHiding.db.data.lastChecked or 0) > Date.now() - $.MINUTE
|
|
||||||
# Was cleaned just now.
|
|
||||||
ThreadHiding.cleanCatalog hiddenThreadsOnCatalog
|
|
||||||
|
|
||||||
ThreadHiding.db.set
|
|
||||||
boardID: g.BOARD.ID
|
|
||||||
val: hiddenThreads
|
|
||||||
|
|
||||||
cleanCatalog: (hiddenThreadsOnCatalog) ->
|
|
||||||
# We need to clean hidden threads on the catalog ourselves,
|
|
||||||
# otherwise if we don't visit the catalog regularly
|
|
||||||
# it will pollute the localStorage and our data.
|
|
||||||
$.cache "//a.4cdn.org/#{g.BOARD}/threads.json", ->
|
|
||||||
return unless @status is 200
|
|
||||||
threads = {}
|
|
||||||
for page in @response
|
|
||||||
for thread in page.threads
|
|
||||||
if thread.no of hiddenThreadsOnCatalog
|
|
||||||
threads[thread.no] = hiddenThreadsOnCatalog[thread.no]
|
|
||||||
if Object.keys(threads).length
|
|
||||||
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify threads
|
|
||||||
else
|
|
||||||
localStorage.removeItem "4chan-hide-t-#{g.BOARD}"
|
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding Link']
|
return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding Link']
|
||||||
@ -163,19 +145,15 @@ ThreadHiding =
|
|||||||
$.prepend root, thread.stub
|
$.prepend root, thread.stub
|
||||||
|
|
||||||
saveHiddenState: (thread, makeStub) ->
|
saveHiddenState: (thread, makeStub) ->
|
||||||
hiddenThreadsOnCatalog = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
|
|
||||||
if thread.isHidden
|
if thread.isHidden
|
||||||
ThreadHiding.db.set
|
ThreadHiding.db.set
|
||||||
boardID: thread.board.ID
|
boardID: thread.board.ID
|
||||||
threadID: thread.ID
|
threadID: thread.ID
|
||||||
val: {makeStub}
|
val: {makeStub}
|
||||||
hiddenThreadsOnCatalog[thread] = true
|
|
||||||
else
|
else
|
||||||
ThreadHiding.db.delete
|
ThreadHiding.db.delete
|
||||||
boardID: thread.board.ID
|
boardID: thread.board.ID
|
||||||
threadID: thread.ID
|
threadID: thread.ID
|
||||||
delete hiddenThreadsOnCatalog[thread]
|
|
||||||
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify hiddenThreadsOnCatalog
|
|
||||||
|
|
||||||
toggle: (thread) ->
|
toggle: (thread) ->
|
||||||
unless thread instanceof Thread
|
unless thread instanceof Thread
|
||||||
|
|||||||
@ -123,10 +123,7 @@ Settings =
|
|||||||
button.textContent = "Hidden: #{hiddenNum}"
|
button.textContent = "Hidden: #{hiddenNum}"
|
||||||
$.on button, 'click', ->
|
$.on button, 'click', ->
|
||||||
@textContent = 'Hidden: 0'
|
@textContent = 'Hidden: 0'
|
||||||
$.get 'hiddenThreads', {}, ({hiddenThreads}) ->
|
$.delete ['hiddenThreads', 'hiddenPosts']
|
||||||
for boardID of hiddenThreads.boards
|
|
||||||
localStorage.removeItem "4chan-hide-t-#{boardID}"
|
|
||||||
$.delete ['hiddenThreads', 'hiddenPosts']
|
|
||||||
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div
|
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div
|
||||||
export: ->
|
export: ->
|
||||||
# Make sure to export the most recent data.
|
# Make sure to export the most recent data.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user