-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgengo-approveTranslations.js
104 lines (77 loc) · 2.79 KB
/
gengo-approveTranslations.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
var fs = require('fs');
var casper = require("casper").create({
//verbose: true,
//logLevel: 'debug',
waitTimeout: 60 * 1000,
viewportSize: {
width: 1024,
height: 768
},
//userAgent: '',
pageSettings: {
clearMemoryCaches: true,
loadImages: false, // do not load images
loadPlugins: false
},
clientScripts: ['jquery-2.1.3.js']
});
casper.echo("Casper CLI passed args:");
require("utils").dump(casper.cli.args);
var links = casper.cli.args[0].toString();
links = links.split(",");
casper.options.onResourceRequested = function(C, requestData, networkRequest) {
if ((/http:\/\/.+?.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {
//console.log(‘Skipping CSS file: ’ + requestData[‘url’]);
//request.abort();
}
//console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData, undefined, 2))
if ( requestData['url'].search('http://')!=-1 || requestData['url'].search('https://')!=-1 ) {
//casper.echo('REQUEST: '+requestData['url']);
}
}
casper.options.onResourceReceived = function(C, response) {
//console.log('Response (#' + response.id + ', stage "' + response.stage + '"): ' + JSON.stringify(response, undefined, 2));
}
//var x = require('casper').selectXPath;
casper.on('page.error', function(msg, trace) {
this.echo('Error: ' + msg, 'ERROR');
for(var i=0; i<trace.length; i++) {
var step = trace[i];
this.echo(' ' + step.file + ' (line ' + step.line + ')', 'ERROR');
}
});
casper.on('remote.message', function(msg) {
this.echo(' ' + msg);
});
var i = -1;
function getLinks() {
// dont get the already approved links
if ( $('div.translation_list').length > 1 ) {
var links = document.querySelectorAll('div.translation_list:nth-child(2) .large-details-link');
return Array.prototype.map.call(links, function (e) {
return e.getAttribute('href');
});
}
}
casper.start('https://sandbox.gengo.com/auth/form/login/', function(){
casper.echo('URL https://sandbox.gengo.com/auth/form/login/ loaded');
//this.fill('form[action="https://sandbox.gengo.com/auth/login/"]', {
this.fill('#login > form', {
login_email : '[email protected]',
login_password: 'rVr#fJ9(6x'
}, true);
});
casper.then(function() {
this.each(links, function() {
i++; // change the link being opened (has to be here specifically)
this.thenOpen(links[i], function() {
this.echo(links[i]); // display the title of page
});
});
});
casper.run(function() {
// echo results in some pretty fashion
this.echo(links.length + ' links found:');
this.echo(links.join('\n'));
this.exit();
});