diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js
index 2a4ef2216..4eccf46de 100644
--- a/builds/4chan-X.user.js
+++ b/builds/4chan-X.user.js
@@ -3145,7 +3145,7 @@
for (threadID in _ref) {
thread = _ref[threadID];
if (thread.isHidden) {
- if (_ref1 = thread.ID, __indexOf.call(Index.liveThreadIDs, _ref1) >= 0) {
+ if (_ref1 = thread.ID, __indexOf.call(Index.liveThreadData.keys, _ref1) >= 0) {
hiddenCount++;
}
}
@@ -3265,34 +3265,32 @@
return Index.buildIndex();
},
parseThreadList: function(pages) {
- var data, i, live, page, thread;
+ var i, j, live, page, thread, threads;
Index.threadsNumPerPage = pages[0].threads.length;
- live = [];
+ live = new SimpleDict();
i = 0;
while (page = pages[i++]) {
- live = live.concat(page.threads);
- }
- data = [];
- i = 0;
- while (thread = live[i++]) {
- data.push(thread.no);
+ j = 0;
+ threads = page.threads;
+ while (thread = threads[j++]) {
+ live.push(thread.no, thread);
+ }
}
Index.liveThreadData = live;
- Index.liveThreadIDs = data;
return g.BOARD.threads.forEach(function(thread) {
var _ref;
- if (_ref = thread.ID, __indexOf.call(Index.liveThreadIDs, _ref) < 0) {
+ if (_ref = thread.ID, __indexOf.call(Index.liveThreadData.keys, _ref) < 0) {
return thread.collect();
}
});
},
buildThreads: function() {
- var err, errors, i, liveThreadData, posts, thread, threadData, threadRoot, threads;
+ var errors, posts, threads;
threads = [];
posts = [];
- i = 0;
- liveThreadData = Index.liveThreadData;
- while (threadData = liveThreadData[i]) {
+ errors = null;
+ Index.liveThreadData.forEach(function(threadData) {
+ var err, thread, threadRoot;
threadRoot = Build.thread(g.BOARD, threadData);
if (thread = g.BOARD.threads[threadData.no]) {
thread.setPage(Math.floor(i / Index.threadsNumPerPage));
@@ -3304,23 +3302,22 @@
thread = new Thread(threadData.no, g.BOARD);
threads.push(thread);
}
- i++;
if (thread.ID in thread.posts) {
- continue;
+ return;
}
try {
- posts.push(new Post($('.opContainer', threadRoot), thread, g.BOARD));
+ return posts.push(new Post($('.opContainer', threadRoot), thread, g.BOARD));
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
- errors.push({
+ return errors.push({
message: "Parsing of Thread No." + thread + " failed. Thread will be skipped.",
error: err
});
}
- }
+ });
if (errors) {
Main.handleErrors(errors);
}
@@ -3330,13 +3327,12 @@
return $.event('IndexRefresh');
},
buildReplies: function(thread) {
- var data, err, errors, i, lastReplies, node, nodes, post, posts, _i, _len;
+ var data, err, errors, lastReplies, node, nodes, post, posts, _i, _len;
if (!Conf['Show Replies']) {
return;
}
posts = [];
- i = Index.liveThreadIDs.indexOf(thread.ID);
- if (!(lastReplies = Index.liveThreadData[i].last_replies)) {
+ if (!(lastReplies = Index.liveThreadData[thread.ID].last_replies)) {
return;
}
nodes = [];
@@ -3400,16 +3396,20 @@
}
},
sort: function() {
- var i, sortedThreadIDs, sortedThreads, thread, threadID;
+ var i, liveData, sortedThreadIDs, sortedThreads, thread, threadID;
sortedThreads = [];
sortedThreadIDs = [];
+ liveData = [];
+ Index.liveThreadData.forEach(function(data) {
+ return liveData.push(data);
+ });
({
'bump': function() {
- return sortedThreadIDs = Index.liveThreadIDs;
+ return sortedThreadIDs = Index.liveThreadData.keys;
},
'lastreply': function() {
- var data, i, liveData;
- liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
+ var data, i;
+ liveData.sort(function(a, b) {
var _ref, _ref1;
if ('last_replies' in a) {
_ref = a.last_replies, a = _ref[_ref.length - 1];
@@ -3425,13 +3425,13 @@
}
},
'birth': function() {
- return sortedThreadIDs = __slice.call(Index.liveThreadIDs).sort(function(a, b) {
+ return sortedThreadIDs = __slice.call(Index.liveThreadData.keys).sort(function(a, b) {
return b - a;
});
},
'replycount': function() {
- var data, i, liveData;
- liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
+ var data, i;
+ liveData.sort(function(a, b) {
return b.replies - a.replies;
});
i = 0;
@@ -3440,8 +3440,12 @@
}
},
'filecount': function() {
- var data, i, liveData;
- liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
+ var data, i;
+ liveData = [];
+ Index.liveThreadData.forEach(function(data) {
+ return liveData.push(data);
+ });
+ liveData.sort(function(a, b) {
return b.images - a.images;
});
i = 0;
@@ -3734,7 +3738,7 @@
sticky = isSticky ? "
" : '';
closed = isClosed ? "
" : '';
if (isOP && g.VIEW === 'index') {
- pageNum = Math.floor(Index.liveThreadIDs.indexOf(postID) / Index.threadsNumPerPage);
+ pageNum = Math.floor(Index.liveThreadData.keys.indexOf(postID) / Index.threadsNumPerPage);
pageIcon = " Page " + pageNum + "";
replyLink = " [Reply]";
} else {
@@ -3800,10 +3804,10 @@
catalogThread: function(thread) {
var comment, data, fileCount, gifIcon, pageCount, postCount, pp, quotelink, root, spoilerRange, src, staticPath, subject, thumb, _i, _j, _len, _len1, _ref, _ref1;
staticPath = Build.staticPath, gifIcon = Build.gifIcon;
- data = Index.liveThreadData[Index.liveThreadIDs.indexOf(thread.ID)];
+ data = Index.liveThreadData[thread.ID];
postCount = data.replies + 1;
fileCount = data.images + !!data.ext;
- pageCount = Math.floor(Index.liveThreadIDs.indexOf(thread.ID) / Index.threadsNumPerPage);
+ pageCount = Math.floor(Index.liveThreadData.keys.indexOf(thread.ID) / Index.threadsNumPerPage);
subject = thread.OP.info.subject ? "
" + thread.OP.info.subject + "
" : '';
comment = thread.OP.nodes.comment.innerHTML.replace(/(
\s*){2,}/g, '
');
root = $.el('div', {
diff --git a/builds/crx/script.js b/builds/crx/script.js
index bb77b4b2c..f36219a85 100644
--- a/builds/crx/script.js
+++ b/builds/crx/script.js
@@ -3204,7 +3204,7 @@
for (threadID in _ref) {
thread = _ref[threadID];
if (thread.isHidden) {
- if (_ref1 = thread.ID, __indexOf.call(Index.liveThreadIDs, _ref1) >= 0) {
+ if (_ref1 = thread.ID, __indexOf.call(Index.liveThreadData.keys, _ref1) >= 0) {
hiddenCount++;
}
}
@@ -3324,34 +3324,32 @@
return Index.buildIndex();
},
parseThreadList: function(pages) {
- var data, i, live, page, thread;
+ var i, j, live, page, thread, threads;
Index.threadsNumPerPage = pages[0].threads.length;
- live = [];
+ live = new SimpleDict();
i = 0;
while (page = pages[i++]) {
- live = live.concat(page.threads);
- }
- data = [];
- i = 0;
- while (thread = live[i++]) {
- data.push(thread.no);
+ j = 0;
+ threads = page.threads;
+ while (thread = threads[j++]) {
+ live.push(thread.no, thread);
+ }
}
Index.liveThreadData = live;
- Index.liveThreadIDs = data;
return g.BOARD.threads.forEach(function(thread) {
var _ref;
- if (_ref = thread.ID, __indexOf.call(Index.liveThreadIDs, _ref) < 0) {
+ if (_ref = thread.ID, __indexOf.call(Index.liveThreadData.keys, _ref) < 0) {
return thread.collect();
}
});
},
buildThreads: function() {
- var err, errors, i, liveThreadData, posts, thread, threadData, threadRoot, threads;
+ var errors, posts, threads;
threads = [];
posts = [];
- i = 0;
- liveThreadData = Index.liveThreadData;
- while (threadData = liveThreadData[i]) {
+ errors = null;
+ Index.liveThreadData.forEach(function(threadData) {
+ var err, thread, threadRoot;
threadRoot = Build.thread(g.BOARD, threadData);
if (thread = g.BOARD.threads[threadData.no]) {
thread.setPage(Math.floor(i / Index.threadsNumPerPage));
@@ -3363,23 +3361,22 @@
thread = new Thread(threadData.no, g.BOARD);
threads.push(thread);
}
- i++;
if (thread.ID in thread.posts) {
- continue;
+ return;
}
try {
- posts.push(new Post($('.opContainer', threadRoot), thread, g.BOARD));
+ return posts.push(new Post($('.opContainer', threadRoot), thread, g.BOARD));
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
- errors.push({
+ return errors.push({
message: "Parsing of Thread No." + thread + " failed. Thread will be skipped.",
error: err
});
}
- }
+ });
if (errors) {
Main.handleErrors(errors);
}
@@ -3389,13 +3386,12 @@
return $.event('IndexRefresh');
},
buildReplies: function(thread) {
- var data, err, errors, i, lastReplies, node, nodes, post, posts, _i, _len;
+ var data, err, errors, lastReplies, node, nodes, post, posts, _i, _len;
if (!Conf['Show Replies']) {
return;
}
posts = [];
- i = Index.liveThreadIDs.indexOf(thread.ID);
- if (!(lastReplies = Index.liveThreadData[i].last_replies)) {
+ if (!(lastReplies = Index.liveThreadData[thread.ID].last_replies)) {
return;
}
nodes = [];
@@ -3459,16 +3455,20 @@
}
},
sort: function() {
- var i, sortedThreadIDs, sortedThreads, thread, threadID;
+ var i, liveData, sortedThreadIDs, sortedThreads, thread, threadID;
sortedThreads = [];
sortedThreadIDs = [];
+ liveData = [];
+ Index.liveThreadData.forEach(function(data) {
+ return liveData.push(data);
+ });
({
'bump': function() {
- return sortedThreadIDs = Index.liveThreadIDs;
+ return sortedThreadIDs = Index.liveThreadData.keys;
},
'lastreply': function() {
- var data, i, liveData;
- liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
+ var data, i;
+ liveData.sort(function(a, b) {
var _ref, _ref1;
if ('last_replies' in a) {
_ref = a.last_replies, a = _ref[_ref.length - 1];
@@ -3484,13 +3484,13 @@
}
},
'birth': function() {
- return sortedThreadIDs = __slice.call(Index.liveThreadIDs).sort(function(a, b) {
+ return sortedThreadIDs = __slice.call(Index.liveThreadData.keys).sort(function(a, b) {
return b - a;
});
},
'replycount': function() {
- var data, i, liveData;
- liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
+ var data, i;
+ liveData.sort(function(a, b) {
return b.replies - a.replies;
});
i = 0;
@@ -3499,8 +3499,12 @@
}
},
'filecount': function() {
- var data, i, liveData;
- liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
+ var data, i;
+ liveData = [];
+ Index.liveThreadData.forEach(function(data) {
+ return liveData.push(data);
+ });
+ liveData.sort(function(a, b) {
return b.images - a.images;
});
i = 0;
@@ -3793,7 +3797,7 @@
sticky = isSticky ? "
" : '';
closed = isClosed ? "
" : '';
if (isOP && g.VIEW === 'index') {
- pageNum = Math.floor(Index.liveThreadIDs.indexOf(postID) / Index.threadsNumPerPage);
+ pageNum = Math.floor(Index.liveThreadData.keys.indexOf(postID) / Index.threadsNumPerPage);
pageIcon = " Page " + pageNum + "";
replyLink = " [Reply]";
} else {
@@ -3859,10 +3863,10 @@
catalogThread: function(thread) {
var comment, data, fileCount, gifIcon, pageCount, postCount, pp, quotelink, root, spoilerRange, src, staticPath, subject, thumb, _i, _j, _len, _len1, _ref, _ref1;
staticPath = Build.staticPath, gifIcon = Build.gifIcon;
- data = Index.liveThreadData[Index.liveThreadIDs.indexOf(thread.ID)];
+ data = Index.liveThreadData[thread.ID];
postCount = data.replies + 1;
fileCount = data.images + !!data.ext;
- pageCount = Math.floor(Index.liveThreadIDs.indexOf(thread.ID) / Index.threadsNumPerPage);
+ pageCount = Math.floor(Index.liveThreadData.keys.indexOf(thread.ID) / Index.threadsNumPerPage);
subject = thread.OP.info.subject ? "" + thread.OP.info.subject + "
" : '';
comment = thread.OP.nodes.comment.innerHTML.replace(/(
\s*){2,}/g, '
');
root = $.el('div', {
diff --git a/src/General/Build.coffee b/src/General/Build.coffee
index b8e115d46..4896ea58a 100755
--- a/src/General/Build.coffee
+++ b/src/General/Build.coffee
@@ -181,7 +181,7 @@ Build =
''
if isOP and g.VIEW is 'index'
- pageNum = Index.liveThreadIDs.indexOf(postID) // Index.threadsNumPerPage
+ pageNum = Index.liveThreadData.keys.indexOf(postID) // Index.threadsNumPerPage
pageIcon = " Page #{pageNum}"
replyLink = " [Reply]"
else
@@ -237,11 +237,11 @@ Build =
catalogThread: (thread) ->
{staticPath, gifIcon} = Build
- data = Index.liveThreadData[Index.liveThreadIDs.indexOf thread.ID]
+ data = Index.liveThreadData[thread.ID]
postCount = data.replies + 1
fileCount = data.images + !!data.ext
- pageCount = Index.liveThreadIDs.indexOf(thread.ID) // Index.threadsNumPerPage
+ pageCount = Index.liveThreadData.keys.indexOf(thread.ID) // Index.threadsNumPerPage
subject = if thread.OP.info.subject
"#{thread.OP.info.subject}
"
diff --git a/src/General/Index.coffee b/src/General/Index.coffee
index 4cdbf0a40..eced981d6 100644
--- a/src/General/Index.coffee
+++ b/src/General/Index.coffee
@@ -477,7 +477,7 @@ Index =
updateHideLabel: ->
hiddenCount = 0
for threadID, thread of g.BOARD.threads when thread.isHidden
- hiddenCount++ if thread.ID in Index.liveThreadIDs
+ hiddenCount++ if thread.ID in Index.liveThreadData.keys
unless hiddenCount
Index.hideLabel.hidden = true
Index.cb.toggleHiddenThreads() if Index.showHiddenThreads
@@ -576,28 +576,25 @@ Index =
parseThreadList: (pages) ->
Index.threadsNumPerPage = pages[0].threads.length
- live = []
+ live = new SimpleDict()
i = 0
while page = pages[i++]
- live = live.concat page.threads
+ j = 0
+ {threads} = page
+ while thread = threads[j++]
+ live.push thread.no, thread
- data = []
- i = 0
- while thread = live[i++]
- data.push thread.no
-
- Index.liveThreadData = live
- Index.liveThreadIDs = data
+ Index.liveThreadData = live
g.BOARD.threads.forEach (thread) ->
- thread.collect() unless thread.ID in Index.liveThreadIDs
+ thread.collect() unless thread.ID in Index.liveThreadData.keys
buildThreads: ->
threads = []
posts = []
- i = 0
- {liveThreadData} = Index
- while threadData = liveThreadData[i]
+ errors = null
+
+ Index.liveThreadData.forEach (threadData) ->
threadRoot = Build.thread g.BOARD, threadData
if thread = g.BOARD.threads[threadData.no]
thread.setPage i // Index.threadsNumPerPage
@@ -605,31 +602,34 @@ Index =
thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit
thread.setStatus 'Sticky', !!threadData.sticky
thread.setStatus 'Closed', !!threadData.closed
+
else
thread = new Thread threadData.no, g.BOARD
threads.push thread
- i++
- continue if thread.ID of thread.posts
+
+ return if thread.ID of thread.posts
+
try
posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD
+
catch err
# Skip posts that we failed to parse.
errors = [] unless errors
errors.push
message: "Parsing of Thread No.#{thread} failed. Thread will be skipped."
error: err
- Main.handleErrors errors if errors
+ Main.handleErrors errors if errors
Main.callbackNodes Thread, threads
Main.callbackNodes Post, posts
Index.updateHideLabel()
+
$.event 'IndexRefresh'
buildReplies: (thread) ->
return unless Conf['Show Replies']
posts = []
- i = Index.liveThreadIDs.indexOf thread.ID
- return unless lastReplies = Index.liveThreadData[i].last_replies
+ return unless lastReplies = Index.liveThreadData[thread.ID].last_replies
nodes = []
for data in lastReplies
if post = thread.posts[data.no]
@@ -676,11 +676,14 @@ Index =
sortedThreads = []
sortedThreadIDs = []
+ liveData = []
+ Index.liveThreadData.forEach (data) -> liveData.push data
+
{
'bump': ->
- sortedThreadIDs = Index.liveThreadIDs
+ sortedThreadIDs = Index.liveThreadData.keys
'lastreply': ->
- liveData = [Index.liveThreadData...].sort (a, b) ->
+ liveData.sort (a, b) ->
[..., a] = a.last_replies if 'last_replies' of a
[..., b] = b.last_replies if 'last_replies' of b
b.no - a.no
@@ -689,15 +692,17 @@ Index =
sortedThreadIDs.push data.no
return
'birth': ->
- sortedThreadIDs = [Index.liveThreadIDs...].sort (a, b) -> b - a
+ sortedThreadIDs = [Index.liveThreadData.keys...].sort (a, b) -> b - a
'replycount': ->
- liveData = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies)
+ liveData.sort (a, b) -> b.replies - a.replies
i = 0
while data = liveData[i++]
sortedThreadIDs.push data.no
return
'filecount': ->
- liveData = [Index.liveThreadData...].sort((a, b) -> b.images - a.images)
+ liveData = []
+ Index.liveThreadData.forEach (data) -> liveData.push data
+ liveData.sort (a, b) -> b.images - a.images
i = 0
while data = liveData[i++]
sortedThreadIDs.push data.no