addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const html = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="language" content="zh-CN">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>📅VPS剩余价值计算器</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background-image: url('https://xxq.dpdns.org/'); background-size: cover; background-position: center; height: 100vh; margin: 0; display: flex; justify-content: center; align-items: center; }
.container { max-width: 500px; margin: 0 auto; background-color: rgba(255, 255, 255, 0.4); padding: 20px; border-radius: 10px; box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1); }
.container1 { max-width: 500px; margin: 0 auto; background-color: rgba(255, 255, 255, 0.4); padding: 8px; border-radius: 6px; box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1); }
h3 { color: #218838; text-align: center; }
h5 { color: red; text-align: left; }
h6 { color: #FFFF00; text-align: left; }
label { display: block; margin-bottom: 8px; color: #333; }
.row { display: flex; justify-content: space-between; margin-bottom: 15px; gap: 10px; }
.field-group { flex: 1; display: flex; flex-direction: column; }
.field-group label { margin-bottom: 5px; }
input, select { padding: 8px; border: 1px solid #ccc; border-radius: 5px; width: 100%; box-sizing: border-box; }
button { padding: 10px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; width: 100%; }
button:hover { background-color: #218838; }
.result { margin-top: 20px; padding: 10px; background-color: #dff0d8; border: 1px solid #d6e9c6; color: black; border-radius: 5px; }
.sites { width:410px; background-color: rgba(211, 211, 211, 0.01); border:1px solid rgba(0,0,0,.001); margin:1px auto; padding:1px; border-radius: 10px; }
.sites1 { width:400px; background-color: rgba(211, 211, 211, 0.2); border:1px solid rgba(0,0,0,.02); margin:1px auto; padding:1px; border-radius: 10px; }
.footer { color: white; width:385px; height:20px; text-align:center; margin:2px auto; padding:1px; border-radius: 10px; }
</style>
</head>
<body>
<div class="sites">
<h3>📅VPS剩余价值计算器</h3>
<h6>⚡mjj祖训:一邮一鸡!不买实名鸡、高溢价鸡和LXC小鸡,慎买预售鸡。</h6>
<div class="sites1">
<div class="container">
<form id="calculator-form">
<div class="row">
<div class="field-group">
<label for="currency">货币种类</label>
<select id="currency" required onchange="updateExchangeRate()">
<option value="CNY">¥人民币 (CNY)</option>
<option value="USD" selected>$美元 (USD)</option>
<option value="EUR">€欧元 (EUR)</option>
<option value="GBP">£英镑 (GBP)</option>
<option value="CAD">$加拿大元 (CAD)</option>
<option value="AUD">$澳元 (AUD)</option>
<option value="JPY">¥日元 (JPY)</option>
<option value="SGD">S$新加坡元 (SGD)</option>
<option value="KRW">₩韩元 (KRW)</option>
<option value="HKD">HK$港币 (HKD)</option>
<option value="TWD">NT$新台币 (TWD)</option>
</select>
</div>
<div class="field-group">
<label for="exchangeRate">今日汇率</label>
<input type="text" id="exchangeRate" value="1" readonly>
</div>
</div>
<div class="row">
<div class="field-group">
<label for="purchaseDate">购买日期</label>
<input type="date" id="purchaseDate" value="${new Date().toISOString().slice(0, 10)}" required>
</div>
<div class="field-group">
<label for="paymentCycle">付款周期</label>
<select id="paymentCycle" required>
<option value="monthly">1月付(Monthly)</option>
<option value="quarterly">1季付(Quarterly)</option>
<option value="semiannually">半年付(Semi-annually)</option>
<option value="yearly" selected>1年付(Yearly)</option>
<option value="biennially">2年付(Biennially)</option>
<option value="triennially">3年付(Triennially)</option>
</select>
</div>
</div>
<div class="row">
<div class="field-group">
<label for="renewalAmount">续费金额</label>
<input type="number" id="renewalAmount" placeholder="请输入续费金额" required>
</div>
<div class="field-group">
<label for="purchaseAmount">购买金额</label>
<input type="number" id="purchaseAmount" placeholder="请输入购买金额" required>
</div>
</div>
<div class="row">
<div class="field-group">
<label for="expiryDate">续费日期</label>
<input type="date" id="expiryDate" required>
</div>
<div class="field-group">
<label> </label>
<button type="button" onclick="calculate()">📅计算</button>
</div>
</div>
</form>
<div id="result" class="result" style="display:none;"></div>
</div>
<!-- 页脚 -->
<div class="container1">
<div class="footer">
<span id="timeDate">载入天数...</span>
<script>
var now = new Date();
function createtime() {
var grt = new Date("11/11/2024 00:00:00");
now.setTime(now.getTime() + 250);
var days = (now - grt) / 1000 / 60 / 60 / 24;
var dnum = Math.floor(days);
document.getElementById("timeDate").innerHTML = "稳定运行" + dnum + "天";
}
setInterval(createtime, 250);
</script>
<span> | 总访问量 <span id="busuanzi_site_pv"></span> 次
<a href="https://hlzh.keplu.eu.org/" target="_blank">
<span style="color: green;">汇率转换</span>
</a>
</span>
<script defer src="https://bsz.211119.xyz/js"></script>
</div>
</div>
</div>
<!-- 主脚本 -->
<script>
const exchangeCache = {};
async function fetchExchangeRate(fromCurrency, toCurrency) {
const cacheKey = fromCurrency + "_" + toCurrency;
if (exchangeCache[cacheKey]) return exchangeCache[cacheKey];
try {
const response = await fetch(\`https://open.er-api.com/v6/latest/\${fromCurrency}\`);
const data = await response.json();
const rate = data.rates[toCurrency];
if (rate) {
exchangeCache[cacheKey] = rate;
return rate;
}
} catch (error) {
console.error('获取汇率时出错:', error);
}
return null;
}
async function updateExchangeRate() {
const currency = document.getElementById('currency').value;
const exchangeRate = await fetchExchangeRate(currency, 'CNY');
document.getElementById('exchangeRate').value = exchangeRate ? exchangeRate.toFixed(2) : '获取失败';
}
window.onload = updateExchangeRate;
async function calculate() {
const purchaseAmount = parseFloat(document.getElementById('purchaseAmount').value);
const renewalAmount = parseFloat(document.getElementById('renewalAmount').value);
const currency = document.getElementById('currency').value;
const exchangeRateToCNY = await fetchExchangeRate(currency, 'CNY');
if (!exchangeRateToCNY) {
document.getElementById('result').innerHTML = '获取汇率时出错,请稍后再试。';
document.getElementById('result').style.display = 'block';
return;
}
const paymentCycle = document.getElementById('paymentCycle').value;
const purchaseDate = new Date(document.getElementById('purchaseDate').value);
const expiryDate = new Date(document.getElementById('expiryDate').value);
const today = new Date();
if (expiryDate <= purchaseDate) {
document.getElementById('result').innerHTML = '续费日期应晚于购买日期。';
document.getElementById('result').style.display = 'block';
return;
}
const totalDays = Math.floor((expiryDate - today) / (1000 * 60 * 60 * 24));
if (totalDays <= 0) {
document.getElementById('result').innerHTML = 'VPS已过期。';
document.getElementById('result').style.display = 'block';
return;
}
const cycleMap = {
'monthly': 30,
'quarterly': 90,
'semiannually': 180,
'yearly': 365,
'biennially': 730,
'triennially': 1095
};
const cycleDays = cycleMap[paymentCycle] || 30;
const remainingValue = (totalDays / cycleDays) * renewalAmount;
const remainingValueCNY = remainingValue * exchangeRateToCNY;
const premiumAmount = purchaseAmount - remainingValueCNY;
let suggestion = '';
if (premiumAmount >= 200) suggestion = '重要的话说三遍,不要买,不要买,不要买。';
else if (premiumAmount >= 100) suggestion = '特超高溢价,不要买,不要买。';
else if (premiumAmount >= 50) suggestion = '超高溢价,不要买。';
else if (premiumAmount >= 20) suggestion = '高溢价,再想想。';
else if (premiumAmount >= 5) suggestion = '小溢价,想想。';
else if (premiumAmount >= 0) suggestion = '超小溢价,不用想。';
else if (premiumAmount >= -20) suggestion = '卖家小亏,需要就买。';
else if (premiumAmount >= -50) suggestion = '卖家大亏,可以买!';
else if (premiumAmount >= -100) suggestion = '卖家血亏,抓紧买!!';
else if (premiumAmount >= -200) suggestion = '卖家大出血,立刻买!!!';
else suggestion = '不得了,卖家大出血,闭眼买!!!';
document.getElementById('result').innerHTML = \`
<strong>⌚剩余天数:</strong> \${totalDays} 天<br>
<strong>💰续费金额:</strong> \${(renewalAmount * exchangeRateToCNY).toFixed(2)} ¥<br>
<strong>➖剩余价值:</strong> \${remainingValueCNY.toFixed(2)} ¥<br>
<strong>➕溢价金额:</strong> \${premiumAmount.toFixed(2)} ¥<br>
<strong>🎤购买建议:</strong> \${suggestion}<br>
\`;
document.getElementById('result').style.display = 'block';
}
</script>
</body>
</html>`;
return new Response(html, {
headers: { "content-type": "text/html;charset=UTF-8" },
});
}