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