Twitter Auto Follow

adds a button to twitter for automatic following of every user displayed

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name     Twitter Auto Follow
// @version  2
// @locale en
// @description adds a button to twitter for automatic following of every user displayed
// @include https://twitter.com/*/following
// @author      Wepwawet
// @run-at document-start
// @grant    none
// @namespace https://greasyfork.org/users/227248
// ==/UserScript==
(function() {
    'use strict'

    window.addEventListener('load', () => {
        addButton('Autofollow', selectReadFn, 'button.autofollow')
    })

    var timer_id = 0;
    var secondary_timer_id = 0;
    var followercount = -1;

    function secondaryTimer() {
        var curlen = jQuery('.Grid-cell').length;

        if (curlen == followercount) {

            window.clearInterval(timer_id);
            window.clearInterval(secondary_timer_id);
            document.getElementById('button.autofollow').innerHTML = 'Preparing to follow... ' + curlen;
            Secondary();
            return;
        }

        followercount = curlen;
    }

    function myTimer() {
        window.scrollTo(0, document.body.scrollHeight);
    }

    var buttons = 0;

    function addButton(text, onclick, buttonName, cssObj) {
        buttons++;
        cssObj = cssObj || {
            display: 'flex',
            'flex-direction': 'column',
            'justify-content': 'space-around',
            'align-items': 'flex-start',
            position: 'fixed',
            bottom: 1 + (buttons * 5) + '%',
            left: '1%',
            'z-index': 3,
            background: '#000000',
            background: '-webkit-linear-gradient(#000000, #000000)',
            background: 'linear-gradient(#000000, #000000)',
            border: '1px solid #556699',
            'border-radius': '5px',
            padding: '8px 20px',
            color: '#ffffff',
            font: 'normal 700 24px/1 "Ubuntu", sans-serif',
            'text-align': 'center',
            'text-shadow': 'none',
        }
        let button = document.createElement('button'),
            btnStyle = button.style
        document.body.appendChild(button)
        button.id = buttonName;
        button.innerHTML = text
        button.onclick = onclick
        Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key])
        return button
    }

    var running = false;
    var running2 = false;

    function selectReadFn() {
        if (running) return;
        running = true;
        timer_id = setInterval(myTimer, 50);
        secondary_timer_id = setInterval(secondaryTimer, 1000);
    }

    function Secondary() {
        if (running2) return;
        running2 = true;
        var FOLLOW_PAUSE = 1250;
        var FOLLOW_RAND = 5050;
        var PAGE_WAIT = 2000;
        var __cnt__ = 0;

        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') {
                return;
            }
            setTimeout(function() {
                ele.click();
                if ((eles.length - 1) == i) {
                    return;
                }
            }, __lcnt__++ * FOLLOW_PAUSE + Math.random() * (FOLLOW_RAND) - FOLLOW_RAND / 2);
            __cnt__++;

        });
        //[...document.getElementsByClassName('MN')].filter(isRead).forEach(element => element.click())
    }

    function isRead(element) {
        childs = element.parentElement.parentElement.parentElement.getElementsByClassName('G3')
        return ![...childs].some(e => e.innerText.search(/unread/i) !== -1)
    }

}())