blob: d3ec5679e1604899ca58d645955314b7a3e3e62b (
plain)
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
|
<!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">
<title>Editor</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<style>
article {
display: block;
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
padding: 80px;
outline: none;
border: 0;
background: #222;
color: #fff;
font-size: 28px;
font-family: Monaco, monospace;
font-weight: 200;
overflow: auto;
}
</style>
<article contenteditable></article>
<script>
window.addEventListener('load', (evt) => {
const autoSaveFrequency = 1000;
const editor = document.querySelector('article');
editor.addEventListener('paste', function (evt) {
evt.preventDefault();
let clipped = evt.clipboardData.getData('text/plain');
clipped = clipped.replace(/(\r\n|\n|\r)/gm, "<br>");
document.execCommand('insertHTML', false, clipped);
});
if (typeof (Storage) !== 'undefined') {
editor.innerHTML = localStorage.getItem('content');
setInterval(function () {
localStorage.setItem('content', editor.innerHTML);
}, autoSaveFrequency);
} else {
console.log('Local Storage not supported');
}
});
</script>
</body>
</html>
|