-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
44 lines (38 loc) · 1.52 KB
/
contentScript.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
(() => {
console.log("Login script loaded");
function reactJSSetValue(elm, value) {
elm.value = value;
elm.defaultValue = value;
elm.dispatchEvent(
new Event("input", { bubbles: true, target: elm, data: value })
);
}
const usernameField = document.getElementById("user-name");
reactJSSetValue(usernameField, "standard_user");
const passwordField = document.getElementById("password");
reactJSSetValue(passwordField, "secret_sauce");
const loginButton = document.getElementById("login-button");
loginButton.click();
//////////////////////////////////////
///// FOR INVENTORY PAGE ACTIONS ////
////////////////////////////////////
chrome.runtime.onMessage.addListener((obj, sender, response) => {
console.log("msg received");
const { type, value } = obj;
if (type === "addToCartInput") {
document.querySelectorAll(".inventory_item button")[value - 1].click();
}
if (type === "goToCheckout") {
document.getElementsByClassName("shopping_cart_link")[0].click();
document.getElementById("checkout").click();
}
if (type === "checkout") {
reactJSSetValue(document.getElementById("first-name"), value.firstName);
reactJSSetValue(document.getElementById("last-name"), value.lastName);
reactJSSetValue(document.getElementById("postal-code"), value.zipCode);
// document.getElementsByClassName("shopping_cart_link")[0].click();
document.getElementById("continue").click();
document.getElementById("finish").click();
}
});
})();