forked from stardothosting/facebook-purge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbpurge.js
152 lines (140 loc) · 5.72 KB
/
fbpurge.js
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
/*******************************************
* Facebook Purge *
* Written with love by Star Dot Hosting Inc. *
* www.shift8web.ca *
********************************************/
var utils = require("utils");
var fs = require('fs');
var casper = require('casper').create({
verbose: true,
logLevel: "warning",
pageSettings: {
userAgent: randomUserAgent(),
//userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24",
loadImages: true, // load images
loadPlugins: true, // load NPAPI plugins (Flash, Silverlight, ...)
webSecurityEnabled: false // allows for flexible ajax
},
clientScripts: ['jquery-3.3.1.min.js']
});
/************
* Functions *
************/
// Used to pick a random user agent every time
function randomUserAgent() {
var userAgents = fs.read('user_agents.txt').split("\n");
var userAgent_r = Math.floor(Math.random() * userAgents.length);
console.log('User agent : ' + userAgents[userAgent_r]);
console.log('User agent r : ' + userAgent_r);
return userAgents[userAgent_r];
}
function randomSentence() {
var uarticle = new Array("The", "A", " One", "Some", "Any", "This", "That", "An", "Such", "What", "Rather", "Quite");
var larticle = new Array("the", "a", "one", "some", "any", "this", "that", "an", "such", "what", "rather", "quite");
var preposition = new Array("to", "from", "over", "under", "on", "of", "with", "at", "into", "including", "unil", "against", "among", "throughout", "despite", "towards", "upon", "concerning");
var noun = fs.read('nouns.txt').split("\n");
var verb = fs.read('verbs.txt').split("\n");
var uarticle_r = Math.floor(Math.random() * uarticle.length);
var noun_r1 = Math.floor(Math.random() * noun.length);
var noun_r2 = Math.floor(Math.random() * noun.length);
var verb_r = Math.floor(Math.random() * verb.length);
var larticle_r = Math.floor(Math.random() * larticle.length);
var preposition_r = Math.floor(Math.random() * preposition.length);
return uarticle[uarticle_r] + " " + noun[noun_r1] + " " + verb[verb_r] + " " + preposition[preposition_r] + " " + larticle[larticle_r] + " " + noun[noun_r2] + ".";
}
var parseQueryString = function( queryString ) {
var params = {}, queries, temp, i, l;
// Split into key/value pairs
queries = queryString.split("&");
// Convert the array of strings into an object
for ( i = 0, l = queries.length; i < l; i++ ) {
temp = queries[i].split('=');
params[temp[0]] = temp[1];
}
return params;
};
/***************************************
* Declare variables and user arguments *
***************************************/
var xpath = require('casper').selectXPath;
var mouse = require("mouse").create(casper);
var config = require("./config.json");
var username = casper.cli.get("user");
var password = casper.cli.get("pass");
var post_id = casper.cli.raw.get("postid"); // story_fbid=
var post_id_file = casper.cli.raw.get("postid_file");
// Force single ids or multiple ids to go through same forEach
if (post_id_file) {
var post_ids = fs.read(post_id_file).split("\n");
} else {
var post_ids = [ post_id ];
}
var user_id = casper.cli.raw.get("userid"); // id=
var action = casper.cli.raw.get("action"); // get the intended action
var waitMinTime = 6000;
var waitMaxTime = 10000;
var minWait = 3000;
var maxWait = 6000;
var wallUrl = config['urls']['loginUrl'] + username.split('@')[0]; // Assuming the email id is your facebook page vanity url.
var waitTime = Math.floor(Math.random() * waitMaxTime) + waitMinTime;
/***************************************
* Login and authenticate with facebook *
***************************************/
casper.start().thenOpen('https://m.facebook.com/login/?ref=dbl&fl', function() {
console.log(username);
console.log("Facebook website opened");
});
casper.then(function(){
this.evaluate(function(username, password){
document.getElementById("m_login_email").value = username;
document.getElementById("m_login_password").value = password;
document.querySelectorAll('button[data-sigil="touchable m_login_button"]')[0].click();
},{
username : username,
password : password
});
});
casper.then(function _waitAfterClick() {
casper.wait(waitTime, function() {});
});
casper.then(function(){
var cookies = phantom.cookies;
var logged_in = null;
for( var i = 0, len = cookies.length; i < len; i++ ) {
console.log('cookies : ' + JSON.stringify(cookies[i]['name']));
if( cookies[i]['name'] === 'c_user' ) {
logged_in = cookies[i]['value'];
break;
}
}
// We want the c_user facebook cookie with the value to equal our user id
if (logged_in === user_id) {
console.log("Logged In Successfully");
this.capture('AfterLogin.png');
} else {
console.log("did not Log In");
this.capture('login.png');
this.exit();
}
});
// Load include dependent on action argument
casper.then(function() {
if (action == 'postgrab') {
phantom.injectJs('./includes/fb_postgrab.js');
} else if (action == 'commentgrab') {
console.log('Grab comment IDs');
} else if (action == 'taggrab') {
console.log('Grab tag IDs');
} else if (action == 'postwipe') {
phantom.injectJs('./includes/fb_postwipe.js');
} else if (action == 'commentwipe') {
console.log('Wipe comments from IDs');
} else if (action == 'tagwipe') {
console.log('Wipe tags from IDs');
} else {
console.log('No proper action provided.');
}
});
casper.run(function() {
this.exit();
});