-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotepad.html
58 lines (52 loc) · 1.76 KB
/
notepad.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Web Notepad</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content="Just a text area to type stuff and save it **locally**"/>
<meta charset="UTF-8"/>
<style>
body {
height: 100%;
}
textarea {
width: 100%;
height: 100vh;
font-family: Consolas, 'Courier New', Courier, monospace;
font-size: x-large;
}
</style>
<script>
"use strict";
function saveText() {
const data = document.getElementById('t').value;
window.localStorage.setItem("data", data);
}
function loadText() {
document.getElementById('t').value = window.localStorage.getItem("data");
}
function handleTab() {
document.getElementById('t').addEventListener('keydown', function (e) {
if (e.key === 'Tab') {
e.preventDefault();
const start = this.selectionStart;
const end = this.selectionEnd;
// set textarea value to: text before caret + tab + text after caret
this.value = this.value.substring(0, start) + "\t" + this.value.substring(end);
// put caret at right position again
this.selectionStart = start + 1;
this.selectionEnd = start + 1;
}
});
}
function initialize() {
handleTab();
loadText();
window.setInterval(saveText, 500);
}
</script>
</head>
<body onload="initialize();">
<textarea id="t" autocomplete="off"></textarea>
</body>
</html>