Repository navigation
Expand file tree
/
Copy pathdemo.html
More file actions
64 lines (56 loc) · 2.36 KB
/
Copy pathdemo.html
File metadata and controls
64 lines (56 loc) · 2.36 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>sb3.js demo</title>
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAbElEQVR42rWSgQmAMAwEs4MrWJzUhVywEuHhgQsQgg9P7ZeeCWmQtglyOgPAfXyLZ8rTEpINwJl9O1mmfQmLzt9oz70xgCvgAwZQFtwvZjyFPVD9Bp6TDJf+Bqx1aU2PALMK0p0KdGHQQmN0L0l/a2mitOqcAAAAAElFTkSuQmCC" type="image/png">
<style>
#project-container {
margin-bottom: 0.5rem;
}
.load-project-controls {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
</style>
</head>
<body>
<div id="project-container"></div>
<div class="load-project-controls">
<input type="file" id="file-input" accept=".sb3">
<div class="id-input">
<input id="id-textbox" type="text" placeholder="Enter a project ID or URL">
<button id="id-button">Load project</button>
</div>
</div>
<script type="module">
import {ProjectElement, Loader} from './dist/index.js';
customElements.define('sb3-project', ProjectElement);
const projectElem = document.createElement('sb3-project');
document.getElementById('project-container').append(projectElem);
const fileInput = document.getElementById('file-input');
async function loadFromFile() {
if (fileInput.files.length !== 1) {
return;
}
const file = fileInput.files[0];
await projectElem.loadProjectFromZip(file);
projectElem.start();
}
fileInput.addEventListener('change', loadFromFile);
loadFromFile();
const idInput = document.getElementById('id-textbox');
const idButton = document.getElementById('id-button');
async function loadFromID() {
const urlOrID = idInput.value;
const idMatch = urlOrID.match(/(\d+)\/?$/);
if (!idMatch) return;
const id = idMatch[1];
await projectElem.loadProjectFromID(id);
projectElem.start();
}
idButton.addEventListener('click', loadFromID);
</script>
</body>
</html>