Created
September 16, 2017 10:11
-
-
Save danikaze/c41109407af512f2434fcb9b69a1fc8e to your computer and use it in GitHub Desktop.
Follows everyone's followers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To be executed in the followers page of somebody. | |
* | |
*/ | |
(function() { | |
// time between clicks | |
var TW_CLICK_DELAY = 1000; | |
// time between scrolls | |
var TW_SCROLL_DELAY = 100; | |
// how many people follow in this batch | |
var TW_FOLLOW = 100; | |
// display console msgs? | |
var TW_VERBOSE = true; | |
/* | |
* Internal | |
*/ | |
var tw_timeoutHandler; | |
var tw_followed; | |
var tw_stop; | |
/* | |
* Start follow batch | |
*/ | |
function start(first) { | |
if(first) { | |
tw_followed = 0; | |
tw_stop = false; | |
} else if(tw_stop) { | |
return; | |
} | |
var button = $('.not-following .user-actions-follow-button').first(); | |
if(button.length != 0) { | |
button.click(); | |
tw_followed++; | |
if(TW_VERBOSE) { | |
var user = '@' + button.parent().data('screen-name'); | |
console.log('Following ' + user + '(' + tw_followed + '/' + TW_FOLLOW + ')'); | |
} | |
} else { | |
var currentScroll = window.scrollY; | |
window.scroll(0, $(document).height()); | |
if(window.scrollY === currentScroll) { | |
console.log('Finished'); | |
} else { | |
timeoutHandler = setTimeout(function() { start(false) }, TW_SCROLL_DELAY); | |
return; | |
} | |
} | |
if(tw_followed < TW_FOLLOW) { | |
timeoutHandler = setTimeout(function() { start(false) }, TW_CLICK_DELAY); | |
} else { | |
console.log('Completed!'); | |
} | |
} | |
/* | |
* Stop following manually | |
*/ | |
function stop() { | |
tw_stop = true; | |
} | |
/* | |
* Export | |
*/ | |
window.tw_start = function() { start(true); }; | |
window.tw_stop = function() { stop(); }; | |
} ()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shows undefined in chrome console:(.