From 4c63dd478bdf3e7fde3b533d25428fb02d69fe3f Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 21 Apr 2013 01:39:58 -0700 Subject: [PATCH] Debounce Unread.update. This will allow use to queue up the scroll events better and prevent lockup. --- builds/4chan-X.js | 12 ++++++------ builds/4chan-X.user.js | 12 ++++++------ builds/crx/script.js | 10 +++++----- src/code/monitoring/unread.coffee | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/builds/4chan-X.js b/builds/4chan-X.js index e30ade4a1..6cd7ec8ab 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -20,7 +20,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== -/* 4chan X - Version 3.1.4 - 2013-04-19 +/* 4chan X - Version 3.1.4 - 2013-04-21 * https://4chan-x.just-believe.in/ * * Copyright (c) 2009-2011 James Campos @@ -6449,8 +6449,8 @@ } return arr.splice(0, i); }, - read: function(e) { - var ID, bottom, height, i, post, posts, read, top, _ref; + read: $.debounce(50, function(e) { + var ID, bottom, height, i, post, posts, read; if (d.hidden || !Unread.posts.length) { return; @@ -6460,8 +6460,8 @@ read = []; i = posts.length; while (post = posts[--i]) { - _ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top; - if ((bottom < height) && (top > 0)) { + bottom = post.nodes.root.getBoundingClientRect().bottom; + if (bottom < height) { ID = post.ID; posts.remove(post); } @@ -6475,7 +6475,7 @@ if (e) { return Unread.update(); } - }, + }), saveLastReadPost: $.debounce(2 * $.SECOND, function() { return Unread.db.set({ boardID: Unread.thread.board.ID, diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 2a5950ff9..2de31a151 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -20,7 +20,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== -/* 4chan X - Version 3.1.4 - 2013-04-19 +/* 4chan X - Version 3.1.4 - 2013-04-21 * https://4chan-x.just-believe.in/ * * Copyright (c) 2009-2011 James Campos @@ -6441,8 +6441,8 @@ } return arr.splice(0, i); }, - read: function(e) { - var ID, bottom, height, i, post, posts, read, top, _ref; + read: $.debounce(50, function(e) { + var ID, bottom, height, i, post, posts, read; if (d.hidden || !Unread.posts.length) { return; @@ -6452,8 +6452,8 @@ read = []; i = posts.length; while (post = posts[--i]) { - _ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top; - if ((bottom < height) && (top > 0)) { + bottom = post.nodes.root.getBoundingClientRect().bottom; + if (bottom < height) { ID = post.ID; posts.remove(post); } @@ -6467,7 +6467,7 @@ if (e) { return Unread.update(); } - }, + }), saveLastReadPost: $.debounce(2 * $.SECOND, function() { return Unread.db.set({ boardID: Unread.thread.board.ID, diff --git a/builds/crx/script.js b/builds/crx/script.js index 826a44af7..47e969c16 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6362,8 +6362,8 @@ } return arr.splice(0, i); }, - read: function(e) { - var ID, bottom, height, i, post, posts, read, top, _ref; + read: $.debounce(50, function(e) { + var ID, bottom, height, i, post, posts, read; if (d.hidden || !Unread.posts.length) { return; @@ -6373,8 +6373,8 @@ read = []; i = posts.length; while (post = posts[--i]) { - _ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top; - if ((bottom < height) && (top > 0)) { + bottom = post.nodes.root.getBoundingClientRect().bottom; + if (bottom < height) { ID = post.ID; posts.remove(post); } @@ -6388,7 +6388,7 @@ if (e) { return Unread.update(); } - }, + }), saveLastReadPost: $.debounce(2 * $.SECOND, function() { return Unread.db.set({ boardID: Unread.thread.board.ID, diff --git a/src/code/monitoring/unread.coffee b/src/code/monitoring/unread.coffee index 53368f1af..b0943b045 100644 --- a/src/code/monitoring/unread.coffee +++ b/src/code/monitoring/unread.coffee @@ -98,7 +98,7 @@ Unread = break if post.ID > Unread.lastReadPost arr.splice 0, i - read: (e) -> + read: $.debounce 50, (e) -> return if d.hidden or !Unread.posts.length height = doc.clientHeight {posts} = Unread @@ -106,8 +106,8 @@ Unread = i = posts.length while post = posts[--i] - {bottom, top} = post.nodes.root.getBoundingClientRect() - if (bottom < height) and (top > 0) # post is completely read + {bottom} = post.nodes.root.getBoundingClientRect() + if (bottom < height) # post is completely read ID = post.ID posts.remove post return unless ID