X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/1d6756bcad0a8b762d43c1262e869d7704dfe279..96f280628763facfcff052bcef1cbb8b153953de:/js/jslib.js diff --git a/js/jslib.js b/js/jslib.js index 72ce15c..07a7e74 100644 --- a/js/jslib.js +++ b/js/jslib.js @@ -7,6 +7,14 @@ Array.prototype.indexFromEnd = function(d) { return p[d]; } +qwebirc.util.dictCopy = function(d) { + var n = {}; + for(var k in d) + n[k] = d[k]; + + return n; +} + /* how horribly inefficient */ String.prototype.replaceAll = function(f, t) { var i = this.indexOf(f); @@ -107,9 +115,28 @@ qwebirc.util.NBSPCreate = function(text, element) { qwebirc.util.longtoduration = function(l) { var seconds = l % 60; - var minutes = l / 60; - var hours = minutes / 60; - var days = hours / 24; + var minutes = Math.round((l % 3600) / 60); + var hours = Math.round((l % (3600 * 24)) / 3600); + var days = Math.round(l / (24*3600)); return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds"; } + +qwebirc.util.pad = function(x) { + x = "" + x; + if(x.length == 1) + return "0" + x; + return x +} + +RegExp.escape = function(text) { + if(!arguments.callee.sRE) { + var specials = [ + '/', '.', '*', '+', '?', '|', + '(', ')', '[', ']', '{', '}', '\\' + ]; + arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); + } + + return text.replace(arguments.callee.sRE, '\\$1'); +} \ No newline at end of file