-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
257 lines (251 loc) · 10.3 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>QuickNote</title>
<link rel="icon" sizes="any" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAHFSURBVHgBxZfvcYJAEMXf3ViAHeQYGzAdYAfpwHSQ+D0jh5PvJh2YCpIOYgehAy4dpIAMZA/BgOJ47CG+GUTWP/e7t3t7IFBK6TREjjkdob3EZZRAFMer0UFiA6IYfPkdAZnGsNJmFcSCZj5Fhi9cQxIzSZY/4FrK5XxEANN6jGwRuKDUMs3/AbJQ0mkKT1Eax+opvUN3KYk+lGONEVjyBihWUI57evsDhrwAdrbvl28ChtgAlHdFv15X19RYhnPAFh31jk9UHVPwZs8GoJxHaLZr1uxZAGXRPR78jQFTnRbPrm237RmZogZzHJfYUG0Y9AFQFF2G99YPdzto2IgJGBpc44zcU1AvOhcJzFy+5gSgonTdaXBk8TnrKzmlwMTBgk6Lwzjl/YVOzd3UWh9PNBzl14oFblpiTtb3AwCMm5fu1vcDkNcArPUrd+v7ARC1wuxofaWjImzcsdR0eKdU7gelA9b6iQFD1oEYPKnilWn9HoBmppkQ4xKAZf0ewL6wIH4tQPeqbwXgQvhYfwTQFcI8Bx/wFd3ItD4DlFtrhEtLyM3Jh5BBICRuTzYij9XhqKKAk7OPYT07YSjvWzreaPCtDfwBVOKarYseuAUAAAAASUVORK5CYII=" />
<link rel="icon" sizes="any" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath fill='%23207EDF' d='M26 32c4 0 6-2 6-6V6c0-4-2-6-6-6H6C2 0 0 2 0 6v17l9 9h17ZM4 4h24v24H10v-6H4V4Zm13.5 9.5 1-8.5L9 17h6.5l-1 10 9-13.5h-6Z'/%3E%3C/svg%3E" />
<style>
:root {
color-scheme: light dark;
--base: 242, 242, 246;
--main: 255, 255, 255;
--accent: 198, 198, 200;
--text: 63, 63, 65;
--blue: 32, 126, 223;
--green: 123, 226, 75;
--red: 199, 0, 24;
--figure: 255, 255, 255;
--line-height: 1.5;
--rule-width: 0.025rem;
--offset: calc( ( 1rem * var(--line-height) - 1rem) / 2 );
}
@media (prefers-color-scheme: dark) {
:root {
--base: 0, 0, 0;
--main: 28, 28, 29;
--accent: 61, 61, 64;
--text: 231, 231, 233;
}
}
html {
height: 100dvh;
box-sizing: border-box;
background-color: rgb(var(--main));
font-family: system-ui;
font-weight: 300;
font-size: 1.375em;
line-height: var(--line-height);
color: rgb(var(--text));
}
*, *:before, *:after {
box-sizing: inherit;
font-family: inherit;
font-weight: inherit;
font-size: inherit;
line-height: inherit;
}
textarea, button {
border: none;
outline: none;
}
body {
height: 100dvh;
margin: 0;
display: grid;
grid-template-rows: auto 1fr auto;
}
nav {
width: 1.8rem;
position: fixed;
top: 1rem;
right: 0;
}
button {
width: 2.2rem;
height: 2rem;
padding: 0 0.5rem 0 0.1rem;
margin-bottom: 0.5rem;
border-radius: 15% 0 0 15%;
box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.5);
line-height: 0;
cursor: pointer;
transition: transform 0.2s;
}
@media (hover: hover) {
button:hover {
transform: translateX(-0.2rem);
}
}
svg {
height: 50%;
fill: rgb(var(--figure));
}
.copy {
background-color: rgba(var(--green), 0.8);
}
.share {
background-color: rgba(var(--blue), 0.8);
}
.clear {
background-color: rgba(var(--red), 0.8);
}
h1 {
margin: 0;
padding: 2rem 1.5rem 0;
line-height: 1;
}
main {
display: grid;
grid-template-rows: 1fr;
}
textarea {
width: 100%;
padding: var(--offset) 1.5rem 0;
display: block;
background: transparent linear-gradient(rgb(var(--base)) var(--rule-width), transparent var(--rule-width)) left top / 100% calc(1rem * var(--line-height)) local;
resize: none;
color: inherit;
}
footer {
padding: 0.25rem 1.5rem;
background-color: rgb(var(--base));
box-shadow: inset 0 0.75rem 0.75rem -1rem rgba(0, 0, 0, 0.25);
text-align: right;
}
footer, footer a {
font-size: 0.5rem;
color: rgba(var(--text), 0.5);
}
@media screen and (min-width: 30em) {
html {
font-size: 1.75em;
}
}
</style>
</head>
<body>
<header>
<h1 id="title">Note from...</h1>
<nav>
<button class="copy" id="copy">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M6 22c-2 0-3-1-3-3V6.5h2V20h10.5v2H6Zm4-4c-2 0-3-1-3-3V5c0-2 1-3 3-3h7c2 0 3 1 3 3v10c0 2-1 3-3 3h-7Zm-1-2h9V4H9v12Z"/>
</svg>
</button>
<button class="share" id="share">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M11 17V4L9 6 7.5 4.5 12 0l4.5 4.5L15 6l-2-2v13h-2Zm9 3c0 2-1 3-3 3h-2.5v-2c.75.0 1.5.0 2.5.0L18 21v-2c0-2 1-2.75 2.5-2.75v-.5C19 15.75 18 15 18 13v-2l-1-.0c-.5-.0-1.5-0-2 0V9h2c2 0 3 1 3 3v2h2v4h-2v2ZM4 18v2c0 2 1 3 3 3h2.5v-2c-.75.0-1.5.0-2.5.0L6 21v-2c0-2-1-2.75-2.5-2.75v-.5C5 15.75 6 15 6 13v-2l1-0c.5-.0 1.5-.0 2 0V9H7c-2 0-3 1-3 3v2H2v4h2Z"/>
</svg>
</button>
<button class="clear" id="clear">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M8 22c-2 0-3-1-3-3V5H3.5V3H8V2h8v1h4.5v2H19v14c0 2-1 3-3 3H8Zm9-17H7v15h10V5ZM9 18V7h2v11H9Zm4 0V7h2v11h-2Z"/>
</svg>
</button>
</nav>
</header>
<main>
<textarea contenteditable id="editor"></textarea>
</main>
<footer id="footer">Made with love by <a href="https://portfolio.madysondesigns.com" target="_blank">@MadysonDesigns</a>. Source on <a href="https://github.com/madysondesigns/quicknote" target="_blank">Github</a>.</footer>
<script>
var App = {
date: new Date(),
ui: {
noteTitle: document.getElementById('title'),
noteEditor: document.getElementById('editor'),
copyButton: document.getElementById('copy'),
shareButton: document.getElementById('share'),
clearButton: document.getElementById('clear')
},
init() {
this.storageKey = 'quicknote_' + this.getNoteID();
this.ui.copyButton.addEventListener('click', this.onCopyNoteContent.bind(this));
this.ui.shareButton.addEventListener('click', this.onShareNoteContent.bind(this));
this.ui.clearButton.addEventListener('click', this.onClearNoteContent.bind(this));
this.ui.noteEditor.addEventListener('input', this.onEditNoteContent.bind(this));
this.note = this.getNoteContents();
this.renderNote();
},
getNoteID() {
return this.getQueryString('id') || this.setQueryString('id', this.date.getTime());
},
async onCopyNoteContent() {
let noteText = [this.note.title, this.note.text].join("\r\n");
try {
await navigator.clipboard.writeText(noteText);
console.log('Copied note!');
} catch (error) {
console.log('Error copying note', error)
}
},
async onShareNoteContent() {
try {
await navigator.share({
files: [new File([JSON.stringify(this.note, null, 2)], this.storageKey + '.json')]
});
console.log('Shared note!');
} catch (error) {
console.log('Error sharing note', error)
}
},
onClearNoteContent() {
this.storage() && this.storage().removeItem(this.storageKey);
this.note = this.getBlankNote();
this.renderNote();
},
onEditNoteContent() {
this.note.title = this.ui.noteTitle.innerText;
this.note.text = this.ui.noteEditor.value;
this.updateStoredNote();
},
getBlankNote() {
return {
title: 'Note from ' + this.date.toDateString(),
text: ''
}
},
getNoteContents() {
return this.storage() && this.storage().getItem(this.storageKey) ? JSON.parse(this.storage().getItem(this.storageKey)) : this.getBlankNote();
},
renderNote() {
this.ui.noteTitle.innerText = this.note.title;
this.ui.noteEditor.value = this.note.text;
this.ui.noteEditor.focus();
},
updateStoredNote() {
this.storage() && this.storage().setItem(this.storageKey, JSON.stringify(this.note));
},
setQueryString(key, val) {
var string = '?' + key + '=' + val;
history.pushState(null, null, string);
return val;
},
getQueryString(key) {
var params = window.location.search.slice(1),
urlParams = new URLSearchParams(params),
val = urlParams.get(key);
return val;
},
storage() {
var storage, fail, uid;
try {
uid = this.date;
(storage = window.localStorage).setItem(uid, uid);
fail = storage.getItem(uid) != uid;
storage.removeItem(uid);
fail && (storage = false);
} catch (exception) {
console.log("localStorage not available: " + exception);
}
return storage;
}
};
document.addEventListener("DOMContentLoaded", function(){
App.init();
});
</script>
</body>
</html>