From 68ffc27a727f55a0eb07a7c9fd5a301239a9a3b5 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 17:38:02 +0200 Subject: [PATCH 1/6] Start backlinking work --- 4chan_x.js | 27 +++++++++++++++++++++++++-- script.coffee | 20 +++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 6968a8c8b..ee8ede328 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -58,7 +58,7 @@ */ (function() { - var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quickReport, quotePreview, redirect, replyHiding, sauce, threadHiding, threading, titlePost, ui, unread, updater, watcher, _config, _ref; + var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quickReport, quoteBacklink, quotePreview, redirect, replyHiding, sauce, threadHiding, threading, titlePost, ui, unread, updater, watcher, _config, _ref; var __slice = Array.prototype.slice; if (typeof console !== "undefined" && console !== null) { log = function(arg) { @@ -84,6 +84,7 @@ 'Post in Title': [true, 'Show the op\'s post in the tab title'], 'Quick Reply': [true, 'Reply without leaving the page'], 'Quick Report': [true, 'Add quick report buttons'], + 'Quote Backlinks': [false, 'Add quote backlinks'], 'Quote Preview': [false, 'Show quote content on hover'], 'Reply Hiding': [true, 'Hide single replies'], 'Sauce': [true, 'Add sauce to images'], @@ -1675,6 +1676,25 @@ } } }; + quoteBacklink = { + init: function() { + return g.callbacks.push(quoteBacklink.node); + }, + node: function(root) { + var el, id, link, quote, _i, _len, _ref, _results; + _ref = $$('a.quotelink', root); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + quote = _ref[_i]; + _results.push((el = d.getElementById(quote.textContent.slice(2))) ? (id = quote.parentNode.parentNode.parentNode.id, link = $.el('a', { + href: '#' + id, + className: 'backlink', + textContent: '>>' + id + }), el.className !== 'op' ? $.before($('br, blockquote', el), link) : void 0) : void 0); + } + return _results; + } + }; quotePreview = { init: function() { var preview; @@ -1688,7 +1708,7 @@ }, node: function(root) { var quote, _i, _len, _ref, _results; - _ref = $$('a.quotelink', root); + _ref = $$('a.quotelink, a.backlink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; @@ -2229,6 +2249,9 @@ if ($.config('Quick Report')) { quickReport.init(); } + if ($.config('Quote Backlinks')) { + quoteBacklink.init(); + } if ($.config('Quote Preview')) { quotePreview.init(); } diff --git a/script.coffee b/script.coffee index a469d31a9..41667573c 100644 --- a/script.coffee +++ b/script.coffee @@ -28,6 +28,7 @@ config = 'Post in Title': [true, 'Show the op\'s post in the tab title'] 'Quick Reply': [true, 'Reply without leaving the page'] 'Quick Report': [true, 'Add quick report buttons'] + 'Quote Backlinks': [false, 'Add quote backlinks'] 'Quote Preview': [false, 'Show quote content on hover'] 'Reply Hiding': [true, 'Hide single replies'] 'Sauce': [true, 'Add sauce to images'] @@ -1340,6 +1341,20 @@ titlePost = if tc = $('span.filetitle').textContent or $('blockquote').textContent d.title = "/#{g.BOARD}/ - #{tc}" +quoteBacklink = + init: -> + g.callbacks.push quoteBacklink.node + node: (root) -> + for quote in $$ 'a.quotelink', root + if el = d.getElementById quote.textContent[2..] + id = quote.parentNode.parentNode.parentNode.id + link = $.el 'a' + href: '#'+id + className: 'backlink' + textContent: '>>'+id + unless el.className is 'op' + $.before $('br, blockquote', el), link + quotePreview = init: -> g.callbacks.push quotePreview.node @@ -1349,7 +1364,7 @@ quotePreview = $.hide preview $.append d.body, preview node: (root) -> - for quote in $$ 'a.quotelink', root + for quote in $$ 'a.quotelink, a.backlink', root $.bind quote, 'mouseover', quotePreview.mouseover $.bind quote, 'mousemove', ui.hover $.bind quote, 'mouseout', ui.hoverend @@ -1734,6 +1749,9 @@ main = if $.config 'Quick Report' quickReport.init() + if $.config 'Quote Backlinks' + quoteBacklink.init() + if $.config 'Quote Preview' quotePreview.init() From ee2c5000c227c4c2b803210d87e955474c1ef348 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 18:21:21 +0200 Subject: [PATCH 2/6] Fix multiple backlinks --- 4chan_x.js | 31 +++++++++++++++++++++++++------ script.coffee | 7 ++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index ee8ede328..1bbb6edff 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1681,16 +1681,35 @@ return g.callbacks.push(quoteBacklink.node); }, node: function(root) { - var el, id, link, quote, _i, _len, _ref, _results; + var backlink, el, id, link, nogood, quote, _i, _len, _ref, _results; _ref = $$('a.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - _results.push((el = d.getElementById(quote.textContent.slice(2))) ? (id = quote.parentNode.parentNode.parentNode.id, link = $.el('a', { - href: '#' + id, - className: 'backlink', - textContent: '>>' + id - }), el.className !== 'op' ? $.before($('br, blockquote', el), link) : void 0) : void 0); + _results.push((function() { + var _j, _len2, _ref2; + if (el = d.getElementById(quote.textContent.slice(2))) { + id = quote.parentNode.parentNode.parentNode.id; + link = $.el('a', { + href: '#' + id, + className: 'backlink', + textContent: '>>' + id + }); + if (el.className !== 'op') { + nogood = 0; + _ref2 = $$('a.backlink', el); + for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { + backlink = _ref2[_j]; + if (backlink.textContent === '>>' + id) { + nogood = 1; + } + } + if (!nogood) { + return $.before($('br, blockquote', el), link); + } + } + } + })()); } return _results; } diff --git a/script.coffee b/script.coffee index 41667573c..dc1908eb0 100644 --- a/script.coffee +++ b/script.coffee @@ -1353,7 +1353,12 @@ quoteBacklink = className: 'backlink' textContent: '>>'+id unless el.className is 'op' - $.before $('br, blockquote', el), link + nogood = 0 + for backlink in $$ 'a.backlink', el + if backlink.textContent is '>>'+id + nogood = 1 + unless nogood + $.before $('br, blockquote', el), link quotePreview = init: -> From 703c737bc553af60ed4301f1b42fe744992a4918 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 18:22:27 +0200 Subject: [PATCH 3/6] Break --- 4chan_x.js | 1 + script.coffee | 1 + 2 files changed, 2 insertions(+) diff --git a/4chan_x.js b/4chan_x.js index 1bbb6edff..87a197b15 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1702,6 +1702,7 @@ backlink = _ref2[_j]; if (backlink.textContent === '>>' + id) { nogood = 1; + break; } } if (!nogood) { diff --git a/script.coffee b/script.coffee index dc1908eb0..8c656f399 100644 --- a/script.coffee +++ b/script.coffee @@ -1357,6 +1357,7 @@ quoteBacklink = for backlink in $$ 'a.backlink', el if backlink.textContent is '>>'+id nogood = 1 + break unless nogood $.before $('br, blockquote', el), link From 5cfb8726d1b1318d09771279a014ec8f4a0ca32f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 18:28:53 +0200 Subject: [PATCH 4/6] Create the link only when needed --- 4chan_x.js | 10 +++++----- script.coffee | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 87a197b15..4e83be2b1 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1690,11 +1690,6 @@ var _j, _len2, _ref2; if (el = d.getElementById(quote.textContent.slice(2))) { id = quote.parentNode.parentNode.parentNode.id; - link = $.el('a', { - href: '#' + id, - className: 'backlink', - textContent: '>>' + id - }); if (el.className !== 'op') { nogood = 0; _ref2 = $$('a.backlink', el); @@ -1706,6 +1701,11 @@ } } if (!nogood) { + link = $.el('a', { + href: '#' + id, + className: 'backlink', + textContent: '>>' + id + }); return $.before($('br, blockquote', el), link); } } diff --git a/script.coffee b/script.coffee index 8c656f399..b77a08847 100644 --- a/script.coffee +++ b/script.coffee @@ -1348,10 +1348,6 @@ quoteBacklink = for quote in $$ 'a.quotelink', root if el = d.getElementById quote.textContent[2..] id = quote.parentNode.parentNode.parentNode.id - link = $.el 'a' - href: '#'+id - className: 'backlink' - textContent: '>>'+id unless el.className is 'op' nogood = 0 for backlink in $$ 'a.backlink', el @@ -1359,6 +1355,10 @@ quoteBacklink = nogood = 1 break unless nogood + link = $.el 'a' + href: '#'+id + className: 'backlink' + textContent: '>>'+id $.before $('br, blockquote', el), link quotePreview = From 19bfaa923dee83bdae4a695ae9b3a810b78840df Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 18:34:51 +0200 Subject: [PATCH 5/6] Make the quote preview work with updates --- 4chan_x.js | 7 ++++++- script.coffee | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 4e83be2b1..e4ef9b130 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1706,6 +1706,11 @@ className: 'backlink', textContent: '>>' + id }); + if ($.config('Quote Preview')) { + $.bind(link, 'mouseover', quotePreview.mouseover); + $.bind(link, 'mousemove', ui.hover); + $.bind(link, 'mouseout', ui.hoverend); + } return $.before($('br, blockquote', el), link); } } @@ -1728,7 +1733,7 @@ }, node: function(root) { var quote, _i, _len, _ref, _results; - _ref = $$('a.quotelink, a.backlink', root); + _ref = $$('a.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; diff --git a/script.coffee b/script.coffee index b77a08847..9b1ad3463 100644 --- a/script.coffee +++ b/script.coffee @@ -1359,6 +1359,10 @@ quoteBacklink = href: '#'+id className: 'backlink' textContent: '>>'+id + if $.config 'Quote Preview' + $.bind link, 'mouseover', quotePreview.mouseover + $.bind link, 'mousemove', ui.hover + $.bind link, 'mouseout', ui.hoverend $.before $('br, blockquote', el), link quotePreview = @@ -1370,7 +1374,7 @@ quotePreview = $.hide preview $.append d.body, preview node: (root) -> - for quote in $$ 'a.quotelink, a.backlink', root + for quote in $$ 'a.quotelink', root $.bind quote, 'mouseover', quotePreview.mouseover $.bind quote, 'mousemove', ui.hover $.bind quote, 'mouseout', ui.hoverend From 9927dc85f8025c67f910cf4717048f1705eb705f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 18:46:47 +0200 Subject: [PATCH 6/6] Go deeper --- 4chan_x.js | 45 ++++++++++++++++++++++----------------------- script.coffee | 34 +++++++++++++++++----------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index e4ef9b130..3f4d55c4b 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1681,38 +1681,37 @@ return g.callbacks.push(quoteBacklink.node); }, node: function(root) { - var backlink, el, id, link, nogood, quote, _i, _len, _ref, _results; + var backlink, el, good, id, link, quote, _i, _len, _ref, _results; _ref = $$('a.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; + el = d.getElementById(quote.textContent.slice(2)); _results.push((function() { var _j, _len2, _ref2; - if (el = d.getElementById(quote.textContent.slice(2))) { + if (el && el.className !== 'op') { + good = 1; id = quote.parentNode.parentNode.parentNode.id; - if (el.className !== 'op') { - nogood = 0; - _ref2 = $$('a.backlink', el); - for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { - backlink = _ref2[_j]; - if (backlink.textContent === '>>' + id) { - nogood = 1; - break; - } + _ref2 = $$('a.backlink', el); + for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { + backlink = _ref2[_j]; + if (backlink.textContent === '>>' + id) { + good = 0; + break; } - if (!nogood) { - link = $.el('a', { - href: '#' + id, - className: 'backlink', - textContent: '>>' + id - }); - if ($.config('Quote Preview')) { - $.bind(link, 'mouseover', quotePreview.mouseover); - $.bind(link, 'mousemove', ui.hover); - $.bind(link, 'mouseout', ui.hoverend); - } - return $.before($('br, blockquote', el), link); + } + if (good) { + link = $.el('a', { + href: '#' + id, + className: 'backlink', + textContent: '>>' + id + }); + if ($.config('Quote Preview')) { + $.bind(link, 'mouseover', quotePreview.mouseover); + $.bind(link, 'mousemove', ui.hover); + $.bind(link, 'mouseout', ui.hoverend); } + return $.before($('br, blockquote', el), link); } } })()); diff --git a/script.coffee b/script.coffee index 9b1ad3463..6da97ec2c 100644 --- a/script.coffee +++ b/script.coffee @@ -1346,24 +1346,24 @@ quoteBacklink = g.callbacks.push quoteBacklink.node node: (root) -> for quote in $$ 'a.quotelink', root - if el = d.getElementById quote.textContent[2..] + el = d.getElementById(quote.textContent[2..]) + if el and el.className isnt 'op' + good = 1 id = quote.parentNode.parentNode.parentNode.id - unless el.className is 'op' - nogood = 0 - for backlink in $$ 'a.backlink', el - if backlink.textContent is '>>'+id - nogood = 1 - break - unless nogood - link = $.el 'a' - href: '#'+id - className: 'backlink' - textContent: '>>'+id - if $.config 'Quote Preview' - $.bind link, 'mouseover', quotePreview.mouseover - $.bind link, 'mousemove', ui.hover - $.bind link, 'mouseout', ui.hoverend - $.before $('br, blockquote', el), link + for backlink in $$ 'a.backlink', el + if backlink.textContent is '>>'+id + good = 0 + break + if good + link = $.el 'a', + href: '#'+id + className: 'backlink' + textContent: '>>'+id + if $.config 'Quote Preview' + $.bind link, 'mouseover', quotePreview.mouseover + $.bind link, 'mousemove', ui.hover + $.bind link, 'mouseout', ui.hoverend + $.before $('br, blockquote', el), link quotePreview = init: ->