-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpanel.js
More file actions
59 lines (54 loc) · 2.1 KB
/
panel.js
File metadata and controls
59 lines (54 loc) · 2.1 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
document.addEventListener("DOMContentLoaded", () => {
const markPageCheckbox = document.getElementById("markPage");
const selectorInput = document.getElementById("selector");
const markPlacementSelect = document.getElementById("markPlacement");
const showBoundingBoxesCheckbox =
document.getElementById("showBoundingBoxes");
const viewPortOnlyCheckbox = document.getElementById("viewPortOnly");
const copyOptionsButton = document.getElementById("copyOptions");
const refreshButton = document.getElementById("refresh");
const outputDiv = document.getElementById("output");
const getCurrentOptions = () => {
return {
selector: selectorInput.value,
markPlacement: markPlacementSelect.value,
showBoundingBoxes: showBoundingBoxesCheckbox.checked,
viewPortOnly: viewPortOnlyCheckbox.checked,
// TODO: Add new options
};
};
const sendMessageToContentScript = (action) => {
const options = getCurrentOptions();
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length === 0) return;
chrome.tabs.sendMessage(tabs[0].id, { action, options }, (response) => {
if (chrome.runtime.lastError) {
outputDiv.textContent = "Error: " + chrome.runtime.lastError.message;
return;
}
if (response && response.markedElements) {
outputDiv.textContent = JSON.stringify(
response.markedElements,
null,
2
);
} else if (response && response.success) {
outputDiv.textContent = "Unmarked successfully.";
}
});
});
};
markPageCheckbox.addEventListener("change", () => {
const action = markPageCheckbox.checked ? "markPage" : "unmarkPage";
sendMessageToContentScript(action);
});
copyOptionsButton.addEventListener("click", () => {
const options = getCurrentOptions();
navigator.clipboard.writeText(JSON.stringify(options, null, 2)).then(() => {
alert("Options copied to clipboard!");
});
});
refreshButton.addEventListener("click", () => {
sendMessageToContentScript("refresh");
});
});