From 6cc786cba6b68205069bd6b22bcc3e8c9d13d4ea Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 1 Mar 2012 00:26:35 +0100 Subject: [PATCH] Simpler filename truncated/full. --- 4chan_x.user.js | 62 +++++++++++++++++++++++++------------------------ script.coffee | 39 +++++++++++++++++-------------- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 400a7e729..e5e2d61e2 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2327,7 +2327,8 @@ size: 996, unit: 'KB', resolution: '1366x768', - filename: 'Untitled.png', + fullname: '[a.f.k.] Sayonara Zetsubou Sensei - 09.avi_snapshot_03.34_[2011.02.20_06.58.00].jpg', + shortname: '[a.f.k.] Sayonara Zetsubou Sen(...).jpg', type: type }; FileInfo.setFormats(); @@ -2937,17 +2938,18 @@ return g.callbacks.push(this.node); }, node: function(root) { - var filename, link, node, regexp, resolution, size, type, unit, _, _ref; + var fullname, link, node, regexp, resolution, shortname, size, type, unit, _, _ref; if (root.className === 'inline' || !(node = $('.filesize', root))) return; type = node.childElementCount === 2 ? 0 : 1; - regexp = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/][type]; - _ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; + regexp = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s([^<]+)/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/][type]; + _ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], fullname = _ref[5], shortname = _ref[6]; FileInfo.data = { link: link, size: size, unit: unit, resolution: resolution, - filename: filename, + fullname: fullname, + shortname: shortname, type: type }; return node.innerHTML = FileInfo.funks[type](FileInfo); @@ -2993,6 +2995,29 @@ return "" + size + " " + unitT; }, formatters: { + l: function() { + if (FileInfo.data.type === 0) { + return FileInfo.data.link.replace(/>\d+\.\w+" + (this.n()) + "<"); + } else { + return FileInfo.data.link; + } + }, + L: function() { + return FileInfo.data.link.replace(/>\d+\.\w+" + FileInfo.data.fullname + "<"); + }, + n: function() { + if (FileInfo.data.fullname === FileInfo.data.shortname) { + return FileInfo.data.fullname; + } else { + return "" + FileInfo.data.fullname + "" + FileInfo.data.shortname + ""; + } + }, + N: function() { + return FileInfo.data.fullname; + }, + s: function() { + return "" + FileInfo.data.size + " " + FileInfo.data.unit; + }, B: function() { return FileInfo.convertUnit('B'); }, @@ -3002,30 +3027,6 @@ M: function() { return FileInfo.convertUnit('MB'); }, - s: function() { - return "" + FileInfo.data.size + " " + FileInfo.data.unit; - }, - l: function() { - if (FileInfo.data.type === 0) { - return FileInfo.data.link.replace(/>\d+\.\w+' + this.n() + '<'); - } else { - return FileInfo.data.link; - } - }, - L: function() { - return FileInfo.data.link.replace(/>\d+\.\w+' + FileInfo.data.filename + '<'); - }, - n: function() { - var ext; - if ((ext = FileInfo.data.filename.lastIndexOf('.')) > 38) { - return "" + FileInfo.data.filename + "" + (FileInfo.data.filename.substr(0, 32)) + "(...)" + (FileInfo.data.filename.substr(ext)) + ""; - } else { - return FileInfo.data.filename; - } - }, - N: function() { - return FileInfo.data.filename; - }, r: function() { return FileInfo.data.resolution; } @@ -4135,7 +4136,8 @@ td.replyhider {\ float: left;\ pointer-events: none;\ }\ -.filesize a:not(:hover) .fnfull, .filesize a:hover .fntrunc {\ +.filename:hover > .fntrunc,\ +.filename:not(:hover) > .fnfull {\ display: none;\ }\ img[md5], img[md5] + img {\ diff --git a/script.coffee b/script.coffee index 2cf4239a4..70a48ac68 100644 --- a/script.coffee +++ b/script.coffee @@ -1910,7 +1910,8 @@ options = size: 996 unit: 'KB' resolution: '1366x768' - filename: 'Untitled.png' + fullname: '[a.f.k.] Sayonara Zetsubou Sensei - 09.avi_snapshot_03.34_[2011.02.20_06.58.00].jpg' + shortname: '[a.f.k.] Sayonara Zetsubou Sen(...).jpg' type: type FileInfo.setFormats() $.id("#{@name}Preview").innerHTML = FileInfo.funks[type] FileInfo @@ -2405,17 +2406,18 @@ FileInfo = return if root.className is 'inline' or not node = $ '.filesize', root type = if node.childElementCount is 2 then 0 else 1 regexp = [ - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/ + /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s([^<]+)/ /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ ][type] - [_, link, size, unit, resolution, filename] = + [_, link, size, unit, resolution, fullname, shortname] = node.innerHTML.match regexp FileInfo.data = link: link size: size unit: unit resolution: resolution - filename: filename + fullname: fullname + shortname: shortname type: type node.innerHTML = FileInfo.funks[type] FileInfo setFormats: -> @@ -2445,22 +2447,22 @@ FileInfo = size = size.toFixed 2 "#{size} #{unitT}" formatters: + l: -> + if FileInfo.data.type is 0 + FileInfo.data.link.replace />\d+\.\w+#{@n()}<" + else + FileInfo.data.link + L: -> FileInfo.data.link.replace />\d+\.\w+#{FileInfo.data.fullname}<" + n: -> + if FileInfo.data.fullname is FileInfo.data.shortname + FileInfo.data.fullname + else + "#{FileInfo.data.fullname}#{FileInfo.data.shortname}" + N: -> FileInfo.data.fullname + s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" B: -> FileInfo.convertUnit 'B' K: -> FileInfo.convertUnit 'KB' M: -> FileInfo.convertUnit 'MB' - s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" - l: -> - if FileInfo.data.type is 0 - FileInfo.data.link.replace />\d+\.\w+' + @n() + '<' - else - FileInfo.data.link - L: -> FileInfo.data.link.replace />\d+\.\w+' + FileInfo.data.filename + '<' - n: -> - if (ext = FileInfo.data.filename.lastIndexOf '.') > 38 - "#{FileInfo.data.filename}#{FileInfo.data.filename.substr 0, 32}(...)#{FileInfo.data.filename.substr ext}" - else - FileInfo.data.filename - N: -> FileInfo.data.filename r: -> FileInfo.data.resolution getTitle = (thread) -> @@ -3428,7 +3430,8 @@ td.replyhider { float: left; pointer-events: none; } -.filesize a:not(:hover) .fnfull, .filesize a:hover .fntrunc { +.filename:hover > .fntrunc, +.filename:not(:hover) > .fnfull { display: none; } img[md5], img[md5] + img {