Skip to content

Commit

Permalink
ud: Add play all for admin character prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Nov 3, 2023
1 parent b546a08 commit d6b85de
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion unmnemonic_devices_vrs/src/templates/admin/prompts.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#> admin/layout}}
{{#each prompts as |value character_name|}}
<h2>{{character_name}}</h2>
<h2 data-character="{{character_name}}">{{character_name}}</h2>
<table data-character="{{character_name}}">
<tbody>
{{#each value as |prompt_text_and_maybe_url prompt_name|}}
Expand All @@ -17,4 +17,27 @@
</tbody>
</table>
{{/each}}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('table[data-character]').forEach(function(table) {
let header = document.querySelector(`h2[data-character='${table.dataset.character}']`);
header.insertAdjacentHTML('beforeend', `<button onclick="playAllFor('${table.dataset.character}')">Play all</button>`);
});
});
// Adapted from https://stackoverflow.com/a/69305053/760389
async function playAllFor(character) {
let sounds = document.querySelectorAll(`table[data-character='${character}'] audio`);
for (let sound of sounds) {
let ended = new Promise(resolve =>
sound.addEventListener("ended", resolve, {once: true})
);
sound.play();
await ended;
}
}
</script>
{{/admin/layout}}

0 comments on commit d6b85de

Please sign in to comment.