-
Notifications
You must be signed in to change notification settings - Fork 161
/
index.html
272 lines (238 loc) · 10.1 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!doctype html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>phosphorus</title>
<link rel=stylesheet href=player.css>
<link rel=stylesheet href=index.css>
<div class=area id=title-area>
<h1 class=title>phosphorus</h1>
<p>phosphorus runs your Scratch projects really fast by compiling them to JavaScript. Try it out by pasting a URL or project ID into the field below or <a class=dropdown>choosing an example<select id=examples>
<option value>
<option value=11397100>3D Remix by DadOfMrLog
<option value=15945630>O by DCPU-16
<option value=10128407>Paper Minecraft by griffpatch
<option value=16207935>Alone in the depths by sticku
<option value=16205373>3D Framework by DadOfMrLog
<option value=31903442>gb.sb2 [Dr. Mario] by DCPU-16
<option value=34791164>gb.sb2 [Mario Land 2] by DCPU-16
<option value=21554369>Epic Ninja by griffpatch
<option value=15832807>Pretty by blob8108
</select></a>.</p>
</div>
<div class=area id=player-area>
<div class=controls>
<span class=stop></span>
<span class=pause></span>
<span class=flag title="Shift+click to enable turbo mode."></span>
<div class=turbo>Turbo Mode</div>
<span class=full-screen></span>
</div>
<div class=player></div>
<div class=internal-error>
An internal error occurred. <a id=error-bug-link target=_blank href=https://github.com/nathan/phosphorus/issues/new>Click here</a> to file a bug report.
</div>
</div>
<div class=title>
<div class=progress-bar></div>
<input class=url value=https://scratch.mit.edu/projects/>
<a target=_blank class=project-link title="View project on Scratch"></a>
</div>
<div class=area id=project-area>
<section class=package>
<h1>Package this project</h1>
<p>Get a link to a web page that automatically runs your project.</p>
<p>
<a href=# target=_blank id=package-link>Package</a>
<input type=checkbox id=package-turbo>
<label for=package-turbo>Turbo mode</label>
<input type=checkbox id=package-full-screen checked>
<label for=package-full-screen>Full screen</label>
</p>
</section>
<section class=package>
<h1>Embed this project</h1>
<p>Include the phosphorus player in your web site.</p>
<p>
<input readonly id=embed-code>
<input type=checkbox id=embed-auto-start checked>
<label for=embed-auto-start>Start automatically</label>
<input type=checkbox id=embed-light-content>
<label for=embed-light-content>Light controls</label>
<input type=checkbox id=embed-hide-controls>
<label for=embed-hide-controls>Hide UI</label>
</p>
</section>
<section>
<h1>Report a problem</h1>
<p>phosphorus is still in development. <a id=bug-link target=_blank href=https://github.com/nathan/phosphorus/issues/new>Click here</a> to report a problem with this project.</p>
</section>
</div>
<section>
<h1>Credits</h1>
<p>phosphorus was created by <a href=https://github.com/nathan>Nathan</a>. Its CPS-style compilation and overall design was inspired by <a href=https://github.com/RHY3756547>Rhys</a>'s <a href=https://code.google.com/p/sb2-js/>sb2.js</a>. It would have more bugs if not for <a href=https://github.com/trumank>Truman</a> and <a href=https://github.com/tjvr>Tim</a>. It uses the <a href=https://stuk.github.io/jszip/>JSZip</a> library, created by <a href=https://github.com/stuk>Stuart Knightley</a>, <a href=https://github.com/dduponchel>David Duponchel</a>, Franz Buchinger, and <a href=https://github.com/aadsm>António Afonso</a>, to read <code>.sb2</code> files and compressed projects, and the <a href=https://code.google.com/p/canvg/>canvg</a> library, created by <a href=https://code.google.com/u/[email protected]/>Gabe Lerner</a>, to render SVGs in <code><canvas></code> elements.
<h1>Code</h1>
<p>The source code for phosphorus is available <a href=https://github.com/nathan/phosphorus>on GitHub</a>.</p>
</section>
<script src=fonts.js></script>
<script src=//cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.js></script>
<script src=lib/rgbcolor.js></script>
<script src=lib/StackBlur.js></script>
<script src=lib/canvg.js></script>
<script src=phosphorus.js></script>
<script src=player.js></script>
<script>
(function() {
'use strict';
var prefix = 'https://scratch.mit.edu/projects/';
var initialId = location.hash.substr(1);
if (initialId === 'zip') initialId = '';
var titleArea = document.querySelector('#title-area');
var playerArea = document.querySelector('#player-area');
var projectArea = document.querySelector('#project-area');
playerArea.style.height = projectArea.style.height = 'auto';
var titleAreaHeight = titleArea.offsetHeight;
var playerAreaHeight = playerArea.offsetHeight;
var projectAreaHeight = projectArea.offsetHeight;
playerArea.style.height = projectArea.style.height = 0;
var examples = document.querySelector('#examples');
var urlInput = document.querySelector('.url');
urlInput.value = prefix + initialId;
var progressBar = document.querySelector('.progress-bar');
var player = document.querySelector('.player');
var projectLink = document.querySelector('.project-link');
var bugLink = document.querySelector('#bug-link');
var packageLink = document.querySelector('#package-link');
var packageTurbo = document.querySelector('#package-turbo');
var packageFullScreen = document.querySelector('#package-full-screen');
var embedCode = document.querySelector('#embed-code');
var embedAutoStart = document.querySelector('#embed-auto-start');
var embedLightContent = document.querySelector('#embed-light-content');
var embedHideControls = document.querySelector('#embed-hide-controls');
var timeout;
urlInput.addEventListener('input', function() {
var ss = urlInput.selectionStart;
var se = urlInput.selectionEnd;
var url = urlInput.value;
var id = url.match(/\d+/g) || [''];
while (id.length > 1 && id.indexOf(P.player.projectId) > -1) {
id.splice(id.indexOf(P.player.projectId), 1);
}
id = id[0];
urlInput.value = url = prefix + id;
urlInput.selectionStart = urlInput.selectionEnd = Math.max(prefix.length, ss);
clearTimeout(timeout);
if (P.player.projectId !== id) {
timeout = setTimeout(function() {
location.hash = '#' + id;
}, 300);
}
});
urlInput.addEventListener('focus', function() {
setTimeout(function() {
if (/\d/.test(urlInput.value)) {
urlInput.select();
}
});
});
examples.addEventListener('change', function() {
if (examples.value) {
location.hash = '#' + examples.value;
examples.selectedIndex = 0;
}
});
window.addEventListener('hashchange', function() {
var id = location.hash.substr(1);
if (id !== 'zip') {
if (+id !== +id) id = '';
urlInput.value = prefix + id;
}
load(id);
});
function show(id) {
titleArea.style.height = id ? 0 : titleAreaHeight + 'px';
playerArea.style.height = id ? playerAreaHeight + 'px' : 0
projectArea.style.height = id ? projectAreaHeight + 'px' : 0;
if (!id) urlInput.focus();
}
function load(id) {
if (id !== 'zip') {
show(id);
} else {
id = '';
}
document.title = 'phosphorus';
P.player.load(id, function(stage) {
stage.triggerGreenFlag();
}, function(title) {
document.title = title ? title + ' \xb7 phosphorus' : 'phosphorus';
updateBugLink();
});
projectLink.href = P.player.projectURL;
updateBugLink();
updatePackageLink();
updateEmbedCode();
}
function updateBugLink() {
bugLink.href = P.player.projectId ? 'https://github.com/nathan/phosphorus/issues/new?title=' + encodeURIComponent(P.player.projectTitle || P.player.projectURL) + '&body=' + encodeURIComponent('\n\n\n' + P.player.projectURL + '\nhttps://phosphorus.github.io/#' + P.player.projectId + '\n' + navigator.userAgent) : 'https://github.com/nathan/phosphorus/issues/new?body=' + encodeURIComponent('\n\n\n' + navigator.userAgent);
}
function updatePackageLink() {
packageLink.href = P.player.projectId ? '/app.html?id=' + P.player.projectId + '&turbo=' + packageTurbo.checked + '&full-screen=' + packageFullScreen.checked : 'about:blank';
}
packageTurbo.addEventListener('change', updatePackageLink);
packageFullScreen.addEventListener('change', updatePackageLink);
function updateEmbedCode(e) {
embedCode.value = P.player.projectId ? '<script src=https://' + location.host + '/embed.js?id=' + P.player.projectId + (embedHideControls.checked ? '&ui=false' : '&auto-start=' + embedAutoStart.checked + '&light-content=' + embedLightContent.checked) + '></' + 'script>' : '';
embedAutoStart.disabled =
embedLightContent.disabled = embedHideControls.checked;
if (embedHideControls.checked) embedAutoStart.checked = true;
if (e) embedCode.focus();
}
function selectEmbedCode() {
setTimeout(function() {
embedCode.select();
});
}
embedCode.addEventListener('focus', selectEmbedCode);
embedCode.addEventListener('click', selectEmbedCode);
embedHideControls.addEventListener('change', updateEmbedCode);
embedAutoStart.addEventListener('change', updateEmbedCode);
embedLightContent.addEventListener('change', updateEmbedCode);
load(initialId);
setTimeout(function() {
function setTransition(el) {
el.style.WebkitTransition =
el.style.MozTransition =
el.style.OTransition =
el.style.transition = 'height 0.2s';
}
setTransition(titleArea);
setTransition(playerArea);
setTransition(projectArea);
});
function cancel(e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
}
document.body.addEventListener('dragover', cancel);
document.body.addEventListener('dragenter', cancel);
document.body.addEventListener('drop', function(e) {
e.preventDefault();
var f = e.dataTransfer.files[0];
if (f) {
location.hash = '#zip';
show('zip');
var ext = f.name.split('.').pop();
if (ext === 'sb2' || ext === 'zip') {
var request = P.IO.loadSB2File(f);
} else if (ext === 'json') {
request = P.IO.loadJSONFile(f);
}
if (request) {
P.player.showProgress(request, function(stage) {
stage.triggerGreenFlag();
});
}
}
});
}());
</script>