-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
184 lines (174 loc) · 5.32 KB
/
demo.html
File metadata and controls
184 lines (174 loc) · 5.32 KB
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
<!DOCTYPE html>
<html>
<head>
<title>
dTweet Demo
</title>
<style>
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
background: #111;
text-align: center;
}
* {
overflow: hidden;
}
#iframe-container-wrapper {
width: 100%;
padding: 0 0 56.25% 0; /* 16:9 */
position: relative;
background: black;
}
#iframe-container {
position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
}
iframe {
width: 100%;
height: 100%;
border: 0;
outline: 0;
margin: 0;
padding: 0;
}
.share-overlay {
text-align: left;
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.8);
opacity: 0;
transition: opacity 0.1s;
z-index: 1;
color: grey;
padding: 15px;
font-size: 20px;
font-family: monospace;
}
.share-overlay input {
margin-left: 15px;
background: transparent;
font-family: monospace;
color: white;
border: 0;
outline: 0;
font-size: 20px;
border-bottom: 1px solid white;
}
html:hover .share-overlay,
body:hover .share-overlay,
.share-overlay:hover {
opacity: 1;
}
code {
white-space: pre;
}
</style>
</head>
<body>
<div id=iframe-container-wrapper>
<div id=iframe-container>
</div>
</div>
<div class=share-overlay>
<code>
function u(t) {
/* Will be called 60 times per second.
* t: Elapsed time in seconds.
* S: Shorthand for Math.sin.
* C: Shorthand for Math.cos.
* T: Shorthand for Math.tan.
* R: Function that generates rgba-strings, usage ex.: R(255, 255, 255, 0.5)
* c: A 1920x1080 canvas.
* x: A 2D context for that canvas. */
<input
id=editor
maxlength=140
autocomplete=off
autocorrect=off
autocapitalize=off
spellcheck=false
size=0
>
} // (<span id=character-count-display></span>/140)
</code>
</div>
<script>
(function() {
var prefix = '/t/';
var code = decodeURI(window.location.pathname.slice(prefix.length));
if(atob(code).length > 140) {
alert('code too long, sorry!');
return;
}
var editor = document.querySelector('#editor');
var ccd = document.querySelector('#character-count-display');
editor.value = atob(code);
var oldCode = editor.value;
replaceIframe(editor.value);
editor.size = Math.max(editor.value.length, 0);
ccd.innerText = editor.value.length;
editor.addEventListener('keyup', function() {
if(editor.value == oldCode) {
return;
}
editor.size = Math.max(editor.value.length, 0);
ccd.innerText = editor.value.length;
replaceIframe(editor.value);
oldCode = editor.value;
window.history.replaceState('', '', prefix + btoa(oldCode));
});
function replaceIframe(code) {
var iframe = document.createElement('iframe');
iframe.sandbox = 'allow-scripts';
var iframeContent = encodeURIComponent(
'<!DOCTYPE html>' +
'<head>' +
'<style>' +
'* {padding:0;margin:0;border:0;outline:0;overflow:hidden}' +
'canvas {' +
'width: 100%;' +
'background: white;' +
'}' +
'</style>' +
'</head>' +
'<body>' +
'<canvas id=c></canvas>' +
'<script>' +
'var c = document.querySelector("#c");' +
'c.width = 1920;' +
'c.height = 1080;' +
'var S = Math.sin;' +
'var C = Math.cos;' +
'var T = Math.tan;' +
'var R = function(r,g,b,a) {' +
'a = a === undefined ? 1 : a;' +
'return "rgba("+(r|0)+","+(g|0)+","+(b|0)+","+a+")";' +
'};' +
'var x = c.getContext("2d");' +
'var startT = +new Date(); ' +
'function u(t) {' +
code +
'};' +
'function loop() {' +
'requestAnimationFrame(loop);' +
'u((new Date() - startT) / 1000);' +
'};' +
'loop();' +
'</scr' + 'ipt>');
iframe.src = 'data:text/html;charset=utf-8,' + iframeContent;
var container = document.querySelector('#iframe-container');
container.innerHTML = '';
container.appendChild(iframe);
}
})();
</script>
</body>
</html>