Continue implementing the random access list and generally

just optimizing Unread
This commit is contained in:
Zixaphir 2014-01-05 10:02:05 -07:00
parent a1d0bf1474
commit 6b3443c12a
4 changed files with 84 additions and 62 deletions

View File

@ -1,5 +1,5 @@
/* /*
* 4chan X - Version 1.2.44 - 2014-01-04 * 4chan X - Version 1.2.44 - 2014-01-05
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

@ -22,7 +22,7 @@
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.2.44 - 2014-01-04 * 4chan X - Version 1.2.44 - 2014-01-05
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -9510,13 +9510,12 @@
} }
} }
Unread.addPosts(posts); Unread.addPosts(posts);
return Unread.scroll(); if (Conf['Scroll to Last Read Post']) {
return Unread.scroll();
}
}, },
scroll: function() { scroll: function() {
var down, hash, post, posts, root; var down, hash, post, posts, root;
if (!Conf['Scroll to Last Read Post']) {
return;
}
if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) { if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) {
return; return;
} }
@ -9539,7 +9538,7 @@
} }
}, },
sync: function() { sync: function() {
var lastReadPost, post; var ID, lastReadPost, post;
lastReadPost = Unread.db.get({ lastReadPost = Unread.db.get({
boardID: Unread.thread.board.ID, boardID: Unread.thread.board.ID,
threadID: Unread.thread.ID, threadID: Unread.thread.ID,
@ -9555,9 +9554,13 @@
if (post.ID > Unread.lastReadPost) { if (post.ID > Unread.lastReadPost) {
break; break;
} }
ID = post.ID;
if (!post.next) {
break;
}
post = post.next; post = post.next;
} }
Unread.posts.splice(0, i); Unread.posts.splice(0, ID);
Unread.readArray(Unread.postsQuotingYou); Unread.readArray(Unread.postsQuotingYou);
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
Unread.setLine(); Unread.setLine();
@ -9565,28 +9568,34 @@
return Unread.update(); return Unread.update();
}, },
addPosts: function(posts) { addPosts: function(posts) {
var ID, data, post, _i, _len, _ref; var ID, db, post, _i, _len, _ref;
db = QR.db ? function(_arg) {
var ID, board, data, thread;
board = _arg.board, thread = _arg.thread, ID = _arg.ID;
data = {
boardID: board.ID,
threadID: thread.ID,
postID: ID
};
if (QR.db.get(data)) {
return true;
} else {
return false;
}
} : function() {
return false;
};
for (_i = 0, _len = posts.length; _i < _len; _i++) { for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i]; post = posts[_i];
ID = post.ID; ID = post.ID;
if (ID <= Unread.lastReadPost || post.isHidden) { if (ID <= Unread.lastReadPost || post.isHidden || db(post)) {
continue; continue;
} }
if (QR.db) {
data = {
boardID: post.board.ID,
threadID: post.thread.ID,
postID: post.ID
};
if (QR.db.get(data)) {
continue;
}
}
Unread.posts.push(post); Unread.posts.push(post);
Unread.addPostQuotingYou(post); Unread.addPostQuotingYou(post);
} }
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
Unread.setLine((_ref = Unread.posts[0], __indexOf.call(posts, _ref) >= 0)); Unread.setLine((_ref = Unread.posts.first, __indexOf.call(posts, _ref) >= 0));
} }
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
@ -9642,7 +9651,7 @@
} }
Unread.posts.splice(ID(post.next.ID)); Unread.posts.splice(ID(post.next.ID));
if (post === Unread.posts.first) { if (post === Unread.posts.first) {
Unread.lastReadPost = post.ID; Unread.lastReadPost = ID;
Unread.saveLastReadPost(); Unread.saveLastReadPost();
} }
if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) {
@ -9709,7 +9718,7 @@
if (!(d.hidden || force === true)) { if (!(d.hidden || force === true)) {
return; return;
} }
if (!(post = Unread.posts[0])) { if (!(post = Unread.posts.first)) {
return $.rm(Unread.hr); return $.rm(Unread.hr);
} }
if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root)) { if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root)) {

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // Generated by CoffeeScript
/* /*
* 4chan X - Version 1.2.44 - 2014-01-04 * 4chan X - Version 1.2.44 - 2014-01-05
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -9493,13 +9493,12 @@
} }
} }
Unread.addPosts(posts); Unread.addPosts(posts);
return Unread.scroll(); if (Conf['Scroll to Last Read Post']) {
return Unread.scroll();
}
}, },
scroll: function() { scroll: function() {
var down, hash, post, posts, root; var down, hash, post, posts, root;
if (!Conf['Scroll to Last Read Post']) {
return;
}
if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) { if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) {
return; return;
} }
@ -9522,7 +9521,7 @@
} }
}, },
sync: function() { sync: function() {
var lastReadPost, post; var ID, lastReadPost, post;
lastReadPost = Unread.db.get({ lastReadPost = Unread.db.get({
boardID: Unread.thread.board.ID, boardID: Unread.thread.board.ID,
threadID: Unread.thread.ID, threadID: Unread.thread.ID,
@ -9538,9 +9537,13 @@
if (post.ID > Unread.lastReadPost) { if (post.ID > Unread.lastReadPost) {
break; break;
} }
ID = post.ID;
if (!post.next) {
break;
}
post = post.next; post = post.next;
} }
Unread.posts.splice(0, i); Unread.posts.splice(0, ID);
Unread.readArray(Unread.postsQuotingYou); Unread.readArray(Unread.postsQuotingYou);
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
Unread.setLine(); Unread.setLine();
@ -9548,28 +9551,34 @@
return Unread.update(); return Unread.update();
}, },
addPosts: function(posts) { addPosts: function(posts) {
var ID, data, post, _i, _len, _ref; var ID, db, post, _i, _len, _ref;
db = QR.db ? function(_arg) {
var ID, board, data, thread;
board = _arg.board, thread = _arg.thread, ID = _arg.ID;
data = {
boardID: board.ID,
threadID: thread.ID,
postID: ID
};
if (QR.db.get(data)) {
return true;
} else {
return false;
}
} : function() {
return false;
};
for (_i = 0, _len = posts.length; _i < _len; _i++) { for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i]; post = posts[_i];
ID = post.ID; ID = post.ID;
if (ID <= Unread.lastReadPost || post.isHidden) { if (ID <= Unread.lastReadPost || post.isHidden || db(post)) {
continue; continue;
} }
if (QR.db) {
data = {
boardID: post.board.ID,
threadID: post.thread.ID,
postID: post.ID
};
if (QR.db.get(data)) {
continue;
}
}
Unread.posts.push(post); Unread.posts.push(post);
Unread.addPostQuotingYou(post); Unread.addPostQuotingYou(post);
} }
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
Unread.setLine((_ref = Unread.posts[0], __indexOf.call(posts, _ref) >= 0)); Unread.setLine((_ref = Unread.posts.first, __indexOf.call(posts, _ref) >= 0));
} }
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
@ -9625,7 +9634,7 @@
} }
Unread.posts.splice(ID(post.next.ID)); Unread.posts.splice(ID(post.next.ID));
if (post === Unread.posts.first) { if (post === Unread.posts.first) {
Unread.lastReadPost = post.ID; Unread.lastReadPost = ID;
Unread.saveLastReadPost(); Unread.saveLastReadPost();
} }
if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) {
@ -9692,7 +9701,7 @@
if (!(d.hidden || force === true)) { if (!(d.hidden || force === true)) {
return; return;
} }
if (!(post = Unread.posts[0])) { if (!(post = Unread.posts.first)) {
return $.rm(Unread.hr); return $.rm(Unread.hr);
} }
if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root)) { if ($.x('preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root)) {

View File

@ -30,10 +30,9 @@ Unread =
for ID, post of Unread.thread.posts for ID, post of Unread.thread.posts
posts.push post if post.isReply posts.push post if post.isReply
Unread.addPosts posts Unread.addPosts posts
Unread.scroll() Unread.scroll() if Conf['Scroll to Last Read Post']
scroll: -> scroll: ->
return unless Conf['Scroll to Last Read Post']
# Let the header's onload callback handle it. # Let the header's onload callback handle it.
return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts
if post = Unread.posts.first if post = Unread.posts.first
@ -46,7 +45,7 @@ Unread =
# Scroll to the last read post. # Scroll to the last read post.
posts = Object.keys Unread.thread.posts posts = Object.keys Unread.thread.posts
{root} = Unread.thread.posts[posts[posts.length - 1]].nodes {root} = Unread.thread.posts[posts[posts.length - 1]].nodes
# Scroll to the target unless we scrolled past it. # Scroll to the target unless we scrolled past it.
Header.scrollTo root, down if Header.getBottomOf(root) < 0 Header.scrollTo root, down if Header.getBottomOf(root) < 0
@ -62,29 +61,34 @@ Unread =
post = Unread.posts.first post = Unread.posts.first
while post while post
break if post.ID > Unread.lastReadPost break if post.ID > Unread.lastReadPost
{ID} = post
break unless post.next
post = post.next post = post.next
Unread.posts.splice 0, i Unread.posts.splice 0, ID
Unread.readArray Unread.postsQuotingYou Unread.readArray Unread.postsQuotingYou
Unread.setLine() if Conf['Unread Line'] Unread.setLine() if Conf['Unread Line']
Unread.update() Unread.update()
addPosts: (posts) -> addPosts: (posts) ->
db = if QR.db
({board, thread, ID}) ->
data =
boardID: board.ID
threadID: thread.ID
postID: ID
return if QR.db.get data then true else false
else ->
return false
for post in posts for post in posts
{ID} = post {ID} = post
if ID <= Unread.lastReadPost or post.isHidden continue if ID <= Unread.lastReadPost or post.isHidden or db post
continue
if QR.db
data =
boardID: post.board.ID
threadID: post.thread.ID
postID: post.ID
continue if QR.db.get data
Unread.posts.push post Unread.posts.push post
Unread.addPostQuotingYou post Unread.addPostQuotingYou post
if Conf['Unread Line'] if Conf['Unread Line']
# Force line on visible threads if there were no unread posts previously. # Force line on visible threads if there were no unread posts previously.
Unread.setLine Unread.posts[0] in posts Unread.setLine Unread.posts.first in posts
Unread.read() Unread.read()
Unread.update() Unread.update()
@ -123,7 +127,7 @@ Unread =
return unless Unread.posts[ID] return unless Unread.posts[ID]
Unread.posts.splice ID post.next.ID Unread.posts.splice ID post.next.ID
if post is Unread.posts.first if post is Unread.posts.first
Unread.lastReadPost = post.ID Unread.lastReadPost = ID
Unread.saveLastReadPost() Unread.saveLastReadPost()
if (i = Unread.postsQuotingYou.indexOf post) isnt -1 if (i = Unread.postsQuotingYou.indexOf post) isnt -1
Unread.postsQuotingYou.splice i, 1 Unread.postsQuotingYou.splice i, 1
@ -168,7 +172,7 @@ Unread =
setLine: (force) -> setLine: (force) ->
return unless d.hidden or force is true return unless d.hidden or force is true
return $.rm Unread.hr unless post = Unread.posts[0] return $.rm Unread.hr unless post = Unread.posts.first
if $.x 'preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root # not the first reply if $.x 'preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root # not the first reply
$.before post.nodes.root, Unread.hr $.before post.nodes.root, Unread.hr
@ -176,7 +180,7 @@ Unread =
count = Unread.posts.length count = Unread.posts.length
if Conf['Unread Count'] if Conf['Unread Count']
d.title = "#{if Conf['Quoted Title'] and Unread.postsQuotingYou.length then '(!) ' else ''}#{if count or !Conf['Hide Unread Count at (0)'] then "(#{count}) " else ''}#{if g.DEAD then "/#{g.BOARD}/ - 404" else "#{Unread.title}"}" d.title = "#{if Conf['Quoted Title'] and Unread.postsQuotingYou.length then '(!) ' else ''}#{if count or !Conf['Hide Unread Count at (0)'] then "(#{count}) " else ''}#{if g.DEAD then "/#{g.BOARD}/ - 404" else "#{Unread.title}"}"
<% if (type === 'crx') { %> <% if (type === 'crx') { %>
# XXX Chrome bug where it doesn't always update the tab title. # XXX Chrome bug where it doesn't always update the tab title.
# crbug.com/124381 # crbug.com/124381