<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Material Notes</title>
<style>
:root {
--primary-color: #6200ee;
--primary-variant: #3700b3;
--secondary-color: #03dac6;
--background: #f5f5f5;
--surface: #ffffff;
--error: #b00020;
--on-primary: #ffffff;
--on-secondary: #000000;
--on-background: #000000;
--on-surface: #000000;
--on-error: #ffffff;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', Arial, sans-serif;
}
body {
background-color: var(--background);
color: var(--on-background);
}
.app-container {
display: flex;
flex-direction: column;
height: 100vh;
}
/* Header styles */
.header {
background-color: var(--primary-color);
color: var(--on-primary);
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
z-index: 10;
}
.header h1 {
font-size: 20px;
font-weight: 500;
}
.search-container {
position: relative;
flex-grow: 1;
margin: 0 16px;
}
.search-container input {
width: 100%;
padding: 8px 12px 8px 40px;
border: none;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.2);
color: var(--on-primary);
outline: none;
transition: background-color 0.3s;
}
.search-container input:focus {
background-color: rgba(255, 255, 255, 0.3);
}
.search-container i {
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
color: var(--on-primary);
opacity: 0.8;
}
/* Main content styles */
.main-content {
display: flex;
flex-grow: 1;
overflow: hidden;
}
.sidebar {
width: 240px;
background-color: var(--surface);
box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
overflow-y: auto;
z-index: 5;
}
.sidebar-item {
display: flex;
align-items: center;
padding: 12px 16px;
cursor: pointer;
transition: background-color 0.2s;
}
.sidebar-item:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.sidebar-item.active {
background-color: rgba(98, 0, 238, 0.1);
color: var(--primary-color);
}
.sidebar-item i {
margin-right: 16px;
opacity: 0.7;
}
.notes-container {
flex-grow: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.toolbar {
background-color: var(--surface);
padding: 8px 16px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
}
.toolbar button {
background: none;
border: none;
border-radius: 4px;
padding: 8px 12px;
margin-right: 8px;
cursor: pointer;
color: var(--on-surface);
transition: background-color 0.2s;
display: flex;
align-items: center;
font-size: 14px;
}
.toolbar button:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.toolbar button i {
margin-right: 6px;
}
.toolbar button.active {
background-color: rgba(98, 0, 238, 0.1);
color: var(--primary-color);
}
.content-area {
flex-grow: 1;
padding: 16px;
overflow-y: auto;
position: relative;
}
/* Notes grid */
.notes-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 16px;
padding-bottom: 80px;
}
.note-card {
background-color: var(--surface);
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
padding: 16px;
cursor: pointer;
transition: box-shadow 0.3s;
overflow: hidden;
position: relative;
}
.note-card:hover {
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.note-card h3 {
margin-bottom: 8px;
font-size: 16px;
font-weight: 500;
}
.note-card p {
font-size: 14px;
color: rgba(0, 0, 0, 0.7);
display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
overflow: hidden;
}
.note-card .note-footer {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 12px;
font-size: 12px;
color: rgba(0, 0, 0, 0.5);
}
/* Add note FAB */
.fab {
position: fixed;
right: 24px;
bottom: 24px;
width: 56px;
height: 56px;
border-radius: 50%;
background-color: var(--primary-color);
color: var(--on-primary);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
z-index: 100;
}
.fab:hover {
background-color: var(--primary-variant);
transform: scale(1.05);
}
/* Note editor */
.note-editor {
display: none;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--surface);
z-index: 10;
padding: 16px;
flex-direction: column;
}
.note-editor.active {
display: flex;
}
.note-editor-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.note-editor-header button {
background: none;
border: none;
color: var(--primary-color);
cursor: pointer;
padding: 8px;
border-radius: 4px;
}
.note-editor-header button:hover {
background-color: rgba(98, 0, 238, 0.1);
}
.note-editor input {
border: none;
outline: none;
font-size: 18px;
font-weight: 500;
margin-bottom: 16px;
width: 100%;
}
.editor-tabs {
display: flex;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
margin-bottom: 16px;
}
.editor-tab {
padding: 8px 16px;
cursor: pointer;
color: rgba(0, 0, 0, 0.6);
position: relative;
}
.editor-tab.active {
color: var(--primary-color);
}
.editor-tab.active::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
right: 0;
height: 2px;
background-color: var(--primary-color);
}
.editor-content {
flex-grow: 1;
overflow-y: auto;
}
.editor-content > div {
display: none;
height: 100%;
}
.editor-content > div.active {
display: block;
}
#text-editor {
width: 100%;
height: 100%;
border: none;
resize: none;
font-size: 16px;
line-height: 1.5;
outline: none;
}
/* Canvas for drawing */
#drawing-canvas {
width: 100%;
height: 100%;
background-color: white;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 4px;
touch-action: none;
}
.drawing-tools {
display: flex;
margin-bottom: 16px;
align-items: center;
}
.drawing-tools button {
background: none;
border: none;
cursor: pointer;
padding: 8px;
border-radius: 4px;
margin-right: 8px;
}
.drawing-tools button:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.drawing-tools button.active {
background-color: rgba(98, 0, 238, 0.1);
color: var(--primary-color);
}
.drawing-tools input[type="color"] {
width: 36px;
height: 36px;
border: none;
padding: 0;
background: none;
cursor: pointer;
}
.drawing-tools select {
padding: 6px;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 4px;
background-color: white;
}
/* Task list */
.task-list {
list-style: none;
}
.task-item {
display: flex;
align-items: center;
padding: 8px 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}
.task-checkbox {
margin-right: 12px;
width: 20px;
height: 20px;
accent-color: var(--primary-color);
}
.task-text {
flex-grow: 1;
font-size: 16px;
border: none;
outline: none;
background: none;
}
.task-completed .task-text {
text-decoration: line-through;
color: rgba(0, 0, 0, 0.4);
}
.add-task-btn {
margin-top: 16px;
padding: 8px 16px;
background-color: rgba(98, 0, 238, 0.1);
color: var(--primary-color);
border: none;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
}
.add-task-btn i {
margin-right: 8px;
}
/* Audio recorder */
.audio-controls {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 24px;
}
.record-btn {
width: 64px;
height: 64px;
border-radius: 50%;
background-color: var(--error);
color: var(--on-error);
border: none;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
margin-bottom: 16px;
}
.record-btn.recording {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
.recordings-list {
width: 100%;
margin-top: 24px;
}
.recording-item {
display: flex;
align-items: center;
padding: 12px;
background-color: white;
border-radius: 8px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
margin-bottom: 8px;
}
.recording-item button {
background: none;
border: none;
cursor: pointer;
margin-right: 12px;
color: var(--primary-color);
}
.recording-item .recording-name {
flex-grow: 1;
font-size: 14px;
}
.recording-item .recording-duration {
font-size: 12px;
color: rgba(0, 0, 0, 0.5);
margin-right: 8px;
}
/* Material icons */
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v139/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
</head>
<body>
<div class="app-container">
<!-- Header -->
<header class="header">
<h1>Material Notes</h1>
<div class="search-container">
<i class="material-icons">search</i>
<input type="text" id="search-input" placeholder="Search your notes">
</div>
<i class="material-icons" id="menu-btn">menu</i>
</header>
<!-- Main content -->
<div class="main-content">
<!-- Sidebar -->
<div class="sidebar">
<div class="sidebar-item active">
<i class="material-icons">note</i>
<span>Notes</span>
</div>
<div class="sidebar-item">
<i class="material-icons">check_circle</i>
<span>Tasks</span>
</div>
<div class="sidebar-item">
<i class="material-icons">brush</i>
<span>Drawings</span>
</div>
<div class="sidebar-item">
<i class="material-icons">mic</i>
<span>Recordings</span>
</div>
<div class="sidebar-item">
<i class="material-icons">delete</i>
<span>Trash</span>
</div>
</div>
<!-- Notes container -->
<div class="notes-container">
<div class="toolbar">
<button class="active">
<i class="material-icons">view_module</i>
Grid view
</button>
<button>
<i class="material-icons">view_list</i>
List view
</button>
<button>
<i class="material-icons">sort</i>
Sort
</button>
</div>
<!-- Content area -->
<div class="content-area">
<div class="notes-grid" id="notes-grid">
<!-- Notes will be added here by JavaScript -->
</div>
<!-- Note editor -->
<div class="note-editor" id="note-editor">
<div class="note-editor-header">
<button id="back-btn">
<i class="material-icons">arrow_back</i>
</button>
<button id="save-btn">
<i class="material-icons">save</i>
Save
</button>
</div>
<input type="text" id="note-title" placeholder="Title">
<div class="editor-tabs">
<div class="editor-tab active" data-tab="text">Text</div>
<div class="editor-tab" data-tab="drawing">Drawing</div>
<div class="editor-tab" data-tab="tasks">Tasks</div>
<div class="editor-tab" data-tab="audio">Audio</div>
</div>
<div class="editor-content">
<!-- Text editor -->
<div id="text-tab" class="active">
<textarea id="text-editor" placeholder="Start typing..."></textarea>
</div>
<!-- Drawing editor -->
<div id="drawing-tab">
<div class="drawing-tools">
<button id="pen-tool" class="active">
<i class="material-icons">create</i>
</button>
<button id="eraser-tool">
<i class="material-icons">delete</i>
</button>
<button id="clear-canvas">
<i class="material-icons">clear</i>
</button>
<input type="color" id="color-picker" value="#000000">
<select id="stroke-width">
<option value="1">Thin</option>
<option value="3" selected>Normal</option>
<option value="5">Thick</option>
<option value="10">Very Thick</option>
</select>
</div>
<canvas id="drawing-canvas"></canvas>
</div>
<!-- Task list editor -->
<div id="tasks-tab">
<ul class="task-list" id="task-list">
<!-- Tasks will be added here by JavaScript -->
</ul>
<button class="add-task-btn" id="add-task-btn">
<i class="material-icons">add</i>
Add task
</button>
</div>
<!-- Audio recorder -->
<div id="audio-tab">
<div class="audio-controls">
<button class="record-btn" id="record-btn">
<i class="material-icons">mic</i>
</button>
<span id="recording-status">Click to start recording</span>
<div id="recording-time"></div>
</div>
<div class="recordings-list" id="recordings-list">
<!-- Recordings will be added here by JavaScript -->
</div>
</div>
</div>
</div>
</div>
<!-- Floating action button -->
<div class="fab" id="add-note-btn">
<i class="material-icons">add</i>
</div>
</div>
</div>
</div>
<script>
// DOM Elements
const notesGrid = document.getElementById('notes-grid');
const noteEditor = document.getElementById('note-editor');
const addNoteBtn = document.getElementById('add-note-btn');
const backBtn = document.getElementById('back-btn');
const saveBtn = document.getElementById('save-btn');
const noteTitle = document.getElementById('note-title');
const textEditor = document.getElementById('text-editor');
const searchInput = document.getElementById('search-input');
const editorTabs = document.querySelectorAll('.editor-tab');
const editorContents = document.querySelectorAll('.editor-content > div');
const canvas = document.getElementById('drawing-canvas');
const ctx = canvas.getContext('2d');
const colorPicker = document.getElementById('color-picker');
const strokeWidth = document.getElementById('stroke-width');
const penTool = document.getElementById('pen-tool');
const eraserTool = document.getElementById('eraser-tool');
const clearCanvas = document.getElementById('clear-canvas');
const taskList = document.getElementById('task-list');
const addTaskBtn = document.getElementById('add-task-btn');
const recordBtn = document.getElementById('record-btn');
const recordingStatus = document.getElementById('recording-status');
const recordingTime = document.getElementById('recording-time');
const recordingsList = document.getElementById('recordings-list');
// App state
let notes = JSON.parse(localStorage.getItem('notes')) || [];
let currentNoteId = null;
let isDrawing = false;
let lastX = 0;
let lastY = 0;
let tasks = [];
let mediaRecorder = null;
let audioChunks = [];
let recordings = [];
let recordingStartTime = null;
let recordingTimer = null;
let isRecording = false;
// Initialize app
function init() {
renderNotes();
setupCanvas();
setupEventListeners();
}
// Event listeners
function setupEventListeners() {
// Add note button
addNoteBtn.addEventListener('click', createNewNote);
// Back button
backBtn.addEventListener('click', closeEditor);
// Save button
saveBtn.addEventListener('click', saveNote);
// Editor tabs
editorTabs.forEach(tab => {
tab.addEventListener('click', () => switchTab(tab.dataset.tab));
});
// Search input
searchInput.addEventListener('input', filterNotes);
// Drawing event listeners
canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);
canvas.addEventListener('mouseout', stopDrawing);
canvas.addEventListener('touchstart', handleTouch);
canvas.addEventListener('touchmove', handleTouch);
canvas.addEventListener('touchend', stopDrawing);
// Drawing tools
penTool.addEventListener('click', () => {
penTool.classList.add('active');
eraserTool.classList.remove('active');
});
eraserTool.addEventListener('click', () => {
eraserTool.classList.add('active');
penTool.classList.remove('active');
});
clearCanvas.addEventListener('click', clearCanvasAction);
// Task list
addTaskBtn.addEventListener('click', addNewTask);
// Audio recording
recordBtn.addEventListener('click', toggleRecording);
// Resize canvas when window resizes
window.addEventListener('resize', resizeCanvas);
}
// Render notes
function renderNotes() {
notesGrid.innerHTML = '';
if (notes.length === 0) {
notesGrid.innerHTML = '<p class="no-notes">No notes yet. Click the + button to create one!</p>';
return;
}
notes.forEach(note => {
const noteCard = document.createElement('div');
noteCard.classList.add('note-card');
noteCard.innerHTML = `
<h3>${note.title || 'Untitled'}</h3>
<p>${getPreviewContent(note)}</p>
<div class="note-footer">
<span>${new Date(note.lastModified).toLocaleDateString()}</span>
<span>${note.type}</span>
</div>
`;
noteCard.addEventListener('click', () => openNote(note.id));
notesGrid.appendChild(noteCard);
});
}
// Get preview content based on note type
function getPreviewContent(note) {
switch (note.type) {
case 'text':
return note.content.substring(0, 100) + (note.content.length > 100 ? '...' : '');
case 'drawing':
return 'Drawing';
case 'tasks':
return `${note.tasks.filter(task => task.completed).length}/${note.tasks.length} tasks completed`;
case 'audio':
return `${note.recordings.length} audio recording(s)`;
default:
return '';
}
}
// Create new note
function createNewNote() {
currentNoteId = Date.now().toString();
noteTitle.value = '';
textEditor.value = '';
tasks = [];
recordings = [];
clearCanvasAction();
renderTaskList();
renderRecordings();
switchTab('text');
noteEditor.classList.add('active');
}
// Open existing note
function openNote(id) {
const note = notes.find(note => note.id === id);
if (!note) return;
currentNoteId = id;
noteTitle.value = note.title || '';
textEditor.value = note.content || '';
// Load tasks if available
tasks = note.tasks ? [...note.tasks] : [];
renderTaskList();
// Load recordings if available
recordings = note.recordings ? [...note.recordings] : [];
renderRecordings();
// Load drawing if available
if (note.drawing) {
const img = new Image();
img.onload = function() {
clearCanvasAction();
ctx.drawImage(img, 0, 0);
};
img.src = note.drawing;
} else {
clearCanvasAction();
}
switchTab(note.type || 'text');
noteEditor.classList.add('active');
}
// Close editor
function closeEditor() {
noteEditor.classList.remove('active');
}
// Save note
function saveNote() {
const activeTab = document.querySelector('.editor-tab.active').dataset.tab;
let noteContent = '';
let noteTasks = [];
let noteDrawing = '';
let noteRecordings = [];
switch (activeTab) {
case 'text':
noteContent = textEditor.value;
break;
case 'tasks':
noteTasks = [...tasks];
break;
case 'drawing':
noteDrawing = canvas.toDataURL('image/png');
break;
case 'audio':
noteRecordings = [...recordings];
break;
}
const note = {
id: currentNoteId,
title: noteTitle.value,
content: noteContent,
tasks: noteTasks,
drawing: noteDrawing,
recordings: noteRecordings,
type: activeTab,
lastModified: Date.now()
};
const existingNoteIndex = notes.findIndex(n => n.id === currentNoteId);
if (existingNoteIndex !== -1) {
notes[existingNoteIndex] = note;
} else {
notes.push(note);
}
localStorage.setItem('notes', JSON.stringify(notes));
renderNotes();
closeEditor();
}
// Switch tabs
function switchTab(tabName) {
editorTabs.forEach(tab => {
if (tab.dataset.tab === tabName) {
tab.classList.add('active');
} else {
tab.classList.remove('active');
}
});
editorContents.forEach(content => {
if (content.id === `${tabName}-tab`) {
content.classList.add('active');
} else {
content.classList.remove('active');
}
});
if (tabName === 'drawing') {
resizeCanvas();
}
}
// Filter notes by search term
function filterNotes() {
const searchTerm = searchInput.value.toLowerCase();
const filteredNotes = searchTerm === '' ? notes : notes.filter(note => {
return (
(note.title && note.title.toLowerCase().includes(searchTerm)) ||
(note.content && note.content.toLowerCase().includes(searchTerm)) ||
(note.tasks && note.tasks.some(task => task.text.toLowerCase().includes(searchTerm)))
);
});
renderFilteredNotes(filteredNotes);
}
// Render filtered notes
function renderFilteredNotes(filteredNotes) {
notesGrid.innerHTML = '';
if (filteredNotes.length === 0) {
notesGrid.innerHTML = '<p class="no-notes">No matching notes found.</p>';
return;
}
filteredNotes.forEach(note => {
const noteCard = document.createElement('div');
noteCard.classList.add('note-card');
noteCard.innerHTML = `
<h3>${note.title || 'Untitled'}</h3>
<p>${getPreviewContent(note)}</p>
<div class="note-footer">
<span>${new Date(note.lastModified).toLocaleDateString()}</span>
<span>${note.type}</span>
</div>
`;
noteCard.addEventListener('click', () => openNote(note.id));
notesGrid.appendChild(noteCard);
});
}
// Drawing functions
function setupCanvas() {
resizeCanvas();
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
}
function resizeCanvas() {
const canvasContainer = document.getElementById('drawing-tab');
canvas.width = canvasContainer.clientWidth;
canvas.height = canvasContainer.clientHeight - 60; // Subtract toolbar height
}
function startDrawing(e) {
isDrawing = true;
[lastX, lastY] = [e.offsetX, e.offsetY];
}
function draw(e) {
if (!isDrawing) return;
ctx.beginPath();
ctx.moveTo(lastX, lastY);
ctx.lineTo(e.offsetX, e.offsetY);
if (eraserTool.classList.contains('active')) {
ctx.strokeStyle = 'white';
ctx.lineWidth = parseInt(strokeWidth.value) * 3;
} else {
ctx.strokeStyle = colorPicker.value;
ctx.lineWidth = parseInt(strokeWidth.value);
}
ctx.stroke();
[lastX, lastY] = [e.offsetX, e.offsetY];
}
function stopDrawing() {
isDrawing = false;
}
function handleTouch(e) {
e.preventDefault();
const touch = e.touches[0];
const rect = canvas.getBoundingClientRect();
const offsetX = touch.clientX - rect.left;
const offsetY = touch.clientY - rect.top;
const mouseEvent = new MouseEvent(
e.type === 'touchstart' ? 'mousedown' : 'mousemove',
{
clientX: touch.clientX,
clientY: touch.clientY
}
);
mouseEvent.offsetX = offsetX;
mouseEvent.offsetY = offsetY;
if (e.type === 'touchstart') {
startDrawing(mouseEvent);
} else {
draw(mouseEvent);
}
}
function clearCanvasAction() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
// Task list functions
function addNewTask() {
tasks.push({
id: Date.now().toString(),
text: '',
completed: false
});
renderTaskList();
// Focus the last task added
const lastTaskInput = document.querySelector('.task-item:last-child .task-text');
if (lastTaskInput) {
lastTaskInput.focus();
}
}
function renderTaskList() {
taskList.innerHTML = '';
tasks.forEach(task => {
const taskItem = document.createElement('li');
taskItem.classList.add('task-item');
if (task.completed) {
taskItem.classList.add('task-completed');
}
taskItem.innerHTML = `
<input type="checkbox" class="task-checkbox" ${task.completed ? 'checked' : ''}>
<input type="text" class="task-text" value="${task.text}" placeholder="Task description">
<button class="task-delete">
<i class="material-icons">close</i>
</button>
`;
const checkbox = taskItem.querySelector('.task-checkbox');
checkbox.addEventListener('change', () => {
task.completed = checkbox.checked;
if (checkbox.checked) {
taskItem.classList.add('task-completed');
} else {
taskItem.classList.remove('task-completed');
}
});
const textInput = taskItem.querySelector('.task-text');
textInput.addEventListener('input', () => {
task.text = textInput.value;
});
const deleteBtn = taskItem.querySelector('.task-delete');
deleteBtn.addEventListener('click', () => {
tasks = tasks.filter(t => t.id !== task.id);
renderTaskList();
});
taskList.appendChild(taskItem);
});
}
// Audio recording functions
function toggleRecording() {
if (isRecording) {
stopRecording();
} else {
startRecording();
}
}
function startRecording() {
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
mediaRecorder = new MediaRecorder(stream);
audioChunks = [];
mediaRecorder.ondataavailable = e => {
audioChunks.push(e.data);
};
mediaRecorder.onstop = () => {
const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
const audioUrl = URL.createObjectURL(audioBlob);
const recording = {
id: Date.now().toString(),
url: audioUrl,
blob: audioBlob,
name: `Recording ${recordings.length + 1}`,
duration: formatRecordingTime(Date.now() - recordingStartTime)
};
recordings.push(recording);
renderRecordings();
// Stop all tracks in the stream
stream.getTracks().forEach(track => track.stop());
};
mediaRecorder.start();
isRecording = true;
recordBtn.classList.add('recording');
recordingStatus.textContent = 'Recording...';
// Start recording timer
recordingStartTime = Date.now();
updateRecordingTime();
recordingTimer = setInterval(updateRecordingTime, 1000);
})
.catch(err => {
console.error('Error accessing microphone:', err);
alert('Unable to access microphone. Please check permissions.');
});
} else {
alert('Audio recording is not supported in this browser.');
}
}
function stopRecording() {
if (mediaRecorder && isRecording) {
mediaRecorder.stop();
isRecording = false;
recordBtn.classList.remove('recording');
recordingStatus.textContent = 'Click to start recording';
// Stop recording timer
clearInterval(recordingTimer);
recordingTime.textContent = '';
}
}
function updateRecordingTime() {
const elapsed = Date.now() - recordingStartTime;
recordingTime.textContent = formatRecordingTime(elapsed);
}
function formatRecordingTime(ms) {
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
}
function renderRecordings() {
recordingsList.innerHTML = '';
recordings.forEach(recording => {
const recordingItem = document.createElement('div');
recordingItem.classList.add('recording-item');
recordingItem.innerHTML = `
<button class="play-btn">
<i class="material-icons">play_arrow</i>
</button>
<span class="recording-name">${recording.name}</span>
<span class="recording-duration">${recording.duration}</span>
<button class="delete-recording">
<i class="material-icons">delete</i>
</button>
`;
const playBtn = recordingItem.querySelector('.play-btn');
playBtn.addEventListener('click', () => {
const audio = new Audio(recording.url);
audio.play();
// Toggle play/pause icon
const icon = playBtn.querySelector('i');
icon.textContent = 'pause';
audio.onended = () => {
icon.textContent = 'play_arrow';
};
audio.onpause = () => {
icon.textContent = 'play_arrow';
};
playBtn.onclick = () => {
if (audio.paused) {
audio.play();
icon.textContent = 'pause';
} else {
audio.pause();
icon.textContent = 'play_arrow';
}
};
});
const deleteBtn = recordingItem.querySelector('.delete-recording');
deleteBtn.addEventListener('click', () => {
recordings = recordings.filter(r => r.id !== recording.id);
renderRecordings();
});
recordingsList.appendChild(recordingItem);
});
}
// Initialize the app
init();
</script>
</body>
</html>
Would you like me to explain how this code works? I've created a full-featured note-taking app with Material Design principles that includes all the features you requested:
- Text notes
- Drawing with a pen tool
- Task management with checkboxes
- Audio recording and playback
- Search functionality
- Material UI design elements
The app uses local storage to save notes, so they'll persist between sessions on the same browser.