Better approach to catalog sync.
- 4chan X pushes everything - catalog pushes only changes
This commit is contained in:
parent
661033c948
commit
fb30a59fe7
@ -3,22 +3,20 @@ ThreadHiding =
|
|||||||
return if g.VIEW is 'thread' 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'
|
||||||
return @catalogWatch() if g.VIEW is 'catalog'
|
return @catalogWatch() if g.VIEW is 'catalog'
|
||||||
@cleanCatalog()
|
@catalogSet g.BOARD
|
||||||
Thread.callbacks.push
|
Thread.callbacks.push
|
||||||
name: 'Thread Hiding'
|
name: 'Thread Hiding'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
getCatalogHidden: ->
|
catalogSet: (board) ->
|
||||||
JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
|
hiddenThreads = ThreadHiding.db.get
|
||||||
|
boardID: board.ID
|
||||||
setCatalogHidden: (threads) ->
|
defaultValue: {}
|
||||||
if Object.keys(threads).length
|
hiddenThreads[threadID] = true for threadID of hiddenThreads
|
||||||
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify threads
|
localStorage.setItem "4chan-hide-t-#{board}", JSON.stringify hiddenThreads
|
||||||
else
|
|
||||||
localStorage.removeItem "4chan-hide-t-#{g.BOARD}"
|
|
||||||
|
|
||||||
catalogWatch: ->
|
catalogWatch: ->
|
||||||
@hiddenThreads = ThreadHiding.getCatalogHidden()
|
@hiddenThreads = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
|
||||||
$.ready ->
|
$.ready ->
|
||||||
# 4chan's catalog sets the style to "display: none;" when hiding or unhiding a thread.
|
# 4chan's catalog sets the style to "display: none;" when hiding or unhiding a thread.
|
||||||
new MutationObserver(ThreadHiding.catalogSave).observe $.id('threads'),
|
new MutationObserver(ThreadHiding.catalogSave).observe $.id('threads'),
|
||||||
@ -27,7 +25,7 @@ ThreadHiding =
|
|||||||
attributeFilter: ['style']
|
attributeFilter: ['style']
|
||||||
|
|
||||||
catalogSave: ->
|
catalogSave: ->
|
||||||
hiddenThreads2 = ThreadHiding.getCatalogHidden()
|
hiddenThreads2 = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
|
||||||
for threadID of hiddenThreads2 when !(threadID of ThreadHiding.hiddenThreads)
|
for threadID of hiddenThreads2 when !(threadID of ThreadHiding.hiddenThreads)
|
||||||
ThreadHiding.db.set
|
ThreadHiding.db.set
|
||||||
boardID: g.BOARD.ID
|
boardID: g.BOARD.ID
|
||||||
@ -52,24 +50,6 @@ ThreadHiding =
|
|||||||
ThreadHiding.makeStub thread, root
|
ThreadHiding.makeStub thread, root
|
||||||
return
|
return
|
||||||
|
|
||||||
cleanCatalog: ->
|
|
||||||
# We need to clean hidden threads on the catalog ourselves,
|
|
||||||
# otherwise if we don't visit the catalog regularly
|
|
||||||
# it will pollute the localStorage.
|
|
||||||
|
|
||||||
# Only clean the catalog if our own hidden threads list was just cleaned.
|
|
||||||
return unless (ThreadHiding.db.data.lastChecked or 0) > Date.now() - $.MINUTE
|
|
||||||
|
|
||||||
$.cache "//a.4cdn.org/#{g.BOARD}/threads.json", ->
|
|
||||||
return unless @status is 200
|
|
||||||
hiddenThreadsOnCatalog = ThreadHiding.getCatalogHidden()
|
|
||||||
threads = {}
|
|
||||||
for page in @response
|
|
||||||
for thread in page.threads
|
|
||||||
if thread.no of hiddenThreadsOnCatalog
|
|
||||||
threads[thread.no] = hiddenThreadsOnCatalog[thread.no]
|
|
||||||
ThreadHiding.setCatalogHidden threads
|
|
||||||
|
|
||||||
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']
|
||||||
@ -171,19 +151,16 @@ ThreadHiding =
|
|||||||
$.prepend root, thread.stub
|
$.prepend root, thread.stub
|
||||||
|
|
||||||
saveHiddenState: (thread, makeStub) ->
|
saveHiddenState: (thread, makeStub) ->
|
||||||
hiddenThreadsOnCatalog = ThreadHiding.getCatalogHidden()
|
|
||||||
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]
|
ThreadHiding.catalogSet thread.board
|
||||||
ThreadHiding.setCatalogHidden hiddenThreadsOnCatalog
|
|
||||||
|
|
||||||
toggle: (thread) ->
|
toggle: (thread) ->
|
||||||
unless thread instanceof Thread
|
unless thread instanceof Thread
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user