-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript.js
More file actions
86 lines (61 loc) · 2.1 KB
/
javascript.js
File metadata and controls
86 lines (61 loc) · 2.1 KB
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
document.getElementById('img').addEventListener('change', ShowImg);
function ShowImg(evt) {
var files = evt.target.files,
f = files[0];
console.log(`This is the file name: ${f.name}`)
console.log(`This is the file size: ${f.size}k`)
// ou can also get easily the following attributes: lastModified (Timestamp), lastModifiedDate (Date), and type (FileType)
console.log(`Last modification :: ${f.lastModified}`)
console.log(`Last modification Date :: ${f.lastModifiedDate}`)
// alert("Changed") Test the event
if (files.length === 0) {
console.log('No file uploaded...');
return;
}
var reader = new FileReader();
reader.onload = function(event) {
var img = new Image();
img.onload = function() {
document.getElementById('result').appendChild(img);
};
img.src = event.target.result;
};
reader.readAsDataURL(files[0]);
}
function sliceFile(file, chunksAmount) {
var byteIndex = 0,
chunks = [];
for (var n = 1; n < chunksAmount; n++) {
var byteEnd = Math.ceil((file.size / chunksAmount) * (i + 1));
chunks.push(file.slice(byteIndex, byteEnd));
byteIndex += (byteEnd - byteIndex)
}
return file;
}
// Notification permission
Notification.requestPermission(() => {
if (Notification.permission === 'granted') {
alert("Cool")
} else if (Notification.permission === 'denied') {
alert('Notifications Denied')
} else {
alert('Default')
}
// Notification.close()
})
// Vibration
window.navigator.vibrate(100)
// Battery
navigator.getBattery().then((battery) => {
battery.addEventListener('chargingChange', function() {
console.log(`New charging battery ${battery.charging}`)
})
battery.addEventListener('levelChange', function() {
console.log(`New battery level: ${battery.level * 100}%`)
})
})
const EventClient = document.getElementById('Event'),
text = document.getElementById('text');
EventClient.onclick = () => {
alert(text.value) // This is just for test if the event works correctly
}