惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

小野博客

QQ音乐播放接口:PHP逆向分析与实现 CTF:最好的语言解密过程 狐蒂云疑似准备跑路:低价云服务器的水有多深 WeMod PRO 会员高级版脚本分享 PowerShell 执行策略被禁止解决方法 一款可以屏蔽国外广告的IP过滤评论插件 当 PCDN 来敲门:一个"小"博客的 200G 流量惊魂记 船新升级!我的“一言”系统支持一键换肤了(内附10套精美皮肤) 给网页装个“灵魂”:我写了一个超丝滑的【一言】自建语录api 桌面工具-极光便签-随时笔记
再续前缘:利用自建一言Api接口嫁接给typecho
小野 · 2026-01-28 · via 小野博客

如何自建api接口看这篇教程:给网页装个“灵魂”:我写了一个超丝滑的【一言】自建语录api

显示图

教程步骤

  1. 修改 post.php (你需要展示的位置)
<div class="diary-hitokoto">
    <div class="hitokoto-content">
        <span id="hitokoto-text">正在翻阅扉页...</span>
    </div>
    <div class="hitokoto-meta">
        <span id="hitokoto-from"></span>
        <span id="hitokoto-who"></span>
    </div>
</div>
  1. 添加 CSS 样式
.diary-hitokoto {
    padding: 20px;
    margin: 20px 0;
    text-align: center;
    border-top: 1px solid rgba(0,0,0,0.05); 
}

.hitokoto-content {
    font-size: 15px;
    color: #444;
    line-height: 1.8;
    margin-bottom: 8px;
    font-weight: 400;
}

.hitokoto-meta {
    font-size: 12px;
    color: #999;
}

#hitokoto-from::before {
    content: "——「";
}

#hitokoto-from::after {
    content: "」";
}

.diary-hitokoto {
    display: none; 
}
/* 适配移动端 */
@media screen and (max-width: 767px) {
    .hitokoto-content { font-size: 14px; }
}
  1. 添加 JavaScript 逻辑 (在 footer.php)

这段脚本会从你的域名/?api=1获取数据。

$(document).ready(function() {
    // 你的自建 API 地址
    const apiUrl = '你的域名/?api=1';

    fetch(apiUrl)
        .then(res => res.json())
        .then(data => {
            const content = data.hitokoto;
            const from = data.from;
            const who = data.from_who ? ` · ${data.from_who}` : '';

            $('#hitokoto-text').fadeOut(400, function() {
                $(this).text(content).fadeIn(600);
            });
            
            if (from) {
                $('#hitokoto-from').text(from);
                if (who) $('#hitokoto-who').text(who);
            }
        })
        .catch(err => {
            console.error('一言加载失败:', err);
            $('#hitokoto-text').text('生活明朗,万物可爱。');
        });
});

[linkcard 240]