File size: 21,850 Bytes
2d8ab1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | <!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ملاحظاتي | تطبيق الملاحظات الشخصية</title>
<!-- استيراد خط Cairo و مكتبة أيقونات FontAwesome -->
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/*
* إعدادات المتغيرات والألوان (Color Palette)
* تصميم Minimal بألوان هادئة (بنفسجي فاتح وأبيض)
*/
:root {
--primary-color: #6c5ce7; /* بنفسجي رئيسي */
--primary-hover: #5649c0; /* لون التفاعل */
--bg-color: #f3f4f6; /* خلفية الصفحة */
--card-bg: #ffffff; /* خلفية البطاقة */
--text-main: #2d3436; /* النص الأساسي */
--text-secondary: #636e72; /* النص الثانوي */
--danger-color: #ff7675; /* لون الحذف */
--shadow-sm: 0 2px 5px rgba(0,0,0,0.05);
--shadow-md: 0 5px 15px rgba(0,0,0,0.08);
--radius: 16px; /* حواف دائرية */
--transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
outline: none;
}
body {
font-family: 'Cairo', system-ui, -apple-system, sans-serif;
background-color: var(--bg-color);
color: var(--text-main);
line-height: 1.6;
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* --- الهيدر وشريط البحث --- */
header {
background: var(--card-bg);
padding: 1.5rem 2rem;
box-shadow: var(--shadow-sm);
position: sticky;
top: 0;
z-index: 100;
backdrop-filter: blur(10px);
background: rgba(255, 255, 255, 0.9);
}
.header-content {
max-width: 1200px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.logo {
font-size: 1.8rem;
font-weight: 700;
color: var(--primary-color);
display: flex;
align-items: center;
gap: 0.5rem;
}
.search-container {
position: relative;
flex-grow: 1;
max-width: 400px;
}
.search-input {
width: 100%;
padding: 0.8rem 1rem 0.8rem 2.5rem;
border: 2px solid #e0e0e0;
border-radius: 50px;
font-family: inherit;
font-size: 1rem;
transition: var(--transition);
}
.search-input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
}
.search-icon {
position: absolute;
left: 15px;
top: 50%;
transform: translateY(-50%);
color: var(--text-secondary);
}
.actions {
display: flex;
gap: 10px;
}
.btn {
padding: 0.6rem 1.2rem;
border: none;
border-radius: 12px;
cursor: pointer;
font-family: inherit;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
transition: var(--transition);
font-size: 0.9rem;
}
.btn-primary {
background-color: var(--primary-color);
color: white;
box-shadow: 0 4px 10px rgba(108, 92, 231, 0.3);
}
.btn-primary:hover {
background-color: var(--primary-hover);
transform: translateY(-2px);
}
.btn-danger {
background-color: #fff0f0;
color: var(--danger-color);
border: 1px solid #ffe0e0;
}
.btn-danger:hover {
background-color: var(--danger-color);
color: white;
}
/* --- حاوية الملاحظات (Grid) --- */
.container {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1.5rem;
flex-grow: 1;
width: 100%;
}
.notes-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1.5rem;
}
/* --- بطاقة الملاحظة --- */
.note-card {
background: var(--card-bg);
border-radius: var(--radius);
padding: 1.5rem;
box-shadow: var(--shadow-sm);
transition: var(--transition);
position: relative;
display: flex;
flex-direction: column;
border: 1px solid transparent;
animation: fadeIn 0.4s ease-out forwards;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.note-card:hover {
transform: translateY(-5px);
box-shadow: var(--shadow-md);
border-color: rgba(108, 92, 231, 0.1);
}
.note-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 1rem;
}
.note-title {
font-size: 1.2rem;
font-weight: 700;
color: var(--text-main);
word-break: break-word;
}
.note-date {
font-size: 0.75rem;
color: var(--text-secondary);
background: #f0f0f0;
padding: 0.2rem 0.6rem;
border-radius: 20px;
white-space: nowrap;
}
.note-content {
color: var(--text-secondary);
font-size: 0.95rem;
margin-bottom: 1.5rem;
white-space: pre-wrap; /* للحفاظ على الأسطر الجديدة */
display: -webkit-box;
-webkit-line-clamp: 5; /* عرض 5 أسطر فقط */
-webkit-box-orient: vertical;
overflow: hidden;
flex-grow: 1;
}
.note-actions {
display: flex;
justify-content: flex-end;
gap: 0.5rem;
border-top: 1px solid #f0f0f0;
padding-top: 1rem;
}
.icon-btn {
background: none;
border: none;
cursor: pointer;
font-size: 1rem;
padding: 0.5rem;
border-radius: 8px;
transition: var(--transition);
color: var(--text-secondary);
}
.icon-btn:hover {
background-color: #f3f4f6;
color: var(--primary-color);
}
.icon-btn.delete:hover {
color: var(--danger-color);
background-color: #fff0f0;
}
/* --- حالة عدم وجود ملاحظات --- */
.empty-state {
text-align: center;
padding: 4rem 1rem;
color: var(--text-secondary);
display: none; /* مخفي افتراضياً */
}
.empty-state i {
font-size: 4rem;
color: #dfe6e9;
margin-bottom: 1rem;
}
.empty-state h3 {
font-size: 1.5rem;
margin-bottom: 0.5rem;
color: var(--text-main);
}
/* --- النافذة المنبثقة (Modal) --- */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: var(--transition);
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal {
background: var(--card-bg);
width: 90%;
max-width: 500px;
border-radius: 20px;
padding: 2rem;
transform: scale(0.9);
transition: var(--transition);
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal-overlay.active .modal {
transform: scale(1);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.modal-title {
font-size: 1.4rem;
font-weight: 700;
}
.close-modal {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--text-secondary);
}
.form-group {
margin-bottom: 1.2rem;
}
.form-label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
font-size: 0.9rem;
}
.form-control {
width: 100%;
padding: 0.8rem;
border: 2px solid #e0e0e0;
border-radius: 12px;
font-family: inherit;
font-size: 1rem;
transition: var(--transition);
}
.form-control:focus {
border-color: var(--primary-color);
}
textarea.form-control {
resize: vertical;
min-height: 120px;
}
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 1rem;
margin-top: 1.5rem;
}
/* --- الفوتر --- */
footer {
text-align: center;
padding: 1.5rem;
color: var(--text-secondary);
font-size: 0.9rem;
margin-top: auto;
}
.anycoder-link {
color: var(--primary-color);
text-decoration: none;
font-weight: 700;
transition: color 0.2s;
}
.anycoder-link:hover {
color: var(--primary-hover);
text-decoration: underline;
}
/* --- التجاوب (Responsive) --- */
@media (max-width: 768px) {
.header-content {
flex-direction: column;
align-items: stretch;
}
.logo {
justify-content: center;
margin-bottom: 1rem;
}
.search-container {
max-width: 100%;
}
.actions {
justify-content: center;
}
.notes-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<!-- الهيدر -->
<header>
<div class="header-content">
<div class="logo">
<i class="fa-solid fa-note-sticky"></i>
ملاحظاتي
</div>
<div class="search-container">
<input type="text" id="searchInput" class="search-input" placeholder="ابحث في ملاحظاتك...">
<i class="fa-solid fa-search search-icon"></i>
</div>
<div class="actions">
<button class="btn btn-danger" onclick="clearAllNotes()">
<i class="fa-solid fa-trash-can"></i> مسح الكل
</button>
<button class="btn btn-primary" onclick="openModal()">
<i class="fa-solid fa-plus"></i> ملاحظة جديدة
</button>
</div>
</div>
</header>
<!-- المحتوى الرئيسي -->
<main class="container">
<!-- شبكة الملاحظات -->
<div id="notesGrid" class="notes-grid">
<!-- سيتم توليد الملاحظات هنا بواسطة JavaScript -->
</div>
<!-- رسالة الحالة الفارغة -->
<div id="emptyState" class="empty-state">
<i class="fa-regular fa-folder-open"></i>
<h3>لا توجد ملاحظات بعد</h3>
<p>ابدأ بإضافة ملاحظة جديدة لتوثيق أفكارك</p>
</div>
</main>
<!-- الفوتر -->
<footer>
<p>تم التطوير بواسطة <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">Built with anycoder</a></p>
</footer>
<!-- النافذة المنبثقة (Modal) -->
<div id="noteModal" class="modal-overlay">
<div class="modal">
<div class="modal-header">
<h2 class="modal-title" id="modalTitleText">ملاحظة جديدة</h2>
<button class="close-modal" onclick="closeModal()">×</button>
</div>
<div class="form-group">
<label class="form-label">العنوان</label>
<input type="text" id="noteTitle" class="form-control" placeholder="اكتب عنواناً جذاباً...">
</div>
<div class="form-group">
<label class="form-label">المحتوى</label>
<textarea id="noteContent" class="form-control" placeholder="اكتب تفاصيل ملاحظتك هنا..."></textarea>
</div>
<div class="modal-footer">
<button class="btn" style="background: #eee; color: #333;" onclick="closeModal()">إلغاء</button>
<button class="btn btn-primary" onclick="saveNote()">حفظ الملاحظة</button>
</div>
</div>
</div>
<script>
// --- متغيرات الحالة (State) ---
let notes = [];
let isEditing = false;
let currentEditId = null;
// --- عناصر DOM ---
const notesGrid = document.getElementById('notesGrid');
const emptyState = document.getElementById('emptyState');
const modal = document.getElementById('noteModal');
const modalTitleText = document.getElementById('modalTitleText');
const titleInput = document.getElementById('noteTitle');
const contentInput = document.getElementById('noteContent');
const searchInput = document.getElementById('searchInput');
// --- التهيئة عند التحميل ---
document.addEventListener('DOMContentLoaded', () => {
loadNotes();
renderNotes();
});
// --- الوظائف الأساسية (CRUD) ---
// 1. تحميل الملاحظات من LocalStorage
function loadNotes() {
const storedNotes = localStorage.getItem('myNotesApp_data');
if (storedNotes) {
notes = JSON.parse(storedNotes);
}
}
// 2. حفظ الملاحظات في LocalStorage
function saveToLocalStorage() {
localStorage.setItem('myNotesApp_data', JSON.stringify(notes));
renderNotes();
}
// 3. إضافة أو تعديل ملاحظة
function saveNote() {
const title = titleInput.value.trim();
const content = contentInput.value.trim();
if (!title && !content) {
alert('الرجاء كتابة عنوان أو محتوى للملاحظة');
return;
}
if (isEditing) {
// وضع التعديل
const noteIndex = notes.findIndex(n => n.id === currentEditId);
if (noteIndex !== -1) {
notes[noteIndex].title = title;
notes[noteIndex].content = content;
notes[noteIndex].lastModified = new Date().toISOString();
}
} else {
// وضع الإضافة
const newNote = {
id: Date.now(), // استخدام الوقت كمعرف فريد
title: title,
content: content,
createdAt: new Date().toISOString(),
lastModified: new Date().toISOString()
};
notes.unshift(newNote); // إضافة في البداية
}
saveToLocalStorage();
closeModal();
}
// 4. حذف ملاحظة
function deleteNote(id) {
if (confirm('هل أنت متأكد من حذف هذه الملاحظة؟')) {
notes = notes.filter(note => note.id !== id);
saveToLocalStorage();
}
}
// 5. حذف جميع الملاحظات
function clearAllNotes() {
if (notes.length === 0) return;
if (confirm('تحذير: سيتم حذف جميع الملاحظات نهائياً. هل أنت متأكد؟')) {
notes = [];
saveToLocalStorage();
}
}
// 6. البحث في الملاحظات
searchInput.addEventListener('input', (e) => {
const searchTerm = e.target.value.toLowerCase();
const filteredNotes = notes.filter(note =>
note.title.toLowerCase().includes(searchTerm) ||
note.content.toLowerCase().includes(searchTerm)
);
renderNotes(filteredNotes);
});
// --- وظائف العرض (UI) ---
// عرض الملاحظات
function renderNotes(notesArray = notes) {
notesGrid.innerHTML = '';
if (notesArray.length === 0) {
emptyState.style.display = 'block';
return;
} else {
emptyState.style.display = 'none';
}
// ترتيب الملاحظات: الأحدث أولاً
// ملاحظة: عند البحث لا نقوم بالترتيب الزمني بل نعرض النتائج
const notesToRender = notesArray === notes ? [...notesArray].sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)) : notesArray;
notesToRender.forEach(note => {
const dateObj = new Date(note.createdAt);
const dateStr = dateObj.toLocaleDateString('ar-EG', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
const noteCard = document.createElement('div');
noteCard.className = 'note-card';
noteCard.innerHTML = `
<div class="note-header">
<h3 class="note-title">${escapeHtml(note.title) || '<i>بدون عنوان</i>'}</h3>
<span class="note-date">${dateStr}</span>
</div>
<div class="note-content">${escapeHtml(note.content)}</div>
<div class="note-actions">
<button class="icon-btn" onclick="editNote(${note.id})" title="تعديل">
<i class="fa-solid fa-pen-to-square"></i>
</button>
<button class="icon-btn delete" onclick="deleteNote(${note.id})" title="حذف">
<i class="fa-solid fa-trash"></i>
</button>
</div>
`;
notesGrid.appendChild(noteCard);
});
}
// --- وظائف المودال (Modal) ---
function openModal() {
isEditing = false;
currentEditId = null;
modalTitleText.textContent = 'ملاحظة جديدة';
titleInput.value = '';
contentInput.value = '';
modal.classList.add('active');
titleInput.focus();
}
function closeModal() {
modal.classList.remove('active');
}
function editNote(id) {
const note = notes.find(n => n.id === id);
if (note) {
isEditing = true;
currentEditId = id;
modalTitleText.textContent = 'تعديل الملاحظة';
titleInput.value = note.title;
contentInput.value = note.content;
modal.classList.add('active');
}
}
// إغلاق المودال عند النقر خارج الصندوق
modal.addEventListener('click', (e) => {
if (e.target === modal) {
closeModal();
}
});
// دالة مساعدة لمنع حقن HTML (Security)
function escapeHtml(text) {
if (!text) return '';
return text
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
</script>
</body>
</html> |