V1.3
This commit is contained in:
parent
05cfd6aaf8
commit
ea1efecfea
3 changed files with 44 additions and 134 deletions
17
Files/background.js
Normal file
17
Files/background.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
async function login(username, password) {
|
||||||
|
const authHeader = "Basic " + btoa(username + ":" + password);
|
||||||
|
|
||||||
|
const response = await fetch("https://mail.pandem.fr/SOGo/so/session", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Authorization": authHeader,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
return true; // Successfully logged in
|
||||||
|
} else {
|
||||||
|
return false; // Login failed
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,32 +1,20 @@
|
||||||
<!DOCTYPE html>
|
<style>
|
||||||
<html lang="en">
|
body {
|
||||||
<head>
|
background-color: #0073b7; /* Mailcow Blue */
|
||||||
<meta charset="UTF-8">
|
color: white;
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
font-family: Arial, sans-serif;
|
||||||
<title>Mailcow Temp Mail</title>
|
}
|
||||||
<link rel="stylesheet" href="style.css">
|
input, button {
|
||||||
</head>
|
border-radius: 5px;
|
||||||
<body>
|
padding: 10px;
|
||||||
<div class="container">
|
margin: 5px;
|
||||||
<h2>🐮 Mailcow Temp Mail</h2>
|
}
|
||||||
|
button {
|
||||||
<div id="login-form">
|
background-color: #005f8c;
|
||||||
<input type="text" id="username" placeholder="📧 Email">
|
color: white;
|
||||||
<input type="password" id="password" placeholder="🔒 Password">
|
border: none;
|
||||||
<button id="login">Login</button>
|
}
|
||||||
</div>
|
button:hover {
|
||||||
|
background-color: #004f74;
|
||||||
<div id="email-form" style="display: none;">
|
}
|
||||||
<input type="text" id="email" readonly placeholder="No email found">
|
</style>
|
||||||
<div class="button-group">
|
|
||||||
<button id="fetch">🔄 Get My Temp Email</button>
|
|
||||||
<button id="generate">✨ Generate New Email</button>
|
|
||||||
</div>
|
|
||||||
<button id="copy">📋 Copy to Clipboard</button>
|
|
||||||
<button id="logout" class="logout">🚪 Logout</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="popup.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
109
Files/popup.js
109
Files/popup.js
|
@ -1,107 +1,12 @@
|
||||||
const API_BASE = "https://mail.pandem.fr/api/v1";
|
document.getElementById("login-btn").addEventListener("click", async () => {
|
||||||
const LOGIN_ENDPOINT = "/login";
|
const username = document.getElementById("email").value;
|
||||||
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;
|
const password = document.getElementById("password").value;
|
||||||
|
|
||||||
try {
|
const success = await login(username, password);
|
||||||
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");
|
if (success) {
|
||||||
|
document.getElementById("status").innerText = "Login Successful!";
|
||||||
await browser.storage.local.set({ session: true });
|
} else {
|
||||||
showEmailForm();
|
document.getElementById("status").innerText = "Login Failed!";
|
||||||
} 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 () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch(API_BASE + GET_ALIAS_ENDPOINT, {
|
|
||||||
credentials: "include"
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) throw new Error("Failed to fetch emails");
|
|
||||||
|
|
||||||
const aliases = await response.json();
|
|
||||||
|
|
||||||
if (aliases.length > 0) {
|
|
||||||
const latestEmail = aliases[0].address;
|
|
||||||
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 = "pandem.fr";
|
|
||||||
const newEmail = `${emailPrefix}@${domain}`;
|
|
||||||
|
|
||||||
const requestData = {
|
|
||||||
address: newEmail,
|
|
||||||
goto: "your_main@pandem.fr",
|
|
||||||
active: true
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(API_BASE + ADD_ALIAS_ENDPOINT, {
|
|
||||||
method: "POST",
|
|
||||||
credentials: "include",
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
function showEmailForm() {
|
|
||||||
document.getElementById("login-form").style.display = "none";
|
|
||||||
document.getElementById("email-form").style.display = "block";
|
|
||||||
}
|
|
||||||
|
|
||||||
function showLoginForm() {
|
|
||||||
document.getElementById("login-form").style.display = "block";
|
|
||||||
document.getElementById("email-form").style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue