问题
I am trying to search for a term in Twitter, and then "like" the tweets that come up, using JavaScript code in the console.
I tried making a class substitution into this working facebook code for auto-inviting users to like your page:
var inputs = document.querySelectorAll('a._42ft._4jy0._4jy3._517h');
for(var i=1; i<inputs.length;i++) {
inputs[i].click();
}
When I inspect the heart icon used by Twitter for liking a tweet, i see
<button class="ProfileTweet-actionButton js-actionButton js-actionFavorite" type="button">
so i tried
var inputs = document.querySelectorAll('button.ProfileTweet-actionButton.js-actionButton.js-actionFavorite');
for(var i=1; i<inputs.length;i++) {
inputs[i].click();
}
in the console.
It is giving an undefined error.
Any ideas for how to change this code to work as intended?
回答1:
The right code for the twitter feed hearts is:
javascript:var inputs = document.getElementsByClassName('HeartAnimation');
for(var i=0; i<inputs.length;i++)
{
inputs[i].click();
}
回答2:
javascript:
var x = document.querySelectorAll("div[aria-label=Like]");
for(var i=0; i<x.length;i++)
{
x[i].click();
}
来源:https://stackoverflow.com/questions/41487987/how-to-automatically-like-twitter-tweets-with-javascript-helper-console-code