-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
64 lines (59 loc) · 2.86 KB
/
popup.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
document.addEventListener('DOMContentLoaded', function () {
const extractButton = document.getElementById("extractButton");
const toggleFormat = document.getElementById("toggleFormat");
const prefixFormat = document.getElementById("prefixFormat");
const plaintiffDefendantFormat = document.getElementById("plaintiffDefendantFormat");
const inflectFormat = document.getElementById("inflectFormat");
const statusMessage = document.getElementById("statusMessage");
if (extractButton) {
extractButton.addEventListener("click", () => {
statusMessage.style.display = 'block';
statusMessage.textContent = "Čekejte...";
statusMessage.className = "status-message";
const includeVRizeni = toggleFormat.checked;
const selectedPrefixFormat = prefixFormat.checked ? "č. j." : "čj.";
const useNavrhovatel = plaintiffDefendantFormat.checked ? "true" : "false";
const inflectText = inflectFormat.checked;
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const activeTab = tabs[0];
chrome.scripting.executeScript({
target: { tabId: activeTab.id },
files: ["content.js"]
}, () => {
chrome.tabs.sendMessage(activeTab.id, {
action: "extractInfo",
includeVRizeni: includeVRizeni,
prefixFormat: selectedPrefixFormat,
useNavrhovatel: useNavrhovatel,
inflectText: inflectText
}, (response) => {
console.log("Response from content script:", response); // Debug log
if (response && response.success) {
statusMessage.textContent = "Text úspěšně zkopírován do schránky.";
statusMessage.className = "status-message success";
} else {
const errorMessage = response ? response.error : "No response from content script";
statusMessage.innerHTML = `Chyba při kopírování textu: ${errorMessage}<br><button id="copyError">Zkopírovat chybovou zprávu</button>`;
statusMessage.className = "status-message error";
document.getElementById("copyError").addEventListener("click", () => {
navigator.clipboard.writeText(errorMessage).then(() => {
statusMessage.textContent = "Chybová zpráva úspěšně zkopírována do schránky.";
}).catch(err => {
console.error("Chyba při kopírování chybové zprávy:", err);
});
});
}
});
});
});
});
}
// Handle link clicks
const externalLinks = document.querySelectorAll('.external-link');
externalLinks.forEach(link => {
link.addEventListener('click', function(event) {
event.preventDefault();
chrome.tabs.create({ url: link.href });
});
});
});