diff options
author | portix <portix@gmx.net> | 2014-02-28 11:33:34 +0100 |
---|---|---|
committer | portix <portix@gmx.net> | 2014-02-28 11:33:34 +0100 |
commit | 7344c775a2bd483f27e6bdb9549f13a1ceb177a7 (patch) | |
tree | 908b7051a779ba49bce63ee293be16d65f5481dd | |
parent | 833f2570645e8e3e5cb6942ac6f3df39d21e4567 (diff) | |
download | dwb-7344c775a2bd483f27e6bdb9549f13a1ceb177a7.zip |
Removing Array.fastIndexOf
-rw-r--r-- | extensions/requestpolicy | 34 | ||||
-rw-r--r-- | extensions/unique_tabs | 19 | ||||
-rw-r--r-- | scripts/lib/dwb.js.in | 57 |
3 files changed, 25 insertions, 85 deletions
diff --git a/extensions/requestpolicy b/extensions/requestpolicy index 4f164fab..eada339a 100644 --- a/extensions/requestpolicy +++ b/extensions/requestpolicy @@ -127,7 +127,7 @@ function listAdd(o, key, value, doWrite) { if (!o[key]) o[key] = []; - if (o[key].fastIndexOf(value) == -1) + if (o[key].indexOf(value) == -1) o[key].push(value); if (doWrite) io.write(config.whiteList, "w", JSON.stringify(persistentList)); @@ -135,7 +135,7 @@ function listAdd(o, key, value, doWrite) function listRemove(o, firstParty, domain, doWrite) { var idx; - if (o[firstParty] && (idx = o[firstParty].fastIndexOf(domain)) != -1) + if (o[firstParty] && (idx = o[firstParty].indexOf(domain)) != -1) { o[firstParty].splice(idx, 1); if (o[firstParty].length === 0) @@ -164,12 +164,12 @@ function showMenu() for (i=0, l=domains.length; i<l; ++i) { (function(dom) { - if (persistentList._alwaysBlock && persistentList._alwaysBlock.fastIndexOf(dom) != -1) + if (persistentList._alwaysBlock && persistentList._alwaysBlock.indexOf(dom) != -1) return; - whiteListed = persistentList[domain] && persistentList[domain].fastIndexOf(dom) != -1; - tmpWhiteListed = tmpList[domain] && tmpList[domain].fastIndexOf(dom) != -1; - if (!persistentList._always || persistentList._always.fastIndexOf(dom) == -1) + whiteListed = persistentList[domain] && persistentList[domain].indexOf(dom) != -1; + tmpWhiteListed = tmpList[domain] && tmpList[domain].indexOf(dom) != -1; + if (!persistentList._always || persistentList._always.indexOf(dom) == -1) { if (!whiteListed) { labels.push({ @@ -209,7 +209,7 @@ function showMenu() } } isWhiteListed = isWhiteListed || whiteListed || tmpWhiteListed; - if (!persistentList._always || persistentList._always.fastIndexOf(dom) == -1) + if (!persistentList._always || persistentList._always.indexOf(dom) == -1) { labels.push({ left : "[" + dom + "] allow on all sites", @@ -235,8 +235,8 @@ function showMenu() }); })(domains[i]); } - var allAllowed = (persistentList._all && persistentList._all.fastIndexOf(domain) != -1) || - (tmpList._all && tmpList._all.fastIndexOf(domain) != -1); + var allAllowed = (persistentList._all && persistentList._all.indexOf(domain) != -1) || + (tmpList._all && tmpList._all.indexOf(domain) != -1); if (isWhiteListed || allAllowed) { labels.unshift({ @@ -304,7 +304,7 @@ function unblockCurrent() var labels = [], i, l; for (i=0, l = domains.length; i<l; i++) { - if (persistentList._alwaysBlock.fastIndexOf(domains[i]) != -1) + if (persistentList._alwaysBlock.indexOf(domains[i]) != -1) labels.push({ left : domains[i] }); } if (labels.length > 0) @@ -372,25 +372,25 @@ var resourceCB = (function () return false; o = getPrivate(wv); - if (o.domains.fastIndexOf(domain) == -1) + if (o.domains.indexOf(domain) == -1) o.domains.push(domain); // Check for requests that are always blocked - if (persistentList._alwaysBlock && persistentList._alwaysBlock.fastIndexOf(domain) != -1) + if (persistentList._alwaysBlock && persistentList._alwaysBlock.indexOf(domain) != -1) return blockRequest(wv, request, o, domain); // Check if domain is always allowed - if ((persistentList._all && persistentList._all.fastIndexOf(firstParty) != -1) || - (tmpList._all && tmpList._all.fastIndexOf(firstParty) != -1)) + if ((persistentList._all && persistentList._all.indexOf(firstParty) != -1) || + (tmpList._all && tmpList._all.indexOf(firstParty) != -1)) return false; // Check request is always allowed - if (persistentList._always && persistentList._always.fastIndexOf(domain) != -1) + if (persistentList._always && persistentList._always.indexOf(domain) != -1) return false; // Check if request is whitelisted - if ( (!persistentList[firstParty] || persistentList[firstParty].fastIndexOf(domain) == -1) && - (!tmpList[firstParty] || tmpList[firstParty].fastIndexOf(domain) == -1)) + if ( (!persistentList[firstParty] || persistentList[firstParty].indexOf(domain) == -1) && + (!tmpList[firstParty] || tmpList[firstParty].indexOf(domain) == -1)) return blockRequest(wv, request, o, domain); }; })(); diff --git a/extensions/unique_tabs b/extensions/unique_tabs index d8a4ab78..71f5f8b1 100644 --- a/extensions/unique_tabs +++ b/extensions/unique_tabs @@ -49,24 +49,21 @@ var signal; var removeDuplicates = function() { var uris = []; - for (var i=tabs.length-1; i>=0; --i) - { - var uri = tabs.nth(i).uri; - if (uris.fastIndexOf(uri) == -1) + tabs.forEach(function(tab) { + var uri = tab.uri; + if (uris.indexOf(uri) == -1) uris.push(uri); else execute((i+1) + "close_tab"); - } + }); }; var onNavigation = function(wv, frame, request) { var uri = request.uri; - for (var i=tabs.length-1; i>=0; --i) - { - if (tabs.nth(i).uri == uri && i != wv.number) - { + tabs.forEach(function(tab, i) { + if (tab.uri == uri && i != wv.number) { /* defer execute, otherwise some other navigation callbacks will - * fail */ + * fail */ timer.start(10, function() { execute((i+1) + "focus_tab"); if (/^\s*$/.test(wv.uri)) @@ -75,7 +72,7 @@ var onNavigation = function(wv, frame, request) }); return true; } - } + }); return false; }; var toggleAutoFocus = function() diff --git a/scripts/lib/dwb.js.in b/scripts/lib/dwb.js.in index 053bcc4d..350b8294 100644 --- a/scripts/lib/dwb.js.in +++ b/scripts/lib/dwb.js.in @@ -990,63 +990,6 @@ } }); } - /** - * Standard javascript array with additional methods - * @name Array - * @class - * */ - /** - * Basically the same as Array.indexOf but without typechecking - * @name fastIndexOf - * @memberOf Array.prototype - * @function - * - * @param {Object} object Object to search for - * - * @returns {Number} - * The index of the object or -1 if the array doesn't contain the - * object - * */ - if (Array.prototype.fastIndexOf === undefined) - { - Object.defineProperty(Array.prototype, "fastIndexOf", - { - value : function (v) - { - for (var i=0, l=this.length; i<l; ++i) { - if (this[i] == v) - return i; - } - return -1; - } - }); - } - /** - * Basically the same as Array.lastIndexOf but without typechecking - * @name fastLastIndexOf - * @memberOf Array.prototype - * @function - * - * @param {Object} object Object to search for - * - * @returns {Number} - * The index of the object or -1 if the array doesn't contain the - * object - * */ - if (Array.prototype.fastLastIndexOf === undefined) - { - Object.defineProperty(Array.prototype, "fastLastIndexOf", - { - value : function (v) - { - for (var i=this.length-1; i>=0; --i) { - if (this[i] == v) - return i; - } - return -1; - } - }); - } /** * Standard RegExp object with additional methods |