Fix javascript errors and follow best practices

This commit is contained in:
Thomas Piccirello
2017-07-01 00:42:20 -04:00
parent 1a506ac582
commit a7f4ea8b18
11 changed files with 145 additions and 145 deletions

View File

@@ -16,8 +16,8 @@ function friendlyUnit(value, isSpeed) {
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";
var i = 0;
while (value >= 1024. && i < 6) {
value /= 1024.;
while (value >= 1024.0 && i < 6) {
value /= 1024.0;
++i;
}
@@ -28,7 +28,7 @@ function friendlyUnit(value, isSpeed) {
}
var ret;
if (i == 0)
if (i === 0)
ret = value + " " + units[i];
else
ret = (Math.floor(10 * value) / 10).toFixed(friendlyUnitPrecision(i)) //Don't round up
@@ -46,7 +46,7 @@ function friendlyDuration(seconds) {
var MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA)
return "∞";
if (seconds == 0)
if (seconds === 0)
return "0";
if (seconds < 60)
return "QBT_TR(< 1m)QBT_TR[CONTEXT=misc]";
@@ -56,11 +56,11 @@ function friendlyDuration(seconds) {
var hours = minutes / 60;
minutes = minutes % 60;
if (hours < 24)
return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes));
var days = hours / 24;
hours = hours % 24;
if (days < 100)
return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours));
return "∞";
}
@@ -96,11 +96,11 @@ if (!Date.prototype.toISOString) {
*/
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>");
return text.replace(exp,"<a target='_blank' href='$1'>$1</a>");
}
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
}