Multifile support in Sauce. #2171
This commit is contained in:
parent
125448c8fb
commit
6ca5b28cd5
@ -43,14 +43,14 @@ Sauce =
|
|||||||
return null
|
return null
|
||||||
parts
|
parts
|
||||||
|
|
||||||
createSauceLink: (link, post) ->
|
createSauceLink: (link, post, file) ->
|
||||||
ext = post.file.url.match(/[^.]*$/)[0]
|
ext = file.url.match(/[^.]*$/)[0]
|
||||||
parts = {}
|
parts = {}
|
||||||
$.extend parts, link
|
$.extend parts, link
|
||||||
|
|
||||||
return null unless !parts['boards'] or post.board.ID in parts['boards'].split ','
|
return null unless !parts['boards'] or post.board.ID in parts['boards'].split ','
|
||||||
return null unless !parts['types'] or ext in parts['types'].split ','
|
return null unless !parts['types'] or ext in parts['types'].split ','
|
||||||
return null unless !parts['regexp'] or (matches = post.file.name.match parts['regexp'])
|
return null unless !parts['regexp'] or (matches = file.name.match parts['regexp'])
|
||||||
|
|
||||||
missing = []
|
missing = []
|
||||||
for key in ['url', 'text']
|
for key in ['url', 'text']
|
||||||
@ -59,7 +59,7 @@ Sauce =
|
|||||||
return orig unless matches
|
return orig unless matches
|
||||||
type = matches[parameter[1..]] or ''
|
type = matches[parameter[1..]] or ''
|
||||||
else
|
else
|
||||||
type = Sauce.formatters[parameter] post, ext
|
type = Sauce.formatters[parameter] post, file, ext
|
||||||
if not type?
|
if not type?
|
||||||
missing.push parameter
|
missing.push parameter
|
||||||
return ''
|
return ''
|
||||||
@ -69,7 +69,7 @@ Sauce =
|
|||||||
type = encodeURIComponent type
|
type = encodeURIComponent type
|
||||||
type
|
type
|
||||||
|
|
||||||
if post.board.ID is 'f' and missing.length and !missing.filter((x) -> !/^.?MD5$/.test(x)).length
|
if g.SITE.areMD5sDeferred?(post.board) and missing.length and !missing.filter((x) -> !/^.?MD5$/.test(x)).length
|
||||||
a = Sauce.link.cloneNode false
|
a = Sauce.link.cloneNode false
|
||||||
a.dataset.skip = '1'
|
a.dataset.skip = '1'
|
||||||
return a
|
return a
|
||||||
@ -83,32 +83,36 @@ Sauce =
|
|||||||
a
|
a
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
return if @isClone or !@file
|
return if @isClone
|
||||||
|
for file in @files
|
||||||
|
Sauce.file @, file
|
||||||
|
return
|
||||||
|
|
||||||
|
file: (post, file) ->
|
||||||
nodes = []
|
nodes = []
|
||||||
skipped = []
|
skipped = []
|
||||||
for link in Sauce.links
|
for link in Sauce.links
|
||||||
if (node = Sauce.createSauceLink link, @)
|
if (node = Sauce.createSauceLink link, post, file)
|
||||||
nodes.push $.tn(' '), node
|
nodes.push $.tn(' '), node
|
||||||
skipped.push [link, node] if node.dataset.skip
|
skipped.push [link, node] if node.dataset.skip
|
||||||
$.add @file.text, nodes
|
$.add file.text, nodes
|
||||||
|
|
||||||
if skipped.length
|
if skipped.length
|
||||||
observer = new MutationObserver =>
|
observer = new MutationObserver ->
|
||||||
if @file.text.dataset.md5
|
if file.text.dataset.md5
|
||||||
for [link, node] in skipped when (node2 = Sauce.createSauceLink link, @)
|
for [link, node] in skipped when (node2 = Sauce.createSauceLink link, post, file)
|
||||||
$.replace node, node2
|
$.replace node, node2
|
||||||
observer.disconnect()
|
observer.disconnect()
|
||||||
observer.observe @file.text, {attributes: true}
|
observer.observe file.text, {attributes: true}
|
||||||
|
|
||||||
formatters:
|
formatters:
|
||||||
TURL: (post) -> post.file.thumbURL
|
TURL: (post, file) -> file.thumbURL
|
||||||
URL: (post) -> post.file.url
|
URL: (post, file) -> file.url
|
||||||
IMG: (post, ext) -> if ext in ['gif', 'jpg', 'png'] then post.file.url else post.file.thumbURL
|
IMG: (post, file, ext) -> if ext in ['gif', 'jpg', 'png'] then file.url else file.thumbURL
|
||||||
MD5: (post) -> post.file.MD5
|
MD5: (post, file) -> file.MD5
|
||||||
sMD5: (post) -> post.file.MD5?.replace /[+/=]/g, (c) -> ({'+': '-', '/': '_', '=': ''})[c]
|
sMD5: (post, file) -> file.MD5?.replace /[+/=]/g, (c) -> ({'+': '-', '/': '_', '=': ''})[c]
|
||||||
hMD5: (post) -> if post.file.MD5 then ("0#{c.charCodeAt(0).toString(16)}"[-2..] for c in atob post.file.MD5).join('')
|
hMD5: (post, file) -> if file.MD5 then ("0#{c.charCodeAt(0).toString(16)}"[-2..] for c in atob file.MD5).join('')
|
||||||
board: (post) -> post.board.ID
|
board: (post) -> post.board.ID
|
||||||
name: (post) -> post.file.name
|
name: (post, file) -> file.name
|
||||||
'%': -> '%'
|
'%': -> '%'
|
||||||
semi: -> ';'
|
semi: -> ';'
|
||||||
|
|||||||
@ -15,6 +15,7 @@ SW.yotsuba =
|
|||||||
"#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{filename}"
|
"#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{filename}"
|
||||||
|
|
||||||
isPrunedByAge: ({boardID}) -> boardID is 'f'
|
isPrunedByAge: ({boardID}) -> boardID is 'f'
|
||||||
|
areMD5sDeferred: ({boardID}) -> boardID is 'f'
|
||||||
|
|
||||||
selectors:
|
selectors:
|
||||||
board: '.board'
|
board: '.board'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user