Add 'Remember Last Read Post' option. #622
This commit is contained in:
parent
eda4a5145d
commit
28597d6a2c
@ -355,9 +355,14 @@ Config =
|
|||||||
true
|
true
|
||||||
'Show a line to distinguish read posts from unread ones.'
|
'Show a line to distinguish read posts from unread ones.'
|
||||||
]
|
]
|
||||||
|
'Remember Last Read Post': [
|
||||||
|
true
|
||||||
|
'Remember how far you\'ve read after you close the thread.'
|
||||||
|
]
|
||||||
'Scroll to Last Read Post': [
|
'Scroll to Last Read Post': [
|
||||||
true
|
true
|
||||||
'Scroll back to the last read post when reopening a thread.'
|
'Scroll back to the last read post when reopening a thread.'
|
||||||
|
1
|
||||||
]
|
]
|
||||||
'Thread Excerpt': [
|
'Thread Excerpt': [
|
||||||
true
|
true
|
||||||
|
|||||||
@ -145,7 +145,7 @@ ThreadWatcher =
|
|||||||
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
|
||||||
if Conf['Show Unread Count']
|
if Conf['Remember Last Read Post'] and Conf['Show Unread Count']
|
||||||
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}
|
||||||
@ -174,7 +174,7 @@ ThreadWatcher =
|
|||||||
clearTimeout ThreadWatcher.timeout
|
clearTimeout ThreadWatcher.timeout
|
||||||
return unless Conf['Auto Update Thread Watcher']
|
return unless Conf['Auto Update Thread Watcher']
|
||||||
{db} = ThreadWatcher
|
{db} = ThreadWatcher
|
||||||
interval = if Conf['Show Unread Count'] then 5 * $.MINUTE else 2 * $.HOUR
|
interval = if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] then 5 * $.MINUTE else 2 * $.HOUR
|
||||||
now = Date.now()
|
now = Date.now()
|
||||||
if now >= (db.data.lastChecked or 0) + interval
|
if now >= (db.data.lastChecked or 0) + interval
|
||||||
db.data.lastChecked = now
|
db.data.lastChecked = now
|
||||||
@ -291,7 +291,7 @@ ThreadWatcher =
|
|||||||
title: data.excerpt
|
title: data.excerpt
|
||||||
className: 'watcher-link'
|
className: 'watcher-link'
|
||||||
|
|
||||||
if Conf['Show Unread Count'] and data.unread?
|
if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] and data.unread?
|
||||||
count = $.el 'span',
|
count = $.el 'span',
|
||||||
textContent: "(#{data.unread})"
|
textContent: "(#{data.unread})"
|
||||||
className: 'watcher-unread'
|
className: 'watcher-unread'
|
||||||
@ -307,7 +307,7 @@ ThreadWatcher =
|
|||||||
div.dataset.fullID = fullID
|
div.dataset.fullID = fullID
|
||||||
$.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}"
|
$.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}"
|
||||||
$.addClass div, 'dead-thread' if data.isDead
|
$.addClass div, 'dead-thread' if data.isDead
|
||||||
if Conf['Show Unread Count']
|
if Conf['Remember Last Read Post'] and Conf['Show Unread Count']
|
||||||
$.addClass div, 'replies-read' if data.unread is 0
|
$.addClass div, 'replies-read' if data.unread is 0
|
||||||
$.addClass div, 'replies-unread' if data.unread
|
$.addClass div, 'replies-unread' if data.unread
|
||||||
$.addClass div, 'replies-quoting-you' if data.quotingYou
|
$.addClass div, 'replies-quoting-you' if data.quotingYou
|
||||||
@ -397,7 +397,7 @@ ThreadWatcher =
|
|||||||
data.excerpt = Get.threadExcerpt thread
|
data.excerpt = Get.threadExcerpt thread
|
||||||
ThreadWatcher.db.set {boardID, threadID, val: data}
|
ThreadWatcher.db.set {boardID, threadID, val: data}
|
||||||
ThreadWatcher.refresh()
|
ThreadWatcher.refresh()
|
||||||
if Conf['Show Unread Count']
|
if Conf['Remember Last Read Post'] and Conf['Show Unread Count']
|
||||||
ThreadWatcher.fetchStatus {boardID, threadID, data}, true
|
ThreadWatcher.fetchStatus {boardID, threadID, data}, true
|
||||||
|
|
||||||
rm: (boardID, threadID) ->
|
rm: (boardID, threadID) ->
|
||||||
@ -473,6 +473,10 @@ ThreadWatcher =
|
|||||||
el: UI.checkbox name, name.replace(' Thread Watcher', '')
|
el: UI.checkbox name, name.replace(' Thread Watcher', '')
|
||||||
entry.el.title = desc
|
entry.el.title = desc
|
||||||
input = entry.el.firstElementChild
|
input = entry.el.firstElementChild
|
||||||
|
if name is 'Show Unread Count' and not Conf['Remember Last Read Post']
|
||||||
|
input.disabled = true
|
||||||
|
$.addClass entry.el, 'disabled'
|
||||||
|
entry.el.title += '\n[Remember Last Read Post is disabled.]'
|
||||||
$.on input, 'change', $.cb.checked
|
$.on input, 'change', $.cb.checked
|
||||||
$.on input, 'change', ThreadWatcher.refresh if name in ['Current Board', 'Show Unread Count']
|
$.on input, 'change', ThreadWatcher.refresh if name in ['Current Board', 'Show Unread Count']
|
||||||
$.on input, 'change', ThreadWatcher.fetchAuto if name in ['Show Unread Count', 'Auto Update Thread Watcher']
|
$.on input, 'change', ThreadWatcher.fetchAuto if name in ['Show Unread Count', 'Auto Update Thread Watcher']
|
||||||
|
|||||||
@ -4,13 +4,14 @@ Unread =
|
|||||||
Conf['Unread Count'] or
|
Conf['Unread Count'] or
|
||||||
Conf['Unread Favicon'] or
|
Conf['Unread Favicon'] or
|
||||||
Conf['Unread Line'] or
|
Conf['Unread Line'] or
|
||||||
Conf['Scroll to Last Read Post'] or
|
Conf['Remember Last Read Post'] or
|
||||||
Conf['Thread Watcher'] or
|
|
||||||
Conf['Desktop Notifications'] or
|
Conf['Desktop Notifications'] or
|
||||||
Conf['Quote Threading']
|
Conf['Quote Threading']
|
||||||
)
|
)
|
||||||
|
|
||||||
@db = new DataBoard 'lastReadPosts', @sync
|
if Conf['Remember Last Read Post']
|
||||||
|
@db = new DataBoard 'lastReadPosts', @sync
|
||||||
|
|
||||||
@hr = $.el 'hr',
|
@hr = $.el 'hr',
|
||||||
id: 'unread-line'
|
id: 'unread-line'
|
||||||
@posts = new Set()
|
@posts = new Set()
|
||||||
@ -50,10 +51,10 @@ Unread =
|
|||||||
node: ->
|
node: ->
|
||||||
Unread.thread = @
|
Unread.thread = @
|
||||||
Unread.title = d.title
|
Unread.title = d.title
|
||||||
Unread.lastReadPost = Unread.db.get
|
Unread.lastReadPost = Unread.db?.get(
|
||||||
boardID: @board.ID
|
boardID: @board.ID
|
||||||
threadID: @ID
|
threadID: @ID
|
||||||
defaultValue: 0
|
) or 0
|
||||||
Unread.readCount = 0
|
Unread.readCount = 0
|
||||||
Unread.readCount++ for ID in @posts.keys when +ID <= Unread.lastReadPost
|
Unread.readCount++ for ID in @posts.keys when +ID <= Unread.lastReadPost
|
||||||
$.one d, '4chanXInitFinished', Unread.ready
|
$.one d, '4chanXInitFinished', Unread.ready
|
||||||
@ -63,7 +64,7 @@ Unread =
|
|||||||
Unread.setLine true
|
Unread.setLine true
|
||||||
Unread.read()
|
Unread.read()
|
||||||
Unread.update()
|
Unread.update()
|
||||||
Unread.scroll() if Conf['Scroll to Last Read Post']
|
Unread.scroll() if Conf['Remember Last Read Post'] and Conf['Scroll to Last Read Post']
|
||||||
$.on d, 'scroll visibilitychange', Unread.read
|
$.on d, 'scroll visibilitychange', Unread.read
|
||||||
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line']
|
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line']
|
||||||
|
|
||||||
@ -192,6 +193,7 @@ Unread =
|
|||||||
return
|
return
|
||||||
|
|
||||||
saveLastReadPost: $.debounce 2 * $.SECOND, ->
|
saveLastReadPost: $.debounce 2 * $.SECOND, ->
|
||||||
|
return unless Conf['Remember Last Read Post'] and Unread.db
|
||||||
postIDs = Unread.thread.posts.keys
|
postIDs = Unread.thread.posts.keys
|
||||||
for i in [Unread.readCount...postIDs.length] by 1
|
for i in [Unread.readCount...postIDs.length] by 1
|
||||||
ID = +postIDs[i]
|
ID = +postIDs[i]
|
||||||
@ -228,7 +230,7 @@ Unread =
|
|||||||
Unread.title
|
Unread.title
|
||||||
d.title = "#{titleQuotingYou}#{titleCount}#{titleDead}"
|
d.title = "#{titleQuotingYou}#{titleCount}#{titleDead}"
|
||||||
|
|
||||||
unless Unread.thread.isDead and !Unread.thread.isArchived
|
if Conf['Remember Last Read Post'] and (!Unread.thread.isDead or Unread.thread.isArchived)
|
||||||
ThreadWatcher.update Unread.thread.board.ID, Unread.thread.ID,
|
ThreadWatcher.update Unread.thread.board.ID, Unread.thread.ID,
|
||||||
isDead: Unread.thread.isDead
|
isDead: Unread.thread.isDead
|
||||||
unread: count
|
unread: count
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user