Fuse OP and Cross Thread quote indicators callbacks. This is somewhat faster.

This commit is contained in:
Nicolas Stepien 2012-02-17 22:20:49 +01:00
parent acdd6af479
commit 0181eb7532
2 changed files with 27 additions and 55 deletions

View File

@ -71,7 +71,7 @@
*/ */
(function() { (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; __slice = Array.prototype.slice;
config = { config = {
@ -1368,7 +1368,7 @@
if (e != null) e.preventDefault(); if (e != null) e.preventDefault();
qr.open(); qr.open();
if (!g.REPLY) { 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); id = this.previousElementSibling.hash.slice(1);
text = ">>" + id + "\n"; text = ">>" + id + "\n";
@ -3047,7 +3047,7 @@
} }
} else { } else {
qp.innerHTML = "Loading " + id + "..."; 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() { $.cache(this.pathname, (function() {
return quotePreview.parse(this, id, threadID); return quotePreview.parse(this, id, threadID);
})); }));
@ -3094,47 +3094,26 @@
} }
}; };
quoteOP = { quoteIndicators = {
init: function() { init: function() {
return g.callbacks.push(this.node); return g.callbacks.push(this.node);
}, },
node: function(root) { node: function(root) {
var quote, tid, _i, _len, _ref, _results; var path, quote, tid, _i, _len, _ref;
if (root.className === 'inline') return; 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); _ref = $$('.quotelink', root);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
if (quote.hash.slice(1) === tid) { if (conf['Indicate OP quote'] && quote.hash.slice(1) === tid) {
_results.push(quote.innerHTML += '&nbsp;(OP)'); quote.innerHTML += '&nbsp;(OP)';
} else { return;
_results.push(void 0); }
path = quote.pathname;
if (conf['Indicate Cross-thread Quotes'] && path.lastIndexOf("/" + tid) === -1 && path.indexOf("/" + g.BOARD + "/") === 0) {
quote.innerHTML += '&nbsp;(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 += '&nbsp;(Cross-thread)');
} else {
_results.push(void 0);
}
}
return _results;
} }
}; };
@ -3584,8 +3563,9 @@
if (conf['Quote Inline']) quoteInline.init(); if (conf['Quote Inline']) quoteInline.init();
if (conf['Quote Preview']) quotePreview.init(); if (conf['Quote Preview']) quotePreview.init();
if (conf['Quote Backlinks']) quoteBacklink.init(); if (conf['Quote Backlinks']) quoteBacklink.init();
if (conf['Indicate OP quote']) quoteOP.init(); if (conf['Indicate OP quote'] || conf['Indicate Cross-thread Quotes']) {
if (conf['Indicate Cross-thread Quotes']) quoteDR.init(); quoteIndicators.init();
}
if (conf['Fix XXX\'d Post Numbers']) unxify.init(); if (conf['Fix XXX\'d Post Numbers']) unxify.init();
if (conf['Quick Reply'] && conf['Hide Original Post Form']) { if (conf['Quick Reply'] && conf['Hide Original Post Form']) {
Main.css += 'form[name=post] { display: none; }'; Main.css += 'form[name=post] { display: none; }';

View File

@ -1013,7 +1013,7 @@ qr =
e?.preventDefault() e?.preventDefault()
qr.open() qr.open()
unless g.REPLY 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 # Make sure we get the correct number, even with XXX censors
id = @previousElementSibling.hash[1..] id = @previousElementSibling.hash[1..]
@ -2391,7 +2391,7 @@ quotePreview =
quote.className = 'forwardlink' quote.className = 'forwardlink'
else else
qp.innerHTML = "Loading #{id}..." 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) $.cache @pathname, (-> quotePreview.parse @, id, threadID)
ui.hover e ui.hover e
$.on @, 'mousemove', ui.hover $.on @, 'mousemove', ui.hover
@ -2427,26 +2427,21 @@ quotePreview =
if conf['Time Formatting'] if conf['Time Formatting']
Time.node qp Time.node qp
quoteOP = quoteIndicators =
init: -> init: ->
g.callbacks.push @node g.callbacks.push @node
node: (root) -> node: (root) ->
return if root.className is 'inline' 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 for quote in $$ '.quotelink', root
if quote.hash[1..] is tid if conf['Indicate OP quote'] and quote.hash[1..] is tid
quote.innerHTML += '&nbsp;(OP)' quote.innerHTML += '&nbsp;(OP)'
return
quoteDR = path = quote.pathname
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
#if quote leads to a different thread id and is located on the same board (index 0) #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 += '&nbsp;(Cross-thread)' quote.innerHTML += '&nbsp;(Cross-thread)'
return
reportButton = reportButton =
init: -> init: ->
@ -2826,11 +2821,8 @@ Main =
if conf['Quote Backlinks'] if conf['Quote Backlinks']
quoteBacklink.init() quoteBacklink.init()
if conf['Indicate OP quote'] if conf['Indicate OP quote'] or conf['Indicate Cross-thread Quotes']
quoteOP.init() quoteIndicators.init()
if conf['Indicate Cross-thread Quotes']
quoteDR.init()
if conf['Fix XXX\'d Post Numbers'] if conf['Fix XXX\'d Post Numbers']
unxify.init() unxify.init()