Fix and use thread.collect for GC
Also merge appchan's JSON option fixes
This commit is contained in:
parent
bcd7ab21e3
commit
481ca6af72
2
LICENSE
2
LICENSE
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.3.2 - 2014-01-13
|
* 4chan X - Version 1.3.2 - 2014-01-14
|
||||||
*
|
*
|
||||||
* 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
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.3.2 - 2014-01-13
|
* 4chan X - Version 1.3.2 - 2014-01-14
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -949,10 +949,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Thread.prototype.collect = function() {
|
Thread.prototype.collect = function() {
|
||||||
var post, postID, _i, _len, _ref;
|
var post, postID, _ref;
|
||||||
_ref = this.posts;
|
_ref = this.posts;
|
||||||
for (post = _i = 0, _len = _ref.length; _i < _len; post = ++_i) {
|
for (postID in _ref) {
|
||||||
postID = _ref[post];
|
post = _ref[postID];
|
||||||
post.collect();
|
post.collect();
|
||||||
}
|
}
|
||||||
delete g.threads[this.fullID];
|
delete g.threads[this.fullID];
|
||||||
@ -11924,12 +11924,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
clean: function() {
|
clean: function() {
|
||||||
var posts, threads;
|
var id, posts, thread, threads, _ref;
|
||||||
posts = g.posts, threads = g.threads;
|
posts = g.posts, threads = g.threads;
|
||||||
g.posts = {};
|
_ref = g.threads;
|
||||||
g.threads = {};
|
for (id in _ref) {
|
||||||
g.BOARD.posts = {};
|
thread = _ref[id];
|
||||||
g.BOARD.threads = {};
|
thread.collect();
|
||||||
|
}
|
||||||
QuoteBacklink.containers = {};
|
QuoteBacklink.containers = {};
|
||||||
return $.rmAll($('.board'));
|
return $.rmAll($('.board'));
|
||||||
},
|
},
|
||||||
@ -13033,7 +13034,7 @@
|
|||||||
});
|
});
|
||||||
$.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
|
$.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
|
||||||
}
|
}
|
||||||
if (g.VIEW === 'thread') {
|
if (!(Conf['JSON Navigation'] && g.VIEW === 'index')) {
|
||||||
Main.initThread();
|
Main.initThread();
|
||||||
} else {
|
} else {
|
||||||
$.event('4chanXInitFinished');
|
$.event('4chanXInitFinished');
|
||||||
@ -13056,19 +13057,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
initThread: function() {
|
initThread: function() {
|
||||||
var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref;
|
var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1;
|
||||||
if (!(threadRoot = $('.thread'))) {
|
if (board = $('.board')) {
|
||||||
return;
|
threads = [];
|
||||||
}
|
|
||||||
thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
|
|
||||||
posts = [];
|
posts = [];
|
||||||
_ref = $$('.thread > .postContainer', threadRoot);
|
_ref = $$('.board > .thread', board);
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
postRoot = _ref[_i];
|
threadRoot = _ref[_i];
|
||||||
|
thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
|
||||||
|
threads.push(thread);
|
||||||
|
_ref1 = $$('.thread > .postContainer', threadRoot);
|
||||||
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
|
postRoot = _ref1[_j];
|
||||||
try {
|
try {
|
||||||
posts.push(new Post(postRoot, thread, g.BOARD, {
|
posts.push(new Post(postRoot, thread, g.BOARD));
|
||||||
isOriginalMarkup: true
|
|
||||||
}));
|
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
err = _error;
|
err = _error;
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
@ -13080,13 +13082,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (errors) {
|
if (errors) {
|
||||||
Main.handleErrors(errors);
|
Main.handleErrors(errors);
|
||||||
}
|
}
|
||||||
Main.callbackNodes(Thread, [thread]);
|
Main.callbackNodes(Thread, threads);
|
||||||
return Main.callbackNodesDB(Post, posts, function() {
|
return Main.callbackNodesDB(Post, posts, function() {
|
||||||
return $.event('4chanXInitFinished');
|
return $.event('4chanXInitFinished');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
callbackNodes: function(klass, nodes) {
|
callbackNodes: function(klass, nodes) {
|
||||||
var cb, i, node;
|
var cb, i, node;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript
|
// Generated by CoffeeScript
|
||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.3.2 - 2014-01-13
|
* 4chan X - Version 1.3.2 - 2014-01-14
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -954,10 +954,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Thread.prototype.collect = function() {
|
Thread.prototype.collect = function() {
|
||||||
var post, postID, _i, _len, _ref;
|
var post, postID, _ref;
|
||||||
_ref = this.posts;
|
_ref = this.posts;
|
||||||
for (post = _i = 0, _len = _ref.length; _i < _len; post = ++_i) {
|
for (postID in _ref) {
|
||||||
postID = _ref[post];
|
post = _ref[postID];
|
||||||
post.collect();
|
post.collect();
|
||||||
}
|
}
|
||||||
delete g.threads[this.fullID];
|
delete g.threads[this.fullID];
|
||||||
@ -11913,12 +11913,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
clean: function() {
|
clean: function() {
|
||||||
var posts, threads;
|
var id, posts, thread, threads, _ref;
|
||||||
posts = g.posts, threads = g.threads;
|
posts = g.posts, threads = g.threads;
|
||||||
g.posts = {};
|
_ref = g.threads;
|
||||||
g.threads = {};
|
for (id in _ref) {
|
||||||
g.BOARD.posts = {};
|
thread = _ref[id];
|
||||||
g.BOARD.threads = {};
|
thread.collect();
|
||||||
|
}
|
||||||
QuoteBacklink.containers = {};
|
QuoteBacklink.containers = {};
|
||||||
return $.rmAll($('.board'));
|
return $.rmAll($('.board'));
|
||||||
},
|
},
|
||||||
@ -13020,7 +13021,7 @@
|
|||||||
});
|
});
|
||||||
$.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
|
$.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
|
||||||
}
|
}
|
||||||
if (g.VIEW === 'thread') {
|
if (!(Conf['JSON Navigation'] && g.VIEW === 'index')) {
|
||||||
Main.initThread();
|
Main.initThread();
|
||||||
} else {
|
} else {
|
||||||
$.event('4chanXInitFinished');
|
$.event('4chanXInitFinished');
|
||||||
@ -13033,19 +13034,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
initThread: function() {
|
initThread: function() {
|
||||||
var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref;
|
var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1;
|
||||||
if (!(threadRoot = $('.thread'))) {
|
if (board = $('.board')) {
|
||||||
return;
|
threads = [];
|
||||||
}
|
|
||||||
thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
|
|
||||||
posts = [];
|
posts = [];
|
||||||
_ref = $$('.thread > .postContainer', threadRoot);
|
_ref = $$('.board > .thread', board);
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
postRoot = _ref[_i];
|
threadRoot = _ref[_i];
|
||||||
|
thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
|
||||||
|
threads.push(thread);
|
||||||
|
_ref1 = $$('.thread > .postContainer', threadRoot);
|
||||||
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
|
postRoot = _ref1[_j];
|
||||||
try {
|
try {
|
||||||
posts.push(new Post(postRoot, thread, g.BOARD, {
|
posts.push(new Post(postRoot, thread, g.BOARD));
|
||||||
isOriginalMarkup: true
|
|
||||||
}));
|
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
err = _error;
|
err = _error;
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
@ -13057,13 +13059,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (errors) {
|
if (errors) {
|
||||||
Main.handleErrors(errors);
|
Main.handleErrors(errors);
|
||||||
}
|
}
|
||||||
Main.callbackNodes(Thread, [thread]);
|
Main.callbackNodes(Thread, threads);
|
||||||
return Main.callbackNodesDB(Post, posts, function() {
|
return Main.callbackNodesDB(Post, posts, function() {
|
||||||
return $.event('4chanXInitFinished');
|
return $.event('4chanXInitFinished');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
callbackNodes: function(klass, nodes) {
|
callbackNodes: function(klass, nodes) {
|
||||||
var cb, i, node;
|
var cb, i, node;
|
||||||
|
|||||||
@ -131,7 +131,7 @@ Main =
|
|||||||
'left=0,top=0,width=500,height=255,toolbar=0,resizable=0'
|
'left=0,top=0,width=500,height=255,toolbar=0,resizable=0'
|
||||||
$.before styleSelector.previousSibling, [$.tn '['; passLink, $.tn ']\u00A0\u00A0']
|
$.before styleSelector.previousSibling, [$.tn '['; passLink, $.tn ']\u00A0\u00A0']
|
||||||
|
|
||||||
if g.VIEW is 'thread'
|
unless Conf['JSON Navigation'] and g.VIEW is 'index'
|
||||||
Main.initThread()
|
Main.initThread()
|
||||||
else
|
else
|
||||||
$.event '4chanXInitFinished'
|
$.event '4chanXInitFinished'
|
||||||
@ -150,21 +150,26 @@ Main =
|
|||||||
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
|
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
|
||||||
|
|
||||||
initThread: ->
|
initThread: ->
|
||||||
return unless threadRoot = $ '.thread'
|
if board = $ '.board'
|
||||||
thread = new Thread +threadRoot.id[1..], g.BOARD
|
threads = []
|
||||||
posts = []
|
posts = []
|
||||||
|
|
||||||
|
for threadRoot in $$ '.board > .thread', board
|
||||||
|
thread = new Thread +threadRoot.id[1..], g.BOARD
|
||||||
|
threads.push thread
|
||||||
for postRoot in $$ '.thread > .postContainer', threadRoot
|
for postRoot in $$ '.thread > .postContainer', threadRoot
|
||||||
try
|
try
|
||||||
posts.push new Post postRoot, thread, g.BOARD, {isOriginalMarkup: true}
|
posts.push new Post postRoot, thread, g.BOARD
|
||||||
catch err
|
catch err
|
||||||
# Skip posts that we failed to parse.
|
# Skip posts that we failed to parse.
|
||||||
errors = [] unless errors
|
unless errors
|
||||||
|
errors = []
|
||||||
errors.push
|
errors.push
|
||||||
message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped."
|
message: "Parsing of Post No.#{postRoot.id.match(/\d+/)} failed. Post will be skipped."
|
||||||
error: err
|
error: err
|
||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
|
|
||||||
Main.callbackNodes Thread, [thread]
|
Main.callbackNodes Thread, threads
|
||||||
Main.callbackNodesDB Post, posts, ->
|
Main.callbackNodesDB Post, posts, ->
|
||||||
$.event '4chanXInitFinished'
|
$.event '4chanXInitFinished'
|
||||||
|
|
||||||
|
|||||||
@ -34,10 +34,7 @@ Navigate =
|
|||||||
{posts, threads} = g
|
{posts, threads} = g
|
||||||
|
|
||||||
# Garbage collection
|
# Garbage collection
|
||||||
g.posts = {}
|
thread.collect() for id, thread of g.threads
|
||||||
g.threads = {}
|
|
||||||
g.BOARD.posts = {}
|
|
||||||
g.BOARD.threads = {}
|
|
||||||
|
|
||||||
QuoteBacklink.containers = {}
|
QuoteBacklink.containers = {}
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,6 @@ class Thread
|
|||||||
@timeOfDeath = Date.now()
|
@timeOfDeath = Date.now()
|
||||||
|
|
||||||
collect: ->
|
collect: ->
|
||||||
for postID, post in @posts
|
post.collect() for postID, post of @posts
|
||||||
post.collect()
|
|
||||||
delete g.threads[@fullID]
|
delete g.threads[@fullID]
|
||||||
delete @board.threads[@]
|
delete @board.threads[@]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user