-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
123 lines (123 loc) · 4.27 KB
/
Copy pathcontent-script.js
File metadata and controls
123 lines (123 loc) · 4.27 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
113
114
115
116
117
118
119
120
121
122
123
"use strict";
(() => {
// trashmail-addon/ts/content-script.ts
var browser = globalThis.browser ?? chrome;
function showMitmWarning(message, title, dismissText) {
if (document.getElementById("trashmail-mitm-warning")) {
return;
}
const dialogTitle = title || "Security Warning";
const continueText = dismissText || "Dismiss";
const overlay = document.createElement("div");
overlay.id = "trashmail-mitm-warning";
overlay.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.9);
z-index: 2147483647;
display: flex;
align-items: center;
justify-content: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
`;
const dialog = document.createElement("div");
dialog.style.cssText = `
background: #1a1a2e;
border: 3px solid #ef4444;
border-radius: 12px;
padding: 32px;
max-width: 500px;
color: white;
box-shadow: 0 0 50px rgba(239, 68, 68, 0.5);
`;
dialog.innerHTML = `
<div style="text-align: center; margin-bottom: 20px;">
<div style="font-size: 64px; margin-bottom: 16px;">\u26A0\uFE0F</div>
<h1 style="color: #ef4444; font-size: 24px; margin: 0 0 8px 0;">
${escapeHtml(dialogTitle)}
</h1>
</div>
<div style="background: #0f0f1a; border-radius: 8px; padding: 16px; margin-bottom: 20px; font-size: 14px; line-height: 1.6; white-space: pre-wrap;">${escapeHtml(message)}</div>
<div style="display: flex; gap: 12px; justify-content: center;">
<button id="trashmail-mitm-close" style="
background: #ef4444;
color: white;
border: none;
padding: 12px 32px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: bold;
">${escapeHtml(continueText)}</button>
</div>
`;
overlay.appendChild(dialog);
document.body.appendChild(overlay);
document.getElementById("trashmail-mitm-close").addEventListener("click", () => {
overlay.remove();
});
}
function escapeHtml(text) {
const div = document.createElement("div");
div.textContent = text;
return div.innerHTML;
}
function pasteIntoFocusedField(pasteText) {
const e = document.activeElement;
if (!e) {
return false;
}
if ("selectionStart" in e) {
const input = e;
const start = input.selectionStart;
const end = input.selectionEnd;
if (start === null || end === null) {
input.value = pasteText;
} else {
input.value = `${input.value.substring(0, start)}${pasteText}${input.value.substring(end)}`;
try {
input.setSelectionRange(start + pasteText.length, start + pasteText.length);
} catch (err) {
console.warn("[Aionda Mail] Cursor konnte nicht gesetzt werden:", err);
}
}
return input.value.includes(pasteText);
}
if (e.isContentEditable) {
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
return false;
}
selection.deleteFromDocument();
selection.getRangeAt(0).insertNode(document.createTextNode(pasteText));
return true;
}
return false;
}
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message && message.action === "guardian_warning") {
const warning = message;
showMitmWarning(warning.message, warning.title, warning.dismissText);
sendResponse({ received: true });
return true;
}
if (message === "check_editable") {
const activeElement = document.activeElement;
const isInput = activeElement && "selectionStart" in activeElement && !activeElement.readOnly;
sendResponse(isInput || activeElement && activeElement.isContentEditable);
return true;
} else {
let pasted = false;
try {
pasted = pasteIntoFocusedField(message);
} catch (err) {
console.warn("[Aionda Mail] Adresse konnte nicht eingefuegt werden:", err);
}
sendResponse({ pasted });
return true;
}
});
})();