Spaces:
Running
Running
Update app/frontend/script.js
Browse files- app/frontend/script.js +73 -7
app/frontend/script.js
CHANGED
|
@@ -29,12 +29,12 @@ function hideLoading(button, originalText) {
|
|
| 29 |
|
| 30 |
function getScoreLevel(score) {
|
| 31 |
if (score < 0.4) {
|
| 32 |
-
return { className: 'good', icon: '
|
| 33 |
}
|
| 34 |
if (score < 0.7) {
|
| 35 |
-
return { className: 'warn', icon: '
|
| 36 |
}
|
| 37 |
-
return { className: 'bad', icon: '
|
| 38 |
}
|
| 39 |
|
| 40 |
function formatScore(score) {
|
|
@@ -197,9 +197,9 @@ async function analyzeText() {
|
|
| 197 |
const verdictClass = data.binary_verdict;
|
| 198 |
const verdictText = verdictClass.charAt(0).toUpperCase() + verdictClass.slice(1);
|
| 199 |
const verdictIcons = {
|
| 200 |
-
'pass': '
|
| 201 |
-
'warn': '
|
| 202 |
-
'fail': '
|
| 203 |
};
|
| 204 |
|
| 205 |
binaryResult.innerHTML = `
|
|
@@ -403,7 +403,9 @@ function initThemeToggle() {
|
|
| 403 |
const updateIcon = (isDark) => {
|
| 404 |
themeToggle.setAttribute('aria-pressed', isDark ? 'true' : 'false');
|
| 405 |
if (themeIcon) {
|
| 406 |
-
|
|
|
|
|
|
|
| 407 |
}
|
| 408 |
};
|
| 409 |
|
|
@@ -422,6 +424,68 @@ function initThemeToggle() {
|
|
| 422 |
});
|
| 423 |
}
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
// Initialize app
|
| 426 |
document.addEventListener('DOMContentLoaded', () => {
|
| 427 |
initTabs();
|
|
@@ -430,6 +494,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 430 |
initModelSelectorGC();
|
| 431 |
initEventListeners();
|
| 432 |
initThemeToggle();
|
|
|
|
|
|
|
| 433 |
|
| 434 |
console.log('LionGuard 2 app initialized');
|
| 435 |
});
|
|
|
|
| 29 |
|
| 30 |
function getScoreLevel(score) {
|
| 31 |
if (score < 0.4) {
|
| 32 |
+
return { className: 'good', icon: '<i class="bx bx-check-circle"></i>', title: 'Low risk' };
|
| 33 |
}
|
| 34 |
if (score < 0.7) {
|
| 35 |
+
return { className: 'warn', icon: '<i class="bx bx-error"></i>', title: 'Needs review' };
|
| 36 |
}
|
| 37 |
+
return { className: 'bad', icon: '<i class="bx bx-error-circle"></i>', title: 'High risk' };
|
| 38 |
}
|
| 39 |
|
| 40 |
function formatScore(score) {
|
|
|
|
| 197 |
const verdictClass = data.binary_verdict;
|
| 198 |
const verdictText = verdictClass.charAt(0).toUpperCase() + verdictClass.slice(1);
|
| 199 |
const verdictIcons = {
|
| 200 |
+
'pass': '<i class="bx bx-check-shield"></i>',
|
| 201 |
+
'warn': '<i class="bx bx-shield-minus"></i>',
|
| 202 |
+
'fail': '<i class="bx bx-shield-x"></i>'
|
| 203 |
};
|
| 204 |
|
| 205 |
binaryResult.innerHTML = `
|
|
|
|
| 403 |
const updateIcon = (isDark) => {
|
| 404 |
themeToggle.setAttribute('aria-pressed', isDark ? 'true' : 'false');
|
| 405 |
if (themeIcon) {
|
| 406 |
+
// Toggle class for boxicons
|
| 407 |
+
themeIcon.className = isDark ? 'bx bx-moon theme-icon' : 'bx bx-sun theme-icon';
|
| 408 |
+
themeIcon.textContent = ''; // clear text content
|
| 409 |
}
|
| 410 |
};
|
| 411 |
|
|
|
|
| 424 |
});
|
| 425 |
}
|
| 426 |
|
| 427 |
+
// Code snippet tabs for Get Started
|
| 428 |
+
function initCodeTabs() {
|
| 429 |
+
const tabs = document.querySelectorAll('.code-tab');
|
| 430 |
+
const blocks = document.querySelectorAll('.code-block');
|
| 431 |
+
|
| 432 |
+
if (!tabs.length) return;
|
| 433 |
+
|
| 434 |
+
tabs.forEach(tab => {
|
| 435 |
+
tab.addEventListener('click', () => {
|
| 436 |
+
// Remove active class from all tabs
|
| 437 |
+
tabs.forEach(t => t.classList.remove('active'));
|
| 438 |
+
// Add active class to clicked tab
|
| 439 |
+
tab.classList.add('active');
|
| 440 |
+
|
| 441 |
+
// Hide all blocks
|
| 442 |
+
blocks.forEach(b => b.classList.remove('active'));
|
| 443 |
+
|
| 444 |
+
// Show target block
|
| 445 |
+
const targetId = `code-${tab.dataset.code}`;
|
| 446 |
+
const targetBlock = document.getElementById(targetId);
|
| 447 |
+
if (targetBlock) {
|
| 448 |
+
targetBlock.classList.add('active');
|
| 449 |
+
}
|
| 450 |
+
});
|
| 451 |
+
});
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
// Copy Code Functionality
|
| 455 |
+
function initCopyButton() {
|
| 456 |
+
const copyBtn = document.getElementById('copy-code-btn');
|
| 457 |
+
if (!copyBtn) return;
|
| 458 |
+
|
| 459 |
+
copyBtn.addEventListener('click', async () => {
|
| 460 |
+
// Find active code block
|
| 461 |
+
const activeBlock = document.querySelector('.code-block.active code');
|
| 462 |
+
if (!activeBlock) return;
|
| 463 |
+
|
| 464 |
+
const textToCopy = activeBlock.textContent;
|
| 465 |
+
|
| 466 |
+
try {
|
| 467 |
+
await navigator.clipboard.writeText(textToCopy);
|
| 468 |
+
|
| 469 |
+
// Provide feedback
|
| 470 |
+
const originalHtml = copyBtn.innerHTML;
|
| 471 |
+
copyBtn.innerHTML = `<i class='bx bx-check'></i> Copied!`;
|
| 472 |
+
copyBtn.classList.add('success');
|
| 473 |
+
|
| 474 |
+
setTimeout(() => {
|
| 475 |
+
copyBtn.innerHTML = originalHtml;
|
| 476 |
+
copyBtn.classList.remove('success');
|
| 477 |
+
}, 2000);
|
| 478 |
+
} catch (err) {
|
| 479 |
+
console.error('Failed to copy:', err);
|
| 480 |
+
copyBtn.innerHTML = `<i class='bx bx-x'></i> Failed`;
|
| 481 |
+
|
| 482 |
+
setTimeout(() => {
|
| 483 |
+
copyBtn.innerHTML = `<i class='bx bx-copy'></i> Copy`;
|
| 484 |
+
}, 2000);
|
| 485 |
+
}
|
| 486 |
+
});
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
// Initialize app
|
| 490 |
document.addEventListener('DOMContentLoaded', () => {
|
| 491 |
initTabs();
|
|
|
|
| 494 |
initModelSelectorGC();
|
| 495 |
initEventListeners();
|
| 496 |
initThemeToggle();
|
| 497 |
+
initCodeTabs();
|
| 498 |
+
initCopyButton();
|
| 499 |
|
| 500 |
console.log('LionGuard 2 app initialized');
|
| 501 |
});
|