问题
Similar to this Follow all users on a twitter page, I am trying to change this to click all the "like" hearts on a Tumblr page instead of the follow button:
javascript:$('.button.follow-button').click()
Thanks
回答1:
javascript:var a = document.getElementsByTagName('a'); var b = []; for(var i=0, len = a.length; i < len; i++){ if(a[i].id.indexOf('like_button') !== -1){b.push(a[i]) } }; for(var i=0, len = b.length; i < len; i++){ b[i].onclick() };
There. What it does is gets all the a tags on the page. Then filters them and finds all the like buttons. Then it just clicks on them.
Note that this solution is pretty inefficient and you should probably be using document.getElementsByClassName
as Samuel did, but that may not be supported in all browsers (I'm looking at you, IE 8).
回答2:
Here's your bookmarklet:
javascript:e=document.getElementsByClassName('like_button');for(i=0;i<e.length;i++){e[i].click();}void(0);
Edit: the above only works in Firefox. Try this instead:
javascript:e=document.getElementsByTagName('a');for(i=0;i<e.length;i++){if(e[i].id.indexOf('like_button')>=0)e[i].click();}void(0);
来源:https://stackoverflow.com/questions/8175822/bookmarklet-click-all-like-buttons-on-tumblr