-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphantom_script.js
40 lines (35 loc) · 1014 Bytes
/
phantom_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
// 'url' is assigned to in a statement before this.
var page = require('webpage').create();
var isReady = function () {
return page.evaluate(function () {
if (typeof Meteor === 'undefined'
|| Meteor.status === undefined
|| !Meteor.status().connected) {
return false;
}
if (typeof Package === 'undefined'
|| Package.spiderable === undefined
|| Package.spiderable.Spiderable === undefined
|| !Package.spiderable.Spiderable._initialSubscriptionsStarted) {
return false;
}
Tracker.flush();
return DDP._allSubscriptionsReady();
});
};
var dumpPageContent = function () {
var out = page.content;
out = out.replace(/<script[^>]+>(.|\n|\r)*?<\/script\s*>/ig, '');
out = out.replace('<meta name="fragment" content="!">', '');
console.log(out);
};
page.open(url, function(status) {
if (status === 'fail')
phantom.exit();
});
setInterval(function() {
if (isReady()) {
dumpPageContent();
phantom.exit();
}
}, 100);