So terrible~

This commit is contained in:
Zixaphir 2014-01-05 13:57:26 -07:00
parent 3f60a05edc
commit 4f8e304ee8
5 changed files with 77 additions and 87 deletions

View File

@ -1480,9 +1480,8 @@
}
this.rmi(item);
next = root.next;
next.prev = item;
root.next = next.prev = item;
item.next = next;
root.next = item;
return item.prev = root;
};
@ -1493,12 +1492,11 @@
this.push(item);
}
first = this.first;
if (this !== first) {
item.next = first;
}
if (first) {
first.prev = item;
if (item === first) {
return;
}
item.next = first;
first.prev = item;
this.first = item;
return delete item.prev;
};
@ -1533,7 +1531,7 @@
this.length--;
this.rmi(item);
delete item.next;
return delete item.previous;
return delete item.prev;
};
RandomAccessList.prototype.rmi = function(item) {
@ -4968,11 +4966,11 @@
});
},
setup: function() {
var ID, post, posts;
var ID, post, _ref;
$.off(d, '4chanXInitFinished', QuoteThreading.setup);
posts = g.posts;
for (ID in posts) {
post = posts[ID];
_ref = g.posts;
for (ID in _ref) {
post = _ref[ID];
if (post.cb) {
post.cb.call(post);
}
@ -4980,48 +4978,42 @@
return QuoteThreading.hasRun = true;
},
node: function() {
var ID, fullID, keys, len, post, posts, qid, quote, quotes, replies, uniq, _i, _len;
var ID, fullID, keys, len, post, posts, quote, quotes, _i, _len;
if (this.isClone || !QuoteThreading.enabled || this.thread.OP === this) {
return;
}
replies = Unread.replies;
quotes = this.quotes, ID = this.ID, fullID = this.fullID;
posts = g.posts;
if (!(post = posts[fullID]) || post.isHidden) {
return;
}
uniq = {};
keys = [];
len = ("" + g.BOARD).length + 1;
for (_i = 0, _len = quotes.length; _i < _len; _i++) {
quote = quotes[_i];
qid = quote;
if (!(qid.slice(len) < ID)) {
continue;
}
if (qid in posts) {
uniq[qid.slice(len)] = true;
if (quote.slice(len) < ID) {
if (quote in posts) {
keys.push(quote);
}
}
}
keys = Object.keys(uniq);
if (keys.length !== 1) {
return;
}
this.threaded = "" + g.BOARD + "." + keys[0];
this.threaded = keys[0];
return this.cb = QuoteThreading.nodeinsert;
},
nodeinsert: function() {
var ID, bottom, height, post, posts, root, threadContainer, top, _ref;
post = g.posts[this.threaded];
posts = Unread.posts;
this.threaded;
this.cb;
if (this.thread.OP === post) {
return false;
}
if (QuoteThreading.hasRun) {
height = doc.clientHeight;
_ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top;
if (!(posts[post.ID] || ((bottom < height) && (top > 0)))) {
if (!((posts != null ? posts[post.ID] : void 0) || ((bottom < height) && (top > 0)))) {
return false;
}
}
@ -5036,6 +5028,9 @@
threadContainer = root.nextSibling;
}
$.add(threadContainer, this.nodes.root);
if (!Conf['Unread Count'] || this.ID < Unread.lastReadPost) {
return true;
}
if (!posts[this.ID]) {
posts.push(this);
}
@ -5052,8 +5047,10 @@
},
toggle: function() {
var container, containers, node, post, replies, reply, thread, _i, _j, _k, _len, _len1, _len2, _ref;
Unread.posts = new RandomAccessList;
Unread.ready();
if (Conf['Unread Count']) {
Unread.posts = new RandomAccessList;
Unread.ready();
}
thread = $('.thread');
replies = $$('.thread > .replyContainer, .threadContainer > .replyContainer', thread);
QuoteThreading.enabled = this.checked;
@ -5091,7 +5088,9 @@
$.rmClass(post, 'threadOP');
}
}
return Unread.update(true);
if (Conf['Unread Count']) {
return Unread.read();
}
},
kb: function() {
var control;

View File

@ -1486,9 +1486,8 @@
}
this.rmi(item);
next = root.next;
next.prev = item;
root.next = next.prev = item;
item.next = next;
root.next = item;
return item.prev = root;
};
@ -1499,12 +1498,11 @@
this.push(item);
}
first = this.first;
if (this !== first) {
item.next = first;
}
if (first) {
first.prev = item;
if (item === first) {
return;
}
item.next = first;
first.prev = item;
this.first = item;
return delete item.prev;
};
@ -1539,7 +1537,7 @@
this.length--;
this.rmi(item);
delete item.next;
return delete item.previous;
return delete item.prev;
};
RandomAccessList.prototype.rmi = function(item) {
@ -4971,11 +4969,11 @@
});
},
setup: function() {
var ID, post, posts;
var ID, post, _ref;
$.off(d, '4chanXInitFinished', QuoteThreading.setup);
posts = g.posts;
for (ID in posts) {
post = posts[ID];
_ref = g.posts;
for (ID in _ref) {
post = _ref[ID];
if (post.cb) {
post.cb.call(post);
}
@ -4983,48 +4981,42 @@
return QuoteThreading.hasRun = true;
},
node: function() {
var ID, fullID, keys, len, post, posts, qid, quote, quotes, replies, uniq, _i, _len;
var ID, fullID, keys, len, post, posts, quote, quotes, _i, _len;
if (this.isClone || !QuoteThreading.enabled || this.thread.OP === this) {
return;
}
replies = Unread.replies;
quotes = this.quotes, ID = this.ID, fullID = this.fullID;
posts = g.posts;
if (!(post = posts[fullID]) || post.isHidden) {
return;
}
uniq = {};
keys = [];
len = ("" + g.BOARD).length + 1;
for (_i = 0, _len = quotes.length; _i < _len; _i++) {
quote = quotes[_i];
qid = quote;
if (!(qid.slice(len) < ID)) {
continue;
}
if (qid in posts) {
uniq[qid.slice(len)] = true;
if (quote.slice(len) < ID) {
if (quote in posts) {
keys.push(quote);
}
}
}
keys = Object.keys(uniq);
if (keys.length !== 1) {
return;
}
this.threaded = "" + g.BOARD + "." + keys[0];
this.threaded = keys[0];
return this.cb = QuoteThreading.nodeinsert;
},
nodeinsert: function() {
var ID, bottom, height, post, posts, root, threadContainer, top, _ref;
post = g.posts[this.threaded];
posts = Unread.posts;
this.threaded;
this.cb;
if (this.thread.OP === post) {
return false;
}
if (QuoteThreading.hasRun) {
height = doc.clientHeight;
_ref = post.nodes.root.getBoundingClientRect(), bottom = _ref.bottom, top = _ref.top;
if (!(posts[post.ID] || ((bottom < height) && (top > 0)))) {
if (!((posts != null ? posts[post.ID] : void 0) || ((bottom < height) && (top > 0)))) {
return false;
}
}
@ -5039,6 +5031,9 @@
threadContainer = root.nextSibling;
}
$.add(threadContainer, this.nodes.root);
if (!Conf['Unread Count'] || this.ID < Unread.lastReadPost) {
return true;
}
if (!posts[this.ID]) {
posts.push(this);
}
@ -5055,8 +5050,10 @@
},
toggle: function() {
var container, containers, node, post, replies, reply, thread, _i, _j, _k, _len, _len1, _len2, _ref;
Unread.posts = new RandomAccessList;
Unread.ready();
if (Conf['Unread Count']) {
Unread.posts = new RandomAccessList;
Unread.ready();
}
thread = $('.thread');
replies = $$('.thread > .replyContainer, .threadContainer > .replyContainer', thread);
QuoteThreading.enabled = this.checked;
@ -5094,7 +5091,9 @@
$.rmClass(post, 'threadOP');
}
}
return Unread.update(true);
if (Conf['Unread Count']) {
return Unread.read();
}
},
kb: function() {
var control;

View File

@ -19,17 +19,17 @@ class RandomAccessList
@rmi item
{next} = root
next.prev = item
root.next = next.prev = item
item.next = next
root.next = item
item.prev = root
prepend: (item) ->
{ID} = item
@push item unless @[ID]
{first} = @
item.next = first unless @ is first
first.prev = item if first
return if item is first
item.next = first
first.prev = item
@first = item
delete item.prev
@ -52,7 +52,7 @@ class RandomAccessList
@length--
@rmi item
delete item.next
delete item.previous
delete item.prev
rmi: (item) ->
{prev, next} = item

View File

@ -7,7 +7,7 @@ Unread =
id: 'unread-line'
@posts = new RandomAccessList
@postsQuotingYou = []
@qr = if QR.db
({board, thread, ID}) ->
data =
@ -37,8 +37,7 @@ Unread =
ready: ->
$.off d, '4chanXInitFinished', Unread.ready
posts = []
for ID, post of Unread.thread.posts
posts.push post if post.isReply
posts.push post for ID, post of Unread.thread.posts when post.isReply
Unread.addPosts posts
QuoteThreading.setup() if Conf['Quote Threading']
Unread.scroll() if Conf['Scroll to Last Read Post']
@ -148,7 +147,7 @@ Unread =
if Conf['Mark Quotes of You'] and post.info.yours
QuoteYou.lastRead = post.nodes.root
posts.rm ID
if post is posts.first
c.log posts
break

View File

@ -26,42 +26,32 @@ QuoteThreading =
setup: ->
$.off d, '4chanXInitFinished', QuoteThreading.setup
{posts} = g
post.cb.call post for ID, post of posts when post.cb
post.cb.call post for ID, post of g.posts when post.cb
QuoteThreading.hasRun = true
node: ->
return if @isClone or not QuoteThreading.enabled or @thread.OP is @
{replies} = Unread
{quotes, ID, fullID} = @
{posts} = g
return if !(post = posts[fullID]) or post.isHidden # Filtered
uniq = {}
keys = []
len = "#{g.BOARD}".length + 1
for quote in quotes
qid = quote
continue unless qid[len..] < ID
if qid of posts
uniq[qid[len..]] = true
for quote in quotes when quote[len..] < ID
keys.push quote if quote of posts
keys = Object.keys uniq
return unless keys.length is 1
@threaded = "#{g.BOARD}.#{keys[0]}"
@threaded = keys[0]
@cb = QuoteThreading.nodeinsert
nodeinsert: ->
post = g.posts[@threaded]
{posts} = Unread
@threaded
@cb
return false if @thread.OP is post
if QuoteThreading.hasRun
@ -69,7 +59,7 @@ QuoteThreading =
{bottom, top} = post.nodes.root.getBoundingClientRect()
# Post is unread or is fully visible.
return false unless posts[post.ID] or ((bottom < height) and (top > 0))
return false unless posts?[post.ID] or ((bottom < height) and (top > 0))
root = post.nodes.root
unless $.hasClass root, 'threadOP'
@ -82,6 +72,8 @@ QuoteThreading =
$.add threadContainer, @nodes.root
return true if not Conf['Unread Count'] or @ID < Unread.lastReadPost
posts.push @ unless posts[@ID]
if posts[post.ID]
@ -91,12 +83,13 @@ QuoteThreading =
posts.after posts[ID], @
else
posts.prepend @
return true
toggle: ->
Unread.posts = new RandomAccessList
Unread.ready()
if Conf['Unread Count']
Unread.posts = new RandomAccessList
Unread.ready()
thread = $ '.thread'
replies = $$ '.thread > .replyContainer, .threadContainer > .replyContainer', thread
@ -120,7 +113,7 @@ QuoteThreading =
containers = $$ '.threadContainer', thread
$.rm container for container in containers
$.rmClass post, 'threadOP' for post in $$ '.threadOP'
Unread.update true
Unread.read() if Conf['Unread Count']
kb: ->
control = $.id 'threadingControl'