diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 9e5b7ab58..f7395d548 100755 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -1,10 +1,14 @@ Build = - staticPath: '//s.4cdn.org/image/' - gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif' + h_staticPath: '//s.4cdn.org/image/' + h_gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif' spoilerRange: {} - escape: (name) -> - name.replace /[&"'<>]/g, (c) -> - {'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[c] + h_escape: (text) -> + (text+'').replace /[&"'<>]/g, (c) -> + {'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[c] + unescape: (text) -> + return text unless text? + text.replace /&(amp|#039|quot|lt|gt);/g, (c) -> + {'&': '&', ''': "'", '"': '"', '<': '<', '>': '>'}[c] shortFilename: (filename, isReply) -> # FILENAME SHORTENING SCIENCE: # OPs have a +10 characters threshold. @@ -25,27 +29,30 @@ Build = threadID: data.resto or data.no boardID: boardID # info - name: data.name + name: Build.unescape 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 + email: Build.unescape data.email + subject: Build.unescape data.sub flagCode: data.country - flagName: data.country_name + flagName: Build.unescape data.country_name date: data.now dateUTC: data.time - comment: data.com + h_comment: data.com or '' # thread status isSticky: !!data.sticky isClosed: !!data.closed # file - if data.ext or data.filedeleted + if data.filedeleted o.file = - name: data.filename + data.ext + 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}".replace /'/g, ''' + "//i.4cdn.org/#{boardID}/#{encodeURIComponent data.filename}#{data.ext}" else "//i.4cdn.org/#{boardID}/#{data.tim}#{data.ext}" height: data.h @@ -56,144 +63,146 @@ Build = theight: data.tn_h twidth: data.tn_w isSpoiler: !!data.spoiler - isDeleted: !!data.filedeleted + isDeleted: false Build.post o post: (o, isArchived) -> ### This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS). @license: https://github.com/4chan/4chan-JS/blob/master/LICENSE ### + E = Build.h_escape { postID, threadID, boardID name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC isSticky, isClosed - comment + h_comment file } = o + name or= '' + subject or= '' isOP = postID is threadID - {staticPath, gifIcon} = Build + {h_staticPath, h_gifIcon} = Build - tripcode = if tripcode - " #{tripcode}" + if isOP + h_sideArrows = '' else - '' + h_sideArrows = "
"
+ if !capcode and uniqueID
+ h_userID = " (ID: #{E uniqueID}) "
else
- " "
+ h_userID = ''
+
+ unless flagCode
+ h_flag = ''
+ else if boardID is 'pol'
+ h_flag = "
"
+ else
+ h_flag = " "
if file?.isDeleted
- fileHTML = if isOP
- "' + '[code]': '' '[/code]': '' '[moot]': '' '[/moot]': '' diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index f228b9031..c091b15cc 100755 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -417,7 +417,7 @@ Settings = dimensions: '1280x720' isImage: true isSpoiler: true - @nextElementSibling.innerHTML = FileInfo.format @value, data + @nextElementSibling.innerHTML = FileInfo.h_format @value, data favicon: -> Favicon.switch() Unread.update() if g.VIEW is 'thread' and Conf['Unread Favicon'] diff --git a/src/General/html/Build/post.html b/src/General/html/Build/post.html index c92354f68..30147d121 100755 --- a/src/General/html/Build/post.html +++ b/src/General/html/Build/post.html @@ -1,36 +1,26 @@ -"""#{if isOP then '' else ">>"} -+"""#{h_sideArrows} +- #{if isOP then fileHTML else ''} + #{if isOP then h_file else ''} -- - #{' '}#{subject or ''}#{' '} - - #{emailStart} - #{name or ''} - #{tripcode + capcodeStart + emailEnd + capcodeIcon + userID + flag} - #{" "} - #{date}#{' '} +""" diff --git a/src/Miscellaneous/FileInfo.coffee b/src/Miscellaneous/FileInfo.coffee index 2f89bbb26..4ec8b6183 100755 --- a/src/Miscellaneous/FileInfo.coffee +++ b/src/Miscellaneous/FileInfo.coffee @@ -7,39 +7,29 @@ FileInfo = cb: @node node: -> return if !@file or @isClone - @file.text.innerHTML = "#{FileInfo.format Conf['fileInfo'], @}" - format: (formatString, post) -> + @file.text.innerHTML = "#{FileInfo.h_format Conf['fileInfo'], @}" + h_format: (formatString, post) -> formatString.replace /%([A-Za-z])|[^%]+/g, (s, c) -> - if c of FileInfo.formatters - FileInfo.formatters[c].call(post) + if c of FileInfo.h_formatters + FileInfo.h_formatters[c].call(post) else - Build.escape s - convertUnit: (size, unit) -> - if unit is 'B' - return "#{size.toFixed()} Bytes" - i = 1 + ['KB', 'MB'].indexOf unit - size /= 1024 while i-- - size = if unit is 'MB' - Math.round(size * 100) / 100 - else - size.toFixed() - "#{size} #{unit}" - formatters: - t: -> Build.escape @file.URL.match(/\d+\..+$/)[0] - T: -> "#{FileInfo.formatters.t.call @}" - l: -> "#{FileInfo.formatters.n.call @}" - L: -> "#{FileInfo.formatters.N.call @}" + Build.h_escape s + h_formatters: + t: -> Build.h_escape @file.URL.match(/\d+\..+$/)[0] + T: -> "#{FileInfo.h_formatters.t.call @}" + l: -> "#{FileInfo.h_formatters.n.call @}" + L: -> "#{FileInfo.h_formatters.N.call @}" n: -> fullname = @file.name shortname = Build.shortFilename @file.name, @isReply if fullname is shortname - Build.escape fullname + Build.h_escape fullname else - "#{Build.escape shortname}#{Build.escape fullname}" - N: -> Build.escape @file.name + "#{Build.h_escape shortname}#{Build.h_escape fullname}" + N: -> Build.h_escape @file.name p: -> if @file.isSpoiler then 'Spoiler, ' else '' - s: -> Build.escape @file.size - B: -> FileInfo.convertUnit @file.sizeInBytes, 'B' - K: -> FileInfo.convertUnit @file.sizeInBytes, 'KB' - M: -> FileInfo.convertUnit @file.sizeInBytes, 'MB' - r: -> Build.escape (@file.dimensions or 'PDF') + s: -> Build.h_escape @file.size + B: -> return "#{+@file.sizeInBytes} Bytes" + K: -> "#{+Math.round(@file.sizeInBytes/1024)} KB" + M: -> "#{+Math.round(@file.sizeInBytes/1048576*100)/100} MB" + r: -> Build.h_escape (@file.dimensions or 'PDF')+ + #{' '}#{E subject}#{' '} + + #{h_emailStart} + #{E name} + #{h_tripcode}#{h_capcodeStart}#{h_emailEnd}#{h_capcodeIcon}#{h_userID}#{h_flag} + #{' '} + #{E date}#{' '} - No. - #{postID} - #{pageIcon + sticky + closed + replyLink} + No. + #{+postID} + #{h_pageIcon}#{h_sticky}#{h_closed}#{h_replyLink}- #{if isOP then '' else fileHTML} + #{if isOP then '' else h_file} -#{comment or ''}#{' '} +#{h_comment}#{' '}