Build =
initPixelRatio: window.devicePixelRatio
spoilerRange: {}
unescape: (text) ->
return text unless text?
text.replace /&(amp|#039|quot|lt|gt);/g, (c) ->
{'&': '&', ''': "'", '"': '"', '<': '<', '>': '>'}[c]
shortFilename: (filename, isReply) ->
threshold = 30
ext = filename.match(/\.?[^\.]*$/)[0]
if filename.length - ext.length > threshold
"#{filename[...threshold - 5]}(...)#{ext}"
else
filename
thumbRotate: do ->
n = 0
-> n = (n + 1) % 3
sameThread: (boardID, threadID) ->
g.VIEW is 'thread' and g.BOARD.ID is boardID and g.THREADID is +threadID
postURL: (boardID, threadID, postID) ->
if Build.sameThread boardID, threadID
"\#p#{postID}"
else
"/#{boardID}/thread/#{threadID}\#p#{postID}"
postFromObject: (data, boardID) ->
o =
# id
postID: data.no
threadID: data.resto or data.no
boardID: boardID
# info
name: Build.unescape data.name
capcode: data.capcode
tripcode: data.trip
uniqueID: data.id
email: Build.unescape data.email
subject: Build.unescape data.sub
flagCode: data.country
flagName: Build.unescape data.country_name
date: data.now
dateUTC: data.time
comment: {innerHTML: data.com or ''}
# thread status
isSticky: !!data.sticky
isClosed: !!data.closed
# file
if data.filedeleted
o.file =
isDeleted: true
else if data.ext
o.file =
name: (Build.unescape data.filename) + data.ext
timestamp: "#{data.tim}#{data.ext}"
url: if boardID is 'f'
"//i.4cdn.org/#{boardID}/#{encodeURIComponent data.filename}#{data.ext}"
else
"//i.4cdn.org/#{boardID}/#{data.tim}#{data.ext}"
height: data.h
width: data.w
MD5: data.md5
size: data.fsize
turl: "//#{Build.thumbRotate()}.t.4cdn.org/#{boardID}/#{data.tim}s.jpg"
theight: data.tn_h
twidth: data.tn_w
isSpoiler: !!data.spoiler
isDeleted: false
tag: data.tag
Build.post o
post: (o) ->
###
This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS).
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE
###
{
postID, threadID, boardID
name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC
isSticky, isClosed
comment
file
} = o
name or= ''
subject or= ''
isOP = postID is threadID
retina = if Build.initPixelRatio >= 2 then '@2x' else ''
### Name Block ###
switch capcode
when 'admin', 'admin_highlight'
capcodeClass = ' capcodeAdmin'
capcodeStart = <%= html(' ## Admin') %>
capcodeIcon = <%= html('
') %>
when 'mod'
capcodeClass = ' capcodeMod'
capcodeStart = <%= html(' ## Mod') %>
capcodeIcon = <%= html('
') %>
when 'developer'
capcodeClass = ' capcodeDeveloper'
capcodeStart = <%= html(' ## Developer') %>
capcodeIcon = <%= html('
') %>
else
capcodeClass = ''
capcodeStart = <%= html('') %>
capcodeIcon = <%= html('') %>
nameClass = if capcode then ' capcode' else ''
tripcodeField = if tripcode
<%= html(' ${tripcode}') %>
else
<%= html('') %>
emailField = <%= html('${name}&{tripcodeField}&{capcodeStart}') %>
if email
emailProcessed = encodeURIComponent(email).replace /%40/g, '@'
emailField = <%= html('&{emailField}') %>
unless isOP and boardID is 'f'
emailField = <%= html('&{emailField} ') %>
userID = if !capcode and uniqueID
<%= html(' (ID: ${uniqueID})') %>
else
<%= html('') %>
flag = unless flagCode
<%= html('') %>
else if boardID is 'pol'
<%= html('
') %>
else
<%= html('') %>
nameBlock = <%= html(
'' +
'&{emailField}&{capcodeIcon}&{userID}&{flag}' +
' '
) %>
### Post Info ###
subjectField = if isOP or boardID is 'f'
<%= html('${subject} ') %>
else
<%= html('') %>
desktop2 = if isOP and boardID is 'f' then '' else ' desktop'
postLink = Build.postURL boardID, threadID, postID
quoteLink = if Build.sameThread boardID, threadID
"javascript:quote('#{postID}');"
else
"/#{boardID}/thread/#{threadID}\#q#{postID}"
pageIcon = if isOP and g.VIEW is 'index' and Conf['JSON Navigation']
pageNum = Math.floor(Index.liveThreadIDs.indexOf(postID) / Index.threadsNumPerPage) + 1
<%= html(' [${pageNum}]') %>
else
<%= html('') %>
sticky = if isSticky
<%= html('
') %>
else
<%= html('') %>
closed = if isClosed
<%= html('
') %>
else
<%= html('') %>
replyLink = if isOP and g.VIEW is 'index'
<%= html(' [Reply]') %>
else
<%= html('') %>
postInfo = <%= html(
'
' +
''
) %>
else if file and boardID is 'f'
<%= html(
'&{comment}') %> wholePost = if isOP <%= html( '