4chan-x/src/Images/Sauce.coffee
Zixaphir 2ac2286ad5 Merge branch 'mayhem' into v3
Conflicts:
	CHANGELOG.md
	src/General/lib/$.coffee
	src/Images/Sauce.coffee
2014-01-28 01:11:06 -07:00

43 lines
1.2 KiB
CoffeeScript
Executable File

Sauce =
init: ->
return if g.VIEW is 'catalog' or !Conf['Sauce']
links = []
for link in Conf['sauces'].split '\n'
try
links.push @createSauceLink link.trim() if link[0] isnt '#'
catch err
# Don't add random text plz.
return unless links.length
@links = links
@link = $.el 'a', target: '_blank'
Post.callbacks.push
name: 'Sauce'
cb: @node
createSauceLink: (link) ->
link = link.replace /%(T?URL|MD5|board|name)/g, (parameter) ->
return (if type = {
'%TURL': 'post.file.thumbURL'
'%URL': 'post.file.URL'
'%MD5': 'post.file.MD5'
'%board': 'post.board'
'%name': 'post.file.name'
}[parameter]
"' + encodeURIComponent(#{type}) + '"
else
parameter)
text = if m = link.match(/;text:(.+)$/) then m[1] else link.match(/(\w+)\.\w+\//)[1]
link = link.replace /;text:.+$/, ''
Function 'post', 'a', """
a.href = '#{link}';
a.textContent = '#{text}';
return a;
"""
node: ->
return if @isClone or !@file
nodes = []
for link in Sauce.links
# \u00A0 is nbsp
nodes.push $.tn('\u00A0'), link @, Sauce.link.cloneNode true
$.add @file.text, nodes