diff --git a/4chan_x.user.js b/4chan_x.user.js index 810308c25..10c7c4c31 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -71,7 +71,7 @@ */ (function() { - var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, SECOND, Time, VERSION, anonymize, conf, config, d, engine, expandComment, expandThread, filter, flatten, g, getTitle, imgExpand, imgGif, imgHover, key, keybinds, log, nav, options, qr, quoteBacklink, quoteDR, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, unxify, updater, val, watcher, _base, + var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, SECOND, Time, VERSION, anonymize, conf, config, d, engine, expandComment, expandThread, filter, flatten, g, getTitle, imgExpand, imgGif, imgHover, key, keybinds, log, nav, options, qr, quoteBacklink, quoteIndicators, quoteInline, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, unxify, updater, val, watcher, _base, __slice = Array.prototype.slice; config = { @@ -1368,7 +1368,7 @@ if (e != null) e.preventDefault(); qr.open(); if (!g.REPLY) { - $('select', qr.el).value = $.x('ancestor::div[@class="thread"]/div', this).id; + $('select', qr.el).value = $.x('ancestor::div', this).firstChild.id; } id = this.previousElementSibling.hash.slice(1); text = ">>" + id + "\n"; @@ -3047,7 +3047,7 @@ } } else { qp.innerHTML = "Loading " + id + "..."; - threadID = this.pathname.split('/').pop() || $.x('ancestor::div[@class="thread"]/div', this).id; + threadID = this.pathname.split('/').pop() || $.x('ancestor::div', this).firstChild.id; $.cache(this.pathname, (function() { return quotePreview.parse(this, id, threadID); })); @@ -3094,47 +3094,26 @@ } }; - quoteOP = { + quoteIndicators = { init: function() { return g.callbacks.push(this.node); }, node: function(root) { - var quote, tid, _i, _len, _ref, _results; + var path, quote, tid, _i, _len, _ref; if (root.className === 'inline') return; - tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; + tid = g.THREAD_ID || $.x('ancestor::div', root).firstChild.id; _ref = $$('.quotelink', root); - _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - if (quote.hash.slice(1) === tid) { - _results.push(quote.innerHTML += ' (OP)'); - } else { - _results.push(void 0); + if (conf['Indicate OP quote'] && quote.hash.slice(1) === tid) { + quote.innerHTML += ' (OP)'; + return; + } + path = quote.pathname; + if (conf['Indicate Cross-thread Quotes'] && path.lastIndexOf("/" + tid) === -1 && path.indexOf("/" + g.BOARD + "/") === 0) { + quote.innerHTML += ' (Cross-thread)'; } } - return _results; - } - }; - - quoteDR = { - init: function() { - return g.callbacks.push(this.node); - }, - node: function(root) { - var quote, tid, _i, _len, _ref, _results; - if (root.className === 'inline') return; - tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; - _ref = $$('.quotelink', root); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - quote = _ref[_i]; - if (quote.pathname.indexOf("res/" + tid) === -1 && !quote.pathname.indexOf("/" + g.BOARD + "/res")) { - _results.push(quote.innerHTML += ' (Cross-thread)'); - } else { - _results.push(void 0); - } - } - return _results; } }; @@ -3584,8 +3563,9 @@ if (conf['Quote Inline']) quoteInline.init(); if (conf['Quote Preview']) quotePreview.init(); if (conf['Quote Backlinks']) quoteBacklink.init(); - if (conf['Indicate OP quote']) quoteOP.init(); - if (conf['Indicate Cross-thread Quotes']) quoteDR.init(); + if (conf['Indicate OP quote'] || conf['Indicate Cross-thread Quotes']) { + quoteIndicators.init(); + } if (conf['Fix XXX\'d Post Numbers']) unxify.init(); if (conf['Quick Reply'] && conf['Hide Original Post Form']) { Main.css += 'form[name=post] { display: none; }'; diff --git a/script.coffee b/script.coffee index 2bcf29d6c..1dfa12f0f 100644 --- a/script.coffee +++ b/script.coffee @@ -1013,7 +1013,7 @@ qr = e?.preventDefault() qr.open() unless g.REPLY - $('select', qr.el).value = $.x('ancestor::div[@class="thread"]/div', @).id + $('select', qr.el).value = $.x('ancestor::div', @).firstChild.id # Make sure we get the correct number, even with XXX censors id = @previousElementSibling.hash[1..] @@ -2391,7 +2391,7 @@ quotePreview = quote.className = 'forwardlink' else qp.innerHTML = "Loading #{id}..." - threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', @).id + threadID = @pathname.split('/').pop() or $.x('ancestor::div', @).firstChild.id $.cache @pathname, (-> quotePreview.parse @, id, threadID) ui.hover e $.on @, 'mousemove', ui.hover @@ -2427,26 +2427,21 @@ quotePreview = if conf['Time Formatting'] Time.node qp -quoteOP = +quoteIndicators = init: -> g.callbacks.push @node node: (root) -> return if root.className is 'inline' - tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id + tid = g.THREAD_ID or $.x('ancestor::div', root).firstChild.id for quote in $$ '.quotelink', root - if quote.hash[1..] is tid + if conf['Indicate OP quote'] and quote.hash[1..] is tid quote.innerHTML += ' (OP)' - -quoteDR = - init: -> - g.callbacks.push @node - node: (root) -> - return if root.className is 'inline' - tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id - for quote in $$ '.quotelink', root + return + path = quote.pathname #if quote leads to a different thread id and is located on the same board (index 0) - if quote.pathname.indexOf("res/#{tid}") is -1 and !quote.pathname.indexOf "/#{g.BOARD}/res" + if conf['Indicate Cross-thread Quotes'] and path.lastIndexOf("/#{tid}") is -1 and path.indexOf("/#{g.BOARD}/") is 0 quote.innerHTML += ' (Cross-thread)' + return reportButton = init: -> @@ -2826,11 +2821,8 @@ Main = if conf['Quote Backlinks'] quoteBacklink.init() - if conf['Indicate OP quote'] - quoteOP.init() - - if conf['Indicate Cross-thread Quotes'] - quoteDR.init() + if conf['Indicate OP quote'] or conf['Indicate Cross-thread Quotes'] + quoteIndicators.init() if conf['Fix XXX\'d Post Numbers'] unxify.init()