Javascript 在 Twitter 页面上关注所有用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5841118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Follow all users on a twitter page
提问by Matthieu
I'm on https://twitter.com/#!/username/followers; is there any greasemonkey script to follow all the twitter users on that page?
我在https://twitter.com/#!/username/followers 上;是否有任何油脂猴脚本来关注该页面上的所有 twitter 用户?
回答by Hari Karam Singh
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!
- 寻找关注按钮
- 您尚未关注或未完成的
display: block
检查(检查) - 设置一个计时器,每 500 毫秒单击一次“关注”按钮以防止垃圾邮件问题。
- 新的!全部完成后,滚动页面并等待几秒钟以等待下一次加载出现,然后重复整个过程!
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 :)
- 截至 2016 年 9 月 30 日,适用于 Chrome 最新版本和 Twitter。
- 您似乎需要“单击” A 标签内的 DIV,而不是 A 标签本身。
- 作业:也许可以尝试使用 jQuery 的 live() 函数来自动单击在初始页面加载后显示的任何新按钮:)
Disclaimer: This is not a hack...just a technique to save some wrist and finger RSI :) Regardless, use cautiously and respectfully.
免责声明:这不是黑客攻击……只是一种节省手腕和手指 RSI 的技术:) 无论如何,请谨慎和尊重地使用。
UPDATE: Improved for latest twitter. Now employs randomness in the timing to make you look less like a bot
更新:针对最新推特进行了改进。现在在时间上使用随机性让你看起来不像机器人
回答by 146
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:
Twitter 使用 JQuery,因此有一种方法可以做到这一点,假设您没有这样做以触发速率限制(与 API 用户相比,速率限制将更积极地应用于 Web 客户端用户)是做等效的的:
$('.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:
如果您愿意,您可以在 GreaseMonkey 中完成此操作,或将其设置为 JavaScript 书签,或将其复制粘贴到您的地址栏中并按 Enter 键:
javascript:$('.button.follow-button').click()
回答by Kwnstantinoulis
I modified the code that Hari Karam Singh posted earlier to work to the to-date Twitter.
我修改了 Hari Karam Singh 之前发布的代码以适用于最新的 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); });
回答by terapia de ozono
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.
它不再起作用,但是如果您使用对象而不是别名,我将执行 javascript: jQuery('.button.follow-button').click();
。您还可以使用 chrome 或 firebug 中的内置调试器添加一个按钮来为您执行此操作,并添加一个settimeout
以避免干扰 api 的限制。
<input type="button" onclick="javascript:jQuery('.button.follow-button').click();" value="follow!
">