-
Notifications
You must be signed in to change notification settings - Fork 1
/
snippet.js
55 lines (42 loc) · 1.15 KB
/
snippet.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
let closedGates = ['כסף 105-R'];
function getData() {
return fetch(location.href)
.then(response => response.text())
.then(res => {
const regex = /'areas': ([\s\S]*?)}] },/g;
m = regex.exec(res)
let data = m[1] + '}]'
data = data.replaceAll('oColor', '"oColor"');
data = JSON.stringify(JSON.parse(data).filter(gate => (!filterGates(gate.name))));
let copy = {date: new Date().toLocaleString('he').replace(',' , ''), values: data};
navigator.clipboard.writeText(JSON.stringify(copy));
console.log(copy)
run(JSON.parse(data))
})
}
function run(data) {
var res = {};
var sum = {
capacity: 0,
free: 0,
counter: 0
}
data.forEach(area =>{
const {capacity, name, free} = area;
const taken = capacity - free;
if(filterGates(name)){
return;
}
res[name] = {capacity, free, taken}
sum.capacity += capacity;
sum.free += free;
sum.counter += taken
})
console.table(sum);
console.table(res);
}
function filterGates(gate){
return closedGates.indexOf(gate) > -1 ||
gate > 500 || gate.indexOf('תא תקשורת') > -1
}
getData();