Add support for is2.4chan.org host.

This commit is contained in:
ccd0 2017-01-05 13:01:17 -08:00
parent a110d2f703
commit c5f175ed13
10 changed files with 41 additions and 29 deletions

View File

@ -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/*",

View File

@ -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'

View File

@ -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 '/'

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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':

View File

@ -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('<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

View File

@ -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) {

View File

@ -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