-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
91 lines (77 loc) · 2.88 KB
/
index.html
File metadata and controls
91 lines (77 loc) · 2.88 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
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
<!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}
#autoSaveText {
text-align: left;
}
</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 class="col col-5" id="autoSaveText">Auto-Saving In <span id="time">20</span> Seconds</div>
<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, function(err) {
if(err) {
console.error('Error saving', err);
return alertMsg('Unable to Save!');
}
alertMsg('Saved!');
});
}
setInterval(saveFile, 21000);
function removeText() {
document.querySelector('#note').innerHTML = ""
alertMsg("Removed Text!");
}
function startTimer(duration, display) {
var timer = duration, seconds;
setInterval(function () {
seconds = parseInt(timer % 60, 10);
display.textContent =seconds;
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
window.onload = function () {
var twentysec = 20,
display = document.querySelector('#time');
startTimer(twentysec, display);
};
</script>
</body>
</html>