Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JamesTheHacker/19db4d3e3b980dc3b333b0f2681ad4c8 to your computer and use it in GitHub Desktop.
Save JamesTheHacker/19db4d3e3b980dc3b333b0f2681ad4c8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Facebook Mass Group Invite
// @namespace http://tampermonkey.net/
// @homepage http://cyberpunks.co.uk/facebook-mass-invite-tampermonkey.html
// @version 1.0
// @description Scrapes targeted ID's from a Facebook group members page, or group discussion, and invite them to your own group.
// @author James Jeffery
// @match https://www.facebook.com/*
// @grant none
// @require https://code.jquery.com/jquery-3.0.0.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.js
// ==/UserScript==
// Gets all UID's from a page
var getUIDs = function() {
var users = $('a[data-hovercard^="/ajax/hovercard/hovercard.php?id"], a[data-hovercard^="/ajax/hovercard/user.php?id"]').filter(function(i, el) {
return $(el).text() !== '';
}).map(function(i, el) {
return $(el).attr('data-hovercard').match(/id=(\d+)/)[1];
});
return _.uniqBy(users);
};
//Invites users to a group
var inviteUsersToGroup = function(dtsg, gid, uids, uid) {
var http = new XMLHttpRequest();
var url = '/ajax/groups/members/add_post.php?source=dialog_typeahead&group_id=' + gid + '&refresh=1&dpr=1';
var members = _.map(uids, function(el, i) { return 'members[' + i + ']=' + el; });
var params = 'fb_dtsg=' + dtsg + '&' + members.join('&') + '&__user=' + uid;
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
return true;
}
};
http.send(params);
};
(function() {
'use strict';
var dtsg = document.documentElement.innerHTML.match(/"token":"([A-Za-z0-9-_]+:[A-Za-z0-9-_]+)"/)[1];
var uid = document.querySelector('[id^="profile_pic_header"]').getAttribute('id').split('_')[3];
var users = [];
// Menu to hold input and buttons
var menu = $("<div></div>").css({
'background': '#FFF',
'position': 'fixed',
'top': '40px',
'right': '0',
'margin': '10px',
'padding': '20px',
'zindex': '100'
});
// Group ID input field
var groupIDInput = $('<input type="text" placeholder="Your Group ID" id="gid" />').css({
'margin-bottom': '10px',
'padding': '5px',
'font-size': '14px'
});
// Scrape members button + onclick event handler
var scrapeMembers = $("<button>Scrape Users</button>").css({
'font-size': '16px',
'display': 'block',
'width': '100%',
'padding': '10px',
'margin-bottom': '10px'
}).click(function() {
var uids = getUIDs();
uids.map(function(id) {
users.push(id);
});
$('#userCount').text(users.length + ' Users Scraped');
});
// Invite to group button + onclick event handler
var inviteToGroup = $("<button>Invite to Group</button>").css({
'font-size': '16px',
'display': 'block',
'width': '100%',
'padding': '10px',
'margin-bottom': '10px'
}).click(function() {
var gid = $('#gid').val();
if(users.length === 0) {
alert('Scrape some users first!');
} else if(gid === '') {
alert('Enter a group ID!');
} else {
_.chunk(users, 10).map(function(ids) {
inviteUsersToGroup(dtsg, gid, ids, uid);
});
users = [];
alert('All members have been invited!');
}
});
// Resset button + onclick event handler
var resetButton = $("<button>Reset</button>").css({
'font-size': '12px',
'display': 'block',
'width': '100%',
'padding': '3px',
'margin-bottom': '10px'
}).click(function() {
users = [];
$('#userCount').text('0 Users Scraped');
});
menu.append(groupIDInput);
menu.append(scrapeMembers);
menu.append(inviteToGroup);
menu.append(resetButton);
menu.append('<p id="userCount">0 Users Scraped</p>').css({
'text-align': 'center',
'font-size': '14px'
});
$('body').append(menu);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment