Better Auto Watch.
This commit is contained in:
parent
b69dad7fea
commit
517fa1c4b6
@ -25,7 +25,6 @@ ThreadWatcher =
|
|||||||
$.on @closeButton, 'click', @toggleWatcher
|
$.on @closeButton, 'click', @toggleWatcher
|
||||||
|
|
||||||
$.onExists doc, 'body', @addDialog
|
$.onExists doc, 'body', @addDialog
|
||||||
$.on d, '4chanXInitFinished', @ready
|
|
||||||
|
|
||||||
switch g.VIEW
|
switch g.VIEW
|
||||||
when 'index'
|
when 'index'
|
||||||
@ -85,8 +84,14 @@ 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)
|
boardID = @board.ID
|
||||||
|
threadID = @thread.ID
|
||||||
|
data = ThreadWatcher.db.get {boardID, threadID}
|
||||||
|
ThreadWatcher.setToggler toggler, !!data
|
||||||
$.on toggler, 'click', ThreadWatcher.cb.toggle
|
$.on toggler, 'click', ThreadWatcher.cb.toggle
|
||||||
|
# Add missing excerpt for threads added by Auto Watch
|
||||||
|
if data and not data.excerpt?
|
||||||
|
ThreadWatcher.db.extend {boardID, threadID, val: {excerpt: Get.threadExcerpt @thread}}
|
||||||
|
|
||||||
catalogNode: ->
|
catalogNode: ->
|
||||||
$.addClass @nodes.root, 'watched' if ThreadWatcher.isWatched @thread
|
$.addClass @nodes.root, 'watched' if ThreadWatcher.isWatched @thread
|
||||||
@ -103,14 +108,6 @@ ThreadWatcher =
|
|||||||
ThreadWatcher.build()
|
ThreadWatcher.build()
|
||||||
$.add Header.hover, ThreadWatcher.dialog
|
$.add Header.hover, ThreadWatcher.dialog
|
||||||
|
|
||||||
ready: ->
|
|
||||||
$.off d, '4chanXInitFinished', ThreadWatcher.ready
|
|
||||||
return unless Main.isThisPageLegit() and Conf['Auto Watch']
|
|
||||||
$.get 'AutoWatch', 0, ({AutoWatch}) ->
|
|
||||||
return unless thread = g.BOARD.threads[AutoWatch]
|
|
||||||
ThreadWatcher.add thread
|
|
||||||
$.delete 'AutoWatch'
|
|
||||||
|
|
||||||
toggleWatcher: ->
|
toggleWatcher: ->
|
||||||
$.toggleClass ThreadWatcher.shortcut, 'disabled'
|
$.toggleClass ThreadWatcher.shortcut, 'disabled'
|
||||||
ThreadWatcher.dialog.hidden = !ThreadWatcher.dialog.hidden
|
ThreadWatcher.dialog.hidden = !ThreadWatcher.dialog.hidden
|
||||||
@ -140,7 +137,7 @@ ThreadWatcher =
|
|||||||
{boardID, threadID, postID} = e.detail
|
{boardID, threadID, postID} = e.detail
|
||||||
if postID is threadID
|
if postID is threadID
|
||||||
if Conf['Auto Watch']
|
if Conf['Auto Watch']
|
||||||
$.set 'AutoWatch', threadID
|
ThreadWatcher.addRaw boardID, threadID, {}
|
||||||
else if Conf['Auto Watch Reply']
|
else if Conf['Auto Watch Reply']
|
||||||
ThreadWatcher.add g.threads[boardID + '.' + threadID]
|
ThreadWatcher.add g.threads[boardID + '.' + threadID]
|
||||||
onIndexRefresh: ->
|
onIndexRefresh: ->
|
||||||
@ -294,9 +291,12 @@ ThreadWatcher =
|
|||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
$.on x, 'click', ThreadWatcher.cb.rm
|
$.on x, 'click', ThreadWatcher.cb.rm
|
||||||
|
|
||||||
|
{excerpt} = data
|
||||||
|
excerpt or= "/#{boardID}/ - No.#{threadID}"
|
||||||
|
|
||||||
link = $.el 'a',
|
link = $.el 'a',
|
||||||
href: "/#{boardID}/thread/#{threadID}"
|
href: "/#{boardID}/thread/#{threadID}"
|
||||||
title: data.excerpt
|
title: excerpt
|
||||||
className: 'watcher-link'
|
className: 'watcher-link'
|
||||||
|
|
||||||
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] and data.unread?
|
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] and data.unread?
|
||||||
@ -306,7 +306,7 @@ ThreadWatcher =
|
|||||||
$.add link, count
|
$.add link, count
|
||||||
|
|
||||||
title = $.el 'span',
|
title = $.el 'span',
|
||||||
textContent: data.excerpt
|
textContent: excerpt
|
||||||
className: 'watcher-title'
|
className: 'watcher-title'
|
||||||
$.add link, title
|
$.add link, title
|
||||||
|
|
||||||
@ -325,6 +325,9 @@ ThreadWatcher =
|
|||||||
build: ->
|
build: ->
|
||||||
nodes = []
|
nodes = []
|
||||||
for {boardID, threadID, data} in ThreadWatcher.getAll()
|
for {boardID, threadID, data} in ThreadWatcher.getAll()
|
||||||
|
# Add missing excerpt for threads added by Auto Watch
|
||||||
|
if not data.excerpt? and (thread = g.threads["#{boardID}.#{threadID}"])
|
||||||
|
ThreadWatcher.db.extend {boardID, threadID, val: {excerpt: Get.threadExcerpt thread}}
|
||||||
nodes.push ThreadWatcher.makeLine boardID, threadID, data
|
nodes.push ThreadWatcher.makeLine boardID, threadID, data
|
||||||
{list} = ThreadWatcher
|
{list} = ThreadWatcher
|
||||||
$.rmAll list
|
$.rmAll list
|
||||||
@ -403,6 +406,9 @@ ThreadWatcher =
|
|||||||
return
|
return
|
||||||
data.isDead = true
|
data.isDead = true
|
||||||
data.excerpt = Get.threadExcerpt thread
|
data.excerpt = Get.threadExcerpt thread
|
||||||
|
ThreadWatcher.addRaw boardID, threadID, data
|
||||||
|
|
||||||
|
addRaw: (boardID, threadID, data) ->
|
||||||
ThreadWatcher.db.set {boardID, threadID, val: data}
|
ThreadWatcher.db.set {boardID, threadID, val: data}
|
||||||
ThreadWatcher.refresh()
|
ThreadWatcher.refresh()
|
||||||
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
|
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
|
||||||
|
|||||||
@ -38,8 +38,11 @@ class DataBoard
|
|||||||
else unless Object.keys(@data.boards[boardID]).length
|
else unless Object.keys(@data.boards[boardID]).length
|
||||||
delete @data.boards[boardID]
|
delete @data.boards[boardID]
|
||||||
|
|
||||||
set: ({boardID, threadID, postID, val}, cb) ->
|
set: (data, cb) ->
|
||||||
$.forceSync @key
|
$.forceSync @key
|
||||||
|
@setUnsafe data, cb
|
||||||
|
|
||||||
|
setUnsafe: ({boardID, threadID, postID, val}, cb) ->
|
||||||
if postID isnt undefined
|
if postID isnt undefined
|
||||||
((@data.boards[boardID] or= {})[threadID] or= {})[postID] = val
|
((@data.boards[boardID] or= {})[threadID] or= {})[postID] = val
|
||||||
else if threadID isnt undefined
|
else if threadID isnt undefined
|
||||||
@ -48,6 +51,12 @@ class DataBoard
|
|||||||
@data.boards[boardID] = val
|
@data.boards[boardID] = val
|
||||||
@save cb
|
@save cb
|
||||||
|
|
||||||
|
extend: ({boardID, threadID, postID, val}, cb) ->
|
||||||
|
$.forceSync @key
|
||||||
|
oldVal = @get {boardID, threadID, postID, val: {}}
|
||||||
|
$.extend oldVal, val
|
||||||
|
@setUnsafe {boardID, threadID, postID, val: oldVal}, cb
|
||||||
|
|
||||||
get: ({boardID, threadID, postID, defaultValue}) ->
|
get: ({boardID, threadID, postID, defaultValue}) ->
|
||||||
if board = @data.boards[boardID]
|
if board = @data.boards[boardID]
|
||||||
unless threadID?
|
unless threadID?
|
||||||
|
|||||||
@ -582,7 +582,7 @@ $.clear = (cb) ->
|
|||||||
# XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
# XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
||||||
# Also support case where GM_listValues is not defined.
|
# Also support case where GM_listValues is not defined.
|
||||||
$.delete Object.keys(Conf)
|
$.delete Object.keys(Conf)
|
||||||
$.delete ['previousversion', 'AutoWatch', 'QR Size', 'captchas', 'QR.persona', 'hiddenPSA']
|
$.delete ['previousversion', 'QR Size', 'captchas', 'QR.persona', 'hiddenPSA']
|
||||||
$.delete ("#{id}.position" for id in ['embedding', 'updater', 'thread-stats', 'thread-watcher', 'qr'])
|
$.delete ("#{id}.position" for id in ['embedding', 'updater', 'thread-stats', 'thread-watcher', 'qr'])
|
||||||
try
|
try
|
||||||
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user