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

View File

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

View File

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

View File

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

View File

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