Spoilered images do not show the filename, use the .title of the fileinfo.

This commit is contained in:
Nicolas Stepien 2012-08-22 23:58:09 +02:00
parent c7e5f3afab
commit 2fac05917d
3 changed files with 34 additions and 23 deletions

View File

@ -487,6 +487,15 @@
$.add(d.head, script);
return $.rm(script);
},
shortenFilename: function(filename, isOP) {
var threshold;
threshold = isOP ? 40 : 30;
if (filename.replace(/\.\w+$/, '').length > threshold) {
return "" + filename.slice(0, threshold - 5) + "(...)" + (filename.match(/\.\w+$/));
} else {
return filename;
}
},
bytesToString: function(size) {
var unit;
unit = 0;
@ -3378,23 +3387,23 @@
return Main.callbacks.push(this.node);
},
node: function(post) {
var alt, node, span;
var alt, filename, node, _ref;
if (post.isInlined && !post.isCrosspost || !post.fileInfo) {
return;
}
node = post.fileInfo.firstElementChild;
alt = post.img.alt;
span = $('span', node);
filename = ((_ref = $('span', node)) != null ? _ref.title : void 0) || node.title;
FileInfo.data = {
link: post.img.parentNode.href,
spoiler: /^Spoiler/.test(alt),
size: alt.match(/\d+\.?\d*/)[0],
unit: alt.match(/\w+$/)[0],
resolution: span.previousSibling.textContent.match(/\d+x\d+|PDF/)[0],
fullname: span.title,
shortname: span.textContent
resolution: node.textContent.match(/\d+x\d+|PDF/)[0],
fullname: filename,
shortname: $.shortenFilename(filename, post.isOP)
};
node.setAttribute('data-filename', span.title);
node.setAttribute('data-filename', filename);
return node.innerHTML = FileInfo.funk(FileInfo);
},
setFormats: function() {
@ -3537,7 +3546,7 @@
}
},
parseArchivedPost: function(req, board, postID, root, cb) {
var bq, br, capcode, data, email, file, filename, filesize, isOP, name, nameBlock, pc, pi, piM, span, spoiler, subject, threadID, threshold, thumb_src, timestamp, trip, userID;
var bq, br, capcode, data, email, file, filename, filesize, isOP, name, nameBlock, pc, pi, piM, span, spoiler, subject, threadID, thumb_src, timestamp, trip, userID;
data = JSON.parse(req.response);
$.addClass(root, 'archivedPost');
if (data.error) {
@ -3710,8 +3719,7 @@
}));
span = $('span[title]', file);
span.title = filename;
threshold = isOP ? 40 : 30;
span.textContent = filename.replace(/\.\w+$/, '').length > threshold ? "" + filename.slice(0, threshold - 5) + "(...)" + (filename.match(/\.\w+$/)) : filename;
span.textContent = $.shortenFilename(filename, isOP);
thumb_src = data.media_status === 'available' ? "src=" + data.thumb_link : '';
$.add(file, $.el('a', {
className: spoiler ? 'fileThumb imgspoiler' : 'fileThumb',

View File

@ -1,4 +1,6 @@
master
-Mayhem
Fix support of change in 4chan's HTML about hidden filename in case of spoiler.
2.34.5
- Mayhem

View File

@ -368,6 +368,15 @@ $.extend $,
script = $.el 'script', textContent: code
$.add d.head, script
$.rm script
shortenFilename: (filename, isOP) ->
# FILENAME SHORTENING SCIENCE:
# OPs have a +10 characters threshold.
# The file extension is not taken into account.
threshold = if isOP then 40 else 30
if filename.replace(/\.\w+$/, '').length > threshold
"#{filename[...threshold - 5]}(...)#{filename.match(/\.\w+$/)}"
else
filename
bytesToString: (size) ->
unit = 0 # Bytes
while size >= 1024
@ -2675,17 +2684,17 @@ FileInfo =
return if post.isInlined and not post.isCrosspost or not post.fileInfo
node = post.fileInfo.firstElementChild
alt = post.img.alt
span = $ 'span', node
filename = $('span', node)?.title or node.title
FileInfo.data =
link: post.img.parentNode.href
spoiler: /^Spoiler/.test alt
size: alt.match(/\d+\.?\d*/)[0]
unit: alt.match(/\w+$/)[0]
resolution: span.previousSibling.textContent.match(/\d+x\d+|PDF/)[0]
fullname: span.title
shortname: span.textContent
resolution: node.textContent.match(/\d+x\d+|PDF/)[0]
fullname: filename
shortname: $.shortenFilename filename, post.isOP
# XXX GM/Scriptish
node.setAttribute 'data-filename', span.title
node.setAttribute 'data-filename', filename
node.innerHTML = FileInfo.funk FileInfo
setFormats: ->
code = Conf['fileInfo'].replace /%([BKlLMnNprs])/g, (s, c) ->
@ -2954,15 +2963,7 @@ Get =
innerHTML: "<span id=fT#{postID} class=fileText>File: <a href='#{data.media_link or data.remote_media_link}' target=_blank>#{data.media_orig}</a>-(#{if spoiler then 'Spoiler Image, ' else ''}#{filesize}, #{data.media_w}x#{data.media_h}, <span title></span>)</span>"
span = $ 'span[title]', file
span.title = filename
threshold = if isOP then 40 else 30
span.textContent =
# FILENAME SHORTENING SCIENCE:
# OPs have a +10 characters threshold.
# The file extension is not taken into account.
if filename.replace(/\.\w+$/, '').length > threshold
"#{filename[...threshold - 5]}(...)#{filename.match(/\.\w+$/)}"
else
filename
span.textContent = $.shortenFilename filename, isOP
thumb_src = if data.media_status is 'available' then "src=#{data.thumb_link}" else ''
$.add file, $.el 'a',
className: if spoiler then 'fileThumb imgspoiler' else 'fileThumb'