-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (63 loc) · 1.54 KB
/
index.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
const puppeteer = require("puppeteer");
const Clipper = require("image-clipper");
Clipper.configure({
canvas: require("canvas"),
});
const usernames = require("./usernames");
async function generateChart(username) {
const browser = await puppeteer.launch({
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.setViewport({
width: 900,
height: 600,
deviceScaleFactor: 3,
});
await page
.goto("https://sourcerer.io/" + username, {
waitUntil: "networkidle2",
})
.catch((err) => {
console.log(err);
});
if (page.url().includes("notfound")) {
browser.close();
return;
}
const closeBrowser = await page.evaluate(() => {
var overviewSelector = document.querySelector("#awesome-chart-section");
if (overviewSelector === null) {
return true;
} else {
overviewSelector.scrollIntoView();
return false;
}
});
if (closeBrowser) {
browser.close();
return;
}
await page.screenshot({
path: "./charts/" + username + ".png",
});
await browser.close();
}
(() => {
usernames.forEach((username) => {
generateChart(username)
.then(() => {
Clipper("./charts/" + username + ".png", function () {
this.crop(150, 100, 2400, 1450).toFile(
"./charts/" + username + "-sourcerer-chart.png",
function () {
console.log("Generated charts for " + username + "!");
}
);
});
})
.catch((err) => {
console.log(err);
});
});
})();