给你的Halo文章添加随机热评
热评
loading...
loading...
代码如下
<div class="poem-wrap">
<div class="poem-border poem-left"></div>
<div class="poem-border poem-right"></div>
<h1>热评</h1>
<p id="poem" style="text-align: center">loading...</p>
<p id="info" style="text-align: center">loading...</p>
</div>
<style type="text/CSS">
/* 留言板增加每日一言模块 */
.poem-wrap {
position: relative;
width: 730px;
max-width: 80%;
border: 2px solid #797979;
border-top: 0;
text-align: center;
margin: 80px auto;
}
.poem-left {
left: 0;
}
.poem-border {
position: absolute;
height: 2px;
width: 27%;
background-color: #797979;
}
.poem-right {
right: 0;
}
.poem-wrap h1 {
position: relative;
margin-top: -20px;
display: inline-block;
letter-spacing: 4px;
color: #797979;
}
.poem-wrap p:nth-of-type(1) {
font-size: 25px;
text-align: center;
margin: 0 auto;
}
.poem-wrap p {
margin: auto;
line-height: 30px;
color: #797979;
font-family: "Linux Biolinum", "Noto Serif SC", Helvetica, Arial, Menlo, Monaco, monospace, sans-serif;
}
.poem-wrap p:nth-of-type(2) {
font-size: 18px;
margin: 15px auto;
}
.bozhushuo {
text-align: center;
font-size: 19px !important;
margin: 0 0 12px !important;
line-height: 1.9rem;
font-family: "Linux Biolinum", "Noto Serif SC", Helvetica, Arial, Menlo, Monaco, monospace, sans-serif;
}
.notice {
margin: 30px auto;
padding: 20px;
border: 1px dashed #e6e6e6;
color: #969696;
position: relative;
display: inline-block;
width: 95%;
background: #fbfbfb50;
border-radius: 10px;
font-size: 16px;
}
.notice-content {
display: initial;
vertical-align: middle;
}
</style>
<script>
function updateComment() {
fetch("https://api.qjqq.cn/api/Yi?c=j") //句子类型可以更换
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then(data => {
const poemElement = document.getElementById('poem');
const infoElement = document.getElementById('info');
poemElement.innerHTML = data.hitokoto;
if (data.from_who !== null) {
infoElement.innerHTML = data.from_who + " · " + "《 " + data.from + " 》";
} else {
infoElement.innerHTML = " “ " + data.from + " ” ";
}
})
.catch(error => {
const poemElement = document.getElementById('poem');
const infoElement = document.getElementById('info');
poemElement.innerHTML = "获取出错啦";
infoElement.innerHTML = "";
console.error('Fetch error:', error);
});
}
updateComment();
window.addEventListener('load', updateComment);
</script>
将上面代码复制,然后新建文章,添加HTML编辑块即可完成。(打开一次文章或者刷新一下浏览器,就会更换内容)
一言接口
接口地址
请求参数
句子类型
返回编码(参数)
返回参数
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 ZLX STUDIO
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果