GitHub Actions commited on
Commit
7b0064a
·
1 Parent(s): b8ff2a8

Sync from GitHub repo

Browse files
Files changed (1) hide show
  1. templates/arena.html +137 -59
templates/arena.html CHANGED
@@ -28,6 +28,10 @@
28
  <button type="submit" class="mobile-synth-btn">Synthesize</button>
29
  </form>
30
 
 
 
 
 
31
  <div class="loading-container" style="display: none;">
32
  <div class="loader-wrapper">
33
  <div class="loader-animation">
@@ -73,7 +77,7 @@
73
  </div>
74
 
75
  <div class="keyboard-hint">
76
- Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random audio, <kbd>Enter</kbd> to generate
77
  </div>
78
  </div>
79
 
@@ -115,11 +119,11 @@
115
  <!-- Script lines will be added here -->
116
  </div>
117
 
118
- <button type="button" class="add-line-btn">+ Add Line</button>
119
-
120
  <div class="keyboard-hint podcast-keyboard-hint">
121
- Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> or <kbd>Alt</kbd>+<kbd>Enter</kbd> to add a new line
122
  </div>
 
 
123
  </div>
124
 
125
  <div class="podcast-loading-container" style="display: none;">
@@ -167,7 +171,7 @@
167
  </div>
168
 
169
  <div class="keyboard-hint">
170
- Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random audio, <kbd>Enter</kbd> to generate
171
  </div>
172
 
173
  <div class="podcast-vote-results vote-results" style="display: none;">
@@ -1345,39 +1349,46 @@
1345
  const ttsTab = document.getElementById('tts-tab');
1346
  if (!ttsTab.classList.contains('active')) return;
1347
 
1348
- // Only process keyboard shortcuts if text input is not focused
 
 
 
 
 
1349
  if (document.activeElement === textInput) {
1350
- return;
1351
- }
1352
-
1353
- if (e.key.toLowerCase() === 'a') {
1354
- if (bothSamplesPlayed && !voteButtons[0].disabled) {
1355
- handleVote('a');
1356
- } else if (playersContainer.style.display !== 'none' && !bothSamplesPlayed) {
1357
- showListenToastMessage();
1358
- }
1359
- } else if (e.key.toLowerCase() === 'b') {
1360
- if (bothSamplesPlayed && !voteButtons[1].disabled) {
1361
- handleVote('b');
1362
- } else if (playersContainer.style.display !== 'none' && !bothSamplesPlayed) {
1363
- showListenToastMessage();
1364
- }
1365
- } else if (e.key.toLowerCase() === 'n') {
1366
- if (nextRoundContainer.style.display === 'block') {
1367
- if (!e.ctrlKey && !e.metaKey) {
1368
- e.preventDefault();
1369
- }
1370
- resetToInitialState();
1371
  }
1372
- } else if (e.key.toLowerCase() === 'r') {
1373
- // Only trigger random if not trying to reload (Ctrl+R or Cmd+R)
 
 
 
 
1374
  if (!e.ctrlKey && !e.metaKey) {
1375
  e.preventDefault();
1376
  handleRandom();
1377
  }
1378
- } else if (e.key === ' ') {
1379
- // Space to play/pause current audio
1380
- if (playersContainer.style.display !== 'none') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1381
  e.preventDefault();
1382
  // If A is playing, toggle A, else if B is playing, toggle B, else play A
1383
  if (wavePlayers.a.isPlaying) {
@@ -1385,10 +1396,35 @@
1385
  } else if (wavePlayers.b.isPlaying) {
1386
  wavePlayers.b.togglePlayPause();
1387
  } else {
1388
- wavePlayers.a.play();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1389
  }
1390
  }
1391
  }
 
 
 
 
 
 
 
 
1392
  });
1393
 
1394
  // Add event listener for random button
@@ -1875,34 +1911,51 @@
1875
  const podcastTab = document.getElementById('conversational-tab');
1876
  if (!podcastTab.classList.contains('active')) return;
1877
 
1878
- // Only process if input fields are not focused
1879
- if (document.activeElement.tagName === 'INPUT' ||
1880
- document.activeElement.tagName === 'TEXTAREA') {
1881
- return;
 
 
 
 
 
 
 
 
 
1882
  }
1883
-
1884
- if (e.key.toLowerCase() === 'a') {
1885
- if (bothPodcastSamplesPlayed && !podcastVoteButtons[0].disabled) {
1886
- handlePodcastVote('a');
1887
- } else if (podcastPlayerContainer.style.display !== 'none' && !bothPodcastSamplesPlayed) {
1888
- openToast("Please listen to both audio samples before voting", "info");
1889
- }
1890
- } else if (e.key.toLowerCase() === 'b') {
1891
- if (bothPodcastSamplesPlayed && !podcastVoteButtons[1].disabled) {
1892
- handlePodcastVote('b');
1893
- } else if (podcastPlayerContainer.style.display !== 'none' && !bothPodcastSamplesPlayed) {
1894
- openToast("Please listen to both audio samples before voting", "info");
1895
  }
1896
- } else if (e.key.toLowerCase() === 'n') {
1897
- if (podcastNextRoundContainer.style.display === 'block') {
1898
- if (!e.ctrlKey && !e.metaKey) {
1899
- e.preventDefault();
1900
- }
1901
- resetPodcastState();
 
 
 
 
 
 
1902
  }
1903
- } else if (e.key === ' ') {
1904
- // Space to play/pause current audio
1905
- if (podcastPlayerContainer.style.display !== 'none') {
 
 
1906
  e.preventDefault();
1907
  // If A is playing, toggle A, else if B is playing, toggle B, else play A
1908
  if (podcastWavePlayers.a && podcastWavePlayers.a.isPlaying) {
@@ -1910,10 +1963,35 @@
1910
  } else if (podcastWavePlayers.b && podcastWavePlayers.b.isPlaying) {
1911
  podcastWavePlayers.b.togglePlayPause();
1912
  } else if (podcastWavePlayers.a) {
1913
- podcastWavePlayers.a.play();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1914
  }
1915
  }
1916
  }
 
 
 
 
 
 
 
 
1917
  });
1918
 
1919
  // Event listeners
 
28
  <button type="submit" class="mobile-synth-btn">Synthesize</button>
29
  </form>
30
 
31
+ <div class="keyboard-hint">
32
+ Press <kbd>R</kbd> for random text, <kbd>Enter</kbd> to synthesize, <kbd>N</kbd> for random + synthesize
33
+ </div>
34
+
35
  <div class="loading-container" style="display: none;">
36
  <div class="loader-wrapper">
37
  <div class="loader-animation">
 
77
  </div>
78
 
79
  <div class="keyboard-hint">
80
+ Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening
81
  </div>
82
  </div>
83
 
 
119
  <!-- Script lines will be added here -->
120
  </div>
121
 
 
 
122
  <div class="keyboard-hint podcast-keyboard-hint">
123
+ Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> or <kbd>Alt</kbd>+<kbd>Enter</kbd> to add a new line, <kbd>R</kbd> for random script, <kbd>Enter</kbd> to generate, <kbd>N</kbd> for random + generate
124
  </div>
125
+
126
+ <button type="button" class="add-line-btn">+ Add Line</button>
127
  </div>
128
 
129
  <div class="podcast-loading-container" style="display: none;">
 
171
  </div>
172
 
173
  <div class="keyboard-hint">
174
+ Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening
175
  </div>
176
 
177
  <div class="podcast-vote-results vote-results" style="display: none;">
 
1349
  const ttsTab = document.getElementById('tts-tab');
1350
  if (!ttsTab.classList.contains('active')) return;
1351
 
1352
+ // --- Shortcut logic based on current state ---
1353
+ const isInputVisible = playersContainer.style.display === 'none' && loadingContainer.style.display === 'none';
1354
+ const isPlaybackVisible = playersContainer.style.display !== 'none';
1355
+ const isNextRoundVisible = nextRoundContainer.style.display === 'block';
1356
+
1357
+ // Ignore shortcuts if text input is focused
1358
  if (document.activeElement === textInput) {
1359
+ // Allow Enter key if focused on text input and input is visible
1360
+ if (e.key === 'Enter' && isInputVisible) {
1361
+ e.preventDefault();
1362
+ handleSynthesize();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1363
  }
1364
+ return; // Don't process other shortcuts when input is focused
1365
+ }
1366
+
1367
+ // Global shortcuts (when not focused on input)
1368
+ if (e.key.toLowerCase() === 'r' && isInputVisible) {
1369
+ // Only trigger random if not trying to reload (Ctrl+R or Cmd+R)
1370
  if (!e.ctrlKey && !e.metaKey) {
1371
  e.preventDefault();
1372
  handleRandom();
1373
  }
1374
+ } else if (e.key === 'Enter' && isInputVisible) {
1375
+ e.preventDefault();
1376
+ handleSynthesize();
1377
+ } else if (e.key.toLowerCase() === 'n' && isInputVisible) {
1378
+ // 'N' for New Random Round (only when input is visible)
1379
+ if (!e.ctrlKey && !e.metaKey) {
1380
+ e.preventDefault();
1381
+ handleRandom(); // Get random text
1382
+ // Add a slight delay to ensure text input is populated before synthesizing
1383
+ setTimeout(() => {
1384
+ handleSynthesize(); // Synthesize the random text
1385
+ }, 50);
1386
+ }
1387
+ }
1388
+
1389
+ // Playback/Voting shortcuts (only when players are visible)
1390
+ else if (isPlaybackVisible) {
1391
+ if (e.key === ' ') { // Space to play/pause
1392
  e.preventDefault();
1393
  // If A is playing, toggle A, else if B is playing, toggle B, else play A
1394
  if (wavePlayers.a.isPlaying) {
 
1396
  } else if (wavePlayers.b.isPlaying) {
1397
  wavePlayers.b.togglePlayPause();
1398
  } else {
1399
+ // If neither is playing, prefer playing A if it hasn't finished, else B
1400
+ if (wavePlayers.a.wavesurfer.getCurrentTime() < wavePlayers.a.wavesurfer.getDuration()) {
1401
+ wavePlayers.a.play();
1402
+ } else {
1403
+ wavePlayers.b.play();
1404
+ }
1405
+ }
1406
+ } else if (e.key.toLowerCase() === 'a') { // Vote A
1407
+ if (bothSamplesPlayed && !voteButtons[0].disabled) {
1408
+ handleVote('a');
1409
+ } else if (!bothSamplesPlayed) {
1410
+ showListenToastMessage();
1411
+ }
1412
+ } else if (e.key.toLowerCase() === 'b') { // Vote B
1413
+ if (bothSamplesPlayed && !voteButtons[1].disabled) {
1414
+ handleVote('b');
1415
+ } else if (!bothSamplesPlayed) {
1416
+ showListenToastMessage();
1417
  }
1418
  }
1419
  }
1420
+
1421
+ // Next Round shortcut (only when next round button is visible)
1422
+ else if (isNextRoundVisible && e.key.toLowerCase() === 'n') {
1423
+ if (!e.ctrlKey && !e.metaKey) {
1424
+ e.preventDefault();
1425
+ }
1426
+ resetToInitialState();
1427
+ }
1428
  });
1429
 
1430
  // Add event listener for random button
 
1911
  const podcastTab = document.getElementById('conversational-tab');
1912
  if (!podcastTab.classList.contains('active')) return;
1913
 
1914
+ // --- Shortcut logic based on current state ---
1915
+ const isScriptEditorVisible = podcastPlayerContainer.style.display === 'none' && podcastLoadingContainer.style.display === 'none';
1916
+ const isPodcastPlaybackVisible = podcastPlayerContainer.style.display !== 'none';
1917
+ const isPodcastNextRoundVisible = podcastNextRoundContainer.style.display === 'block';
1918
+
1919
+ // Only process if specific input fields are not focused
1920
+ const activeElementTag = document.activeElement.tagName;
1921
+ const isInputFocused = activeElementTag === 'INPUT' || activeElementTag === 'TEXTAREA';
1922
+
1923
+ // Handle adding new line shortcut separately if input is focused
1924
+ if (isInputFocused && e.key === 'Enter' && (e.altKey || e.ctrlKey)) {
1925
+ // Already handled by input's keydown listener, prevent double action
1926
+ return;
1927
  }
1928
+
1929
+ // Ignore other shortcuts if any input/textarea is focused
1930
+ if (isInputFocused) {
1931
+ return;
1932
+ }
1933
+
1934
+ // Global shortcuts (when not focused on input)
1935
+ if (e.key.toLowerCase() === 'r' && isScriptEditorVisible) {
1936
+ // Only trigger random if not trying to reload (Ctrl+R or Cmd+R)
1937
+ if (!e.ctrlKey && !e.metaKey) {
1938
+ e.preventDefault();
1939
+ loadRandomScript();
1940
  }
1941
+ } else if (e.key === 'Enter' && isScriptEditorVisible) {
1942
+ e.preventDefault();
1943
+ generatePodcast();
1944
+ } else if (e.key.toLowerCase() === 'n' && isScriptEditorVisible) {
1945
+ // 'N' for New Random Podcast (only when script editor is visible)
1946
+ if (!e.ctrlKey && !e.metaKey) {
1947
+ e.preventDefault();
1948
+ loadRandomScript(); // Get random script
1949
+ // Add a slight delay before generating
1950
+ setTimeout(() => {
1951
+ generatePodcast(); // Generate the random script
1952
+ }, 50);
1953
  }
1954
+ }
1955
+
1956
+ // Playback/Voting shortcuts (only when players are visible)
1957
+ else if (isPodcastPlaybackVisible) {
1958
+ if (e.key === ' ') { // Space to play/pause
1959
  e.preventDefault();
1960
  // If A is playing, toggle A, else if B is playing, toggle B, else play A
1961
  if (podcastWavePlayers.a && podcastWavePlayers.a.isPlaying) {
 
1963
  } else if (podcastWavePlayers.b && podcastWavePlayers.b.isPlaying) {
1964
  podcastWavePlayers.b.togglePlayPause();
1965
  } else if (podcastWavePlayers.a) {
1966
+ // If neither is playing, prefer playing A if it hasn't finished, else B
1967
+ if (podcastWavePlayers.a.wavesurfer.getCurrentTime() < podcastWavePlayers.a.wavesurfer.getDuration()) {
1968
+ podcastWavePlayers.a.play();
1969
+ } else if (podcastWavePlayers.b) {
1970
+ podcastWavePlayers.b.play();
1971
+ }
1972
+ }
1973
+ } else if (e.key.toLowerCase() === 'a') { // Vote A
1974
+ if (bothPodcastSamplesPlayed && !podcastVoteButtons[0].disabled) {
1975
+ handlePodcastVote('a');
1976
+ } else if (!bothPodcastSamplesPlayed) {
1977
+ openToast("Please listen to both audio samples before voting", "info");
1978
+ }
1979
+ } else if (e.key.toLowerCase() === 'b') { // Vote B
1980
+ if (bothPodcastSamplesPlayed && !podcastVoteButtons[1].disabled) {
1981
+ handlePodcastVote('b');
1982
+ } else if (!bothPodcastSamplesPlayed) {
1983
+ openToast("Please listen to both audio samples before voting", "info");
1984
  }
1985
  }
1986
  }
1987
+
1988
+ // Next Round shortcut (only when next round button is visible)
1989
+ else if (isPodcastNextRoundVisible && e.key.toLowerCase() === 'n') {
1990
+ if (!e.ctrlKey && !e.metaKey) {
1991
+ e.preventDefault();
1992
+ }
1993
+ resetPodcastState();
1994
+ }
1995
  });
1996
 
1997
  // Event listeners