Browse Source

Remove prototype pollution, call on ready

pull/40/head
8chan 10 years ago
committed by czaks
parent
commit
c3ba4cc7ef
  1. 74
      js/id_highlighter.js

74
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){ function getPostsById(id){
return $(".poster_id").filter(function(i){ return $(".poster_id").filter(function(i){
return $(this).text() == id; return $(this).text() == id;
}); });
} }
function getMasterPosts(parents){ function getMasterPosts(parents){
if(!parents.hasClass("post")) return; if(!parents.hasClass("post")) return;
var toRet = []; var toRet = [];
$(parents).each(function(){ $(parents).each(function(){
if($(this).hasClass("post")) if($(this).hasClass("post"))
toRet.push($(this)); toRet.push($(this));
}); });
return toRet; return toRet;
} }
$(".poster_id").click(function(){ $(".poster_id").click(function(){
var id = $(this).text(); var id = $(this).text();
if($.inArray(id, idshighlighted) !== -1){ if($.inArray(id, idshighlighted) !== -1){
idshighlighted.remove(id); arrayRemove(idshighlighted, id);
$(getMasterPosts(getPostsById(id).parents())).each(function(i){ $(getMasterPosts(getPostsById(id).parents())).each(function(i){
$(this).removeClass("highlighted"); $(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");
});
}
});

Loading…
Cancel
Save