-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
24 lines (23 loc) · 836 Bytes
/
main.js
File metadata and controls
24 lines (23 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function saveText() {
var textToSave = document.getElementById("python-code").value;
var blob = new Blob([textToSave], { type: "text/plain" });
var a = document.createElement("a");
a.download = "saved_code.py";
a.href = window.URL.createObjectURL(blob);
a.click();
}
function importText() {
var fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = ".py";
fileInput.addEventListener("change", function (event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function (event) {
var importedText = event.target.result;
document.getElementById("python-code").value = importedText;
};
reader.readAsText(file);
});
fileInput.click();
}