-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (45 loc) · 1.32 KB
/
app.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
// console.log('here');
//doms
const container = document.querySelector('.container');
const topic = document.querySelector('#topic');
const title = document.querySelector('#title');
const body = document.querySelector('#body');
const email = document.querySelector('#email');
const key = document.querySelector('#key');
const button = document.getElementById('submit');
const log = document.getElementById('log');
//
const url = 'https://fcm.googleapis.com/fcm/send';
//event listeners
button.addEventListener('click',sendNotification);
function sendNotification(e){
e.preventDefault();
button.disabled = true;
topic.disabled = true;
title.disabled = true;
body.disabled = true;
if(topic.value ==='' || title ==='' || body === '' || key.value === ''){
showError('please enter all the fields correctly')
}
else{
let data = {
"data": {
"title": title.value,
"body": body.value,
"token": "permission"
},
"to": "/topics/" + topic.value,
"priority": "high"
}
send(url,data,key.value,callBack);
}
}
function callBack(posts){
showError(posts);
}
function showError(error){
log.innerHTML = error;
setTimeout(() => {
document.location.reload(true);
},3000);
}