305 lines
8 KiB
HTML
305 lines
8 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8" />
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
|
<title>Direct Message</title>
|
||
|
|
<style>
|
||
|
|
body {
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
align-items: center;
|
||
|
|
padding-top: 50px;
|
||
|
|
min-height: 120vh;
|
||
|
|
margin: 0;
|
||
|
|
font-family: Arial, sans-serif;
|
||
|
|
background-color: #111;
|
||
|
|
}
|
||
|
|
|
||
|
|
#fractal-canvas {
|
||
|
|
position: fixed;
|
||
|
|
top: 0;
|
||
|
|
left: 0;
|
||
|
|
width: 100%;
|
||
|
|
height: 100%;
|
||
|
|
z-index: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.form-container {
|
||
|
|
position: relative;
|
||
|
|
z-index: 1;
|
||
|
|
background-color: rgba(0, 0, 0, 0.7);
|
||
|
|
color: #fff;
|
||
|
|
padding: 30px;
|
||
|
|
border-radius: 8px;
|
||
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
|
||
|
|
width: 90%;
|
||
|
|
max-width: 800px;
|
||
|
|
min-height: 400px;
|
||
|
|
max-height: 1000px;
|
||
|
|
margin-bottom: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
nav.directory {
|
||
|
|
position: relative;
|
||
|
|
z-index: 1;
|
||
|
|
width: 90%;
|
||
|
|
max-width: 800px;
|
||
|
|
margin: 0 auto;
|
||
|
|
text-align: center;
|
||
|
|
}
|
||
|
|
|
||
|
|
nav.directory dt a {
|
||
|
|
text-decoration: none;
|
||
|
|
color: #fff;
|
||
|
|
padding: 0.5rem 1rem;
|
||
|
|
display: inline-block;
|
||
|
|
background: rgba(0, 0, 0, 0.3);
|
||
|
|
border-radius: 4px;
|
||
|
|
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
|
||
|
|
transition: background 0.2s;
|
||
|
|
}
|
||
|
|
|
||
|
|
nav.directory dt a:hover {
|
||
|
|
background: rgba(0, 0, 0, 0.5);
|
||
|
|
}
|
||
|
|
|
||
|
|
.input-group {
|
||
|
|
margin-bottom: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
label {
|
||
|
|
display: block;
|
||
|
|
margin-bottom: 5px;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
|
||
|
|
input[type="text"],
|
||
|
|
input[type="password"] {
|
||
|
|
width: 100%;
|
||
|
|
padding: 8px;
|
||
|
|
border: 1px solid #555;
|
||
|
|
border-radius: 4px;
|
||
|
|
box-sizing: border-box;
|
||
|
|
background: rgba(255, 255, 255, 0.1);
|
||
|
|
color: #fff;
|
||
|
|
}
|
||
|
|
|
||
|
|
textarea {
|
||
|
|
width: 100%;
|
||
|
|
height: 120px;
|
||
|
|
padding: 8px;
|
||
|
|
border: 1px solid #555;
|
||
|
|
border-radius: 4px;
|
||
|
|
resize: vertical;
|
||
|
|
box-sizing: border-box;
|
||
|
|
background: rgba(255, 255, 255, 0.1);
|
||
|
|
color: #fff;
|
||
|
|
}
|
||
|
|
|
||
|
|
.expandable-section {
|
||
|
|
margin-top: 20px;
|
||
|
|
}
|
||
|
|
.expandable-header {
|
||
|
|
cursor: pointer;
|
||
|
|
padding: 10px;
|
||
|
|
background-color: rgba(255, 255, 255, 0.1);
|
||
|
|
border-radius: 4px;
|
||
|
|
}
|
||
|
|
.expandable-content {
|
||
|
|
display: none;
|
||
|
|
padding: 10px;
|
||
|
|
background-color: rgba(255, 255, 255, 0.05);
|
||
|
|
border-radius: 0 0 4px 4px;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
<script src="/routes/contact/pkg/message_tools.js"></script>
|
||
|
|
<script>
|
||
|
|
const { make_salt, make_key_bytes, box_message } = wasm_bindgen;
|
||
|
|
var serverPublicKey;
|
||
|
|
|
||
|
|
async function run() {
|
||
|
|
await wasm_bindgen();
|
||
|
|
await fetchPublicKey();
|
||
|
|
|
||
|
|
const form = document.getElementById("message-form");
|
||
|
|
form.addEventListener("submit", (event) => {
|
||
|
|
event.preventDefault();
|
||
|
|
submit();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
async function fetchPublicKey() {
|
||
|
|
try {
|
||
|
|
const response = await fetch("/api/pubkey");
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const pubkeyJSON = await response.text();
|
||
|
|
serverPublicKey = JSON.parse(pubkeyJSON);
|
||
|
|
} catch (error) {
|
||
|
|
console.error("Error fetching public key:", error);
|
||
|
|
document.getElementById("status").textContent =
|
||
|
|
"Failed to load public key.";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async function submit() {
|
||
|
|
const user = document.getElementById("name").value;
|
||
|
|
const password = document.getElementById("password").value;
|
||
|
|
const message = document.getElementById("message").value;
|
||
|
|
|
||
|
|
const salt = make_salt();
|
||
|
|
|
||
|
|
const makeKeyBytesArgs = {
|
||
|
|
name: String(user),
|
||
|
|
password: String(password),
|
||
|
|
salt: [...salt],
|
||
|
|
};
|
||
|
|
|
||
|
|
const keyBytes = make_key_bytes(JSON.stringify(makeKeyBytesArgs));
|
||
|
|
|
||
|
|
const boxMessageArgs = {
|
||
|
|
user: String(user),
|
||
|
|
salt: [...salt],
|
||
|
|
user_sk: [...keyBytes],
|
||
|
|
remote_pk: [...serverPublicKey],
|
||
|
|
plaintext: String(message),
|
||
|
|
};
|
||
|
|
const boxed = box_message(JSON.stringify(boxMessageArgs));
|
||
|
|
const boxedObj = JSON.parse(boxed);
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch("/api/publish", {
|
||
|
|
method: "POST",
|
||
|
|
headers: {
|
||
|
|
"Content-Type": "application/json",
|
||
|
|
},
|
||
|
|
body: JSON.stringify(boxedObj),
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const result = await response.json();
|
||
|
|
alert("Sent!");
|
||
|
|
location.reload();
|
||
|
|
} catch (error) {
|
||
|
|
console.error("Error:", error);
|
||
|
|
alert("Failed to send message: " + error.message);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
run();
|
||
|
|
</script>
|
||
|
|
<script>
|
||
|
|
function toggleSection() {
|
||
|
|
const content = document.getElementById("expandableContent");
|
||
|
|
const header = document.querySelector(".expandable-header");
|
||
|
|
if (content.style.display === "block") {
|
||
|
|
content.style.display = "none";
|
||
|
|
header.innerHTML = "How to use ▼";
|
||
|
|
} else {
|
||
|
|
content.style.display = "block";
|
||
|
|
header.innerHTML = "How to use ▲";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<canvas id="fractal-canvas"></canvas>
|
||
|
|
|
||
|
|
<div class="form-container">
|
||
|
|
<form id="message-form">
|
||
|
|
<div class="input-group">
|
||
|
|
<label for="name">Name</label>
|
||
|
|
<input type="text" id="name" name="name" />
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="input-group">
|
||
|
|
<label for="password">Password (optional)</label>
|
||
|
|
<input type="password" id="password" name="password" />
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="input-group">
|
||
|
|
<label for="message">Message</label>
|
||
|
|
<textarea id="message" name="message"></textarea>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="input-group">
|
||
|
|
<button
|
||
|
|
type="submit"
|
||
|
|
style="
|
||
|
|
width: 100%;
|
||
|
|
padding: 10px;
|
||
|
|
background-color: rgba(255, 255, 255, 0.15);
|
||
|
|
color: #fff;
|
||
|
|
border: 1px solid #555;
|
||
|
|
border-radius: 4px;
|
||
|
|
cursor: pointer;
|
||
|
|
"
|
||
|
|
>
|
||
|
|
Submit
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
|
||
|
|
<div class="expandable-section">
|
||
|
|
<div class="expandable-header" onclick="toggleSection()">
|
||
|
|
How to use ▼
|
||
|
|
</div>
|
||
|
|
<div class="expandable-content" id="expandableContent">
|
||
|
|
<p>
|
||
|
|
Tell me who you are, and add an optional password. If I do not
|
||
|
|
otherwise have your contact information, please tell me the best way
|
||
|
|
to reach you back.
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<nav class="directory">
|
||
|
|
<dt><a href="/contact">back to contact</a></dt>
|
||
|
|
</nav>
|
||
|
|
|
||
|
|
<script src="/routes/root/pkg/fractal_engine.js"></script>
|
||
|
|
<script>
|
||
|
|
(async function() {
|
||
|
|
await wasm_bindgen('/routes/root/pkg/fractal_engine_bg.wasm');
|
||
|
|
|
||
|
|
const canvas = document.getElementById('fractal-canvas');
|
||
|
|
|
||
|
|
function resizeCanvas() {
|
||
|
|
canvas.width = window.innerWidth;
|
||
|
|
canvas.height = window.innerHeight;
|
||
|
|
}
|
||
|
|
|
||
|
|
resizeCanvas();
|
||
|
|
window.addEventListener('resize', resizeCanvas);
|
||
|
|
|
||
|
|
let startTime = performance.now();
|
||
|
|
const animationSpeed = 0.0001;
|
||
|
|
const scale = 4;
|
||
|
|
|
||
|
|
function animate() {
|
||
|
|
const elapsed = performance.now() - startTime;
|
||
|
|
const time = elapsed * animationSpeed;
|
||
|
|
|
||
|
|
try {
|
||
|
|
wasm_bindgen.render_fractal_animated('fractal-canvas', time, scale);
|
||
|
|
} catch (e) {
|
||
|
|
console.error('Fractal render error:', e);
|
||
|
|
}
|
||
|
|
|
||
|
|
requestAnimationFrame(animate);
|
||
|
|
}
|
||
|
|
|
||
|
|
animate();
|
||
|
|
})();
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|