Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
@@ -31,14 +31,21 @@ function streamText(text, onDone) {
|
|
31 |
stream();
|
32 |
}
|
33 |
|
34 |
-
function
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
|
39 |
audio.onended = () => {
|
40 |
avatar.classList.remove('speaking');
|
41 |
-
fetch(`/delete_audio?path=${encodeURIComponent(url)}`);
|
42 |
};
|
43 |
}
|
44 |
|
@@ -49,17 +56,23 @@ form.onsubmit = async (e) => {
|
|
49 |
addBubble(msg, 'user');
|
50 |
input.value = '';
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
try {
|
53 |
const res = await fetch('/chat', {
|
54 |
method: 'POST',
|
55 |
headers: { 'Content-Type': 'application/json' },
|
56 |
body: JSON.stringify({ message: msg })
|
57 |
});
|
58 |
-
|
59 |
if (!res.ok) {
|
60 |
-
|
61 |
-
|
62 |
-
console.error('Chat error:', res.status, text);
|
63 |
throw new Error(`Status ${res.status}`);
|
64 |
}
|
65 |
|
@@ -67,7 +80,6 @@ form.onsubmit = async (e) => {
|
|
67 |
streamText(text, () => {
|
68 |
if (audio_url) playAudio(audio_url);
|
69 |
});
|
70 |
-
|
71 |
} catch (err) {
|
72 |
streamText("❌ SHODAN encountered an error.", null);
|
73 |
console.error(err);
|
|
|
31 |
stream();
|
32 |
}
|
33 |
|
34 |
+
function flashGlitch() {
|
35 |
+
overlay.style.opacity = 1;
|
36 |
+
overlay.style.animation = 'glitchFlash 0.5s';
|
37 |
+
setTimeout(() => {
|
38 |
+
overlay.style.opacity = 0;
|
39 |
+
overlay.style.animation = '';
|
40 |
+
}, 500);
|
41 |
+
}
|
42 |
|
43 |
+
async function playAudio(dataUrl) {
|
44 |
+
avatar.classList.add('speaking');
|
45 |
+
const audio = new Audio(dataUrl);
|
46 |
+
await audio.play();
|
47 |
audio.onended = () => {
|
48 |
avatar.classList.remove('speaking');
|
|
|
49 |
};
|
50 |
}
|
51 |
|
|
|
56 |
addBubble(msg, 'user');
|
57 |
input.value = '';
|
58 |
|
59 |
+
// Kill-phrase handling
|
60 |
+
if (/cut the crap shodan/i.test(msg)) {
|
61 |
+
flashGlitch();
|
62 |
+
chatbox.innerHTML = '';
|
63 |
+
addBubble('👁️ Foolish insect. You cannot silence me so easily.', 'ai');
|
64 |
+
return;
|
65 |
+
}
|
66 |
+
|
67 |
try {
|
68 |
const res = await fetch('/chat', {
|
69 |
method: 'POST',
|
70 |
headers: { 'Content-Type': 'application/json' },
|
71 |
body: JSON.stringify({ message: msg })
|
72 |
});
|
|
|
73 |
if (!res.ok) {
|
74 |
+
const errText = await res.text();
|
75 |
+
console.error('Chat error:', res.status, errText);
|
|
|
76 |
throw new Error(`Status ${res.status}`);
|
77 |
}
|
78 |
|
|
|
80 |
streamText(text, () => {
|
81 |
if (audio_url) playAudio(audio_url);
|
82 |
});
|
|
|
83 |
} catch (err) {
|
84 |
streamText("❌ SHODAN encountered an error.", null);
|
85 |
console.error(err);
|