@ywkrlerche/richardwho 1.0.38 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,71 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <script src="sounds.js" type="module"></script>
6
+ <script src="main.js?v=4" type="module"></script>
7
+ <link href="style.css?v=4" rel="stylesheet">
8
+ </head>
9
+
10
+ <body>
11
+ <div id="controls">
12
+ <button id="toggleFavorites" class="control-button favorites-toggle">⭐ Favorites: OFF</button>
13
+ <button id="toggleButton" class="control-button overlap-toggle">🔇 Overlap: OFF</button>
14
+ <button id="stopButton" class="control-button stop-button">⏹️ Stop All Sounds</button>
15
+ <input id="searchInput" type="text" placeholder="Search sounds...">
16
+ <select id="sortSelect" class="control-button sort-select" aria-label="Sort sounds">
17
+ <option value="popular">🔥 Popular</option>
18
+ <option value="mine">🔁 My most used</option>
19
+ </select>
20
+ <button id="ttsToggle" class="control-button tts-toggle">🗣️ Text-to-Speech</button>
21
+ </div>
22
+ <div id="ttsPanel" class="tts-panel hidden">
23
+ <div class="tts-panel-header">
24
+ <span class="tts-title">🎙️ Text-to-Speech</span>
25
+ <button id="ttsClose" class="tts-close">✕</button>
26
+ </div>
27
+ <textarea id="ttsText" class="tts-textarea" placeholder="Type something to speak..."></textarea>
28
+ <div class="tts-controls-grid">
29
+ <div class="tts-control-group full-width">
30
+ <label class="tts-label">Voice</label>
31
+ <select id="ttsVoice" class="tts-select"></select>
32
+ </div>
33
+ <div class="tts-control-group">
34
+ <label class="tts-label">Volume <span id="ttsVolumeVal" class="tts-val">1.0</span></label>
35
+ <input type="range" id="ttsVolume" class="tts-slider" min="0" max="1" step="0.05" value="1">
36
+ </div>
37
+ <div class="tts-control-group">
38
+ <label class="tts-label">Rate <span id="ttsRateVal" class="tts-val">1.0</span></label>
39
+ <input type="range" id="ttsRate" class="tts-slider" min="0.1" max="10" step="0.1" value="1">
40
+ </div>
41
+ <div class="tts-control-group">
42
+ <label class="tts-label">Pitch <span id="ttsPitchVal" class="tts-val">1.0</span></label>
43
+ <input type="range" id="ttsPitch" class="tts-slider" min="0" max="2" step="0.05" value="1">
44
+ </div>
45
+ <div class="tts-control-group">
46
+ <label class="tts-label">Filter by Lang</label>
47
+ <select id="ttsLangFilter" class="tts-select"></select>
48
+ </div>
49
+
50
+ </div>
51
+
52
+ <div id="ttsStatus" class="tts-status">Ready</div>
53
+
54
+ <div class="tts-actions">
55
+ <button id="ttsSpeak" class="tts-btn tts-btn-speak">▶ Speak</button>
56
+ <button id="ttsPause" class="tts-btn tts-btn-pause" disabled>⏸ Pause</button>
57
+ <button id="ttsResume" class="tts-btn tts-btn-resume" disabled>▶ Resume</button>
58
+ <button id="ttsStop" class="tts-btn tts-btn-stop" disabled>⏹ Stop</button>
59
+ <button id="ttsReset" class="tts-btn tts-btn-reset">↺ Reset</button>
60
+ </div>
61
+
62
+ <div id="ttsSpeaking" class="tts-speaking-display hidden">
63
+ <span class="tts-speaking-label">Now speaking:</span>
64
+ <span id="ttsCurrentWord" class="tts-current-word"></span>
65
+ </div>
66
+ </div>
67
+
68
+ <div id="soundboard"></div>
69
+ </body>
70
+
71
+ </html>
@@ -0,0 +1,356 @@
1
+ import {
2
+ sounds
3
+ } from './sounds.js?v=4';
4
+ const stats = (() => { try { return parent.rugSoundStats || null; } catch { return null; } })();
5
+ const USES_KEY = "rug-sound-uses", SORT_KEY = "rug-sound-sort";
6
+ const soundKey = (sound) => sound.mp3.split("/").pop().replace(/\.mp3$/i, "");
7
+ const order = new Map(sounds.map((s, i) => [s.mp3, i]));
8
+ let popular = {};
9
+ let myUses = {};
10
+ try { myUses = JSON.parse(localStorage.getItem(USES_KEY) || "{}"); } catch {}
11
+ let sortMode = "popular";
12
+ try { sortMode = localStorage.getItem(SORT_KEY) || "popular"; } catch {}
13
+ let lastCounted = 0;
14
+ function noteUse(sound) {
15
+ const key = soundKey(sound);
16
+ myUses[key] = (myUses[key] || 0) + 1;
17
+ try { localStorage.setItem(USES_KEY, JSON.stringify(myUses)); } catch {}
18
+ // everyone's count: at most one every 4s per person (the database refuses faster ones)
19
+ if (stats && Date.now() - lastCounted > 4100) {
20
+ lastCounted = Date.now();
21
+ popular[key] = (popular[key] || 0) + 1;
22
+ stats.count(key);
23
+ }
24
+ }
25
+ function sortSounds(list) {
26
+ const pop = (s) => popular[soundKey(s)] || 0, mine = (s) => myUses[soundKey(s)] || 0;
27
+ const byOrder = (a, b) => order.get(a.mp3) - order.get(b.mp3);
28
+ return [...list].sort(sortMode === "mine"
29
+ ? (a, b) => mine(b) - mine(a) || pop(b) - pop(a) || byOrder(a, b)
30
+ : (a, b) => pop(b) - pop(a) || byOrder(a, b));
31
+ }
32
+ const soundUrl = (mp3) => mp3.startsWith("sounds/") ? new URL(mp3, document.baseURI).href : "https://cdn.jsdelivr.net/gh/genizymath/soundboard@main/" + mp3;
33
+ let allowOverlap = false;
34
+ let showFavorites = false;
35
+ let currentAudios = [];
36
+ const toggleButton = document.getElementById('toggleButton');
37
+ const stopButton = document.getElementById('stopButton');
38
+ const searchInput = document.getElementById('searchInput');
39
+ const favoriteButton = document.getElementById('toggleFavorites')
40
+ const soundBoard = document.getElementById('soundboard');
41
+ toggleButton.onclick = () => {
42
+ allowOverlap = !allowOverlap;
43
+ toggleButton.textContent = allowOverlap ? '🔊 Overlap: ON' : '🔇 Overlap: OFF';
44
+ };
45
+ stopButton.onclick = () => {
46
+ currentAudios.forEach(a => a.pause());
47
+ currentAudios = [];
48
+ };
49
+ favoriteButton.onclick = () => {
50
+ showFavorites = !showFavorites;
51
+ favoriteButton.textContent = showFavorites ? '🌟 Favorites: ON' : '⭐ Favorites: OFF';
52
+ renderSounds(showFavorites ? "filter:favorite "+searchInput.value : searchInput.value);
53
+ }
54
+
55
+ function renderSounds(filter = '') {
56
+ soundBoard.innerHTML = '';
57
+ let finalSound;
58
+ if (filter.startsWith("filter:favorite ")) {
59
+ finalSound = (localStorage.getItem('favorites') ? JSON.parse(localStorage.getItem('favorites')) : [])
60
+ .filter(s => s.name.toLowerCase().includes(filter.toLowerCase().replace('filter:favorite ', '')));
61
+ } else {
62
+ finalSound = sounds.filter(s => s.name.toLowerCase().includes(filter.toLowerCase()));
63
+ }
64
+ finalSound = sortSounds(finalSound);
65
+ finalSound.forEach(sound => {
66
+ const wrapper = document.createElement('div');
67
+ wrapper.className = 'sound-wrapper';
68
+ const button = document.createElement('button');
69
+ wrapper.addEventListener("contextmenu", (e) => {
70
+ rightClickPanel(e, wrapper, sound);
71
+ });
72
+ button.className = 'sound-button-img';
73
+ button.style.setProperty('--btn-color', sound.color);
74
+ const image = document.createElement('div');
75
+ image.className = 'sound-image';
76
+ button.appendChild(image);
77
+ button.onclick = () => {
78
+ if (!allowOverlap) {
79
+ currentAudios.forEach(a => a.pause());
80
+ currentAudios = [];
81
+ }
82
+ noteUse(sound);
83
+ const audio = new Audio(soundUrl(sound.mp3));
84
+ audio.play();
85
+ currentAudios.push(audio);
86
+ image.classList.add('pressed');
87
+ setTimeout(() => image.classList.remove('pressed'), 150);
88
+ };
89
+ const label = document.createElement('div');
90
+ label.className = 'sound-label';
91
+ label.textContent = sound.name;
92
+ wrapper.appendChild(button);
93
+ wrapper.appendChild(label);
94
+ soundBoard.appendChild(wrapper);
95
+ });
96
+ }
97
+ const currentFilter = () => (showFavorites ? "filter:favorite " : "") + searchInput.value;
98
+ const sortSelect = document.getElementById('sortSelect');
99
+ sortSelect.value = sortMode;
100
+ sortSelect.onchange = () => {
101
+ sortMode = sortSelect.value;
102
+ try { localStorage.setItem(SORT_KEY, sortMode); } catch {}
103
+ renderSounds(currentFilter());
104
+ };
105
+ renderSounds(currentFilter());
106
+ if (stats) stats.counts().then((c) => { popular = c; renderSounds(currentFilter()); });
107
+ searchInput.addEventListener('input', () => {
108
+ renderSounds((showFavorites? "filter:favorite ": "")+searchInput.value);
109
+ });
110
+
111
+ function rightClickPanel(event, button, sound) {
112
+ document.querySelectorAll('.right-click-panel').forEach(p => p.remove());
113
+
114
+ const panel = document.createElement('div');
115
+ panel.className = 'right-click-panel';
116
+ panel.style.setProperty('--btn-color', button.style.getPropertyValue('--btn-color'));
117
+ panel.style.position = 'absolute';
118
+ panel.style.left = `${event.pageX}px`;
119
+ panel.style.top = `${event.pageY}px`;
120
+
121
+ // favorite button
122
+ let favoriteJson = localStorage.getItem('favorites') ? JSON.parse(localStorage.getItem('favorites')) : [];
123
+ const favorite = document.createElement('button');
124
+ favorite.className = 'right-click-panel-button';
125
+ const isFavorite = favoriteJson.some(item => item.name === sound.name);
126
+ favorite.textContent = isFavorite ? '⭐ Unfavorite' : "🌟 Favorite";
127
+
128
+ favorite.onclick = () => {
129
+ const isFavorite = favoriteJson.some(item => item.name === sound.name);
130
+ if (isFavorite) {
131
+ favoriteJson = favoriteJson.filter(item => item.name !== sound.name);
132
+ if (showFavorites) {
133
+ renderSounds("filter:favorite "+searchInput.value);
134
+ }
135
+ } else {
136
+ favoriteJson.push(sound);
137
+ }
138
+ localStorage.setItem("favorites", JSON.stringify(favoriteJson));
139
+ panel.remove();
140
+ };
141
+
142
+ // download button
143
+ const download = document.createElement('button');
144
+ download.className = 'right-click-panel-button';
145
+ download.textContent = '💾 Download';
146
+
147
+ download.onclick = () => {
148
+ const link = document.createElement('a');
149
+ link.href = soundUrl(sound.mp3);
150
+ link.download = sound.mp3.split("/").pop();
151
+ document.body.appendChild(link);
152
+ link.click();
153
+ document.body.removeChild(link);
154
+ };
155
+
156
+ panel.appendChild(favorite);
157
+ panel.appendChild(download);
158
+ document.body.appendChild(panel);
159
+
160
+ event.preventDefault();
161
+
162
+ setTimeout(() => {
163
+ const handleOutsideClick = (e) => {
164
+ if (!panel.contains(e.target)) {
165
+ panel.remove();
166
+ document.removeEventListener('click', handleOutsideClick);
167
+ }
168
+ };
169
+ document.addEventListener('click', handleOutsideClick);
170
+ }, 0);
171
+ }
172
+
173
+ // tts
174
+
175
+ const ttsToggle = document.getElementById('ttsToggle');
176
+ const ttsPanel = document.getElementById('ttsPanel');
177
+ const ttsClose = document.getElementById('ttsClose');
178
+ const ttsText = document.getElementById('ttsText');
179
+ const ttsVoice = document.getElementById('ttsVoice');
180
+ const ttsLangFilter = document.getElementById('ttsLangFilter');
181
+ const ttsVolume = document.getElementById('ttsVolume');
182
+ const ttsRate = document.getElementById('ttsRate');
183
+ const ttsPitch = document.getElementById('ttsPitch');
184
+ const ttsVolumeVal = document.getElementById('ttsVolumeVal');
185
+ const ttsRateVal = document.getElementById('ttsRateVal');
186
+ const ttsPitchVal = document.getElementById('ttsPitchVal');
187
+ const ttsSpeak = document.getElementById('ttsSpeak');
188
+ const ttsPauseBtn = document.getElementById('ttsPause');
189
+ const ttsResumeBtn = document.getElementById('ttsResume');
190
+ const ttsStopBtn = document.getElementById('ttsStop');
191
+ const ttsResetBtn = document.getElementById('ttsReset');
192
+ const ttsStatus = document.getElementById('ttsStatus');
193
+ const ttsSpeaking = document.getElementById('ttsSpeaking');
194
+ const ttsCurrentWord = document.getElementById('ttsCurrentWord');
195
+
196
+ const synth = window.speechSynthesis;
197
+ let allVoices = [];
198
+ let currentUtterance = null;
199
+
200
+ ttsToggle.onclick = () => {
201
+ ttsPanel.classList.toggle('hidden');
202
+ ttsToggle.classList.toggle('tts-toggle-active');
203
+ };
204
+ ttsClose.onclick = () => {
205
+ ttsPanel.classList.add('hidden');
206
+ ttsToggle.classList.remove('tts-toggle-active');
207
+ };
208
+
209
+ function loadVoices() {
210
+ allVoices = synth.getVoices();
211
+ if (!allVoices.length) return;
212
+
213
+ const langs = [...new Set(allVoices.map(v => v.lang))].sort();
214
+ ttsLangFilter.innerHTML = '<option value="">All Languages</option>';
215
+ langs.forEach(lang => {
216
+ const opt = document.createElement('option');
217
+ opt.value = lang;
218
+ opt.textContent = lang;
219
+ ttsLangFilter.appendChild(opt);
220
+ });
221
+
222
+ populateVoiceList('');
223
+ }
224
+
225
+ function populateVoiceList(langFilter) {
226
+ const filtered = langFilter
227
+ ? allVoices.filter(v => v.lang === langFilter)
228
+ : allVoices;
229
+
230
+ ttsVoice.innerHTML = '';
231
+ filtered.forEach((voice, i) => {
232
+ const opt = document.createElement('option');
233
+ opt.value = i;
234
+ opt.dataset.voiceName = voice.name;
235
+ opt.textContent = `${voice.name} (${voice.lang})${voice.default ? ' ★' : ''}`;
236
+ ttsVoice.appendChild(opt);
237
+ });
238
+
239
+ const defIdx = filtered.findIndex(v => v.default);
240
+ if (defIdx >= 0) ttsVoice.selectedIndex = defIdx;
241
+ }
242
+
243
+ function getSelectedVoice() {
244
+ const langFilter = ttsLangFilter.value;
245
+ const filtered = langFilter ? allVoices.filter(v => v.lang === langFilter) : allVoices;
246
+ return filtered[ttsVoice.selectedIndex] || null;
247
+ }
248
+
249
+ loadVoices();
250
+ if (synth.onvoiceschanged !== undefined) {
251
+ synth.onvoiceschanged = loadVoices;
252
+ }
253
+
254
+ ttsLangFilter.addEventListener('change', () => {
255
+ populateVoiceList(ttsLangFilter.value);
256
+ });
257
+
258
+ ttsVolume.addEventListener('input', () => { ttsVolumeVal.textContent = parseFloat(ttsVolume.value).toFixed(2); });
259
+ ttsRate.addEventListener('input', () => { ttsRateVal.textContent = parseFloat(ttsRate.value).toFixed(1); });
260
+ ttsPitch.addEventListener('input', () => { ttsPitchVal.textContent = parseFloat(ttsPitch.value).toFixed(2); });
261
+
262
+ ttsSpeak.onclick = () => {
263
+ const text = ttsText.value.trim();
264
+ if (!text) {
265
+ setStatus('⚠️ Please enter some text first.', 'warn');
266
+ return;
267
+ }
268
+ synth.cancel();
269
+
270
+ currentUtterance = new SpeechSynthesisUtterance(text);
271
+ currentUtterance.voice = getSelectedVoice();
272
+ currentUtterance.volume = parseFloat(ttsVolume.value);
273
+ currentUtterance.rate = parseFloat(ttsRate.value);
274
+ currentUtterance.pitch = parseFloat(ttsPitch.value);
275
+
276
+ currentUtterance.onstart = () => {
277
+ setStatus('🔊 Speaking…', 'speaking');
278
+ setBtns(true);
279
+ ttsSpeaking.classList.remove('hidden');
280
+ };
281
+
282
+ currentUtterance.onboundary = (e) => {
283
+ if (e.name === 'word') {
284
+ const word = text.substr(e.charIndex, e.charLength);
285
+ ttsCurrentWord.textContent = word;
286
+ ttsCurrentWord.classList.remove('word-pop');
287
+ void ttsCurrentWord.offsetWidth; // reflow
288
+ ttsCurrentWord.classList.add('word-pop');
289
+ }
290
+ };
291
+
292
+ currentUtterance.onpause = () => {
293
+ setStatus('⏸ Paused', 'paused');
294
+ };
295
+
296
+ currentUtterance.onresume = () => {
297
+ setStatus('🔊 Resumed…', 'speaking');
298
+ };
299
+
300
+ currentUtterance.onend = () => {
301
+ setStatus('✅ Done', 'done');
302
+ setBtns(false);
303
+ ttsSpeaking.classList.add('hidden');
304
+ ttsCurrentWord.textContent = '';
305
+ };
306
+
307
+ currentUtterance.onerror = (e) => {
308
+ setStatus(`❌ Error: ${e.error}`, 'error');
309
+ setBtns(false);
310
+ ttsSpeaking.classList.add('hidden');
311
+ };
312
+
313
+ synth.speak(currentUtterance);
314
+ };
315
+
316
+ ttsPauseBtn.onclick = () => {
317
+ if (synth.speaking && !synth.paused) synth.pause();
318
+ ttsPauseBtn.disabled = true;
319
+ ttsResumeBtn.disabled = false;
320
+ };
321
+
322
+ ttsResumeBtn.onclick = () => {
323
+ if (synth.paused) synth.resume();
324
+ ttsPauseBtn.disabled = false;
325
+ ttsResumeBtn.disabled = true;
326
+ };
327
+
328
+ ttsStopBtn.onclick = () => {
329
+ synth.cancel();
330
+ setBtns(false);
331
+ ttsSpeaking.classList.add('hidden');
332
+ ttsCurrentWord.textContent = '';
333
+ setStatus('⏹ Stopped', 'idle');
334
+ };
335
+
336
+ ttsResetBtn.onclick = () => {
337
+ ttsVolume.value = 1; ttsVolumeVal.textContent = '1.00';
338
+ ttsRate.value = 1; ttsRateVal.textContent = '1.0';
339
+ ttsPitch.value = 1; ttsPitchVal.textContent = '1.00';
340
+ ttsLangFilter.value = '';
341
+ populateVoiceList('');
342
+ setStatus('↺ Settings reset', 'idle');
343
+ };
344
+
345
+ function setBtns(active) {
346
+ ttsSpeak.disabled = active;
347
+ ttsPauseBtn.disabled = !active;
348
+ ttsStopBtn.disabled = !active;
349
+ ttsResumeBtn.disabled = true;
350
+ }
351
+
352
+ function setStatus(msg, state) {
353
+ ttsStatus.textContent = msg;
354
+ ttsStatus.className = `tts-status tts-status--${state}`;
355
+
356
+ }