-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathembed.html
More file actions
41 lines (36 loc) · 1.05 KB
/
embed.html
File metadata and controls
41 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Embed Example</title>
</head>
<body>
<button id="generate">Generate</button>
<div id="result"></div>
<script type="module">
import { parsePhraseBook, generateString } from './js/core.js';
const SKETCH_ID = '-L0jT5zaERgBPaf3P6LP';
async function fetchSketch(sketchId) {
const url = `https://emrg-pcg.firebaseio.com/sketch/${SKETCH_ID}.json`;
const res = await fetch(url);
return await res.json();
}
async function loadSketch(seed) {
const sketch = await fetchSketch(SKETCH_ID);
const phraseBook = await parsePhraseBook(sketch.source, fetchSketch);
return phraseBook;
}
async function onGenerate() {
if (!window.sketch) return;
const result = await generateString(window.sketch, { seed: Date.now() });
console.log(result);
document.querySelector('#result').innerHTML = result;
}
async function init() {
window.sketch = await loadSketch(SKETCH_ID);
document.querySelector('#generate').addEventListener('click', onGenerate);
onGenerate();
}
init();
</script>
</body>