forked from cloudacademy/static-website-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
decoder.js
70 lines (56 loc) · 1.62 KB
/
decoder.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
function status(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response)
} else {
return Promise.reject(new Error(response.statusText))
}
}
function json(response) {
return response.json()
}
function compare_web_violation_decoder(violations_json,violation_value) {
myjson = {} ;
for(var key in violations_json){
if ((key & violation_value) != 0) {
myjson[key] = violations_json[key] ;
console.log(key + ' - ' + violations_json[key]);
}
}
console.log(myjson);
document.getElementById("web_violations_decoded").innerHTML = JSON.stringify(myjson, null, 2);
}
function compare_web_whitelist_decoder(whitelist_json, user_input_value) {
myjson = {} ;
for(var key in whitelist_json){
if ((key & user_input_value) != 0) {
myjson[key] = whitelist_json[key] ;
console.log(key + ' - ' + whitelist_json[key]);
}
}
console.log(myjson);
document.getElementById("web_whitelist_decoded").innerHTML = JSON.stringify(myjson, null, 2);
}
function web_violation_decode() {
fetch('/web_violations.json')
.then(status)
.then(json)
.then(function(data) {
if (n1.value != "") {
compare_web_violation_decoder(data,n1.value);
}
}).catch(function(error) {
console.log('Request failed', error);
});
};
function web_whitelist_decode() {
fetch('/web_whitelist.json')
.then(status)
.then(json)
.then(function(data) {
if (n2.value != "") {
compare_web_whitelist_decoder(data,n2.value);
}
}).catch(function(error) {
console.log('Request failed', error);
});
};