PageRenderTime 34ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/config/chromium/Default/Extensions/ajpgkpeckebdhofmmjfgcjjiiejpodla/0.7.10/foxmarks-utils.js

https://github.com/PerfMonk/funtoo-quebec
JavaScript | 194 lines | 143 code | 18 blank | 33 comment | 65 complexity | d3f374cc2eed307dc9f673dcc5bfbbf2 MD5 | raw file
  1. /*
  2. forEach, version 1.0
  3. Copyright 2006, Dean Edwards
  4. License: http://www.opensource.org/licenses/mit-license.php
  5. */
  6. // array-like enumeration
  7. if (!Array.forEach) { // mozilla already supports this
  8. Array.forEach = function(array, block, context) {
  9. for (var i = 0; i < array.length; i++) {
  10. block.call(context, array[i], i, array);
  11. }
  12. };
  13. }
  14. // generic enumeration
  15. if (!Function.prototype.forEach) {
  16. Function.prototype.forEach = function(object, block, context) {
  17. for (var key in object) {
  18. if (typeof this.prototype[key] == "undefined") {
  19. block.call(context, object[key], key, object);
  20. }
  21. }
  22. };
  23. }
  24. // character enumeration
  25. if (!String.forEach) {
  26. String.forEach = function(string, block, context) {
  27. Array.forEach(string.split(""), function(chr, index) {
  28. block.call(context, chr, index, string);
  29. });
  30. };
  31. }
  32. // globally resolve forEach enumeration
  33. var forEach = function(object, block, context) {
  34. if (object) {
  35. var resolve = Object; // default
  36. if (object instanceof Function) {
  37. // functions have a "length" property
  38. resolve = Function;
  39. } else if (object.forEach instanceof Function) {
  40. // the object implements a custom forEach method so use that
  41. object.forEach(block, context);
  42. return;
  43. } else if (typeof object == "string") {
  44. // the object is a string
  45. resolve = String;
  46. } else if (typeof object.length == "number") {
  47. // the object is array-like
  48. resolve = Array;
  49. }
  50. resolve.forEach(object, block, context);
  51. }
  52. };
  53. /* function atob is:
  54. *
  55. * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
  56. * Released under the MIT license
  57. */
  58. function My_atob(str) {
  59. var chars =
  60. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  61. var invalid = {
  62. strlen: (str.length % 4 != 0),
  63. chars: new RegExp('[^' + chars + ']').test(str),
  64. equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
  65. };
  66. if (invalid.strlen || invalid.chars || invalid.equals)
  67. throw new Error('Invalid base64 data');
  68. var decoded = [];
  69. var c = 0;
  70. while (c < str.length) {
  71. var i0 = chars.indexOf(str.charAt(c++));
  72. var i1 = chars.indexOf(str.charAt(c++));
  73. var i2 = chars.indexOf(str.charAt(c++));
  74. var i3 = chars.indexOf(str.charAt(c++));
  75. var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
  76. var b0 = (buf & (255 << 16)) >> 16;
  77. var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
  78. var b2 = (i3 == 64) ? -1 : (buf & 255);
  79. decoded.push(b0);
  80. if (b1 >= 0) decoded.push(b1);
  81. if (b2 >= 0) decoded.push(b2);
  82. }
  83. return decoded;
  84. }
  85. function clone (deep) {
  86. var objectClone = new this.constructor();
  87. for (var property in this) {
  88. if (!this.hasOwnProperty(property))
  89. continue;
  90. if (deep && typeof this[property] == 'object' && this[property]) {
  91. objectClone[property] = this[property].clone(deep);
  92. } else {
  93. objectClone[property] = this[property];
  94. }
  95. }
  96. return objectClone;
  97. }
  98. Object.prototype.clone = clone;
  99. /*
  100. * From http://www.somacon.com/p355.php
  101. */
  102. if (!String.prototype.trim) {
  103. String.prototype.trim = function() {
  104. return this.replace(/^\s+|\s+$/g,"");
  105. }
  106. String.prototype.ltrim = function() {
  107. return this.replace(/^\s+/,"");
  108. }
  109. String.prototype.rtrim = function() {
  110. return this.replace(/\s+$/,"");
  111. }
  112. }
  113. /*
  114. Fron http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:indexOf
  115. indexOf is a JavaScript extension to the ECMA-262 standard; as such it may
  116. not be present in other implementations of the standard. You can work around
  117. this by inserting the following code at the beginning of your scripts,
  118. allowing use of indexOf in ECMA-262 implementations which do not natively
  119. support it. This algorithm is exactly the one used in Firefox and
  120. SpiderMonkey.
  121. */
  122. if (!Array.prototype.indexOf) {
  123. Array.prototype.indexOf = function(elt /*, from*/) {
  124. var len = this.length;
  125. var from = Number(arguments[1]) || 0;
  126. from = (from < 0)
  127. ? Math.ceil(from)
  128. : Math.floor(from);
  129. if (from < 0)
  130. from += len;
  131. for (; from < len; from++) {
  132. if (from in this && this[from] === elt)
  133. return from;
  134. }
  135. return -1;
  136. };
  137. }
  138. if (!Array.prototype.filter) {
  139. Array.prototype.filter = function(fun /*, thisp*/) {
  140. var len = this.length;
  141. if (typeof fun != "function")
  142. throw new TypeError();
  143. var res = new Array();
  144. var thisp = arguments[1];
  145. for (var i = 0; i < len; i++) {
  146. if (i in this) {
  147. var val = this[i]; // in case fun mutates this
  148. if (fun.call(thisp, val, i, this))
  149. res.push(val);
  150. }
  151. }
  152. return res;
  153. };
  154. }
  155. function equals(a, b) {
  156. if (typeof a != typeof b)
  157. return false;
  158. if (typeof a != 'object')
  159. return a == b;
  160. if (a == b)
  161. return true;
  162. if (a.constructor == Array && b.constructor == Array) {
  163. if (a.length != b.length)
  164. return false;
  165. for (var i = 0; i < a.length; ++i) {
  166. if (a[i] != b[i])
  167. return false;
  168. }
  169. return true;
  170. } else {
  171. throw Error("can't compare non-Array objects");
  172. }
  173. }