148 lines
5.2 KiB
JavaScript
Raw Normal View History

2025-06-28 20:26:46 +02:00
// OpenDia Popup
2025-06-13 23:21:32 +02:00
let statusIndicator = document.getElementById("statusIndicator");
let statusText = document.getElementById("statusText");
let toolCount = document.getElementById("toolCount");
2025-06-25 19:07:09 +02:00
let currentPage = document.getElementById("currentPage");
2025-07-12 21:04:26 +02:00
let serverUrl = document.getElementById("serverUrl");
2025-06-13 23:21:32 +02:00
2025-06-27 15:01:01 +02:00
// Get dynamic tool count from background script
function updateToolCount() {
2025-06-28 20:26:46 +02:00
const toolsList = [
"page_analyze", "page_extract_content", "element_click", "element_fill",
"element_get_state", "page_navigate", "page_wait_for", "page_scroll",
"tab_create", "tab_close", "tab_list", "tab_switch",
"get_bookmarks", "add_bookmark", "get_history", "get_selected_text", "get_page_links"
];
2025-06-27 15:01:01 +02:00
if (chrome.runtime?.id) {
chrome.runtime.sendMessage({ action: "getToolCount" }, (response) => {
if (!chrome.runtime.lastError && response?.toolCount) {
2025-06-28 20:26:46 +02:00
toolCount.innerHTML = `<span class="tooltip">${response.toolCount}
<span class="tooltip-content">Available MCP Tools:\npage_analyze page_extract_content element_click element_fill element_get_state page_navigate page_wait_for page_scroll tab_create tab_close tab_list tab_switch get_bookmarks add_bookmark get_history get_selected_text get_page_links</span>
</span>`;
2025-06-27 15:01:01 +02:00
} else {
// Fallback to calculating from background script
2025-06-28 20:26:46 +02:00
toolCount.innerHTML = `<span class="tooltip">17
<span class="tooltip-content">Available MCP Tools:\npage_analyze page_extract_content element_click element_fill element_get_state page_navigate page_wait_for page_scroll tab_create tab_close tab_list tab_switch get_bookmarks add_bookmark get_history get_selected_text get_page_links</span>
</span>`;
2025-06-27 15:01:01 +02:00
}
});
}
}
2025-06-13 23:21:32 +02:00
2025-06-25 19:07:09 +02:00
// Check connection status and get page info
2025-06-13 23:21:32 +02:00
function checkStatus() {
if (chrome.runtime?.id) {
chrome.runtime.sendMessage({ action: "getStatus" }, (response) => {
if (chrome.runtime.lastError) {
updateStatus(false);
} else {
updateStatus(response?.connected || false);
}
});
2025-06-25 19:07:09 +02:00
2025-06-27 15:01:01 +02:00
// Update tool count
updateToolCount();
2025-06-25 19:07:09 +02:00
// Get current page info
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
if (tabs[0]) {
const url = new URL(tabs[0].url);
currentPage.textContent = url.hostname;
}
});
2025-06-13 23:21:32 +02:00
} else {
updateStatus(false);
}
}
// Check status on load and periodically
checkStatus();
setInterval(checkStatus, 2000);
2025-07-12 21:04:26 +02:00
// Update server URL display
function updateServerUrl() {
if (chrome.runtime?.id) {
chrome.runtime.sendMessage({ action: "getPorts" }, (response) => {
if (!chrome.runtime.lastError && response?.websocketUrl) {
serverUrl.textContent = response.websocketUrl;
}
});
}
}
// Update server URL periodically
updateServerUrl();
setInterval(updateServerUrl, 5000);
2025-06-13 23:21:32 +02:00
// Update UI based on connection status
function updateStatus(connected) {
if (connected) {
statusIndicator.className = "status-indicator connected";
2025-06-28 20:26:46 +02:00
statusText.innerHTML = `Connected to MCP server
2025-07-12 21:04:26 +02:00
<span class="tooltip-content">Connected successfully! Server auto-discovery is working. Default ports: WebSocket=5555, HTTP=5556</span>`;
2025-06-13 23:21:32 +02:00
} else {
statusIndicator.className = "status-indicator disconnected";
2025-06-28 20:26:46 +02:00
statusText.innerHTML = `Disconnected from MCP server
2025-07-15 17:33:03 +02:00
<span class="tooltip-content">Start server with: npx opendia. Auto-discovery will find the correct ports. Existing processes are automatically terminated on startup</span>`;
2025-06-13 23:21:32 +02:00
}
}
// Reconnect button
document.getElementById("reconnectBtn").addEventListener("click", () => {
if (chrome.runtime?.id) {
chrome.runtime.sendMessage({ action: "reconnect" }, (response) => {
2025-06-28 20:26:46 +02:00
if (!chrome.runtime.lastError) {
2025-06-13 23:21:32 +02:00
setTimeout(checkStatus, 1000);
}
});
}
});
// Listen for updates from background script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "statusUpdate") {
updateStatus(message.connected);
}
2025-06-28 20:26:46 +02:00
});
// Video speed control based on mouse movement
const logoVideo = document.querySelector('.logo video');
let mouseTimeout;
let lastMouseX = 0;
let lastMouseY = 0;
let mouseSpeed = 0;
if (logoVideo) {
// Track mouse movement and calculate speed
document.addEventListener('mousemove', (e) => {
const deltaX = e.clientX - lastMouseX;
const deltaY = e.clientY - lastMouseY;
// Calculate mouse speed (distance moved)
mouseSpeed = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// Update video playback rate based on mouse speed
// Faster mouse = faster video (clamped between 0.2x and 10x)
// Very sensitive to mouse movement (divided by 15 for more responsiveness)
const playbackRate = Math.min(10, Math.max(0.2, 1 + (mouseSpeed / 15)));
logoVideo.playbackRate = playbackRate;
lastMouseX = e.clientX;
lastMouseY = e.clientY;
// Clear existing timeout
clearTimeout(mouseTimeout);
// Reset to normal speed after mouse stops
mouseTimeout = setTimeout(() => {
logoVideo.playbackRate = 1;
}, 100);
});
// Set initial playback rate
logoVideo.playbackRate = 1;
}