diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2019-11-10 11:40:58 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2019-11-10 11:41:49 +0000 |
| commit | 3633e0db6b557ddba60984f04f29c4fd0deff943 (patch) | |
| tree | 69a71fbcb22af44efc476a54bbf6a6557f12bc8e | |
| parent | add README and examples (diff) | |
| download | leap-finger-scan-3633e0db6b557ddba60984f04f29c4fd0deff943.tar.gz leap-finger-scan-3633e0db6b557ddba60984f04f29c4fd0deff943.zip | |
load example on start
| -rw-r--r-- | Dockerfile | 1 | ||||
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | src/index.js | 19 |
3 files changed, 13 insertions, 14 deletions
@@ -7,4 +7,5 @@ RUN npm run build FROM nginx:alpine COPY --from=build-env /build/dist /usr/share/nginx/html +COPY --from=build-env /build/examples /usr/share/nginx/html/examples RUN chmod 555 -R /usr/share/nginx/html @@ -7,8 +7,5 @@ as the research basis for an ergonomic keyboard some time in the future.  You can try it in your browser at https://leap-finger-scan.s-ol.nu. -If you don't have a Leap, you can still play with my saved scans: - -1. download a scan from the `examples` folder -2. open the website -3. press `l` and load the data +If you don't have a Leap, it will load up one of my example captures automatically. +You can also load the other one (`examples/two.json`) and import it using the `L` key. diff --git a/src/index.js b/src/index.js index 0c3e79b..e5e0435 100644 --- a/src/index.js +++ b/src/index.js @@ -235,13 +235,7 @@ fingers = [0,1,2,3,4].map(i => { return finger; }); -const restore = (str) => { - if (!str) - return; - - const data = JSON.parse(str); - data.forEach((data, i) => fingers[i].load(data)); -} +const restore = (data) => data.forEach((data, i) => fingers[i].load(data)); let viewSliceOnly = false; window.onkeydown = (e) => { @@ -257,7 +251,7 @@ window.onkeydown = (e) => { input.onchange = e => { const reader = new FileReader(); - reader.onload = e => restore(e.target.result); + reader.onload = e => restore(JSON.parse(e.target.result)); reader.readAsText(e.target.files[0]); } } else if (e.key === 'Shift') { @@ -289,7 +283,14 @@ window.onkeyup = (e) => { } } -restore(localStorage.getItem('data')); +if (localStorage.getItem('data')) { + restore(JSON.parse(localStorage.getItem('data'))); +} else { + fetch('examples/one.json') + .then(r => r.json()) + .then(restore); +} + setInterval(() => { const data = fingers.map(finger => finger.store()); localStorage.setItem('data', JSON.stringify(data)); |
