diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index c0957dc00..90c9d3e6b 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -2281,6 +2281,7 @@ }); this.searchInput = $('#index-search', this.navLinks); this.currentPage = this.getCurrentPage(); + $.on(d, 'scroll', Index.scroll); $.on(this.pagelist, 'click', this.cb.pageNav); $.on(this.searchInput, 'input', this.onSearchInput); $.on($('#index-search-clear', this.navLinks), 'click', this.clearSearch); @@ -2315,6 +2316,39 @@ } }); }, + scroll: $.debounce(100, function() { + var nodes, nodesPerPage, pageNum; + if (Conf['Index Mode'] !== 'paged' || ((d.body.scrollTop || doc.scrollTop) <= doc.scrollHeight - (300 + window.innerHeight))) { + return; + } + pageNum = Index.getCurrentPage() + 1; + if (pageNum >= Index.pagesNum) { + return Index.endNotice(); + } + nodesPerPage = Index.threadsNumPerPage * 2; + history.pushState(null, '', "/" + g.BOARD + "/" + pageNum); + nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1)); + if (Conf['Show Replies']) { + Index.buildReplies(nodes); + } + $.add(Index.root, nodes); + return Index.setPage(); + }), + endNotice: (function() { + var notify, reset; + notify = false; + reset = function() { + return notify = false; + }; + return function() { + if (notify) { + return; + } + notify = true; + new Notice('info', "Last page reached.", 2); + return setTimeout(reset, 3 * $.SECOND); + }; + })(), cb: { mode: function() { Index.togglePagelist(); diff --git a/builds/crx/script.js b/builds/crx/script.js index ebf970f69..1ab2d782f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -2291,6 +2291,7 @@ }); this.searchInput = $('#index-search', this.navLinks); this.currentPage = this.getCurrentPage(); + $.on(d, 'scroll', Index.scroll); $.on(this.pagelist, 'click', this.cb.pageNav); $.on(this.searchInput, 'input', this.onSearchInput); $.on($('#index-search-clear', this.navLinks), 'click', this.clearSearch); @@ -2325,6 +2326,39 @@ } }); }, + scroll: $.debounce(100, function() { + var nodes, nodesPerPage, pageNum; + if (Conf['Index Mode'] !== 'paged' || ((d.body.scrollTop || doc.scrollTop) <= doc.scrollHeight - (300 + window.innerHeight))) { + return; + } + pageNum = Index.getCurrentPage() + 1; + if (pageNum >= Index.pagesNum) { + return Index.endNotice(); + } + nodesPerPage = Index.threadsNumPerPage * 2; + history.pushState(null, '', "/" + g.BOARD + "/" + pageNum); + nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1)); + if (Conf['Show Replies']) { + Index.buildReplies(nodes); + } + $.add(Index.root, nodes); + return Index.setPage(); + }), + endNotice: (function() { + var notify, reset; + notify = false; + reset = function() { + return notify = false; + }; + return function() { + if (notify) { + return; + } + notify = true; + new Notice('info', "Last page reached.", 2); + return setTimeout(reset, 3 * $.SECOND); + }; + })(), cb: { mode: function() { Index.togglePagelist(); diff --git a/src/General/Index.coffee b/src/General/Index.coffee index a7e33a362..101f95e16 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -78,6 +78,7 @@ Index = @searchInput = $ '#index-search', @navLinks @currentPage = @getCurrentPage() + $.on d, 'scroll', Index.scroll $.on @pagelist, 'click', @cb.pageNav $.on @searchInput, 'input', @onSearchInput $.on $('#index-search-clear', @navLinks), 'click', @clearSearch @@ -106,6 +107,26 @@ Index = else $.after $.id('delform'), Index.pagelist + scroll: $.debounce 100, -> + return if Conf['Index Mode'] isnt 'paged' or ((d.body.scrollTop or doc.scrollTop) <= doc.scrollHeight - (300 + window.innerHeight)) + pageNum = Index.getCurrentPage() + 1 + return Index.endNotice() if pageNum >= Index.pagesNum + nodesPerPage = Index.threadsNumPerPage * 2 + history.pushState null, '', "/#{g.BOARD}/#{pageNum}" + nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)] + Index.buildReplies nodes if Conf['Show Replies'] + $.add Index.root, nodes + Index.setPage() + + endNotice: do -> + notify = false + reset = -> notify = false + return -> + return if notify + notify = true + new Notice 'info', "Last page reached.", 2 + setTimeout reset, 3 * $.SECOND + cb: mode: -> Index.togglePagelist()