Skip to content

Instantly share code, notes, and snippets.

@jewel-andraia
Last active December 21, 2016 14:04
Show Gist options
  • Save jewel-andraia/f13c808a3e4fd1dc1ca3b8e124be213a to your computer and use it in GitHub Desktop.
Save jewel-andraia/f13c808a3e4fd1dc1ca3b8e124be213a to your computer and use it in GitHub Desktop.
Add many users to reddit friends

This script prompts you for many usernames and adds them to your your r/friends list.

Usage:

  1. Visit https://www.reddit.com/prefs/friends
  2. Run this script.
  3. Wait around for a while. (1 minute / 30 people.)

⚠️ You really shouldn't run random scripts from people on the internet. Your account/computer might get compromised or broken.

function sanityCheck() {
if (document.location.pathname.indexOf('/prefs/friends') !== 0) {
alert('You must be on https://www.reddit.com/prefs/friends/ to do this.');
window.location = '/prefs/friends';
return false;
}
}
function promptForFriends() {
sanityCheck();
var usernamesStr = prompt('Who to friend? in the format:\n username1, username2, username3', 'username1, username2, username3');
if (!usernamesStr) return;
var usernames = usernamesStr.split(/[,\s]+/).filter(function(a) {
return a;
});
friendMany(usernames);
}
function friendMany(usernames) {
var promises = usernames.map(function(username, index, usernames) {
var deferred = $.Deferred();
setTimeout(function() {
var ajax = friend(username);
ajax.done(function() {
deferred.resolve();
if (allDone()) {
alert('Friended ' + username + '(' + (1 + index) + '/' + usernames.length + ')');
}
});
ajax.fail(function() {
deferred.reject();
alert('Could not friend ' + username);
});
}, index * 2000);
return deferred.promise();
});
function allDone() {
return promises.some(function(promise) {
return promise.state() !== 'pending';
})
}
$(window).on('beforeunload', function() {
if (!allDone()) {
return 'Not done adding friends';
}
});
}
function friend(username) {
if (!username) return;
return $.ajax({
url: '/api/friend',
method: 'POST',
data: {
action: 'add',
type: 'friend',
name: username,
uh: document.querySelector('input[name=uh]').value,
container: document.querySelector('#friend input[name=container]').value,
id: '#friend',
renderstyle: 'json'
}
});
}
promptForFriends();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment