Last active
April 12, 2022 05:28
-
-
Save thosakwe/6f9fb4c3b7df5bac20c552781409dd41 to your computer and use it in GitHub Desktop.
Press CTRL+SHIFT+Y/⌘+SHIFT+Y to click every 'Follow' button on the current Twitter page.
This file contains 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
// ==UserScript== | |
// @name Auto-Follow Twitter Users | |
// @namespace https://gist.github.com/thosakwe/6f9fb4c3b7df5bac20c552781409dd41 | |
// @version 1.0 | |
// @description Press CTRL+SHIFT+Y/⌘+SHIFT+Y to click every 'Follow' button on the current Twitter page. | |
// @author thosakwe | |
// @match https://*.twitter.com/* | |
// @require https://code.jquery.com/jquery-3.1.1.slim.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.0/mousetrap.min.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function loadScript(src) { | |
var s = document.createElement('script'); | |
s.src = src; | |
document.body.appendChild(s); | |
} | |
function mass(jQuery, options) { | |
var $ = jQuery; | |
var opts = $.extend({}, { | |
maxButtonsInWorker: 20 | |
}, options); | |
var queue = []; | |
$(".user-actions.not-following.not-muting").each(function() { | |
var group = $(this); | |
var userId = group.attr("data-user-id"); | |
var name = group.attr("data-name"); | |
var btn = group.find("button.follow-button"); | |
queue.push(new Promise(function(resolve, reject) { | |
try { | |
btn.click(); | |
console.log('Followed user #', userId, ": ", name); | |
resolve(); | |
} catch(e) { | |
reject(e); | |
} | |
})); | |
}); | |
Promise.all(queue).then(function(results) { | |
alert('Followed ' + results.length + ' user(s)!'); | |
}).catch(function(e) { | |
console.error(e); | |
alert('Failed to auto-follow.'); | |
}); | |
} | |
if (!window.jQuery) | |
loadScript('https://code.jquery.com/jquery-3.1.1.slim.min.js'); | |
if (!window.Mousetrap) | |
loadScript('https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.0/mousetrap.min.js'); | |
$(document).ready(function() { | |
console.info('Ready to auto-follow...'); | |
window.Mousetrap.bind(['command+shift+y', 'ctrl+shift+y'], function() { | |
if (window.confirm('Auto-follow users?')) { | |
mass(window.jQuery); | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment