-
Notifications
You must be signed in to change notification settings - Fork 2
/
kludgy.js
74 lines (44 loc) · 1.16 KB
/
kludgy.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
#!/usr/bin/env node
// jshint esversion:6
const path = require('path');
const zombie = require('zombie');
const fs = require('fs');
const helpers = require('./helpers');
const browser = new zombie({
loadCSS: false,
//waitDuration: (10 * 1000),
});
const html = './temp.html';
function init() {
let key = helpers.argv();
if (key.length) {
let template = `
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=${key}"></script>
<script src="maps.js"></script>
`.replace(/\s{2,}/g, '');
fs.writeFileSync(html, template, 'utf8');
start();
}
}
function start() {
browser.visit(`file://${path.resolve(html)}`, function(error) {
if ( ! error) {
browser
.wait()
.then(() => {
coords = JSON.parse(browser.window.COORDS);
browser.window.close();
// https://github.com/mhulse/random-street-coords/issues/4
if (coords.copyright == '© 2017 Google') {
console.log(`${coords.lat},${coords.lng},${coords.id}`);
fs.unlinkSync(html);
} else {
start();
}
});
} else {
throw error;
}
});
}
init();