How to automatically “like” Twitter tweets with JavaScript helper console code

蹲街弑〆低调 提交于 2020-01-05 09:29:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!