-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript.js
66 lines (55 loc) · 1.98 KB
/
script.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
/* jshint node: true */
/* global: casper */
"use strict";
phantom.casperPath = 'node_modules/casperjs';
phantom.injectJs('node_modules/casperjs/bin/bootstrap.js');
var LOGIN_URLS = [
'https://stackoverflow.com/users/#',
'https://programmers.stackexchange.com/',
'https://superuser.com/',
'https://codereview.stackexchange.com/'
];
var start = +new Date();
var casper = require('casper').create({
exitOnError: true,
pageSettings: {
loadImages: false,
loadPlugins: false
}
});
var email = casper.cli.get(0);
var password = casper.cli.get(1);
casper.echo('Today: ' + new Date());
if (!email || !password || !(/@/).test(email)) {
casper.die('USAGE: casperjs stackoverflow-fanatic.js <email> <password> --ssl-protocol=any', 1);
} else {
casper.echo('Loading login page');
}
casper.start()
.each(LOGIN_URLS, function (casper, link) {
if(LOGIN_URLS.indexOf(link)===0){
casper.thenOpen(link, function () {
this.echo('Logging in using email address ' + email +
' and password ' + (new Array(password.length + 1)).join('*'));
this.fill('#login-form', {email: email, password: password}, true);
});
casper.wait(500);
casper.then(function () {
if (this.getCurrentUrl().indexOf(link) === 0) {
this.die('Could not log in. Check your credentials.');
} else {
this.echo('Clicking profile link');
this.click('.my-profile');
this.then(function () {
this.echo('User ' + this.getCurrentUrl().split('/').reverse()[0] + ' logged in!' +
'\nTook ' + (((+new Date()) - start) / 1000) + 's');
});
}
});
}else{
casper.thenOpen(link, function () {
this.echo(link+' visited');
});
}
});
casper.run();