From 5431fd53118604963fe02923a5101b573486d4fa Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 25 Jun 2011 00:17:58 +0200 Subject: [PATCH] Image spoiler revealer. Close #187 --- 4chan_x.user.js | 25 +++++++++++++++++++++++-- script.coffee | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a77641e2e..62c901c01 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -59,7 +59,7 @@ */ (function() { - var $, $$, Favicon, NAMESPACE, Recaptcha, Time, anonymize, config, cooldown, d, expandComment, expandThread, firstRun, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, watcher, _config, _ref; + var $, $$, Favicon, NAMESPACE, Recaptcha, Time, anonymize, config, cooldown, d, expandComment, expandThread, firstRun, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, watcher, _config, _ref; var __slice = Array.prototype.slice; if (typeof console !== "undefined" && console !== null) { log = function(arg) { @@ -95,7 +95,8 @@ 'Image Expansion': [true, 'Expand images'], 'Image Hover': [false, 'Show full image on mouseover'], 'Image Preloading': [false, 'Preload Images'], - 'Sauce': [true, 'Add sauce to images'] + 'Sauce': [true, 'Add sauce to images'], + 'Reveal Spoilers': [false, 'Replace spoiler thumbnails by the original thumbnail'] }, Hiding: { 'Reply Hiding': [true, 'Hide single replies'], @@ -1817,6 +1818,23 @@ } } }; + revealSpoilers = { + init: function() { + return g.callbacks.push(revealSpoilers.cb.node); + }, + cb: { + node: function(root) { + var board, img, nb, _, _ref; + if (root.className === 'inline' || !(img = $('img[alt^=Spoiler]', root))) { + return; + } + img.removeAttribute('height'); + img.removeAttribute('width'); + _ref = img.parentNode.href.match(/(\w+)\/src\/(\d+)/), _ = _ref[0], board = _ref[1], nb = _ref[2]; + return img.src = "http://0.thumbs.4chan.org/" + board + "/thumb/" + nb + "s.jpg"; + } + } + }; Time = { init: function() { Time.foo(); @@ -2679,6 +2697,9 @@ if ($.config('Sauce')) { sauce.init(); } + if ($.config('Reveal Spoilers')) { + revealSpoilers.init(); + } if ($.config('Anonymize')) { anonymize.init(); } diff --git a/script.coffee b/script.coffee index c855a601e..1acedb184 100644 --- a/script.coffee +++ b/script.coffee @@ -30,6 +30,7 @@ config = 'Image Hover': [false, 'Show full image on mouseover'] 'Image Preloading': [false, 'Preload Images'] 'Sauce': [true, 'Add sauce to images'] + 'Reveal Spoilers': [false, 'Replace spoiler thumbnails by the original thumbnail'] Hiding: 'Reply Hiding': [true, 'Hide single replies'] 'Thread Hiding': [true, 'Hide entire threads'] @@ -1463,6 +1464,17 @@ sauce = href: prefix + suffix $.append span, $.tn(' '), link +revealSpoilers = + init: -> + g.callbacks.push revealSpoilers.cb.node + cb: + node: (root) -> + return if root.className is 'inline' or not img = $('img[alt^=Spoiler]', root) + img.removeAttribute 'height' + img.removeAttribute 'width' + [_, board, nb] = img.parentNode.href.match /(\w+)\/src\/(\d+)/ + img.src = "http://0.thumbs.4chan.org/#{board}/thumb/#{nb}s.jpg" + Time = init: -> Time.foo() @@ -2099,6 +2111,9 @@ main = if $.config 'Sauce' sauce.init() + if $.config 'Reveal Spoilers' + revealSpoilers.init() + if $.config 'Anonymize' anonymize.init()