-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (51 loc) · 1.86 KB
/
main.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 theme=false;
let body = document.getElementsByTagName('body')[0];
async function Cook() {
url='https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies.json';
const response = await fetch(url);
const json = await response.json();
addOptions('fcurrency',json);
addOptions('scurrency',json);
}
function addOptions(id,obj){
let keys=Object.keys(obj);
for(i=0;i<keys.length;i++){
var option = document.createElement('option');
option.value= keys[i];
option.innerText= obj[option.value];
document.getElementById(id).appendChild(option);
}
}
async function calculate(){
let fcr=document.getElementById('fcurrency').value;
let scr=document.getElementById('scurrency').value;
let calUrl='https://raw.githubusercontent.com/fawazahmed0/currency-api/1/latest/currencies/'+fcr+'/'+scr+'.json';
const response = await fetch(calUrl);
const json = await response.json();
keys=Object.keys(json);
let rate=fcr.toUpperCase()+" 1 /- = "+scr.toUpperCase()+" "+json[keys[1]]+" /-";
document.getElementById('exrate').innerText=rate;
document.getElementById('exvalue').innerText=scr.toUpperCase()+" "+document.getElementById('currency-id').value*json[keys[1]]+" /-";
}
function toggleTheme() {
console.log(theme);
let switcher=document.getElementById("switcher");
let cross=document.getElementById("cross-icon");
let themeicon=document.getElementById("theme-icon");
if(theme==false){
switcher.style.display="block";
cross.style.display="block";
themeicon.style.display="none";
theme=true;
}else{
switcher.style.display="none";
cross.style.display="none";
themeicon.style.display="block";
theme=false;
}
}
function changeTheme(theme) {
body.classList.replace(body.classList[0],theme);
}
Cook();
calculate();