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

Language Javascript Lines 195
MD5 Hash d3f374cc2eed307dc9f673dcc5bfbbf2
Repository https://github.com/PerfMonk/funtoo-quebec.git View Raw File
| Open JSFiddle
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 forEach, version 1.0
 Copyright 2006, Dean Edwards
 License: http://www.opensource.org/licenses/mit-license.php
 */

// array-like enumeration
if (!Array.forEach) { // mozilla already supports this
    Array.forEach = function(array, block, context) {
        for (var i = 0; i < array.length; i++) {
            block.call(context, array[i], i, array);
        }
    };
}

// generic enumeration
if (!Function.prototype.forEach) {
    Function.prototype.forEach = function(object, block, context) {
        for (var key in object) {
            if (typeof this.prototype[key] == "undefined") {
                block.call(context, object[key], key, object);
            }
        }
    };
}

// character enumeration
if (!String.forEach) {
    String.forEach = function(string, block, context) {
        Array.forEach(string.split(""), function(chr, index) {
                block.call(context, chr, index, string);
            });
    };
}

// globally resolve forEach enumeration
var forEach = function(object, block, context) {
    if (object) {
        var resolve = Object; // default
        if (object instanceof Function) {
            // functions have a "length" property
            resolve = Function;
        } else if (object.forEach instanceof Function) {
            // the object implements a custom forEach method so use that
            object.forEach(block, context);
            return;
        } else if (typeof object == "string") {
            // the object is a string
            resolve = String;
        } else if (typeof object.length == "number") {
            // the object is array-like
            resolve = Array;
        }
        resolve.forEach(object, block, context);
    }
};


/* function atob is:
 *
 * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
 * Released under the MIT license
 */


function My_atob(str) {
    var chars = 
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
    var invalid = {
        strlen: (str.length % 4 != 0),
        chars:  new RegExp('[^' + chars + ']').test(str),
        equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
    };
    if (invalid.strlen || invalid.chars || invalid.equals)
        throw new Error('Invalid base64 data');
    var decoded = [];
    var c = 0;
    while (c < str.length) {
        var i0 = chars.indexOf(str.charAt(c++));
        var i1 = chars.indexOf(str.charAt(c++));
        var i2 = chars.indexOf(str.charAt(c++));
        var i3 = chars.indexOf(str.charAt(c++));
        var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
        var b0 = (buf & (255 << 16)) >> 16;
        var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
        var b2 = (i3 == 64) ? -1 : (buf & 255);
        decoded.push(b0);
        if (b1 >= 0) decoded.push(b1);
        if (b2 >= 0) decoded.push(b2);
    }
    return decoded;
}

function clone (deep) {
    var objectClone = new this.constructor();
    for (var property in this) {
        if (!this.hasOwnProperty(property))
            continue;
        if (deep && typeof this[property] == 'object' && this[property]) {
            objectClone[property] = this[property].clone(deep);
        } else {
            objectClone[property] = this[property];
        }
    }
    return objectClone;
}
Object.prototype.clone = clone;

/*
 * From http://www.somacon.com/p355.php
 */
if (!String.prototype.trim) {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
    }
    String.prototype.ltrim = function() {
        return this.replace(/^\s+/,"");
    }
    String.prototype.rtrim = function() {
        return this.replace(/\s+$/,"");
    }
}

/*
 
 Fron http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:indexOf

 indexOf is a JavaScript extension to the ECMA-262 standard; as such it may
 not be present in other implementations of the standard. You can work around 
 this by inserting the following code at the beginning of your scripts, 
 allowing use of indexOf in ECMA-262 implementations which do not natively 
 support it. This algorithm is exactly the one used in Firefox and 
 SpiderMonkey.

*/

if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++) {
      if (from in this && this[from] === elt)
        return from;
    }
    return -1;
  };
}

if (!Array.prototype.filter) {
  Array.prototype.filter = function(fun /*, thisp*/) {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
      if (i in this) {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

function equals(a, b) {
    if (typeof a != typeof b)
        return false;
    if (typeof a != 'object')
        return a == b;
    if (a == b)
        return true;
    if (a.constructor == Array && b.constructor == Array) {
        if (a.length != b.length)
            return false;
        for (var i = 0; i < a.length; ++i) {
            if (a[i] != b[i])
                return false;
        }
        return true;
    } else {
        throw Error("can't compare non-Array objects");
    }
}
Back to Top