Mostly fix everything broken. Mostly.

This commit is contained in:
Zixaphir 2014-01-16 16:44:18 -07:00
parent fc90fd45d9
commit 7eb2d0aa34
7 changed files with 193 additions and 155 deletions

View File

@ -1519,8 +1519,15 @@
})(); })();
RandomAccessList = (function() { RandomAccessList = (function() {
function RandomAccessList() { function RandomAccessList(items) {
var item, _i, _len;
this.length = 0; this.length = 0;
if (items) {
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
this.push(item);
}
}
} }
RandomAccessList.prototype.push = function(data) { RandomAccessList.prototype.push = function(data) {
@ -1589,6 +1596,15 @@
return this.rm(this.first.ID); return this.rm(this.first.ID);
}; };
RandomAccessList.prototype.order = function() {
var item, order;
order = [item = this.first];
while (item = item.next) {
order.push(item);
}
return order;
};
RandomAccessList.prototype.rm = function(ID) { RandomAccessList.prototype.rm = function(ID) {
var item; var item;
item = this[ID]; item = this[ID];
@ -2738,46 +2754,44 @@
return Main.callbackNodes(Post, posts); return Main.callbackNodes(Post, posts);
}, },
sort: function() { sort: function() {
var cnd, fn, i, item, items, node, nodes, sortedThreadIDs, threadID, _i, _j, _len, _len1; var cnd, fn, i, item, items, liveThreadData, liveThreadIDs, nodes, sortedNodes, sortedThreadIDs, threadID, _i, _len;
liveThreadIDs = Index.liveThreadIDs, liveThreadData = Index.liveThreadData;
sortedThreadIDs = { sortedThreadIDs = {
lastreply: __slice.call(Index.liveThreadData).sort(function(a, b) { lastreply: __slice.call(liveThreadData).sort(function(a, b) {
if ('last_replies' in a) { var num;
a = a.last_replies[a.last_replies.length - 1]; if ((num = a.last_replies)) {
a = num[num.length - 1];
} }
if ('last_replies' in b) { if ((num = b.last_replies)) {
b = b.last_replies[b.last_replies.length - 1]; b = num[num.length - 1];
} }
return b.no - a.no; return b.no - a.no;
}).map(function(data) { }).map(function(post) {
return data.no; return post.no;
}), }),
bump: Index.liveThreadIDs, bump: liveThreadIDs,
birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) { birth: __slice.call(liveThreadIDs).sort(function(a, b) {
return b - a; return b - a;
}), }),
replycount: __slice.call(Index.liveThreadData).sort(function(a, b) { replycount: __slice.call(liveThreadData).sort(function(a, b) {
return b.replies - a.replies; return b.replies - a.replies;
}).map(function(data) { }).map(function(post) {
return data.no; return post.no;
}), }),
filecount: __slice.call(Index.liveThreadData).sort(function(a, b) { filecount: __slice.call(liveThreadData).sort(function(a, b) {
return b.images - a.images; return b.images - a.images;
}).map(function(data) { }).map(function(post) {
return data.no; return post.no;
}) })
}[Conf['Index Sort']]; }[Conf['Index Sort']];
Index.sortedNodes = new RandomAccessList; Index.sortedNodes = sortedNodes = new RandomAccessList;
nodes = Index.nodes; nodes = Index.nodes;
for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) {
threadID = sortedThreadIDs[_i]; threadID = sortedThreadIDs[_i];
Index.sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]); sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]);
} }
if (Index.isSearching && (nodes = Index.querySearch(Index.searchInput.value))) { if (Index.isSearching && (nodes = Index.querySearch(Index.searchInput.value))) {
Index.sortedNodes = new RandomAccessList; Index.sortedNodes = new RandomAccessList(nodes);
for (_j = 0, _len1 = nodes.length; _j < _len1; _j++) {
node = nodes[_j];
Index.sortedNodes.push(node);
}
} }
items = [ items = [
{ {
@ -2809,10 +2823,10 @@
var j, offset, sortedNodes, target, threadRoot; var j, offset, sortedNodes, target, threadRoot;
offset = 0; offset = 0;
sortedNodes = Index.sortedNodes; sortedNodes = Index.sortedNodes;
threadRoot = Index.sortedNodes.first; threadRoot = sortedNodes.first;
while (threadRoot) { while (threadRoot) {
if (match(Get.threadFromRoot(threadRoot.data))) { if (match(Get.threadFromRoot(threadRoot.data))) {
target = Index.sortedNodes.first; target = sortedNodes.first;
j = 0; j = 0;
while (j++ < offset) { while (j++ < offset) {
target = target.next; target = target.next;
@ -2830,11 +2844,9 @@
if (Conf['Index Mode'] !== 'all pages') { if (Conf['Index Mode'] !== 'all pages') {
nodes = Index.buildSinglePage(Index.getCurrentPage()); nodes = Index.buildSinglePage(Index.getCurrentPage());
} else { } else {
nodes = []; nodes = [(target = Index.sortedNodes.first).data];
target = Index.sortedNodes.first; while (target = target.next) {
while (target) {
nodes.push(target.data); nodes.push(target.data);
target = target.next;
} }
} }
$.rmAll(Index.root); $.rmAll(Index.root);
@ -2845,17 +2857,15 @@
return Index.buildStructure(nodes); return Index.buildStructure(nodes);
}, },
buildSinglePage: function(pageNum) { buildSinglePage: function(pageNum) {
var end, i, nodes, nodesPerPage, offset, target; var end, nodes, nodesPerPage, offset, target;
nodes = []; nodes = [];
nodesPerPage = Index.threadsNumPerPage; nodesPerPage = Index.threadsNumPerPage;
offset = nodesPerPage * pageNum; offset = nodesPerPage * pageNum;
end = offset + nodesPerPage; end = offset + nodesPerPage;
target = Index.sortedNodes.first; target = Index.sortedNodes.order()[offset];
i = 0; Index.sortedNodes;
while (i <= end) { while ((offset++ <= end) && target) {
if (offset <= i++) { nodes.push(target.data);
nodes.push(target.data);
}
target = target.next; target = target.next;
} }
return nodes; return nodes;
@ -5228,14 +5238,18 @@
return QuoteThreading.force(); return QuoteThreading.force();
}, },
force: function() { force: function() {
return g.posts.forEach(function(post) { g.posts.forEach(function(post) {
if (post.cb) { if (post.cb) {
return post.cb(true); return post.cb(true);
} }
}); });
if (Conf['Unread Count'] && Unread.thread.OP.nodes.root.parentElement.parentElement) {
Unread.read();
return Unread.update();
}
}, },
node: function() { node: function() {
var keys, len, post, posts, quote, _i, _len, _ref; var keys, len, posts, quote, _i, _len, _ref;
posts = g.posts; posts = g.posts;
if (this.isClone || !QuoteThreading.enabled) { if (this.isClone || !QuoteThreading.enabled) {
return; return;
@ -5243,7 +5257,7 @@
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Unread.posts.push(this); Unread.posts.push(this);
} }
if (this.thread.OP === this || !(post = posts[this.fullID]) || post.isHidden) { if (this.thread.OP === this || this.isHidden) {
return; return;
} }
keys = []; keys = [];
@ -5291,10 +5305,10 @@
if (!Conf['Unread Count']) { if (!Conf['Unread Count']) {
return true; return true;
} }
if (posts[post.ID]) { if (post = posts[post.ID]) {
posts.after(post, this); posts.after(post, posts[this.ID]);
} else { } else {
posts.prepend(this); posts.prepend(posts[this.ID]);
} }
return true; return true;
}, },
@ -9891,7 +9905,7 @@
return; return;
} }
if (post = Unread.posts.first) { if (post = Unread.posts.first) {
while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root)) { while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root)) {
if (!(post = Get.postFromRoot(root)).isHidden) { if (!(post = Get.postFromRoot(root)).isHidden) {
break; break;
} }
@ -9935,7 +9949,7 @@
return Unread.update(); return Unread.update();
}, },
addPosts: function(posts) { addPosts: function(posts) {
var ID, post, _i, _len, _ref; var ID, post, _i, _len, _ref, _ref1;
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;
@ -9952,7 +9966,7 @@
Unread.addPostQuotingYou(post); Unread.addPostQuotingYou(post);
} }
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
Unread.setLine((_ref = Unread.posts.first.data, __indexOf.call(posts, _ref) >= 0)); Unread.setLine((_ref = (_ref1 = Unread.posts.first) != null ? _ref1.data : void 0, __indexOf.call(posts, _ref) >= 0));
} }
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
@ -10001,16 +10015,17 @@
} }
}, },
readSinglePost: function(post) { readSinglePost: function(post) {
var ID, i; var ID, i, posts;
ID = post.ID; ID = post.ID;
if (!Unread.posts[ID]) { posts = Unread.posts;
if (!posts[ID]) {
return; return;
} }
if (post === Unread.posts.first) { if (post === posts.first) {
Unread.lastReadPost = ID; Unread.lastReadPost = ID;
Unread.saveLastReadPost(); Unread.saveLastReadPost();
} }
Unread.posts.rm(ID); posts.rm(ID);
if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) {
Unread.postsQuotingYou.splice(i, 1); Unread.postsQuotingYou.splice(i, 1);
} }
@ -10034,10 +10049,10 @@
height = doc.clientHeight; height = doc.clientHeight;
posts = Unread.posts; posts = Unread.posts;
while (post = posts.first) { while (post = posts.first) {
ID = post.ID, data = post.data; if (!(Header.getBottomOf(post.data.nodes.root) > -1)) {
if (!(Header.getBottomOf(data.nodes.root) > -1)) {
break; break;
} }
ID = post.ID, data = post.data;
posts.rm(ID); posts.rm(ID);
if (Conf['Mark Quotes of You'] && QR.db.get({ if (Conf['Mark Quotes of You'] && QR.db.get({
boardID: data.board.ID, boardID: data.board.ID,
@ -10077,8 +10092,8 @@
if (!(post = Unread.posts.first)) { 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.data.nodes.root)) {
return $.before(post.nodes.root, Unread.hr); return $.before(post.data.nodes.root, Unread.hr);
} }
}, },
update: function() { update: function() {
@ -12092,7 +12107,7 @@
err = _error; err = _error;
error = [ error = [
{ {
message: "Quote Threading Failed.", message: "" + name + " Failed.",
error: err error: err
} }
]; ];
@ -12323,7 +12338,8 @@
} }
Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']);
Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']);
Navigate.buildThread(); Navigate.buildThread();
return Header.hashScroll.call(window); return Header.hashScroll.call(window);
}, },
@ -12333,7 +12349,6 @@
$.rmAll(board); $.rmAll(board);
$.add(board, [Navigate.threadRoot, $.el('hr')]); $.add(board, [Navigate.threadRoot, $.el('hr')]);
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Navigate.ready('Unread Count', Unread.ready, !Conf['Quote Threading']);
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
} }

View File

@ -1525,8 +1525,15 @@
})(); })();
RandomAccessList = (function() { RandomAccessList = (function() {
function RandomAccessList() { function RandomAccessList(items) {
var item, _i, _len;
this.length = 0; this.length = 0;
if (items) {
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
this.push(item);
}
}
} }
RandomAccessList.prototype.push = function(data) { RandomAccessList.prototype.push = function(data) {
@ -1595,6 +1602,15 @@
return this.rm(this.first.ID); return this.rm(this.first.ID);
}; };
RandomAccessList.prototype.order = function() {
var item, order;
order = [item = this.first];
while (item = item.next) {
order.push(item);
}
return order;
};
RandomAccessList.prototype.rm = function(ID) { RandomAccessList.prototype.rm = function(ID) {
var item; var item;
item = this[ID]; item = this[ID];
@ -2748,46 +2764,44 @@
return Main.callbackNodes(Post, posts); return Main.callbackNodes(Post, posts);
}, },
sort: function() { sort: function() {
var cnd, fn, i, item, items, node, nodes, sortedThreadIDs, threadID, _i, _j, _len, _len1; var cnd, fn, i, item, items, liveThreadData, liveThreadIDs, nodes, sortedNodes, sortedThreadIDs, threadID, _i, _len;
liveThreadIDs = Index.liveThreadIDs, liveThreadData = Index.liveThreadData;
sortedThreadIDs = { sortedThreadIDs = {
lastreply: __slice.call(Index.liveThreadData).sort(function(a, b) { lastreply: __slice.call(liveThreadData).sort(function(a, b) {
if ('last_replies' in a) { var num;
a = a.last_replies[a.last_replies.length - 1]; if ((num = a.last_replies)) {
a = num[num.length - 1];
} }
if ('last_replies' in b) { if ((num = b.last_replies)) {
b = b.last_replies[b.last_replies.length - 1]; b = num[num.length - 1];
} }
return b.no - a.no; return b.no - a.no;
}).map(function(data) { }).map(function(post) {
return data.no; return post.no;
}), }),
bump: Index.liveThreadIDs, bump: liveThreadIDs,
birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) { birth: __slice.call(liveThreadIDs).sort(function(a, b) {
return b - a; return b - a;
}), }),
replycount: __slice.call(Index.liveThreadData).sort(function(a, b) { replycount: __slice.call(liveThreadData).sort(function(a, b) {
return b.replies - a.replies; return b.replies - a.replies;
}).map(function(data) { }).map(function(post) {
return data.no; return post.no;
}), }),
filecount: __slice.call(Index.liveThreadData).sort(function(a, b) { filecount: __slice.call(liveThreadData).sort(function(a, b) {
return b.images - a.images; return b.images - a.images;
}).map(function(data) { }).map(function(post) {
return data.no; return post.no;
}) })
}[Conf['Index Sort']]; }[Conf['Index Sort']];
Index.sortedNodes = new RandomAccessList; Index.sortedNodes = sortedNodes = new RandomAccessList;
nodes = Index.nodes; nodes = Index.nodes;
for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) {
threadID = sortedThreadIDs[_i]; threadID = sortedThreadIDs[_i];
Index.sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]); sortedNodes.push(nodes[Index.liveThreadIDs.indexOf(threadID)]);
} }
if (Index.isSearching && (nodes = Index.querySearch(Index.searchInput.value))) { if (Index.isSearching && (nodes = Index.querySearch(Index.searchInput.value))) {
Index.sortedNodes = new RandomAccessList; Index.sortedNodes = new RandomAccessList(nodes);
for (_j = 0, _len1 = nodes.length; _j < _len1; _j++) {
node = nodes[_j];
Index.sortedNodes.push(node);
}
} }
items = [ items = [
{ {
@ -2819,10 +2833,10 @@
var j, offset, sortedNodes, target, threadRoot; var j, offset, sortedNodes, target, threadRoot;
offset = 0; offset = 0;
sortedNodes = Index.sortedNodes; sortedNodes = Index.sortedNodes;
threadRoot = Index.sortedNodes.first; threadRoot = sortedNodes.first;
while (threadRoot) { while (threadRoot) {
if (match(Get.threadFromRoot(threadRoot.data))) { if (match(Get.threadFromRoot(threadRoot.data))) {
target = Index.sortedNodes.first; target = sortedNodes.first;
j = 0; j = 0;
while (j++ < offset) { while (j++ < offset) {
target = target.next; target = target.next;
@ -2840,11 +2854,9 @@
if (Conf['Index Mode'] !== 'all pages') { if (Conf['Index Mode'] !== 'all pages') {
nodes = Index.buildSinglePage(Index.getCurrentPage()); nodes = Index.buildSinglePage(Index.getCurrentPage());
} else { } else {
nodes = []; nodes = [(target = Index.sortedNodes.first).data];
target = Index.sortedNodes.first; while (target = target.next) {
while (target) {
nodes.push(target.data); nodes.push(target.data);
target = target.next;
} }
} }
$.rmAll(Index.root); $.rmAll(Index.root);
@ -2855,17 +2867,15 @@
return Index.buildStructure(nodes); return Index.buildStructure(nodes);
}, },
buildSinglePage: function(pageNum) { buildSinglePage: function(pageNum) {
var end, i, nodes, nodesPerPage, offset, target; var end, nodes, nodesPerPage, offset, target;
nodes = []; nodes = [];
nodesPerPage = Index.threadsNumPerPage; nodesPerPage = Index.threadsNumPerPage;
offset = nodesPerPage * pageNum; offset = nodesPerPage * pageNum;
end = offset + nodesPerPage; end = offset + nodesPerPage;
target = Index.sortedNodes.first; target = Index.sortedNodes.order()[offset];
i = 0; Index.sortedNodes;
while (i <= end) { while ((offset++ <= end) && target) {
if (offset <= i++) { nodes.push(target.data);
nodes.push(target.data);
}
target = target.next; target = target.next;
} }
return nodes; return nodes;
@ -5231,14 +5241,18 @@
return QuoteThreading.force(); return QuoteThreading.force();
}, },
force: function() { force: function() {
return g.posts.forEach(function(post) { g.posts.forEach(function(post) {
if (post.cb) { if (post.cb) {
return post.cb(true); return post.cb(true);
} }
}); });
if (Conf['Unread Count'] && Unread.thread.OP.nodes.root.parentElement.parentElement) {
Unread.read();
return Unread.update();
}
}, },
node: function() { node: function() {
var keys, len, post, posts, quote, _i, _len, _ref; var keys, len, posts, quote, _i, _len, _ref;
posts = g.posts; posts = g.posts;
if (this.isClone || !QuoteThreading.enabled) { if (this.isClone || !QuoteThreading.enabled) {
return; return;
@ -5246,7 +5260,7 @@
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Unread.posts.push(this); Unread.posts.push(this);
} }
if (this.thread.OP === this || !(post = posts[this.fullID]) || post.isHidden) { if (this.thread.OP === this || this.isHidden) {
return; return;
} }
keys = []; keys = [];
@ -5294,10 +5308,10 @@
if (!Conf['Unread Count']) { if (!Conf['Unread Count']) {
return true; return true;
} }
if (posts[post.ID]) { if (post = posts[post.ID]) {
posts.after(post, this); posts.after(post, posts[this.ID]);
} else { } else {
posts.prepend(this); posts.prepend(posts[this.ID]);
} }
return true; return true;
}, },
@ -9874,7 +9888,7 @@
return; return;
} }
if (post = Unread.posts.first) { if (post = Unread.posts.first) {
while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root)) { while (root = $.x('preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root)) {
if (!(post = Get.postFromRoot(root)).isHidden) { if (!(post = Get.postFromRoot(root)).isHidden) {
break; break;
} }
@ -9918,7 +9932,7 @@
return Unread.update(); return Unread.update();
}, },
addPosts: function(posts) { addPosts: function(posts) {
var ID, post, _i, _len, _ref; var ID, post, _i, _len, _ref, _ref1;
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;
@ -9935,7 +9949,7 @@
Unread.addPostQuotingYou(post); Unread.addPostQuotingYou(post);
} }
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
Unread.setLine((_ref = Unread.posts.first.data, __indexOf.call(posts, _ref) >= 0)); Unread.setLine((_ref = (_ref1 = Unread.posts.first) != null ? _ref1.data : void 0, __indexOf.call(posts, _ref) >= 0));
} }
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
@ -9984,16 +9998,17 @@
} }
}, },
readSinglePost: function(post) { readSinglePost: function(post) {
var ID, i; var ID, i, posts;
ID = post.ID; ID = post.ID;
if (!Unread.posts[ID]) { posts = Unread.posts;
if (!posts[ID]) {
return; return;
} }
if (post === Unread.posts.first) { if (post === posts.first) {
Unread.lastReadPost = ID; Unread.lastReadPost = ID;
Unread.saveLastReadPost(); Unread.saveLastReadPost();
} }
Unread.posts.rm(ID); posts.rm(ID);
if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) { if ((i = Unread.postsQuotingYou.indexOf(post)) !== -1) {
Unread.postsQuotingYou.splice(i, 1); Unread.postsQuotingYou.splice(i, 1);
} }
@ -10017,10 +10032,10 @@
height = doc.clientHeight; height = doc.clientHeight;
posts = Unread.posts; posts = Unread.posts;
while (post = posts.first) { while (post = posts.first) {
ID = post.ID, data = post.data; if (!(Header.getBottomOf(post.data.nodes.root) > -1)) {
if (!(Header.getBottomOf(data.nodes.root) > -1)) {
break; break;
} }
ID = post.ID, data = post.data;
posts.rm(ID); posts.rm(ID);
if (Conf['Mark Quotes of You'] && QR.db.get({ if (Conf['Mark Quotes of You'] && QR.db.get({
boardID: data.board.ID, boardID: data.board.ID,
@ -10060,8 +10075,8 @@
if (!(post = Unread.posts.first)) { 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.data.nodes.root)) {
return $.before(post.nodes.root, Unread.hr); return $.before(post.data.nodes.root, Unread.hr);
} }
}, },
update: function(dontrepeat) { update: function(dontrepeat) {
@ -12081,7 +12096,7 @@
err = _error; err = _error;
error = [ error = [
{ {
message: "Quote Threading Failed.", message: "" + name + " Failed.",
error: err error: err
} }
]; ];
@ -12312,7 +12327,8 @@
} }
Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']);
Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']);
Navigate.buildThread(); Navigate.buildThread();
return Header.hashScroll.call(window); return Header.hashScroll.call(window);
}, },
@ -12322,7 +12338,6 @@
$.rmAll(board); $.rmAll(board);
$.add(board, [Navigate.threadRoot, $.el('hr')]); $.add(board, [Navigate.threadRoot, $.el('hr')]);
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Navigate.ready('Unread Count', Unread.ready, !Conf['Quote Threading']);
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
} }

View File

@ -375,25 +375,25 @@ Index =
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
sort: -> sort: ->
{liveThreadIDs, liveThreadData} = Index
sortedThreadIDs = { sortedThreadIDs = {
lastreply: lastreply:
[Index.liveThreadData...].sort((a, b) -> [liveThreadData...].sort((a, b) ->
a = a.last_replies[a.last_replies.length - 1] if 'last_replies' of a a = num[num.length - 1] if (num = a.last_replies)
b = b.last_replies[b.last_replies.length - 1] if 'last_replies' of b b = num[num.length - 1] if (num = b.last_replies)
b.no - a.no b.no - a.no
).map (data) -> data.no ).map (post) -> post.no
bump: Index.liveThreadIDs bump: liveThreadIDs
birth: [Index.liveThreadIDs... ].sort (a, b) -> b - a birth: [liveThreadIDs... ].sort (a, b) -> b - a
replycount: [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no replycount: [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no
filecount: [Index.liveThreadData...].sort((a, b) -> b.images - a.images ).map (data) -> data.no filecount: [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no
}[Conf['Index Sort']] }[Conf['Index Sort']]
Index.sortedNodes = new RandomAccessList Index.sortedNodes = sortedNodes = new RandomAccessList
{nodes} = Index {nodes} = Index
for threadID in sortedThreadIDs for threadID in sortedThreadIDs
Index.sortedNodes.push nodes[Index.liveThreadIDs.indexOf(threadID)] sortedNodes.push nodes[Index.liveThreadIDs.indexOf(threadID)]
if Index.isSearching and nodes = Index.querySearch(Index.searchInput.value) if Index.isSearching and nodes = Index.querySearch(Index.searchInput.value)
Index.sortedNodes = new RandomAccessList Index.sortedNodes = new RandomAccessList nodes
Index.sortedNodes.push node for node in nodes
items = [ items = [
# Sticky threads # Sticky threads
fn: (thread) -> thread.isSticky fn: (thread) -> thread.isSticky
@ -414,10 +414,10 @@ Index =
sortOnTop: (match) -> sortOnTop: (match) ->
offset = 0 offset = 0
{sortedNodes} = Index {sortedNodes} = Index
threadRoot = Index.sortedNodes.first threadRoot = sortedNodes.first
while threadRoot while threadRoot
if match Get.threadFromRoot threadRoot.data if match Get.threadFromRoot threadRoot.data
target = Index.sortedNodes.first target = sortedNodes.first
j = 0 j = 0
while j++ < offset while j++ < offset
target = target.next target = target.next
@ -431,11 +431,9 @@ Index =
if Conf['Index Mode'] isnt 'all pages' if Conf['Index Mode'] isnt 'all pages'
nodes = Index.buildSinglePage Index.getCurrentPage() nodes = Index.buildSinglePage Index.getCurrentPage()
else else
nodes = [] nodes = [(target = Index.sortedNodes.first).data]
target = Index.sortedNodes.first while target = target.next
while target
nodes.push target.data nodes.push target.data
target = target.next
$.rmAll Index.root $.rmAll Index.root
$.rmAll Header.hover $.rmAll Header.hover
Index.buildReplies nodes if Conf['Show Replies'] Index.buildReplies nodes if Conf['Show Replies']
@ -446,11 +444,10 @@ Index =
nodesPerPage = Index.threadsNumPerPage nodesPerPage = Index.threadsNumPerPage
offset = nodesPerPage * pageNum offset = nodesPerPage * pageNum
end = offset + nodesPerPage end = offset + nodesPerPage
target = Index.sortedNodes.first target = Index.sortedNodes.order()[offset]
i = 0 Index.sortedNodes
while i <= end while (offset++ <= end) and target
if offset <= i++ nodes.push target.data
nodes.push target.data
target = target.next target = target.next
nodes nodes
@ -501,7 +498,7 @@ Index =
Index.search keywords Index.search keywords
search: (keywords) -> search: (keywords) ->
found = [] found = []
target = Index.sortedNodes.first target = Index.sortedNodes.first
while target while target
{data} = target {data} = target

View File

@ -83,7 +83,7 @@ Navigate =
feature() if condition feature() if condition
catch err catch err
error = [ error = [
message: "Quote Threading Failed." message: "#{name} Failed."
error: err error: err
] ]
Main.handleErrors error if error Main.handleErrors error if error
@ -284,7 +284,8 @@ Navigate =
Main.callbackNodes Thread, [thread] Main.callbackNodes Thread, [thread]
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] and not Conf['Unread Count']
Navigate.ready 'Unread Count', Unread.ready, Conf['Unread Count']
Navigate.buildThread() Navigate.buildThread()
Header.hashScroll.call window Header.hashScroll.call window
@ -295,7 +296,6 @@ Navigate =
$.add board, [Navigate.threadRoot, $.el 'hr'] $.add board, [Navigate.threadRoot, $.el 'hr']
if Conf['Unread Count'] if Conf['Unread Count']
Navigate.ready 'Unread Count', Unread.ready, not Conf['Quote Threading']
Unread.read() Unread.read()
Unread.update() Unread.update()

View File

@ -1,6 +1,7 @@
class RandomAccessList class RandomAccessList
constructor: -> constructor: (items) ->
@length = 0 @length = 0
@push item for item in items if items
push: (data) -> push: (data) ->
{ID} = data {ID} = data
@ -52,6 +53,11 @@ class RandomAccessList
shift: -> shift: ->
@rm @first.ID @rm @first.ID
order: ->
order = [item = @first]
order.push item while item = item.next
order
rm: (ID) -> rm: (ID) ->
item = @[ID] item = @[ID]

View File

@ -52,7 +52,7 @@ Unread =
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
# Scroll to a non-hidden, non-OP post that's before the first unread post. # Scroll to a non-hidden, non-OP post that's before the first unread post.
while root = $.x 'preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root while root = $.x 'preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root
break unless (post = Get.postFromRoot root).isHidden break unless (post = Get.postFromRoot root).isHidden
return unless root return unless root
down = true down = true
@ -95,7 +95,7 @@ Unread =
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.first.data in posts Unread.setLine Unread.posts.first?.data in posts
Unread.read() Unread.read()
Unread.update() Unread.update()
@ -131,11 +131,12 @@ Unread =
readSinglePost: (post) -> readSinglePost: (post) ->
{ID} = post {ID} = post
return unless Unread.posts[ID] {posts} = Unread
if post is Unread.posts.first return unless posts[ID]
if post is posts.first
Unread.lastReadPost = ID Unread.lastReadPost = ID
Unread.saveLastReadPost() Unread.saveLastReadPost()
Unread.posts.rm ID posts.rm ID
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
Unread.update() Unread.update()
@ -151,8 +152,8 @@ Unread =
{posts} = Unread {posts} = Unread
while post = posts.first while post = posts.first
break unless Header.getBottomOf(post.data.nodes.root) > -1 # post is not completely read
{ID, data} = post {ID, data} = post
break unless Header.getBottomOf(data.nodes.root) > -1 # post is not completely read
posts.rm ID posts.rm ID
if Conf['Mark Quotes of You'] and QR.db.get { if Conf['Mark Quotes of You'] and QR.db.get {
@ -179,8 +180,8 @@ 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.first 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.data.nodes.root # not the first reply
$.before post.nodes.root, Unread.hr $.before post.data.nodes.root, Unread.hr
update: <% if (type === 'crx') { %>(dontrepeat) <% } %>-> update: <% if (type === 'crx') { %>(dontrepeat) <% } %>->
count = Unread.posts.length count = Unread.posts.length

View File

@ -45,12 +45,16 @@ QuoteThreading =
g.posts.forEach (post) -> g.posts.forEach (post) ->
post.cb true if post.cb post.cb true if post.cb
if Conf['Unread Count'] and Unread.thread.OP.nodes.root.parentElement.parentElement
Unread.read()
Unread.update()
node: -> node: ->
{posts} = g {posts} = g
return if @isClone or not QuoteThreading.enabled return if @isClone or not QuoteThreading.enabled
Unread.posts.push @ if Conf['Unread Count']
return if @thread.OP is @ or !(post = posts[@fullID]) or post.isHidden # Filtered Unread.posts.push @ if Conf['Unread Count']
return if @thread.OP is @ or @isHidden # Filtered
keys = [] keys = []
len = g.BOARD.ID.length + 1 len = g.BOARD.ID.length + 1
@ -90,11 +94,11 @@ QuoteThreading =
return true unless Conf['Unread Count'] return true unless Conf['Unread Count']
if posts[post.ID] if post = posts[post.ID]
posts.after post, @ posts.after post, posts[@ID]
else else
posts.prepend @ posts.prepend posts[@ID]
return true return true