forked from Grommers00/my-note
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
61 lines (52 loc) · 1.97 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="notepad.css">
<style>
#alert {text-align: center; visibility: hidden; width:15%; font-size: 20pt; margin-top:10pt}
</style>
<title>My Web Note Pad</title>
</head>
<body>
<div class="col col-8">
<div id="note" contenteditable class="paper" style="min-height:15px"></div>
<button class="btn-secondary" onclick="saveFile()">saveFile</button>
<button class="btn-warning" onclick="removeText()">Remove all text</button>
<div id="alert" class="alert alert-danger"></div>
</div>
<script src="https://unpkg.com/filer/dist/filer.min.js"></script>
<script>
const fs = new Filer.FileSystem();
window.addEventListener('DOMContentLoaded', (event) => {
fs.readFile('/note', 'utf8', function (err, data) {
if (err) {
console.log(err);
fs.writeFile('/note', 'utf8', function (err) {
if (err) console.log(err); throw err;
});
} if (data) {
document.querySelector('#note').innerHTML = data;
}
})
})
function alertMsg(msg) {
document.querySelector('#alert').innerHTML = msg;
document.querySelector('#alert').style.visibility = "visible";
setTimeout(()=>{
document.querySelector('#alert').style.visibility = "hidden";
}, 2000);
}
function saveFile() {
fs.writeFile('/note', document.querySelector('#note').innerHTML);
alertMsg("Saved!");
}
function removeText() {
document.querySelector('#note').innerHTML = ""
alertMsg("Removed Text!");
}
</script>
</body>
</html>