-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (78 loc) · 2.06 KB
/
script.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
document.querySelectorAll('.header-item').forEach(x =>
x.addEventListener('click', (e) => {
switch (e.target.id) {
case 's': saveAsVLX(); break;
case 'o': openVLX(); break;
case 'm': openProject(); break;
case 'j': saveAsSB3(); break;
case 'k': openSB3(); break;
case 'i': openWiki(); break;
}
e.stopPropagation();
})
);
const tabs = document.querySelectorAll('.editor-tablist .tab')
tabs[0].classList.add('active');
tabs.forEach(tab =>
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
})
);
document.addEventListener('keydown', (e) => {
if (e.ctrlKey) {
switch (e.key) {
case 's': saveAsVLX(); break;
case 'o': openVLX(); break;
case 'm': openProject(); break;
case 'j': saveAsSB3(); break;
case 'k': openSB3(); break;
case 'i': openWiki(); break;
default: return;
}
e.preventDefault();
}
});
const sb3FileInput = document.getElementById('sb3');
const vlxFileInput = document.getElementById('vlx');
function saveAsVLX() {
console.log('Saving as VLX file');
}
function openVLX() {
vlxFileInput.click();
}
function saveAsSB3() {
console.log('Saving SB3 file');
}
function openSB3() {
sb3FileInput.click();
}
function openWiki() {
window.open('https://www.youtube.com/watch?v=QB7ACr7pUuE', '_blank');
}
function openProject() {
let link = prompt("Project link? (e.g. https://scratch.mit.edu/projects/12345678/)");
if (link !== null && link.trim() !== "") {
let id = extractProjectNumber(link);
if (id !== null) {
alert("Loading project id "+id);
} else {
alert("Invalid project id")
}
} else {
alert("You didn't provide.");
}
}
sb3FileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) {
if (file.name.endsWith('.sb3')) {
console.log(`File uploaded: ${file.name}`);
readSB3File(file);
} else {
alert('Please upload a valid .sb3 file.');
}
}
});
function readSB3File() {}
function readVLXFile() {}