Some FileInfo refactoring. Fix FileInfo preview in options when it was disabled.
This commit is contained in:
parent
28923042ab
commit
9d0594312e
@ -2931,29 +2931,22 @@
|
|||||||
FileInfo = {
|
FileInfo = {
|
||||||
init: function() {
|
init: function() {
|
||||||
if (g.BOARD === 'f') return;
|
if (g.BOARD === 'f') return;
|
||||||
FileInfo.ffConf = ['fileInfoR', 'fileInfoT'];
|
|
||||||
FileInfo.ffMtrs = [/%([BKlLMnNrs])/g, /%([BKlMrs])/g];
|
|
||||||
FileInfo.ffRgex = [/File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s<span\stitle=\"([^\"]+)\">/, /File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/];
|
|
||||||
this.parse = function(node) {
|
|
||||||
var filename, link, resolution, size, unit, _, _ref;
|
|
||||||
FileInfo.ffType = node.childNodes.length > 3 ? 0 : 1;
|
|
||||||
_ref = node.innerHTML.match(FileInfo.ffRgex[FileInfo.ffType]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5];
|
|
||||||
return {
|
|
||||||
link: link,
|
|
||||||
size: size,
|
|
||||||
unit: unit,
|
|
||||||
resolution: resolution,
|
|
||||||
filename: filename
|
|
||||||
};
|
|
||||||
};
|
|
||||||
FileInfo.funks = FileInfo.setFormats();
|
FileInfo.funks = FileInfo.setFormats();
|
||||||
return g.callbacks.push(this.node);
|
return g.callbacks.push(this.node);
|
||||||
},
|
},
|
||||||
node: function(root) {
|
node: function(root) {
|
||||||
var node;
|
var filename, link, node, resolution, size, unit, _, _ref;
|
||||||
if (root.className === 'inline' || !(node = $('.filesize', root))) return;
|
if (root.className === 'inline' || !(node = $('.filesize', root))) return;
|
||||||
FileInfo.data = FileInfo.parse(node);
|
FileInfo.ffType = node.childElementCount === 2 ? 0 : 1;
|
||||||
return node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo) + ' ';
|
_ref = node.innerHTML.match(FileInfo.ffRgex[FileInfo.ffType]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5];
|
||||||
|
FileInfo.data = {
|
||||||
|
link: link,
|
||||||
|
size: size,
|
||||||
|
unit: unit,
|
||||||
|
resolution: resolution,
|
||||||
|
filename: filename
|
||||||
|
};
|
||||||
|
return node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo);
|
||||||
},
|
},
|
||||||
setFormats: function() {
|
setFormats: function() {
|
||||||
var code, i, _results;
|
var code, i, _results;
|
||||||
@ -2993,6 +2986,9 @@
|
|||||||
}
|
}
|
||||||
return "" + size + " " + unitT;
|
return "" + size + " " + unitT;
|
||||||
},
|
},
|
||||||
|
ffConf: ['fileInfoR', 'fileInfoT'],
|
||||||
|
ffMtrs: [/%([BKlLMnNrs])/g, /%([BKlMrs])/g],
|
||||||
|
ffRgex: [/File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s<span\stitle=\"([^\"]+)\">/, /File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/],
|
||||||
formatters: {
|
formatters: {
|
||||||
B: function() {
|
B: function() {
|
||||||
return FileInfo.convertUnit('B');
|
return FileInfo.convertUnit('B');
|
||||||
|
|||||||
@ -2398,26 +2398,20 @@ Time =
|
|||||||
FileInfo =
|
FileInfo =
|
||||||
init: ->
|
init: ->
|
||||||
return if g.BOARD is 'f'
|
return if g.BOARD is 'f'
|
||||||
FileInfo.ffConf = [ 'fileInfoR', 'fileInfoT' ]
|
|
||||||
FileInfo.ffMtrs = [ /%([BKlLMnNrs])/g, /%([BKlMrs])/g ]
|
|
||||||
FileInfo.ffRgex = [ /File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s<span\stitle=\"([^\"]+)\">/,
|
|
||||||
/File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ ]
|
|
||||||
@parse = (node) ->
|
|
||||||
FileInfo.ffType = if node.childNodes.length > 3 then 0 else 1
|
|
||||||
[_, link, size, unit, resolution, filename] =
|
|
||||||
node.innerHTML.match FileInfo.ffRgex[FileInfo.ffType]
|
|
||||||
link : link
|
|
||||||
size : size
|
|
||||||
unit : unit
|
|
||||||
resolution: resolution
|
|
||||||
filename : filename
|
|
||||||
|
|
||||||
FileInfo.funks = FileInfo.setFormats()
|
FileInfo.funks = FileInfo.setFormats()
|
||||||
g.callbacks.push @node
|
g.callbacks.push @node
|
||||||
node: (root) ->
|
node: (root) ->
|
||||||
return if root.className is 'inline' or not node = $ '.filesize', root
|
return if root.className is 'inline' or not node = $ '.filesize', root
|
||||||
FileInfo.data = FileInfo.parse node
|
FileInfo.ffType = if node.childElementCount is 2 then 0 else 1
|
||||||
node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo) + ' '
|
[_, link, size, unit, resolution, filename] =
|
||||||
|
node.innerHTML.match FileInfo.ffRgex[FileInfo.ffType]
|
||||||
|
FileInfo.data =
|
||||||
|
link: link
|
||||||
|
size: size
|
||||||
|
unit: unit
|
||||||
|
resolution: resolution
|
||||||
|
filename: filename
|
||||||
|
node.innerHTML = FileInfo.funks[FileInfo.ffType] FileInfo
|
||||||
setFormats: ->
|
setFormats: ->
|
||||||
for i in [0..1]
|
for i in [0..1]
|
||||||
code = conf[FileInfo.ffConf[i]].replace FileInfo.ffMtrs[i], (s, c) ->
|
code = conf[FileInfo.ffConf[i]].replace FileInfo.ffMtrs[i], (s, c) ->
|
||||||
@ -2430,8 +2424,8 @@ FileInfo =
|
|||||||
size = FileInfo.data.size
|
size = FileInfo.data.size
|
||||||
unitF = FileInfo.data.unit
|
unitF = FileInfo.data.unit
|
||||||
if unitF isnt unitT
|
if unitF isnt unitT
|
||||||
units = [ 'B', 'KB', 'MB' ]
|
units = ['B', 'KB', 'MB']
|
||||||
i = units.indexOf(unitF) - units.indexOf(unitT)
|
i = units.indexOf(unitF) - units.indexOf unitT
|
||||||
unitT = 'Bytes' if unitT is 'B'
|
unitT = 'Bytes' if unitT is 'B'
|
||||||
if i > 0
|
if i > 0
|
||||||
size *= 1024 while i-- > 0
|
size *= 1024 while i-- > 0
|
||||||
@ -2440,19 +2434,33 @@ FileInfo =
|
|||||||
if size < 1 and size.toString().length > size.toFixed(2).length
|
if size < 1 and size.toString().length > size.toFixed(2).length
|
||||||
size = size.toFixed 2
|
size = size.toFixed 2
|
||||||
"#{size} #{unitT}"
|
"#{size} #{unitT}"
|
||||||
|
ffConf: [
|
||||||
|
'fileInfoR'
|
||||||
|
'fileInfoT'
|
||||||
|
]
|
||||||
|
ffMtrs: [
|
||||||
|
/%([BKlLMnNrs])/g
|
||||||
|
/%([BKlMrs])/g
|
||||||
|
]
|
||||||
|
ffRgex: [
|
||||||
|
/File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s<span\stitle=\"([^\"]+)\">/
|
||||||
|
/File:\s(<a.+<\/a>)-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/
|
||||||
|
]
|
||||||
formatters:
|
formatters:
|
||||||
B: -> FileInfo.convertUnit 'B'
|
B: -> FileInfo.convertUnit 'B'
|
||||||
K: -> FileInfo.convertUnit 'KB'
|
K: -> FileInfo.convertUnit 'KB'
|
||||||
l: -> if FileInfo.ffType is 0
|
l: ->
|
||||||
FileInfo.data.link.replace />\d+\.\w+</, '>' + FileInfo.formatters.n() + '<'
|
if FileInfo.ffType is 0
|
||||||
else
|
FileInfo.data.link.replace />\d+\.\w+</, '>' + FileInfo.formatters.n() + '<'
|
||||||
FileInfo.data.link
|
else
|
||||||
|
FileInfo.data.link
|
||||||
L: -> FileInfo.data.link.replace />\d+\.\w+</, '>' + FileInfo.data.filename + '<'
|
L: -> FileInfo.data.link.replace />\d+\.\w+</, '>' + FileInfo.data.filename + '<'
|
||||||
M: -> FileInfo.convertUnit 'MB'
|
M: -> FileInfo.convertUnit 'MB'
|
||||||
n: -> if (ext = FileInfo.data.filename.lastIndexOf '.') > 38
|
n: ->
|
||||||
'<span class=fnfull>' + FileInfo.data.filename + '</span><span class=fntrunc>' + FileInfo.data.filename.substr(0, 32) + ' (...)' + FileInfo.data.filename.substr(ext) + '</span>'
|
if (ext = FileInfo.data.filename.lastIndexOf '.') > 38
|
||||||
else
|
'<span class=fnfull>' + FileInfo.data.filename + '</span><span class=fntrunc>' + FileInfo.data.filename.substr(0, 32) + ' (...)' + FileInfo.data.filename.substr(ext) + '</span>'
|
||||||
FileInfo.data.filename
|
else
|
||||||
|
FileInfo.data.filename
|
||||||
N: -> FileInfo.data.filename
|
N: -> FileInfo.data.filename
|
||||||
r: -> FileInfo.data.resolution
|
r: -> FileInfo.data.resolution
|
||||||
s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}"
|
s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user