From 566c8bffd0328e146ad0f9b943875a8e45c9c705 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 10 Jul 2019 16:29:22 -0700 Subject: [PATCH] "Change `Use Faster Image Host` setting to `Override 4chan Image Host` in Advanced menu, which can be set to whichever image host you want to use. #2046 --- src/General/Settings.coffee | 9 ++++++++- src/General/Settings/Advanced.html | 7 +++++++ src/Images/ImageHost.coffee | 13 ++++++++----- src/Linkification/Linkify.coffee | 1 + src/config/Config.coffee | 6 ++---- src/main/Main.coffee | 1 + src/site/SW.tinyboard.coffee | 1 - 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index f1a96ad7f..6d64cb2e9 100644 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -493,6 +493,9 @@ Settings = if data['sauces']? set 'sauces', data['sauces'].replace(/^(#?\s*)(?:http:)?\/\/(www\.pixiv\.net|www\.deviantart\.com|imgur\.com|flickr\.com)\//mg, '$1https://$2/') set 'sauces', data['sauces'].replace(/https:\/\/yandex\.com\/images\/search\?rpt=imageview&img_url=%IMG/g, 'https://yandex.com/images/search?rpt=imageview&url=%IMG') + if compareString < '00001.00014.00009.00001' + if data['Use Faster Image Host']? and not data['fourchanImageHost']? + set 'fourchanImageHost', (if data['Use Faster Image Host'] then 'i.4cdn.org' else '') changes loadSettings: (data, cb) -> @@ -559,7 +562,7 @@ Settings = $.id('lastarchivecheck').textContent = 'never' items = {} - for name in ['archiveLists', 'archiveAutoUpdate', 'captchaLanguage', 'captchaServiceDomain', 'boardnav', 'time', 'timeLocale', 'backlink', 'pastedname', 'fileInfo', 'QR.personas', 'favicon', 'usercss', 'customCooldown', 'jsWhitelist'] + for name in ['archiveLists', 'archiveAutoUpdate', 'fourchanImageHost', 'captchaLanguage', 'captchaServiceDomain', 'boardnav', 'time', 'timeLocale', 'backlink', 'pastedname', 'fileInfo', 'QR.personas', 'favicon', 'usercss', 'customCooldown', 'jsWhitelist'] items[name] = Conf[name] input = inputs[name] event = if name in ['archiveLists', 'archiveAutoUpdate', 'QR.personas', 'favicon', 'usercss'] then 'change' else 'input' @@ -575,6 +578,10 @@ Settings = Settings[key].call input return + listImageHost = $.id 'list-fourchanImageHost' + for textContent in ImageHost.suggestions + $.add listImageHost, $.el 'option', {textContent} + $.on inputs['captchaServiceKey'], 'input', Settings.captchaServiceKey $.get 'captchaServiceKey', Conf['captchaServiceKey'], ({captchaServiceKey}) -> Conf['captchaServiceKey'] = captchaServiceKey diff --git a/src/General/Settings/Advanced.html b/src/General/Settings/Advanced.html index 2fd445cc2..36333e97e 100644 --- a/src/General/Settings/Advanced.html +++ b/src/General/Settings/Advanced.html @@ -19,6 +19,13 @@ Last updated: +
+ Override 4chan Image Host +
Change 4chan image links to this domain. Leave blank for no change.
+
+ +
+
Captcha Language
Choose from list of language codes. Leave blank to autoselect.
diff --git a/src/Images/ImageHost.coffee b/src/Images/ImageHost.coffee index 126994b56..116e3ea49 100644 --- a/src/Images/ImageHost.coffee +++ b/src/Images/ImageHost.coffee @@ -1,12 +1,14 @@ ImageHost = init: -> - return unless (@useFaster = Conf['Use Faster Image Host']) and g.VIEW in ['index', 'thread'] + return unless (@useFaster = /\S/.test(Conf['fourchanImageHost'])) and g.SITE.software is 'yotsuba' and g.VIEW in ['index', 'thread'] Callbacks.Post.push name: 'Image Host Rewriting' cb: @node + suggestions: ['i.4cdn.org', 'is2.4chan.org'] + host: -> - 'i.4cdn.org' + Conf['fourchanImageHost'].trim() or 'i.4cdn.org' flashHost: -> 'i.4cdn.org' thumbHost: -> @@ -19,13 +21,14 @@ ImageHost = node: -> return if @isClone host = ImageHost.host() - if @file and ImageHost.regex.test(@file.url.split('/')[2]) + if @file and ImageHost.test(@file.url.split('/')[2]) and not /\.swf$/.test(@file.url) @file.link.hostname = host @file.thumbLink.hostname = host if @file.thumbLink @file.url = @file.link.href ImageHost.fixLinks $$('a', @nodes.comment) fixLinks: (links) -> - for link in links when ImageHost.regex.test(link.hostname) - link.hostname = ImageHost.host() + for link in links when ImageHost.test(link.hostname) and not /\.swf$/.test(link.pathname) + host = ImageHost.host() + link.hostname = host unless link.hostname is host return diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 9f2c3ec9f..7fd9fb4a4 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -16,6 +16,7 @@ Linkify = return unless Linkify.regString.test @info.comment for link in $$ 'a', @nodes.comment when ImageHost.test(link.hostname) or /\bnofollow\b/.test(link.rel) $.addClass link, 'linkify' + ImageHost.fixLinks [link] if ImageHost.useFaster Embedding.process link, @ links = Linkify.process @nodes.comment ImageHost.fixLinks links if ImageHost.useFaster diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 248573dd5..051474817 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -304,10 +304,6 @@ Config = true 'Apply <%= meta.name %> mute and volume settings to videos opened in their own tabs.' ] - 'Use Faster Image Host': [ - true - 'Change is*.4chan.org links to point to the faster i.4cdn.org host.' - ] 'Menu': 'Menu': [ @@ -1164,3 +1160,5 @@ Config = 'https://api.captcha.guru': '' 'https://2captcha.com': '' }] + + fourchanImageHost: 'i.4cdn.org' diff --git a/src/main/Main.coffee b/src/main/Main.coffee index 734d0920c..1b11dc095 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -76,6 +76,7 @@ Main = Conf['Bottom QR Link'] = true Conf['Toggleable Thread Watcher'] = true Conf['siteSoftware'] = '' + Conf['Use Faster Image Host'] = 'true' # Enforce JS whitelist if /\.4chan(?:nel)?\.org$/.test(location.hostname) and !$$('script:not([src])', d).filter((s) -> /this\[/.test(s.textContent)).length diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index 5fb3e5054..85b0e0b5c 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -6,7 +6,6 @@ SW.tinyboard = 'Board Configuration' 'Normalize URL' 'Captcha Configuration' - 'Image Host Rewriting' 'Index Generator' 'Announcement Hiding' 'Resurrect Quotes'