From f17f9fd441a6649bf20f50701faaddf6f9d95561 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 9 Dec 2013 11:38:32 +0100 Subject: [PATCH 1/7] Anchor hidden threads on the index. --- CHANGELOG.md | 3 +++ src/General/Config.coffee | 1 + src/General/Index.coffee | 27 ++++++++++++++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14584f327..060462cd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +- More index navigation improvements: + - New setting: `Anchor Hidden Threads`, enabled by default. Hidden threads will be moved at the end of the index to fill the first pages. + ### 3.14.3 - *2013-12-09* - Minor bug fixes. diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 086bb7262..39b025920 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -143,6 +143,7 @@ Config = 'Index Mode': 'paged' 'Index Sort': 'bump' 'Show Replies': true + 'Anchor Hidden Threads': true Header: 'Header auto-hide': false 'Header auto-hide on scroll': false diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 81c04d9bb..cae8482a7 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -38,17 +38,25 @@ Index = repliesEntry = el: $.el 'label', innerHTML: ' Show replies' - input = repliesEntry.el.firstChild - input.checked = Conf['Show Replies'] - $.on input, 'change', $.cb.checked - $.on input, 'change', @cb.replies + anchorEntry = + el: $.el 'label', innerHTML: ' Anchor hidden threads' + for label in [repliesEntry, anchorEntry] + input = label.el.firstChild + {name} = input + input.checked = Conf[name] + $.on input, 'change', $.cb.checked + switch name + when 'Show Replies' + $.on input, 'change', @cb.replies + when 'Anchor Hidden Threads' + $.on input, 'change', @cb.sort $.event 'AddMenuEntry', type: 'header' el: $.el 'span', textContent: 'Index Navigation' order: 90 - subEntries: [modeEntry, sortEntry, repliesEntry] + subEntries: [modeEntry, sortEntry, repliesEntry, anchorEntry] $.addClass doc, 'index-loading' @update() @@ -318,12 +326,17 @@ Index = Index.sortedNodes.push Index.nodes[i], Index.nodes[i + 1] if Index.isSearching Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes - # Put the sticky threads on top of the index. + # Move non-hidden threads on top of the index. + if Conf['Anchor Hidden Threads'] + offset = 0 + for threadRoot, i in Index.sortedNodes by 2 when not Get.threadFromRoot(threadRoot).isHidden + Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... + # Move sticky threads on top of the index. offset = 0 for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isSticky Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... return unless Conf['Filter'] - # Put the highlighted thread &
on top of the index + # Move highlighted threads &
on top of the index # while keeping the original order they appear in. offset = 0 for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isOnTop From ceff7c5d5fa4030e04b001a949259caafb4c3348 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 3 Dec 2013 11:36:43 +0100 Subject: [PATCH 2/7] Add Refreshed Navigation setting. Close #1323, #1332. --- CHANGELOG.md | 1 + src/General/Config.coffee | 1 + src/General/Index.coffee | 43 ++++++++++++++++++++++--------- src/Miscellaneous/Keybinds.coffee | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 060462cd2..2d218f82c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ - More index navigation improvements: - New setting: `Anchor Hidden Threads`, enabled by default. Hidden threads will be moved at the end of the index to fill the first pages. + - New setting: `Refreshed Navigation`, disabled by default. When enabled, navigating through pages will refresh the index. ### 3.14.3 - *2013-12-09* diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 39b025920..14b665337 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -144,6 +144,7 @@ Config = 'Index Sort': 'bump' 'Show Replies': true 'Anchor Hidden Threads': true + 'Refreshed Navigation': false Header: 'Header auto-hide': false 'Header auto-hide on scroll': false diff --git a/src/General/Index.coffee b/src/General/Index.coffee index cae8482a7..30b151caf 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -37,10 +37,17 @@ Index = $.on input, 'change', @cb.sort repliesEntry = - el: $.el 'label', innerHTML: ' Show replies' + el: $.el 'label', + innerHTML: ' Show replies' anchorEntry = - el: $.el 'label', innerHTML: ' Anchor hidden threads' - for label in [repliesEntry, anchorEntry] + el: $.el 'label', + innerHTML: ' Anchor hidden threads' + title: 'Move hidden threads at the end of the index.' + refNavEntry = + el: $.el 'label', + innerHTML: ' Refreshed navigation' + title: 'Refresh index when navigating through pages.' + for label in [repliesEntry, anchorEntry, refNavEntry] input = label.el.firstChild {name} = input input.checked = Conf[name] @@ -56,7 +63,7 @@ Index = el: $.el 'span', textContent: 'Index Navigation' order: 90 - subEntries: [modeEntry, sortEntry, repliesEntry, anchorEntry] + subEntries: [modeEntry, sortEntry, repliesEntry, anchorEntry, refNavEntry] $.addClass doc, 'index-loading' @update() @@ -118,13 +125,18 @@ Index = return return if a.textContent is 'Catalog' e.preventDefault() - Index.pageNav +a.pathname.split('/')[2] + Index.userPageNav +a.pathname.split('/')[2] scrollToIndex: -> Header.scrollToIfNeeded Index.root getCurrentPage: -> +window.location.pathname.split('/')[2] + userPageNav: (pageNum) -> + if Conf['Refreshed Navigation'] and Conf['Index Mode'] is 'paged' + Index.update pageNum + else + Index.pageNav pageNum pageNav: (pageNum) -> return if Index.currentPage is pageNum history.pushState null, '', if pageNum is 0 then './' else pageNum @@ -181,7 +193,7 @@ Index = $.before a, strong $.add strong, a - update: -> + update: (pageNum) -> return unless navigator.onLine Index.req?.abort() Index.notice?.close() @@ -196,13 +208,14 @@ Index = return unless Index.req and !Index.notice Index.notice = new Notice 'info', 'Refreshing index...' ), 5 * $.SECOND - (Date.now() - now) + onload = (e) -> Index.load e, pageNum Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json", - onabort: Index.load - onloadend: Index.load + onabort: onload + onloadend: onload , whenModified: true $.addClass Index.button, 'fa-spin' - load: (e) -> + load: (e, pageNum) -> $.rmClass Index.button, 'fa-spin' {req, notice} = Index delete Index.req @@ -214,7 +227,10 @@ Index = return try - Index.parse JSON.parse req.response if req.status is 200 + if req.status is 200 + Index.parse JSON.parse(req.response), pageNum + else if req.status is 304 and pageNum? + Index.pageNav pageNum catch err c.error 'Index failure:', err.stack # network error or non-JSON content for example. @@ -235,12 +251,15 @@ Index = timeEl.dataset.utc = e.timeStamp <% if (type === 'userscript') { %>/ 1000<% } %> RelativeDates.update timeEl Index.scrollToIndex() - parse: (pages) -> + parse: (pages, pageNum) -> Index.parseThreadList pages Index.buildThreads() Index.sort() - Index.buildIndex() Index.buildPagelist() + if pageNum? + Index.pageNav pageNum + return + Index.buildIndex() Index.setPage() parseThreadList: (pages) -> Index.pagesNum = pages.length diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index 76370e38c..c158cb183 100644 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -75,7 +75,7 @@ Keybinds = # Board Navigation when Conf['Front page'] if g.VIEW is 'index' - Index.pageNav 0 + Index.userPageNav 0 else window.location = "/#{g.BOARD}/" when Conf['Open front page'] From 3928ae08e030b131a82b256e0e340f97d2531a92 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Thu, 12 Dec 2013 02:10:53 +0100 Subject: [PATCH 3/7] Fix #1365. --- src/General/Index.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 30b151caf..8f79f133c 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -208,6 +208,7 @@ Index = return unless Index.req and !Index.notice Index.notice = new Notice 'info', 'Refreshing index...' ), 5 * $.SECOND - (Date.now() - now) + pageNum = null if typeof pageNum isnt 'number' # event onload = (e) -> Index.load e, pageNum Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json", onabort: onload From f34288511be158d530a43de66d7943cd6a922375 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Thu, 12 Dec 2013 02:18:53 +0100 Subject: [PATCH 4/7] Use the Last-Modified header's date for the index refresh timer. Instead of showing how long has it been since we refreshed the index, we show how long has it been since the index has changed on 4chan's side. That'll be a more meaningful timer when 4chan freezes for example. --- src/General/Index.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 8f79f133c..06d19b3e8 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -249,7 +249,7 @@ Index = setTimeout notice.close, $.SECOND timeEl = $ '#index-last-refresh', Index.navLinks - timeEl.dataset.utc = e.timeStamp <% if (type === 'userscript') { %>/ 1000<% } %> + timeEl.dataset.utc = Date.parse req.getResponseHeader 'Last-Modified' RelativeDates.update timeEl Index.scrollToIndex() parse: (pages, pageNum) -> From cf1b6dec3f4229d33a1b52fa5ca428d5575ecc87 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 13 Dec 2013 01:55:48 +0100 Subject: [PATCH 5/7] Changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d218f82c..ea9de1bea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ - More index navigation improvements: - New setting: `Anchor Hidden Threads`, enabled by default. Hidden threads will be moved at the end of the index to fill the first pages. - New setting: `Refreshed Navigation`, disabled by default. When enabled, navigating through pages will refresh the index. + - The last index refresh timer will now indicate the last time the index changed from 4chan's side, instead of the last time you refreshed the index. ### 3.14.3 - *2013-12-09* From cfbdf1edb551d1e30f4fc73baae7cb4afb49912e Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 13 Dec 2013 14:23:46 +0100 Subject: [PATCH 6/7] Release 4chan X v3.15.0. --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea9de1bea..3b4671e90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 3.15.0 - *2013-12-13* + - More index navigation improvements: - New setting: `Anchor Hidden Threads`, enabled by default. Hidden threads will be moved at the end of the index to fill the first pages. - New setting: `Refreshed Navigation`, disabled by default. When enabled, navigating through pages will refresh the index. diff --git a/package.json b/package.json index 91fe8fcd3..04b54cfe6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "4chan-X", - "version": "3.14.3", + "version": "3.15.0", "description": "Cross-browser extension for productive lurking on 4chan.", "meta": { "name": "4chan X", From 1f411efb1e67e91be29a6aa34fc3d4239846eae2 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Sat, 14 Dec 2013 18:00:57 +0100 Subject: [PATCH 7/7] Refactor Index.sort and fix hidden+highlighted threads should be at the end. --- src/General/Index.coffee | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 06d19b3e8..900560d8c 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -346,20 +346,15 @@ Index = Index.sortedNodes.push Index.nodes[i], Index.nodes[i + 1] if Index.isSearching Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes - # Move non-hidden threads on top of the index. - if Conf['Anchor Hidden Threads'] - offset = 0 - for threadRoot, i in Index.sortedNodes by 2 when not Get.threadFromRoot(threadRoot).isHidden - Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... - # Move sticky threads on top of the index. + # Sticky threads + Index.sortOnTop (thread) -> thread.isSticky + # Highlighted threads + Index.sortOnTop((thread) -> thread.isOnTop) if Conf['Filter'] + # Non-hidden threads + Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads'] + sortOnTop: (match) -> offset = 0 - for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isSticky - Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... - return unless Conf['Filter'] - # Move highlighted threads &
on top of the index - # while keeping the original order they appear in. - offset = 0 - for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isOnTop + for threadRoot, i in Index.sortedNodes by 2 when match Get.threadFromRoot threadRoot Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... return buildIndex: ->