1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 22:34:12 +01:00

Add an experimental prototype download manager replacement. Fix some bugs.

--HG--
extra : rebase_source : aea703414d4bd601bfdea779c5878a30d5b3d782
This commit is contained in:
Kris Maglione
2011-01-16 22:38:44 -05:00
parent b52e78b92e
commit ed696fe5c4
16 changed files with 444 additions and 77 deletions

View File

@@ -135,6 +135,13 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
throw FailedAssertion(message, 1);
},
/**
* Capitalizes the first character of the given string.
* @param {string} str The string to capitalize
* @returns {string}
*/
capitalize: function capitalize(str) str && str[0].toUpperCase() + str.slice(1),
/**
* Returns a RegExp object that matches characters specified in the range
* expression *list*, or signals an appropriate error if *list* is invalid.
@@ -499,9 +506,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
stackLines: function (stack) {
let lines = [];
let match, re = /([^]*?)(@[^@\n]*)(?:\n|$)/g;
let match, re = /([^]*?)@([^@\n]*)(?:\n|$)/g;
while (match = re.exec(stack))
lines.push(match[1].replace(/\n/g, "\\n").substr(0, 80) + match[2]);
lines.push(match[1].replace(/\n/g, "\\n").substr(0, 80) + "@" +
match[2].replace(/.* -> /, ""));
return lines;
},
@@ -653,6 +661,28 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
return strNum[0] + " " + unitVal[unitIndex];
},
/**
* Converts *seconds* into a human readable time string.
*
* @param {number} seconds
* @returns {string}
*/
formatSeconds: function formatSeconds(seconds) {
function div(num, denom) [Math.round(num / denom), Math.round(num % denom)];
let days, hours, minutes;
[minutes, seconds] = div(seconds, 60);
[hours, minutes] = div(minutes, 60);
[days, hours] = div(hours, 24);
if (days)
return days + " days " + hours + " hours"
if (hours)
return hours + "h " + minutes + "m";
if (minutes)
return minutes + ":" + seconds;
return seconds + "s";
},
/**
* Returns the file which backs a given URL, if available.
*