Spaces:
Running
Running
Update index.html
Browse files10 unmodified lines111213141516207 unmodified lines22422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329486 unmodified lines38138238338438538638738838964 unmodified lines45445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648714 unmodified lines50250350450550650750850951051151251351451551651751851952052152217 unmodified lines54054154254354454554654754854955055155255355455555615 unmodified lines5725735745755765775785795805815825835845855865875889 unmodified lines598599600601602603604605606203 unmodified lines810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920108 unmodified lines1029103010311032103310341035103610371038103910402 unmodified lines10431044104510461047104810496 unmodified lines10561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108514 unmodified lines1100110111021103110411051106110711081109111011113 unmodified lines1115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119110 unmodified linesSupabase (قاعدة بيانات حقيقية + تسجيل دخول حقيقي - مجاني)============================================================= --><script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/dist/umd/supabase.js"></script><style>:root{207 unmodified lines.rating-row .star.filled{color:var(--accent-2);}.rating-row .rating-summary{color:var(--muted); font-size:12px; margin-inline-start:8px;}/* ---------- Highlights & Comments (new) ---------- */.modal-section{margin-top:20px; padding-top:16px; border-top:1px solid var(--border); text-align:start;}.modal-section h4{margin:0 0 10px; font-size:13px; color:var(--muted); font-weight:700;}.add-highlight-row, .add-comment-row{display:flex; flex-direction:column; gap:8px; margin-bottom:14px;}.add-highlight-row textarea, .add-comment-row textarea{width:100%; min-height:60px; padding:10px 12px; border-radius:10px; border:1px solid var(--border);background:var(--bg); color:var(--text); font-family:inherit; font-size:13.5px; resize:vertical;}.highlight-item{background:var(--accent-soft); border-radius:10px; padding:10px 12px; margin-bottom:8px; font-size:13px;}.highlight-item p{margin:0 0 6px; font-style:italic; line-height:1.6;}.comment-item{border-bottom:1px solid var(--border); padding:10px 0; font-size:13px;}.comment-item:last-child{border-bottom:none;}.comment-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:3px; gap:8px;}.comment-item p{margin:0; line-height:1.7;}.mini-del{border:none; background:none; color:var(--muted); cursor:pointer; font-size:12px; font-family:inherit; flex-shrink:0;}.mini-del:hover{color:var(--accent);}/* ---------- Confetti (new) ---------- */@keyframes confetti-fall{0%{ transform:translateY(0) rotate(0deg); opacity:1; }100%{ transform:translateY(105vh) rotate(560deg); opacity:0; }}/* ---------- Reader ---------- */.reader-overlay{position:fixed; inset:0; background:var(--bg); z-index:50; display:flex; flex-direction:column;}.reader-overlay[hidden]{display:none;}.reader-topbar{background:var(--bg-elevated); border-bottom:1px solid var(--border); padding:12px 16px;display:flex; align-items:center; justify-content:space-between; gap:10px;}.reader-topbar .rt-side{font-size:12px; color:var(--muted); flex:1;}.reader-topbar .rt-side.rt-end{text-align:end;}.reader-topbar .rt-center{font-weight:700; font-size:14px; color:var(--accent); white-space:nowrap;}.reader-back{border:none; background:none; font-size:16px; color:var(--text); cursor:pointer; padding:0 4px;}.reader-page{flex:1; overflow-y:auto; padding:28px 22px 100px; max-width:640px; margin:0 auto; width:100%;}.reader-page .rp-chapter{font-size:12px; color:var(--accent); font-weight:700; margin-bottom:10px;}.reader-page .rp-text{font-size:16.5px; line-height:2.3;}html[data-lang="ar"] .reader-page .rp-text{font-family:'Amiri', serif;}.reader-nav{position:fixed; bottom:74px; inset-inline:0; display:flex; justify-content:space-between; padding:0 16px; pointer-events:none;}.reader-nav button{pointer-events:auto; width:42px; height:42px; border-radius:50%; border:1px solid var(--border);background:var(--bg-elevated); box-shadow:var(--shadow); cursor:pointer; font-size:16px; color:var(--text);}.reader-bottombar{background:var(--bg-elevated); border-top:1px solid var(--border);display:grid; grid-template-columns:repeat(4,1fr); z-index:51;}.reader-bottombar button{border:none; background:none; padding:10px 4px 12px; display:flex; flex-direction:column;align-items:center; gap:4px; font-size:10.5px; color:var(--text); cursor:pointer; font-family:inherit;}.reader-bottombar button .rb-icon{font-size:18px;}.reader-note-box{position:fixed; bottom:74px; inset-inline:0; background:var(--bg-elevated); border-top:1px solid var(--border);padding:14px 16px; display:flex; flex-direction:column; gap:8px; z-index:55;}.reader-note-box[hidden]{display:none;}.reader-note-box textarea{width:100%; min-height:60px; padding:10px 12px; border-radius:10px; border:1px solid var(--border);background:var(--bg); color:var(--text); font-family:inherit; font-size:13.5px; resize:vertical;}.reader-note-box .rnb-actions{display:flex; gap:8px;}.reader-note-box .rnb-actions .btn{margin:0;}.toc-overlay{position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:60; display:flex; align-items:flex-end; justify-content:center;}.toc-overlay[hidden]{display:none;}.toc-panel{background:var(--bg-elevated); width:100%; max-width:480px; border-radius:18px 18px 0 0; padding:20px 20px 26px; max-height:70vh; overflow-y:auto;}.toc-panel-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;}.toc-panel-head h4{margin:0; font-size:15px;}.toc-item{display:flex; justify-content:space-between; padding:12px 2px; border-bottom:1px solid var(--border); cursor:pointer; font-size:14px;}.toc-item:hover{color:var(--accent);}.toc-item span.tp{color:var(--muted); font-size:12px;}.toast{position:fixed; bottom:96px; left:50%; transform:translateX(-50%); background:var(--text); color:var(--bg);padding:10px 20px; border-radius:20px; font-size:13px; z-index:80; opacity:0; pointer-events:none; transition:opacity .25s; white-space:nowrap;}.toast.show{opacity:1;}86 unmodified lines<section class="tab-panel" id="homeTab"><div class="section-head"><h2 class="display" data-t="homeTitle">اختيارات لك اليوم</h2><div class="grid" id="homeGrid"></div></section>64 unmodified lines<div class="modal" id="bookModal"></div></div><div class="toast" id="toast"></div><!-- IN-APP READER (PDF stays inside the app) --><div class="reader-overlay" id="readerOverlay" hidden><div class="reader-topbar"><button class="reader-back" onclick="closeReader()">✕</button><div class="rt-center" id="readerTitle">—</div><button class="reader-back" onclick="openInNewTab()">↗</button></div><iframe id="readerFrame" title="book" style="flex:1; width:100%; border:none; background:#fff;"></iframe><div class="reader-note-box" id="readerNoteBox" hidden><textarea id="readerNoteInput" data-t-ph="highlightPlaceholder" placeholder="اكتب مقطعًا تريد تمييزه أو ملاحظة..."></textarea><div class="rnb-actions"><button class="btn primary" onclick="saveReaderNote()"><span data-t="saveHighlightBtn">💾 حفظ التأشير</span></button><button class="btn" onclick="toggleReaderNoteBox()"><span data-t="cancelBtn">إلغاء</span></button></div></div><div class="reader-bottombar"><button onclick="closeReader()"><span class="rb-icon">⬅</span><span data-t="backBtn">رجوع</span></button><button onclick="toggleReaderNoteBox()"><span class="rb-icon">✎</span><span data-t="highlightBtnShort">تأشير</span></button><button onclick="readerToggleRead()"><span class="rb-icon">📖</span><span id="readerReadLabel">—</span></button><button onclick="openInNewTab()"><span class="rb-icon">↗</span><span data-t="openExternalBtn">خارجيًا</span></button></div></div></div></div><script>/* =========================================================================إعدادات الاتصال بـ Supabase========================================================================= */14 unmodified lines});}/* ---------------- Categories (يمكن لاحقًا سحبها من جدول categories) ---------------- */const CATEGORIES = [{key:'literature', ar:'أدب', en:'Literature', color:'#0F5C4E'},{key:'religion', ar:'دين', en:'Religion', color:'#B9902E'},{key:'history', ar:'تاريخ', en:'History', color:'#7B2D26'},{key:'spelling', ar:'الإملاء', en:'Spelling', color:'#4C6B8A'},{key:'morphology', ar:'الصرف', en:'Morphology', color:'#6B4C6B'},];/* ---------------- الكتب — تُجلب حصرًا من قاعدة البيانات، لا يوجد بيانات وهمية ---------------- */let BOOKS = [];let ADHKAR = [];let RATINGS = [];let COMMENTS = []; // تعليقات الكتاب المفتوح حاليًاlet HIGHLIGHTS = []; // تأشيرات المستخدم الحالي على الكتاب المفتوح/* ---------------- Translations ---------------- */const I18N = {17 unmodified linesreadBtn:'📖 قراءة الكتاب', noPdfMsg:'لم يتم رفع ملف PDF لهذا الكتاب بعد',emptyLibrary:'المكتبة فارغة حاليًا', emptyLibraryDesc:'أضف كتبًا من لوحة تحكم المدير لتظهر هنا فورًا لجميع المستخدمين.',notConnected:'لم يتم الاتصال بقاعدة البيانات بعد', notConnectedDesc:'أضف بيانات Supabase أعلى ملف الكود لتفعيل الحسابات والكتب.',loading:'جارِ التحميل...',errInvalidCreds:'البريد الإلكتروني أو كلمة المرور غير صحيحة', errEmailTaken:'هذا البريد مستخدم بالفعل',errGeneric:'حدث خطأ، حاول مرة أخرى', errWeakPass:'كلمة المرور يجب أن تكون 6 أحرف على الأقل',checkEmailMsg:'تم إرسال رابط تأكيد إلى بريدك الإلكتروني', resetSentMsg:'تم إرسال رابط استعادة كلمة المرور إلى بريدك',needAccountMsg:'سجّل دخولك لحفظ المفضلة وسجل القراءة',highlightsLabel:'تأشيراتي', highlightPlaceholder:'اكتب مقطعًا تريد تمييزه أو ملاحظة...', saveHighlightBtn:'💾 حفظ التأشير',noHighlights:'لا توجد تأشيرات بعد',commentsLabel:'التعليقات', commentPlaceholder:'شارك رأيك حول الكتاب...', postCommentBtn:'📝 نشر التعليق',noComments:'لا توجد تعليقات بعد، كن أول من يعلق', deleteBtn:'حذف',backBtn:'رجوع', highlightBtnShort:'تأشير', openExternalBtn:'خارجيًا', cancelBtn:'إلغاء',highlightSavedMsg:'تم حفظ التأشير',},en:{appName:'Imam Al-Muttaqin Library', loginSubtitle:'Your Arabic library for reading and discovery',15 unmodified linesreadBtn:'📖 Read book', noPdfMsg:'No PDF has been uploaded for this book yet',emptyLibrary:'The library is empty right now', emptyLibraryDesc:'Add books from the admin dashboard and they will appear here instantly for every user.',notConnected:'Not connected to a database yet', notConnectedDesc:'Add your Supabase credentials at the top of the code to enable accounts and books.',loading:'Loading...',errInvalidCreds:'Incorrect email or password', errEmailTaken:'This email is already registered',errGeneric:'Something went wrong, please try again', errWeakPass:'Password must be at least 6 characters',checkEmailMsg:'A confirmation link has been sent to your email', resetSentMsg:'A password reset link has been sent to your email',needAccountMsg:'Log in to save favorites and reading history',highlightsLabel:'My Highlights', highlightPlaceholder:'Write a passage or note to save...', saveHighlightBtn:'💾 Save highlight',noHighlights:'No highlights yet',commentsLabel:'Comments', commentPlaceholder:'Share your thoughts about the book...', postCommentBtn:'📝 Post comment',noComments:'No comments yet, be the first', deleteBtn:'Delete',backBtn:'Back', highlightBtnShort:'Highlight', openExternalBtn:'External', cancelBtn:'Cancel',highlightSavedMsg:'Highlight saved',}};9 unmodified linesfunction catInfo(key){ return CATEGORIES.find(c=>c.key===key) || {ar:key, en:key, color:'#0F5C4E'}; }function t(key){ return I18N[state.lang][key] || key; }function escapeHtml(str){return (str||'').replace(/[&<>"']/g, m => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[m]));}/* ---------------- Auth: forms & tabs ---------------- */function switchAuthTab(mode){203 unmodified linesopenBookModal(id);}/* ---------------- التعليقات على الكتاب (جدول book_comments) ---------------- */async function loadComments(bookId){if(!CONFIGURED){ COMMENTS = []; return; }const { data, error } = await supabaseClient.from('book_comments').select('*').eq('book_id', bookId).order('created_at', { ascending:false });COMMENTS = error ? [] : (data || []);}function commentsListHtml(){if(!COMMENTS.length) return `<p class="drawer-empty">${t('noComments')}</p>`;return COMMENTS.map(c=>`<div class="comment-item"><div class="comment-head"><strong>${escapeHtml(c.user_name || '')}</strong>${(state.user && !state.isGuest && c.user_id===state.user.id)? `<button class="mini-del" onclick="deleteComment('${c.id}','${c.book_id}')">✕ ${t('deleteBtn')}</button>` : ''}</div><p>${escapeHtml(c.text)}</p></div>`).join('');}async function addComment(bookId){if(state.isGuest){ showToast(t('needAccountMsg')); return; }const input = document.getElementById('commentInput');if(!input) return;const text = input.value.trim();if(!text || !CONFIGURED || !state.user) return;await supabaseClient.from('book_comments').insert({book_id: bookId, user_id: state.user.id, user_name: state.user.name, text});input.value = '';await loadComments(bookId);const list = document.getElementById('commentsList');if(list) list.innerHTML = commentsListHtml();}async function deleteComment(commentId, bookId){if(!CONFIGURED) return;await supabaseClient.from('book_comments').delete().eq('id', commentId);await loadComments(bookId);const list = document.getElementById('commentsList');if(list) list.innerHTML = commentsListHtml();}/* ---------------- تأشيرات المستخدم على الكتاب (جدول book_highlights) ---------------- */async function loadHighlights(bookId){if(!CONFIGURED || !state.user || state.isGuest){ HIGHLIGHTS = []; return; }const { data, error } = await supabaseClient.from('book_highlights').select('*').eq('book_id', bookId).eq('user_id', state.user.id).order('created_at', { ascending:false });HIGHLIGHTS = error ? [] : (data || []);}function highlightsListHtml(){if(!HIGHLIGHTS.length) return `<p class="drawer-empty">${t('noHighlights')}</p>`;return HIGHLIGHTS.map(h=>`<div class="highlight-item"><p>"${escapeHtml(h.text)}"</p><button class="mini-del" onclick="deleteHighlight('${h.id}','${h.book_id}')">✕ ${t('deleteBtn')}</button></div>`).join('');}async function addHighlight(bookId){if(state.isGuest){ showToast(t('needAccountMsg')); return; }const input = document.getElementById('highlightInput');if(!input) return;const text = input.value.trim();if(!text || !CONFIGURED || !state.user) return;await supabaseClient.from('book_highlights').insert({book_id: bookId, user_id: state.user.id, text});input.value = '';await loadHighlights(bookId);const list = document.getElementById('highlightsList');if(list) list.innerHTML = highlightsListHtml();}async function deleteHighlight(id, bookId){if(!CONFIGURED) return;await supabaseClient.from('book_highlights').delete().eq('id', id);await loadHighlights(bookId);const list = document.getElementById('highlightsList');if(list) list.innerHTML = highlightsListHtml();}/* ---------------- احتفال 🎉 عند إنهاء قراءة كتاب ---------------- */function burstConfetti(){const colors = ['#0F5C4E','#B9902E','#7B2D26','#4C6B8A','#D4AF37'];const container = document.createElement('div');container.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:200;overflow:hidden;';document.body.appendChild(container);for(let i=0;i<60;i++){const piece = document.createElement('span');const size = 6 + Math.random()*6;piece.style.cssText = `position:absolute; top:-20px; left:${Math.random()*100}%;width:${size}px; height:${size*0.4}px; background:${colors[Math.floor(Math.random()*colors.length)]};opacity:${0.8+Math.random()*0.2}; transform:rotate(${Math.random()*360}deg);animation: confetti-fall ${1.6+Math.random()*1.4}s ease-in ${Math.random()*0.3}s forwards;`;container.appendChild(piece);}setTimeout(()=> container.remove(), 3200);}/* ---------------- تحميل مفضلة/سجل/علامات المستخدم من قاعدة البيانات ---------------- */async function loadUserData(){if(!CONFIGURED || !state.user || !state.user.id) return;108 unmodified lines<div class="book-author">${t('by')} ${b.author[state.lang]}</div></div>`;}async function openBookModal(id){const b = BOOKS.find(x=>String(x.id)===String(id));if(!b) return;await Promise.all([loadComments(b.id), loadHighlights(b.id)]);const info = catInfo(b.cat);const isFav = state.favorites.has(b.id);const isRead = state.history.has(b.id);2 unmodified linesconst starsHtml = [1,2,3,4,5].map(n=>`<span class="star ${n<=myRating?'filled':''}" onclick="rateBook('${b.id}', ${n})">★</span>`).join('');document.getElementById('bookModal').innerHTML = `<button class="modal-close" onclick="closeModal()">✕</button><div class="modal-cover" style="background:${b.color||info.color}">📕</div>6 unmodified lines<button class="btn ${isFav?'primary':''}" onclick="toggleFav('${b.id}')">${isFav?t('removeFav'):t('addFav')}</button><button class="btn ${isRead?'primary':''}" onclick="toggleRead('${b.id}')">${isRead?t('markedRead'):t('markRead')}</button>${state.isGuest ? `<p class="muted-line" style="margin:2px 0 0;">${t('needAccountMsg')}</p>` : ''}</div><div class="modal-section"><h4>${t('highlightsLabel')}</h4>${state.isGuest ? `<p class="muted-line" style="margin:0 0 10px;">${t('needAccountMsg')}</p>` : `<div class="add-highlight-row"><textarea id="highlightInput" placeholder="${t('highlightPlaceholder')}"></textarea><button class="btn" onclick="addHighlight('${b.id}')">${t('saveHighlightBtn')}</button></div>`}<div id="highlightsList">${highlightsListHtml()}</div></div><div class="modal-section"><h4>${t('commentsLabel')}</h4>${state.isGuest ? '' : `<div class="add-comment-row"><textarea id="commentInput" placeholder="${t('commentPlaceholder')}"></textarea><button class="btn" onclick="addComment('${b.id}')">${t('postCommentBtn')}</button></div>`}<div id="commentsList">${commentsListHtml()}</div></div>`;document.getElementById('modalOverlay').hidden = false;}function closeModal(){ document.getElementById('modalOverlay').hidden = true; }14 unmodified linesasync function toggleRead(id){if(state.isGuest){ showToast(t('needAccountMsg')); return; }const has = state.history.has(id);if(has){state.history.delete(id);} else {state.history.add(id);burstConfetti();}openBookModal(id); renderDrawerList();if(!CONFIGURED || !state.user) return;if(has){3 unmodified lines}}/* ---------------- القارئ الداخلي: الكتاب يبقى داخل التطبيق (بدون فتح تبويب جديد) ---------------- */let readerBookId = null;function readBook(id){const book = BOOKS.find(b=>String(b.id)===String(id));if(!book) return;if(!book.pdfUrl){ showToast(t('noPdfMsg')); return; }closeModal();openReader(id);}function openReader(id){const book = BOOKS.find(b=>String(b.id)===String(id));if(!book || !book.pdfUrl) return;readerBookId = id;document.getElementById('readerTitle').textContent = book.title[state.lang];document.getElementById('readerFrame').src = book.pdfUrl;document.getElementById('readerNoteBox').hidden = true;updateReaderReadLabel();document.getElementById('readerOverlay').hidden = false;if(CONFIGURED){supabaseClient.rpc('increment_book_views', { p_book_id: id }).then(()=>{});}}function closeReader(){document.getElementById('readerOverlay').hidden = true;document.getElementById('readerFrame').src = 'about:blank';readerBookId = null;}function openInNewTab(){const book = BOOKS.find(b=>String(b.id)===String(readerBookId));if(book && book.pdfUrl) window.open(book.pdfUrl, '_blank');}function toggleReaderNoteBox(){if(state.isGuest){ showToast(t('needAccountMsg')); return; }const box = document.getElementById('readerNoteBox');box.hidden = !box.hidden;if(!box.hidden){ document.getElementById('readerNoteInput').value = ''; document.getElementById('readerNoteInput').focus(); }}async function saveReaderNote(){if(state.isGuest){ showToast(t('needAccountMsg')); return; }const input = document.getElementById('readerNoteInput');const text = input.value.trim();if(!text || !CONFIGURED || !state.user || !readerBookId) return;await supabaseClient.from('book_highlights').insert({book_id: readerBookId, user_id: state.user.id, text});input.value = '';document.getElementById('readerNoteBox').hidden = true;showToast(t('highlightSavedMsg'));}async function readerToggleRead(){if(state.isGuest){ showToast(t('needAccountMsg')); return; }if(!readerBookId) return;const id = readerBookId;const has = state.history.has(id);if(has){ state.history.delete(id); }else { state.history.add(id); burstConfetti(); }updateReaderReadLabel();renderDrawerList();if(!CONFIGURED || !state.user) return;if(has){await supabaseClient.from('reading_history').delete().eq('user_id', state.user.id).eq('book_id', id);} else {await supabaseClient.from('reading_history').insert({ user_id: state.user.id, book_id: id });}}function updateReaderReadLabel(){const el = document.getElementById('readerReadLabel');if(!el || !readerBookId) return;el.textContent = state.history.has(readerBookId) ? t('markedRead') : t('markRead');}function showToast(msg){const el = document.getElementById('toast');10 unmodified lines1112131415161718207 unmodified lines22622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927086 unmodified lines35735835936036136236336436536664 unmodified lines43143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346414 unmodified lines47948048148248348448548648748817 unmodified lines50650750850951051151251351451551615 unmodified lines5325335345355365375385395405415429 unmodified lines552553554555556557203 unmodified lines761762763764765766108 unmodified lines8758768778788798808818828832 unmodified lines8868878888898908916 unmodified lines89889990090190290390414 unmodified lines9199209219229239249253 unmodified lines9299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210 unmodified linesSupabase (قاعدة بيانات حقيقية + تسجيل دخول حقيقي - مجاني)============================================================= --><script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/dist/umd/supabase.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script><script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.2/dist/confetti.browser.min.js"></script><style>:root{207 unmodified lines.rating-row .star.filled{color:var(--accent-2);}.rating-row .rating-summary{color:var(--muted); font-size:12px; margin-inline-start:8px;}/* ---------- Comments ---------- */.comments-section{border-top:1px solid var(--border); margin-top:6px; padding-top:14px; text-align:start;}.comments-section h4{margin:0 0 10px; font-size:13.5px; color:var(--muted);}.comments-list{max-height:180px; overflow-y:auto; margin-bottom:10px;}.comment-item{padding:8px 0; border-bottom:1px solid var(--border); font-size:13px;}.comment-item .c-name{font-weight:700; margin-inline-end:6px;}.comment-item .c-text{line-height:1.7; margin-top:2px;}.comments-empty{color:var(--muted); font-size:12.5px; padding:8px 0;}.comment-form{display:flex; gap:8px; align-items:flex-end;}.comment-form textarea{flex:1; min-height:44px; max-height:90px; padding:9px 12px; border-radius:10px; border:1px solid var(--border);background:var(--bg); color:var(--text); font-family:inherit; font-size:13px; resize:vertical;}.comment-form button{width:auto; padding:9px 16px; margin-bottom:0;}/* ---------- Reader (PDF + highlighting) ---------- */.reader-overlay{position:fixed; inset:0; background:#2b2b2b; z-index:50; display:flex; flex-direction:column;}.reader-overlay[hidden]{display:none;}.reader-topbar{background:var(--bg-elevated); border-bottom:1px solid var(--border); padding:10px 14px;display:flex; align-items:center; justify-content:space-between; gap:10px; flex-shrink:0;}.reader-topbar .rt-side{font-size:12px; color:var(--muted); flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}.reader-topbar .rt-center{font-weight:700; font-size:13px; color:var(--accent); white-space:nowrap;}.reader-back{border:none; background:none; font-size:16px; color:var(--text); cursor:pointer; padding:0 4px;}.reader-canvas-wrap{flex:1; overflow:auto; display:flex; align-items:flex-start; justify-content:center; padding:14px; position:relative;}.reader-canvas-inner{position:relative; margin:0 auto; box-shadow:0 6px 24px rgba(0,0,0,.35); background:#fff;}.reader-canvas-inner canvas{display:block; position:absolute; top:0; left:0;}#highlightCanvas{cursor:default;}#highlightCanvas.active{cursor:crosshair;}.reader-nav{position:fixed; bottom:80px; inset-inline:0; display:flex; justify-content:space-between; padding:0 16px; pointer-events:none;}.reader-nav button{pointer-events:auto; width:42px; height:42px; border-radius:50%; border:1px solid var(--border);background:var(--bg-elevated); box-shadow:var(--shadow); cursor:pointer; font-size:16px; color:var(--text);}.reader-bottombar{background:var(--bg-elevated); border-top:1px solid var(--border); flex-shrink:0;display:flex; align-items:center; justify-content:center; gap:6px; padding:8px 10px; flex-wrap:wrap;}.rb-btn{border:1px solid var(--border); background:var(--bg); border-radius:20px; padding:7px 12px;display:flex; align-items:center; gap:6px; font-size:12px; color:var(--text); cursor:pointer; font-family:inherit;}.rb-btn.active{background:var(--accent-soft); border-color:var(--accent);}.rb-dot{width:14px; height:14px; border-radius:50%; display:inline-block; border:1px solid rgba(0,0,0,.15);}/* ---------- Reader ---------- */.toast{position:fixed; bottom:96px; left:50%; transform:translateX(-50%); background:var(--text); color:var(--bg);padding:10px 20px; border-radius:20px; font-size:13px; z-index:80; opacity:0; pointer-events:none; transition:opacity .25s; white-space:nowrap;}.toast.show{opacity:1;}86 unmodified lines<section class="tab-panel" id="homeTab"><div class="section-head"><h2 class="display" data-t="homeTitle">اختيارات لك اليوم</h2><button class="shuffle-btn" onclick="shuffleHome()" data-t="shuffleBtn">🔀 تبديل</button></div><div class="ribbon thin"></div><p class="muted-line" data-t="homeSub">كتب مختارة من رفوف المكتبة في كل مرة تفتح فيها الصفحة</p><div class="grid" id="homeGrid"></div></section>64 unmodified lines<div class="modal" id="bookModal"></div></div><!-- PDF READER --><div class="reader-overlay" id="readerOverlay" hidden><div class="reader-topbar"><button class="reader-back" onclick="closeReader()">✕</button><div class="rt-side" id="readerBookTitle">—</div><div class="rt-center" id="readerPageNum">1 / 1</div></div><div class="reader-canvas-wrap" id="readerCanvasWrap"><div class="reader-canvas-inner" id="readerCanvasInner"><canvas id="pdfCanvas"></canvas></div></div><div class="reader-nav"><button onclick="prevPdfPage()">‹</button><button onclick="nextPdfPage()">›</button></div><div class="reader-bottombar"><button class="rb-btn" onclick="jumpToPdfPagePrompt()">🔢 انتقل لصفحة</button><button class="rb-btn" onclick="window.open(currentPdfUrl, '_blank')">⬇️ فتح/تحميل الملف</button></div></div><div class="toast" id="toast"></div></div></div><script>/* =========================================================================إعدادات الاتصال بـ Supabase========================================================================= */14 unmodified lines});}/* ---------------- الكتب — تُجلب حصرًا من قاعدة البيانات، لا يوجد بيانات وهمية ---------------- */let BOOKS = [];let ADHKAR = [];let RATINGS = [];/* ---------------- Translations ---------------- */const I18N = {17 unmodified linesreadBtn:'📖 قراءة الكتاب', noPdfMsg:'لم يتم رفع ملف PDF لهذا الكتاب بعد',emptyLibrary:'المكتبة فارغة حاليًا', emptyLibraryDesc:'أضف كتبًا من لوحة تحكم المدير لتظهر هنا فورًا لجميع المستخدمين.',notConnected:'لم يتم الاتصال بقاعدة البيانات بعد', notConnectedDesc:'أضف بيانات Supabase أعلى ملف الكود لتفعيل الحسابات والكتب.',loading:'جارِ التحميل...', pdfLoadError:'تعذّر تحميل ملف الكتاب، حاول مرة أخرى',errInvalidCreds:'البريد الإلكتروني أو كلمة المرور غير صحيحة', errEmailTaken:'هذا البريد مستخدم بالفعل',errGeneric:'حدث خطأ، حاول مرة أخرى', errWeakPass:'كلمة المرور يجب أن تكون 6 أحرف على الأقل',checkEmailMsg:'تم إرسال رابط تأكيد إلى بريدك الإلكتروني', resetSentMsg:'تم إرسال رابط استعادة كلمة المرور إلى بريدك',needAccountMsg:'سجّل دخولك لحفظ المفضلة وسجل القراءة',},en:{appName:'Imam Al-Muttaqin Library', loginSubtitle:'Your Arabic library for reading and discovery',15 unmodified linesreadBtn:'📖 Read book', noPdfMsg:'No PDF has been uploaded for this book yet',emptyLibrary:'The library is empty right now', emptyLibraryDesc:'Add books from the admin dashboard and they will appear here instantly for every user.',notConnected:'Not connected to a database yet', notConnectedDesc:'Add your Supabase credentials at the top of the code to enable accounts and books.',loading:'Loading...', pdfLoadError:'Could not load the book file, please try again',errInvalidCreds:'Incorrect email or password', errEmailTaken:'This email is already registered',errGeneric:'Something went wrong, please try again', errWeakPass:'Password must be at least 6 characters',checkEmailMsg:'A confirmation link has been sent to your email', resetSentMsg:'A password reset link has been sent to your email',needAccountMsg:'Log in to save favorites and reading history',}};9 unmodified linesfunction catInfo(key){ return CATEGORIES.find(c=>c.key===key) || {ar:key, en:key, color:'#0F5C4E'}; }function t(key){ return I18N[state.lang][key] || key; }/* ---------------- Auth: forms & tabs ---------------- */function switchAuthTab(mode){203 unmodified linesopenBookModal(id);}/* ---------------- تحميل مفضلة/سجل/علامات المستخدم من قاعدة البيانات ---------------- */async function loadUserData(){if(!CONFIGURED || !state.user || !state.user.id) return;108 unmodified lines<div class="book-author">${t('by')} ${b.author[state.lang]}</div></div>`;}function openBookModal(id){const b = BOOKS.find(x=>String(x.id)===String(id));if(!b) return;const info = catInfo(b.cat);const isFav = state.favorites.has(b.id);const isRead = state.history.has(b.id);2 unmodified linesconst starsHtml = [1,2,3,4,5].map(n=>`<span class="star ${n<=myRating?'filled':''}" onclick="rateBook('${b.id}', ${n})">★</span>`).join('');document.getElementById('bookModal').innerHTML = `<button class="modal-close" onclick="closeModal()">✕</button><div class="modal-cover" style="background:${b.color||info.color}">📕</div>6 unmodified lines<button class="btn ${isFav?'primary':''}" onclick="toggleFav('${b.id}')">${isFav?t('removeFav'):t('addFav')}</button><button class="btn ${isRead?'primary':''}" onclick="toggleRead('${b.id}')">${isRead?t('markedRead'):t('markRead')}</button>${state.isGuest ? `<p class="muted-line" style="margin:2px 0 0;">${t('needAccountMsg')}</p>` : ''}</div>`;document.getElementById('modalOverlay').hidden = false;}function closeModal(){ document.getElementById('modalOverlay').hidden = true; }14 unmodified linesasync function toggleRead(id){if(state.isGuest){ showToast(t('needAccountMsg')); return; }const has = state.history.has(id);if(has){ state.history.delete(id); } else { state.history.add(id); }openBookModal(id); renderDrawerList();if(!CONFIGURED || !state.user) return;if(has){3 unmodified lines}}/* ---------------- قارئ PDF داخل التطبيق (صفحة بصفحة) ---------------- */let pdfDoc = null;let currentPdfPage = 1;let pdfTotalPages = 1;let currentPdfUrl = null;let currentPdfBookId = null;if(typeof pdfjsLib !== 'undefined'){pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';}async function readBook(id){const book = BOOKS.find(b=>String(b.id)===String(id));if(!book) return;if(!book.pdfUrl){ showToast(t('noPdfMsg')); return; }closeModal();currentPdfUrl = book.pdfUrl;currentPdfBookId = id;document.getElementById('readerBookTitle').textContent = book.title[state.lang];document.getElementById('readerOverlay').hidden = false;document.getElementById('pdfCanvas').getContext('2d').clearRect(0,0,9999,9999);document.getElementById('readerPageNum').textContent = t('loading');try{pdfDoc = await pdfjsLib.getDocument(book.pdfUrl).promise;pdfTotalPages = pdfDoc.numPages;currentPdfPage = 1;await renderPdfPage(currentPdfPage);} catch(err){console.error(err);showToast(t('pdfLoadError'));closeReader();return;}if(CONFIGURED){supabaseClient.rpc('increment_book_views', { p_book_id: id }).then(()=>{});}if(!state.history.has(id)){ toggleRead(id); }}async function renderPdfPage(n){if(!pdfDoc) return;const page = await pdfDoc.getPage(n);const wrap = document.getElementById('readerCanvasWrap');const unscaledViewport = page.getViewport({ scale: 1 });const availableWidth = wrap.clientWidth - 28;const scale = Math.min(2.5, availableWidth / unscaledViewport.width);const viewport = page.getViewport({ scale });const canvas = document.getElementById('pdfCanvas');const ctx = canvas.getContext('2d');canvas.width = viewport.width;canvas.height = viewport.height;document.getElementById('readerCanvasInner').style.width = viewport.width + 'px';document.getElementById('readerCanvasInner').style.height = viewport.height + 'px';await page.render({ canvasContext: ctx, viewport }).promise;document.getElementById('readerPageNum').textContent = `${n} / ${pdfTotalPages}`;if(n === pdfTotalPages){ triggerFinishConfetti(); }}function nextPdfPage(){if(currentPdfPage >= pdfTotalPages) return;currentPdfPage++;renderPdfPage(currentPdfPage);}function prevPdfPage(){if(currentPdfPage <= 1) return;currentPdfPage--;renderPdfPage(currentPdfPage);}function jumpToPdfPagePrompt(){const val = prompt(`${t('jumpPagePrompt')} (1-${pdfTotalPages})`, currentPdfPage);if(val===null) return;const n = parseInt(val,10);if(!isNaN(n) && n>=1 && n<=pdfTotalPages){ currentPdfPage = n; renderPdfPage(n); }}function closeReader(){document.getElementById('readerOverlay').hidden = true;pdfDoc = null;}let _confettiShownFor = new Set();function triggerFinishConfetti(){if(!currentPdfBookId || _confettiShownFor.has(currentPdfBookId)) return;_confettiShownFor.add(currentPdfBookId);if(typeof confetti !== 'function') return;const duration = 1800;const end = Date.now() + duration;(function frame(){confetti({ particleCount: 5, angle: 60, spread: 60, origin: { x: 0 } });confetti({ particleCount: 5, angle: 120, spread: 60, origin: { x: 1 } });if(Date.now() < end) requestAnimationFrame(frame);})();}function showToast(msg){const el = document.getElementById('toast');
index.html+131-300