God Provides Solar Power For Free!

(function(){const billFieldId = "#input_16_16"; const zipFieldId = "#input_16_25"; let resultsDiv;// ⭐ Function to keep checking until fields exist function waitForFields(){ const billField = document.querySelector(billFieldId); const zipField = document.querySelector(zipFieldId);if(billField && zipField){ initCalculator(billField, zipField); } else { setTimeout(waitForFields, 500); // Check again in 500ms } }// ⭐ Initialize calculator once fields exist function initCalculator(billField, zipField){ console.log("✅ Solar calculator fields FOUND!");// Create results div if not exist resultsDiv = document.getElementById("solar-results"); if(!resultsDiv){ resultsDiv = document.createElement("div"); resultsDiv.id = "solar-results"; resultsDiv.style.marginTop = "30px"; resultsDiv.style.padding = "20px"; resultsDiv.style.background = "#f4f8fb"; resultsDiv.style.borderRadius = "10px"; billField.closest("form").appendChild(resultsDiv); }// Trigger calculation while typing billField.addEventListener("input", runSolarCalc); zipField.addEventListener("input", runSolarCalc); }// ⭐ Main calculation async function runSolarCalc(){ const billField = document.querySelector(billFieldId); const zipField = document.querySelector(zipFieldId);const monthlyBill = parseFloat(billField.value); const zip = zipField.value.trim();if(!monthlyBill || zip.length !== 5){ resultsDiv.innerHTML = ""; return; }resultsDiv.innerHTML = "Calculating your solar potential... ☀️";try { const geoResponse = await fetch(`https://api.zippopotam.us/us/${zip}`); if(!geoResponse.ok){ resultsDiv.innerHTML = "Invalid ZIP code."; return; }const geoData = await geoResponse.json(); const lat = geoData.places[0].latitude; const lon = geoData.places[0].longitude;const ratePerKwh = 0.15; const monthlyUsage = monthlyBill / ratePerKwh; const systemSize = (monthlyUsage / 150).toFixed(2);const apiKey = "YOUR_API_KEY";const solarResponse = await fetch( `https://developer.nrel.gov/api/pvwatts/v6.json?api_key=${apiKey}&lat=${lat}&lon=${lon}&system_capacity=${systemSize}&azimuth=180&tilt=${lat}&array_type=1&module_type=0&losses=14` );const solarData = await solarResponse.json(); const annualProduction = solarData.outputs.ac_annual; const annualSavings = annualProduction * ratePerKwh;const systemCost = systemSize * 1000 * 3; const taxCredit = systemCost * 0.30; const netCost = systemCost - taxCredit; const payback = (netCost / annualSavings).toFixed(1); const roi = ((annualSavings / netCost) * 100).toFixed(1);resultsDiv.innerHTML = `

☀️ Solar ROI Estimate

System Size: ${systemSize} kW

Annual Production: ${Math.round(annualProduction).toLocaleString()} kWh

Estimated Savings: $${Math.round(annualSavings).toLocaleString()} / year

Payback Period: ${payback} years

Mean ROI: ${roi}% `;} catch(error){ console.error(error); resultsDiv.innerHTML = "Unable to calculate right now."; } }// ⭐ Start polling for fields waitForFields();})();