-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
73 lines (62 loc) · 2.51 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
<!doctype html>
<head>
<title>Butterfly Sakura 1k</title>
<meta name="author" content="Author"></meta>
<meta name="description" content="Short description"></meta>
<meta name="title" content="Title"></meta>
<meta charset=utf-8>
</head>
<body id=b>
<canvas id=a></canvas>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
#a { position: relative; display: block; }
.play { position: fixed; top: 50%; left: 50%; transform: translateX(-50%)translateY(-50%); font-size: 30px; font-family: arial, sans-serif; background: #f3f4f5; padding: 15px; border: 2px solid #ddd; border-radius: 5px; }
</style>
<script>
// Entry configuration
// ===================
var title = "Butterfly Sakura 1k"; // this will be assigned automatically
// Shim setup and polyfills (do not edit)
// ======================================
// canvas automatically adjusted !
a.width = innerWidth;
a.height = innerHeight;
c = a.getContext("2d"); // no more $type conditional
d = document;
window.AudioContext = window.AudioContext || window.webkitAudioContext;
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
a.requestPointerLock = a.requestPointerLock || a.mozRequestPointerLock || a.webkitRequestPointerLock;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
if (typeof OscillatorNode !== 'undefined' && OscillatorNode.prototype) {
OscillatorNode.prototype.start = OscillatorNode.prototype.start || OscillatorNode.prototype.noteOn;
OscillatorNode.prototype.stop = OscillatorNode.prototype.stop || OscillatorNode.prototype.noteOff;
}
// Add a start button if sound is present in the code
onload = () => {
var entry_code = entry.innerText;
var has_sound = false;
if(entry_code.includes('eval')){
try {
eval(entry_code.replace(/eval\(/g, 'throw(').replace(/eval\`/g, 'throw`'));
}
catch(e){
entry_code = e;
}
}
if(entry_code.includes("AudioContext")||entry_code.includes("Oscillator")||entry_code.includes("speak")||entry_code.includes("play")||entry_code.includes("autoplay")){
b.insertAdjacentHTML("beforeEnd", "<button class='play' onclick='console.log(entry.innerText);eval(entry.innerText);this.remove()'>PLAY</button>");
}
else {
eval(entry.innerText);
}
};
console.log(
a, // canvas
b, // body
c, // 2D canvas context
d // document
);
</script>
<script src='./demo.js' id=entry></script>
</body>