Below is an all-in-one HTML file that implements a sleek dark mode diary app. It features a large text area for writing your diary entry, an option to attach a picture (using a file input), and a built-in audio recorder (using the MediaRecorder API) so you can record and attach audio. Simply copy and paste the code into an HTML file and open it in a modern browser.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dark Mode Diary App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Global style reset */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: #121212;
color: #f1f1f1;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
#app {
background-color: #1e1e1e;
border-radius: 8px;
padding: 20px;
max-width: 600px;
width: 100%;
box-shadow: 0 4px 8px rgba(0,0,0,0.6);
}
h1 {
text-align: center;
margin-bottom: 20px;
font-size: 2rem;
letter-spacing: 1px;
}
textarea {
width: 100%;
height: 150px;
resize: vertical;
border: none;
border-radius: 5px;
padding: 10px;
background-color: #2a2a2a;
color: #fff;
font-size: 1rem;
outline: none;
margin-bottom: 15px;
}
.inputs {
display: flex;
flex-direction: column;
gap: 15px;
margin-bottom: 15px;
}
/* Custom file upload button */
.photo {
position: relative;
}
.photo input[type="file"] {
display: none;
}
.photo label {
display: inline-block;
padding: 10px 15px;
background-color: #3a3a3a;
border-radius: 5px;
cursor: pointer;
text-align: center;
transition: background-color 0.3s ease;
}
.photo label:hover {
background-color: #555;
}
.audio {
display: flex;
flex-direction: column;
gap: 10px;
}
.audio button {
padding: 10px;
border: none;
border-radius: 5px;
background-color: #3a3a3a;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}
.audio button:hover:not(:disabled) {
background-color: #555;
}
.audio button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
#saveEntry {
width: 100%;
padding: 12px;
background-color: #007acc;
border: none;
color: #fff;
border-radius: 5px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
#saveEntry:hover {
background-color: #005fa3;
}
.preview {
margin-top: 10px;
}
.preview img {
max-width: 100%;
border-radius: 5px;
margin-top: 5px;
}
</style>
</head>
<body>
<div id="app">
<h1>My Dark Diary</h1>
<textarea id="diaryText" placeholder="Write something heartfelt..."></textarea>
<div class="inputs">
<!-- Picture Input -->
<div class="photo">
<label for="photoInput">Attach Picture</label>
<input type="file" id="photoInput" accept="image/*">
<div class="preview" id="photoPreview"></div>
</div>
<!-- Audio Recording -->
<div class="audio">
<button id="startRecording">Start Recording Audio</button>
<button id="stopRecording" disabled>Stop Recording</button>
<audio id="audioPlayback" controls></audio>
</div>
</div>
<button id="saveEntry">Save Diary Entry</button>
</div>
<script>
// Handle image preview
const photoInput = document.getElementById("photoInput");
const photoPreview = document.getElementById("photoPreview");
photoInput.addEventListener("change", function(event) {
photoPreview.innerHTML = "";
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.createElement("img");
img.src = e.target.result;
photoPreview.appendChild(img);
}
reader.readAsDataURL(file);
}
});
// Audio recording with MediaRecorder API
let mediaRecorder;
let audioChunks = [];
let audioBlob = null;
const startBtn = document.getElementById("startRecording");
const stopBtn = document.getElementById("stopRecording");
const audioPlayback = document.getElementById("audioPlayback");
startBtn.addEventListener("click", async () => {
// Request permission and start recording
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
audioChunks = [];
mediaRecorder.addEventListener("dataavailable", event => {
if (event.data.size > 0) {
audioChunks.push(event.data);
}
});
mediaRecorder.addEventListener("stop", () => {
audioBlob = new Blob(audioChunks, { type: "audio/webm" });
const audioURL = URL.createObjectURL(audioBlob);
audioPlayback.src = audioURL;
});
mediaRecorder.start();
startBtn.disabled = true;
stopBtn.disabled = false;
} catch (error) {
console.error("Audio recording error:", error);
alert("Unable to access microphone. Please check your browser settings.");
}
});
stopBtn.addEventListener("click", () => {
if (mediaRecorder && mediaRecorder.state !== "inactive") {
mediaRecorder.stop();
startBtn.disabled = false;
stopBtn.disabled = true;
}
});
// Save the diary entry
document.getElementById("saveEntry").addEventListener("click", () => {
const diaryText = document.getElementById("diaryText").value;
const photoFile = photoInput.files[0];
// Here we build an entry object. In a full app, you could store this entry in localStorage or send it to a server.
const diaryEntry = {
text: diaryText,
photo: null,
audio: null,
timestamp: new Date().toISOString()
};
// Convert the image file (if any) to a Data URL
if (photoFile) {
const reader = new FileReader();
reader.onload = function(e) {
diaryEntry.photo = e.target.result;
finalizeEntry(diaryEntry);
}
reader.readAsDataURL(photoFile);
} else {
finalizeEntry(diaryEntry);
}
});
function finalizeEntry(entry) {
// Attach the audio Blob URL if exists
if (audioBlob) {
entry.audio = URL.createObjectURL(audioBlob);
}
console.log("Diary Entry Saved:", entry);
alert("Diary entry saved! Check the console for details.");
// Clear the form for a new entry
document.getElementById("diaryText").value = "";
photoInput.value = "";
photoPreview.innerHTML = "";
audioPlayback.src = "";
audioBlob = null;
}
</script>
</body>
</html>
This code runs fully in your browser and can be extended further (for example, to persist entries to a server or local storage) as needed. Enjoy your sleek dark mode diary app!