mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 23:37:58 +01:00
better byte formating
This commit is contained in:
@@ -494,14 +494,14 @@ vimperator.Buffer = function () //{{{
|
|||||||
|
|
||||||
pageInfo: function (verbose)
|
pageInfo: function (verbose)
|
||||||
{
|
{
|
||||||
// TODO: copied from firefox. Needs some review/work...
|
const feedTypes = {
|
||||||
// const feedTypes = {
|
"application/rss+xml": "RSS",
|
||||||
// "application/rss+xml": gBundle.getString("feedRss"),
|
"application/atom+xml": "Atom",
|
||||||
// "application/atom+xml": gBundle.getString("feedAtom"),
|
"text/xml": "XML",
|
||||||
// "text/xml": gBundle.getString("feedXML"),
|
"application/xml": "XML",
|
||||||
// "application/xml": gBundle.getString("feedXML"),
|
"application/rdf+xml": "XML"
|
||||||
// "application/rdf+xml": gBundle.getString("feedXML")
|
};
|
||||||
// };
|
|
||||||
function isValidFeed(aData, aPrincipal, aIsFeed)
|
function isValidFeed(aData, aPrincipal, aIsFeed)
|
||||||
{
|
{
|
||||||
if (!aData || !aPrincipal)
|
if (!aData || !aPrincipal)
|
||||||
@@ -589,8 +589,10 @@ vimperator.Buffer = function () //{{{
|
|||||||
var pageSize = []; // [0] bytes; [1] kbytes
|
var pageSize = []; // [0] bytes; [1] kbytes
|
||||||
if (cacheEntryDescriptor)
|
if (cacheEntryDescriptor)
|
||||||
{
|
{
|
||||||
pageSize[0] = vimperator.util.formatNumber(cacheEntryDescriptor.dataSize);
|
pageSize[0] = vimperator.util.formatBytes(cacheEntryDescriptor.dataSize, 0, false);
|
||||||
pageSize[1] = vimperator.util.formatNumber(Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100);
|
pageSize[1] = vimperator.util.formatBytes(cacheEntryDescriptor.dataSize, 2, true);
|
||||||
|
if (pageSize[1] == pageSize[0])
|
||||||
|
pageSize[1] = null; // don't output "xx Bytes" twice
|
||||||
}
|
}
|
||||||
|
|
||||||
// put feeds rss into pageFeeds[]
|
// put feeds rss into pageFeeds[]
|
||||||
@@ -615,9 +617,8 @@ vimperator.Buffer = function () //{{{
|
|||||||
var feed = { title: link.title, href: link.href, type: link.type || "" };
|
var feed = { title: link.title, href: link.href, type: link.type || "" };
|
||||||
if (isValidFeed(feed, window.content.document.nodePrincipal, rels.feed))
|
if (isValidFeed(feed, window.content.document.nodePrincipal, rels.feed))
|
||||||
{
|
{
|
||||||
// var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; // TODO: dig into that.. --calmar
|
var type = feedTypes[feed.type] || feedTypes["application/rss+xml"];
|
||||||
var type = feed.type || "application/rss+xml";
|
pageFeeds.push([feed.title, vimperator.util.highlightURL(feed.href, true) + " (" + type + ")"]);
|
||||||
pageFeeds.push([feed.title, vimperator.util.highlightURL(feed.href, true)]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -635,8 +636,8 @@ vimperator.Buffer = function () //{{{
|
|||||||
var file = window.content.document.location.pathname.split("/").pop() || "[No Name]";
|
var file = window.content.document.location.pathname.split("/").pop() || "[No Name]";
|
||||||
var title = window.content.document.title || "[No Title]";
|
var title = window.content.document.title || "[No Title]";
|
||||||
|
|
||||||
if (pageSize[1])
|
if (pageSize[0])
|
||||||
info.push(pageSize[1] + "KiB");
|
info.push(pageSize[1] || pageSize[0]);
|
||||||
|
|
||||||
if (lastMod)
|
if (lastMod)
|
||||||
info.push(lastMod);
|
info.push(lastMod);
|
||||||
@@ -662,7 +663,12 @@ vimperator.Buffer = function () //{{{
|
|||||||
pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]);
|
pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]);
|
||||||
|
|
||||||
if (pageSize[0])
|
if (pageSize[0])
|
||||||
pageGeneral.push(["File Size", pageSize[1] + "KiB (" + pageSize[0] + " bytes)"]);
|
{
|
||||||
|
if (pageSize[1])
|
||||||
|
pageGeneral.push(["File Size", pageSize[1] + " (" + pageSize[0] + ")"]);
|
||||||
|
else
|
||||||
|
pageGeneral.push(["File Size", pageSize[0]]);
|
||||||
|
}
|
||||||
|
|
||||||
pageGeneral.push(["Mime-Type", content.document.contentType]);
|
pageGeneral.push(["Mime-Type", content.document.contentType]);
|
||||||
pageGeneral.push(["Encoding", content.document.characterSet]);
|
pageGeneral.push(["Encoding", content.document.characterSet]);
|
||||||
|
|||||||
@@ -168,24 +168,43 @@ vimperator.util = {
|
|||||||
|
|
||||||
highlightURL: function (str, force)
|
highlightURL: function (str, force)
|
||||||
{
|
{
|
||||||
if (force || /^[a-zA-Z]+:\/\/.*\//.test(str))
|
if (force || /^[a-zA-Z]+:\/\//.test(str))
|
||||||
return "<a class='hl-URL' href='" + str + "'>" + vimperator.util.escapeHTML(str) + "</a>";
|
return "<a class='hl-URL' href='" + str + "'>" + vimperator.util.escapeHTML(str) + "</a>";
|
||||||
else
|
else
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
formatNumber: function (num)
|
formatBytes: function (num, decimalPlaces, humanReadable)
|
||||||
{
|
{
|
||||||
var strNum = (num + "").split(".", 2);
|
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
||||||
|
var unitIndex = 0;
|
||||||
|
var tmpNum = parseInt(num) || 0;
|
||||||
|
var strNum = [tmpNum + ""];
|
||||||
|
|
||||||
for (var u = strNum[0].length - 3; u > 0; u -= 3)
|
if (humanReadable)
|
||||||
|
{
|
||||||
|
while (tmpNum >= 1024)
|
||||||
|
{
|
||||||
|
tmpNum /= 1024;
|
||||||
|
if (++unitIndex > (unitVal.length - 1))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let decPower = Math.pow(10, decimalPlaces);
|
||||||
|
strNum = ((Math.round(tmpNum * decPower) / decPower) + "").split(".", 2);
|
||||||
|
|
||||||
|
if (!strNum[1])
|
||||||
|
strNum[1] = "";
|
||||||
|
while (strNum[1].length < decimalPlaces) // padd with "0" to the desired decimalPlaces)
|
||||||
|
strNum[1] += "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var u = strNum[0].length - 3; u > 0; u -= 3) // make a 10000 a 10,000
|
||||||
strNum[0] = strNum[0].substring(0, u) + "," + strNum[0].substring(u, strNum[0].length);
|
strNum[0] = strNum[0].substring(0, u) + "," + strNum[0].substring(u, strNum[0].length);
|
||||||
|
|
||||||
if (strNum[1])
|
if (unitIndex) // decimalPlaces only when > Bytes
|
||||||
strNum[0] += "." + strNum[1];
|
strNum[0] += "." + strNum[1];
|
||||||
|
|
||||||
return strNum[0];
|
return strNum[0] + " " + unitVal[unitIndex];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// vim: set fdm=marker sw=4 ts=4 et:
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
|
|||||||
Reference in New Issue
Block a user