From 7c330f39bc8267dc81923dcf316c8b0938d1eb84 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 6 May 2013 14:49:01 -0700 Subject: [PATCH] Quote Hash Navigation --- builds/4chan-X.js | 48 ++++++++++++++++++++++------- builds/4chan-X.user.js | 48 ++++++++++++++++++++++------- builds/crx/script.js | 48 ++++++++++++++++++++++------- src/General/Config.coffee | 4 +++ src/Quotelinks/QuoteBacklink.coffee | 5 +-- src/Quotelinks/QuoteInline.coffee | 28 ++++++++++++++--- 6 files changed, 142 insertions(+), 39 deletions(-) diff --git a/builds/4chan-X.js b/builds/4chan-X.js index bea75262e..53a441212 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -200,6 +200,7 @@ 'Quote Backlinks': [true, 'Add quote backlinks.'], 'OP Backlinks': [true, 'Add backlinks to the OP.'], 'Quote Inlining': [true, 'Inline quoted post on click.'], + 'Quote Hash Navigation': [false, 'Include an extra link after quotes for autoscrolling to quoted posts.'], 'Forward Hiding': [true, 'Hide original posts of inlined backlinks.'], 'Quote Previewing': [true, 'Show quoted post on hover.'], 'Quote Highlighting': [true, 'Highlight the previewed post.'], @@ -3488,7 +3489,7 @@ }); }, firstNode: function() { - var a, clone, container, containers, link, post, quote, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; + var a, clone, container, containers, frag, link, post, quote, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; if (this.isClone || !this.quotes.length) { return; @@ -3511,14 +3512,17 @@ } for (_k = 0, _len2 = containers.length; _k < _len2; _k++) { container = containers[_k]; - link = a.cloneNode(true); + frag = [$.tn(' '), link = a.cloneNode(true)]; if (Conf['Quote Previewing']) { $.on(link, 'mouseover', QuotePreview.mouseover); } if (Conf['Quote Inlining']) { $.on(link, 'click', QuoteInline.toggle); + if (Conf['Quote Hash Navigation']) { + frag.pushArrays(QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + } } - $.add(container, [$.tn(' '), link]); + $.add(container, frag); } } }, @@ -3594,19 +3598,41 @@ if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } + if (Conf['Quote Hash Navigation']) { + this.node = function() { + var link, _i, _len, _ref; + + _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + $.after(link, QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + $.on(link, 'click', QuoteInline.toggle); + } + }; + } else { + this.node = function() { + var link, _i, _len, _ref; + + _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + $.on(link, 'click', QuoteInline.toggle); + } + }; + } return Post.prototype.callbacks.push({ name: 'Quote Inlining', cb: this.node }); }, - node: function() { - var link, _i, _len, _ref; - - _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - link = _ref[_i]; - $.on(link, 'click', QuoteInline.toggle); - } + qiQuote: function(link, hidden) { + return [ + $.tn(' '), $.el('a', { + className: hidden ? 'hashlink filtered' : 'hashlink', + textContent: '#', + href: link.href + }) + ]; }, toggle: function(e) { var boardID, context, postID, threadID, _ref; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 19559bdd3..c933ba3d3 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -201,6 +201,7 @@ 'Quote Backlinks': [true, 'Add quote backlinks.'], 'OP Backlinks': [true, 'Add backlinks to the OP.'], 'Quote Inlining': [true, 'Inline quoted post on click.'], + 'Quote Hash Navigation': [false, 'Include an extra link after quotes for autoscrolling to quoted posts.'], 'Forward Hiding': [true, 'Hide original posts of inlined backlinks.'], 'Quote Previewing': [true, 'Show quoted post on hover.'], 'Quote Highlighting': [true, 'Highlight the previewed post.'], @@ -3484,7 +3485,7 @@ }); }, firstNode: function() { - var a, clone, container, containers, link, post, quote, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; + var a, clone, container, containers, frag, link, post, quote, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; if (this.isClone || !this.quotes.length) { return; @@ -3507,14 +3508,17 @@ } for (_k = 0, _len2 = containers.length; _k < _len2; _k++) { container = containers[_k]; - link = a.cloneNode(true); + frag = [$.tn(' '), link = a.cloneNode(true)]; if (Conf['Quote Previewing']) { $.on(link, 'mouseover', QuotePreview.mouseover); } if (Conf['Quote Inlining']) { $.on(link, 'click', QuoteInline.toggle); + if (Conf['Quote Hash Navigation']) { + frag.pushArrays(QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + } } - $.add(container, [$.tn(' '), link]); + $.add(container, frag); } } }, @@ -3590,19 +3594,41 @@ if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } + if (Conf['Quote Hash Navigation']) { + this.node = function() { + var link, _i, _len, _ref; + + _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + $.after(link, QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + $.on(link, 'click', QuoteInline.toggle); + } + }; + } else { + this.node = function() { + var link, _i, _len, _ref; + + _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + $.on(link, 'click', QuoteInline.toggle); + } + }; + } return Post.prototype.callbacks.push({ name: 'Quote Inlining', cb: this.node }); }, - node: function() { - var link, _i, _len, _ref; - - _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - link = _ref[_i]; - $.on(link, 'click', QuoteInline.toggle); - } + qiQuote: function(link, hidden) { + return [ + $.tn(' '), $.el('a', { + className: hidden ? 'hashlink filtered' : 'hashlink', + textContent: '#', + href: link.href + }) + ]; }, toggle: function(e) { var boardID, context, postID, threadID, _ref; diff --git a/builds/crx/script.js b/builds/crx/script.js index 438b0ef17..0320f4b4c 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -183,6 +183,7 @@ 'Quote Backlinks': [true, 'Add quote backlinks.'], 'OP Backlinks': [true, 'Add backlinks to the OP.'], 'Quote Inlining': [true, 'Inline quoted post on click.'], + 'Quote Hash Navigation': [false, 'Include an extra link after quotes for autoscrolling to quoted posts.'], 'Forward Hiding': [true, 'Hide original posts of inlined backlinks.'], 'Quote Previewing': [true, 'Show quoted post on hover.'], 'Quote Highlighting': [true, 'Highlight the previewed post.'], @@ -3487,7 +3488,7 @@ }); }, firstNode: function() { - var a, clone, container, containers, link, post, quote, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; + var a, clone, container, containers, frag, link, post, quote, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; if (this.isClone || !this.quotes.length) { return; @@ -3510,14 +3511,17 @@ } for (_k = 0, _len2 = containers.length; _k < _len2; _k++) { container = containers[_k]; - link = a.cloneNode(true); + frag = [$.tn(' '), link = a.cloneNode(true)]; if (Conf['Quote Previewing']) { $.on(link, 'mouseover', QuotePreview.mouseover); } if (Conf['Quote Inlining']) { $.on(link, 'click', QuoteInline.toggle); + if (Conf['Quote Hash Navigation']) { + frag.pushArrays(QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + } } - $.add(container, [$.tn(' '), link]); + $.add(container, frag); } } }, @@ -3593,19 +3597,41 @@ if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } + if (Conf['Quote Hash Navigation']) { + this.node = function() { + var link, _i, _len, _ref; + + _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + $.after(link, QuoteInline.qiQuote(link, $.hasClass(link, 'filtered'))); + $.on(link, 'click', QuoteInline.toggle); + } + }; + } else { + this.node = function() { + var link, _i, _len, _ref; + + _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + $.on(link, 'click', QuoteInline.toggle); + } + }; + } return Post.prototype.callbacks.push({ name: 'Quote Inlining', cb: this.node }); }, - node: function() { - var link, _i, _len, _ref; - - _ref = this.nodes.quotelinks.concat(__slice.call(this.nodes.backlinks)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - link = _ref[_i]; - $.on(link, 'click', QuoteInline.toggle); - } + qiQuote: function(link, hidden) { + return [ + $.tn(' '), $.el('a', { + className: hidden ? 'hashlink filtered' : 'hashlink', + textContent: '#', + href: link.href + }) + ]; }, toggle: function(e) { var boardID, context, postID, threadID, _ref; diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 796f1ea9c..d0cb8acc8 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -303,6 +303,10 @@ Config = true 'Inline quoted post on click.' ] + 'Quote Hash Navigation': [ + false + 'Include an extra link after quotes for autoscrolling to quoted posts.' + ] 'Forward Hiding': [ true 'Hide original posts of inlined backlinks.' diff --git a/src/Quotelinks/QuoteBacklink.coffee b/src/Quotelinks/QuoteBacklink.coffee index e663c7394..a974babab 100644 --- a/src/Quotelinks/QuoteBacklink.coffee +++ b/src/Quotelinks/QuoteBacklink.coffee @@ -36,12 +36,13 @@ QuoteBacklink = for clone in post.clones containers.push clone.nodes.backlinkContainer for container in containers - link = a.cloneNode true + frag = [$.tn(' '), link = a.cloneNode true] if Conf['Quote Previewing'] $.on link, 'mouseover', QuotePreview.mouseover if Conf['Quote Inlining'] $.on link, 'click', QuoteInline.toggle - $.add container, [$.tn(' '), link] + frag.pushArrays QuoteInline.qiQuote link, $.hasClass link, 'filtered' if Conf['Quote Hash Navigation'] + $.add container, frag return secondNode: -> if @isClone and (@origin.isReply or Conf['OP Backlinks']) diff --git a/src/Quotelinks/QuoteInline.coffee b/src/Quotelinks/QuoteInline.coffee index c7541aa4a..59e575c24 100644 --- a/src/Quotelinks/QuoteInline.coffee +++ b/src/Quotelinks/QuoteInline.coffee @@ -5,13 +5,32 @@ QuoteInline = if Conf['Comment Expansion'] ExpandComment.callbacks.push @node + if Conf['Quote Hash Navigation'] + @node = -> + for link in @nodes.quotelinks.concat [@nodes.backlinks...] + $.after link, QuoteInline.qiQuote link, $.hasClass link, 'filtered' + $.on link, 'click', QuoteInline.toggle + return + + else + @node = -> + for link in @nodes.quotelinks.concat [@nodes.backlinks...] + $.on link, 'click', QuoteInline.toggle + return + Post::callbacks.push name: 'Quote Inlining' cb: @node - node: -> - for link in @nodes.quotelinks.concat [@nodes.backlinks...] - $.on link, 'click', QuoteInline.toggle - return + + qiQuote: (link, hidden) -> + [ + $.tn(' ') + $.el 'a', + className: if hidden then 'hashlink filtered' else 'hashlink' + textContent: '#' + href: link.href + ] + toggle: (e) -> return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 e.preventDefault() @@ -29,6 +48,7 @@ QuoteInline = quotelink.parentNode.parentNode else $.x 'ancestor-or-self::*[parent::blockquote][1]', quotelink + add: (quotelink, boardID, threadID, postID, context) -> isBacklink = $.hasClass quotelink, 'backlink' inline = $.el 'div',