-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_img.js
42 lines (34 loc) · 1.28 KB
/
save_img.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
var page = require('webpage').create(), system = require('system'), fs = require('fs');
var ajaxUrl = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js";
page.viewportSize = {width: window.screen.width, height: window.screen.height};
page.zoomFactor = 1;
page.open(system.args[1], function (status) {
if (status === 'success') {
var body = page.evaluate(function () {
return document.getElementsByTagName('html')[0].getBoundingClientRect();
});
var isJQ = page.evaluate(function () {
return typeof(jQuery) == "function" ? true : false;
});
var action = function () {
page.evaluate(function () {
$(document).ready(function () {
//action
$('body').trigger("mouseenter");
});
});
};
if (isJQ) {
action();
} else {
page.includeJs(ajaxUrl, function () {
action();
});
}
page.clipRect = {top: body.top, left: body.left, width: body.width, height: body.height};
page.render(system.args[2]); //save image
fs.write(system.args[3], page.content, 'w'); //save html
page.close();
phantom.exit();
}
});