Remove needless wather refreshing / index sorting, make watcher load without waiting for whole page. #685
This commit is contained in:
parent
c91ac0ba89
commit
b69dad7fea
@ -24,6 +24,7 @@ ThreadWatcher =
|
|||||||
$.on @refreshButton, 'click', @buttonFetchAll
|
$.on @refreshButton, 'click', @buttonFetchAll
|
||||||
$.on @closeButton, 'click', @toggleWatcher
|
$.on @closeButton, 'click', @toggleWatcher
|
||||||
|
|
||||||
|
$.onExists doc, 'body', @addDialog
|
||||||
$.on d, '4chanXInitFinished', @ready
|
$.on d, '4chanXInitFinished', @ready
|
||||||
|
|
||||||
switch g.VIEW
|
switch g.VIEW
|
||||||
@ -69,7 +70,11 @@ ThreadWatcher =
|
|||||||
cb: @catalogNode
|
cb: @catalogNode
|
||||||
|
|
||||||
isWatched: (thread) ->
|
isWatched: (thread) ->
|
||||||
ThreadWatcher.db?.get {boardID: thread.board.ID, threadID: thread.ID}
|
!!ThreadWatcher.db?.get {boardID: thread.board.ID, threadID: thread.ID}
|
||||||
|
|
||||||
|
setToggler: (toggler, isWatched) ->
|
||||||
|
toggler.classList.toggle 'watched', isWatched
|
||||||
|
toggler.title = "#{if isWatched then 'Unwatch' else 'Watch'} Thread"
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
return if @isReply
|
return if @isReply
|
||||||
@ -80,6 +85,7 @@ ThreadWatcher =
|
|||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
className: 'watch-thread-link'
|
className: 'watch-thread-link'
|
||||||
$.before $('input', @nodes.post), toggler
|
$.before $('input', @nodes.post), toggler
|
||||||
|
ThreadWatcher.setToggler toggler, ThreadWatcher.isWatched(@thread)
|
||||||
$.on toggler, 'click', ThreadWatcher.cb.toggle
|
$.on toggler, 'click', ThreadWatcher.cb.toggle
|
||||||
|
|
||||||
catalogNode: ->
|
catalogNode: ->
|
||||||
@ -92,13 +98,14 @@ ThreadWatcher =
|
|||||||
# Prevent highlighting thumbnail in Firefox.
|
# Prevent highlighting thumbnail in Firefox.
|
||||||
e.preventDefault() if e.button is 0 and e.altKey
|
e.preventDefault() if e.button is 0 and e.altKey
|
||||||
|
|
||||||
|
addDialog: ->
|
||||||
|
return unless Main.isThisPageLegit()
|
||||||
|
ThreadWatcher.build()
|
||||||
|
$.add Header.hover, ThreadWatcher.dialog
|
||||||
|
|
||||||
ready: ->
|
ready: ->
|
||||||
$.off d, '4chanXInitFinished', ThreadWatcher.ready
|
$.off d, '4chanXInitFinished', ThreadWatcher.ready
|
||||||
return unless Main.isThisPageLegit()
|
return unless Main.isThisPageLegit() and Conf['Auto Watch']
|
||||||
ThreadWatcher.refresh()
|
|
||||||
$.add d.body, ThreadWatcher.dialog
|
|
||||||
|
|
||||||
return unless Conf['Auto Watch']
|
|
||||||
$.get 'AutoWatch', 0, ({AutoWatch}) ->
|
$.get 'AutoWatch', 0, ({AutoWatch}) ->
|
||||||
return unless thread = g.BOARD.threads[AutoWatch]
|
return unless thread = g.BOARD.threads[AutoWatch]
|
||||||
ThreadWatcher.add thread
|
ThreadWatcher.add thread
|
||||||
@ -140,7 +147,9 @@ ThreadWatcher =
|
|||||||
{db} = ThreadWatcher
|
{db} = ThreadWatcher
|
||||||
boardID = g.BOARD.ID
|
boardID = g.BOARD.ID
|
||||||
db.forceSync()
|
db.forceSync()
|
||||||
|
nKilled = 0
|
||||||
for threadID, data of db.data.boards[boardID] when not data?.isDead and threadID not of g.BOARD.threads
|
for threadID, data of db.data.boards[boardID] when not data?.isDead and threadID not of g.BOARD.threads
|
||||||
|
nKilled++
|
||||||
if Conf['Auto Prune'] or not (data and typeof data is 'object') # corrupt data
|
if Conf['Auto Prune'] or not (data and typeof data is 'object') # corrupt data
|
||||||
db.delete {boardID, threadID}
|
db.delete {boardID, threadID}
|
||||||
else
|
else
|
||||||
@ -148,7 +157,7 @@ ThreadWatcher =
|
|||||||
ThreadWatcher.fetchStatus {boardID, threadID, data}
|
ThreadWatcher.fetchStatus {boardID, threadID, data}
|
||||||
data.isDead = true
|
data.isDead = true
|
||||||
db.set {boardID, threadID, val: data}
|
db.set {boardID, threadID, val: data}
|
||||||
ThreadWatcher.refresh()
|
ThreadWatcher.refresh() if nKilled
|
||||||
onThreadRefresh: (e) ->
|
onThreadRefresh: (e) ->
|
||||||
thread = g.threads[e.detail.threadID]
|
thread = g.threads[e.detail.threadID]
|
||||||
return unless e.detail[404] and ThreadWatcher.db.get {boardID: thread.board.ID, threadID: thread.ID}
|
return unless e.detail[404] and ThreadWatcher.db.get {boardID: thread.board.ID, threadID: thread.ID}
|
||||||
@ -313,28 +322,29 @@ ThreadWatcher =
|
|||||||
$.add div, [x, $.tn(' '), link]
|
$.add div, [x, $.tn(' '), link]
|
||||||
div
|
div
|
||||||
|
|
||||||
refresh: ->
|
build: ->
|
||||||
nodes = []
|
nodes = []
|
||||||
for {boardID, threadID, data} in ThreadWatcher.getAll()
|
for {boardID, threadID, data} in ThreadWatcher.getAll()
|
||||||
nodes.push ThreadWatcher.makeLine boardID, threadID, data
|
nodes.push ThreadWatcher.makeLine boardID, threadID, data
|
||||||
|
|
||||||
{list} = ThreadWatcher
|
{list} = ThreadWatcher
|
||||||
$.rmAll list
|
$.rmAll list
|
||||||
$.add list, nodes
|
$.add list, nodes
|
||||||
|
|
||||||
|
ThreadWatcher.refreshIcon()
|
||||||
|
for refresher in ThreadWatcher.menu.refreshers
|
||||||
|
refresher()
|
||||||
|
return
|
||||||
|
|
||||||
|
refresh: ->
|
||||||
|
ThreadWatcher.build()
|
||||||
|
|
||||||
g.threads.forEach (thread) ->
|
g.threads.forEach (thread) ->
|
||||||
helper = if ThreadWatcher.isWatched thread then ['addClass', 'Unwatch'] else ['rmClass', 'Watch']
|
isWatched = ThreadWatcher.isWatched thread
|
||||||
if thread.OP
|
if thread.OP
|
||||||
for post in [thread.OP, thread.OP.clones...]
|
for post in [thread.OP, thread.OP.clones...]
|
||||||
toggler = $ '.watch-thread-link', post.nodes.post
|
toggler = $ '.watch-thread-link', post.nodes.post
|
||||||
$[helper[0]] toggler, 'watched'
|
ThreadWatcher.setToggler toggler, isWatched
|
||||||
toggler.title = "#{helper[1]} Thread"
|
thread.catalogView.nodes.root.classList.toggle 'watched', isWatched if thread.catalogView
|
||||||
$[helper[0]] thread.catalogView.nodes.root, 'watched' if thread.catalogView
|
|
||||||
|
|
||||||
ThreadWatcher.refreshIcon()
|
|
||||||
|
|
||||||
for refresher in ThreadWatcher.menu.refreshers
|
|
||||||
refresher()
|
|
||||||
|
|
||||||
if Conf['Pin Watched Threads']
|
if Conf['Pin Watched Threads']
|
||||||
$.event 'SortIndex', {deferred: Conf['Index Mode'] isnt 'catalog'}
|
$.event 'SortIndex', {deferred: Conf['Index Mode'] isnt 'catalog'}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user