Here's a sleek dark mode diary app with multimodal input capabilities. This code combines HTML, CSS, and JavaScript in one file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dark Mode Diary</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: #1a1a1a;
color: #ffffff;
min-height: 100vh;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
padding: 20px 0;
border-bottom: 2px solid #333;
}
.new-entry {
margin: 20px 0;
background-color: #2d2d2d;
padding: 20px;
border-radius: 10px;
}
.input-group {
margin: 15px 0;
}
.input-group label {
display: block;
margin-bottom: 5px;
color: #b3b3b3;
}
input[type="text"],
textarea {
width: 100%;
padding: 10px;
background-color: #333;
border: none;
border-radius: 5px;
color: #ffffff;
font-size: 16px;
}
textarea {
height: 150px;
resize: vertical;
}
.media-buttons {
display: flex;
gap: 10px;
margin: 15px 0;
}
.media-btn {
padding: 10px 20px;
background-color: #4a4a4a;
border: none;
border-radius: 5px;
color: #ffffff;
cursor: pointer;
transition: background-color 0.3s;
}
.media-btn:hover {
background-color: #666;
}
.save-btn {
background-color: #4CAF50;
width: 100%;
padding: 12px;
border: none;
border-radius: 5px;
color: white;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.save-btn:hover {
background-color: #45a049;
}
.entries-container {
margin-top: 30px;
}
.entry {
background-color: #2d2d2d;
padding: 20px;
margin: 15px 0;
border-radius: 10px;
}
.entry-header {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: #b3b3b3;
}
.media-preview {
margin: 10px 0;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.media-preview img {
max-width: 200px;
border-radius: 5px;
}
.audio-preview {
width: 100%;
}
.delete-btn {
background-color: #ff4444;
padding: 5px 10px;
border: none;
border-radius: 3px;
color: white;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Dark Mode Diary</h1>
</div>
<div class="new-entry">
<div class="input-group">
<label>Title</label>
<input type="text" id="entry-title" placeholder="Enter title...">
</div>
<div class="input-group">
<label>Content</label>
<textarea id="entry-content" placeholder="Write your thoughts..."></textarea>
</div>
<div class="media-buttons">
<button class="media-btn" onclick="document.getElementById('image-input').click()">
📷 Add Photo
</button>
<button class="media-btn" id="record-btn">🎤 Record Audio</button>
</div>
<input type="file" id="image-input" accept="image/*" style="display: none">
<div id="media-preview" class="media-preview"></div>
<button class="save-btn" onclick="saveEntry()">Save Entry</button>
</div>
<div class="entries-container" id="entries-container">
<!-- Entries will be added here -->
</div>
</div>
<script>
let isRecording = false;
let mediaRecorder;
let audioChunks = [];
let entries = [];
// Handle image upload
document.getElementById('image-input').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.createElement('img');
img.src = e.target.result;
document.getElementById('media-preview').appendChild(img);
}
reader.readAsDataURL(file);
}
});
// Handle audio recording
const recordBtn = document.getElementById('record-btn');
recordBtn.addEventListener('click', async () => {
if (!isRecording) {
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = (e) => {
audioChunks.push(e.data);
};
mediaRecorder.onstop = () => {
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
const audioUrl = URL.createObjectURL(audioBlob);
const audio = document.createElement('audio');
audio.src = audioUrl;
audio.controls = true;
audio.classList.add('audio-preview');
document.getElementById('media-preview').appendChild(audio);
};
mediaRecorder.start();
isRecording = true;
recordBtn.textContent = '⏹️ Stop Recording';
} catch (err) {
console.error('Error accessing microphone:', err);
}
} else {
mediaRecorder.stop();
isRecording = false;
recordBtn.textContent = '🎤 Record Audio';
audioChunks = [];
}
});
function saveEntry() {
const title = document.getElementById('entry-title').value;
const content = document.getElementById('entry-content').value;
const mediaPreview = document.getElementById('media-preview').innerHTML;
const date = new Date().toLocaleDateString();
if (!title || !content) {
alert('Please fill in both title and content!');
return;
}
const entry = {
title,
content,
media: mediaPreview,
date
};
entries.unshift(entry);
displayEntries();
clearForm();
}
function displayEntries() {
const container = document.getElementById('entries-container');
container.innerHTML = '';
entries.forEach((entry, index) => {
const entryElement = document.createElement('div');
entryElement.classList.add('entry');
entryElement.innerHTML = `
<div class="entry-header">
<span>${entry.date}</span>
<button class="delete-btn" onclick="deleteEntry(${index})">Delete</button>
</div>
<h2>${entry.title}</h2>
<p>${entry.content}</p>
<div class="media-preview">
${entry.media}
</div>
`;
container.appendChild(entryElement);
});
}
function clearForm() {
document.getElementById('entry-title').value = '';
document.getElementById('entry-content').value = '';
document.getElementById('media-preview').innerHTML = '';
}
function deleteEntry(index) {
if (confirm('Are you sure you want to delete this entry?')) {
entries.splice(index, 1);
displayEntries();
}
}
</script>
</body>
</html>
This code creates a diary app with the following features:
- Dark mode interface
- Title and content input
- Image upload capability
- Audio recording functionality
- Entry saving and display
- Entry deletion
- Responsive design
- Date tracking for entries
To use the app:
- Enter a title and content for your diary entry
- Click "Add Photo" to upload images
- Click "Record Audio" to record and attach audio clips
- Click "Save Entry" to save your entry
- Entries are displayed below the input form
- You can delete entries using the delete button
Note: For the audio recording to work, you'll need to run this on a secure context (HTTPS) or localhost, as modern browsers require this for accessing the microphone.
The app stores entries in memory, so they'll be lost when you refresh the page. For persistence, you'd need to add local storage or a backend database.