From bfbfcf1de967c80ae3c232f50a0b68ae7a566716 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 10 Jul 2012 15:56:04 +0200 Subject: [PATCH] Update filename threshold in parseArchivedPost. --- 4chan_x.user.js | 6 +++--- script.coffee | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index be9c177ec..87a7b9a24 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3497,7 +3497,7 @@ } }, parseArchivedPost: function(req, board, postID, root, cb) { - var bq, br, capcode, data, email, file, filename, filesize, isOP, max, name, nameBlock, pc, pi, piM, span, spoiler, subject, threadID, thumb_src, timestamp, trip; + var bq, br, capcode, data, email, file, filename, filesize, isOP, name, nameBlock, pc, pi, piM, span, spoiler, subject, threadID, threshold, thumb_src, timestamp, trip; data = JSON.parse(req.response); $.addClass(root, 'archivedPost'); if (data.error) { @@ -3635,8 +3635,8 @@ })); span = $('span[title]', file); span.title = filename; - max = isOP ? 40 : 30; - span.textContent = filename.replace(/\.\w+$/, '').length > max ? "" + filename.slice(0, max) + "(...)" + (filename.match(/\.\w+$/)) : filename; + threshold = isOP ? 40 : 30; + span.textContent = filename.replace(/\.\w+$/, '').length > threshold ? "" + filename.slice(0, threshold - 5) + "(...)" + (filename.match(/\.\w+$/)) : filename; thumb_src = data.media_status === 'available' ? "src=" + data.thumb_link : ''; $.add(file, $.el('a', { className: spoiler ? 'fileThumb imgspoiler' : 'fileThumb', diff --git a/script.coffee b/script.coffee index b1a879bef..e0241584f 100644 --- a/script.coffee +++ b/script.coffee @@ -2892,15 +2892,13 @@ Get = innerHTML: "File: #{data.media_orig}-(#{if spoiler then 'Spoiler Image, ' else ''}#{filesize}, #{data.media_w}x#{data.media_h}, )" span = $ 'span[title]', file span.title = filename - max = if isOP then 40 else 30 + threshold = if isOP then 40 else 30 span.textContent = # FILENAME SHORTENING SCIENCE: - # OPs have +10 characters max. + # OPs have a +10 characters threshold. # The file extension is not taken into account. - # abcdefghijklmnopqrstuvwxyz_1234.jpg is shortened. - # abcdefghijklmnopqrstuvwxyz_123.jpg is not shortened. - if filename.replace(/\.\w+$/, '').length > max - "#{filename[...max]}(...)#{filename.match(/\.\w+$/)}" + if filename.replace(/\.\w+$/, '').length > threshold + "#{filename[...threshold - 5]}(...)#{filename.match(/\.\w+$/)}" else filename thumb_src = if data.media_status is 'available' then "src=#{data.thumb_link}" else ''