Fix File Info Formatting.

This commit is contained in:
Nicolas Stepien 2012-05-03 12:08:31 +02:00
parent e516eed4eb
commit dc3f6b93a4
3 changed files with 99 additions and 131 deletions

View File

@ -153,8 +153,7 @@
sauces: ['http://iqdb.org/?url=$1', 'http://www.google.com/searchbyimage?image_url=$1', '#http://tineye.com/search?url=$1', '#http://saucenao.com/search.php?db=999&url=$1', '#http://3d.iqdb.org/?url=$1', '#http://regex.info/exif.cgi?imgurl=$2', '# uploaders:', '#http://imgur.com/upload?url=$2', '#http://omploader.org/upload?url1=$2', '# "View Same" in archives:', '#http://archive.foolz.us/$4/image/$3/', '#https://archive.installgentoo.net/$4/image/$3'].join('\n'), sauces: ['http://iqdb.org/?url=$1', 'http://www.google.com/searchbyimage?image_url=$1', '#http://tineye.com/search?url=$1', '#http://saucenao.com/search.php?db=999&url=$1', '#http://3d.iqdb.org/?url=$1', '#http://regex.info/exif.cgi?imgurl=$2', '# uploaders:', '#http://imgur.com/upload?url=$2', '#http://omploader.org/upload?url1=$2', '# "View Same" in archives:', '#http://archive.foolz.us/$4/image/$3/', '#https://archive.installgentoo.net/$4/image/$3'].join('\n'),
time: '%m/%d/%y(%a)%H:%M', time: '%m/%d/%y(%a)%H:%M',
backlink: '>>%id', backlink: '>>%id',
fileInfoR: '%l (%s, %r)', fileInfo: '%l (%p%s, %r)',
fileInfoT: '%l (%s, %r)',
favicon: 'ferongr', favicon: 'ferongr',
hotkeys: { hotkeys: {
openQR: ['i', 'Open QR with post number inserted'], openQR: ['i', 'Open QR with post number inserted'],
@ -2190,7 +2189,7 @@
} }
}, },
dialog: function() { dialog: function() {
var arr, back, checked, description, dialog, favicon, fileInfoR, fileInfoT, hiddenNum, hiddenThreads, indicator, indicators, input, key, li, obj, overlay, ta, time, tr, ul, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3; var arr, back, checked, description, dialog, favicon, fileInfo, hiddenNum, hiddenThreads, indicator, indicators, input, key, li, obj, overlay, ta, time, tr, ul, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3;
dialog = $.el('div', { dialog = $.el('div', {
id: 'options', id: 'options',
className: 'reply dialog', className: 'reply dialog',
@ -2268,16 +2267,13 @@
</ul>\ </ul>\
<div class=warning><code>File Info Formatting</code> is disabled.</div>\ <div class=warning><code>File Info Formatting</code> is disabled.</div>\
<ul>\ <ul>\
Thread File Info Formatting\ File Info Formatting\
<li><input type=text name=fileInfoT> : <span id=fileInfoTPreview></span></li>\ <li><input type=text name=fileInfo> : <span id=fileInfoPreview></span></li>\
<li>Link: %l (lowercase L)</li>\ <li>Link (with original file name): %l (lowercase L, truncated), %L (untruncated)</li>\
<li>Original file name: %n (Truncated), %N (Untruncated)</li>\
<li>Spoiler indicator: %p</li>\
<li>Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)</li>\ <li>Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)</li>\
<li>Resolution: %r (Displays PDF on /po/, for PDFs)</li>\ <li>Resolution: %r (Displays PDF on /po/, for PDFs)</li>\
Reply File Info Formatting\
<li><input type=text name=fileInfoR> : <span id=fileInfoRPreview></span></li>\
<li>All thread formatters also work for reply formatting.</li>\
<li>Link (with original file name): %l (lowercase L)(Truncated), %L (Untruncated)</li>\
<li>Original file name: %n (Truncated), %N (Untruncated)</li>\
</ul>\ </ul>\
<div class=warning><code>Unread Favicon</code> is disabled.</div>\ <div class=warning><code>Unread Favicon</code> is disabled.</div>\
Unread favicons<br>\ Unread favicons<br>\
@ -2332,16 +2328,13 @@
} }
(back = $('[name=backlink]', dialog)).value = Conf['backlink']; (back = $('[name=backlink]', dialog)).value = Conf['backlink'];
(time = $('[name=time]', dialog)).value = Conf['time']; (time = $('[name=time]', dialog)).value = Conf['time'];
(fileInfoR = $('[name=fileInfoR]', dialog)).value = Conf['fileInfoR']; (fileInfo = $('[name=fileInfo]', dialog)).value = Conf['fileInfo'];
(fileInfoT = $('[name=fileInfoT]', dialog)).value = Conf['fileInfoT'];
$.on(back, 'keyup', $.cb.value); $.on(back, 'keyup', $.cb.value);
$.on(back, 'keyup', Options.backlink); $.on(back, 'keyup', Options.backlink);
$.on(time, 'keyup', $.cb.value); $.on(time, 'keyup', $.cb.value);
$.on(time, 'keyup', Options.time); $.on(time, 'keyup', Options.time);
$.on(fileInfoR, 'keyup', $.cb.value); $.on(fileInfo, 'keyup', $.cb.value);
$.on(fileInfoR, 'keyup', Options.fileInfo); $.on(fileInfo, 'keyup', Options.fileInfo);
$.on(fileInfoT, 'keyup', $.cb.value);
$.on(fileInfoT, 'keyup', Options.fileInfo);
favicon = $('select', dialog); favicon = $('select', dialog);
favicon.value = Conf['favicon']; favicon.value = Conf['favicon'];
$.on(favicon, 'change', $.cb.value); $.on(favicon, 'change', $.cb.value);
@ -2380,8 +2373,7 @@
d.body.style.setProperty('overflow', 'hidden', null); d.body.style.setProperty('overflow', 'hidden', null);
Options.backlink.call(back); Options.backlink.call(back);
Options.time.call(time); Options.time.call(time);
Options.fileInfo.call(fileInfoR); Options.fileInfo.call(fileInfo);
Options.fileInfo.call(fileInfoT);
return Options.favicon.call(favicon); return Options.favicon.call(favicon);
}, },
close: function() { close: function() {
@ -2416,19 +2408,17 @@
return $.id('backlinkPreview').textContent = Conf['backlink'].replace(/%id/, '123456789'); return $.id('backlinkPreview').textContent = Conf['backlink'].replace(/%id/, '123456789');
}, },
fileInfo: function() { fileInfo: function() {
var type;
type = this.name === 'fileInfoR' ? 0 : 1;
FileInfo.data = { FileInfo.data = {
link: '<a href="javascript:;">1329791824.png</a>', link: 'javascript:;',
size: 996, spoiler: true,
size: '276',
unit: 'KB', unit: 'KB',
resolution: '1366x768', resolution: '1280x720',
fullname: '[a.f.k.] Sayonara Zetsubou Sensei - 09.avi_snapshot_03.34_[2011.02.20_06.58.00].jpg', fullname: 'd9bb2efc98dd0df141a94399ff5880b7.jpg',
shortname: '[a.f.k.] Sayonara Zetsubou Sen(...).jpg', shortname: 'd9bb2efc98dd0df141a94399ff5880(...).jpg'
type: type
}; };
FileInfo.setFormats(); FileInfo.setFormats();
return $.id("" + this.name + "Preview").innerHTML = FileInfo.funks[type](FileInfo); return $.id('fileInfoPreview').innerHTML = FileInfo.funk(FileInfo);
}, },
favicon: function() { favicon: function() {
Favicon["switch"](); Favicon["switch"]();
@ -2917,42 +2907,34 @@
return Main.callbacks.push(this.node); return Main.callbacks.push(this.node);
}, },
node: function(post) { node: function(post) {
var data, link, node, regexp, resolution, size, span, unit, _, _ref; var alt, node, span;
if (post.isInlined && !post.isCrosspost || !(node = post.filesize)) { if (post.isInlined && !post.isCrosspost || !post.fileInfo) {
return; return;
} }
regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/; node = post.fileInfo.firstElementChild;
_ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4]; alt = post.img.alt;
data = { span = $('span', node);
link: link, FileInfo.data = {
size: size, link: post.img.parentNode.href,
unit: unit, spoiler: /^Spoiler/.test(alt),
resolution: resolution size: alt.match(/\d+/)[0],
unit: alt.match(/\w+$/)[0],
resolution: span.previousSibling.textContent.match(/\d+x\d+|PDF/)[0],
fullname: span.title,
shortname: span.textContent
}; };
if (span = $('span', node)) { return node.innerHTML = FileInfo.funk(FileInfo);
data.fullname = span.title;
data.shortname = span.textContent;
}
data.type = +(!span);
FileInfo.data = data;
return node.innerHTML = FileInfo.funks[data.type](FileInfo);
}, },
setFormats: function() { setFormats: function() {
var code, format, funks, i, param, _i; var code;
funks = []; code = Conf['fileInfo'].replace(/%([BKlLMnNprs])/g, function(s, c) {
for (i = _i = 0; _i <= 1; i = ++_i) { if (c in FileInfo.formatters) {
format = i ? Conf['fileInfoT'] : Conf['fileInfoR']; return "' + f.formatters." + c + "() + '";
param = i ? /%([BKlMrs])/g : /%([BKlLMnNrs])/g; } else {
code = format.replace(param, function(s, c) { return s;
if (c in FileInfo.formatters) { }
return "' + f.formatters." + c + "() + '"; });
} else { return this.funk = Function('f', "return '" + code + "'");
return s;
}
});
funks.push(Function('f', "return '" + code + "'"));
}
return this.funks = funks;
}, },
convertUnit: function(unitT) { convertUnit: function(unitT) {
var i, size, unitF, units; var i, size, unitF, units;
@ -2981,25 +2963,28 @@
}, },
formatters: { formatters: {
l: function() { l: function() {
if (FileInfo.data.type === 0) { return "<a href=" + FileInfo.data.link + " target=_blank>" + (this.n()) + "</a>";
return FileInfo.data.link.replace(/>\d+\.\w+</, ">" + (this.n()) + "<");
} else {
return FileInfo.data.link;
}
}, },
L: function() { L: function() {
return FileInfo.data.link.replace(/>\d+\.\w+</, ">" + FileInfo.data.fullname + "<"); return "<a href=" + FileInfo.data.link + " target=_blank>" + (this.N()) + "</a>";
}, },
n: function() { n: function() {
if (FileInfo.data.fullname === FileInfo.data.shortname) { if (FileInfo.data.fullname === FileInfo.data.shortname) {
return FileInfo.data.fullname; return FileInfo.data.fullname;
} else { } else {
return "<span class=filename><span class=fnfull>" + FileInfo.data.fullname + "</span><span class=fntrunc>" + FileInfo.data.shortname + "</span></span>"; return "<span class=fntrunc>" + FileInfo.data.shortname + "</span><span class=fnfull>" + FileInfo.data.fullname + "</span>";
} }
}, },
N: function() { N: function() {
return FileInfo.data.fullname; return FileInfo.data.fullname;
}, },
p: function() {
if (FileInfo.data.spoiler) {
return 'Spoiler, ';
} else {
return '';
}
},
s: function() { s: function() {
return "" + FileInfo.data.size + " " + FileInfo.data.unit; return "" + FileInfo.data.size + " " + FileInfo.data.unit;
}, },
@ -4440,8 +4425,8 @@ textarea.field {\
float: left;\ float: left;\
pointer-events: none;\ pointer-events: none;\
}\ }\
.filename:hover > .fntrunc,\ .fileText:hover .fntrunc,\
.filename:not(:hover) > .fnfull {\ .fileText:not(:hover) .fnfull {\
display: none;\ display: none;\
}\ }\
img[data-md5], img[data-md5] + img {\ img[data-md5], img[data-md5] + img {\

View File

@ -1,4 +1,6 @@
master master
- Mayhem
Add Spoiler indicator option in File Info Formatting
2.29.4 2.29.4
- Mayhem - Mayhem

View File

@ -114,8 +114,7 @@ Config =
].join '\n' ].join '\n'
time: '%m/%d/%y(%a)%H:%M' time: '%m/%d/%y(%a)%H:%M'
backlink: '>>%id' backlink: '>>%id'
fileInfoR: '%l (%s, %r)' fileInfo: '%l (%p%s, %r)'
fileInfoT: '%l (%s, %r)'
favicon: 'ferongr' favicon: 'ferongr'
hotkeys: hotkeys:
# QR & Options # QR & Options
@ -1779,16 +1778,13 @@ Options =
</ul> </ul>
<div class=warning><code>File Info Formatting</code> is disabled.</div> <div class=warning><code>File Info Formatting</code> is disabled.</div>
<ul> <ul>
Thread File Info Formatting File Info Formatting
<li><input type=text name=fileInfoT> : <span id=fileInfoTPreview></span></li> <li><input type=text name=fileInfo> : <span id=fileInfoPreview></span></li>
<li>Link: %l (lowercase L)</li> <li>Link (with original file name): %l (lowercase L, truncated), %L (untruncated)</li>
<li>Original file name: %n (Truncated), %N (Untruncated)</li>
<li>Spoiler indicator: %p</li>
<li>Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)</li> <li>Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)</li>
<li>Resolution: %r (Displays PDF on /po/, for PDFs)</li> <li>Resolution: %r (Displays PDF on /po/, for PDFs)</li>
Reply File Info Formatting
<li><input type=text name=fileInfoR> : <span id=fileInfoRPreview></span></li>
<li>All thread formatters also work for reply formatting.</li>
<li>Link (with original file name): %l (lowercase L)(Truncated), %L (Untruncated)</li>
<li>Original file name: %n (Truncated), %N (Untruncated)</li>
</ul> </ul>
<div class=warning><code>Unread Favicon</code> is disabled.</div> <div class=warning><code>Unread Favicon</code> is disabled.</div>
Unread favicons<br> Unread favicons<br>
@ -1836,18 +1832,15 @@ Options =
$.on ta, 'change', $.cb.value $.on ta, 'change', $.cb.value
#rice #rice
(back = $ '[name=backlink]', dialog).value = Conf['backlink'] (back = $ '[name=backlink]', dialog).value = Conf['backlink']
(time = $ '[name=time]', dialog).value = Conf['time'] (time = $ '[name=time]', dialog).value = Conf['time']
(fileInfoR = $ '[name=fileInfoR]', dialog).value = Conf['fileInfoR'] (fileInfo = $ '[name=fileInfo]', dialog).value = Conf['fileInfo']
(fileInfoT = $ '[name=fileInfoT]', dialog).value = Conf['fileInfoT']
$.on back, 'keyup', $.cb.value $.on back, 'keyup', $.cb.value
$.on back, 'keyup', Options.backlink $.on back, 'keyup', Options.backlink
$.on time, 'keyup', $.cb.value $.on time, 'keyup', $.cb.value
$.on time, 'keyup', Options.time $.on time, 'keyup', Options.time
$.on fileInfoR, 'keyup', $.cb.value $.on fileInfo, 'keyup', $.cb.value
$.on fileInfoR, 'keyup', Options.fileInfo $.on fileInfo, 'keyup', Options.fileInfo
$.on fileInfoT, 'keyup', $.cb.value
$.on fileInfoT, 'keyup', Options.fileInfo
favicon = $ 'select', dialog favicon = $ 'select', dialog
favicon.value = Conf['favicon'] favicon.value = Conf['favicon']
$.on favicon, 'change', $.cb.value $.on favicon, 'change', $.cb.value
@ -1880,8 +1873,7 @@ Options =
Options.backlink.call back Options.backlink.call back
Options.time.call time Options.time.call time
Options.fileInfo.call fileInfoR Options.fileInfo.call fileInfo
Options.fileInfo.call fileInfoT
Options.favicon.call favicon Options.favicon.call favicon
close: -> close: ->
@ -1909,17 +1901,16 @@ Options =
backlink: -> backlink: ->
$.id('backlinkPreview').textContent = Conf['backlink'].replace /%id/, '123456789' $.id('backlinkPreview').textContent = Conf['backlink'].replace /%id/, '123456789'
fileInfo: -> fileInfo: ->
type = if @name is 'fileInfoR' then 0 else 1
FileInfo.data = FileInfo.data =
link: '<a href="javascript:;">1329791824.png</a>' link: 'javascript:;'
size: 996 spoiler: true
size: '276'
unit: 'KB' unit: 'KB'
resolution: '1366x768' resolution: '1280x720'
fullname: '[a.f.k.] Sayonara Zetsubou Sensei - 09.avi_snapshot_03.34_[2011.02.20_06.58.00].jpg' fullname: 'd9bb2efc98dd0df141a94399ff5880b7.jpg'
shortname: '[a.f.k.] Sayonara Zetsubou Sen(...).jpg' shortname: 'd9bb2efc98dd0df141a94399ff5880(...).jpg'
type: type
FileInfo.setFormats() FileInfo.setFormats()
$.id("#{@name}Preview").innerHTML = FileInfo.funks[type] FileInfo $.id('fileInfoPreview').innerHTML = FileInfo.funk FileInfo
favicon: -> favicon: ->
Favicon.switch() Favicon.switch()
Unread.update true Unread.update true
@ -2295,33 +2286,26 @@ FileInfo =
@setFormats() @setFormats()
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.isInlined and not post.isCrosspost or not node = post.filesize return if post.isInlined and not post.isCrosspost or not post.fileInfo
regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/ node = post.fileInfo.firstElementChild
[_, link, size, unit, resolution] = alt = post.img.alt
node.innerHTML.match regexp span = $ 'span', node
data = FileInfo.data =
link: link link: post.img.parentNode.href
size: size spoiler: /^Spoiler/.test alt
unit: unit size: alt.match(/\d+/)[0]
resolution: resolution unit: alt.match(/\w+$/)[0]
if span = $ 'span', node resolution: span.previousSibling.textContent.match(/\d+x\d+|PDF/)[0]
data.fullname = span.title fullname: span.title
data.shortname = span.textContent shortname: span.textContent
data.type = +!span node.innerHTML = FileInfo.funk FileInfo
FileInfo.data = data
node.innerHTML = FileInfo.funks[data.type] FileInfo
setFormats: -> setFormats: ->
funks = [] code = Conf['fileInfo'].replace /%([BKlLMnNprs])/g, (s, c) ->
for i in [0..1] if c of FileInfo.formatters
format = if i then Conf['fileInfoT'] else Conf['fileInfoR'] "' + f.formatters.#{c}() + '"
param = if i then /%([BKlMrs])/g else /%([BKlLMnNrs])/g else
code = format.replace param, (s, c) -> s
if c of FileInfo.formatters @funk = Function 'f', "return '#{code}'"
"' + f.formatters.#{c}() + '"
else
s
funks.push Function 'f', "return '#{code}'"
@funks = funks
convertUnit: (unitT) -> convertUnit: (unitT) ->
size = @data.size size = @data.size
unitF = @data.unit unitF = @data.unit
@ -2337,18 +2321,15 @@ FileInfo =
size = size.toFixed 2 size = size.toFixed 2
"#{size} #{unitT}" "#{size} #{unitT}"
formatters: formatters:
l: -> l: -> "<a href=#{FileInfo.data.link} target=_blank>#{@n()}</a>"
if FileInfo.data.type is 0 L: -> "<a href=#{FileInfo.data.link} target=_blank>#{@N()}</a>"
FileInfo.data.link.replace />\d+\.\w+</, ">#{@n()}<"
else
FileInfo.data.link
L: -> FileInfo.data.link.replace />\d+\.\w+</, ">#{FileInfo.data.fullname}<"
n: -> n: ->
if FileInfo.data.fullname is FileInfo.data.shortname if FileInfo.data.fullname is FileInfo.data.shortname
FileInfo.data.fullname FileInfo.data.fullname
else else
"<span class=filename><span class=fnfull>#{FileInfo.data.fullname}</span><span class=fntrunc>#{FileInfo.data.shortname}</span></span>" "<span class=fntrunc>#{FileInfo.data.shortname}</span><span class=fnfull>#{FileInfo.data.fullname}</span>"
N: -> FileInfo.data.fullname N: -> FileInfo.data.fullname
p: -> if FileInfo.data.spoiler then 'Spoiler, ' else ''
s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}"
B: -> FileInfo.convertUnit 'B' B: -> FileInfo.convertUnit 'B'
K: -> FileInfo.convertUnit 'KB' K: -> FileInfo.convertUnit 'KB'
@ -3453,8 +3434,8 @@ textarea.field {
float: left; float: left;
pointer-events: none; pointer-events: none;
} }
.filename:hover > .fntrunc, .fileText:hover .fntrunc,
.filename:not(:hover) > .fnfull { .fileText:not(:hover) .fnfull {
display: none; display: none;
} }
img[data-md5], img[data-md5] + img { img[data-md5], img[data-md5] + img {