-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb-renderer.js
More file actions
256 lines (220 loc) · 16.1 KB
/
web-renderer.js
File metadata and controls
256 lines (220 loc) · 16.1 KB
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
// ═══════════════════════════════════════════════════════════════════════════════
// 🚀 GraTech Commander - COMPLETE WORKING VERSION
// By Suliman Nazal Alshammari | @Grar00t | @GrAxOS
// "بذمة وصدق - This ACTUALLY works!"
// ═══════════════════════════════════════════════════════════════════════════════
// 🌍 TRANSLATIONS
const TRANSLATIONS = {
ar: { chat:'💬 المحادثة', vault:'🔐 الخزنة', notes:'📝 ملاحظاتي', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 حساباتي', settings:'⚙️ الإعدادات', safety:'🛡️ الحماية', send:'إرسال ▶', thinking:'⏳ جاري التفكير...', placeholder:'اكتب بالعربي براحتك... 😊', saved:'✅ تم الحفظ!' },
en: { chat:'💬 Chat', vault:'🔐 Vault', notes:'📝 Notes', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 Accounts', settings:'⚙️ Settings', safety:'🛡️ Safety', send:'Send ▶', thinking:'⏳ Thinking...', placeholder:'Type your message...', saved:'✅ Saved!' },
fr: { chat:'💬 Discussion', vault:'🔐 Coffre', notes:'📝 Notes', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 Comptes', settings:'⚙️ Paramètres', safety:'🛡️ Sécurité', send:'Envoyer ▶', thinking:'⏳ Réflexion...', placeholder:'Tapez votre message...', saved:'✅ Sauvegardé!' },
de: { chat:'💬 Chat', vault:'🔐 Tresor', notes:'📝 Notizen', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 Konten', settings:'⚙️ Einstellungen', safety:'🛡️ Sicherheit', send:'Senden ▶', thinking:'⏳ Denke...', placeholder:'Nachricht eingeben...', saved:'✅ Gespeichert!' },
es: { chat:'💬 Chat', vault:'🔐 Bóveda', notes:'📝 Notas', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 Cuentas', settings:'⚙️ Configuración', safety:'🛡️ Seguridad', send:'Enviar ▶', thinking:'⏳ Pensando...', placeholder:'Escribe tu mensaje...', saved:'✅ ¡Guardado!' },
zh: { chat:'💬 聊天', vault:'🔐 保险库', notes:'📝 笔记', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 账户', settings:'⚙️ 设置', safety:'🛡️ 安全', send:'发送 ▶', thinking:'⏳ 思考中...', placeholder:'输入消息...', saved:'✅ 已保存!' },
ja: { chat:'💬 チャット', vault:'🔐 金庫', notes:'📝 メモ', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 アカウント', settings:'⚙️ 設定', safety:'🛡️ セキュリティ', send:'送信 ▶', thinking:'⏳ 考え中...', placeholder:'メッセージを入力...', saved:'✅ 保存しました!' },
ko: { chat:'💬 채팅', vault:'🔐 금고', notes:'📝 메모', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 계정', settings:'⚙️ 설정', safety:'🛡️ 보안', send:'보내기 ▶', thinking:'⏳ 생각 중...', placeholder:'메시지 입력...', saved:'✅ 저장됨!' },
tr: { chat:'💬 Sohbet', vault:'🔐 Kasa', notes:'📝 Notlar', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 Hesaplar', settings:'⚙️ Ayarlar', safety:'🛡️ Güvenlik', send:'Gönder ▶', thinking:'⏳ Düşünüyor...', placeholder:'Mesajınızı yazın...', saved:'✅ Kaydedildi!' },
ru: { chat:'💬 Чат', vault:'🔐 Хранилище', notes:'📝 Заметки', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 Аккаунты', settings:'⚙️ Настройки', safety:'🛡️ Безопасность', send:'Отправить ▶', thinking:'⏳ Думаю...', placeholder:'Введите сообщение...', saved:'✅ Сохранено!' },
hi: { chat:'💬 चैट', vault:'🔐 तिजोरी', notes:'📝 नोट्स', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 खाते', settings:'⚙️ सेटिंग्स', safety:'🛡️ सुरक्षा', send:'भेजें ▶', thinking:'⏳ सोच रहा...', placeholder:'संदेश लिखें...', saved:'✅ सहेजा गया!' },
ur: { chat:'💬 چیٹ', vault:'🔐 خزانہ', notes:'📝 نوٹس', github:'🐙 GitHub', azure:'☁️ Azure', accounts:'👤 اکاؤنٹس', settings:'⚙️ ترتیبات', safety:'🛡️ سیکورٹی', send:'بھیجیں ▶', thinking:'⏳ سوچ رہا...', placeholder:'پیغام لکھیں...', saved:'✅ محفوظ!' }
};
let currentLang = 'ar';
let isLoading = false;
// ═══════════════════════════════════════════════════════════════════════════════
// 🚀 INIT
// ═══════════════════════════════════════════════════════════════════════════════
document.addEventListener('DOMContentLoaded', () => {
console.log('⚡ GraTech Commander Starting...');
currentLang = localStorage.getItem('gratech_lang') || 'ar';
initLanguage();
initNavigation();
initChat();
initSettings();
initModals();
updateUI();
console.log('✅ Ready!');
});
// ═══════════════════════════════════════════════════════════════════════════════
// 🌍 LANGUAGE - WORKING!
// ═══════════════════════════════════════════════════════════════════════════════
function t(key) { return TRANSLATIONS[currentLang]?.[key] || TRANSLATIONS.en[key] || key; }
function initLanguage() {
const sel = document.getElementById('language-select');
if (!sel) return;
sel.value = currentLang;
sel.addEventListener('change', (e) => {
currentLang = e.target.value;
localStorage.setItem('gratech_lang', currentLang);
updateUI();
showNotification(t('saved'));
});
}
function updateUI() {
// Direction
const rtl = ['ar','ur'].includes(currentLang);
document.documentElement.dir = rtl ? 'rtl' : 'ltr';
document.documentElement.lang = currentLang;
// Nav buttons
const keys = ['chat','vault','notes','github','azure','accounts','settings','safety'];
document.querySelectorAll('.nav-btn').forEach((btn,i) => {
if (keys[i]) btn.textContent = t(keys[i]);
});
// Other elements
const sendBtn = document.getElementById('send-btn');
if (sendBtn) sendBtn.textContent = t('send');
const input = document.getElementById('message-input');
if (input) input.placeholder = t('placeholder');
console.log('🌍 Lang:', currentLang, rtl ? 'RTL' : 'LTR');
}
// ═══════════════════════════════════════════════════════════════════════════════
// 📍 NAVIGATION - WORKING!
// ═══════════════════════════════════════════════════════════════════════════════
function initNavigation() {
document.querySelectorAll('.nav-btn').forEach(btn => {
btn.addEventListener('click', function() {
const viewId = this.dataset.view;
document.querySelectorAll('.nav-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
document.getElementById(viewId + '-view')?.classList.add('active');
console.log('📍', viewId);
});
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// 💬 CHAT - REAL AI!
// ═══════════════════════════════════════════════════════════════════════════════
function initChat() {
document.getElementById('send-btn')?.addEventListener('click', sendMessage);
document.getElementById('message-input')?.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); }
});
document.querySelectorAll('.mode-btn').forEach(btn => {
btn.addEventListener('click', function() {
document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
});
});
document.querySelectorAll('.quick-prompt').forEach(btn => {
btn.addEventListener('click', function() {
const input = document.getElementById('message-input');
if (input) { input.value = this.textContent.replace(/^[^\s]+\s/,''); input.focus(); }
});
});
}
async function sendMessage() {
const input = document.getElementById('message-input');
const container = document.getElementById('chat-container');
const model = document.getElementById('model-select')?.value || 'gpt-4o';
const msg = input?.value?.trim();
if (!msg || isLoading) return;
// Remove welcome
container.querySelector('.welcome-message')?.remove();
// Add user msg
addMessage(msg, 'user');
input.value = '';
isLoading = true;
// Loading
const loadId = 'load-' + Date.now();
const loadDiv = document.createElement('div');
loadDiv.className = 'message assistant';
loadDiv.id = loadId;
loadDiv.textContent = t('thinking');
container.appendChild(loadDiv);
container.scrollTop = container.scrollHeight;
try {
const result = await window.GraTechAI.send(msg, model);
document.getElementById(loadId)?.remove();
if (result.success) {
addMessage(result.message, 'assistant');
if (result.remaining !== undefined) {
showNotification(`✅ ${result.model} | ${result.remaining} left`);
}
} else {
addMessage(result.error, 'assistant');
}
} catch (err) {
document.getElementById(loadId)?.remove();
addMessage('❌ ' + err.message, 'assistant');
}
isLoading = false;
}
function addMessage(content, role) {
const container = document.getElementById('chat-container');
const div = document.createElement('div');
div.className = 'message ' + role;
div.innerHTML = content.replace(/```(\w*)\n?([\s\S]*?)```/g,'<pre><code>$2</code></pre>').replace(/`([^`]+)`/g,'<code>$1</code>').replace(/\n/g,'<br>');
container.appendChild(div);
container.scrollTop = container.scrollHeight;
}
window.insertPrompt = (text) => {
const input = document.getElementById('message-input');
if (input) { input.value = text + ' '; input.focus(); }
};
// ═══════════════════════════════════════════════════════════════════════════════
// ⚙️ SETTINGS
// ═══════════════════════════════════════════════════════════════════════════════
function initSettings() {
document.getElementById('azure-api-key').value = localStorage.getItem('gratech_api_key') || '';
document.getElementById('azure-endpoint').value = localStorage.getItem('gratech_endpoint') || '';
document.getElementById('github-token').value = localStorage.getItem('gratech_github') || '';
document.getElementById('save-settings')?.addEventListener('click', () => {
const k = document.getElementById('azure-api-key').value;
const e = document.getElementById('azure-endpoint').value;
const g = document.getElementById('github-token').value;
if (k) localStorage.setItem('gratech_api_key', k); else localStorage.removeItem('gratech_api_key');
if (e) localStorage.setItem('gratech_endpoint', e); else localStorage.removeItem('gratech_endpoint');
if (g) localStorage.setItem('gratech_github', g); else localStorage.removeItem('gratech_github');
showNotification(t('saved'));
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// 🎭 MODALS
// ═══════════════════════════════════════════════════════════════════════════════
function initModals() {
document.getElementById('quick-note-btn')?.addEventListener('click', () => document.getElementById('quick-note-modal')?.classList.remove('hidden'));
document.getElementById('attach-file-btn')?.addEventListener('click', () => document.getElementById('attach-modal')?.classList.remove('hidden'));
document.querySelectorAll('.close-modal').forEach(b => b.addEventListener('click', () => document.querySelectorAll('.modal').forEach(m => m.classList.add('hidden'))));
document.getElementById('save-quick-note')?.addEventListener('click', () => {
const txt = document.getElementById('quick-note-text').value;
if (txt) {
const notes = JSON.parse(localStorage.getItem('gratech_notes')||'[]');
notes.push({text:txt, date:new Date().toISOString()});
localStorage.setItem('gratech_notes', JSON.stringify(notes));
document.getElementById('quick-note-text').value = '';
document.getElementById('quick-note-modal').classList.add('hidden');
showNotification('✅');
}
});
document.getElementById('emergency-stop')?.addEventListener('click', () => {
isLoading = false;
document.querySelectorAll('[id^="load-"]').forEach(el => el.remove());
showNotification('🚨 Stopped!');
});
document.querySelectorAll('.vault-cat').forEach(b => b.addEventListener('click', function() {
document.querySelectorAll('.vault-cat').forEach(x => x.classList.remove('active'));
this.classList.add('active');
}));
document.querySelectorAll('.copy-btn').forEach(b => b.addEventListener('click', function() {
const k = this.closest('.vault-item')?.querySelector('.hidden-key')?.textContent;
if (k) { navigator.clipboard.writeText(k); this.textContent = '✅'; setTimeout(() => this.textContent = '📋', 1500); }
}));
document.getElementById('browse-files')?.addEventListener('click', () => document.getElementById('file-input')?.click());
}
// ═══════════════════════════════════════════════════════════════════════════════
// 🔔 NOTIFICATIONS
// ═══════════════════════════════════════════════════════════════════════════════
function showNotification(msg) {
let n = document.getElementById('gratech-notif');
if (!n) {
n = document.createElement('div');
n.id = 'gratech-notif';
n.style.cssText = 'position:fixed;bottom:30px;left:50%;transform:translateX(-50%);background:linear-gradient(135deg,#00d4ff,#7c3aed);color:white;padding:15px 30px;border-radius:30px;z-index:10000;font-family:Cairo,sans-serif;font-weight:600;box-shadow:0 4px 20px rgba(0,0,0,0.3);';
document.body.appendChild(n);
}
n.textContent = msg;
n.style.display = 'block';
setTimeout(() => n.style.display = 'none', 3000);
}
window.showNotification = showNotification;
console.log('✨ GraTech Ready - ALL WORKING!');