Spaces:
Paused
Paused
Download phishvision-extension/popup.js from paras9909/opticparse-python: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/spaces/paras9909/opticparse-python/resolve/main/phishvision-extension/popup.js
- Command line
-
hf download hf://spaces/paras9909/opticparse-python/phishvision-extension/popup.js
-
curl -L -o popup.js https://huggingface.co/spaces/paras9909/opticparse-python/resolve/main/phishvision-extension/popup.js
2.12 kB
| document.getElementById('scanBtn').addEventListener('click', async () => { | |
| const statusDiv = document.getElementById('status'); | |
| const resultDiv = document.getElementById('result'); | |
| const detailsDiv = document.getElementById('details'); | |
| const scanBtn = document.getElementById('scanBtn'); | |
| statusDiv.textContent = "Capturing active tab..."; | |
| resultDiv.style.display = 'none'; | |
| resultDiv.className = ''; | |
| detailsDiv.textContent = ''; | |
| scanBtn.disabled = true; | |
| try { | |
| const tabs = await chrome.tabs.query({ active: true, currentWindow: true }); | |
| if (tabs.length === 0) { | |
| throw new Error("No active tab found"); | |
| } | |
| const activeTab = tabs[0]; | |
| const dataUrl = await chrome.tabs.captureVisibleTab(activeTab.windowId, { format: 'png' }); | |
| // Strip the data URL prefix if needed, or let the backend handle it. | |
| // We send the raw Base64 image | |
| const base64Image = dataUrl.split(',')[1] || dataUrl; | |
| statusDiv.textContent = "Analyzing with PhishVision AI..."; | |
| // Call the live Node.js PhishVision endpoint | |
| const response = await fetch('https://opticparse-1opticparse-node-sg.onrender.com/api/phishvision/scan', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify({ image_base64: base64Image }) | |
| }); | |
| if (!response.ok) { | |
| const errorText = await response.text(); | |
| throw new Error(`API Error ${response.status}: ${errorText}`); | |
| } | |
| const data = await response.json(); | |
| statusDiv.textContent = "Analysis complete."; | |
| resultDiv.style.display = 'block'; | |
| if (data.is_malicious || data.threat_level === "HIGH") { | |
| resultDiv.textContent = "⚠️ MALICIOUS PAGE DETECTED"; | |
| resultDiv.classList.add('malicious'); | |
| } else { | |
| resultDiv.textContent = "✅ PAGE APPEARS SAFE"; | |
| resultDiv.classList.add('safe'); | |
| } | |
| if (data.analysis) { | |
| detailsDiv.textContent = `Analysis: ${data.analysis}`; | |
| } | |
| } catch (err) { | |
| statusDiv.textContent = `Error: ${err.message}`; | |
| } finally { | |
| scanBtn.disabled = false; | |
| } | |
| }); | |