]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/jslib.js
Better hilighting.
[irc/quakenet/qwebirc.git] / js / jslib.js
index 72ce15cfb317842b11c5f4de6634f0276d2e6a15..07a7e74644448c0e2ae2bd5d1a0732efea954cc3 100644 (file)
@@ -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