Repository navigation
Expand file tree
/
Copy pathscripts.js
More file actions
293 lines (248 loc) · 9.59 KB
/
Copy pathscripts.js
File metadata and controls
293 lines (248 loc) · 9.59 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
///////////////////////////////////////////////////////////////////////////////
// File: script.js
//
// Desc:
//
// Author: Ana Cristina Schmidt, Fernando Acauan e Thiago Tarantino.
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Variaveis Globais
///////////////////////////////////////////////////////////////////////////////
g_trocou = false;
let g_dictionary = {
"AED": "AE", // United Arab Emirates Dirham
"AFN": "AF", // Afghan Afghani
"ALL": "AL", // Albanian Lek
"AMD": "AM", // Armenian Dram
"ANG" : "AO",
"AOA": "AO", // Angolan Kwanza
"ARS": "AR", // Argentine Peso
"AUD": "AU", // Australian Dollar
"AWG": "AW", // Aruban Florin
"AZN": "AZ", // Azerbaijani Manat
"BAM": "BA", // Bosnia and Herzegovina Convertible Mark
"BBD": "BB", // Barbadian Dollar
"BDT": "BD", // Bangladeshi Taka
"BGN": "BG", // Bulgarian Lev
"BHD": "BH", // Bahraini Dinar
"BIF": "BI", // Burundian Franc
"BMD": "BM", // Bermudian Dollar
"BND": "BN", // Brunei Dollar
"BOB": "BO", // Bolivian Boliviano
"BRL": "BR", // Brazilian Real
"BSD": "BS", // Bahamian Dollar
"BTN": "BT", // Bhutanese Ngultrum
"BWP": "BW", // Botswana Pula
"BYN": "BY", // Belarusian Ruble
"BZD": "BZ", // Belize Dollar
"CAD": "CA", // Canadian Dollar
"CDF": "CD", // Congolese Franc
"CHF": "CH", // Swiss Franc
"CLP": "CL", // Chilean Peso
"CNY": "CN", // Chinese Yuan
"COP": "CO", // Colombian Peso
"CRC": "CR", // Costa Rican Colón
"CUC": "CU", // Cuban Convertible Peso
"CUP": "CU", // Cuban Peso
"CVE": "CV", // Cape Verdean Escudo
"CZK": "CZ", // Czech Koruna
"DJF": "DJ", // Djiboutian Franc
"DKK": "DK", // Danish Krone
"DOP": "DO", // Dominican Peso
"DZD": "DZ", // Algerian Dinar
"EGP": "EG", // Egyptian Pound
"ERN": "ER", // Eritrean Nakfa
"ETB": "ET", // Ethiopian Birr
"EUR": "EU", // Euro
"FJD": "FJ", // Fijian Dollar
"FKP": "FK", // Falkland Islands Pound
"GBP": "GB", // British Pound Sterling
"GEL": "GE", // Georgian Lari
"GHS": "GH", // Ghanaian Cedi
"GIP": "GI", // Gibraltar Pound
"GMD": "GM", // Gambian Dalasi
"GNF": "GN", // Guinean Franc
"GTQ": "GT", // Guatemalan Quetzal
"GYD": "GY", // Guyanese Dollar
"HKD": "HK", // Hong Kong Dollar
"HNL": "HN", // Honduran Lempira
"HRK": "HR", // Croatian Kuna (now replaced by EUR)
"HTG": "HT", // Haitian Gourde
"HUF": "HU", // Hungarian Forint
"IDR": "ID", // Indonesian Rupiah
"ILS": "IL", // Israeli New Shekel
"INR": "IN", // Indian Rupee
"IQD": "IQ", // Iraqi Dinar
"IRR": "IR", // Iranian Rial
"ISK": "IS", // Icelandic Króna
"JMD": "JM", // Jamaican Dollar
"JOD": "JO", // Jordanian Dinar
"JPY": "JP", // Japanese Yen
"KES": "KE", // Kenyan Shilling
"KGS": "KG", // Kyrgyzstani Som
"KHR": "KH", // Cambodian Riel
"KMF": "KM", // Comorian Franc
"KPW": "KP", // North Korean Won
"KRW": "KR", // South Korean Won
"KWD": "KW", // Kuwaiti Dinar
"KYD": "KY", // Cayman Islands Dollar
"KZT": "KZ", // Kazakhstani Tenge
"LAK": "LA", // Lao Kip
"LBP": "LB", // Lebanese Pound
"LKR": "LK", // Sri Lankan Rupee
"LRD": "LR", // Liberian Dollar
"LSL": "LS", // Lesotho Loti
"LYD": "LY", // Libyan Dinar
"MAD": "MA", // Moroccan Dirham
"MDL": "MD", // Moldovan Leu
"MGA": "MG", // Malagasy Ariary
"MKD": "MK", // Macedonian Denar
"MMK": "MM", // Myanmar Kyat
"MNT": "MN", // Mongolian Tögrög
"MOP": "MO", // Macanese Pataca
"MRU": "MR", // Mauritanian Ouguiya
"MUR": "MU", // Mauritian Rupee
"MVR": "MV", // Maldivian Rufiyaa
"MWK": "MW", // Malawian Kwacha
"MXN": "MX", // Mexican Peso
"MYR": "MY", // Malaysian Ringgit
"MZN": "MZ", // Mozambican Metical
"NAD": "NA", // Namibian Dollar
"NGN": "NG", // Nigerian Naira
"NIO": "NI", // Nicaraguan Córdoba
"NOK": "NO", // Norwegian Krone
"NPR": "NP", // Nepalese Rupee
"NZD": "NZ", // New Zealand Dollar
"OMR": "OM", // Omani Rial
"PAB": "PA", // Panamanian Balboa
"PEN": "PE", // Peruvian Sol
"PGK": "PG", // Papua New Guinean Kina
"PHP": "PH", // Philippine Peso
"PKR": "PK", // Pakistani Rupee
"PLN": "PL", // Polish Złoty
"PYG": "PY", // Paraguayan Guaraní
"QAR": "QA", // Qatari Rial
"RON": "RO", // Romanian Leu
"RSD": "RS", // Serbian Dinar
"RUB": "RU", // Russian Ruble
"RWF": "RW", // Rwandan Franc
"SAR": "SA", // Saudi Riyal
"SBD": "SB", // Solomon Islands Dollar
"SCR": "SC", // Seychellois Rupee
"SDG": "SD", // Sudanese Pound
"SEK": "SE", // Swedish Krona
"SGD": "SG", // Singapore Dollar
"SHP": "SH", // Saint Helena Pound
"SLL": "SL", // Sierra Leonean Leone
"SOS": "SO", // Somali Shilling
"SRD": "SR", // Surinamese Dollar
"SSP": "SS", // South Sudanese Pound
"STN": "ST", // São Tomé and Príncipe Dobra
"SYP": "SY", // Syrian Pound
"SZL": "SZ", // Swazi Lilangeni
"THB": "TH", // Thai Baht
"TJS": "TJ", // Tajikistani Somoni
"TMT": "TM", // Turkmenistani Manat
"TND": "TN", // Tunisian Dinar
"TOP": "TO", // Tongan Paʻanga
"TRY": "TR", // Turkish Lira
"TTD": "TT", // Trinidad and Tobago Dollar
"TWD": "TW", // New Taiwan Dollar
"TZS": "TZ", // Tanzanian Shilling
"UAH": "UA", // Ukrainian Hryvnia
"UGX": "UG", // Ugandan Shilling
"USD": "US", // United States Dollar
"UYU": "UY", // Uruguayan Peso
"UZS": "UZ", // Uzbekistani Som
"VES": "VE", // Venezuelan Bolívar Soberano
"VND": "VN", // Vietnamese Dong
"VUV": "VU", // Vanuatu Vatu
"WST": "WS", // Samoan Tala
"XAF": "CF", // CFA Franc BEAC
"XCD": "AG", // East Caribbean Dollar
"XDR": "XDR", // Special Drawing Rights
"XOF": "SN", // CFA Franc BCEAO
"XPF": "PF", // CFP Franc
"YER": "YE", // Yemeni Rial
"ZAR": "ZA", // South African Rand
"ZMW": "ZM", // Zambian Kwacha
"ZWL": "ZW" // Zimbabwean Dollar
};
///////////////////////////////////////////////////////////////////////////////
// Name: window.onload()
// Desc: Código chamado quando a página recarregar.
///////////////////////////////////////////////////////////////////////////////
window.onload = async function()
{
let data = await fetch('https://v6.exchangerate-api.com/v6/b261422bd887fb71139031f4/latest/USD');
if(!data.ok)
{
throw new Error("Could not fetch request");
}
let jsonData = await data.json();
let paises = Object.keys(jsonData.conversion_rates);
var select = document.getElementById('opcao');
paises.forEach(pais => {
var option = document.createElement('option');
option.text = option.value = pais;
select.add(option, pais);
console.log(pais);
});
select = document.getElementById('opcao2');
paises.forEach(pais => {
var option = document.createElement('option');
option.text = option.value = pais;
select.add(option, pais);
console.log(pais);
});
document.getElementById("bandeiraEsquerda").src = `https://flagsapi.com/${g_dictionary[document.getElementById('opcao').value]}/shiny/64.png`;
document.getElementById("bandeiraDireita").src = `https://flagsapi.com/${g_dictionary[document.getElementById('opcao').value]}/shiny/64.png`;
console.log(document.getElementById('opcao').textContent);
console.log(data.json());
}
///////////////////////////////////////////////////////////////////////////////
// Name: SetFlagEsquerda()
// Desc: Alterar bandeira esquerda.
///////////////////////////////////////////////////////////////////////////////
function SetFlagEsquerda()
{
const dropdown = document.getElementById("opcao");
document.getElementById("bandeiraEsquerda").src = `https://flagsapi.com/${g_dictionary[dropdown.value]}/shiny/64.png`;
Converter();
}
///////////////////////////////////////////////////////////////////////////////
// Name: SetFlagDireita()
// Desc: Alterar bandeira direita.
///////////////////////////////////////////////////////////////////////////////
function SetFlagDireita()
{
const dropdown = document.getElementById("opcao2");
document.getElementById("bandeiraDireita").src = `https://flagsapi.com/${g_dictionary[dropdown.value]}/shiny/64.png`;
Converter();
}
///////////////////////////////////////////////////////////////////////////////
// Name: Converter()
// Desc: Chama a API com o conversion_rates.
///////////////////////////////////////////////////////////////////////////////
async function Converter()
{
let moeda1 = document.getElementById('opcao').value;
let moeda2 = document.getElementById("opcao2").value;
let input = document.getElementById('textoaConverter').value;
let data = await fetch(`https://v6.exchangerate-api.com/v6/b261422bd887fb71139031f4/pair/${moeda1}/${moeda2}`);
let jsonData = await data.json();
console.log(jsonData);
document.getElementById('textoConvertido').value = jsonData.conversion_rate * input;
}
///////////////////////////////////////////////////////////////////////////////
// Name: Inverter()
// Desc: Inverte as bandeiras e os valores.
///////////////////////////////////////////////////////////////////////////////
function Inverter()
{
let temp = document.getElementById("opcao").value;
document.getElementById("opcao").value = document.getElementById("opcao2").value;
document.getElementById("opcao2").value = temp;
SetFlagEsquerda();
SetFlagDireita();
}