EUR-DZD_currency_converter/index.html

212 lines
5.9 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;
}
</style>
2024-04-09 10:02:43 +02:00
<style>
#installButton {
display: block;
margin: 0 auto;
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
#install-instructions {
display: none;
text-align: center;
padding: 20px;
}
</style>
2024-04-09 09:29:48 +02:00
</head>
<body>
2024-04-09 10:02:43 +02:00
<div id="install-instructions" style="text-align: center; padding: 20px;">
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:02:43 +02:00
<button onclick="installApp()">Install App</button>
2024-04-09 09:29:48 +02:00
<h1>Exchange Rate Calculator</h1>
<form>
<label>Enter amount in Euro:</label>
<input type="number" id="euro" placeholder="Enter amount in Euro">
<label>Enter amount in Algerian Dinar:</label>
<input type="number" id="dinar" placeholder="Enter amount in Algerian Dinar">
<button type="submit" onclick="convert(event)">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) {
const result = (euro * exchangeRate).toFixed(2);
const calculation = `${euro} Euro = ${result} Algerian Dinar`;
document.getElementById("result").innerHTML = calculation;
recentCalculations.unshift(calculation);
} else if (dinar) {
const result = (dinar / exchangeRate).toFixed(2);
const calculation = `${dinar} Algerian Dinar = ${result} Euro`;
document.getElementById("result").innerHTML = calculation;
recentCalculations.unshift(calculation);
}
recentCalculations = recentCalculations.slice(0, 5);
updateRecentCalculations();
})
.catch(error => {
console.log(error);
document.getElementById("result").innerHTML = "Oops, something went wrong! Please try again later.";
});
}
function updateRecentCalculations() {
const calculationList = document.getElementById("calculationList");
2024-04-09 10:02:43 +02:00
calculationList.innerHTML = "";
2024-04-09 09:29:48 +02:00
recentCalculations.forEach(calculation => {
const li = document.createElement("li");
li.textContent = calculation;
calculationList.appendChild(li);
});
}
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(function(registration) {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch(function(error) {
console.error('Service Worker registration failed:', error);
});
}
2024-04-09 10:02:43 +02:00
</script>
<script>
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
deferredPrompt = event;
if (!window.matchMedia('(display-mode: standalone)').matches) {
document.getElementById('install-instructions').style.display = 'block';
}
});
function installApp() {
if (deferredPrompt) {
deferredPrompt.prompt();
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
document.getElementById('install-instructions').style.display = 'none';
}
deferredPrompt = null;
});
}
}
</script>
2024-04-09 09:29:48 +02:00
</body>
</html>