Build =
staticPath: '//s.4cdn.org/image/'
gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif'
spoilerRange: {}
shortFilename: (filename, isReply) ->
# FILENAME SHORTENING SCIENCE:
# OPs have a +10 characters threshold.
# The file extension is not taken into account.
threshold = if isReply then 30 else 40
ext = filename.match(/\.[^.]+$/)[0]
if filename.length - ext.length > threshold
"#{filename[...threshold - 5]}(...)#{ext}"
else
filename
thumbRotate: do ->
n = 0
-> n = (n + 1) % 2
postFromObject: (data, boardID) ->
o =
# id
postID: data.no
threadID: data.resto or data.no
boardID: boardID
# info
name: data.name
capcode: data.capcode
tripcode: data.trip
uniqueID: data.id
email: if data.email then encodeURI data.email.replace /"/g, '"' else ''
subject: data.sub
flagCode: data.country
flagName: data.country_name
date: data.now
dateUTC: data.time
comment: data.com
# thread status
isSticky: !!data.sticky
isClosed: !!data.closed
# file
if data.ext or data.filedeleted
o.file =
name: data.filename + data.ext
timestamp: "#{data.tim}#{data.ext}"
url: if boardID is 'f'
"//i.4cdn.org/#{boardID}/#{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: !!data.filedeleted
Build.post o
post: (o, isArchived) ->
{
postID, threadID, boardID
name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC
isSticky, isClosed
comment
file
} = o
isOP = postID is threadID
{staticPath, gifIcon} = Build
tripcode = if tripcode
" #{tripcode}"
else
''
if email
emailStart = ''
emailEnd = ''
else
emailStart = ''
emailEnd = ''
switch capcode
when 'admin', 'admin_highlight'
capcodeClass = " capcodeAdmin"
capcodeStart = " ## Admin"
capcodeIcon = " "
when 'mod'
capcodeClass = " capcodeMod"
capcodeStart = " ## Mod"
capcodeIcon = "
"
when 'developer'
capcodeClass = " capcodeDeveloper"
capcodeStart = " ## Developer"
capcodeIcon = "
"
else
capcodeClass = ''
capcodeStart = ''
capcodeIcon = ''
userID = if uniqueID and !capcode
" (ID: " +
"#{uniqueID})"
else
''
flag = unless flagCode
''
else if boardID is 'pol'
"
"
else
" "
if file?.isDeleted
fileHTML = if isOP
"
#{comment or ''}" + '