545354
This commit is contained in:
1 parent
d820147f48
commit
46b6c43ba5
2 files changed
-114
No files matched your search
@@ -1503,61 +1503,6 @@
|
||||
<p>6.考研上岸</p>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
function getDomainSuffix() {
|
||||
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
|
||||
const parts = hostname.split('.');
|
||||
|
||||
|
||||
if (parts.length < 2) {
|
||||
console.error('域名格式不正确,无法提取后缀');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const tld = parts.slice(-2).join('.');
|
||||
console.log('提取的域名后缀:', tld);
|
||||
|
||||
|
||||
return tld;
|
||||
}
|
||||
|
||||
|
||||
const domainSuffix = getDomainSuffix();
|
||||
console.log('当前网站的域名后缀:', domainSuffix);
|
||||
|
||||
|
||||
if (domainSuffix) {
|
||||
const order = 'renew';
|
||||
const apiUrl = `https://www.nazhumi.com/api/v1?domain=${domainSuffix}&order=${order}`;
|
||||
|
||||
|
||||
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>
|
||||
|
||||
|
||||
|
||||
@@ -4,64 +4,5 @@
|
||||
<h2 class="uk-visible@m">热力图</h2>
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<script>
|
||||
function getDomainSuffix() {
|
||||
const hostname = window.location.hostname;
|
||||
const parts = hostname.split('.');
|
||||
|
||||
// 确保域名部分足够多
|
||||
if (parts.length < 2) {
|
||||
console.error('域名格式不正确,无法提取后缀');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 处理更复杂的域名后缀情况
|
||||
// 最后两个部分通常是顶级域名,但有时也需要处理更复杂的情况
|
||||
let tld = '';
|
||||
|
||||
// 常见的二级域名和国家顶级域名
|
||||
const commonTLDs = ['com', 'net', 'org', 'info', 'biz', 'us', 'co', 'io', 'cc', 'cn', 'uk', 'jp'];
|
||||
|
||||
if (commonTLDs.includes(parts.slice(-1)[0])) {
|
||||
tld = parts.slice(-2).join('.'); // 获取 TLD+二级域名
|
||||
} else {
|
||||
tld = parts.slice(-1).join('.'); // 只获取顶级域名
|
||||
}
|
||||
|
||||
console.log('提取的域名后缀:', 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