-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
51 lines (43 loc) · 1.57 KB
/
Copy pathbackground.js
File metadata and controls
51 lines (43 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
const letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I"];
let matrix = {};
if (browser.storage.local.get('matrix')) {
console.log("Initial load:", browser.storage.local.get('matrix'));
updateDict(browser.storage.local.get('matrix'));
}
function updateDict(rawMatrix) {
for (let i = 0; i < rawMatrix.length; i++) {
const row = letters[Math.floor(i / 9)];
const col = (i % 9) + 1;
const key = row + col;
matrix[key] = rawMatrix[i];
}
console.log("Updated dict:", matrix);
const values = Array.from(
document.querySelectorAll('.otpInput .digit-label')).map(el => el.textContent.trim());
const containers = document.querySelectorAll('.input-container');
containers.forEach((container, index) => {
const input = container.querySelector('input.digit-input');
if (input && values[index] !== undefined && matrix[values[index]] !== undefined) {
input.value = matrix[values[index]];
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
}
});
}
// initial load
(async () => {
const { matrix } = await browser.storage.local.get("matrix");
if (matrix) {
updateDict(matrix);
}
})();
// dynamic updates
browser.storage.onChanged.addListener((changes, area) => {
if (area === "local" && changes.matrix) {
const newMatrix = changes.matrix.newValue;
console.log("Matrix changed:", newMatrix);
if (newMatrix) {
updateDict(newMatrix);
}
}
});