تست: تفاوت میان نسخهها
ظاهر
بدون خلاصۀ ویرایش |
بدون خلاصۀ ویرایش |
||
خط ۲۵: | خط ۲۵: | ||
color: #2c3e50; | color: #2c3e50; | ||
margin-bottom: 30px; | margin-bottom: 30px; | ||
} | } | ||
.form-group { | .form-group { | ||
خط ۴۹: | خط ۴۲: | ||
font-size: 16px; | font-size: 16px; | ||
box-sizing: border-box; | box-sizing: border-box; | ||
} | } | ||
.iframe-container { | .iframe-container { | ||
خط ۷۳: | خط ۵۳: | ||
height: 600px; | height: 600px; | ||
border: none; | border: none; | ||
} | } | ||
.admin-section { | .admin-section { | ||
خط ۸۵: | خط ۶۰: | ||
border-radius: 6px; | border-radius: 6px; | ||
margin-top: 15px; | margin-top: 15px; | ||
display: none; | |||
} | |||
.user-section { | |||
background: #fff3cd; | |||
border: 1px solid #ffeaa7; | |||
padding: 15px; | |||
border-radius: 6px; | |||
margin-top: 15px; | |||
display: none; | |||
} | } | ||
.admin-title { | .admin-title { | ||
خط ۹۰: | خط ۷۴: | ||
font-weight: bold; | font-weight: bold; | ||
margin-bottom: 10px; | margin-bottom: 10px; | ||
} | |||
.user-title { | |||
color: #856404; | |||
font-weight: bold; | |||
margin-bottom: 10px; | |||
} | |||
.loading { | |||
text-align: center; | |||
color: #007bff; | |||
padding: 10px; | |||
} | } | ||
</style> | </style> | ||
خط ۹۷: | خط ۹۱: | ||
<h1>کتابخانه پدیا بایبل</h1> | <h1>کتابخانه پدیا بایبل</h1> | ||
<div class=" | <div class="form-group"> | ||
<label for="bookSelect">انتخاب کتاب:</label> | |||
<select id="bookSelect"> | |||
<option value="">-- لطفاً یک کتاب انتخاب کنید --</option> | |||
<option value="کتاب_مقدس">کتاب مقدس</option> | |||
<option value="انجیل_متی">انجیل متی</option> | |||
<option value="انجیل_مرقس">انجیل مرقس</option> | |||
<option value="مزامیر">مزامیر</option> | |||
</select> | |||
</div> | |||
<div id="adminSection" class="admin-section"> | |||
<div class="admin-title">🔧 بخش مدیریت - ایجاد کتاب جدید</div> | |||
<div class="form-group"> | <div class="form-group"> | ||
<label for=" | <label for="bookSearch">نام کتاب جدید:</label> | ||
< | <input type="text" id="bookSearch" placeholder="نام کتاب جدید را وارد کرده و Enter بزنید..."> | ||
</div> | </div> | ||
</div> | |||
<div id="userSection" class="user-section"> | |||
<div class="user-title">👤 بخش کاربران</div> | |||
<div class="form-group"> | |||
<label for="userSearch">جستجوی کتاب (فقط نمایش):</label> | |||
<input type="text" id="userSearch" placeholder="نام کتاب را برای نمایش وارد کنید..."> | |||
</div> | </div> | ||
</div> | </div> | ||
خط ۱۲۱: | خط ۱۲۴: | ||
<script> | <script> | ||
class BookManager { | |||
constructor() { | |||
this.bookSelect = document.getElementById('bookSelect'); | |||
this.bookSearch = document.getElementById('bookSearch'); | |||
this.userSearch = document.getElementById('userSearch'); | |||
this.contentFrame = document.getElementById('contentFrame'); | |||
this.adminSection = document.getElementById('adminSection'); | |||
this.userSection = document.getElementById('userSection'); | |||
this.DYNAMIC_BOOKS_KEY = 'pb_dynamic_books_v2'; | |||
this.isAdmin = false; | |||
this.isCheckingAdmin = false; | |||
this.init(); | |||
} | |||
async init() { | |||
await this.checkAdminStatus(); | |||
this.loadDynamicBooks(); | |||
this.setupEventListeners(); | |||
this.showInitialBook(); | |||
} | |||
// | // تشخیص مدیر از طریق تست دسترسی به ویکی | ||
async checkAdminStatus() { | |||
this.isCheckingAdmin = true; | |||
const | try { | ||
// تست ایجاد یک صفحه موقت برای بررسی دسترسی | |||
const testPageName = `Temp_Test_${Date.now()}`; | |||
const testUrl = `https://www.pediabible.com/index.php/${encodeURIComponent(testPageName)}`; | |||
const response = await fetch(testUrl, { | |||
method: 'GET', | |||
credentials: 'include' // ارجاع کوکیهای session | |||
}); | }); | ||
// اگر | // اگر صفحه باز شد و خطای دسترسی نداد، احتمالاً مدیر است | ||
if ( | if (response.ok) { | ||
const html = await response.text(); | |||
// بررسی وجود فرم لاگین یا پیام دسترسی ممنوع | |||
this.isAdmin = !html.includes('log in') && | |||
!html.includes('لاگین') && | |||
!html.includes('permission') && | |||
!html.includes('دسترسی'); | |||
} | } | ||
} catch (error) { | |||
console.log('خطا در بررسی دسترسی:', error); | |||
this.isAdmin = false; | |||
} | } | ||
this.isCheckingAdmin = false; | |||
this.updateUI(); | |||
} | } | ||
updateUI() { | |||
if (this.isAdmin) { | |||
this.adminSection.style.display = 'block'; | |||
this.userSection.style.display = 'none'; | |||
console.log('👑 حالت مدیر فعال شد'); | |||
} else { | |||
this.adminSection.style.display = 'none'; | |||
this.userSection.style.display = 'block'; | |||
console.log('👤 حالت کاربر عادی فعال شد'); | |||
} | } | ||
} | } | ||
loadDynamicBooks() { | |||
const savedBooks = localStorage.getItem(this.DYNAMIC_BOOKS_KEY); | |||
if (savedBooks) { | |||
try { | |||
const books = JSON.parse(savedBooks); | |||
books.forEach(book => { | |||
if (!this.bookExistsInList(book)) { | |||
this.addBookToSelect(book); | |||
} | |||
}); | |||
} catch (e) { | |||
console.error('خطا در بارگذاری لیست کتابها:', e); | |||
} | } | ||
} | } | ||
} | |||
bookExistsInList(bookName) { | |||
return Array.from(this.bookSelect.options).some(option => | |||
option.value === bookName | |||
); | |||
} | |||
addBookToSelect(bookName) { | |||
const option = document.createElement('option'); | const option = document.createElement('option'); | ||
option.value = bookName; | option.value = bookName; | ||
option.textContent = bookName; | option.textContent = this.formatBookName(bookName); | ||
bookSelect.appendChild(option); | this.bookSelect.appendChild(option); | ||
return true; | } | ||
formatBookName(bookName) { | |||
return bookName.replace(/_/g, ' '); | |||
} | |||
saveNewBook(bookName) { | |||
const savedBooks = localStorage.getItem(this.DYNAMIC_BOOKS_KEY); | |||
let books = savedBooks ? JSON.parse(savedBooks) : []; | |||
if (!books.includes(bookName)) { | |||
books.push(bookName); | |||
localStorage.setItem(this.DYNAMIC_BOOKS_KEY, JSON.stringify(books)); | |||
return true; | |||
} | |||
return false; | |||
} | } | ||
showBook(bookName) { | |||
if (!bookName) return; | if (!bookName) return; | ||
const encodedBookName = encodeURIComponent(bookName); | const encodedBookName = encodeURIComponent(bookName); | ||
this.contentFrame.src = `https://www.pediabible.com/index.php/${encodedBookName}`; | |||
} | } | ||
// ایجاد کتاب جدید | // ایجاد کتاب جدید (فقط برای مدیر) | ||
async createNewBook(bookName) { | |||
if (!bookName.trim()) { | if (!bookName.trim()) { | ||
alert('لطفاً نام کتاب را وارد کنید'); | alert('لطفاً نام کتاب را وارد کنید'); | ||
خط ۱۸۶: | خط ۲۵۱: | ||
} | } | ||
// | if (!this.isAdmin) { | ||
if ( | alert('شما دسترسی لازم برای ایجاد کتاب جدید را ندارید'); | ||
return; | |||
} | |||
const formattedBookName = bookName.trim().replace(/ /g, '_'); | |||
// بررسی نهایی دسترسی قبل از ایجاد | |||
if (this.isCheckingAdmin) { | |||
alert('لطفاً چند ثانیه صبر کنید...'); | |||
return; | |||
} | |||
try { | |||
// تست نهایی دسترسی | |||
const testUrl = `https://www.pediabible.com/index.php/${encodeURIComponent(formattedBookName)}`; | |||
const response = await fetch(testUrl, { credentials: 'include' }); | |||
if (!response.ok) { | |||
throw new Error('دسترسی ممنوع'); | |||
} | |||
// | // اضافه کردن به لیست | ||
const isNew = this.saveNewBook(formattedBookName); | |||
if (isNew) { | |||
this.addBookToSelect(formattedBookName); | |||
} | |||
alert(`کتاب "${ | // نمایش کتاب | ||
} | this.bookSelect.value = formattedBookName; | ||
alert( | this.showBook(formattedBookName); | ||
this.bookSearch.value = ''; | |||
alert(`✅ کتاب "${this.formatBookName(formattedBookName)}" با موفقیت ایجاد شد`); | |||
} catch (error) { | |||
console.error('خطا در ایجاد کتاب:', error); | |||
alert('❌ خطا در ایجاد کتاب. ممکن است دسترسی لازم را نداشته باشید.'); | |||
} | } | ||
} | } | ||
// | // جستجو برای کاربران عادی | ||
searchBook(bookName) { | |||
if (!bookName.trim()) return; | |||
const formattedBookName = bookName.trim().replace(/ /g, '_'); | |||
this.showBook(formattedBookName); | |||
this.userSearch.value = ''; | |||
} | |||
// | setupEventListeners() { | ||
// انتخاب از لیست | |||
if (this.value) { | this.bookSelect.addEventListener('change', () => { | ||
this.showBook(this.bookSelect.value); | |||
} | }); | ||
} | |||
// جستجوی مدیر | |||
this.bookSearch.addEventListener('keypress', (e) => { | |||
if (e.key === 'Enter') { | |||
this.createNewBook(this.bookSearch.value); | |||
} | |||
}); | |||
// جستجوی کاربر عادی | |||
this.userSearch.addEventListener('keypress', (e) => { | |||
if (e.key === 'Enter') { | |||
this.searchBook(this.userSearch.value); | |||
} | |||
}); | |||
} | |||
showInitialBook() { | |||
if (this.bookSelect.options.length > 1 && !this.bookSelect.value) { | |||
if ( | this.bookSelect.selectedIndex = 1; | ||
this.showBook(this.bookSelect.value); | |||
} | } | ||
} | } | ||
} | |||
// راهاندازی سیستم | |||
document.addEventListener('DOMContentLoaded', () => { | |||
new BookManager(); | |||
}); | }); | ||
</script> | </script> | ||
</body> | </body> | ||
</html> | </html> |
نسخهٔ ۱۲ اکتبر ۲۰۲۵، ساعت ۱۸:۰۴
<!DOCTYPE html>
کتابخانه پدیا بایبل
🔧 بخش مدیریت - ایجاد کتاب جدید
👤 بخش کاربران