From 7a03d0eedd76fd8c1e6b4144eac2a235b8ec6a79 Mon Sep 17 00:00:00 2001 From: Jordan Bates Date: Wed, 24 Apr 2013 14:20:25 -0700 Subject: [PATCH] Add remove spoilers and indicate spoilers --- builds/4chan-X.js | 36 +++++++++++++++++++++++-- builds/4chan-X.user.js | 36 +++++++++++++++++++++++-- builds/crx/script.js | 36 +++++++++++++++++++++++-- src/config.coffee | 8 ++++++ src/features/misc/removespoilers.coffee | 20 ++++++++++++++ src/main.coffee | 1 + 6 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 src/features/misc/removespoilers.coffee diff --git a/builds/4chan-X.js b/builds/4chan-X.js index c3108ceb5..b84eeecca 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -102,7 +102,7 @@ * this notice is kept intact. */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __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; }, @@ -125,7 +125,9 @@ 'Index Navigation': [false, 'Add buttons to navigate between threads.'], 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], - 'Emoji': [false, 'Adds icons next to names for different emails'] + 'Emoji': [false, 'Adds icons next to names for different emails'], + 'Remove Spoilers': [false, 'Remove all spoilers in text.'], + 'Indicate Spoilers': [false, 'Indicate spoilers if Remove Spoilers is enabled.'] }, 'Linkification': { 'Linkify': [true, 'Convert text into links where applicable.'], @@ -5701,6 +5703,35 @@ } }; + RemoveSpoilers = { + init: function() { + if (!Conf['Remove Spoilers']) { + return; + } + if (Conf['Indicate Spoilers']) { + this.wrapper = function(text) { + return "[spoiler]" + text + "[/spoiler]"; + }; + } + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + wrapper: function(text) { + return text; + }, + node: function(post) { + var spoiler, spoilers, _i, _len; + + spoilers = $$('s', this.nodes.comment); + for (_i = 0, _len = spoilers.length; _i < _len; _i++) { + spoiler = spoilers[_i]; + $.replace(spoiler, $.tn(RemoveSpoilers.wrapper(spoiler.textContent))); + } + } + }; + Report = { init: function() { if (!/report/.test(location.search)) { @@ -9437,6 +9468,7 @@ 'Announcement Hiding': PSAHiding, 'Fourchan thingies': Fourchan, 'Emoji': Emoji, + 'Remove Spoilers': RemoveSpoilers, 'Custom CSS': CustomCSS, 'Linkify': Linkify, 'Resurrect Quotes': Quotify, diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 621ca25a6..526354338 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -102,7 +102,7 @@ * this notice is kept intact. */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __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; }, @@ -125,7 +125,9 @@ 'Index Navigation': [false, 'Add buttons to navigate between threads.'], 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], - 'Emoji': [false, 'Adds icons next to names for different emails'] + 'Emoji': [false, 'Adds icons next to names for different emails'], + 'Remove Spoilers': [false, 'Remove all spoilers in text.'], + 'Indicate Spoilers': [false, 'Indicate spoilers if Remove Spoilers is enabled.'] }, 'Linkification': { 'Linkify': [true, 'Convert text into links where applicable.'], @@ -5692,6 +5694,35 @@ } }; + RemoveSpoilers = { + init: function() { + if (!Conf['Remove Spoilers']) { + return; + } + if (Conf['Indicate Spoilers']) { + this.wrapper = function(text) { + return "[spoiler]" + text + "[/spoiler]"; + }; + } + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + wrapper: function(text) { + return text; + }, + node: function(post) { + var spoiler, spoilers, _i, _len; + + spoilers = $$('s', this.nodes.comment); + for (_i = 0, _len = spoilers.length; _i < _len; _i++) { + spoiler = spoilers[_i]; + $.replace(spoiler, $.tn(RemoveSpoilers.wrapper(spoiler.textContent))); + } + } + }; + Report = { init: function() { if (!/report/.test(location.search)) { @@ -9455,6 +9486,7 @@ 'Announcement Hiding': PSAHiding, 'Fourchan thingies': Fourchan, 'Emoji': Emoji, + 'Remove Spoilers': RemoveSpoilers, 'Custom CSS': CustomCSS, 'Linkify': Linkify, 'Resurrect Quotes': Quotify, diff --git a/builds/crx/script.js b/builds/crx/script.js index 6e99d709e..9150c050f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,5 +1,5 @@ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __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; }, @@ -22,7 +22,9 @@ 'Index Navigation': [false, 'Add buttons to navigate between threads.'], 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], - 'Emoji': [false, 'Adds icons next to names for different emails'] + 'Emoji': [false, 'Adds icons next to names for different emails'], + 'Remove Spoilers': [false, 'Remove all spoilers in text.'], + 'Indicate Spoilers': [false, 'Indicate spoilers if Remove Spoilers is enabled.'] }, 'Linkification': { 'Linkify': [true, 'Convert text into links where applicable.'], @@ -5556,6 +5558,35 @@ } }; + RemoveSpoilers = { + init: function() { + if (!Conf['Remove Spoilers']) { + return; + } + if (Conf['Indicate Spoilers']) { + this.wrapper = function(text) { + return "[spoiler]" + text + "[/spoiler]"; + }; + } + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + wrapper: function(text) { + return text; + }, + node: function(post) { + var spoiler, spoilers, _i, _len; + + spoilers = $$('s', this.nodes.comment); + for (_i = 0, _len = spoilers.length; _i < _len; _i++) { + spoiler = spoilers[_i]; + $.replace(spoiler, $.tn(RemoveSpoilers.wrapper(spoiler.textContent))); + } + } + }; + Report = { init: function() { if (!/report/.test(location.search)) { @@ -9298,6 +9329,7 @@ 'Announcement Hiding': PSAHiding, 'Fourchan thingies': Fourchan, 'Emoji': Emoji, + 'Remove Spoilers': RemoveSpoilers, 'Custom CSS': CustomCSS, 'Linkify': Linkify, 'Resurrect Quotes': Quotify, diff --git a/src/config.coffee b/src/config.coffee index eb730bef7..42a19969d 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -61,6 +61,14 @@ Config = false 'Adds icons next to names for different emails' ] + 'Remove Spoilers': [ + false + 'Remove all spoilers in text.' + ] + 'Indicate Spoilers': [ + false + 'Indicate spoilers if Remove Spoilers is enabled.' + ] 'Linkification': 'Linkify': [ diff --git a/src/features/misc/removespoilers.coffee b/src/features/misc/removespoilers.coffee new file mode 100644 index 000000000..62ec1c6cc --- /dev/null +++ b/src/features/misc/removespoilers.coffee @@ -0,0 +1,20 @@ +RemoveSpoilers = + init: -> + return unless Conf['Remove Spoilers'] + + if Conf['Indicate Spoilers'] + @wrapper = (text) -> + "[spoiler]#{text}[/spoiler]" + + Post::callbacks.push + name: 'Reveal Spoilers' + cb: @node + + wrapper: (text) -> + text + + node: (post) -> + spoilers = $$ 's', @nodes.comment + for spoiler in spoilers + $.replace spoiler, $.tn RemoveSpoilers.wrapper spoiler.textContent + return \ No newline at end of file diff --git a/src/main.coffee b/src/main.coffee index 11b64a081..ff5a69d11 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -72,6 +72,7 @@ Main = 'Announcement Hiding': PSAHiding 'Fourchan thingies': Fourchan 'Emoji': Emoji + 'Remove Spoilers': RemoveSpoilers 'Custom CSS': CustomCSS 'Linkify': Linkify 'Resurrect Quotes': Quotify