From 3259517b0d492b65e412cb0662607301b3196e02 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 5 Nov 2016 13:48:27 -0700 Subject: [PATCH] Make rewriting of is.4chan.org links to i.4cdn.org optional (`Use Faster Image Host` option, default: true). #1141 --- src/Images/ImageHost.coffee | 12 ++++++++++++ src/classes/Post.coffee | 4 ---- src/config/Config.coffee | 4 ++++ src/main/Main.coffee | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/Images/ImageHost.coffee diff --git a/src/Images/ImageHost.coffee b/src/Images/ImageHost.coffee new file mode 100644 index 000000000..8d024aeb6 --- /dev/null +++ b/src/Images/ImageHost.coffee @@ -0,0 +1,12 @@ +ImageHost = + init: -> + return unless Conf['Use Faster Image Host'] and g.VIEW in ['index', 'thread'] + Callbacks.Post.push + name: 'Image Host Rewriting' + cb: @node + + node: -> + return unless @file and not @isClone and (m = @file.url.match /^https?:\/\/is\.4chan\.org\/(.*)$/) + @file.link.hostname = 'i.4cdn.org' + @file.thumbLink.hostname = 'i.4cdn.org' if @file.thumbLink + @file.url = @file.link.href diff --git a/src/classes/Post.coffee b/src/classes/Post.coffee index 427582c61..ebf66201e 100644 --- a/src/classes/Post.coffee +++ b/src/classes/Post.coffee @@ -188,8 +188,6 @@ class Post return if not (link = $ '.fileText > a, .fileText-original > a', fileRoot) return if not (info = link.nextSibling?.textContent.match /\(([\d.]+ [KMG]?B).*\)/) fileText = fileRoot.firstElementChild - # XXX full images on https://is.4chan.org don't load - link.hostname = 'i.4cdn.org' if link.hostname is 'is.4chan.org' @file = text: fileText link: link @@ -205,8 +203,6 @@ class Post size *= 1024 while unit-- > 0 @file.sizeInBytes = size if (thumb = $ 'a.fileThumb > [data-md5]', fileRoot) - # XXX full images on https://is.4chan.org don't load - thumb.parentNode.hostname = 'i.4cdn.org' if thumb.parentNode.hostname is 'is.4chan.org' $.extend @file, thumb: thumb thumbLink: thumb.parentNode diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 3a38e5985..81e33717b 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -184,6 +184,10 @@ Config = ] 'Images and Videos': + 'Use Faster Image Host': [ + true + 'Change is.4chan.org links to point to the faster i.4cdn.org host.' + ] 'Image Expansion': [ true 'Expand images / videos.' diff --git a/src/main/Main.coffee b/src/main/Main.coffee index 3921ff298..125fd906d 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -425,6 +425,7 @@ Main = ['Board Configuration', BoardConfig] ['Normalize URL', NormalizeURL] ['Captcha Configuration', Captcha.replace] + ['Image Host Rewriting', ImageHost] ['Redirect', Redirect] ['Header', Header] ['Catalog Links', CatalogLinks]