-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalHTML5VolumeControl.js
46 lines (38 loc) · 1.45 KB
/
globalHTML5VolumeControl.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
(function(){
var hash = function(s) {
for(var i = 0, h = 1; i < s.length; i++)
h = Math.imul(h ^ s.charCodeAt(i), 2654435761);
return (h ^ h >>> 7) >>> 0;
};
var audios = document.querySelectorAll('audio');
var volume;
var storageName = hash( window.location.hostname + '_salty!' ) + '_GlobalVolume';
var applyVolume = function () {
audios.forEach( function ( e ) { e.volume = volume; });
volumeControl.value = volume;
}
var volumeContainer = document.createElement('div');
volumeContainer.style = 'position: fixed; bottom: 0px; right: 0px; z-index: 999999;';
var volumeControl = document.createElement('input');
volumeControl.type = 'range';
volumeControl.max = 1;
volumeControl.min = 0;
volumeControl.step = 0.05;
volumeControl.value = 0.75;
volumeControl.onchange = function () {
volume = volumeControl.value;
localStorage.setItem( storageName, volume );
applyVolume();
}
var volumeClose = document.createElement('button');
volumeClose.textContent = 'X';
volumeClose.onclick = function () {
document.body.removeChild( volumeContainer );
delete( volumeContainer );
}
volumeContainer.appendChild( volumeControl );
volumeContainer.appendChild( volumeClose );
document.body.appendChild( volumeContainer );
volume = localStorage.getItem( storageName, volume ) || 0.75;
applyVolume();
})();