Cod1 / 222
mohamadelectronic's picture
Create 222
416c0bd verified
Raw History Blame Contribute Delete
21 kB
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>چت بات هوش مصنوعی با پنل رمزدار</title>
<style>
/* Reset and base */
*, *::before, *::after { box-sizing: border-box; }
html, body {
margin: 0; padding: 0;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
direction: rtl;
background: #ffffff;
color: #6b7280;
font-size: 16px;
line-height: 1.5;
min-height: 100vh;
}
a { color: #2563eb; text-decoration: none; }
a:hover, button:hover { text-decoration: underline; cursor: pointer; }
/* Container */
.container {
max-width: 1200px;
margin: 3rem auto 5rem;
padding: 0 1rem;
}
/* Header & Navigation */
header {
position: sticky;
top: 0;
background: white;
border-bottom: 1px solid #e5e7eb;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
z-index: 1000;
}
header .logo {
font-size: 2rem;
font-weight: 700;
color: #111827;
user-select: none;
}
nav a {
margin-left: 2rem;
font-weight: 600;
color: #6b7280;
transition: color 0.3s ease;
font-size: 1rem;
}
nav a:hover { color: #111827; }
nav .cta-btn {
background: #111827;
color: white;
padding: 0.5rem 1.5rem;
border-radius: 0.5rem;
font-weight: 700;
font-size: 1rem;
text-decoration: none;
user-select: none;
transition: background-color 0.3s ease;
}
nav .cta-btn:hover {
background: #374151;
}
/* Hero Section */
.hero {
text-align: center;
margin-bottom: 4rem;
}
.hero h1 {
font-weight: 800;
font-size: 48px;
color: #111827;
margin-bottom: 1rem;
user-select: none;
}
.hero p {
font-size: 18px;
color: #6b7280;
max-width: 600px;
margin: 0 auto 2rem;
}
.hero button {
font-weight: 700;
font-size: 18px;
padding: 14px 36px;
border-radius: 0.75rem;
border: none;
background: #111827;
color: white;
user-select: none;
transition: background-color 0.3s ease;
}
.hero button:hover {
background: #4b5563;
}
/* Chatbot widget */
#chatbot {
position: fixed;
bottom: 24px;
left: 24px;
width: 350px;
max-height: 600px;
background: white;
box-shadow: 0 4px 24px rgba(0,0,0,0.1);
border-radius: 0.75rem;
display: flex;
flex-direction: column;
overflow: hidden;
z-index: 10000;
font-size: 16px;
user-select: text;
transform: translateY(120%);
transition: transform 0.4s ease;
}
#chatbot.open {
transform: translateY(0);
}
#chatbot-header {
background: linear-gradient(45deg, #0088cc, #e1306c);
color: white;
font-weight: 700;
font-size: 1.25rem;
padding: 1rem 1.5rem;
border-top-left-radius: 0.75rem;
border-top-right-radius: 0.75rem;
display: flex;
justify-content: space-between;
align-items: center;
user-select: none;
}
#chatbot-header #bot-name {
max-width: 80%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#chatbot-close-btn {
background: transparent;
border: none;
color: white;
font-size: 1.5rem;
line-height: 1;
cursor: pointer;
transition: color 0.3s ease;
}
#chatbot-close-btn:hover {
color: #ffcccb;
}
#chat-messages {
flex: 1;
padding: 1rem;
overflow-y: auto;
background: #fafafa;
display: flex;
flex-direction: column;
}
.message {
max-width: 80%;
margin-bottom: 0.75rem;
padding: 12px 16px;
border-radius: 12px;
font-size: 14px;
line-height: 1.4;
white-space: pre-wrap;
word-break: break-word;
box-shadow: 0 1px 4px rgb(0 0 0 / 0.05);
animation: fadeInUp 0.3s ease forwards;
user-select: text;
}
@keyframes fadeInUp {
from {opacity: 0; transform: translateY(10px);} to {opacity:1; transform: translateY(0);}
}
.message.user {
background: linear-gradient(135deg, #e1306c, #0088cc);
color: white;
align-self: flex-end;
border-bottom-right-radius: 4px;
}
.message.bot {
background: white;
color: #374151;
border: 1.5px solid #0088cc;
align-self: flex-start;
border-bottom-left-radius: 4px;
}
#chat-input-form {
display: flex;
border-top: 1.5px solid #0088cc;
background: white;
padding: 0.75rem 1rem;
}
#chat-input {
flex: 1;
border-radius: 0.5rem;
border: 1px solid #ddd;
padding: 10px 14px;
font-size: 14px;
font-family: inherit;
resize: none;
height: 50px;
line-height: 1.3;
outline-offset: 2px;
color: #374151;
}
#chat-input::placeholder {
color: #a1a1aa;
}
#chat-send-btn {
background: #0088cc;
border: none;
color: white;
font-weight: 700;
font-size: 16px;
padding: 0 18px;
margin-left: 12px;
border-radius: 0.5rem;
cursor: pointer;
user-select: none;
transition: background-color 0.3s ease;
}
#chat-send-btn:hover:not(:disabled) {
background: #e1306c;
}
#chat-send-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
/* Typing indicator */
.typing-indicator {
display: flex;
gap: 6px;
margin-left: 4px;
align-items: center;
padding: 12px 16px;
}
.typing-indicator span {
width: 8px;
height: 8px;
background: #0088cc;
border-radius: 50%;
opacity: 0.4;
animation: typing-blink 1.4s infinite;
}
.typing-indicator span:nth-child(2) {
animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes typing-blink {
0%, 80%, 100% {opacity: 0.4;}
40% {opacity: 1;}
}
/* Developer Panel Overlay */
#dev-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.75);
backdrop-filter: blur(4px);
display: none;
justify-content: center;
align-items: center;
z-index: 11000;
user-select: text;
}
#dev-overlay.active {
display: flex;
}
#dev-panel {
background: white;
width: 750px;
max-width: 95vw;
max-height: 90vh;
border-radius: 0.75rem;
box-shadow: 0 10px 40px rgb(0 0 0 / 0.15);
display: flex;
flex-direction: column;
overflow: hidden;
}
#dev-header {
background: linear-gradient(45deg, #0088cc, #e1306c);
color: white;
font-size: 1.75rem;
font-weight: 700;
padding: 1rem 2rem;
user-select: none;
display: flex;
justify-content: space-between;
align-items: center;
}
#dev-close-btn {
background: transparent;
border: none;
font-size: 1.5rem;
color: white;
cursor: pointer;
transition: color 0.3s ease;
}
#dev-close-btn:hover {
color: #fca5a5;
}
#dev-content {
flex: 1;
overflow-y: auto;
padding: 1.5rem 2rem;
color: #374151;
font-size: 15px;
}
.tabs {
display: flex;
border-bottom: 2px solid #ddd;
margin-bottom: 1rem;
gap: 1rem;
user-select: none;
}
.tabs button {
padding: 12px 20px;
border: none;
border-bottom: 4px solid transparent;
font-weight: 600;
font-size: 1rem;
background: transparent;
color: #6b7280;
cursor: pointer;
transition: border-color 0.3s ease, color 0.3s ease;
border-radius: 0.5rem 0.5rem 0 0;
}
.tabs button.active {
border-color: #e1306c;
color: #e1306c;
font-weight: 700;
}
.tabs button:hover:not(.active) {
color: #0088cc;
}
.tab-panel {
display: none;
}
.tab-panel.active {
display: block;
}
form label {
display: block;
margin-top: 1rem;
margin-bottom: .5rem;
font-weight: 700;
color: #374151;
}
input[type=text], input[type=url], textarea, select, input[type=password] {
width: 100%;
padding: 10px 14px;
border: 1.5px solid #ddd;
border-radius: 0.5rem;
font-size: 15px;
resize: vertical;
font-family: inherit;
}
textarea {
min-height: 100px;
}
button[type=submit], button.remove-btn, button.add-btn {
margin-top: 1.25rem;
padding: 10px 20px;
font-weight: 700;
font-size: 1rem;
border-radius: 0.5rem;
border: none;
cursor: pointer;
user-select: none;
transition: background-color 0.3s ease;
}
button[type=submit] {
background: linear-gradient(45deg, #0088cc, #e1306c);
color: white;
}
button[type=submit]:hover {
background: linear-gradient(45deg, #e1306c, #0088cc);
}
button.remove-btn {
background: #ef4444;
color: white;
padding: 6px 12px;
font-size: 14px;
}
button.remove-btn:hover {
background: #b91c1c;
}
button.add-btn {
background: #22c55e;
color: white;
}
button.add-btn:hover {
background: #15803d;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
}
th, td {
padding: 12px 10px;
border-bottom: 1px solid #eee;
text-align: right;
font-weight: 600;
font-size: 14px;
color: #4b5563;
}
th {
background: #f9fafb;
color: #374151;
}
tr:hover td {
background: #f3f4f6;
}
#password-message {
margin-top: 0.5rem;
min-height: 1.25rem;
font-weight: 700;
}
#password-message.error { color: #ef4444; }
#password-message.success { color: #22c55e; }
</style>
</head>
<body>
<header>
<div class="logo" aria-label="لوگوی چت بات هوش مصنوعی">AI ChatBot</div>
<nav>
<a href="#features">ویژگی‌ها</a>
<a href="#usage">نحوه استفاده</a>
<a href="#contact">تماس</a>
<a href="javascript:void(0)" id="open-chat-btn" class="cta-btn" aria-expanded="false" aria-controls="chatbot">شروع چت</a>
</nav>
</header>
<main class="container" role="main">
<section id="features" aria-label="ویژگی های چت بات">
<h1>چت بات هوش مصنوعی با پنل توسعه‌دهنده رمزدار</h1>
<p>افزودن پایگاه دانش، مدیریت چند ربات، انتخاب تم و تنظیمات پیشرفته بدون نیاز به سرور و با استفاده از هوش مصنوعی Hugging Face.</p>
</section>
<section id="usage" aria-label="نحوه استفاده">
<h2>کد کوتاه برای افزودن به سایت شما:</h2>
<pre style="background:#f3f4f6;padding:1rem;border-radius:0.5rem;user-select:text;">
&lt;div id="ai-chatbot-container"&gt;&lt;/div&gt;
&lt;script src="PATH_TO_THIS_FILE_OR_EMBED_JS" defer&gt;&lt;/script&gt;
</pre>
</section>
<section id="contact" aria-label="تماس">
<h2>تماس با ما</h2>
<p>برای همکاری، میزبانی یا راهنمایی، ایمیل بزنید: <a href="mailto:support@example.com">support@example.com</a></p>
</section>
</main>
<!-- Chatbot Widget -->
<div id="chatbot" role="dialog" aria-modal="true" aria-label="پنجره چت بات هوش مصنوعی" tabindex="-1" aria-hidden="true" >
<div id="chatbot-header">
<span id="bot-name" aria-live="polite" aria-atomic="true" aria-relevant="additions">ربات من</span>
<button aria-label="بستن چت بات" id="chatbot-close-btn" title="بستن چت بات">&times;</button>
</div>
<div id="chat-messages" tabindex="0" aria-live="polite" aria-atomic="false"></div>
<form id="chat-input-form" aria-label="فرم ارسال پیام چت">
<textarea id="chat-input" autocomplete="off" placeholder="پیام خود را اینجا بنویسید..." rows="2" required></textarea>
<button type="submit" id="chat-send-btn" disabled>ارسال</button>
</form>
<button id="open-dev-panel-btn" title="پنل توسعه‌دهنده" aria-label="باز کردن پنل توسعه‌دهنده" style="position:absolute;top:0.75rem;left:0.75rem;background:none;border:none;font-size:1.5rem;color:white;cursor:pointer;user-select:none;">⚙️</button>
</div>
<!-- Developer Panel Overlay -->
<div id="dev-overlay" role="dialog" aria-modal="true" aria-labelledby="dev-header-title" tabindex="-1" aria-hidden="true">
<div id="dev-panel">
<div id="dev-header">
<span id="dev-header-title">پنل توسعه‌دهنده</span>
<button id="dev-close-btn" aria-label="بستن پنل توسعه‌دهنده" title="بستن پنل توسعه‌دهنده">&times;</button>
</div>
<div id="dev-content">
<div class="tabs" role="tablist" aria-label="تب‌های پنل توسعه‌دهنده">
<button role="tab" aria-selected="true" aria-controls="tab-kb" id="tab-kb-btn" class="active">پایگاه دانش</button>
<button role="tab" aria-selected="false" aria-controls="tab-settings" id="tab-settings-btn">تنظیمات ربات</button>
<button role="tab" aria-selected="false" aria-controls="tab-bots" id="tab-bots-btn">ربات‌ها</button>
</div>
<section id="tab-kb" class="tab-panel active" role="tabpanel" aria-labelledby="tab-kb-btn" tabindex="0">
<form id="kb-form" aria-label="فرم افزودن سوال و پاسخ به پایگاه دانش">
<label for="kb-question">سوال</label>
<input type="text" id="kb-question" autocomplete="off" placeholder="سوال خود را وارد کنید" required/>
<label for="kb-answer">پاسخ</label>
<textarea id="kb-answer" placeholder="پاسخ خود را وارد کنید" required></textarea>
<button type="submit">افزودن به پایگاه دانش</button>
</form>
<table aria-label="لیست سوال و پاسخ‌ها">
<thead>
<tr><th>سوال</th><th>پاسخ</th><th>حذف</th></tr>
</thead>
<tbody id="kb-list"></tbody>
</table>
</section>
<section id="tab-settings" class="tab-panel" role="tabpanel" aria-labelledby="tab-settings-btn" tabindex="0" hidden>
<form id="settings-form" aria-label="فرم تنظیمات ربات">
<label for="bot-name-input">نام ربات</label>
<input type="text" id="bot-name-input" placeholder="نام ربات" />
<label for="response-type-select">نوع پاسخ‌دهی ربات</label>
<select id="response-type-select" aria-label="نوع پاسخ‌دهی ربات">
<option value="knowledge-base">پاسخ بر اساس پایگاه دانش</option>
<option value="ai">پاسخ با هوش مصنوعی</option>
<option value="hybrid">ترکیبی از هر دو</option>
</select>
<label for="allow-profanity-select">مجاز بودن فحش</label>
<select id="allow-profanity-select" aria-label="تنظیم مجاز بودن فحش">
<option value="false" selected>غیرمجاز</option>
<option value="true">مجاز</option>
</select>
<label for="bot-image-url">آدرس تصویر ربات (URL)</label>
<input type="url" id="bot-image-url" placeholder="https://example.com/avatar.png" />
<fieldset style="border:1px solid #ddd; padding:1rem; margin-top:2rem; border-radius:0.5rem;">
<legend>تغییر رمز پنل توسعه‌دهنده</legend>
<label for="mother-password">رمز مادر (برای غیرفعال کردن رمز)</label>
<input type="password" id="mother-password" placeholder="رمز مادر" autocomplete="new-password" />
<label for="current-password">رمز فعلی</label>
<input type="password" id="current-password" placeholder="رمز فعلی" autocomplete="current-password" />
<label for="new-password">رمز جدید</label>
<input type="password" id="new-password" placeholder="رمز جدید" autocomplete="new-password" />
<label for="confirm-password">تکرار رمز جدید</label>
<input type="password" id="confirm-password" placeholder="تکرار رمز جدید" />
<button type="button" id="change-password-btn">تغییر رمز</button>
<p id="password-message" aria-live="polite"></p>
</fieldset>
<button type="submit">ذخیره تنظیمات</button>
</form>
</section>
<section id="tab-bots" class="tab-panel" role="tabpanel" aria-labelledby="tab-bots-btn" tabindex="0" hidden>
<button id="create-bot-btn" class="add-btn">ساخت ربات جدید</button>
<table aria-label="لیست ربات‌ها">
<thead>
<tr><th>نام ربات</th><th>فعالسازی</th><th>حذف</th></tr>
</thead>
<tbody id="bots-list"></tbody>
</table>
</section>
</div>
</div>
</div>
<script>
(async () => {
// Utility
const $ = id => document.getElementById(id);
function delay(ms) { return new Promise(r => setTimeout(r, ms)); }
async function sha256(msg) {
const buf = new TextEncoder().encode(msg);
const hash = await crypto.subtle.digest('SHA-256', buf);
return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2,'0')).join('');
}
function sanitize(str) {
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
}
// DOM Elements
const chatbot = $('chatbot');
const openChatBtn = $('open-chat-btn');
const closeChatBtn = $('chatbot-close-btn');
const chatMessages = $('chat-messages');
const chatInput = $('chat-input');
const chatSendBtn = $('chat-send-btn');
const openDevPanelBtn = $('open-dev-panel-btn');
const devOverlay = $('dev-overlay');
const devCloseBtn = $('dev-close-btn');
// Developer panel elements
const tabs = {
kbBtn: $('tab-kb-btn'),
settingsBtn: $('tab-settings-btn'),
botsBtn: $('tab-bots-btn'),
kbPanel: $('tab-kb'),
settingsPanel: $('tab-settings'),
botsPanel: $('tab-bots'),
};
const kbForm = $('kb-form');
const kbQuestion = $('kb-question');
const kbAnswer = $('kb-answer');
const kbList = $('kb-list');
const settingsForm = $('settings-form');
const botNameInput = $('bot-name-input');
const responseTypeSelect = $('response-type-select');
const allowProfanitySelect = $('allow-profanity-select');
const botImageUrlInput = $('bot-image-url');
const motherPasswordInput = $('mother-password');
const currentPasswordInput = $('current-password');
const newPasswordInput = $('new-password');
const confirmPasswordInput = $('confirm-password');
const changePasswordBtn = $('change-password-btn');
const passwordMessage = $('password-message');
const botsList = $('bots-list');
const createBotBtn = $('create-bot-btn');
const botNameDisplay = $('bot-name');
// Persistent keys and default passwords
const STORAGE_KEY = 'ai_chatbot_app_state';
const PASSWORD_HASH_KEY = 'ai_chatbot_dev_password_hash';
const MOTHER_PASS_HASH_KEY = 'ai_chatbot_mother_pass_hash';
const DEFAULT_PASSWORD = '1234';
const MASTER_PASSWORD = '12340000';
// State
let state = {
bots: {},
activeBotId: '',
devPanelOpen: false,
authenticated: false
};
// Initialize default bot
function defaultBotTemplate() {
return {
id: 'default-bot',
name: 'ربات من',
kb: [],
settings: {
responseType: 'hybrid',
allowProfanity: false,
botImageUrl: ''
}
};
}
// Load state from localStorage
async function loadState() {
const data = localStorage.getItem(STORAGE_KEY);
if (data) {
try {
state = JSON.parse(data);
if (!state.bots || Object.keys(state.bots).length === 0) {
state.bots = {[defaultBotTemplate().id]: defaultBotTemplate()};
state.activeBotId = defaultBotTemplate().id;
}
if (!state.activeBotId || !state.bots[state.activeBotId]) {
state.activeBotId = Obje