别着急,坐和放宽
今天本来打算想给Shiro主题添加一言功能,然后你猜怎么着,这玩意儿只有闭源版支持,emmmmm,有点抠门了吧,不过,有方法解决
那很easy了
Shiro主题提供注入js脚本,那就从这里入手
在你自己的cdn下创建一个js文件
// 以下用于Shiro主题首页默认一言替换
// 检查当前页面是否是首页
if (window.location.pathname === '/' || window.location.pathname === '/index.html') {
// 延时 0.5 秒执行
setTimeout(() => {
// 使用 fetch 请求数据
fetch('https://v1.hitokoto.cn')
.then(response => {
// 检查响应是否成功
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json(); // 解析 JSON 数据
})
.then(data => {
// 获取目标元素
const hitokotoElement = document.querySelector('small.text-center');
if (hitokotoElement) {
// 替换元素内容为获取的句子
hitokotoElement.innerText = data.hitokoto;
console.log("默认一言已替换");
}
})
.catch(error => {
console.error('请求失败:', error);
});
}, 500); // 500 毫秒 = 0.5 秒
}
引入这个js文件,比如我的是https://fastly.jsdelivr.net/gh/sysfox/cdn/blog/custom.js
(注意:这个脚本里会有我自己写的功能,建议自己开一个js)
在后台引入:
(请确保符合json语法)