-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirect.js
52 lines (44 loc) · 1.28 KB
/
direct.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
var ready = function(fn) {
if (document.readyState != 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
};
var checkLoad = function() {
if (this.status >= 200 && this.status < 400) {
document.getElementById('slack').style.display = 'none';
document.getElementById('confirm').style.display = 'block';
} else {
alert('Error with API Endpoint\n' + this.repsonse);
}
};
var ajaxError = function() {
alert('Connection Error with API Endpoint');
};
var processFormData = function() {
return JSON.stringify({
'text': document.getElementById('email')
.value + ' asks: ' + document.getElementById('message').value,
'username': document.getElementById('name').value,
'icon_emoji': ':slack:'
});
};
var submitter = function(event) {
var request = new XMLHttpRequest();
request.open('POST',
'https://hooks.slack.com/services/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',
true);
request.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded; charset=UTF-8'
);
request.onload = checkLoad;
request.onerror = ajaxError;
request.send(processFormData());
event.preventDefault();
};
ready(function() {
document.getElementById('slack')
.addEventListener('submit', submitter);
});