diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index d6a3c7c52..35be7a6bf 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -25,7 +25,6 @@ ThreadWatcher = $.on @closeButton, 'click', @toggleWatcher $.onExists doc, 'body', @addDialog - $.on d, '4chanXInitFinished', @ready switch g.VIEW when 'index' @@ -85,8 +84,14 @@ ThreadWatcher = href: 'javascript:;' className: 'watch-thread-link' $.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 + # 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: -> $.addClass @nodes.root, 'watched' if ThreadWatcher.isWatched @thread @@ -103,14 +108,6 @@ ThreadWatcher = ThreadWatcher.build() $.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: -> $.toggleClass ThreadWatcher.shortcut, 'disabled' ThreadWatcher.dialog.hidden = !ThreadWatcher.dialog.hidden @@ -140,7 +137,7 @@ ThreadWatcher = {boardID, threadID, postID} = e.detail if postID is threadID if Conf['Auto Watch'] - $.set 'AutoWatch', threadID + ThreadWatcher.addRaw boardID, threadID, {} else if Conf['Auto Watch Reply'] ThreadWatcher.add g.threads[boardID + '.' + threadID] onIndexRefresh: -> @@ -294,9 +291,12 @@ ThreadWatcher = href: 'javascript:;' $.on x, 'click', ThreadWatcher.cb.rm + {excerpt} = data + excerpt or= "/#{boardID}/ - No.#{threadID}" + link = $.el 'a', href: "/#{boardID}/thread/#{threadID}" - title: data.excerpt + title: excerpt className: 'watcher-link' if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] and data.unread? @@ -306,7 +306,7 @@ ThreadWatcher = $.add link, count title = $.el 'span', - textContent: data.excerpt + textContent: excerpt className: 'watcher-title' $.add link, title @@ -325,6 +325,9 @@ ThreadWatcher = build: -> nodes = [] 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 {list} = ThreadWatcher $.rmAll list @@ -403,6 +406,9 @@ ThreadWatcher = return data.isDead = true data.excerpt = Get.threadExcerpt thread + ThreadWatcher.addRaw boardID, threadID, data + + addRaw: (boardID, threadID, data) -> ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.refresh() if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] diff --git a/src/classes/DataBoard.coffee b/src/classes/DataBoard.coffee index d810a3071..12fa9e873 100644 --- a/src/classes/DataBoard.coffee +++ b/src/classes/DataBoard.coffee @@ -38,8 +38,11 @@ class DataBoard else unless Object.keys(@data.boards[boardID]).length delete @data.boards[boardID] - set: ({boardID, threadID, postID, val}, cb) -> + set: (data, cb) -> $.forceSync @key + @setUnsafe data, cb + + setUnsafe: ({boardID, threadID, postID, val}, cb) -> if postID isnt undefined ((@data.boards[boardID] or= {})[threadID] or= {})[postID] = val else if threadID isnt undefined @@ -48,6 +51,12 @@ class DataBoard @data.boards[boardID] = val @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}) -> if board = @data.boards[boardID] unless threadID? diff --git a/src/platform/$.coffee b/src/platform/$.coffee index edfb70fec..7fe4d46da 100644 --- a/src/platform/$.coffee +++ b/src/platform/$.coffee @@ -582,7 +582,7 @@ $.clear = (cb) -> # XXX https://github.com/greasemonkey/greasemonkey/issues/2033 # Also support case where GM_listValues is not defined. $.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']) try $.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''