Files
blog/themes/Ying/layouts/_default/about.html
T
2024-08-03 19:59:31 +08:00

64 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{ define "main" }}
<div id="pjax-container">
<div class="post-content" itemprop="articleBody" uk-scrollspy="target: > h2,#heatmap,p; cls: uk-animation-fade; delay: 0">
<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 }}