diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 1421ff806..4f422357e 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -170,9 +170,9 @@ Config = 'Eqn tags': ['Alt+e', 'Insert eqn tags.'] 'Math tags': ['Alt+m', 'Insert math tags.'] 'Submit QR': ['Alt+s', 'Submit post.'] - # Thread related + # Index/Thread related + 'Update': ['r', 'Refresh the index/thread.'] 'Watch': ['w', 'Watch thread.'] - 'Update': ['r', 'Update the thread.'] # Images 'Expand image': ['Shift+e', 'Expand selected image.'] 'Expand images': ['e', 'Expand all images.'] diff --git a/src/General/Header.coffee b/src/General/Header.coffee index e16001638..7eb6e06fe 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -246,8 +246,8 @@ Header = hashScroll: -> return unless (hash = @location.hash[1..]) and post = $.id hash return if (Get.postFromRoot post).isHidden - Header.scrollToPost post - scrollToPost: (post) -> + Header.scrollTo post + scrollTo: (post) -> {top} = post.getBoundingClientRect() unless Conf['Bottom header'] headRect = Header.toggle.getBoundingClientRect() @@ -268,8 +268,8 @@ Header = createNotification: (e) -> {type, content, lifetime, cb} = e.detail - notif = new Notice type, content, lifetime - cb notif if cb + notice = new Notice type, content, lifetime + cb notice if cb areNotificationsEnabled: false enableDesktopNotifications: -> diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 9410365c0..2829eb208 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -69,6 +69,7 @@ Main = initFeature 'Polyfill', Polyfill initFeature 'Header', Header initFeature 'Settings', Settings + initFeature 'Index Pager', Index initFeature 'Announcement Hiding', PSAHiding initFeature 'Fourchan thingies', Fourchan initFeature 'Custom CSS', CustomCSS diff --git a/src/Miscellaneous/Index.coffee b/src/Miscellaneous/Index.coffee new file mode 100644 index 000000000..06aa5b329 --- /dev/null +++ b/src/Miscellaneous/Index.coffee @@ -0,0 +1,41 @@ +Index = + init: -> + return if g.VIEW isnt 'index' + + update: -> + # return unless navigator.onLine + Index.req?.abort() + Index.notice?.close() + Index.notice = new Notice 'info', 'Refreshing index...' + Index.req = $.ajax "//api.4chan.org/#{g.BOARD}/catalog.json", + onabort: Index.load + onloadend: Index.load + , + whenModified: true + load: (e) -> + {req, notice} = Index + delete Index.req + delete Index.notice + + if e.type is 'abort' + req.onloadend = null + notice.close() + return + + try + Index.parse JSON.parse req.response + catch e + # network error or non-JSON content for example. + notice.setType 'error' + notice.el.lastElementChild.textContent = 'Index refresh failed.' + setTimeout notice.close, 2 * $.SECOND + return + + notice.setType 'success' + notice.el.lastElementChild.textContent = 'Index refreshed!' + setTimeout notice.close, $.SECOND + + Header.scrollTo $.id 'delform' + parse: (pages) -> + pageNum = +window.location.pathname.split('/')[2] + threads = pages[pageNum].threads diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index a06a6043b..31a237e9c 100644 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -58,11 +58,15 @@ Keybinds = Keybinds.tags 'math', target when Conf['Submit QR'] QR.submit() if QR.nodes and !QR.status() - # Thread related + # Index/Thread related + when Conf['Update'] + switch g.VIEW + when 'thread' + ThreadUpdater.update() + when 'index' + Index.update() when Conf['Watch'] ThreadWatcher.toggle thread - when Conf['Update'] - ThreadUpdater.update() # Images when Conf['Expand image'] Keybinds.img threadRoot diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 677db825d..03c8b5053 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -145,7 +145,7 @@ ThreadUpdater = return unless navigator.onLine ThreadUpdater.count() ThreadUpdater.set 'timer', '...' - ThreadUpdater.req.abort() if ThreadUpdater.req + ThreadUpdater.req?.abort() url = "//api.4chan.org/#{ThreadUpdater.thread.board}/res/#{ThreadUpdater.thread}.json" ThreadUpdater.req = $.ajax url, onabort: ThreadUpdater.cb.load @@ -258,7 +258,7 @@ ThreadUpdater = if Conf['Bottom Scroll'] window.scrollTo 0, d.body.clientHeight else - Header.scrollToPost nodes[0] + Header.scrollTo nodes[0] # Enable 4chan features. threadID = ThreadUpdater.thread.ID diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index fc7e2940e..2898c6c69 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -47,7 +47,7 @@ Unread = # Scroll to the last read post. posts = Object.keys Unread.thread.posts {root} = Unread.thread.posts[posts[posts.length - 1]].nodes - onload = -> Header.scrollToPost root if checkPosition root + onload = -> Header.scrollTo root if checkPosition root checkPosition = (target) -> # Scroll to the target unless we scrolled past it. target.getBoundingClientRect().bottom > doc.clientHeight @@ -102,7 +102,7 @@ Unread = body: post.info.comment icon: Favicon.logo notif.onclick = -> - Header.scrollToPost post.nodes.root + Header.scrollTo post.nodes.root window.focus() notif.onshow = -> setTimeout ->