This script prompts you for many usernames and adds them to your your r/friends list.
Usage:
- Visit https://www.reddit.com/prefs/friends
- Run this script.
- Wait around for a while. (1 minute / 30 people.)
This script prompts you for many usernames and adds them to your your r/friends list.
Usage:
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(); |