Use is.4chan.org for building posts if 'Use Faster Image Host' is off.
Also consolidate the image host related code.
This commit is contained in:
parent
b32735322f
commit
0f6a98e5e9
@ -64,14 +64,14 @@ Build =
|
||||
o.file =
|
||||
name: (Build.unescape data.filename) + data.ext
|
||||
url: if boardID is 'f'
|
||||
"#{location.protocol}//i.4cdn.org/#{boardID}/#{encodeURIComponent data.filename}#{data.ext}"
|
||||
"#{location.protocol}//#{ImageHost.host()}/#{boardID}/#{encodeURIComponent data.filename}#{data.ext}"
|
||||
else
|
||||
"#{location.protocol}//i.4cdn.org/#{boardID}/#{data.tim}#{data.ext}"
|
||||
"#{location.protocol}//#{ImageHost.host()}/#{boardID}/#{data.tim}#{data.ext}"
|
||||
height: data.h
|
||||
width: data.w
|
||||
MD5: data.md5
|
||||
size: $.bytesToString data.fsize
|
||||
thumbURL: "#{location.protocol}//i.4cdn.org/#{boardID}/#{data.tim}s.jpg"
|
||||
thumbURL: "#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{data.tim}s.jpg"
|
||||
theight: data.tn_h
|
||||
twidth: data.tn_w
|
||||
isSpoiler: !!data.spoiler
|
||||
|
||||
@ -634,7 +634,7 @@ Settings =
|
||||
data =
|
||||
isReply: true
|
||||
file:
|
||||
url: '//i.4cdn.org/g/1334437723720.jpg'
|
||||
url: "//#{ImageHost.host()}/g/1334437723720.jpg"
|
||||
name: 'd9bb2efc98dd0df141a94399ff5880b7.jpg'
|
||||
size: '276 KB'
|
||||
sizeInBytes: 276 * 1024
|
||||
|
||||
@ -34,7 +34,7 @@ ImageCommon =
|
||||
return true
|
||||
|
||||
isFromArchive: (file) ->
|
||||
!Main.isImageHost(file.src.split('/')[2])
|
||||
!ImageHost.test(file.src.split('/')[2])
|
||||
|
||||
error: (file, post, delay, cb) ->
|
||||
src = post.file.url.split '/'
|
||||
|
||||
@ -1,21 +1,29 @@
|
||||
ImageHost =
|
||||
init: ->
|
||||
return unless (@enabled = Conf['Use Faster Image Host'] and g.VIEW in ['index', 'thread'])
|
||||
return unless (@useFaster = Conf['Use Faster Image Host']) and g.VIEW in ['index', 'thread']
|
||||
Callbacks.Post.push
|
||||
name: 'Image Host Rewriting'
|
||||
cb: @node
|
||||
|
||||
host: ->
|
||||
if @useFaster then 'i.4cdn.org' else 'is.4chan.org'
|
||||
thumbHost: ->
|
||||
'i.4cdn.org'
|
||||
test: (hostname) ->
|
||||
hostname is 'i.4cdn.org' or ImageHost.regex.test(hostname)
|
||||
|
||||
regex: /^is\d*\.4chan\.org$/
|
||||
|
||||
node: ->
|
||||
return if @isClone
|
||||
host = ImageHost.host()
|
||||
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.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 = 'i.4cdn.org'
|
||||
link.hostname = ImageHost.host()
|
||||
return
|
||||
|
||||
@ -229,7 +229,7 @@ Embedding =
|
||||
controls: true
|
||||
preload: 'auto'
|
||||
src: a.dataset.href
|
||||
loop: Main.isImageHost a.dataset.href.split('/')[2]
|
||||
loop: ImageHost.test a.dataset.href.split('/')[2]
|
||||
$.on el, 'loadedmetadata', ->
|
||||
if el.videoHeight is 0 and el.parentNode
|
||||
$.replace el, Embedding.types.audio.el(a)
|
||||
@ -337,7 +337,7 @@ Embedding =
|
||||
when 'pi' then ["https://u.pomf.is/#{base}"]
|
||||
when 'wl' then ["http://webm.land/media/#{base}"]
|
||||
when 'ko' then ["https://kordy.kastden.org/loopvid/#{base}"]
|
||||
when 'fc' then ["//i.4cdn.org/#{base}.webm"]
|
||||
when 'fc' then ["//#{ImageHost.host()}/#{base}.webm"]
|
||||
when 'gc' then ["https://#{type}.gfycat.com/#{name}.webm"]
|
||||
for url in urls
|
||||
$.add el, $.el 'source', src: url
|
||||
|
||||
@ -14,11 +14,11 @@ Linkify =
|
||||
node: ->
|
||||
return Embedding.events @ if @isClone
|
||||
return unless Linkify.regString.test @info.comment
|
||||
for link in $$ 'a', @nodes.comment when Main.isImageHost link.hostname
|
||||
for link in $$ 'a', @nodes.comment when ImageHost.test link.hostname
|
||||
$.addClass link, 'linkify'
|
||||
Embedding.process link, @
|
||||
links = Linkify.process @nodes.comment
|
||||
ImageHost.fixLinks links if ImageHost.enabled
|
||||
ImageHost.fixLinks links if ImageHost.useFaster
|
||||
Embedding.process link, @ for link in links
|
||||
return
|
||||
|
||||
|
||||
@ -176,14 +176,14 @@ class Fetcher
|
||||
name: data.media.media_filename
|
||||
url: data.media.media_link or data.media.remote_media_link or
|
||||
if @boardID is 'f'
|
||||
"#{location.protocol}//i.4cdn.org/#{@boardID}/#{encodeURIComponent data.media.media_filename}"
|
||||
"#{location.protocol}//#{ImageHost.host()}/#{@boardID}/#{encodeURIComponent data.media.media_filename}"
|
||||
else
|
||||
"#{location.protocol}//i.4cdn.org/#{@boardID}/#{encodeURIComponent data.media.media_orig}"
|
||||
"#{location.protocol}//#{ImageHost.host()}/#{@boardID}/#{encodeURIComponent data.media.media_orig}"
|
||||
height: data.media.media_h
|
||||
width: data.media.media_w
|
||||
MD5: data.media.media_hash
|
||||
size: $.bytesToString data.media.media_size
|
||||
thumbURL: data.media.thumb_link or "#{location.protocol}//i.4cdn.org/#{@boardID}/#{data.media.preview_orig}"
|
||||
thumbURL: data.media.thumb_link or "#{location.protocol}//#{ImageHost.thumbHost()}/#{@boardID}/#{data.media.preview_orig}"
|
||||
theight: data.media.preview_h
|
||||
twidth: data.media.preview_w
|
||||
isSpoiler: data.media.spoiler is '1'
|
||||
|
||||
@ -207,9 +207,11 @@ class Post
|
||||
$.extend @file,
|
||||
thumb: thumb
|
||||
thumbLink: thumb.parentNode
|
||||
thumbURL: if m = link.href.match(/\d+(?=\.\w+$)/) then "#{location.protocol}//i.4cdn.org/#{@board}/#{m[0]}s.jpg"
|
||||
thumbURL: thumb.src
|
||||
MD5: thumb.dataset.md5
|
||||
isSpoiler: $.hasClass thumb.parentNode, 'imgspoiler'
|
||||
if @file.isSpoiler
|
||||
@file.thumbURL = if (m = link.href.match /\d+(?=\.\w+$)/) then "#{location.protocol}//#{ImageHost.thumbHost()}/#{@board}/#{m[0]}s.jpg"
|
||||
|
||||
@deadMark =
|
||||
# \u00A0 is nbsp
|
||||
|
||||
@ -130,7 +130,7 @@ Main =
|
||||
PostSuccessful.init()
|
||||
return
|
||||
|
||||
if Main.isImageHost hostname
|
||||
if ImageHost.test 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']
|
||||
@ -411,9 +411,6 @@ Main =
|
||||
url = "<%= meta.newIssue.replace('%title', '#{encodeURIComponent title}').replace('%details', '#{encodeURIComponent details}') %>"
|
||||
<%= html('<span class="report-error"> [<a href="${url}" target="_blank">report</a>]</span>') %>
|
||||
|
||||
isImageHost: (hostname) ->
|
||||
hostname is 'i.4cdn.org' or /^is\d*\.4chan\.org$/.test(hostname)
|
||||
|
||||
isThisPageLegit: ->
|
||||
# 404 error page or similar.
|
||||
unless 'thisPageIsLegit' of Main
|
||||
|
||||
@ -15,7 +15,7 @@ CrossOrigin =
|
||||
url = url.replace /^((?:https?:)?\/\/(?:\w+\.)?4c(?:ha|d)n\.org)\/adv\//, '$1//adv/'
|
||||
<% if (type === 'crx') { %>
|
||||
parts = url.split '/'
|
||||
if parts[0] is location.protocol and parts[1] is '' and Main.isImageHost(parts[2])
|
||||
if parts[0] is location.protocol and parts[1] is '' and ImageHost.test(parts[2])
|
||||
xhr = new XMLHttpRequest()
|
||||
xhr.open 'GET', url, true
|
||||
xhr.setRequestHeader key, value for key, value of headers
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user