about summary refs log tree commit diff stats
path: root/js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-01-15 21:15:17 -0500
committerelioat <elioat@tilde.institute>2024-01-15 21:15:17 -0500
commite71fd1a14ed539b7c8d328e5df13df65ae939189 (patch)
treed1226cfdba61a7e0fc7ee4f3191ae65d93dc7531 /js
parent12723d963540e99bb60197042e705260e01882ce (diff)
downloadtour-e71fd1a14ed539b7c8d328e5df13df65ae939189.tar.gz
*
Diffstat (limited to 'js')
-rw-r--r--js/inknswitch/ink.js68
-rw-r--r--js/inknswitch/sw.js15
2 files changed, 40 insertions, 43 deletions
diff --git a/js/inknswitch/ink.js b/js/inknswitch/ink.js
index dbfa0e4..3ac1892 100644
--- a/js/inknswitch/ink.js
+++ b/js/inknswitch/ink.js
@@ -1,12 +1,12 @@
 if ('serviceWorker' in navigator) {
     navigator.serviceWorker.register('./sw.js')
     .then(function(registration) {
-      console.log('Service Worker registered with scope:', registration.scope);
+        console.log('Service Worker registered with scope:', registration.scope);
     })
     .catch(function(err) {
-      console.log('Service Worker registration failed:', err);
+        console.error('Service Worker registration failed:', err);
     });
-  }
+}
 
 document.getElementById('noteArea').focus(); // ensures that textarea is focused when the page loads
 
@@ -125,6 +125,25 @@ if (savedImage) {
     img.src = savedImage;
 }
 
+const saveCanvasAsImage = () => {
+    const confirmDownload = confirm('Do you really want to save the canvas as an image?');
+    if (confirmDownload) {
+        const dataUrl = canvas.toDataURL();
+        const a = document.createElement('a');
+        a.href = dataUrl;
+        a.download = 'canvas.png';
+        a.click();
+    }
+}
+
+const clearCanvas = () => {
+    const confirmClear = confirm('Do you really want to clear the canvas?');
+    if (confirmClear) {
+        ctx.clearRect(0, 0, canvas.width, canvas.height);
+        localStorage.removeItem('canvasImage');
+    }
+}
+
 // Toggle between drawing and note mode
 const toggle = () => {
     if (canvas.style.pointerEvents === 'none') {
@@ -155,37 +174,11 @@ toggleButton.addEventListener('click', toggle);
 
 const helpText = "This is a modal note taking tool. With it, you can type text that'll be saved to the browser, and you can draw pictures that'll also be saved to the browser. You are in typing mode right now. To toggle between modes tap either cmd + d, ctrl + d or cmd + 1, or ctrl + 1. When in drawing mode, tap c to clear the canvas, tap s to save the contents of the canvas to a png."
 
-// Currently unused
-// const saveTextAsFile() => {
-//     const textToWrite = document.getElementById('noteArea').value;
-//     const textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' });
-//     const fileNameToSaveAs = 'notes.txt';
-
-//     const downloadLink = document.createElement('a');
-//     downloadLink.download = fileNameToSaveAs;
-//     downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
-//     downloadLink.style.display = 'none';
-//     document.body.appendChild(downloadLink);
-//     downloadLink.click();
-//     document.body.removeChild(downloadLink);
-// }
-
 const handleSelectChange = () => {
     if (selectElement.value === 'clear') {
-        const confirmClear = confirm('Do you really want to clear the canvas?');
-        if (confirmClear) {
-            ctx.clearRect(0, 0, canvas.width, canvas.height);
-            localStorage.removeItem('canvasImage');
-        }
+        clearCanvas();
     } else if (selectElement.value === 'save') {
-        const confirmDownload = confirm('Do you really want to save the canvas as an image?');
-        if (confirmDownload) {
-            const dataUrl = canvas.toDataURL();
-            const a = document.createElement('a');
-            a.href = dataUrl;
-            a.download = 'canvas.png';
-            a.click();
-        }
+        saveCanvasAsImage();
     } else if (selectElement.value === 'help') {
         alert(helpText);
     }
@@ -206,23 +199,16 @@ const handleKeyDown = (e) => {
 
     // C key to clear the canvas
     if (e.key === 'c' && canvas.style.pointerEvents === 'auto') {
-        const confirmClear = confirm('Do you really want to clear the canvas?');
-        if (confirmClear) {
-            ctx.clearRect(0, 0, canvas.width, canvas.height);
-            localStorage.removeItem('canvasImage');
-        }
+        clearCanvas();
     }
 
     // S key to save the canvas as an image
     if (e.key === 's' && canvas.style.pointerEvents === 'auto') {
-        const dataUrl = canvas.toDataURL();
-        const a = document.createElement('a');
-        a.href = dataUrl;
-        a.download = 'canvas.png';
-        a.click();
+        saveCanvasAsImage();
     }
 
     localStorage.setItem('noteContent', noteArea.value);
 };
 
 document.addEventListener('keydown', handleKeyDown);
+
diff --git a/js/inknswitch/sw.js b/js/inknswitch/sw.js
index 81e6bf4..4a63871 100644
--- a/js/inknswitch/sw.js
+++ b/js/inknswitch/sw.js
@@ -4,12 +4,23 @@ self.addEventListener('install', function(event) {
         return cache.addAll([
           './index.html',
           './ink.js',
-          './icon.png',
           './android-icon-36x36.png',
           './android-icon-48x48.png',
           './android-icon-72x72.png',
           './android-icon-96x96.png',
-          './android-icon-144x144.png'
+          './android-icon-144x144.png',
+          './android-icon-192x192.png',
+          './apple-icon-57x57.png',
+          './apple-icon-60x60.png',
+          './apple-icon-72x72.png',
+          './apple-icon-76x76.png',
+          './apple-icon-114x114.png',
+          './apple-icon-120x120.png',
+          './apple-icon-144x144.png',
+          './apple-icon-152x152.png',
+          './apple-icon-180x180.png',
+          './apple-icon-precomposed.png',
+          './apple-icon.png',
         ]);
       })
     );
-0700 996 - string literals' href='/akkartik/mu/commit/cpp/029string?h=main&id=66b97b4d923274e1b6d2fd97df16cb73d820169b'>66b97b4d ^
7fb3fccb ^




























fc52705f ^

7fb3fccb ^
66b97b4d ^

fc52705f ^
ff58b456 ^
23fd54f1 ^
b1bfd921 ^
23fd54f1 ^

66b97b4d ^

ff58b456 ^


66b97b4d ^
1d0a623a ^

7fb3fccb ^




fc52705f ^

7fb3fccb ^

fc52705f ^




7fb3fccb ^











fc52705f ^
1d0a623a ^
fc52705f ^

66b97b4d ^
5e21a9f6 ^
7a9b05fa ^
05d17773 ^


7a9b05fa ^

7c0d16a7 ^
7a9b05fa ^






ea542d0a ^




7cc045d9 ^



















88be3dbc ^
3d6c13dc ^
e3fa6cc7 ^
3d6c13dc ^
c712c271 ^
c51043ab ^
23fd54f1 ^



c712c271 ^
23fd54f1 ^
fc52705f ^






c51043ab ^



35457609 ^
c712c271 ^
d7494165 ^
4f5cf668 ^
c51043ab ^
2f677225 ^






7fb3fccb ^














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