-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevtools.js
83 lines (81 loc) · 3.34 KB
/
devtools.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
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
chrome.devtools.panels.elements.createSidebarPane(
"Verifier",
function (sidebar) {
let currentElement = "None";
let trackingId = "None";
let proof = "None";
let verifier =
"https://sepolia.etherscan.io/address/0xbb6ee4b1b44e3715fa114575f90349186018e338#readContract";
chrome.runtime.onMessage.addListener(function (
message,
sender,
sendResponse
) {
if (message.message.action === "status") {
trackingId = message.message.trackingId;
proof = message.message.proof;
sidebar.setObject({
selected_element: currentElement,
status: message.message.status,
...(message.message.trackingId
? { trackingId: message.message.trackingId }
: {}),
...(message.message.proof
? { proof: message.message.proof }
: {}),
verifier,
});
}
if (message.message.action === "error") {
sidebar.setObject({
error: "Please try another element",
});
}
});
chrome.devtools.panels.elements.onSelectionChanged.addListener(
async () => {
chrome.devtools.inspectedWindow.eval(
"[$0.outerHTML, window.location.href]",
function (result, isException) {
if (isException) {
console.error(
"Error retrieving selected element:",
isException
);
sidebar.setObject({
error: "Error retrieving element",
});
} else {
sidebar.setObject({
selected_element:
result[0] || "No outerHTML available",
});
chrome.runtime.sendMessage(
{
action: "sendData",
data: {
html: result[0],
url: result[1],
},
},
function (response) {
console.log(response);
if (response) currentElement = result[0];
else {
sidebar.setObject({
currentElement,
trackingId,
proof,
verifier,
error: "Please wait until the previous proof finishes",
});
}
}
);
}
}
);
}
);
}
);