Files
blog/themes/Ying/layouts/_default/about.html
T

67 lines
2.2 KiB
HTML
Raw Normal View History

2024-07-11 16:08:51 +08:00
{{ define "main" }}
<div id="pjax-container">
2024-08-01 16:55:57 +08:00
<div class="post-content" itemprop="articleBody" uk-scrollspy="target: > h2,#heatmap,p; cls: uk-animation-fade; delay: 0">
<h2 class="uk-visible@m">热力图</h2>
2024-07-13 11:42:38 +08:00
{{ .Content }}
2024-07-11 16:08:51 +08:00
</div>
2024-08-03 19:59:31 +08:00
<script>
function getDomainSuffix() {
const hostname = window.location.hostname;
const parts = hostname.split('.');
2024-08-03 20:15:15 +08:00
// 确保域名部分足够多
2024-08-03 19:59:31 +08:00
if (parts.length < 2) {
console.error('域名格式不正确,无法提取后缀');
return null;
}
2024-08-03 20:15:15 +08:00
// 处理更复杂的域名后缀情况
// 最后两个部分通常是顶级域名,但有时也需要处理更复杂的情况
let tld = '';
// 常见的二级域名和国家顶级域名
const commonTLDs = ['com', 'net', 'org', 'info', 'biz', 'us', 'co', 'io', 'cc', 'cn', 'uk', 'jp'];
2024-08-03 19:59:31 +08:00
2024-08-03 20:15:15 +08:00
if (commonTLDs.includes(parts.slice(-1)[0])) {
tld = parts.slice(-2).join('.'); // 获取 TLD+二级域名
} else {
tld = parts.slice(-1).join('.'); // 只获取顶级域名
}
console.log('提取的域名后缀:', tld);
2024-08-03 19:59:31 +08:00
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>
2024-07-13 11:42:38 +08:00
</div>
{{ end }}