var name; var thumbPrefix; var getName = function(comment){ } // Returns all comment div elements var getDivs = function(){ console.debug("[THUMBER] _GETTING DIVS_"); return $("div[id*='cc']"); } // Takes an array with comment div elements // Returns ids for thumbs to be clicked var getThumbs = function(d){ console.debug("[THUMBER] _GETTING THUMBS_ args: " + d + " with length: " + d.length); var t = []; for(var i = 0; i < d.length; i++){ var aChildren = d[i].getElementsByTagName("a"); var divID = d[i].id; divID = divID.replace("cc", ""); for(var j = 0; j < aChildren.length; j++){ if(aChildren[j].text == name){ t.push(divID); console.debug("[THUMBER] _GOT THUMB FROM " + d + " at index " + i); break; } } } console.debug("[THUMBER] _RETURNING THUMBS_"); return t; } // Takes an array with ids var clickThumbs = function(t){ console.debug("[THUMBER] _CLICKING " + t.length + " THUMBS_"); for(var i = 0; i < t.length; i++){ if(thumbPrefix == "dn"){ comments.thumbsVote('down', t[i]); }else if(thumbPrefix == "up"){ comments.thumbsVote('up', t[i]); } } console.debug("[THUMBER] _CLICKED THUMBS_"); } // Username of user to be thumbed // Thumb up or down? // Valid args: "up", "dn" var thumbUser = function(username, thumb){ name = username; thumbPrefix = thumb; var divs = getDivs(); var thumbs = getThumbs(divs); clickThumbs(thumbs); }