Embedded E-Waste Calculator
https://cdn.tailwindcss.com
body {
font-family: “Inter”, sans-serif;
background-color: #f0f4f8; /* Light blue-grey background */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 1rem; /* Add some padding for smaller screens */
box-sizing: border-box;
}
iframe {
border: none; /* Remove default iframe border */
border-radius: 12px; /* Match the calculator’s rounded corners */
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 0px 10px -5px rgba(0, 0, 0, 0.05); /* Soft shadow */
width: 100%; /* Make iframe responsive */
max-width: 768px; /* Limit max width for larger screens */
height: 600px; /* Fixed height, adjust as needed */
transition: all 0.3s ease-in-out;
}
@media (max-width: 768px) {
iframe {
height: 550px; /* Slightly adjust height for smaller devices */
}
}
@media (max-width: 480px) {
iframe {
height: 500px; /* Further adjust height for very small devices */
}
}
<iframe
srcdoc="
E-Waste Value Calculator
https://cdn.tailwindcss.com
body {
font-family: "Inter", sans-serif;
background-color: #f0f4f8; /* Light blue-grey background */
}
.container {
max-width: 90%; /* Responsive width */
padding: 1.5rem;
margin: 2rem auto;
background-color: #ffffff;
border-radius: 12px; /* More rounded corners */
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 0px 10px -5px rgba(0, 0, 0, 0.05); /* Softer shadow */
}
.form-label {
font-weight: 600; /* Semi-bold */
color: #334155; /* Darker text */
margin-bottom: 0.5rem;
}
.form-select, .form-input {
width: 100%;
padding: 0.75rem;
border: 1px solid #cbd5e1; /* Light grey border */
border-radius: 8px; /* Slightly more rounded */
background-color: #f8fafc; /* Very light grey input background */
transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.form-select:focus, .form-input:focus {
outline: none;
border-color: #6366f1; /* Indigo focus border */
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2); /* Soft focus shadow */
}
.btn-primary {
background-color: #4f46e5; /* Indigo */
color: #ffffff;
padding: 0.75rem 1.5rem;
border-radius: 8px;
font-weight: 600;
transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.btn-primary:hover {
background-color: #4338ca; /* Darker indigo on hover */
transform: translateY(-1px); /* Slight lift */
}
.result-box {
background-color: #e0e7ff; /* Light blue */
padding: 1rem;
border-radius: 8px;
border: 1px solid #a5b4fc; /* Medium blue border */
color: #1e3a8a; /* Dark blue text */
font-weight: 600;
margin-top: 1rem;
}
.reason-box {
background-color: #dbeafe; /* Lighter blue */
padding: 1rem;
border-radius: 8px;
border: 1px solid #93c5fd; /* Light blue border */
color: #1e40af; /* Darker blue text */
margin-top: 1rem;
line-height: 1.6;
}
/* Message Box Styling */
#messageBox {
display: none; /* Hidden by default */
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
z-index: 1000;
text-align: center;
}
#messageBox.show {
display: block;
}
#messageOverlay {
display: none; /* Hidden by default */
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
}
#messageOverlay.show {
display: block;
}
#messageBox button {
background-color: #4f46e5;
color: white;
padding: 8px 15px;
border: none;
border-radius: 6px;
cursor: pointer;
margin-top: 15px;
}
E-Waste Value Calculator
Laptop
Smartphone
Printer
Television (CRT/LCD/LED)
Computer Monitor (CRT/LCD/LED)
Desktop PC (Tower only)
Server/Network Equipment
Lithium-ion Battery (e.g., from laptop/phone)
Other Electronics
Calculate Value
Value in USD:
Value in GHS:
Reasons for Calculation:
OK
// Function to show a custom message box
function showMessageBox(message) {
document.getElementById(‘messageText’).innerText = message;
document.getElementById(‘messageBox’).classList.add(‘show’);
document.getElementById(‘messageOverlay’).classList.add(‘show’);
}
// Function to hide the custom message box
function hideMessageBox() {
document.getElementById(‘messageBox’).classList.remove(‘show’);
document.getElementById(‘messageOverlay’).classList.remove(‘show’);
}
const ewasteTypeSelect = document.getElementById(‘ewasteType’);
const quantityInput = document.getElementById(‘quantity’);
const calculateBtn = document.getElementById(‘calculateBtn’);
const resultsDiv = document.getElementById(‘results’);
const valueUSDElement = document.getElementById(‘valueUSD’);
const valueGHSElement = document.getElementById(‘valueGHS’);
const calculationReasonsElement = document.getElementById(‘calculationReasons’);
let usdToGhsRate = 0; // Global variable to store the exchange rate
// Hypothetical base values for e-waste in USD per unit/kg
// These values are illustrative and can vary greatly in real-world scenarios
const ewasteValuesUSD = {
laptop: { valuePerUnit: 15.00, unit: ‘unit’,
reason: ‘Laptops contain valuable components like RAM, CPU, motherboards (with trace amounts of gold, silver, palladium), and copper wiring. The value reflects potential recovery of these materials.’ },
smartphone: { valuePerUnit: 5.00, unit: ‘unit’,
reason: ‘Smartphones are rich in precious metals (gold, silver, copper, palladium) and rare earth elements. Their compact size concentrates more valuable material per unit weight compared to larger electronics.’ },
printer: { valuePerUnit: 2.00, unit: ‘unit’,
reason: ‘Printers typically have less recoverable valuable material compared to other electronics. Their value is mainly from common metals and plastics suitable for recycling.’ },
tv: { valuePerUnit: 0.20, unit: ‘kg’, // Assuming average TV weight ~15-30kg, so ~3-6 USD per TV
reason: ‘Televisions, especially older CRT models, contain leaded glass. Newer LCD/LED TVs have less hazardous materials but still contain plastics, glass, and some metals. Value is based on material recovery, with considerations for safe disposal costs.’ },
monitor: { valuePerUnit: 0.25, unit: ‘kg’, // Assuming average monitor weight ~5-10kg, so ~1.25-2.5 USD per monitor
reason: ‘Computer monitors are similar to TVs in composition, with glass, plastics, and some metals. Value derived from material recycling potential and disposal considerations.’ },
desktop: { valuePerUnit: 10.00, unit: ‘unit’,
reason: ‘Desktop PCs (towers) contain power supplies, circuit boards, and various metal components (aluminum, steel, copper). They offer a good mix of recoverable materials.’ },
server: { valuePerUnit: 50.00, unit: ‘unit’, // Servers can be much heavier and contain more valuable components
reason: ‘Servers and network equipment often contain higher-grade components, more precious metals on circuit boards, and valuable metals like copper and aluminum, making them more valuable for recycling.’ },
battery: { valuePerUnit: 0.50, unit: ‘kg’, // Lithium-ion batteries
reason: ‘Lithium-ion batteries contain valuable materials like cobalt, lithium, and nickel, which are increasingly sought after for recycling to support new battery production and reduce environmental impact.’ },
other: { valuePerUnit: 0.10, unit: ‘kg’,
reason: ‘This category covers miscellaneous electronics. The value is a general estimate based on mixed e-waste, considering the presence of common metals, plastics, and minimal valuable components.’ }
};
// Function to fetch the current USD to GHS exchange rate
async function fetchExchangeRate() {
try {
// Using a free and public exchange rate API (no API key required)
const response = await fetch(‘https://open.er-api.com/v6/latest/USD’);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.rates && data.rates.GHS) {
usdToGhsRate = data.rates.GHS;
console.log(`Current USD to GHS Exchange Rate: 1 USD = ${usdToGhsRate} GHS`);
} else {
throw new Error(‘GHS exchange rate not found in API response.’);
}
} catch (error) {
console.error(‘Failed to fetch exchange rate:’, error);
// Fallback rate if API fails
usdToGhsRate = 12.00; // A reasonable fallback rate (as of early June 2025 based on search results)
showMessageBox(`Failed to fetch live exchange rate. Using a fallback rate: 1 USD = ${usdToGhsRate} GHS. Please try again later for real-time rates.`);
}
}
// Function to calculate e-waste value
function calculateEwasteValue() {
const selectedType = ewasteTypeSelect.value;
let quantity = parseFloat(quantityInput.value);
if (isNaN(quantity) || quantity 1 ? ‘s’ : ”}.`;
resultsDiv.classList.remove(‘hidden’); // Show results section
}
// Event Listeners
calculateBtn.addEventListener(‘click’, calculateEwasteValue);
// Fetch exchange rate on page load
document.addEventListener(‘DOMContentLoaded’, fetchExchangeRate);
“
title=”E-Waste Value Calculator”
>
🌍 Just EWAII (E-waste AI Identifier) ♻️
Error:
AI’s Identification:
Copy to Clipboard${keyword.charAt(0).toUpperCase() + keyword.slice(1)}: ${educationalContent[keyword]}
`; tipsFound = true; } } if (tipsFound) { educationalTipsText.innerHTML = tipsHtml; educationalTipsSection.classList.remove(‘hidden’); } else { educationalTipsSection.classList.add(‘hidden’); educationalTipsText.innerHTML = ”; } }; // — Copy to Clipboard Functionality — copyButton.addEventListener(‘click’, () => { const textToCopy = aiResponseText.textContent; if (textToCopy) { // Create a temporary textarea element const tempTextArea = document.createElement(‘textarea’); tempTextArea.value = textToCopy; document.body.appendChild(tempTextArea); tempTextArea.select(); try { document.execCommand(‘copy’); copyFeedbackMessage.classList.add(‘show’); setTimeout(() => { copyFeedbackMessage.classList.remove(‘show’); }, 2000); // Hide after 2 seconds } catch (err) { console.error(‘Failed to copy text: ‘, err); displayAppError(‘Failed to copy text to clipboard. Please try manually.’); } finally { document.body.removeChild(tempTextArea); } } else { displayAppError(‘No text to copy.’); } }); // Initial setup on page load document.addEventListener(‘DOMContentLoaded’, () => { resetClassificationUI(); // Ensure UI is clean on load });