diff --git a/4chan_x.user.js b/4chan_x.user.js index 8e04fc7f4..d80d7c6e6 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -74,7 +74,7 @@ */ (function() { - var $, $$, Board, Build, Clone, Conf, Config, FileInfo, Get, Main, Post, QuoteBacklink, QuoteInline, QuotePreview, Quotify, Redirect, Sauce, Thread, Time, UI, d, g, + var $, $$, Board, Build, Clone, Conf, Config, FileInfo, Get, Main, Post, QuoteBacklink, QuoteInline, QuotePreview, Quotify, Redirect, RevealSpoilers, Sauce, Thread, Time, UI, d, g, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -985,6 +985,13 @@ $.log(err, 'Sauce'); } } + if (Conf['Reveal Spoilers']) { + try { + RevealSpoilers.init(); + } catch (err) { + $.log(err, 'Reveal Spoilers'); + } + } return $.ready(Main.initFeaturesReady); }, initFeaturesReady: function() { @@ -1996,7 +2003,7 @@ }, p: function() { if (this.file.isSpoiler) { - return 'Spoiler'; + return 'Spoiler, '; } else { return ''; } @@ -2089,6 +2096,26 @@ } }; + RevealSpoilers = { + init: function() { + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + node: function() { + var style, thumb, _ref; + if (this.isClone || !((_ref = this.file) != null ? _ref.isSpoiler : void 0)) { + return; + } + thumb = this.file.thumb; + thumb.removeAttribute('style'); + style = thumb.style; + style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; + return thumb.src = this.file.thumbURL; + } + }; + Main.init(); }).call(this); diff --git a/script.coffee b/script.coffee index f13cdf2d9..bae496c7e 100644 --- a/script.coffee +++ b/script.coffee @@ -790,6 +790,13 @@ Main = # XXX handle error $.log err, 'Sauce' + if Conf['Reveal Spoilers'] + try + RevealSpoilers.init() + catch err + # XXX handle error + $.log err, 'Reveal Spoilers' + $.ready Main.initFeaturesReady initFeaturesReady: -> if d.title is '4chan - 404 Not Found' @@ -1726,7 +1733,7 @@ FileInfo = else "#{FileInfo.escape shortname}#{FileInfo.escape fullname}" N: -> FileInfo.escape @file.name - p: -> if @file.isSpoiler then 'Spoiler' else '' + p: -> if @file.isSpoiler then 'Spoiler, ' else '' s: -> $.bytesToString @file.size B: -> FileInfo.convertUnit @file.size, 'B' K: -> FileInfo.convertUnit @file.size, 'KB' @@ -1776,6 +1783,20 @@ Sauce = nodes.push $.tn('\u00A0'), link @ $.add @file.info, nodes +RevealSpoilers = + init: -> + Post::callbacks.push + name: 'Reveal Spoilers' + cb: @node + node: -> + return if @isClone or !@file?.isSpoiler + {thumb} = @file + # revealed spoilers do not have height/width set, this fixes auto-gifs dimensions. + thumb.removeAttribute 'style' + {style} = thumb + style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px' + thumb.src = @file.thumbURL + Main.init()