diff --git a/4chan_x.user.js b/4chan_x.user.js index f3e12ddf5..c52c08547 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3345,12 +3345,6 @@ }, add: function(q, id) { var board, el, i, inline, isBacklink, path, postID, root, threadID; - if (!(isBacklink = /\bbacklink\b/.test(q.className))) { - root = q; - while (root.parentNode.nodeName !== 'BLOCKQUOTE') { - root = root.parentNode; - } - } if (q.host === 'boards.4chan.org') { path = q.pathname.split('/'); board = path[1]; @@ -3366,7 +3360,8 @@ id: "i" + postID, className: el ? 'inline' : 'inline crosspost' }); - $.after((isBacklink ? q.parentNode : root), inline); + root = (isBacklink = /\bbacklink\b/.test(q.className)) ? q.parentNode : $.x('ancestor::*[parent::blockquote][1]', q); + $.after(root, inline); Get.post(board, threadID, postID, inline); if (!el) { return; @@ -3424,7 +3419,7 @@ } }, mouseover: function(e) { - var board, el, parent, path, postID, qp, quote, quoterID, threadID, _i, _len, _ref; + var board, el, path, postID, qp, quote, quoterID, threadID, _i, _len, _ref; if (/\binlined\b/.test(this.className)) { return; } @@ -3489,11 +3484,7 @@ $.addClass(el, 'qphl'); } } - parent = this.parentNode; - while (!parent.id) { - parent = parent.parentNode; - } - quoterID = parent.id.match(/\d+$/)[0]; + quoterID = $.x('ancestor::*[@id][1]', this).id.match(/\d+$/)[0]; _ref = $$('.quotelink, .backlink', qp); for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; diff --git a/script.coffee b/script.coffee index 5bc46fbce..b5278cf15 100644 --- a/script.coffee +++ b/script.coffee @@ -2598,13 +2598,6 @@ QuoteInline = @classList.toggle 'inlined' add: (q, id) -> - # Can't use this because Firefox a shit: - # root = $.x 'ancestor::*[parent::blockquote]', q - unless isBacklink = /\bbacklink\b/.test q.className - root = q - until root.parentNode.nodeName is 'BLOCKQUOTE' - root = root.parentNode - if q.host is 'boards.4chan.org' path = q.pathname.split '/' board = path[1] @@ -2619,7 +2612,12 @@ QuoteInline = inline = $.el 'div', id: "i#{postID}" className: if el then 'inline' else 'inline crosspost' - $.after (if isBacklink then q.parentNode else root), inline + root = + if isBacklink = /\bbacklink\b/.test q.className + q.parentNode + else + $.x 'ancestor::*[parent::blockquote][1]', q + $.after root, inline Get.post board, threadID, postID, inline return unless el @@ -2709,11 +2707,7 @@ QuotePreview = $.addClass el.parentNode, 'qphl' else $.addClass el, 'qphl' - # can't use xpath because >firefox - parent = @parentNode - until parent.id - parent = parent.parentNode - quoterID = parent.id.match(/\d+$/)[0] + quoterID = $.x('ancestor::*[@id][1]', @).id.match(/\d+$/)[0] for quote in $$ '.quotelink, .backlink', qp if quote.hash[2..] is quoterID $.addClass quote, 'forwardlink'