This repository was archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (47 loc) · 1.57 KB
/
index.js
File metadata and controls
60 lines (47 loc) · 1.57 KB
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
const puppeteer = require("puppeteer");
const config = require("./config.json");
async function run() {
let url = "https://myabb.in/";
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url, { waitUntil: "networkidle0" });
await page.type("#DUser", config.username, { delay: config.buffer_delay });
await page.type("#Pwd", config.password, { delay: config.buffer_delay });
await page.click(".btn.waves-effect.waves-light", { delay: 1000 });
await page.waitForNavigation({ waitUntil: "networkidle0" });
const usage_page = await browser.newPage();
await usage_page.goto(`${url}/goToForm?formId=CUP001`, {
waitUntil: "networkidle0",
});
const remaining = await getRemainingData(usage_page);
const used = await getUsedData(usage_page);
const total = await getTotalData(usage_page);
console.log("action called....");
console.log(`Total: ${toGB(total)}GB`);
console.log(`Used: ${toGB(used)}GB`);
console.log(`Remaining: ${toGB(remaining)}GB`);
console.log("action completed....");
await browser.close();
}
async function getRemainingData(page) {
return await page.evaluate(() => {
return getValue("#totalOctets");
});
}
async function getUsedData(page) {
return await page.evaluate(() => {
return getValue("#totalOctet");
});
}
async function getTotalData(page) {
return await page.evaluate(() => {
return getValue("#totalOc");
});
}
function toGB(mb) {
return (mb / 1024).toFixed(2);
}
function getValue(id){
return document.querySelector(id).innerText;
}
run();