-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.html
197 lines (184 loc) · 8.66 KB
/
notes.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notes</title>
<style>
*,*:before,*:after {box-sizing: border-box;}
* {margin:0;padding:0;text-decoration: none;list-style-type: none;outline: none;}
html {background: #00000d;color: #8798A5;font-family: trebuchet ms;}
body {width: 800px;max-width: calc(100% - 20px);margin: 0 auto;}
.gen {background: #141D26;margin-bottom: 1.5rem;box-shadow: 2px 3px 3px rgba(0,0,0,0.52);padding: 10px;border-radius: 8px;margin-top: 1.5rem;}
input, select, button, textarea {background: transparent;color: #8798A5;border: 1px solid #1b2836;border-radius: 8px;padding: .6rem .5rem;}
select option {background: #1b2836;}
a {color: #A9894F;}
a:hover {transition: all .3s !important;color: white;}
h1 {display: flex;align-items: center;justify-content: space-between;margin: 0 0 10px 0;font-size: 1.4rem;}
.form {display: flex;}
.form input {flex: 5;}
.form button {flex: 1;}
#saveBUTTON {border-radius: 0 8px 8px 0;}
#noteINPUT {border-right: none;border-radius: 8px 0 0 8px;}
button:hover, input:focus, select:focus, textarea:focus select:hover {background: #1b2836;transition: all .3s;}
button, select {cursor: pointer;}
#notes {display: flex;flex-direction: column;border-radius: 10px;overflow: hidden;}
.note {display: flex;background: #111922;gap: 5px;border-bottom: 1px solid #00000d21;}
.noteContent {display: flex;align-items: center;padding: 5px 0;}
.buttons {display: flex;gap: 5px;margin-left: auto;}
.id, .buttons > span {color: #a47642;min-width: 35px;display: flex;justify-content: center;background: #00000d45;padding: 4px 2px;align-items: center;user-select: none;}
.buttons > span {background: transparent;color: #777;text-shadow: 1px 1px 3px #00000d;min-width: 25px;}
.buttons > span:hover {background: #00000d;transition: all .3s !important;cursor: pointer;}
.buttons .hide {opacity: 0;transform: translateX(100%);transition: all 0.3s ease-in-out;}
.buttons:hover .hide {opacity: 1;transform: translateX(0);}
.id {position: relative;}
.id .copy {position: absolute;top: 50%;left: -100%;transform: translateY(-50%);transition: all 0.3s ease-in-out;}
.id:hover .copy {left: 50%;transform: translate(-50%, -50%);cursor: pointer;}
.id .index {visibility: visible;}
.id:hover .index {visibility: hidden;}
.checkmark__circle{stroke-dasharray:166;stroke-dashoffset:166;stroke-width:2;stroke-miterlimit:10;stroke:#7ac142;fill:none;animation:stroke .6s cubic-bezier(.65,0,.45,1) forwards}
.checkmark{width:25px;height:25px;border-radius:50%;display:block;stroke-width:2;stroke:#fff;stroke-miterlimit:10;box-shadow:inset 0 0 0 none;animation:fill .4s ease-in-out .4s forwards,scale .3s ease-in-out .9s both}
.cross {animation-name:fillred, scale!important;}
.cross .checkmark__circle {stroke:#BE1E2D!important;}
.checkmark__check{transform-origin:50% 50%;stroke-dasharray:48;stroke-dashoffset:48;animation:stroke .3s cubic-bezier(.65,0,.45,1) .8s forwards}
@keyframes stroke{100%{stroke-dashoffset:0}}
@keyframes scale{0%,100%{transform:none}50%{transform:scale3d(1.1,1.1,1)}}
@keyframes fill{100%{box-shadow:inset 0 0 0 30px #7ac142}}
@keyframes fillred{100%{box-shadow:inset 0 0 0 30px #BE1E2D}}
</style>
</head>
<body>
<div id="notification"></div>
<div class="gen">
<form class="form">
<input id="noteINPUT" type="text" placeholder="Notes/HTML" name="note" autocomplete="off" title="Enter a Note"/>
<button id="saveBUTTON" type="submit">Save</button>
</form>
</div>
<div class="gen">
<h1 id="notesH"></h1>
<div id="notes">
</div>
</div>
<script>
class LocalStorage {
constructor(key) {this.key = key;}
modify(index, value) {
let values = this.values;
index === -1
? values.push(value)
: value
? (values[index] = value)
: values.splice(index, 1);
localStorage.setItem(this.key, JSON.stringify(values));
}
removeAll() {localStorage.removeItem(this.key);}
findIndex(key, value) {return this.values.findIndex(key && value ? obj => obj[key] === value : item => item === key);}
move(index, direction) {
const values = this.values;
const newIndex = (index + direction + values.length) % values.length;
const [item] = values.splice(index, 1);
values.splice(newIndex, 0, item);
localStorage.setItem(this.key, JSON.stringify(values));
}
get values() {return JSON.parse(localStorage.getItem(this.key)) || [];}
}
const notesLS = new LocalStorage('notes');
const saveBUTTON = document.getElementById('saveBUTTON');
const notesDIV = document.getElementById('notes');
const notesH1 = document.getElementById('notesH');
const notification = document.querySelector("#notification");
function alertthis(alerttext, success=true){
let removefirst = document.getElementById("removethis");
if (document.body.contains(removefirst)) {removefirst.remove();}
let elem = document.createElement('div');
elem.style.cssText = 'z-index: 99999 !important; position: fixed !important; top: 50% !important; left: 50% !important; transform: translate(-50%, -50%);background-color: rgb(17, 19, 26) !important; color: rgb(135, 152, 165) !important; padding: 5px 10px !important;box-shadow: rgba(0, 0, 0, 0.52) 1px 2px 8px !important;border-radius: 8px !important;display: flex!important;justify-content: center!important;align-items: center!important;gap: 8px!important;'
elem.setAttribute("id", "removethis");
if (success) {var ct = `M14.1 27.2l7.1 7.2 16.7-16.8`;}
else {ct = `M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8`;var cl = `cross`;}
elem.innerHTML = `${alerttext}<svg class="checkmark ${cl}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52"><circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"></circle><path class="checkmark__check" fill="none" d="${ct}"></path></svg>`;
document.body.appendChild(elem);
setTimeout(function(){ elem.remove(); }, 1650);
}
function generateID() {
let array = new Uint32Array(1);
window.crypto.getRandomValues(array);
return array[0].toString(36);
}
function retINDEX(id) {
let index = notesLS.findIndex('id', id);
return index
}
saveBUTTON.addEventListener('click', (e) => {
e.preventDefault();
let noteINPUT = document.getElementById('noteINPUT');
let id = noteINPUT.dataset.id || generateID();
let note = noteINPUT.value;
if (!note) {return}
let index = retINDEX(id);
let data = {id, note}
notesLS.modify(index, data)
noteINPUT.value = '';
noteINPUT.removeAttribute('data-id')
alertthis('Saved!')
appendNotes()
});
function appendNotes() {
notesDIV.innerHTML = '';
notesH1.innerHTML = '';
notesH1.innerHTML = `<span>Notes</span><small>${notesLS.values.length}</small>`;
notesLS.values.forEach((notes, i) => {
let {id, note} = notes;
let div = `<div class="note">
<span class="id"><span class="index">${++i}</span><span class="copy" data-id="${id}" title="copy">✢</span></span>
<span class="noteContent">${note}</span>
<span class="buttons">
<span class="hide edit"data-id="${id}" title="edit">✍</span>
<span class="hide move up" data-wh="-1" data-id="${id}" title="move up">⏶</span>
<span class="hide move down" data-wh="1" data-id="${id}" title="move down">⏷</span>
<span class="delete" data-id="${id}" title="remove">×</span>
</span>
</div>`
notesDIV.innerHTML += div
});
}
appendNotes()
document.addEventListener('click', function(e){
let remove = e.target.closest('.delete');
let move = e.target.closest('.move');
let edit = e.target.closest('.edit');
let copy = e.target.closest('.copy');
if (edit) {
let id = edit.dataset.id
let index = retINDEX(id);
let note = notesLS.values[index].note;
let noteINPUT = document.getElementById('noteINPUT');
noteINPUT.value = note;
noteINPUT.dataset.id = id
}
if (remove) {
let id = remove.dataset.id
let index = retINDEX(id);
notesLS.modify(index)
alertthis('Removed!', false)
appendNotes()
}
if (move) {
let dataWH = Number(move.dataset.wh)
let id = move.dataset.id
let index = retINDEX(id);
notesLS.move(index, dataWH)
appendNotes()
}
if (copy) {
let id = copy.dataset.id
let index = retINDEX(id);
let note = notesLS.values[index].note;
navigator.clipboard.writeText(note);
alertthis('Copied!')
}
});
</script>
</body>
</html>