From 987b77bb608f999633485860f69366184be91939 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 8 May 2011 01:42:35 +0200 Subject: [PATCH 1/3] Start work to merging backwash. --- 4chan_x.js | 62 +++++++++++++++++++++++++++++++++++++++++++-------- script.coffee | 44 ++++++++++++++++++++++++++++++------ 2 files changed, 90 insertions(+), 16 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index edc3e6582..2226a658e 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, 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, 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) { @@ -83,6 +83,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 Preview': [true, 'Show quote content on hover'], 'Reply Hiding': [true, 'Hide single replies'], 'Sauce': [true, 'Add sauce to images'], 'Show Stubs': [true, 'Of hidden threads / replies'], @@ -1685,6 +1686,50 @@ } } }; + quotePreview = { + init: function() { + var preview, quote, quotes, _i, _len, _results; + preview = $.el('div', { + id: 'qp', + className: 'reply' + }); + $.hide(preview); + $.append(d.body, preview); + quotes = $$('a.quotelink'); + _results = []; + for (_i = 0, _len = quotes.length; _i < _len; _i++) { + quote = quotes[_i]; + _results.push($.bind(quote, 'mouseover', quotePreview.mouseover)); + } + return _results; + }, + mouseover: function(e) { + var clientX, clientY, id, preview, target; + target = e.target, clientX = e.clientX, clientY = e.clientY; + preview = $('#qp'); + id = target.textContent; + id = id.replace(">>", ''); + preview.innerHTML = d.getElementById(id).innerHTML; + $.show(preview); + $.bind(target, 'mousemove', quotePreview.mousemove); + return $.bind(target, 'mouseout', quotePreview.mouseout); + }, + mousemove: function(e) { + var clientX, clientY, preview; + clientX = e.clientX, clientY = e.clientY; + preview = $('#qp'); + preview.style.left = clientX + 45; + return preview.style.top = clientY - 120; + }, + mouseout: function(e) { + var preview, target; + target = e.target; + preview = $('#qp'); + $.hide(preview); + $.unbind(target, 'mousemove', quotePreview.mousemove); + return $.unbind(target, 'mouseout', quotePreview.mouseout); + } + }; quickReport = { init: function() { return g.callbacks.push(quickReport.cb.node); @@ -1873,13 +1918,9 @@ id: 'iHover' }); $.hide(img); - d.body.appendChild(img); + $.append(d.body, img); return g.callbacks.push(imageHover.cb.node); }, - offset: { - x: 45, - y: -120 - }, cb: { node: function(root) { var thumb, thumbs, _i, _len, _results; @@ -1907,10 +1948,10 @@ clientX = e.clientX, clientY = e.clientY; img = $('#iHover'); imgHeight = img.offsetHeight; - top = clientY + imageHover.offset.y; + top = clientY - 120; bot = top + imgHeight; img.style.top = imageHover.winHeight < imgHeight || top < 0 ? '0px' : bot > imageHover.winHeight ? imageHover.winHeight - imgHeight + 'px' : top + 'px'; - return img.style.left = clientX + imageHover.offset.x; + return img.style.left = clientX + 45; }, mouseout: function(e) { var img, target; @@ -2188,6 +2229,9 @@ if ($.config('Quick Report')) { quickReport.init(); } + if ($.config('Quote Preview')) { + quotePreview.init(); + } if ($.config('Thread Watcher')) { watcher.init(); } @@ -2273,7 +2317,7 @@ display: none;\ }\ \ - #iHover {\ + #qp, #iHover {\ position: fixed;\ }\ \ diff --git a/script.coffee b/script.coffee index 892b2e7e8..503391747 100644 --- a/script.coffee +++ b/script.coffee @@ -27,6 +27,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 Preview': [true, 'Show quote content on hover'] 'Reply Hiding': [true, 'Hide single replies'] 'Sauce': [true, 'Add sauce to images'] 'Show Stubs': [true, 'Of hidden threads / replies'] @@ -1317,6 +1318,35 @@ titlePost = if tc = $('span.filetitle').textContent or $('blockquote').textContent d.title = "/#{g.BOARD}/ - #{tc}" +quotePreview = + init: -> + preview = $.el 'div', id: 'qp', className: 'reply' + $.hide preview + $.append d.body, preview + quotes = $$ 'a.quotelink' + for quote in quotes + $.bind quote, 'mouseover', quotePreview.mouseover + mouseover: (e) -> + {target, clientX, clientY} = e + preview = $ '#qp' + id = target.textContent + id = id.replace ">>", '' + preview.innerHTML = d.getElementById(id).innerHTML + $.show preview + $.bind target, 'mousemove', quotePreview.mousemove + $.bind target, 'mouseout', quotePreview.mouseout + mousemove: (e) -> + {clientX, clientY} = e + preview = $ '#qp' + preview.style.left = clientX + 45 + preview.style.top = clientY - 120 + mouseout: (e) -> + {target} = e + preview = $ '#qp' + $.hide preview + $.unbind target, 'mousemove', quotePreview.mousemove + $.unbind target, 'mouseout', quotePreview.mouseout + quickReport = init: -> g.callbacks.push quickReport.cb.node @@ -1434,11 +1464,8 @@ imageHover = init: -> img = $.el 'img', id: 'iHover' $.hide img - d.body.appendChild img + $.append d.body, img g.callbacks.push imageHover.cb.node - offset: - x: 45 - y: -120 cb: node: (root) -> thumbs = $$ 'img[md5]', root @@ -1458,7 +1485,7 @@ imageHover = img = $ '#iHover' imgHeight = img.offsetHeight - top = clientY + imageHover.offset.y + top = clientY - 120 bot = top + imgHeight img.style.top = if imageHover.winHeight < imgHeight or top < 0 @@ -1467,7 +1494,7 @@ imageHover = imageHover.winHeight - imgHeight + 'px' else top + 'px' - img.style.left = clientX + imageHover.offset.x + img.style.left = clientX + 45 mouseout: (e) -> {target} = e img = $ '#iHover' @@ -1688,6 +1715,9 @@ main = if $.config 'Quick Report' quickReport.init() + if $.config 'Quote Preview' + quotePreview.init() + if $.config 'Thread Watcher' watcher.init() @@ -1770,7 +1800,7 @@ main = display: none; } - #iHover { + #qp, #iHover { position: fixed; } From 8947d62deceff10399756da08bdf59d2f0297db1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 8 May 2011 02:33:47 +0200 Subject: [PATCH 2/3] Preview the OP too. --- 4chan_x.js | 31 ++++++++++++++++--------------- script.coffee | 30 +++++++++++++++--------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 2226a658e..ac8680af2 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1240,18 +1240,20 @@ } $.append(op, node); op.id = $('input[name]', op).name; - node = op; - div = $.el('div', { - className: 'thread' - }); - $.before(node, div); - while (node.nodeName !== 'HR') { - $.append(div, node); - node = div.nextSibling; - } - node = node.nextElementSibling; - if (!(node.align || node.nodeName === 'CENTER')) { - return threading.thread(node); + if (!g.REPLY) { + node = op; + div = $.el('div', { + className: 'thread' + }); + $.before(node, div); + while (node.nodeName !== 'HR') { + $.append(div, node); + node = div.nextSibling; + } + node = node.nextElementSibling; + if (!(node.align || node.nodeName === 'CENTER')) { + return threading.thread(node); + } } }, stopPropagation: function(e) { @@ -1707,8 +1709,7 @@ var clientX, clientY, id, preview, target; target = e.target, clientX = e.clientX, clientY = e.clientY; preview = $('#qp'); - id = target.textContent; - id = id.replace(">>", ''); + id = target.textContent.replace(">>", ''); preview.innerHTML = d.getElementById(id).innerHTML; $.show(preview); $.bind(target, 'mousemove', quotePreview.mousemove); @@ -2238,6 +2239,7 @@ if ($.config('Keybinds')) { keybinds.init(); } + threading.init(); if (g.REPLY) { if ($.config('Thread Updater')) { updater.init(); @@ -2258,7 +2260,6 @@ watcher.watch(null, g.THREAD_ID); } } else { - threading.init(); if ($.config('Thread Hiding')) { threadHiding.init(); } diff --git a/script.coffee b/script.coffee index 503391747..bae7c8d90 100644 --- a/script.coffee +++ b/script.coffee @@ -966,20 +966,21 @@ threading = $.append op, node #add the blockquote op.id = $('input[name]', op).name - node = op + unless g.REPLY + node = op - div = $.el 'div', - className: 'thread' - $.before node, div + div = $.el 'div', + className: 'thread' + $.before node, div - while node.nodeName isnt 'HR' - $.append div, node - node = div.nextSibling + while node.nodeName isnt 'HR' + $.append div, node + node = div.nextSibling - node = node.nextElementSibling #skip text node - #{N,}SFW - unless node.align or node.nodeName is 'CENTER' - threading.thread node + node = node.nextElementSibling #skip text node + #{N,}SFW + unless node.align or node.nodeName is 'CENTER' + threading.thread node stopPropagation: (e) -> e.stopPropagation() @@ -1329,8 +1330,7 @@ quotePreview = mouseover: (e) -> {target, clientX, clientY} = e preview = $ '#qp' - id = target.textContent - id = id.replace ">>", '' + id = target.textContent.replace ">>", '' preview.innerHTML = d.getElementById(id).innerHTML $.show preview $.bind target, 'mousemove', quotePreview.mousemove @@ -1724,6 +1724,8 @@ main = if $.config 'Keybinds' keybinds.init() + threading.init() + if g.REPLY if $.config 'Thread Updater' updater.init() @@ -1745,8 +1747,6 @@ main = watcher.watch null, g.THREAD_ID else #not reply - threading.init() - if $.config 'Thread Hiding' threadHiding.init() From 4c1ea030404a7404d0c0fb8fefd8284125f462ab Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 8 May 2011 03:08:04 +0200 Subject: [PATCH 3/3] Preview quotes fetched with the thread updater. --- 4chan_x.js | 9 ++++++--- script.coffee | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 5694cc216..b812fd3f3 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -7,7 +7,6 @@ // @license MIT; http://en.wikipedia.org/wiki/Mit_license // @include http://boards.4chan.org/* // @include http://sys.4chan.org/* -// @include file://* // @updateURL http://userscripts.org/scripts/source/51412.meta.js // ==/UserScript== @@ -1664,13 +1663,17 @@ }; quotePreview = { init: function() { - var preview, quote, quotes, _i, _len, _results; + var preview; + g.callbacks.push(quotePreview.node); preview = $.el('div', { id: 'qp', className: 'reply' }); $.hide(preview); - $.append(d.body, preview); + return $.append(d.body, preview); + }, + node: function() { + var quote, quotes, _i, _len, _results; quotes = $$('a.quotelink'); _results = []; for (_i = 0, _len = quotes.length; _i < _len; _i++) { diff --git a/script.coffee b/script.coffee index c1aad2961..74bebb49a 100644 --- a/script.coffee +++ b/script.coffee @@ -1320,9 +1320,11 @@ titlePost = quotePreview = init: -> + g.callbacks.push quotePreview.node preview = $.el 'div', id: 'qp', className: 'reply' $.hide preview $.append d.body, preview + node: -> quotes = $$ 'a.quotelink' for quote in quotes $.bind quote, 'mouseover', quotePreview.mouseover