EUR-DZD_currency_converter/index.html

177 lines
5.1 KiB
HTML
Raw Normal View History

2024-04-09 09:29:48 +02:00
<!DOCTYPE html>
<html>
<head>
2024-04-09 09:53:54 +02:00
<title>EUR DZD</title>
2024-04-09 09:29:48 +02:00
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="/manifest.json">
2024-04-09 09:36:24 +02:00
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="EUR-DZD Calculator">
<link rel="apple-touch-icon" href="icon.png">
2024-04-09 09:29:48 +02:00
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}
h1 {
text-align: center;
margin-top: 20px;
}
form {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="number"] {
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
width: 100%;
margin-bottom: 20px;
}
button[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
width: 100%;
}
p.result {
font-size: 20px;
font-weight: bold;
margin-top: 20px;
text-align: center;
}
#recentCalculations {
margin-top: 40px;
border-top: 2px solid #ccc;
padding-top: 20px;
}
#calculationList {
list-style-type: none;
padding: 0;
text-align: center;
}
#calculationList li {
margin-bottom: 10px;
}
footer {
text-align: center;
margin-top: 40px;
padding-top: 20px;
border-top: 1px solid #ddd;
color: #666;
font-size: 12px;
}
2024-04-09 10:02:43 +02:00
#install-instructions {
display: none;
text-align: center;
padding: 20px;
}
</style>
2024-04-09 09:29:48 +02:00
</head>
<body>
2024-04-09 10:24:14 +02:00
<h1>Exchange Rate Calculator</h1>
2024-04-09 10:13:47 +02:00
2024-04-09 10:24:14 +02:00
<!-- Installation instructions (initially hidden) -->
2024-04-09 10:13:47 +02:00
<div id="install-instructions">
2024-04-09 09:57:34 +02:00
<p>For the best experience, add this web app to your home screen:</p>
<p>1. Tap the <strong>Share</strong> button.</p>
<p>2. Tap <strong>Add to Home Screen</strong>.</p>
</div>
2024-04-09 10:06:44 +02:00
2024-04-09 10:20:13 +02:00
<form onsubmit="return convert(event)">
2024-04-09 10:13:47 +02:00
<label for="euro">Enter amount in Euro:</label>
2024-04-09 09:29:48 +02:00
<input type="number" id="euro" placeholder="Enter amount in Euro">
2024-04-09 10:13:47 +02:00
<label for="dinar">Enter amount in Algerian Dinar:</label>
2024-04-09 09:29:48 +02:00
<input type="number" id="dinar" placeholder="Enter amount in Algerian Dinar">
2024-04-09 10:13:47 +02:00
<button type="submit">Convert</button>
2024-04-09 09:29:48 +02:00
</form>
2024-04-09 10:13:47 +02:00
2024-04-09 09:29:48 +02:00
<p class="result" id="result"></p>
<div id="recentCalculations">
<h2>Recent Calculations</h2>
<ul id="calculationList"></ul>
</div>
<footer>
<hr>
<p>EUR-DZD Calculator Version 1.2 (C) by KABI Fancy Media and Communication</p>
</footer>
<script>
2024-04-09 10:20:13 +02:00
let recentCalculations = [];
function convert(event) {
2024-04-09 09:29:48 +02:00
event.preventDefault();
2024-04-09 10:20:13 +02:00
const euro = document.getElementById("euro").value;
const dinar = document.getElementById("dinar").value;
const apiKey = "ab0076697b3401ea71d2c393";
const url = `https://v6.exchangerate-api.com/v6/${apiKey}/pair/EUR/DZD`;
fetch(url)
.then(response => response.json())
.then(data => {
const exchangeRate = data.conversion_rate;
if (euro && !isNaN(euro)) {
const result = (euro * exchangeRate).toFixed(2);
const calculation = `${euro} Euro = ${result} Algerian Dinar`;
document.getElementById("result").textContent = calculation;
recentCalculations.unshift(calculation);
} else if (dinar && !isNaN(dinar)) {
const result = (dinar / exchangeRate).toFixed(2);
const calculation = `${dinar} Algerian Dinar = ${result} Euro`;
document.getElementById("result").textContent = calculation;
recentCalculations.unshift(calculation);
}
recentCalculations = recentCalculations.slice(0, 5);
updateRecentCalculations();
})
.catch(error => {
console.log(error);
document.getElementById("result").textContent = "Oops, something went wrong! Please try again later.";
});
return false; // Prevent form submission
}
function updateRecentCalculations() {
const calculationList = document.getElementById("calculationList");
calculationList.innerHTML = "";
recentCalculations.forEach(calculation => {
const li = document.createElement("li");
li.textContent = calculation;
calculationList.appendChild(li);
});
}
2024-04-09 10:33:04 +02:00
// Show installation instructions only if accessed via browser
if (!window.matchMedia('(display-mode: standalone)').matches) {
2024-04-09 10:24:14 +02:00
document.getElementById('install-instructions').style.display = 'block';
2024-04-09 10:33:04 +02:00
}
2024-04-09 10:38:35 +02:00
// Detect when the app is launched from the home screen and hide installation instructions
window.addEventListener('appinstalled', (event) => {
document.getElementById('install-instructions').style.display = 'none';
});
2024-04-09 10:13:47 +02:00
</script>
2024-04-09 09:29:48 +02:00
</body>
</html>