-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
250 lines (245 loc) · 9.83 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
<!doctype html>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>ScratchViewer</title>
<!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />-->
<link rel=stylesheet href='./player.css'>
<link rel=stylesheet href='./index.css'>
</head>
<div class=area id=title-area>
<h1 class=title>ScratchViewer</h1>
<p>Scratch Viewer 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=114718620>Tree Maker by csf30816
<option value=114510033>Pen Dot - First Experience by csf30816
<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>
<div id=title></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/csf30816/scratchviewer/issues/new>Click here</a> to file a bug report.
</div>
</div>
<div class=title>
<div class=progress-bar></div>
<input class=url value=http://scratch.mit.edu/projects/ spellcheck=false>
<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 the project on the screen.</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 ScratchViewer 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>ScratchViewer is still in development. <a id='bug-link' target='_blank' href='https://github.com/csf30816/scratchviewer/issues/new'>Click here</a> to report a problem with this project.</p>
</section>
</div>
<section>
<h1>Credits</h1>
<p>Scratchviewer is and edited version of Phosphorus by <a href='https://github.com/nathan'>Nathan Dinsmore</a>, but was edited by <a href='https://github.com/csf30816'>Csf30816</a>.
<h1>Code</h1>
<p>The source code for ScratchViewer is available <a href='https://github.com/csf30816/scratchviewer'>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 type="text/javascript" src="http://canvg.github.io/canvg/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/StackBlur.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/canvg.js"></script>
<script src='phosphorus.js'></script>
<script src='player.js'></script>
<script>
(function() {
'use strict';
if (location.protocol === 'https:') {
location.replace(('' + location).replace(/^https:/, 'http:'));
}
var prefix = 'http://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 = 'ScratchViewer';
P.player.load(id, function(stage) {
stage.triggerGreenFlag();
}, function(title) {
document.title = title ? title + ' \xb7 ScratchViewer' : 'ScratchViewer';
document.getElementById('title').innerHTML = title;
updateBugLink();
});
projectLink.href = P.player.projectURL;
updateBugLink();
updatePackageLink();
updateEmbedCode();
}
function updateBugLink() {
bugLink.href = P.player.projectId ? 'https://github.com/csf30816/scratchviewer/issues/new?title=' + encodeURIComponent(P.player.projectTitle || P.player.projectURL) + '&body=' + encodeURIComponent('\n\n\n' + P.player.projectURL + '\nhttp://scratchviewer.usa.cc/#' + P.player.projectId + '\n' + navigator.userAgent) : 'https://github.com/csf30816/acratchviewer/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>