-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.js
99 lines (78 loc) · 2.81 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
92
93
94
95
96
97
98
99
import * as common from "./common.js";
import * as canvas from "./canvas.js";
import * as term from "./term.js";
import * as hid from "./hid.js";
import * as extensions from "./extensions.js";
import * as bot from "./bot.js";
import * as basic from "./basic.js";
window.basic = basic;
import * as syntax from "./syntax.js";
window.syntax = syntax;
window.inDocsPopout = false;
window.toggleDocumentation = canvas.toggleDocs;
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("sw.js").then(function() {
console.log("Service worker successfully registered");
});
navigator.serviceWorker.ready.then(function() {
console.log("Service worker is now ready");
});
} else {
console.log("Service workers not supported in this browser");
}
if (common.getParameter("lsp") != null) {
localStorage.setItem("atto_lastSessionProgram", common.getParameter("lsp"));
window.location.replace("/");
}
canvas.onReady(function() {
term.print("Welcome to ");
term.foreground("blue");
term.print("atto\n");
term.foreground();
term.print("Type ");
term.foreground("green");
term.print("help");
term.foreground();
term.print(" to view the guide\n");
if (localStorage.getItem("atto_lastSessionProgram") != null) {
term.print("Type ");
term.foreground("red");
term.print("load");
term.foreground();
term.print(" to load last session\n");
}
if (common.getParameter("exttestcode") != null) {
extensions.load(`data:script/javascript;base64,${common.getParameter("exttestcode")}`, common.getParameter("exttestname") || "test", true);
}
if (common.getParameter("code") != null && common.getParameter("runmode") != "list") {
basic.textToProgram(common.getParameter("code"));
term.print("\nLoaded shared program\n");
try {
basic.parseProgram(basic.editingProgram);
basic.startProgram();
if (common.getParameter("bot") != null) {
bot.invoke(common.getParameter("bot"));
}
} catch (e) {
basic.displayError(e);
term.print("Ready\n");
hid.startProgramInput();
if (common.getParameter("bot") != null) {
bot.invoke(common.getParameter("bot"));
}
}
} else {
if (common.getParameter("code") != null && common.getParameter("runmode") == "list") {
term.print("\n");
basic.textToProgram(common.getParameter("code"));
basic.listLines();
term.print("\nType ");
term.foreground("magenta");
term.print("run");
term.foreground();
term.print(" to run the program");
}
term.print("\nReady\n");
hid.startProgramInput();
}
});