Follow all users on a twitter page [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this questionI'm on https://twitter.com/#!/username/followers ; is 开发者_StackOverflowthere any greasemonkey script to follow all the twitter users on that page?
Here's a new one which also employs a delay to prevent spam issues.
var FOLLOW_PAUSE = 1250;
var FOLLOW_RAND = 250;
var PAGE_WAIT = 2000;
__cnt__ = 0;
var f;
f = function() {
var eles;
var __lcnt__ = 0;
eles = jQuery('.Grid-cell .not-following .follow-text').each(function(i, ele) {
ele = jQuery(ele);
if (ele.css('display') != 'block') {
console.trace('Already following: ' + i);
return;
}
setTimeout(function() {
console.trace("Following " + i + " of " + eles.length);
ele.click();
if ((eles.length - 1) == i) {
console.trace("Scrolling...");
window.scrollTo(0, document.body.scrollHeight);
setTimeout(function() {
f();
}, PAGE_WAIT);
}
}, __lcnt__++ * FOLLOW_PAUSE + Math.random()*(FOLLOW_RAND) - FOLLOW_RAND/2);
__cnt__++;
});
}
f();
What it does:
- Looks for follow buttons
- Checks that you aren't already following or pending (
display: block
check) - Sets a timer to click the FOLLOW buttons every 500ms to prevent spam issues.
- NEW! When it's done them all, scrolls the page and waits a couple seconds for the next loads to appear, then repeats the whole process!
Notes for hackers:
- Works on Chrome latest version and Twitter as of the 30th of Sep 2016.
- You seem to need to "click" the DIV inside the A tag, not the A tag itself.
- HOMEWORK: Maybe try jQuery's live() function to auto-click any new buttons which show up after the initial page load :)
Disclaimer: This is not a hack...just a technique to save some wrist and finger RSI :) Regardless, use cautiously and respectfully.
UPDATE: Improved for latest twitter. Now employs randomness in the timing to make you look less like a bot
Twitter uses JQuery, so a way to do this, assuming that you aren't doing this so much as to trigger the rate limits (the rate limits will apply more aggressively to web client users as compared to API users) is to do the equivalent of:
$('.button.follow-button').click()
You can accomplish this in GreaseMonkey if you'd like, or setting it as a JavaScript bookmarklet, or by copy-pasting this into your address bar and hitting enter:
javascript:$('.button.follow-button').click()
I modified the code that Hari Karam Singh posted earlier to work to the to-date Twitter.
__cnt__=0; jQuery('.stream button.follow-button > span.follow-text').each(function (i, ele) { ele = jQuery(ele); if (ele.css('display')!='block') {console.log('already following:', i); return;} setTimeout(function () {ele.click();}, __cnt__++*500); });
It doesn´t work anymore, but if you use the object instead of the alias i´ll do javascript:jQuery('.button.follow-button').click();
.
You can also use the in-built debugger in chrome or firebug to add a button that cam do this for you, and add a settimeout
to avoid interference with the api's restrictions.
<input type="button" onclick="javascript:jQuery('.button.follow-button').click();" value="follow!
">
精彩评论