-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
128 lines (111 loc) · 4.73 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/paper.min.css">
<link rel="stylesheet" href="style.css">
<title>Note Taking App</title>
</head>
<body>
<!-- This is a comment -->
<div class="switch">Dark mode:
<button class="inner-switch">OFF</span>
</div>
<h1>Note Taking App</h1>
<h3>by: drwm-base</h3>
<script src="https://unpkg.com/filer/dist/filer.min.js"></script>
<script src="https://cdn.jsdelivr.net/g/filesaver.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
const fs = new Filer.FileSystem();
var str = "";
window.addEventListener('DOMContentLoaded', (event) => {
fs.readFile('/note', 'utf8', function (err, data) {
if (err !== null) {
str = "Welcome to my note-taking app!"
}
else if (data !== null) {
str = data;
}
document.querySelector('#note').innerHTML = str;
wordCount();
})
});
window.setInterval(() => {
save();
}, 2000);
window.setInterval(() => {
wordCount();
}, 200);
function wordCount() {
var count = document.querySelector("#note").innerHTML.trim();
count = count.replace(/ +/g, "");
count = count.replace(/<[^>]*>/g, " ");
count = count.replace(/\s+/g, " ");
count = count.split(" ");
var p = 0;
for( var i = 0; i < count.length; i++){
if(count[i] == "")
++p;
}
count = count.length - p;
document.querySelector("#word").innerHTML = "Word Count: " + count;
}
function download(name) {
var b = new Blob([document.querySelector('#note').innerHTML],
{ type: "text/plain;charset=utf-8" });
if (name) {
saveAs(b, name + ".txt");
}
else {
saveAs(b, "note.txt");
}
}
function alertSystem(msg) {
if (msg) {
document.querySelector('#alert').innerHTML = msg;
document.querySelector('#alert').style.visibility = "visible";
setTimeout(() => {
document.querySelector('#alert').style.visibility = "hidden";
}, 1000);
}
}
function save() {
fs.writeFile('/note',
document.querySelector('#note').innerHTML, function (err) {
if (err) { throw err; }
});
}
function saveAlert() {
save();
alertSystem("Saved!");
}
$(".inner-switch").on("click", function () {
if ($("body").hasClass("dark")) {
$("body").removeClass("dark");
$(".inner-switch").text("OFF");
} else {
$("body").addClass("dark");
$(".inner-switch").text("ON");
}
});
</script>
<!--The actual container for the note taking-->
<div id="parent">
<div class="paper container" id="note" contenteditable></div>
<div id="word" class="container">0</div>
<div id="buttons" class="row">
<div class="col-2 col"></div>
<div id="centered" class="col-10 col">
<div id="downloadLayout" class="row container">
<button id="save" class="col-3 col" onclick="saveAlert()">Save</button>
<button class="col-3 col" onclick="download(document.querySelector('.downloadName').innerHTML)">Download</button>
<div id="download" class="col-3 col">Download Name: (default: note)</div>
<div class="downloadName col-3 col paper" contenteditable></div>
</div>
</div>
</div>
<div id="alert"></div>
</div>
</body>
</html>