-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (63 loc) · 2.9 KB
/
index.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
"use strict";
const kartInput = document.getElementById("kartInput");
const kartInpContainer = document.getElementById("kartInputContainer");
const kartDataContainer = document.getElementById("kartDataContainer");
const kartBalance = document.getElementById("kartBalance");
const kartLastUseDate = document.getElementById("kartLastUseDate");
const kartLastUsePrice = document.getElementById("kartLastUsePrice");
const kartLastLoadDate = document.getElementById("kartLastLoadDate");
const kartLastLoadPrice = document.getElementById("kartLastLoadPrice");
const kartPendingBalance = document.getElementById("kartPendingBalance");
const pendinBalanceContainer = document.getElementById("pendinBalanceContainer");
let isActive = false;
const isModifierKey = (event) => {
const key = event.key;
return (key == "Shift" || key === "Control" || key === "Enter") ||
(key === "Backspace" || key === "Tab" || key === "Space" || key === "Delete") ||
(key == "ArrowLeft" || key == "ArrowRight" || key == "Home" || key == "End") ||
(
(event.ctrlKey === true || event.metaKey === true) &&
(key === "a" || key === "c" || key === "v" || key === "x" || key === "z")
)
};
function getData() {
kartDataContainer.style.display = "block";
fetch("https://openapi.izmir.bel.tr/api/iztek/bakiyesorgulama/"+kartInput.value.replace("-","")).then(response=>response.json()).then(data=>{
if (data.HataVarMi) {
alert("Hatalı Giriş");
return;
}
let bakiye = data.UlasimKartBakiyesi;
if (bakiye.BekleyenYuklemeler.length) {
let pendingTotal = 0;
for (const yukleme of bakiye.BekleyenYuklemeler) {
pendingTotal += parseFloat(yukleme.YuklenenTutar);
}
pendinBalanceContainer.style.display = "flex";
kartPendingBalance.innerHTML = pendingTotal + " TL";
}
else {
pendinBalanceContainer.style.display = "none";
}
kartBalance.innerHTML = bakiye.MevcutBakiye + " TL";
kartLastUseDate.innerHTML = bakiye.SonIslemTarihi;
kartLastUsePrice.innerHTML = bakiye.SonHarcananTutar + " TL";
kartLastLoadDate.innerHTML = bakiye.SonYuklemeTarihi;
kartLastLoadPrice.innerHTML = bakiye.SonYuklenenTutar + " TL";
});
}
kartInput.addEventListener("keydown", function (event) {
if (!(event.key >= 0 && event.key <= 9) && !isModifierKey(event)) {
event.preventDefault();
}
});
kartInput.addEventListener("keyup", function (event) {
event.target.value = event.target.value.replace(/[^0-9]/g, '').replace(/^(\d{5})(\d{1,5})$/, '$1-$2').replace(/^(\d{5})(\d{5})(\d{1})$/, '$1-$2-$3');
if (event.target.value.length == 13){
if (!isActive) {
kartInpContainer.style.transform = "translate(-50%, -200px)";
isActive = true;
}
getData();
}
});