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

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

小野博客

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]