2014-11-08 16:13:00 +01:00
|
|
|
/*
|
|
|
|
* JS counterpart of the function in src/misc.cpp
|
|
|
|
*/
|
|
|
|
function friendlyUnit(value, isSpeed) {
|
2014-11-30 14:14:09 +01:00
|
|
|
units = [
|
2017-05-01 01:45:02 +03:00
|
|
|
"QBT_TR(B)QBT_TR[CONTEXT=misc]",
|
|
|
|
"QBT_TR(KiB)QBT_TR[CONTEXT=misc]",
|
|
|
|
"QBT_TR(MiB)QBT_TR[CONTEXT=misc]",
|
|
|
|
"QBT_TR(GiB)QBT_TR[CONTEXT=misc]",
|
|
|
|
"QBT_TR(TiB)QBT_TR[CONTEXT=misc]",
|
2017-05-05 03:27:49 +03:00
|
|
|
"QBT_TR(PiB)QBT_TR[CONTEXT=misc]",
|
|
|
|
"QBT_TR(EiB)QBT_TR[CONTEXT=misc]"
|
2014-11-30 14:14:09 +01:00
|
|
|
];
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
if (value < 0)
|
2017-05-01 01:45:02 +03:00
|
|
|
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";
|
2015-07-26 14:30:35 +02:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
var i = 0;
|
2017-05-05 03:27:49 +03:00
|
|
|
while (value >= 1024. && i < 6) {
|
2014-11-30 14:14:09 +01:00
|
|
|
value /= 1024.;
|
2015-07-26 14:30:35 +02:00
|
|
|
++i;
|
|
|
|
}
|
2017-05-05 20:09:04 +03:00
|
|
|
|
|
|
|
function friendlyUnitPrecision(sizeUnit) {
|
|
|
|
if (sizeUnit <= 2) return 1; // KiB, MiB
|
|
|
|
else if (sizeUnit === 3) return 2; // GiB
|
|
|
|
else return 3; // TiB, PiB, EiB
|
|
|
|
}
|
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
var ret;
|
2015-07-26 14:30:35 +02:00
|
|
|
if (i == 0)
|
|
|
|
ret = value + " " + units[i];
|
|
|
|
else
|
2017-05-05 20:09:04 +03:00
|
|
|
ret = (Math.floor(10 * value) / 10).toFixed(friendlyUnitPrecision(i)) //Don't round up
|
2014-12-24 04:39:18 +03:00
|
|
|
+ " " + units[i];
|
2015-07-26 14:30:35 +02:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
if (isSpeed)
|
2017-05-01 01:45:02 +03:00
|
|
|
ret += "QBT_TR(/s)QBT_TR[CONTEXT=misc]";
|
2014-11-30 14:14:09 +01:00
|
|
|
return ret;
|
2014-11-08 16:13:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JS counterpart of the function in src/misc.cpp
|
|
|
|
*/
|
|
|
|
function friendlyDuration(seconds) {
|
2014-11-30 14:14:09 +01:00
|
|
|
var MAX_ETA = 8640000;
|
|
|
|
if (seconds < 0 || seconds >= MAX_ETA)
|
|
|
|
return "∞";
|
|
|
|
if (seconds == 0)
|
|
|
|
return "0";
|
|
|
|
if (seconds < 60)
|
2017-05-01 01:45:02 +03:00
|
|
|
return "QBT_TR(< 1m)QBT_TR[CONTEXT=misc]";
|
2014-11-30 14:14:09 +01:00
|
|
|
var minutes = seconds / 60;
|
|
|
|
if (minutes < 60)
|
2017-05-01 01:45:02 +03:00
|
|
|
return "QBT_TR(%1m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(minutes));
|
2014-11-30 14:14:09 +01:00
|
|
|
var hours = minutes / 60;
|
2015-01-29 17:13:48 +03:00
|
|
|
minutes = minutes % 60;
|
2014-11-30 14:14:09 +01:00
|
|
|
if (hours < 24)
|
2017-05-01 01:45:02 +03:00
|
|
|
return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
|
2014-11-30 14:14:09 +01:00
|
|
|
var days = hours / 24;
|
2015-01-29 17:13:48 +03:00
|
|
|
hours = hours % 24;
|
2014-11-30 14:14:09 +01:00
|
|
|
if (days < 100)
|
2017-05-01 01:45:02 +03:00
|
|
|
return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
|
2014-11-08 16:13:00 +01:00
|
|
|
return "∞";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
|
|
|
*/
|
|
|
|
if (!Date.prototype.toISOString) {
|
2014-11-30 14:14:09 +01:00
|
|
|
(function() {
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
function pad(number) {
|
|
|
|
if (number < 10) {
|
|
|
|
return '0' + number;
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
}
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
Date.prototype.toISOString = function() {
|
|
|
|
return this.getUTCFullYear() +
|
|
|
|
'-' + pad(this.getUTCMonth() + 1) +
|
|
|
|
'-' + pad(this.getUTCDate()) +
|
|
|
|
'T' + pad(this.getUTCHours()) +
|
|
|
|
':' + pad(this.getUTCMinutes()) +
|
|
|
|
':' + pad(this.getUTCSeconds()) +
|
|
|
|
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
|
|
|
|
'Z';
|
|
|
|
};
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
}());
|
2014-12-17 15:12:11 +03:00
|
|
|
}
|
2014-12-24 04:39:18 +03:00
|
|
|
|
2015-07-08 15:27:33 +02:00
|
|
|
/*
|
|
|
|
* JS counterpart of the function in src/misc.cpp
|
|
|
|
*/
|
|
|
|
function parseHtmlLinks(text) {
|
|
|
|
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
|
|
|
return text.replace(exp,"<a target='_blank' href='$1'>$1</a>");
|
|
|
|
}
|
|
|
|
|
2014-12-24 04:39:18 +03:00
|
|
|
function escapeHtml(str) {
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.appendChild(document.createTextNode(str));
|
|
|
|
return div.innerHTML;
|
2015-07-08 15:27:33 +02:00
|
|
|
};
|