summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
author8chan <admin@8chan.co>2014-09-27 20:04:27 +0000
committerczaks <marcin@6irc.net>2014-10-05 17:48:07 +0200
commitc3ba4cc7efc3ec345634fa1a8f409008e2c535e8 (patch)
treea673a1bd07452ac82df353679381c751ff17bf45 /js
parentcbe12019c4f892b1128b28c411ea6f5f98cb238d (diff)
Remove prototype pollution, call on ready
Diffstat (limited to 'js')
-rw-r--r--js/id_highlighter.js74
1 files changed, 39 insertions, 35 deletions
diff --git a/js/id_highlighter.js b/js/id_highlighter.js
index 60052031..82e2c79d 100644
--- a/js/id_highlighter.js
+++ b/js/id_highlighter.js
@@ -1,40 +1,44 @@
-Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); }
+if (active_page == 'thread' || active_page == 'index') {
+ $(document).ready(function(){
+ function arrayRemove(a, v) { a.splice(a.indexOf(v) == -1 ? a.length : a.indexOf(v), 1); }
-var idshighlighted = [];
+ var idshighlighted = [];
-function getPostsById(id){
- return $(".poster_id").filter(function(i){
- return $(this).text() == id;
- });
-}
+ function getPostsById(id){
+ return $(".poster_id").filter(function(i){
+ return $(this).text() == id;
+ });
+ }
-function getMasterPosts(parents){
- if(!parents.hasClass("post")) return;
-
- var toRet = [];
-
- $(parents).each(function(){
- if($(this).hasClass("post"))
- toRet.push($(this));
- });
-
- return toRet;
-}
+ function getMasterPosts(parents){
+ if(!parents.hasClass("post")) return;
+
+ var toRet = [];
+
+ $(parents).each(function(){
+ if($(this).hasClass("post"))
+ toRet.push($(this));
+ });
+
+ return toRet;
+ }
-$(".poster_id").click(function(){
- var id = $(this).text();
-
- if($.inArray(id, idshighlighted) !== -1){
- idshighlighted.remove(id);
-
- $(getMasterPosts(getPostsById(id).parents())).each(function(i){
- $(this).removeClass("highlighted");
+ $(".poster_id").click(function(){
+ var id = $(this).text();
+
+ if($.inArray(id, idshighlighted) !== -1){
+ arrayRemove(idshighlighted, id);
+
+ $(getMasterPosts(getPostsById(id).parents())).each(function(i){
+ $(this).removeClass("highlighted");
+ });
+ }else{
+ idshighlighted.push(id);
+
+ $(getMasterPosts(getPostsById(id).parents())).each(function(i){
+ $(this).addClass("highlighted");
+ });
+ }
});
- }else{
- idshighlighted.push(id);
-
- $(getMasterPosts(getPostsById(id).parents())).each(function(i){
- $(this).addClass("highlighted");
- });
- }
-});
+ });
+}