File size: 8,846 Bytes
940c962 8443bb0 940c962 8443bb0 940c962 8443bb0 940c962 8443bb0 940c962 8443bb0 940c962 8443bb0 940c962 8443bb0 940c962 8443bb0 940c962 | 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 | document.addEventListener('DOMContentLoaded', () => {
// Initialize
const loginScreen = document.getElementById('login-screen');
const appContainer = document.getElementById('app-container');
const loginBtn = document.getElementById('login-btn');
const chatInterface = document.getElementById('chat-interface');
const minimizeChat = document.getElementById('minimize-chat');
const chatInput = document.getElementById('chat-input');
const sendChat = document.getElementById('send-chat');
const chatMessages = document.getElementById('chat-messages');
const webview = document.getElementById('main-webview');
const loadingOverlay = document.getElementById('loading-overlay');
const tabBar = document.getElementById('tab-bar');
// Simulate login
loginBtn.addEventListener('click', () => {
loginScreen.classList.add('motion-blur-active');
setTimeout(() => {
loginScreen.classList.add('hidden');
loginScreen.classList.remove('motion-blur-active');
appContainer.classList.remove('hidden');
// Add first tab - fallback to DuckDuckGo if Google fails
addNewTab('New Tab', 'https://www.google.com').catch(() => {
addNewTab('New Tab', 'https://duckduckgo.com');
});
// Show chat after slight delay
setTimeout(() => {
chatInterface.classList.remove('hidden');
chatInterface.classList.add('animate-slideIn');
// Add welcome message
addChatMessage('agent', 'Hello! How can I help you today?');
}, 1000);
}, 300);
});
// Chat functionality
let isChatMinimized = false;
minimizeChat.addEventListener('click', () => {
isChatMinimized = !isChatMinimized;
const messagesContainer = chatInterface.querySelector('#chat-messages');
const inputContainer = chatInterface.querySelector('div:last-child');
if (isChatMinimized) {
messagesContainer.classList.add('hidden');
inputContainer.classList.add('hidden');
minimizeChat.innerHTML = feather.icons.maximize.toSvg();
} else {
messagesContainer.classList.remove('hidden');
inputContainer.classList.remove('hidden');
minimizeChat.innerHTML = feather.icons.minus.toSvg();
}
});
function addChatMessage(sender, text) {
const messageDiv = document.createElement('div');
messageDiv.className = `chat-bubble ${sender} animate-slideIn`;
messageDiv.textContent = text;
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
sendChat.addEventListener('click', () => {
const message = chatInput.value.trim();
if (message) {
addChatMessage('user', message);
chatInput.value = '';
// Simulate response
setTimeout(() => {
const responses = [
"I'm here to help with any proxy issues!",
"Would you like me to check your connection?",
"Our servers are operating normally.",
"Try clearing your cache if you're having issues.",
"You can bookmark the current page for later."
];
addChatMessage('agent', responses[Math.floor(Math.random() * responses.length)]);
}, 1000);
}
});
chatInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendChat.click();
}
});
// Tab management
let tabs = [];
let activeTabIndex = 0;
function addNewTab(title, url) {
return new Promise((resolve, reject) => {
const tabId = Date.now();
const tab = {
id: tabId,
title: title,
url: url,
favicon: null
};
tabs.push(tab);
activeTabIndex = tabs.length - 1;
renderTabs();
navigateToUrl(url).then(resolve).catch(reject);
}
function renderTabs() {
tabBar.innerHTML = '';
tabs.forEach((tab, index) => {
const tabElement = document.createElement('div');
tabElement.className = `tab flex items-center px-4 py-2 cursor-pointer text-sm border-r border-gray-700 ${index === activeTabIndex ? 'active bg-gray-900 text-fuchsia-300' : 'text-gray-400 hover:bg-gray-700'}`;
tabElement.innerHTML = `
${tab.favicon ? `<img src="${tab.favicon}" class="w-4 h-4 mr-2">` : `<i data-feather="globe" class="w-4 h-4 mr-2"></i>`}
<span class="truncate max-w-xs">${tab.title}</span>
<button class="ml-2 text-gray-400 hover:text-white">
<i data-feather="x" class="w-4 h-4"></i>
</button>
`;
tabElement.addEventListener('click', () => {
switchToTab(index);
});
const closeBtn = tabElement.querySelector('button');
closeBtn.addEventListener('click', (e) => {
e.stopPropagation();
closeTab(index);
});
tabBar.appendChild(tabElement);
});
// Add new tab button
const newTabBtn = document.createElement('div');
newTabBtn.className = 'flex items-center px-3 py-2 cursor-pointer text-gray-400 hover:text-fuchsia-400';
newTabBtn.innerHTML = `<i data-feather="plus" class="w-4 h-4"></i>`;
newTabBtn.addEventListener('click', () => {
addNewTab('New Tab', 'https://www.google.com');
});
tabBar.appendChild(newTabBtn);
feather.replace();
}
function switchToTab(index) {
if (index >= 0 && index < tabs.length) {
activeTabIndex = index;
const tab = tabs[activeTabIndex];
navigateToUrl(tab.url).catch(() => {
// If navigation fails, fall back to DuckDuckGo
tab.url = 'https://duckduckgo.com';
navigateToUrl(tab.url);
});
renderTabs();
}
}
function closeTab(index) {
if (tabs.length <= 1) {
// Don't close the last tab
return;
}
tabs.splice(index, 1);
if (activeTabIndex >= index) {
activeTabIndex = Math.max(0, activeTabIndex - 1);
}
if (tabs.length > 0) {
const tab = tabs[activeTabIndex];
navigateToUrl(tab.url);
}
renderTabs();
}
function navigateToUrl(url) {
return new Promise((resolve, reject) => {
loadingOverlay.classList.remove('hidden');
webview.classList.add('opacity-0');
setTimeout(() => {
webview.src = url;
const errorHandler = () => {
webview.removeEventListener('error', errorHandler);
loadingOverlay.classList.add('hidden');
webview.classList.remove('opacity-0');
reject();
};
webview.addEventListener('error', errorHandler);
webview.onload = () => {
webview.removeEventListener('error', errorHandler);
setTimeout(() => {
loadingOverlay.classList.add('hidden');
webview.classList.remove('opacity-0');
resolve();
// Update tab title
try {
const title = webview.contentDocument.title || new URL(webview.src).hostname;
tabs[activeTabIndex].title = title;
// Try to get favicon
const favicon = webview.contentDocument.querySelector('link[rel*="icon"]');
if (favicon) {
const faviconUrl = new URL(favicon.href, webview.src).href;
tabs[activeTabIndex].favicon = faviconUrl;
}
renderTabs();
} catch (e) {
console.log("Couldn't access iframe document due to CORS");
}
}, 300);
};
}, 300);
}
// Initialize with one tab
window.addEventListener('load', () => {
// In a real proxy, you would handle the actual proxying here
// This is just the UI implementation
});
}); |