8978787
This commit is contained in:
1 parent
7894f08c46
commit
80c8c42e25
2 files changed
+110
No files matched your search
@@ -4,5 +4,60 @@
|
||||
<h2 class="uk-visible@m">热力图</h2>
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<script>
|
||||
function getDomainSuffix() {
|
||||
// 获取当前页面的主机名
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
// 获取域名的各部分
|
||||
const parts = hostname.split('.');
|
||||
|
||||
// 如果域名部分少于 2 个,无法提取后缀
|
||||
if (parts.length < 2) {
|
||||
console.error('域名格式不正确,无法提取后缀');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 提取后缀
|
||||
// 顶级域名(TLD)可能是二级(如 'co.uk')或者单一(如 'com')
|
||||
// 我们取最后两个部分(假设TLD是最后两个部分的组合)来处理常见情况
|
||||
const tld = parts.slice(-2).join('.');
|
||||
console.log('提取的域名后缀:', tld);
|
||||
|
||||
// 返回 TLD
|
||||
return tld;
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
const domainSuffix = getDomainSuffix();
|
||||
console.log('当前网站的域名后缀:', domainSuffix);
|
||||
|
||||
// 根据域名后缀构建 API 请求
|
||||
if (domainSuffix) {
|
||||
const order = 'renew';
|
||||
const apiUrl = `https://www.nazhumi.com/api/v1?domain=${domainSuffix}&order=${order}`;
|
||||
|
||||
// 异步请求数据并处理 JSON
|
||||
async function fetchRenewalPrice() {
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
const data = await response.json();
|
||||
const prices = data.data.price;
|
||||
const lowestPrice = prices.reduce((min, current) => {
|
||||
const renewPrice = parseFloat(current.renew);
|
||||
return (renewPrice < min) ? renewPrice : min;
|
||||
}, Infinity);
|
||||
console.log('最低续费价格:', lowestPrice);
|
||||
return lowestPrice;
|
||||
} catch (error) {
|
||||
console.error('获取数据失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
fetchRenewalPrice();
|
||||
}
|
||||
|
||||
</script>
|
||||
</div>
|
||||
{{ end }}
|
||||
Reference in new issue
Block a user