diff --git a/builds/4chan-X.js b/builds/4chan-X.js index 37613c19c..7fbabbc3a 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -1436,18 +1436,22 @@ return Polyfill.visibility(); }, visibility: function() { - var event, prefix, property; - - if ('visibilityState' in document || !(prefix = ('webkitVisibilityState' in document ? 'webkit' : 'mozVisibilityState' in document ? 'moz' : void 0))) { + if (!('webkitHidden' in document)) { return; } - property = prefix + 'VisibilityState'; - event = prefix + 'visibilitychange'; - d.visibilityState = d[property]; - d.hidden = d.visibilityState === 'hidden'; - return $.on(d, event, function() { - d.visibilityState = d[property]; - d.hidden = d.visibilityState === 'hidden'; + Object.defineProperties(HTMLDocument.prototype, { + visibilityState: { + get: function() { + return this.webkitVisibilityState; + } + }, + hidden: { + get: function() { + return this.webkitHidden; + } + } + }); + return $.on(d, 'webkitvisibilitychange', function() { return $.event('visibilitychange'); }); } @@ -3821,12 +3825,16 @@ return Unread.readSinglePost(post); }, rm: function(quotelink, boardID, threadID, postID, context) { - var el, inlined, isBacklink, post, root, _ref; + var el, inlined, isBacklink, post, qroot, root, _ref; isBacklink = $.hasClass(quotelink, 'backlink'); root = QuoteInline.findRoot(quotelink, isBacklink); root = $.x("following-sibling::div[@id='i" + postID + "'][1]", root); + qroot = $.x('ancestor::*[contains(@class,"postContainer")][1]', root); $.rm(root); + if (!$('.inline', qroot)) { + $.rmClass(qroot, 'hasInline'); + } if (!(el = root.firstElementChild)) { return; } @@ -9030,7 +9038,7 @@ } }, hl: function(delta, thread) { - var headRect, next, postEl, rect, replies, reply, root, topMargin, _i, _len; + var axe, headRect, next, postEl, rect, replies, reply, root, topMargin, _i, _len; if (Conf['Fixed Header'] && Conf['Bottom header']) { topMargin = 0; @@ -9043,7 +9051,8 @@ rect = postEl.getBoundingClientRect(); if (rect.bottom >= topMargin && rect.top <= doc.clientHeight) { root = postEl.parentNode; - next = $.x('child::div[contains(@class,"post reply")]', delta === +1 ? root.nextElementSibling : root.previousElementSibling); + axe = delta === +1 ? 'following' : 'preceding'; + next = $.x("" + axe + "-sibling::div[contains(@class,'replyContainer')][1]/child::div[contains(@class,'reply')]", root); if (!next) { this.focus(postEl); return; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 9ad124789..0a0ab69cd 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1432,18 +1432,22 @@ return Polyfill.visibility(); }, visibility: function() { - var event, prefix, property; - - if ('visibilityState' in document || !(prefix = ('webkitVisibilityState' in document ? 'webkit' : 'mozVisibilityState' in document ? 'moz' : void 0))) { + if (!('webkitHidden' in document)) { return; } - property = prefix + 'VisibilityState'; - event = prefix + 'visibilitychange'; - d.visibilityState = d[property]; - d.hidden = d.visibilityState === 'hidden'; - return $.on(d, event, function() { - d.visibilityState = d[property]; - d.hidden = d.visibilityState === 'hidden'; + Object.defineProperties(HTMLDocument.prototype, { + visibilityState: { + get: function() { + return this.webkitVisibilityState; + } + }, + hidden: { + get: function() { + return this.webkitHidden; + } + } + }); + return $.on(d, 'webkitvisibilitychange', function() { return $.event('visibilitychange'); }); } @@ -3817,12 +3821,16 @@ return Unread.readSinglePost(post); }, rm: function(quotelink, boardID, threadID, postID, context) { - var el, inlined, isBacklink, post, root, _ref; + var el, inlined, isBacklink, post, qroot, root, _ref; isBacklink = $.hasClass(quotelink, 'backlink'); root = QuoteInline.findRoot(quotelink, isBacklink); root = $.x("following-sibling::div[@id='i" + postID + "'][1]", root); + qroot = $.x('ancestor::*[contains(@class,"postContainer")][1]', root); $.rm(root); + if (!$('.inline', qroot)) { + $.rmClass(qroot, 'hasInline'); + } if (!(el = root.firstElementChild)) { return; } @@ -9024,7 +9032,7 @@ } }, hl: function(delta, thread) { - var headRect, next, postEl, rect, replies, reply, root, topMargin, _i, _len; + var axe, headRect, next, postEl, rect, replies, reply, root, topMargin, _i, _len; if (Conf['Fixed Header'] && Conf['Bottom header']) { topMargin = 0; @@ -9037,7 +9045,8 @@ rect = postEl.getBoundingClientRect(); if (rect.bottom >= topMargin && rect.top <= doc.clientHeight) { root = postEl.parentNode; - next = $.x('child::div[contains(@class,"post reply")]', delta === +1 ? root.nextElementSibling : root.previousElementSibling); + axe = delta === +1 ? 'following' : 'preceding'; + next = $.x("" + axe + "-sibling::div[contains(@class,'replyContainer')][1]/child::div[contains(@class,'reply')]", root); if (!next) { this.focus(postEl); return; diff --git a/builds/crx/script.js b/builds/crx/script.js index d10370c99..cb4ce5c72 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1434,18 +1434,22 @@ return Polyfill.visibility(); }, visibility: function() { - var event, prefix, property; - - if ('visibilityState' in document || !(prefix = ('webkitVisibilityState' in document ? 'webkit' : 'mozVisibilityState' in document ? 'moz' : void 0))) { + if (!('webkitHidden' in document)) { return; } - property = prefix + 'VisibilityState'; - event = prefix + 'visibilitychange'; - d.visibilityState = d[property]; - d.hidden = d.visibilityState === 'hidden'; - return $.on(d, event, function() { - d.visibilityState = d[property]; - d.hidden = d.visibilityState === 'hidden'; + Object.defineProperties(HTMLDocument.prototype, { + visibilityState: { + get: function() { + return this.webkitVisibilityState; + } + }, + hidden: { + get: function() { + return this.webkitHidden; + } + } + }); + return $.on(d, 'webkitvisibilitychange', function() { return $.event('visibilitychange'); }); } @@ -3819,12 +3823,16 @@ return Unread.readSinglePost(post); }, rm: function(quotelink, boardID, threadID, postID, context) { - var el, inlined, isBacklink, post, root, _ref; + var el, inlined, isBacklink, post, qroot, root, _ref; isBacklink = $.hasClass(quotelink, 'backlink'); root = QuoteInline.findRoot(quotelink, isBacklink); root = $.x("following-sibling::div[@id='i" + postID + "'][1]", root); + qroot = $.x('ancestor::*[contains(@class,"postContainer")][1]', root); $.rm(root); + if (!$('.inline', qroot)) { + $.rmClass(qroot, 'hasInline'); + } if (!(el = root.firstElementChild)) { return; } @@ -9007,7 +9015,7 @@ } }, hl: function(delta, thread) { - var headRect, next, postEl, rect, replies, reply, root, topMargin, _i, _len; + var axe, headRect, next, postEl, rect, replies, reply, root, topMargin, _i, _len; if (Conf['Fixed Header'] && Conf['Bottom header']) { topMargin = 0; @@ -9020,7 +9028,8 @@ rect = postEl.getBoundingClientRect(); if (rect.bottom >= topMargin && rect.top <= doc.clientHeight) { root = postEl.parentNode; - next = $.x('child::div[contains(@class,"post reply")]', delta === +1 ? root.nextElementSibling : root.previousElementSibling); + axe = delta === +1 ? 'following' : 'preceding'; + next = $.x("" + axe + "-sibling::div[contains(@class,'replyContainer')][1]/child::div[contains(@class,'reply')]", root); if (!next) { this.focus(postEl); return; diff --git a/src/General/lib/polyfill.coffee b/src/General/lib/polyfill.coffee index 64224bfc6..5d9ddc124 100644 --- a/src/General/lib/polyfill.coffee +++ b/src/General/lib/polyfill.coffee @@ -3,21 +3,10 @@ Polyfill = Polyfill.visibility() visibility: -> # page visibility API - return if 'visibilityState' of document or not ( - prefix = ( - if 'webkitVisibilityState' of document - 'webkit' - else if 'mozVisibilityState' of document - 'moz' - ) - ) - - property = prefix + 'VisibilityState' - event = prefix + 'visibilitychange' - - d.visibilityState = d[property] - d.hidden = d.visibilityState is 'hidden' - $.on d, event, -> - d.visibilityState = d[property] - d.hidden = d.visibilityState is 'hidden' - $.event 'visibilitychange' + return unless 'webkitHidden' of document + Object.defineProperties HTMLDocument.prototype, + visibilityState: + get: -> @webkitVisibilityState + hidden: + get: -> @webkitHidden + $.on d, 'webkitvisibilitychange', -> $.event 'visibilitychange' diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index 0c4f70f04..303601dca 100644 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -204,8 +204,11 @@ Keybinds = rect = postEl.getBoundingClientRect() if rect.bottom >= topMargin and rect.top <= doc.clientHeight # We're at least partially visible root = postEl.parentNode - next = $.x 'child::div[contains(@class,"post reply")]', - if delta is +1 then root.nextElementSibling else root.previousElementSibling + axe = if delta is +1 + 'following' + else + 'preceding' + next = $.x "#{axe}-sibling::div[contains(@class,'replyContainer')][1]/child::div[contains(@class,'reply')]", root unless next @focus postEl return @@ -228,4 +231,4 @@ Keybinds = return focus: (post) -> - $.addClass post, 'highlight' \ No newline at end of file + $.addClass post, 'highlight'