// ==UserScript==
// @name       Twitter followers
// @include    https://twitter.com/*
// @version    0.1
// @author     sportclub2010
// @grant      none
// ==/UserScript==

if (document.location.href.indexOf('followers') != -1){
    document.body.onkeydown = function(e) {
        e = e || event;
        if (e.keyCode == 13) {
            var Grid = document.getElementsByClassName('Grid-cell u-size1of2 u-lg-size1of3 u-mb10');
            Grid = Array.from(Grid).filter(b => !b.querySelectorAll(".btn-group:not(.not-following)").length).filter(b => /\<b\>followback\<\/b\>/.test(b.innerHTML));
            //alert(Grid.length);

            var i=0;
            var btn = [];
            function Timer() {
                document.getElementsByTagName('title')[0].innerHTML = Grid.length + ' ' + i;
                btn = Grid[i].getElementsByClassName('user-actions-follow-button js-follow-btn follow-button');
                if(btn[0]) btn[0].click();
                i++;
                if(i<Grid.length) setTimeout(Timer, 5000);
            }
            Timer();
        }
    }
}