/
404.html
687 lines (564 loc) Β· 17.5 KB
/
404.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>printi</title>
<meta charset="utf-8" />
<script>
console.log("printi, by Fons van der Plas (http://github.com/fonsp) π");
</script>
<meta name="author" content="Fons van der Plas" />
<link rel="author" href="https://github.com/fonsp" />
<link rel="license" href="https://github.com/fonsp/printi/blob/master/LICENSE" />
<meta name="theme-color" content="#FFEFEF" />
<meta name="description" content="Send your pictures to the world's fastest photo printer!" />
<link href="https://fonts.googleapis.com/css?family=Courgette|Itim" rel="stylesheet">
<style>
/* GENERAL PAGE LAYOUT */
body {
background-color: #ffe3e3;
margin: 0px;
}
main,
footer {
margin: 0 auto;
width: 250px;
align-content: center;
text-align: center;
}
footer {
text-decoration: underline;
font-family: monospace;
font-style: italic;
margin-top: 400px;
padding-bottom: 50px;
}
footer a {
color: black;
opacity: .6;
}
#logje {
text-align: left;
font-family: monospace;
}
#logje p::before {
content: "> ";
opacity: .5;
}
/* HEADER */
header {
letter-spacing: 3px;
background-color: #ffefef;
font-family: 'Courgette', sans-serif;
width: 100%;
overflow: hidden;
}
#logocontainer {
margin: 0 auto;
width: 250px;
height: 80px;
padding-top: 30px;
padding-bottom: 20px;
align-content: center;
text-align: center;
position: relative;
}
#logocontainer img {
margin-bottom: -8px;
margin-left: 5px;
margin-right: 5px;
}
#logocontainer h1 {
margin-top: 10px;
}
#printernametitle {
position: absolute;
white-space: nowrap;
font-weight: normal;
opacity: .6;
}
/* PRINTI CAM */
.titlesecret {
background-color: rgba(255, 255, 255, .75);
width: 100%;
align-content: center;
text-align: center;
font-size: 40px;
cursor: pointer;
overflow: hidden;
}
#cameracontainer {
max-height: 0px;
transition: max-height 500ms;
-webkit-transition: max-height 500ms;
}
#printicambuttoncontainer {
height: 0px;
transition: height 500ms;
-webkit-transition: height 500ms;
}
.showcamera {
max-height: 500px !important;
}
.showprinticambutton {
height: 80px !important;
}
.printicamrotator {
font-family: monospace;
text-decoration: underline;
font-size: 15px;
margin: auto;
padding-top: 10px;
overflow: hidden;
letter-spacing: .3ex;
}
.printicamtext {
animation: moveleft 1500ms linear;
animation-iteration-count: infinite;
}
@keyframes moveleft {
0% {
margin-left: 0ex;
}
100% {
margin-left: -100%;
}
}
#videoscreen {
width: 250px;
margin: auto;
background-color: white;
padding-top: 12px;
}
video {
width: 226px;
pointer-events: none;
}
.takepicture {
animation: pictureflash 200ms linear;
}
@keyframes pictureflash {
0% {
filter: grayscale(1.0) contrast(2.0);
}
100% {
filter: grayscale(0.0) contrast(1.0);
}
}
/* MAIN */
.receiptcontainer {
overflow: hidden;
font-family: monospace;
overflow-wrap: break-word;
}
.receiptpadder {
padding-top: 20px;
/*
--Timing--
Printer speed: 4.5 inch per second = 114.3 mm/s
Receipt width: 80 mm or 250 px
=> Printer speed: 114.3 * 250 / 80 = 357.1875 px/s
Transition distance: 1000px
=> Transition duration: 1000 / 357.1875 = 2.8 s
*/
transition: margin 2800ms;
-webkit-transition: margin 2800ms;
transition-timing-function: linear;
-webkit-transition-timing-function: linear;
}
.receiptbackground {
padding: 12px;
border: 5px solid white;
background-color: white;
position: relative;
}
#curtain {
transition: 200ms linear left;
position: absolute;
right: 0px;
top: 0px;
height: 100%;
width: 0%;
background-color: rgba(255, 255, 255, 0.8);
}
.previewimg {
max-width: 100%;
height: auto;
transition: 500ms filter linear;
-webkit-transition: 500ms -webkit-filter linear;
}
.bwfilter {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
}
#formcontainer {
overflow-x: hidden;
}
.printed {
margin-top: -1000px !important;
}
.wiggler {
animation: wiggle 200ms;
animation-iteration-count: infinite;
-webkit-animation: wiggle 200ms;
-webkit-animation-iteration-count: infinite;
}
@keyframes wiggle {
0% {
transform: rotate(0deg);
}
25% {
transform: rotate(-1deg);
}
50% {
transform: rotate(0deg);
}
75% {
transform: rotate(1deg);
}
100% {
transform: rotate(0deg);
}
}
.fadein {
animation: fadein 1000ms linear;
}
@keyframes fadein {
0% {
opacity: 0%;
}
80% {
opacity: 0%;
}
100% {
opacity: 100%;
}
}
</style>
</head>
<body>
<header>
<div id="logocontainer">
<h1><img src="Content/printi_logo_transparent.svg" width="100" height="34" alt="printi" title="printi" /><span id="printernametitle"></span></h1>
</div>
<div id="cameracontainer" class="titlesecret">
<div id="videoscreen">
<video playsinline autoplay></video>
</div>
</div>
<div id="printicambuttoncontainer" class="titlesecret">
<div class="printicamrotator" style="width: 8.4ex; transform: rotate(-15deg) translate(-17px, 12px);">
<div class="printicamtext" style="animation-duration: 3000ms;">printiprintiprintiprinti</div>
</div>
<div class="printicamrotator" style="width: 4.2ex; transform: rotate(-15deg) translate(23px, 7px);">
<div class="printicamtext">camcamcamcam</div>
</div>
</div>
</header>
<main id="receiptstack">
<span style="display: none" id="receiptprototype">
<div class="receiptcontainer">
<div class="receiptpadder">
<div class="receiptbackground">
<div class="preview">
<img class="previewimg" src="#" width="250" />
<div id="curtain"></div>
</div>
</div>
</div>
</div>
</span>
<div class="receiptcontainer" id="receiptupload">
<div class="receiptpadder">
<div class="receiptbackground">
<div id="formcontainer">
<form id="leform" action="" method="post" enctype="multipart/form-data" target="responseframe">
<input id="filepicker" type="file" name="theshiz" accept="image/*">
<!--<br /><br />
<input type="submit">-->
</form>
</div>
</div>
</div>
</div>
<span id="logje"></span>
<iframe name="responseframe" style="display: none;"></iframe>
</main>
<footer>
<a href="https://github.com/fons-/printi/blob/master/README.md" rel="help">What is printi?</a>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function() {
if (document.location.pathname != "/") {
document.querySelector("#printernametitle").textContent = decodeURI(document.location.pathname)
}
if (window.location.search.indexOf("log") != -1) {
if (typeof console != "undefined")
if (typeof console.log != 'undefined')
console.olog = console.log;
else
console.olog = function() {};
console.log = function(message) {
console.olog(message);
var messageEl = document.createElement("p");
messageEl.innerText = message;
document.querySelector('#logje').prepend(messageEl);
};
console.error = console.debug = console.info = console.log;
console.log("Now logging on page π");
}
var video = document.querySelector("video");
window.video = video;
// Renders the image source onto a downscaled canvas and returns a jpeg/png compressed DataURI
sourceToDataUri = function(source, width, height) {
console.log(source);
var canvas = document.createElement("canvas"); // (will not be displayed)
var PAGEWIDTH = document.location.pathname == "/" ? 576 : 384; // 576 for printi classic, 384 for printi mini
var vert = height > width;
var minorlength = vert ? width : height;
var newWidth = 0;
var newHeight = 0;
if (minorlength <= PAGEWIDTH) {
newWidth = width;
newHeight = height;
} else {
var ratio = PAGEWIDTH / minorlength;
newWidth = vert ? PAGEWIDTH : ratio * width;
newHeight = vert ? ratio * height : PAGEWIDTH;
}
canvas.width = newWidth;
canvas.height = newHeight;
var ctx = canvas.getContext("2d");
ctx.drawImage(source, 0, 0, newWidth, newHeight);
console.log(canvas);
console.log(canvas.width);
console.log(canvas.height);
var datayumyum;
if (minorlength <= PAGEWIDTH) {
// uploaded file was probably purposefully cropped to printi dimensions;
// we will not compress
datayumyum = canvas.toDataURL("image/png");
} else {
// render image to a jpeg (data URI) at 70% compression quality
datayumyum = canvas.toDataURL("image/jpeg", .7);
}
// strip header from data URI
var base64data = datayumyum.split(',')[1];
//TODO: destroy canvas?
return {
dataURL: datayumyum,
base64data: base64data,
};
};
// Performs the image compression, networking and UI of a single file or video.
uploadImage = function(fileSource, videoSource) {
// Will hold the DOM element of the receipt corresponding to this image.
var receiptEl = document.querySelector("#receiptprototype > div").cloneNode(true);
// Not supported in IE:
//document.querySelector("#receiptstack").prepend(receiptEl);
document.querySelector("#receiptstack").insertBefore(receiptEl, document.querySelector("#receiptprototype"));
var xhr = new XMLHttpRequest();
// We first define the (graphical) event handlers for loading progress and loading completion.
xhr.upload.onprogress = function(e) {
console.log(e);
console.log(xhr);
var reverseprogress = ((e.total - e.loaded) / e.total) * 100;
receiptEl.querySelector("#curtain").setAttribute("style", "width: " + reverseprogress + "%;");
if (reverseprogress < 5 && !receiptEl.classList.contains("wiggler")) {
receiptEl.classList.add("wiggler");
}
};
xhr.onload = function(e) {
console.log(e);
receiptEl.querySelector("#curtain").setAttribute("style", "width: 0%;");
try{
receiptEl.querySelector(".previewimg").classList.add("bwfilter");
} catch (e){}
setTimeout(function() {
receiptEl.classList.remove("wiggler");
receiptEl.querySelector(".receiptpadder").classList.add("printed");
setTimeout(function() {
//TODO: remove el
document.querySelector("#receiptstack").removeChild(receiptEl);
}, 2000);
}, 1000);
};
xhr.onerror = console.log;
xhr.onabort = console.log;
const api_server = window.printi_api_server ?? "https://api.printi.me"
const printi_name = window.printi_name ?? document.location.pathname.replace(/^\//, '')
console.log("Sending to ", new URL(`submitimages/${printi_name}`, api_server))
xhr.open('POST', new URL(`submitimages/${printi_name}`, api_server), true);
var ua = window.navigator.userAgent;
var ie = (ua.indexOf('MSIE ') + ua.indexOf('Trident/') + ua.indexOf('Edge/') > -3);
var isNotAnImageFile = videoSource === null && (!fileSource.type.match("image.*"));
var filereadersupport = 'FileReader' in window;
if (!ie && !isNotAnImageFile && filereadersupport) {
// We will compress the image, and send it to the API as a base64 encoded string.
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
if (videoSource !== null) {
// in this case, we are not dealing with a file upload, but with a printi cam video snapshot
var result = sourceToDataUri(videoSource, videoSource.videoWidth, videoSource.videoHeight);
receiptEl.querySelector(".previewimg").setAttribute("src", result.dataURL);
console.log("sending...");
xhr.send(JSON.stringify({
images: [result.base64data]
}));
} else {
console.log(fileSource);
var reader = new FileReader();
reader.onload = function(e) {
receiptEl.querySelector(".previewimg").setAttribute("src", e.target.result);
var immie = document.createElement("img"); // (will not be displayed)
immie.onload = function() {
console.log("immie loaded:");
console.log(immie.width);
console.log(immie.height);
var result = sourceToDataUri(immie, immie.width, immie.height);
console.log("sending...");
xhr.send(JSON.stringify({
images: [result.base64data]
}));
};
// setting the image source starts the loading process
immie.src = e.target.result;
}
// start the file reading process
reader.readAsDataURL(fileSource);
}
} else {
console.log("not downsizing; sending raw files...");
var previewEl = receiptEl.querySelector(".preview");
var filenameP = document.createElement("p");
filenameP.innerText = fileSource.name;
var previewImg = previewEl.querySelector("img");
previewImg.parentNode.removeChild(previewImg);
previewEl.appendChild(filenameP);
var data = new FormData();
data.append("file0", fileSource);
xhr.send(data);
}
};
document.getElementById("filepicker").onchange = function() {
for (var i = 0; i < this.files.length; i++) {
uploadImage(this.files[i], null);
}
// To make it look like a new form was created:
var receiptUploadEl = document.getElementById("receiptupload");
receiptUploadEl.classList.remove("fadein");
void receiptUploadEl.offsetHeight;
receiptUploadEl.classList.add("fadein");
receiptUploadEl.querySelector("input").value = "";
};
document.addEventListener('paste', function(e) {
if (e.clipboardData) {
var items = e.clipboardData.items;
var pastedFiles = [];
for (var i = 0; i < items.length; i++) {
console.log(items[i].type)
// if an image is pasted, convert it to a file and add it to the file list for uploading.
if (items[i].type.indexOf("image") >= 0) {
var blob = items[i].getAsFile();
pastedFiles.push(blob);
}
// if text is pasted, we assume that it is a URL, and it will be sent to the URL server (which is actually deprecated...)
if (items[i].type.indexOf("text") >= 0) {
/*items[i].getAsString(function(s) {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://url.printi.me/api/url/printi', true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify({
url: s
}));
document.querySelector(".preview").setAttribute("style", "display: block;");
//document.querySelector("#formcontainer").setAttribute("style", "display: none;");
});*/
//alert("Oops! URL support has been deprecated, but the printi mail feature might be useful π")
}
}
for (var i = 0; i < pastedFiles.length; i++) {
uploadImage(pastedFiles[i], null);
}
e.preventDefault();
}
}, false);
document.body.ondrop = function(e) {
e.preventDefault();
if (e.dataTransfer.items) {
for (var i = 0; i < e.dataTransfer.items.length; i++) {
if (e.dataTransfer.items[i].kind === "file") {
uploadImage(e.dataTransfer.items[i].getAsFile(), null);
}
}
} else {
for (var i = 0; i < e.dataTransfer.files.length; i++) {
uploadImage(e.dataTransfer.files[i], null);
}
}
};
document.body.ondragenter = document.body.ondragover = document.body.onddragleave = function(e) {
e.preventDefault();
}
/* PRINTI CAM */
window.cameraConnected = false;
document.getElementById("logocontainer").onclick = function() {
if (window.cameraConnected) {
var cl = document.getElementById("cameracontainer").classList;
if (cl.contains("showcamera")) {
setTimeout(function() {
window.stream.getTracks()[0].stop();
window.cameraConnected = false;
video.srcObject = null;
}, 500);
}
cl.toggle("showcamera");
} else {
document.getElementById("printicambuttoncontainer").classList.toggle("showprinticambutton");
}
};
document.getElementById("printicambuttoncontainer").onclick = function() {
navigator.mediaDevices.getUserMedia({
audio: false,
video: {
facingMode: "environment",
},
}).then(function(stream) {
window.stream = stream;
video.srcObject = stream;
window.cameraConnected = true;
video.controls = false;
video.play();
video.controls = false;
document.getElementById("printicambuttoncontainer").classList.remove("showprinticambutton");
document.getElementById("cameracontainer").classList.add("showcamera");
}).catch(function(error) {
console.log(error);
window.cameraConnected = false;
});
};
// Turns off the camera when the page is out of focus
document.onvisibilitychange = function() {
if (window.cameraConnected) {
if (document.visibilityState != "visible") {
window.stream.getTracks()[0].stop();
window.cameraConnected = false;
video.srcObject = null;
document.getElementById("printicambuttoncontainer").classList.add("showprinticambutton");
document.getElementById("cameracontainer").classList.remove("showcamera");
}
}
};
document.getElementById("cameracontainer").onclick = function() {
var cl = video.classList;
cl.remove("takepicture");
void video.offsetHeight;
cl.add("takepicture");
video.play();
video.controls = false;
uploadImage(null, video);
};
});
</script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
</body>
</html>