-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (65 loc) · 1.65 KB
/
index.js
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
if (document.readyState == 'loading') {
document.addEventListener('DOMContentLoaded', ready)
}
else {
ready()
}
var playState = false;
var music = new Sound('music/fcpremix.mp3', 20, true)
function ready() {
var playButton = document.getElementsByClassName('btn-play')[0]
playButton.addEventListener('click', playClick)
}
function playClick(event) {
if (!playState) play(event)
else pause(event)
}
function play(event) {
music.start()
playState = true;
var button = event.target
button.innerText = '▐▐'
button.style.fontSize = '10px'
}
function pause(event) {
music.stop()
playState = false;
var button = event.target
button.innerText = '▶️'
button.style.fontSize = '1em'
}
function Sound(source, volume, loop)
{
this.source = source;
this.volume = volume;
this.loop = loop;
var son;
this.son = son;
this.finish = false;
this.stop = function()
{
document.body.removeChild(this.son);
}
this.start = function()
{
if (this.finish) return false;
this.son = document.createElement("embed");
this.son.setAttribute("src", this.source);
this.son.setAttribute("hidden", "true");
this.son.setAttribute("volume", this.volume);
this.son.setAttribute("autostart", "true");
this.son.setAttribute("loop", this.loop);
document.body.appendChild(this.son);
}
this.remove = function()
{
document.body.removeChild(this.son);
this.finish = true;
}
this.init = function(volume, loop)
{
this.finish = false;
this.volume = volume;
this.loop = loop;
}
}