From b060a9c23ec8ae62e8a37509e0d7c1d743149036 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 24 Dec 2013 15:33:39 -0700 Subject: [PATCH] Cheats. Don't do this. Why am I doing it, then? Because indexOf is so slooooooooooooooooooooooooooooooooooooooooooooooooooooooooooow --- Gruntfile.coffee | 1 + builds/4chan-X.user.js | 26 ++++++++++++++------------ builds/crx/script.js | 26 ++++++++++++++------------ src/General/cheats.coffee | 10 ++++++++++ src/General/lib/$.coffee | 6 ------ 5 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/General/cheats.coffee diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 3d8f890a1..a46383ac1 100755 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -16,6 +16,7 @@ module.exports = (grunt) -> ) coffee: src: [ + 'src/General/Cheats.coffee' 'src/General/Config.coffee' 'src/General/Globals.coffee' 'src/General/lib/*.coffee' diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 53b4e99e8..1bbd76b04 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -352,18 +352,6 @@ posts: {} }; - Array.prototype.indexOf = function(val) { - var i; - - i = this.length; - while (i--) { - if (this[i] === val) { - return i; - } - } - return i; - }; - $ = function(selector, root) { if (root == null) { root = d.body; @@ -833,6 +821,20 @@ return __slice.call(root.querySelectorAll(selector)); }; + Array.prototype.indexOf = function(val) { + var i; + + i = this.length; + while (i--) { + if (this[i] === val) { + return i; + } + } + return i; + }; + + __indexOf = [].indexOf; + Board = (function() { Board.prototype.toString = function() { return this.ID; diff --git a/builds/crx/script.js b/builds/crx/script.js index f2f40781f..c08faf62a 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -330,18 +330,6 @@ posts: {} }; - Array.prototype.indexOf = function(val) { - var i; - - i = this.length; - while (i--) { - if (this[i] === val) { - return i; - } - } - return i; - }; - $ = function(selector, root) { if (root == null) { root = d.body; @@ -840,6 +828,20 @@ return __slice.call(root.querySelectorAll(selector)); }; + Array.prototype.indexOf = function(val) { + var i; + + i = this.length; + while (i--) { + if (this[i] === val) { + return i; + } + } + return i; + }; + + __indexOf = [].indexOf; + Board = (function() { Board.prototype.toString = function() { return this.ID; diff --git a/src/General/cheats.coffee b/src/General/cheats.coffee new file mode 100644 index 000000000..6b2926359 --- /dev/null +++ b/src/General/cheats.coffee @@ -0,0 +1,10 @@ +# I am bad at JavaScript and if you reuse this, so are you. +Array::indexOf = (val) -> + i = @length + while i-- + return i if @[i] is val + return i + +# Update CoffeeScript's reference to [].indexOf +# Reserved keywords are ignored in embedded javascript. +`__indexOf = [].indexOf` diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index 77f57d307..cf6951cbc 100755 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -1,9 +1,3 @@ -Array::indexOf = (val) -> - i = @length - while i-- - return i if @[i] is val - return i - # loosely follows the jquery api: # http://api.jquery.com/ # not chainable