diff --git a/package.json b/package.json index 94b407315..c6dc06417 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "*://sys.4chan.org/*", "*://www.4chan.org/*", "*://i.4cdn.org/*", - "*://is.4chan.org/*" + "*://is.4chan.org/*", + "*://is2.4chan.org/*" ], "matches_only": [ "*://*.4chan.org/*", diff --git a/src/General/Build.Test.coffee b/src/General/Build.Test.coffee index b529b95e6..17b05b1ce 100644 --- a/src/General/Build.Test.coffee +++ b/src/General/Build.Test.coffee @@ -26,7 +26,7 @@ Build.Test = href = el.href href = href.replace /(^\w+:\/\/boards.4chan.org\/[^\/]+\/thread\/\d+)\/.*/, '$1' el.setAttribute 'href', href - for el in $$ '.fileText > a, a.fileThumb', root2 when el.hostname is 'is.4chan.org' + for el in $$ '.fileText > a, a.fileThumb', root2 when ImageHost.regex.test(el.hostname) el.hostname = 'i.4cdn.org' for el in $$ 'img[src]', root2 el.src = el.src.replace /(spoiler-\w+)\d(\.png)$/, '$11$2' diff --git a/src/Images/ImageCommon.coffee b/src/Images/ImageCommon.coffee index b94835b90..626eb429c 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -34,7 +34,7 @@ ImageCommon = return true isFromArchive: (file) -> - file.src.split('/')[2] not in ['i.4cdn.org', 'is.4chan.org'] + !Main.isImageHost(file.src.split('/')[2]) error: (file, post, delay, cb) -> src = post.file.url.split '/' diff --git a/src/Images/ImageHost.coffee b/src/Images/ImageHost.coffee index 88d88bcae..2bad8f56b 100644 --- a/src/Images/ImageHost.coffee +++ b/src/Images/ImageHost.coffee @@ -1,16 +1,21 @@ ImageHost = init: -> - return unless Conf['Use Faster Image Host'] and g.VIEW in ['index', 'thread'] + return unless (@enabled = Conf['Use Faster Image Host'] and g.VIEW in ['index', 'thread']) Callbacks.Post.push name: 'Image Host Rewriting' cb: @node + regex: /^is\d*\.4chan\.org$/ + node: -> return if @isClone - if @file and (m = @file.url.match /^https?:\/\/is\d*\.4chan\.org\/(.*)$/) + if @file and ImageHost.regex.test(@file.url.split('/')[2]) @file.link.hostname = 'i.4cdn.org' @file.thumbLink.hostname = 'i.4cdn.org' if @file.thumbLink @file.url = @file.link.href - for link in $$ 'a[href^="http://is.4chan.org/"], a[href^="https://is.4chan.org/"]', @nodes.comment + ImageHost.fixLinks $$('a', @nodes.comment) + + fixLinks: (links) -> + for link in links when ImageHost.regex.test(link.hostname) link.hostname = 'i.4cdn.org' return diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index e9f1734ac..867dfb4c4 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -229,7 +229,7 @@ Embedding = controls: true preload: 'auto' src: a.dataset.href - loop: /^https?:\/\/(i\.4cdn|is\.4chan)\.org\//.test a.dataset.href + loop: Main.isImageHost a.dataset.href.split('/')[2] $.on el, 'loadedmetadata', -> if el.videoHeight is 0 and el.parentNode $.replace el, Embedding.types.audio.el(a) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 8f2107acb..68e66f961 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -14,10 +14,11 @@ Linkify = node: -> return Embedding.events @ if @isClone return unless Linkify.regString.test @info.comment - for link in $$ 'a[href^="http://i.4cdn.org/"], a[href^="https://i.4cdn.org/"], a[href^="http://is.4chan.org/"], a[href^="https://is.4chan.org/"]', @nodes.comment + for link in $$ 'a', @nodes.comment when Main.isImageHost link.hostname $.addClass link, 'linkify' Embedding.process link, @ links = Linkify.process @nodes.comment + ImageHost.fixLinks links if ImageHost.enabled Embedding.process link, @ for link in links return diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 274c13326..e7c722ae5 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -290,7 +290,7 @@ Config = ] 'Use Faster Image Host': [ true - 'Change is.4chan.org links to point to the faster i.4cdn.org host.' + 'Change is*.4chan.org links to point to the faster i.4cdn.org host.' ] 'Menu': diff --git a/src/main/Main.coffee b/src/main/Main.coffee index ec3dabf70..cc34f8edb 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -129,23 +129,24 @@ Main = else if pathname[2] is 'post' PostSuccessful.init() return - when 'i.4cdn.org', 'is.4chan.org' - return unless pathname[2] and not /[sm]\.jpg$/.test(pathname[2]) - $.asap (-> d.readyState isnt 'loading'), -> - if Conf['404 Redirect'] and d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] - Redirect.navigate 'file', { - boardID: g.BOARD.ID - filename: pathname[pathname.length - 1] - } - else if video = $ 'video' - if Conf['Volume in New Tab'] - Volume.setup video - if Conf['Loop in New Tab'] - video.loop = true - video.controls = false - video.play() - ImageCommon.addControls video - return + + if Main.isImageHost hostname + return unless pathname[2] and not /[sm]\.jpg$/.test(pathname[2]) + $.asap (-> d.readyState isnt 'loading'), -> + if Conf['404 Redirect'] and d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] + Redirect.navigate 'file', { + boardID: g.BOARD.ID + filename: pathname[pathname.length - 1] + } + else if video = $ 'video' + if Conf['Volume in New Tab'] + Volume.setup video + if Conf['Loop in New Tab'] + video.loop = true + video.controls = false + video.play() + ImageCommon.addControls video + return return unless hostname is 'boards.4chan.org' @@ -410,6 +411,9 @@ Main = url = "<%= meta.newIssue.replace('%title', '#{encodeURIComponent title}').replace('%details', '#{encodeURIComponent details}') %>" <%= html(' [report]') %> + isImageHost: (hostname) -> + hostname is 'i.4cdn.org' or /^is\d*\.4chan\.org$/.test(hostname) + isThisPageLegit: -> # 404 error page or similar. unless 'thisPageIsLegit' of Main diff --git a/src/meta/metadata.js b/src/meta/metadata.js index 554a86dae..d2905e3b3 100644 --- a/src/meta/metadata.js +++ b/src/meta/metadata.js @@ -34,8 +34,8 @@ ).join('\n'); })() %> -// @connect i.4cdn.org -// @connect is.4chan.org +// @connect 4chan.org +// @connect 4cdn.org // @connect * <%= meta.grants.map(function(grant) { diff --git a/src/platform/CrossOrigin.coffee b/src/platform/CrossOrigin.coffee index 90543102e..aa8973358 100644 --- a/src/platform/CrossOrigin.coffee +++ b/src/platform/CrossOrigin.coffee @@ -14,7 +14,8 @@ CrossOrigin = # XXX https://forums.lanik.us/viewtopic.php?f=64&t=24173&p=78310 url = url.replace /^((?:https?:)?\/\/(?:\w+\.)?4c(?:ha|d)n\.org)\/adv\//, '$1//adv/' <% if (type === 'crx') { %> - if url.split('/')[...3].join('/') in ["#{location.protocol}//i.4cdn.org", "#{location.protocol}//is.4chan.org"] + parts = url.split '/' + if parts[0] is location.protocol and parts[1] is '' and Main.isImageHost(parts[2]) xhr = new XMLHttpRequest() xhr.open 'GET', url, true xhr.setRequestHeader key, value for key, value of headers