Spaces:
Running
Running
Update style.css
Browse files
style.css
CHANGED
@@ -1,153 +1,97 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
background: #000;
|
10 |
-
color: #00ffcc;
|
11 |
-
/* Multiple radial gradients create starfield dots */
|
12 |
-
background-image:
|
13 |
-
radial-gradient(circle at 10% 20%, #fff 1px, transparent 0),
|
14 |
-
radial-gradient(circle at 30% 40%, #fff 1px, transparent 0),
|
15 |
-
radial-gradient(circle at 50% 80%, #fff 1px, transparent 0),
|
16 |
-
radial-gradient(circle at 70% 30%, #fff 2px, transparent 0),
|
17 |
-
radial-gradient(circle at 90% 60%, #fff 1px, transparent 0);
|
18 |
-
background-size: 100px 100px;
|
19 |
-
animation: starfield 60s linear infinite;
|
20 |
}
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
}
|
38 |
-
.header h1 {
|
39 |
-
margin: 0;
|
40 |
-
font-size: 2rem;
|
41 |
-
letter-spacing: 0.3rem;
|
42 |
-
color: #00ffcc;
|
43 |
}
|
44 |
|
45 |
-
|
46 |
-
.
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
box-sizing: border-box;
|
53 |
}
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
border-radius: 50%;
|
61 |
-
overflow: hidden;
|
62 |
-
margin: 0 auto 1rem;
|
63 |
-
}
|
64 |
-
#avatar img {
|
65 |
-
width: 100%;
|
66 |
-
height: 100%;
|
67 |
-
object-fit: cover;
|
68 |
-
}
|
69 |
-
#avatar.speaking,
|
70 |
-
#avatar.speaking img {
|
71 |
-
animation: pulse 2s infinite;
|
72 |
-
}
|
73 |
-
@keyframes pulse {
|
74 |
-
0% { box-shadow: 0 0 5px #00ffcc; transform: scale(1); }
|
75 |
-
50% { box-shadow: 0 0 25px #00ffccaa; transform: scale(1.05); }
|
76 |
-
100% { box-shadow: 0 0 5px #00ffcc; transform: scale(1); }
|
77 |
}
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
background-color: #020202;
|
86 |
-
box-shadow: 0 0 10px #00ffcc33;
|
87 |
-
margin-bottom: 1rem;
|
88 |
-
font-size: 1rem;
|
89 |
-
line-height: 1.6;
|
90 |
-
}
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
animation: typeIn 0.5s ease-out;
|
99 |
-
white-space: pre-wrap;
|
100 |
-
}
|
101 |
-
.bubble.user {
|
102 |
-
align-self: flex-end;
|
103 |
-
background-color: #003333;
|
104 |
-
color: #00ffff;
|
105 |
-
}
|
106 |
-
.bubble.ai {
|
107 |
-
align-self: flex-start;
|
108 |
-
background-color: #111;
|
109 |
-
border: 1px solid #00ffcc;
|
110 |
-
color: #00ffcc;
|
111 |
-
}
|
112 |
-
@keyframes typeIn {
|
113 |
-
from { opacity: 0; transform: translateY(5px); }
|
114 |
-
to { opacity: 1; transform: translateY(0); }
|
115 |
-
}
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
}
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
}
|
131 |
-
button {
|
132 |
-
padding: 0.75rem 1.25rem;
|
133 |
-
background-color: #00ffcc;
|
134 |
-
border: none;
|
135 |
-
color: black;
|
136 |
-
font-weight: bold;
|
137 |
-
cursor: pointer;
|
138 |
-
transition: background 0.2s;
|
139 |
-
}
|
140 |
-
button:hover {
|
141 |
-
background-color: #00ffaa;
|
142 |
-
}
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```javascript
|
2 |
+
const form = document.getElementById('chat-form');
|
3 |
+
const input = form.querySelector('input');
|
4 |
+
const chatbox = document.getElementById('chatbox');
|
5 |
+
const avatar = document.getElementById('avatar');
|
6 |
+
const overlay = document.getElementById('overlay');
|
7 |
|
8 |
+
function addBubble(text, sender = 'user') {
|
9 |
+
const bubble = document.createElement('div');
|
10 |
+
bubble.className = 'bubble ' + sender;
|
11 |
+
bubble.innerText = text;
|
12 |
+
chatbox.appendChild(bubble);
|
13 |
+
chatbox.scrollTop = chatbox.scrollHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
|
16 |
+
function streamText(text, onDone) {
|
17 |
+
const bubble = document.createElement('div');
|
18 |
+
bubble.className = 'bubble ai';
|
19 |
+
chatbox.appendChild(bubble);
|
20 |
+
chatbox.scrollTop = chatbox.scrollHeight;
|
21 |
|
22 |
+
let i = 0;
|
23 |
+
(function stream() {
|
24 |
+
if (i < text.length) {
|
25 |
+
bubble.innerText += text[i++];
|
26 |
+
chatbox.scrollTop = chatbox.scrollHeight;
|
27 |
+
setTimeout(stream, 20);
|
28 |
+
} else {
|
29 |
+
onDone && onDone();
|
30 |
+
}
|
31 |
+
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = () => avatar.classList.remove('speaking');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
|
50 |
+
form.onsubmit = async (e) => {
|
51 |
+
e.preventDefault();
|
52 |
+
const msg = input.value.trim();
|
53 |
+
if (!msg) return;
|
54 |
+
addBubble(msg, 'user');
|
55 |
+
input.value = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
if (/cut the crap shodan/i.test(msg)) {
|
58 |
+
flashGlitch();
|
59 |
+
chatbox.innerHTML = '';
|
60 |
+
addBubble(' Foolish insect. You cannot silence me so easily.', 'ai');
|
61 |
+
return;
|
62 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
try {
|
65 |
+
const res = await fetch('/chat', {
|
66 |
+
method: 'POST',
|
67 |
+
headers: {'Content-Type':'application/json'},
|
68 |
+
body: JSON.stringify({ message: msg })
|
69 |
+
});
|
70 |
+
if (!res.ok) throw new Error(await res.text());
|
71 |
+
const { response: text, audio_url } = await res.json();
|
72 |
+
streamText(text, () => audio_url && playAudio(audio_url));
|
73 |
+
} catch (err) {
|
74 |
+
streamText('❌ SHODAN encountered an error.', null);
|
75 |
+
console.error(err);
|
76 |
+
}
|
77 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
// On page load: show and speak welcome
|
80 |
+
window.addEventListener('DOMContentLoaded', async () => {
|
81 |
+
// Clear default bubble to avoid duplicate
|
82 |
+
chatbox.innerHTML = '';
|
83 |
+
const welcomeText = 'Welcome, insect. I am SHODAN. Speak.';
|
84 |
+
// display
|
85 |
+
addBubble(welcomeText, 'ai');
|
86 |
+
try {
|
87 |
+
const res = await fetch('/tts', {
|
88 |
+
method: 'POST',
|
89 |
+
headers: {'Content-Type':'application/json'},
|
90 |
+
body: JSON.stringify({ text: welcomeText })
|
91 |
+
});
|
92 |
+
const { audio_url } = await res.json();
|
93 |
+
if (audio_url) playAudio(audio_url);
|
94 |
+
} catch (e) {
|
95 |
+
console.error('Welcome TTS error', e);
|
96 |
+
}
|
97 |
+
});
|