V1.1
This commit is contained in:
parent
2600300d36
commit
b15651b5b3
3 changed files with 65 additions and 58 deletions
|
@ -2,8 +2,14 @@
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Mailcow Temp Mail",
|
"name": "Mailcow Temp Mail",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"description": "Fetch and generate temporary emails via Mailcow",
|
"description": "Login and generate temporary emails via Mailcow",
|
||||||
"permissions": ["cookies", "storage", "clipboardWrite", "activeTab", "https://mail.pandem.fr*"],
|
"permissions": [
|
||||||
|
"cookies",
|
||||||
|
"storage",
|
||||||
|
"clipboardWrite",
|
||||||
|
"activeTab",
|
||||||
|
"https://mail.pandem.fr/*"
|
||||||
|
],
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_popup": "popup.html",
|
"default_popup": "popup.html",
|
||||||
"default_icon": "icon.png"
|
"default_icon": "icon.png"
|
||||||
|
|
|
@ -4,16 +4,26 @@
|
||||||
<title>Mailcow Temp Mail</title>
|
<title>Mailcow Temp Mail</title>
|
||||||
<style>
|
<style>
|
||||||
body { width: 250px; padding: 10px; font-family: Arial, sans-serif; }
|
body { width: 250px; padding: 10px; font-family: Arial, sans-serif; }
|
||||||
button { width: 100%; padding: 5px; margin-top: 5px; }
|
button, input { width: 100%; padding: 5px; margin-top: 5px; }
|
||||||
input { width: 100%; padding: 5px; margin-bottom: 5px; text-align: center; }
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h3>Mailcow Temp Mail</h3>
|
<h3>Mailcow Temp Mail</h3>
|
||||||
<input type="text" id="email" readonly placeholder="No email found">
|
|
||||||
<button id="fetch">Get My Temp Email</button>
|
<div id="login-form">
|
||||||
<button id="generate">Generate New Email</button>
|
<input type="text" id="username" placeholder="Email">
|
||||||
<button id="copy">Copy to Clipboard</button>
|
<input type="password" id="password" placeholder="Password">
|
||||||
|
<button id="login">Login</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="email-form" style="display: none;">
|
||||||
|
<input type="text" id="email" readonly placeholder="No email found">
|
||||||
|
<button id="fetch">Get My Temp Email</button>
|
||||||
|
<button id="generate">Generate New Email</button>
|
||||||
|
<button id="copy">Copy to Clipboard</button>
|
||||||
|
<button id="logout">Logout</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,11 +1,47 @@
|
||||||
const API_BASE = "https://mail.paxcia.net";
|
const API_BASE = "https://mail.pandem.fr/api/v1";
|
||||||
const GET_ALIAS_ENDPOINT = "/api/v1/get/alias";
|
const LOGIN_ENDPOINT = "/login";
|
||||||
const ADD_ALIAS_ENDPOINT = "/api/v1/add/alias";
|
const GET_ALIAS_ENDPOINT = "/get/alias";
|
||||||
|
const ADD_ALIAS_ENDPOINT = "/add/alias";
|
||||||
|
|
||||||
|
// Check if user is logged in
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
const storedSession = await browser.storage.local.get("session");
|
||||||
|
if (storedSession.session) {
|
||||||
|
showEmailForm();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("login").addEventListener("click", async () => {
|
||||||
|
const username = document.getElementById("username").value;
|
||||||
|
const password = document.getElementById("password").value;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(API_BASE + LOGIN_ENDPOINT, {
|
||||||
|
method: "POST",
|
||||||
|
credentials: "include",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ username, password })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) throw new Error("Login failed");
|
||||||
|
|
||||||
|
await browser.storage.local.set({ session: true });
|
||||||
|
showEmailForm();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
alert("Login error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("logout").addEventListener("click", async () => {
|
||||||
|
await browser.storage.local.remove("session");
|
||||||
|
showLoginForm();
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("fetch").addEventListener("click", async () => {
|
document.getElementById("fetch").addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(API_BASE + GET_ALIAS_ENDPOINT, {
|
const response = await fetch(API_BASE + GET_ALIAS_ENDPOINT, {
|
||||||
credentials: "include" // Ensures the request uses the user's Mailcow session
|
credentials: "include"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) throw new Error("Failed to fetch emails");
|
if (!response.ok) throw new Error("Failed to fetch emails");
|
||||||
|
@ -15,49 +51,4 @@ document.getElementById("fetch").addEventListener("click", async () => {
|
||||||
if (aliases.length > 0) {
|
if (aliases.length > 0) {
|
||||||
const latestEmail = aliases[0].address;
|
const latestEmail = aliases[0].address;
|
||||||
document.getElementById("email").value = latestEmail;
|
document.getElementById("email").value = latestEmail;
|
||||||
} else {
|
}
|
||||||
document.getElementById("email").value = "No temp email found";
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
alert("Error fetching email");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById("generate").addEventListener("click", async () => {
|
|
||||||
const emailPrefix = "temp" + Date.now();
|
|
||||||
const domain = "paxcia.net";
|
|
||||||
const newEmail = `${emailPrefix}@${domain}`;
|
|
||||||
|
|
||||||
const requestData = {
|
|
||||||
address: newEmail,
|
|
||||||
goto: "your_main@paxcia.net", // Redirect emails to your main inbox
|
|
||||||
active: true
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(API_BASE + ADD_ALIAS_ENDPOINT, {
|
|
||||||
method: "POST",
|
|
||||||
credentials: "include", // Uses session login
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
body: JSON.stringify(requestData)
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) throw new Error("Failed to generate email");
|
|
||||||
|
|
||||||
document.getElementById("email").value = newEmail;
|
|
||||||
alert("New email created: " + newEmail);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
alert("Error creating email");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById("copy").addEventListener("click", () => {
|
|
||||||
const emailField = document.getElementById("email");
|
|
||||||
emailField.select();
|
|
||||||
document.execCommand("copy");
|
|
||||||
alert("Copied: " + emailField.value);
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue