-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddFriendBot.java
389 lines (358 loc) · 15.4 KB
/
AddFriendBot.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JCheckBox;
public class AddFriendBot{
private static JTextField tfusername;
private static JPasswordField tfpassword;
private static JTextField tftarget;
private static WebDriver driver;
private static JTextField tfspeed;
private static JTextField tfidrange;
private static JTextField tfnumber;
private static JCheckBox chckbxRememberMe;
private static ArrayList<String> idlist = new ArrayList<String>();
private static HashMap<String,String> userlist = new HashMap<String,String>();
@SuppressWarnings("unchecked")
public static boolean checkFacebookID(String id) throws IOException, ClassNotFoundException {
String location = "bin/"+tfusername.getText()+"-facebookIDList.txt";
boolean result = true;
File file =new File(location);
if(file.exists()){
ObjectInputStream input = new ObjectInputStream(new FileInputStream(location));
idlist = (ArrayList<String>) input.readObject();
input.close();
if (!idlist.contains(id)) {
idlist.add(id);
result = true;
}else {
result = false;
}
}else {
idlist.add(id);
result = true;
}
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(location));
output.writeObject(idlist);
output.close();
return result;
}
@SuppressWarnings({ "unchecked", "deprecation" })
public static void UserInformationSave() throws ClassNotFoundException, IOException {
String location = "bin/User Information.txt";
File file =new File(location);
if(file.exists()){
ObjectInputStream input = new ObjectInputStream(new FileInputStream(location));
userlist = (HashMap<String,String>) input.readObject();
input.close();
boolean isSelected = chckbxRememberMe.isSelected();
if(isSelected) {
userlist.put("username",tfusername.getText());
userlist.put("password",tfpassword.getText());
userlist.put("target",tftarget.getText());
userlist.put("number",tfnumber.getText());
userlist.put("checkbox","true");
}else {
userlist.put("username","");
userlist.put("password","");
userlist.put("target","");
userlist.put("number","999");
userlist.put("checkbox","");
}
}else {
userlist.put("username","");
userlist.put("password","");
userlist.put("target","");
userlist.put("number","999");
userlist.put("checkbox","true");
}
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(location));
output.writeObject(userlist);
output.close();
}
@SuppressWarnings({ "unchecked" })
public static HashMap<String,String> UserInformationRead() throws ClassNotFoundException, IOException {
new File("bin").mkdirs();
String location = "bin/User Information.txt";
File file =new File(location);
if(file.exists()){
ObjectInputStream input = new ObjectInputStream(new FileInputStream(location));
userlist = (HashMap<String,String>) input.readObject();
input.close();
}else {
userlist.put("username","");
userlist.put("password","");
userlist.put("target","");
userlist.put("number","999");
userlist.put("checkbox","true");
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(location));
output.writeObject(userlist);
output.close();
}
return userlist;
}
public static void LaunchGUIPanel() throws ClassNotFoundException, IOException {
userlist = UserInformationRead();
JFrame frame = new JFrame("Facebook Add Friend Bot");
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(522, 351);
frame.getContentPane().setLayout(null);
JLabel lblUsername = new JLabel("Username :");
lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblUsername.setBounds(21, 21, 182, 26);
frame.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("Password :");
lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblPassword.setBounds(21, 58, 171, 26);
frame.getContentPane().add(lblPassword);
JLabel lblUrl = new JLabel("Target :");
lblUrl.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblUrl.setBounds(21, 83, 148, 39);
frame.getContentPane().add(lblUrl);
tfusername = new JTextField();
tfusername.setFont(new Font("Tahoma", Font.PLAIN, 16));
tfusername.setBounds(112, 18, 199, 32);
tfusername.setText(userlist.get("username"));
frame.getContentPane().add(tfusername);
tfusername.setColumns(10);
tfpassword = new JPasswordField();
tfpassword.setFont(new Font("Tahoma", Font.PLAIN, 16));
tfpassword.setBounds(112, 55, 199, 26);
tfpassword.setText(userlist.get("password"));
frame.getContentPane().add(tfpassword);
tfpassword.setColumns(10);
tftarget = new JTextField();
tftarget.setFont(new Font("Tahoma", Font.PLAIN, 16));
tftarget.setBounds(112, 86, 385, 32);
tftarget.setText(userlist.get("target"));
// tftarget.setText("https://www.facebook.com/groups/592918330837781/members/");
frame.getContentPane().add(tftarget);
tftarget.setColumns(10);
JButton btnCencal = new JButton("Cancel Requests");
btnCencal.setFont(new Font("Source Code Pro", Font.BOLD, 12));
btnCencal.setBounds(21, 228, 171, 39);
btnCencal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
LaunchingChromeCancelRequests();
} catch (ClassNotFoundException | IOException e1) {}
}
});
frame.getContentPane().add(btnCencal);
JButton btnRun = new JButton("RUN");
btnRun.setFont(new Font("Source Code Pro", Font.BOLD, 37));
btnRun.setBounds(216, 191, 281, 76);
btnRun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
LaunchingChromeRUN();
} catch (ClassNotFoundException | IOException e1) {}
}
});
frame.getContentPane().add(btnRun);
JLabel lblCopyright = new JLabel("Copyright\u00A9 Ryan Kwan . [email protected]");
lblCopyright.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblCopyright.setForeground(Color.LIGHT_GRAY);
lblCopyright.setBounds(21, 276, 275, 22);
frame.getContentPane().add(lblCopyright);
JLabel lblFacebook = new JLabel("FACEBOOK");
lblFacebook.setFont(new Font("Source Code Pro Black", Font.BOLD, 31));
lblFacebook.setBackground(Color.WHITE);
lblFacebook.setForeground(new Color(0, 0, 255));
lblFacebook.setBounds(318, 5, 199, 48);
frame.getContentPane().add(lblFacebook);
JLabel lblSpeed = new JLabel("Speed :");
lblSpeed.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblSpeed.setBounds(21, 151, 148, 39);
frame.getContentPane().add(lblSpeed);
tfspeed = new JTextField();
tfspeed.setFont(new Font("Tahoma", Font.PLAIN, 16));
tfspeed.setBounds(112, 154, 94, 32);
tfspeed.setText("3000");
frame.getContentPane().add(tfspeed);
tfspeed.setColumns(10);
JLabel lblAddfdbot = new JLabel("ADDFDBOT");
lblAddfdbot.setForeground(Color.BLUE);
lblAddfdbot.setFont(new Font("Source Code Pro Black", Font.BOLD, 31));
lblAddfdbot.setBackground(Color.WHITE);
lblAddfdbot.setBounds(318, 46, 182, 41);
frame.getContentPane().add(lblAddfdbot);
JLabel lblIdRange = new JLabel("ID range :");
lblIdRange.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblIdRange.setBounds(21, 118, 148, 39);
frame.getContentPane().add(lblIdRange);
tfidrange = new JTextField();
tfidrange.setText("groupsMemberSection_recently_joined");
tfidrange.setFont(new Font("Tahoma", Font.PLAIN, 16));
tfidrange.setColumns(10);
tfidrange.setBounds(112, 121, 385, 32);
frame.getContentPane().add(tfidrange);
JLabel lblNumber = new JLabel("No. :");
lblNumber.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblNumber.setBounds(359, 151, 123, 39);
frame.getContentPane().add(lblNumber);
tfnumber = new JTextField();
tfnumber.setText(userlist.get("number"));
tfnumber.setFont(new Font("Tahoma", Font.PLAIN, 16));
tfnumber.setColumns(10);
tfnumber.setBounds(403, 154, 94, 32);
frame.getContentPane().add(tfnumber);
chckbxRememberMe = new JCheckBox("Remember me");
if (userlist.get("checkbox").equals("true")) {
chckbxRememberMe.setSelected(true);
}else {chckbxRememberMe.setSelected(false);}
chckbxRememberMe.setFont(new Font("Tahoma", Font.PLAIN, 16));
chckbxRememberMe.setBounds(21, 191, 179, 35);
frame.getContentPane().add(chckbxRememberMe);
JLabel lblLastestUpdateAugust = new JLabel("Lastest update: August 14");
lblLastestUpdateAugust.setFont(new Font("Tahoma", Font.ITALIC, 12));
lblLastestUpdateAugust.setBounds(341, 274, 156, 26);
frame.getContentPane().add(lblLastestUpdateAugust);
frame.setVisible(true);
}
@SuppressWarnings("deprecation")
public static void LaunchingChromeRUN() throws ClassNotFoundException, IOException{
UserInformationSave();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
String exePath = "chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
driver = new ChromeDriver(options);
driver.get(tftarget.getText());
WebElement emailelement = driver.findElement(By.id("email"));
emailelement.clear();
emailelement.sendKeys(tfusername.getText());
WebElement passwordelement = driver.findElement(By.id("pass"));
passwordelement.clear();
passwordelement.sendKeys(tfpassword.getText());
WebElement login = driver.findElement(By.id("loginbutton"));
login.submit();
int number = Integer.parseInt(tfnumber.getText())-1;
for (int x = 0; x <= number; x++) {
while (true) {
try {
WebElement addfriendsection = driver.findElement(By.id(tfidrange.getText()));
ArrayList<WebElement> addfriend = (ArrayList<WebElement>) addfriendsection.findElements(By.className("FriendButton"));
WebElement facebookid = addfriend.get(x).findElement(By.xpath("../../../../../.."));
boolean result = checkFacebookID(facebookid.getAttribute("id"));
if (result) {
JavascriptExecutor jse = (JavascriptExecutor) driver;
int sleeptime = (int )(Math.random() * 15 + 1)*100+Integer.parseInt(tfspeed.getText());
while(true) {
try {
if (driver.getCurrentUrl().equals(tftarget.getText())) {
if(x>1) {
jse.executeScript("arguments[0].scrollIntoView(true);", addfriend.get(x-2));
}
addfriend.get(x).click();
try {
Thread.sleep(sleeptime);
} catch (InterruptedException e1) {}
break;
}else {
driver.get(tftarget.getText());
addfriendsection = driver.findElement(By.id(tfidrange.getText()));
addfriend = (ArrayList<WebElement>) addfriendsection.findElements(By.className("FriendButton"));
facebookid = addfriend.get(x).findElement(By.xpath("../../../../../.."));
}
} catch (org.openqa.selenium.WebDriverException e3) {
for (int i=0; i<4; i++) {
try {
switch (i) {
case 0: WebElement Confirmpopup = driver.findElement(By.xpath("//button[contains(.,'Confirm')]"));
Confirmpopup.click();
break;
case 1: WebElement Closepopup = driver.findElement(By.xpath("//a[@title='Close']"));
Closepopup.click();
break;
case 2: WebElement Closepopup2 = driver.findElement(By.xpath("//a[contains(.,'Close') and @action='cancel']"));
Closepopup2.click();
break;
case 3: addfriendsection.click();
if(x != 0) {
jse.executeScript("arguments[0].scrollIntoView(true);", addfriend.get(x-1));
}
break;
default: break;
}
try {
Thread.sleep(sleeptime);
} catch (InterruptedException e1) {}
break;
} catch (org.openqa.selenium.NoSuchElementException | org.openqa.selenium.StaleElementReferenceException | org.openqa.selenium.ElementNotVisibleException e) {}
}
}
}
}else {
number = number+1;
}
break;
}catch (java.lang.IndexOutOfBoundsException e) {
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollTo(0, document.body.scrollHeight);", "");
}catch (org.openqa.selenium.StaleElementReferenceException | org.openqa.selenium.NoSuchElementException e5) {
driver.get(tftarget.getText());
}
}
}
}
@SuppressWarnings("deprecation")
public static void LaunchingChromeCancelRequests() throws ClassNotFoundException, IOException {
UserInformationSave();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
String exePath = "chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
driver = new ChromeDriver(options);
driver.get("http://www.facebook.com");
WebElement emailelement = driver.findElement(By.id("email"));
emailelement.clear();
emailelement.sendKeys(tfusername.getText());
WebElement passwordelement = driver.findElement(By.id("pass"));
passwordelement.clear();
passwordelement.sendKeys(tfpassword.getText());
WebElement login = driver.findElement(By.id("loginbutton"));
login.submit();
driver.get("https://m.facebook.com/friends/center/requests/outgoing/#friends_center_main");
WebElement friends_center_main = driver.findElement(By.id("friends_center_main"));
while (true) {
int old_height = friends_center_main.getSize().getHeight();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollTo(0, document.body.scrollHeight);", "");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {}
if (friends_center_main.getSize().getHeight() == old_height) {
for(int i=1; i<10; i++){
jse.executeScript("window.scrollTo(0, document.body.scrollHeight);", "");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {}
}
if (friends_center_main.getSize().getHeight() == old_height) {
jse.executeScript("var inputs = document.getElementsByClassName('_54k8 _56bs _56bt'); for(var i=0; i<inputs.length;i++) { inputs[i].click();}", "");
break;
}
}
}
}
public static void main(String[] args) throws ClassNotFoundException, IOException {
AddFriendBot.LaunchGUIPanel();
}
}