From ceef9f9edc746132f6b514a13580b3b628bfe12d Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 17 Aug 2014 18:50:21 -0700 Subject: [PATCH] Fix a bunch of Unread features. --- LICENSE | 2 +- builds/appchan-x.user.js | 65 +++++++++++++++++++------------- builds/crx/script.js | 65 +++++++++++++++++++------------- src/General/lib/simpledict.class | 2 + src/Linkification/Linkify.coffee | 2 +- src/Monitoring/Unread.coffee | 41 +++++++++++--------- 6 files changed, 104 insertions(+), 73 deletions(-) diff --git a/LICENSE b/LICENSE index 51f137da2..66e462657 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* appchan x - Version 2.9.33 - 2014-07-31 +* appchan x - Version 2.9.33 - 2014-08-17 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index b919bd696..f12b3fcd8 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -28,7 +28,7 @@ // ==/UserScript== /* -* appchan x - Version 2.9.33 - 2014-07-31 +* appchan x - Version 2.9.33 - 2014-08-17 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -4107,6 +4107,10 @@ } }; + SimpleDict.prototype.first = function() { + return this[this.keys[0]]; + }; + SimpleDict.prototype.forEach = function(fn) { var key, _i, _len, _ref; _ref = __slice.call(this.keys); @@ -8411,7 +8415,7 @@ return el.textContent = "ERROR " + status; } files = this.response.files; - _ref = ['video/mp4', 'video/webm', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'audio/mpeg', 'audio/ogg']; + _ref = ['video/webm', 'video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'audio/mpeg', 'audio/ogg']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { type = _ref[_i]; for (_j = 0, _len1 = files.length; _j < _len1; _j++) { @@ -12899,11 +12903,12 @@ if (hr = Unread.hr, Unread) { $.rm(hr); } - _ref = ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost']; + _ref = ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { name = _ref[_i]; delete this[name]; } + this.lastReadPost = 0; $.off(d, '4chanXInitFinished', this.ready); $.off(d, 'ThreadUpdate', this.onUpdate); $.off(d, 'scroll visibilitychange', this.read); @@ -12928,23 +12933,29 @@ } }, ready: function() { - var posts; + var post, posts; $.off(d, '4chanXInitFinished', Unread.ready); - if (!Conf['Quote Threading']) { - posts = []; - Unread.thread.posts.forEach(function(post) { - if (post.isReply) { - return posts.push(post); - } - }); - Unread.addPosts(posts); - } - if (Conf['Quote Threading']) { - QuoteThreading.force(); - } - if (Conf['Scroll to Last Read Post']) { - return Unread.scroll(); - } + posts = Unread.thread.posts; + post = posts.first().nodes.root; + return $.asap((function() { + return post.getBoundingClientRect().bottom; + }), function() { + var arr; + if (Conf['Quote Threading']) { + QuoteThreading.force(); + } else { + arr = []; + posts.forEach(function(post) { + if (post.isReply) { + return arr.push(post); + } + }); + Unread.addPosts(arr); + } + if (Conf['Scroll to Last Read Post']) { + return setTimeout(Unread.scroll, 200); + } + }); }, scroll: function() { var down, hash, keys, post, posts, root; @@ -12977,13 +12988,14 @@ threadID: Unread.thread.ID, defaultValue: 0 }); - if (!(Unread.lastReadPost < lastReadPost)) { + if (Unread.lastReadPost > lastReadPost) { return; } Unread.lastReadPost = lastReadPost; post = Unread.posts.first; while (post) { - if ((ID = post.ID, post) > Unread.lastReadPost) { + ID = post.ID; + if (ID > lastReadPost) { break; } post = post.next; @@ -13088,11 +13100,10 @@ return arr.splice(0, i); }, read: $.debounce(100, function(e) { - var ID, data, height, post, posts; + var ID, data, post, posts; if (d.hidden || !Unread.posts.length) { return; } - height = doc.clientHeight; posts = Unread.posts; while (post = posts.first) { if (!(Header.getBottomOf(post.data.nodes.root) > -1)) { @@ -13111,7 +13122,7 @@ if (!ID) { return; } - if (Unread.lastReadPost < ID || !Unread.lastReadPost) { + if (Unread.lastReadPost < ID) { Unread.lastReadPost = ID; } Unread.saveLastReadPost(); @@ -13203,7 +13214,7 @@ } return Redirect.data = o; }, - archives: [{"uid":0,"name":"Foolz","domain":"archive.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["a","biz","c","co","diy","gd","int","jp","m","out","po","sci","sp","tg","tv","vg","vp","vr","wsg"],"files":["a","biz","c","co","diy","gd","jp","m","po","sci","tg","vg","vp","vr","wsg"]},{"uid":1,"name":"NSFW Foolz","domain":"nsfw.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["u"],"files":["u"]},{"uid":3,"name":"4plebs Archive","domain":"archive.4plebs.org","http":true,"https":true,"software":"foolfuuka","boards":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"],"files":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"]},{"uid":4,"name":"Nyafuu","domain":"archive.nyafuu.org","http":true,"https":true,"software":"foolfuuka","boards":["c","e","w","wg"],"files":["c","e","w","wg"]},{"uid":5,"name":"Love is Over","domain":"archive.loveisover.me","http":true,"https":true,"software":"foolfuuka","boards":["d","i","lgbt"],"files":["d","i","lgbt"]},{"uid":8,"name":"Rebecca Black Tech","domain":"archive.rebeccablacktech.com","http":false,"https":true,"software":"fuuka","boards":["cgl","g","mu","w"],"files":["cgl","g","mu","w"]},{"uid":9,"name":"Heinessen","domain":"archive.heinessen.com","http":true,"https":false,"software":"fuuka","boards":["an","fit","k","mlp","r9k","toy"],"files":["an","fit","k","mlp","r9k","toy"]},{"uid":10,"name":"warosu","domain":"warosu.org","http":false,"https":true,"software":"fuuka","boards":["3","biz","cgl","ck","diy","fa","g","ic","jp","lit","sci","tg","vr"],"files":["3","biz","cgl","ck","diy","fa","ic","jp","lit","sci","tg","vr"]},{"uid":15,"name":"fgts","domain":"fgts.jp","http":true,"https":true,"software":"foolfuuka","boards":["asp","cm","h","hc","hm","n","p","r","s","soc","y"],"files":["asp","cm","h","hc","hm","n","p","r","s","soc","y"]},{"uid":16,"name":"maware","domain":"archive.mawa.re","http":true,"https":false,"software":"foolfuuka","boards":["t"],"files":["t"]},{"uid":19,"name":"Deniable Plausibility","domain":"boards.deniableplausibility.net","http":true,"https":false,"software":"foolfuuka","boards":["v","vg"],"files":["v","vg"]},{"uid":13,"name":"Foolz Beta","domain":"beta.foolz.us","http":true,"https":true,"withCredentials":true,"software":"foolfuuka","boards":["a","biz","c","co","d","diy","gd","h","i","int","jp","m","out","po","s4s","sci","sp","tg","tv","u","v","vg","vp","vr","wsg"],"files":["a","biz","c","co","d","diy","gd","h","i","jp","m","po","s4s","sci","tg","u","v","vg","vp","vr","wsg"]}], + archives: [{"uid":0,"name":"Foolz","domain":"archive.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["a","biz","c","co","diy","gd","int","jp","m","out","po","sci","sp","tg","tv","vg","vp","vr","wsg"],"files":["a","biz","c","co","diy","gd","jp","m","po","sci","tg","vg","vp","vr","wsg"]},{"uid":1,"name":"NSFW Foolz","domain":"nsfw.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["u"],"files":["u"]},{"uid":3,"name":"4plebs Archive","domain":"archive.4plebs.org","http":true,"https":true,"software":"foolfuuka","boards":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"],"files":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"]},{"uid":4,"name":"Nyafuu","domain":"archive.nyafuu.org","http":true,"https":true,"software":"foolfuuka","boards":["c","e","w","wg"],"files":["c","e","w","wg"]},{"uid":5,"name":"Love is Over","domain":"archive.loveisover.me","http":true,"https":true,"software":"foolfuuka","boards":["d","i","lgbt","e","wg"],"files":["d","i","lgbt","e","wg"]},{"uid":8,"name":"Rebecca Black Tech","domain":"archive.rebeccablacktech.com","http":false,"https":true,"software":"fuuka","boards":["cgl","g","mu","w"],"files":["cgl","g","mu","w"]},{"uid":9,"name":"Heinessen","domain":"archive.heinessen.com","http":true,"https":false,"software":"fuuka","boards":["an","fit","k","mlp","r9k","toy"],"files":["an","fit","k","mlp","r9k","toy"]},{"uid":10,"name":"warosu","domain":"warosu.org","http":false,"https":true,"software":"fuuka","boards":["3","biz","cgl","ck","diy","fa","g","ic","jp","lit","sci","tg","vr"],"files":["3","biz","cgl","ck","diy","fa","ic","jp","lit","sci","tg","vr"]},{"uid":15,"name":"fgts","domain":"fgts.jp","http":true,"https":true,"software":"foolfuuka","boards":["asp","cm","h","hc","hm","n","p","r","s","soc","y"],"files":["asp","cm","h","hc","hm","n","p","r","s","soc","y"]},{"uid":16,"name":"maware","domain":"archive.mawa.re","http":true,"https":false,"software":"foolfuuka","boards":["t"],"files":["t"]},{"uid":19,"name":"Deniable Plausibility","domain":"boards.deniableplausibility.net","http":true,"https":false,"software":"foolfuuka","boards":["v","vg"],"files":["v","vg"]},{"uid":13,"name":"Foolz Beta","domain":"beta.foolz.us","http":true,"https":true,"withCredentials":true,"software":"foolfuuka","boards":["a","biz","c","co","d","diy","gd","h","i","int","jp","m","out","po","s4s","sci","sp","tg","tv","u","v","vg","vp","vr","wsg"],"files":["a","biz","c","co","d","diy","gd","h","i","jp","m","po","s4s","sci","tg","u","v","vg","vp","vr","wsg"]}], to: function(dest, data) { var archive; archive = (dest === 'search' || dest === 'board' ? Redirect.data.thread : Redirect.data[dest])[data.boardID]; @@ -13303,8 +13314,8 @@ "http": true, "https": true, "software": "foolfuuka", - "boards": ["d", "i", "lgbt"], - "files": ["d", "i", "lgbt"] + "boards": ["d", "i", "lgbt", "e", "wg"], + "files": ["d", "i", "lgbt", "e", "wg"] }, { "uid": 8, "name": "Rebecca Black Tech", diff --git a/builds/crx/script.js b/builds/crx/script.js index 0c0b11a53..9cbe37f95 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* appchan x - Version 2.9.33 - 2014-07-31 +* appchan x - Version 2.9.33 - 2014-08-17 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -4156,6 +4156,10 @@ } }; + SimpleDict.prototype.first = function() { + return this[this.keys[0]]; + }; + SimpleDict.prototype.forEach = function(fn) { var key, _i, _len, _ref; _ref = __slice.call(this.keys); @@ -8455,7 +8459,7 @@ return el.textContent = "ERROR " + status; } files = this.response.files; - _ref = ['video/mp4', 'video/webm', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'audio/mpeg', 'audio/ogg']; + _ref = ['video/webm', 'video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'audio/mpeg', 'audio/ogg']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { type = _ref[_i]; for (_j = 0, _len1 = files.length; _j < _len1; _j++) { @@ -12905,11 +12909,12 @@ if (hr = Unread.hr, Unread) { $.rm(hr); } - _ref = ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost']; + _ref = ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { name = _ref[_i]; delete this[name]; } + this.lastReadPost = 0; $.off(d, '4chanXInitFinished', this.ready); $.off(d, 'ThreadUpdate', this.onUpdate); $.off(d, 'scroll visibilitychange', this.read); @@ -12934,23 +12939,29 @@ } }, ready: function() { - var posts; + var post, posts; $.off(d, '4chanXInitFinished', Unread.ready); - if (!Conf['Quote Threading']) { - posts = []; - Unread.thread.posts.forEach(function(post) { - if (post.isReply) { - return posts.push(post); - } - }); - Unread.addPosts(posts); - } - if (Conf['Quote Threading']) { - QuoteThreading.force(); - } - if (Conf['Scroll to Last Read Post']) { - return Unread.scroll(); - } + posts = Unread.thread.posts; + post = posts.first().nodes.root; + return $.asap((function() { + return post.getBoundingClientRect().bottom; + }), function() { + var arr; + if (Conf['Quote Threading']) { + QuoteThreading.force(); + } else { + arr = []; + posts.forEach(function(post) { + if (post.isReply) { + return arr.push(post); + } + }); + Unread.addPosts(arr); + } + if (Conf['Scroll to Last Read Post']) { + return setTimeout(Unread.scroll, 200); + } + }); }, scroll: function() { var down, hash, keys, post, posts, root; @@ -12983,13 +12994,14 @@ threadID: Unread.thread.ID, defaultValue: 0 }); - if (!(Unread.lastReadPost < lastReadPost)) { + if (Unread.lastReadPost > lastReadPost) { return; } Unread.lastReadPost = lastReadPost; post = Unread.posts.first; while (post) { - if ((ID = post.ID, post) > Unread.lastReadPost) { + ID = post.ID; + if (ID > lastReadPost) { break; } post = post.next; @@ -13094,11 +13106,10 @@ return arr.splice(0, i); }, read: $.debounce(100, function(e) { - var ID, data, height, post, posts; + var ID, data, post, posts; if (d.hidden || !Unread.posts.length) { return; } - height = doc.clientHeight; posts = Unread.posts; while (post = posts.first) { if (!(Header.getBottomOf(post.data.nodes.root) > -1)) { @@ -13117,7 +13128,7 @@ if (!ID) { return; } - if (Unread.lastReadPost < ID || !Unread.lastReadPost) { + if (Unread.lastReadPost < ID) { Unread.lastReadPost = ID; } Unread.saveLastReadPost(); @@ -13208,7 +13219,7 @@ } return Redirect.data = o; }, - archives: [{"uid":0,"name":"Foolz","domain":"archive.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["a","biz","c","co","diy","gd","int","jp","m","out","po","sci","sp","tg","tv","vg","vp","vr","wsg"],"files":["a","biz","c","co","diy","gd","jp","m","po","sci","tg","vg","vp","vr","wsg"]},{"uid":1,"name":"NSFW Foolz","domain":"nsfw.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["u"],"files":["u"]},{"uid":3,"name":"4plebs Archive","domain":"archive.4plebs.org","http":true,"https":true,"software":"foolfuuka","boards":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"],"files":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"]},{"uid":4,"name":"Nyafuu","domain":"archive.nyafuu.org","http":true,"https":true,"software":"foolfuuka","boards":["c","e","w","wg"],"files":["c","e","w","wg"]},{"uid":5,"name":"Love is Over","domain":"archive.loveisover.me","http":true,"https":true,"software":"foolfuuka","boards":["d","i","lgbt"],"files":["d","i","lgbt"]},{"uid":8,"name":"Rebecca Black Tech","domain":"archive.rebeccablacktech.com","http":false,"https":true,"software":"fuuka","boards":["cgl","g","mu","w"],"files":["cgl","g","mu","w"]},{"uid":9,"name":"Heinessen","domain":"archive.heinessen.com","http":true,"https":false,"software":"fuuka","boards":["an","fit","k","mlp","r9k","toy"],"files":["an","fit","k","mlp","r9k","toy"]},{"uid":10,"name":"warosu","domain":"warosu.org","http":false,"https":true,"software":"fuuka","boards":["3","biz","cgl","ck","diy","fa","g","ic","jp","lit","sci","tg","vr"],"files":["3","biz","cgl","ck","diy","fa","ic","jp","lit","sci","tg","vr"]},{"uid":15,"name":"fgts","domain":"fgts.jp","http":true,"https":true,"software":"foolfuuka","boards":["asp","cm","h","hc","hm","n","p","r","s","soc","y"],"files":["asp","cm","h","hc","hm","n","p","r","s","soc","y"]},{"uid":16,"name":"maware","domain":"archive.mawa.re","http":true,"https":false,"software":"foolfuuka","boards":["t"],"files":["t"]},{"uid":19,"name":"Deniable Plausibility","domain":"boards.deniableplausibility.net","http":true,"https":false,"software":"foolfuuka","boards":["v","vg"],"files":["v","vg"]},{"uid":13,"name":"Foolz Beta","domain":"beta.foolz.us","http":true,"https":true,"withCredentials":true,"software":"foolfuuka","boards":["a","biz","c","co","d","diy","gd","h","i","int","jp","m","out","po","s4s","sci","sp","tg","tv","u","v","vg","vp","vr","wsg"],"files":["a","biz","c","co","d","diy","gd","h","i","jp","m","po","s4s","sci","tg","u","v","vg","vp","vr","wsg"]}], + archives: [{"uid":0,"name":"Foolz","domain":"archive.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["a","biz","c","co","diy","gd","int","jp","m","out","po","sci","sp","tg","tv","vg","vp","vr","wsg"],"files":["a","biz","c","co","diy","gd","jp","m","po","sci","tg","vg","vp","vr","wsg"]},{"uid":1,"name":"NSFW Foolz","domain":"nsfw.foolz.us","http":true,"https":true,"software":"foolfuuka","boards":["u"],"files":["u"]},{"uid":3,"name":"4plebs Archive","domain":"archive.4plebs.org","http":true,"https":true,"software":"foolfuuka","boards":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"],"files":["adv","f","hr","o","pol","s4s","tg","trv","tv","x"]},{"uid":4,"name":"Nyafuu","domain":"archive.nyafuu.org","http":true,"https":true,"software":"foolfuuka","boards":["c","e","w","wg"],"files":["c","e","w","wg"]},{"uid":5,"name":"Love is Over","domain":"archive.loveisover.me","http":true,"https":true,"software":"foolfuuka","boards":["d","i","lgbt","e","wg"],"files":["d","i","lgbt","e","wg"]},{"uid":8,"name":"Rebecca Black Tech","domain":"archive.rebeccablacktech.com","http":false,"https":true,"software":"fuuka","boards":["cgl","g","mu","w"],"files":["cgl","g","mu","w"]},{"uid":9,"name":"Heinessen","domain":"archive.heinessen.com","http":true,"https":false,"software":"fuuka","boards":["an","fit","k","mlp","r9k","toy"],"files":["an","fit","k","mlp","r9k","toy"]},{"uid":10,"name":"warosu","domain":"warosu.org","http":false,"https":true,"software":"fuuka","boards":["3","biz","cgl","ck","diy","fa","g","ic","jp","lit","sci","tg","vr"],"files":["3","biz","cgl","ck","diy","fa","ic","jp","lit","sci","tg","vr"]},{"uid":15,"name":"fgts","domain":"fgts.jp","http":true,"https":true,"software":"foolfuuka","boards":["asp","cm","h","hc","hm","n","p","r","s","soc","y"],"files":["asp","cm","h","hc","hm","n","p","r","s","soc","y"]},{"uid":16,"name":"maware","domain":"archive.mawa.re","http":true,"https":false,"software":"foolfuuka","boards":["t"],"files":["t"]},{"uid":19,"name":"Deniable Plausibility","domain":"boards.deniableplausibility.net","http":true,"https":false,"software":"foolfuuka","boards":["v","vg"],"files":["v","vg"]},{"uid":13,"name":"Foolz Beta","domain":"beta.foolz.us","http":true,"https":true,"withCredentials":true,"software":"foolfuuka","boards":["a","biz","c","co","d","diy","gd","h","i","int","jp","m","out","po","s4s","sci","sp","tg","tv","u","v","vg","vp","vr","wsg"],"files":["a","biz","c","co","d","diy","gd","h","i","jp","m","po","s4s","sci","tg","u","v","vg","vp","vr","wsg"]}], to: function(dest, data) { var archive; archive = (dest === 'search' || dest === 'board' ? Redirect.data.thread : Redirect.data[dest])[data.boardID]; @@ -13308,8 +13319,8 @@ "http": true, "https": true, "software": "foolfuuka", - "boards": ["d", "i", "lgbt"], - "files": ["d", "i", "lgbt"] + "boards": ["d", "i", "lgbt", "e", "wg"], + "files": ["d", "i", "lgbt", "e", "wg"] }, { "uid": 8, "name": "Rebecca Black Tech", diff --git a/src/General/lib/simpledict.class b/src/General/lib/simpledict.class index 6c6b3edfd..be2f4f814 100644 --- a/src/General/lib/simpledict.class +++ b/src/General/lib/simpledict.class @@ -12,6 +12,8 @@ class SimpleDict if (i = @keys.indexOf key) isnt -1 @keys.splice i, 1 delete @[key] + + first: -> @[@keys[0]] forEach: (fn) -> fn @[key] for key in [@keys...] diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index e65f42389..df965c0d8 100755 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -293,7 +293,7 @@ Linkify = {status} = @ return el.textContent = "ERROR #{status}" unless status in [200, 304] {files} = @response - for type in ['video/mp4', 'video/webm', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'audio/mpeg', 'audio/ogg'] + for type in ['video/webm', 'video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'audio/mpeg', 'audio/ogg'] for file in files if file.type is type embed = file diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 856d18cc3..88e021cfb 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -18,7 +18,8 @@ Unread = Unread.db.disconnect() $.rm hr if {hr} = Unread - delete @[name] for name in ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost'] + delete @[name] for name in ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title'] + @lastReadPost = 0 $.off d, '4chanXInitFinished', @ready $.off d, 'ThreadUpdate', @onUpdate @@ -31,8 +32,8 @@ Unread = Unread.thread = @ Unread.title = d.title Unread.lastReadPost = Unread.db.get - boardID: @board.ID - threadID: @ID + boardID: @board.ID + threadID: @ID defaultValue: 0 $.on d, '4chanXInitFinished', Unread.ready $.on d, 'ThreadUpdate', Unread.onUpdate @@ -41,12 +42,17 @@ Unread = ready: -> $.off d, '4chanXInitFinished', Unread.ready - unless Conf['Quote Threading'] - posts = [] - Unread.thread.posts.forEach (post) -> posts.push post if post.isReply - Unread.addPosts posts - QuoteThreading.force() if Conf['Quote Threading'] - Unread.scroll() if Conf['Scroll to Last Read Post'] + {posts} = Unread.thread + post = posts.first().nodes.root + # XXX I'm guessing the browser isn't reflowing fast enough? + $.asap (-> post.getBoundingClientRect().bottom), -> + if Conf['Quote Threading'] + QuoteThreading.force() + else + arr = [] + posts.forEach (post) -> arr.push post if post.isReply + Unread.addPosts arr + setTimeout Unread.scroll, 200 if Conf['Scroll to Last Read Post'] scroll: -> # Let the header's onload callback handle it. @@ -68,15 +74,17 @@ Unread = sync: -> lastReadPost = Unread.db.get - boardID: Unread.thread.board.ID - threadID: Unread.thread.ID + boardID: Unread.thread.board.ID + threadID: Unread.thread.ID defaultValue: 0 - return unless Unread.lastReadPost < lastReadPost - Unread.lastReadPost = lastReadPost + return if Unread.lastReadPost > lastReadPost + + Unread.lastReadPost = lastReadPost post = Unread.posts.first while post - break if ({ID} = post) > Unread.lastReadPost + {ID} = post + break if ID > lastReadPost post = post.next Unread.posts.rm ID @@ -147,9 +155,8 @@ Unread = read: $.debounce 100, (e) -> return if d.hidden or !Unread.posts.length - height = doc.clientHeight - {posts} = Unread + while post = posts.first break unless Header.getBottomOf(post.data.nodes.root) > -1 # post is not completely read {ID, data} = post @@ -164,7 +171,7 @@ Unread = return unless ID - Unread.lastReadPost = ID if Unread.lastReadPost < ID or !Unread.lastReadPost + Unread.lastReadPost = ID if Unread.lastReadPost < ID Unread.saveLastReadPost() Unread.readArray Unread.postsQuotingYou Unread.update() if e