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.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

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

View File

@ -1,6 +1,6 @@
// 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.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -9493,13 +9493,12 @@
}
}
Unread.addPosts(posts);
return Unread.scroll();
if (Conf['Scroll to Last Read Post']) {
return Unread.scroll();
}
},
scroll: function() {
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) {
return;
}
@ -9522,7 +9521,7 @@
}
},
sync: function() {
var lastReadPost, post;
var ID, lastReadPost, post;
lastReadPost = Unread.db.get({
boardID: Unread.thread.board.ID,
threadID: Unread.thread.ID,
@ -9538,9 +9537,13 @@
if (post.ID > Unread.lastReadPost) {
break;
}
ID = post.ID;
if (!post.next) {
break;
}
post = post.next;
}
Unread.posts.splice(0, i);
Unread.posts.splice(0, ID);
Unread.readArray(Unread.postsQuotingYou);
if (Conf['Unread Line']) {
Unread.setLine();
@ -9548,28 +9551,34 @@
return Unread.update();
},
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++) {
post = posts[_i];
ID = post.ID;
if (ID <= Unread.lastReadPost || post.isHidden) {
if (ID <= Unread.lastReadPost || post.isHidden || db(post)) {
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.addPostQuotingYou(post);
}
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();
return Unread.update();
@ -9625,7 +9634,7 @@
}
Unread.posts.splice(ID(post.next.ID));
if (post === Unread.posts.first) {
Unread.lastReadPost = post.ID;
Unread.lastReadPost = ID;
Unread.saveLastReadPost();
}
if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) {
@ -9692,7 +9701,7 @@
if (!(d.hidden || force === true)) {
return;
}
if (!(post = Unread.posts[0])) {
if (!(post = Unread.posts.first)) {
return $.rm(Unread.hr);
}
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
posts.push post if post.isReply
Unread.addPosts posts
Unread.scroll()
Unread.scroll() if Conf['Scroll to Last Read Post']
scroll: ->
return unless Conf['Scroll to Last Read Post']
# Let the header's onload callback handle it.
return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts
if post = Unread.posts.first
@ -46,7 +45,7 @@ Unread =
# Scroll to the last read post.
posts = Object.keys Unread.thread.posts
{root} = Unread.thread.posts[posts[posts.length - 1]].nodes
# Scroll to the target unless we scrolled past it.
Header.scrollTo root, down if Header.getBottomOf(root) < 0
@ -62,29 +61,34 @@ Unread =
post = Unread.posts.first
while post
break if post.ID > Unread.lastReadPost
{ID} = post
break unless post.next
post = post.next
Unread.posts.splice 0, i
Unread.posts.splice 0, ID
Unread.readArray Unread.postsQuotingYou
Unread.setLine() if Conf['Unread Line']
Unread.update()
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
{ID} = post
if ID <= Unread.lastReadPost or post.isHidden
continue
if QR.db
data =
boardID: post.board.ID
threadID: post.thread.ID
postID: post.ID
continue if QR.db.get data
continue if ID <= Unread.lastReadPost or post.isHidden or db post
Unread.posts.push post
Unread.addPostQuotingYou post
if Conf['Unread Line']
# 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.update()
@ -123,7 +127,7 @@ Unread =
return unless Unread.posts[ID]
Unread.posts.splice ID post.next.ID
if post is Unread.posts.first
Unread.lastReadPost = post.ID
Unread.lastReadPost = ID
Unread.saveLastReadPost()
if (i = Unread.postsQuotingYou.indexOf post) isnt -1
Unread.postsQuotingYou.splice i, 1
@ -168,7 +172,7 @@ Unread =
setLine: (force) ->
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
$.before post.nodes.root, Unread.hr
@ -176,7 +180,7 @@ Unread =
count = Unread.posts.length
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') { %>
# XXX Chrome bug where it doesn't always update the tab title.
# crbug.com/124381