Spaces:
Running
Running
File size: 6,539 Bytes
586c312 418ecc4 586c312 418ecc4 586c312 418ecc4 586c312 418ecc4 |
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 |
// Enhanced JavaScript for DeepChat Pro
console.log('DeepChat Pro - Advanced AI Assistant Loaded');
// Initialize enhanced tooltips and interactions
document.addEventListener('DOMContentLoaded', function() {
// Enhanced icon tooltips
const icons = document.querySelectorAll('[data-feather]');
icons.forEach(icon => {
const iconName = icon.getAttribute('data-feather');
icon.setAttribute('title', iconName.charAt(0).toUpperCase() + iconName.slice(1));
icon.setAttribute('aria-label', iconName);
});
// Initialize keyboard shortcuts
initializeKeyboardShortcuts();
// Initialize real-time capabilities indicator
initializeCapabilitiesIndicator();
// Initialize performance monitoring
initializePerformanceMonitor();
});
// Keyboard Shortcuts
function initializeKeyboardShortcuts() {
document.addEventListener('keydown', function(e) {
// Ctrl + / for focus on input
if (e.ctrlKey && e.key === '/') {
e.preventDefault();
const input = document.getElementById('message-input');
if (input) input.focus();
}
// Escape to clear input
if (e.key === 'Escape') {
const input = document.getElementById('message-input');
if (input) input.value = '';
}
// Enter to send (with Ctrl for new line)
if (e.key === 'Enter' && !e.ctrlKey) {
const input = document.getElementById('message-input');
if (input && input === document.activeElement && input.value.trim()) {
document.getElementById('chat-form').dispatchEvent(new Event('submit'));
}
}
});
}
// Real-time Capabilities Indicator
function initializeCapabilitiesIndicator() {
const capabilities = [
'Analyzing real-time data...',
'Searching academic databases...',
'Processing natural language...',
'Generating insights...',
'Cross-referencing sources...'
];
let currentCapability = 0;
setInterval(() => {
const indicator = document.querySelector('.capability-indicator');
if (indicator) {
indicator.style.opacity = '0';
setTimeout(() => {
indicator.textContent = capabilities[currentCapability];
indicator.style.opacity = '1';
currentCapability = (currentCapability + 1) % capabilities.length;
}, 300);
}
}, 3000);
}
// Performance Monitoring
function initializePerformanceMonitor() {
const startTime = performance.now();
window.addEventListener('load', () => {
const loadTime = performance.now() - startTime;
console.log(`DeepChat Pro loaded in ${loadTime.toFixed(2)}ms`);
// Send performance metrics (in a real app, this would go to analytics)
if (loadTime < 1000) {
console.log('๐ Excellent performance!');
}
});
}
// Enhanced Message Management
class MessageManager {
constructor() {
this.messages = [];
this.maxMessages = 100; // Prevent memory issues
}
addMessage(content, sender, type = 'text') {
const message = {
id: Date.now(),
content,
sender,
type,
timestamp: new Date().toISOString(),
metadata: {}
};
this.messages.push(message);
// Keep only the last maxMessages
if (this.messages.length > this.maxMessages) {
this.messages = this.messages.slice(-this.maxMessages);
}
return message;
}
getConversationHistory() {
return this.messages.slice(-10); // Last 10 messages for context
}
clearMessages() {
this.messages = [];
}
}
// Initialize message manager
const messageManager = new MessageManager();
// Enhanced API Integration (simulated for now)
class AIClient {
constructor() {
this.baseURL = 'https://api.deepchat.pro/v1';
this.isOnline = true;
}
async sendMessage(message, context = []) {
// Simulate API call with enhanced capabilities
return new Promise((resolve) => {
setTimeout(() => {
const responses = this.generateEnhancedResponse(message, context);
resolve(responses);
}, 1500 + Math.random() * 1000); // Simulate network delay
});
}
generateEnhancedResponse(message, context) {
// Enhanced response generation simulation
const responseTypes = [
{
type: 'analysis',
content: `I've analyzed "${message}" across multiple dimensions...`,
confidence: 0.92
},
{
type: 'insight',
content: `Key insight: This topic shows strong correlation with recent developments in AI research.`,
confidence: 0.88
},
{
type: 'recommendation',
content: `Based on my analysis, I recommend exploring these 3 areas for deeper understanding.`,
confidence: 0.85
}
];
return responseTypes;
}
}
// Initialize AI Client
const aiClient = new AIClient();
// Utility Functions
const Utils = {
// Format timestamps
formatTime: (date) => {
return new Date(date).toLocaleTimeString('en-US', {
hour12: true,
hour: 'numeric',
minute: '2-digit'
});
},
// Truncate long text
truncate: (text, length = 100) => {
return text.length > length ? text.substring(0, length) + '...' : text;
},
// Copy to clipboard
copyToClipboard: async (text) => {
try {
await navigator.clipboard.writeText(text);
return true;
} catch (err) {
console.error('Failed to copy text: ', err);
return false;
}
},
// Download content
downloadContent: (content, filename) => {
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
};
// Export for global access
window.DeepChatPro = {
messageManager,
aiClient,
Utils,
version: '2.0.0'
};
|