EUR-DZD_currency_converter/index.html
2024-04-09 10:42:43 +02:00

177 lines
5.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>EUR DZD</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="/manifest.json">
<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">
<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;
}
#install-instructions {
display: none;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h1>Exchange Rate Calculator</h1>
<!-- Installation instructions (initially hidden) -->
<div id="install-instructions">
<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>
<form onsubmit="return convert(event)">
<label for="euro">Enter amount in Euro:</label>
<input type="number" id="euro" placeholder="Enter amount in Euro">
<label for="dinar">Enter amount in Algerian Dinar:</label>
<input type="number" id="dinar" placeholder="Enter amount in Algerian Dinar">
<button type="submit">Convert</button>
</form>
<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>
let recentCalculations = [];
function convert(event) {
event.preventDefault();
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);
});
}
// Show installation instructions only if accessed via browser
if (window.matchMedia('(display-mode: browser)').matches) {
document.getElementById('install-instructions').style.display = 'block';
}
// Hide installation instructions once installed as standalone PWA
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault(); // Prevent default browser prompt
document.getElementById('install-instructions').style.display = 'none';
});
</script>
</body>
</html>