-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
112 lines (96 loc) · 3.15 KB
/
content.js
File metadata and controls
112 lines (96 loc) · 3.15 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// content.js — Save + Autofill ONLY (NO submit, NO auto-login)
(() => {
function nativeSet(el, value) {
const proto = Object.getPrototypeOf(el);
const desc = Object.getOwnPropertyDescriptor(proto, "value");
if (desc && desc.set) desc.set.call(el, value);
else el.value = value;
el.dispatchEvent(new Event("input", { bubbles: true }));
el.dispatchEvent(new Event("change", { bubbles: true }));
}
function showToast(text) {
let t = document.getElementById("erp-autofill-toast");
if (!t) {
t = document.createElement("div");
t.id = "erp-autofill-toast";
Object.assign(t.style, {
position: "fixed",
bottom: "90px",
right: "16px",
zIndex: 999999,
background: "rgba(0,0,0,0.85)",
color: "white",
padding: "8px 12px",
borderRadius: "6px",
fontSize: "13px",
fontFamily: "Arial"
});
document.body.appendChild(t);
}
t.textContent = text;
t.style.opacity = "1";
setTimeout(() => (t.style.opacity = "0"), 1800);
}
function injectSaveButton() {
if (document.getElementById("erp-save-btn")) return;
const btn = document.createElement("button");
btn.id = "erp-save-btn";
btn.textContent = "Save ERP creds";
Object.assign(btn.style, {
position: "fixed",
bottom: "18px",
right: "16px",
zIndex: 999999,
padding: "10px 14px",
borderRadius: "8px",
border: "none",
background: "#0b5fff",
color: "#fff",
fontSize: "14px",
cursor: "pointer",
boxShadow: "0 6px 18px rgba(0,0,0,0.25)"
});
btn.onclick = () => {
const user = document.querySelector("#user_id")?.value || "";
const pass = document.querySelector("#password")?.value || "";
const sec = document.querySelector("#answer")?.value || "";
if (!user || !pass) {
showToast("Enter ID & password first");
return;
}
chrome.storage.sync.set(
{ userid: user, password: pass, security: sec || "" },
() => showToast("Credentials saved ✅")
);
};
document.body.appendChild(btn);
}
function autofillFromStorage() {
chrome.storage.sync.get(
["userid", "password", "security"],
(data) => {
const user = document.querySelector("#user_id");
const pass = document.querySelector("#password");
const sec = document.querySelector("#answer");
if (user && data.userid && !user.value)
nativeSet(user, data.userid);
if (pass && data.password && !pass.value)
nativeSet(pass, data.password);
if (sec && data.security && !sec.value)
nativeSet(sec, data.security);
}
);
}
// Wait until ERP inputs appear
let tries = 0;
const interval = setInterval(() => {
const user = document.querySelector("#user_id");
const pass = document.querySelector("#password");
if (user && pass) {
injectSaveButton();
autofillFromStorage();
}
tries++;
if (tries > 40) clearInterval(interval);
}, 300);
})();