配置文件修改

This commit is contained in:
1152958806@qq.com 2023-07-08 22:14:15 +08:00
parent 19e2e735de
commit 9d2b031355
3 changed files with 390 additions and 376 deletions

View File

@ -769,7 +769,7 @@ spec:
help: "文章主色匹配图片颜色"
- $formkit: radio
name: summarize
label: 文章摘要
label: 文章摘要(首页)
value: false
options:
- label: 打开
@ -777,6 +777,88 @@ spec:
- label: 关闭
value: false
help: "是否显示文章摘要"
- $formkit: group
name: aiDescription
label: 文章ai摘要
value:
aiDescriptionEnable:
gptName:
mode:
switchBtn:
btnLink:
randomNum:
basicWordCount:
key:
Referer:
children:
- $formkit: radio
name: aiDescriptionEnable
id: aiDescriptionEnable
key: aiDescriptionEnable
label: 启用ai 摘要
value: false
options:
- label: 启用
value: true
- label: 禁用
value: false
- $formkit: text
if: "$get(aiDescriptionEnable).value"
name: gptName
label: 名称
placeholder: 请输入内容
value: KunKunYu
- $formkit: radio
if: "$get(aiDescriptionEnable).value"
name: mode
label: 模式
value: local
help: "本地模式需要自己填写文章摘要"
options:
- label: 本地
value: local
- label: ai
value: tianli
- $formkit: radio
if: "$get(aiDescriptionEnable).value"
name: switchBtn
label: 显示切换按钮
value: false
options:
- label:
value: true
- label:
value: false
- $formkit: url
if: "$get(aiDescriptionEnable).value"
name: btnLink
label: 链接地址
placeholder: 输入链接地址
value: https://afdian.net/item/f18c2e08db4411eda2f25254001e7c00
- $formkit: number
if: "$get(aiDescriptionEnable).value"
name: randomNum
label: 标签数量
value: 3
help: "按钮最大的随机次数,也就是一篇文章最大随机出来几种"
- $formkit: number
if: "$get(aiDescriptionEnable).value"
name: basicWordCount
label: 标签数量
value: 1000
help: "最低获取字符数, 最小1000, 最大1999"
- $formkit: text
if: "$get(aiDescriptionEnable).value"
name: key
label: key
value: xxxx
placeholder: 请输入key
- $formkit: url
if: "$get(aiDescriptionEnable).value"
name: Referer
label: 你的博客地址
help: 注意保留最后的斜杠
value: https://xx.xx/
- $formkit: group
name: post_edit
label: 运营模式与责任
@ -786,6 +868,8 @@ spec:
children:
- $formkit: radio
name: enable_post_edit
id: enable_post_edit
key: enable_post_edit
help: 启用文章运营模式与责任,请正确填写链接
value: false
options:
@ -795,6 +879,7 @@ spec:
value: false
- $formkit: url
name: post_edit_url
if: "$get(enable_post_edit).value"
label: 运营模式与责任地址
placeholder: "请输入运营模式与责任地址"
value: "/rss"
@ -840,77 +925,6 @@ spec:
value: default
- label: 3D
value: 3D
- group: aiDescription
label: 文章ai摘要
formSchema:
- $formkit: radio
name: enable
id: enable
key: enable
label: 启用ai 摘要
value: false
options:
- label: 启用
value: true
- label: 禁用
value: false
- $formkit: text
if: "$get(enable).value"
name: gptName
label: 名称
placeholder: 请输入内容
value: KunKunYu
- $formkit: radio
if: "$get(enable).value"
name: mode
label: 模式
value: local
help: "本地模式需要自己填写文章摘要"
options:
- label: 本地
value: local
- label: ai
value: tianli
- $formkit: radio
if: "$get(enable).value"
name: switchBtn
label: 显示切换按钮
value: false
options:
- label:
value: true
- label:
value: false
- $formkit: url
if: "$get(enable).value"
name: btnLink
label: 链接地址
placeholder: 输入链接地址
value: https://afdian.net/item/f18c2e08db4411eda2f25254001e7c00
- $formkit: number
if: "$get(enable).value"
name: randomNum
label: 标签数量
value: 3
help: "按钮最大的随机次数,也就是一篇文章最大随机出来几种"
- $formkit: number
if: "$get(enable).value"
name: basicWordCount
label: 标签数量
value: 1000
help: "最低获取字符数, 最小1000, 最大1999"
- $formkit: text
if: "$get(enable).value"
name: key
label: key
value: xxxx
placeholder: 请输入key
- $formkit: url
if: "$get(enable).value"
name: Referer
label: 你的博客地址
help: 注意保留最后的斜杠
value: https://xx.xx/
- group: aboutReward
label: 个人(打赏名单)

View File

@ -3,299 +3,262 @@
<!-- 文章ai摘要 -->
<script data-pjax th:fragment="postHeadAiDescription" th:if="${theme.config.aiDescription.enable}">
<script data-pjax th:fragment="postHeadAiDescription" th:if="${theme.config.post.aiDescription.aiDescriptionEnable}">
(function () {
(function () {
let ai = "[[${post.status.excerpt}]]"
let randomNum = [[${theme.config.aiDescription.randomNum}]] //按钮最大的随机次数,也就是一篇文章最大随机出来几种
let basicWordCount = [[${theme.config.aiDescription.basicWordCount}]] // 最低获取字符数, 最小1000, 最大1999
let btnLink = "[[${theme.config.aiDescription.btnLink}]]"
let gptName = "[[${theme.config.aiDescription.gptName}]]"
let modeName = "[[${theme.config.aiDescription.mode}]]"
let switchBtn = [[${theme.config.aiDescription.switchBtn}]] //# 可以配置是否显示切换按钮 以切换tianli/local
let keys = "[[${theme.config.aiDescription.key}]]"
let Referers = "[[${theme.config.aiDescription.Referer}]]"
let ai = "[[${post.status.excerpt}]]"
let randomNum = [[${theme.config.post.aiDescription.randomNum}]] //按钮最大的随机次数,也就是一篇文章最大随机出来几种
let basicWordCount = [[${theme.config.post.aiDescription.basicWordCount}]] // 最低获取字符数, 最小1000, 最大1999
let btnLink = "[[${theme.config.post.aiDescription.btnLink}]]"
let gptName = "[[${theme.config.post.aiDescription.gptName}]]"
let modeName = "[[${theme.config.post.aiDescription.mode}]]"
let switchBtn = [[${theme.config.post.aiDescription.switchBtn}]] //# 可以配置是否显示切换按钮 以切换tianli/local
let keys = "[[${theme.config.post.aiDescription.key}]]"
let Referers = "[[${theme.config.post.aiDescription.Referer}]]"
// 当前随机到的ai摘要到index
let lastAiRandomIndex = -1;
let animationRunning = true; // 标志变量,控制动画函数的运行
// 当前gpt模式
let mode = modeName
// 刷新点击次数
let refreshNum = 0
// 记录上一次传递给aiAbstract的参数
let prevParam;
const aiTitleRefreshIcon = document.querySelector(".ai-title .anzhiyufont.anzhiyu-icon-arrow-rotate-right")
const explanation = document.querySelector(".ai-explanation");
const post_ai = document.querySelector(".post-ai");
let ai_str = "";
let ai_str_length = "";
let delay_init = 600;
let i = 0;
let j = 0;
let sto = [];
let elapsed = 0;
const animate = timestamp => {
if (!animationRunning) {
return; // 动画函数停止运行
}
if (!animate.start) animate.start = timestamp;
elapsed = timestamp - animate.start;
if (elapsed >= 20) {
animate.start = timestamp;
if (i < ai_str_length - 1) {
let char = ai_str.charAt(i + 1);
let delay = /[,.,。!?]/.test(char) ? 150 : 20;
if (explanation.firstElementChild) {
explanation.removeChild(explanation.firstElementChild);
}
explanation.innerHTML += char;
let div = document.createElement("div");
div.className = "ai-cursor";
explanation.appendChild(div);
i++;
if (delay === 150) {
document.querySelector(".ai-explanation .ai-cursor").style.opacity = "0";
}
if (i === ai_str_length - 1) {
observer.disconnect(); // 暂停监听
explanation.removeChild(explanation.firstElementChild);
}
sto[0] = setTimeout(() => {
requestAnimationFrame(animate);
}, delay);
}
} else {
requestAnimationFrame(animate);
}
};
const observer = new IntersectionObserver(
entries => {
let isVisible = entries[0].isIntersecting;
animationRunning = isVisible; // 标志变量更新
if (animationRunning) {
delay_init = i === 0 ? 200 : 20;
sto[1] = setTimeout(() => {
if (j) {
i = 0;
j = 0;
}
if (i === 0) {
explanation.innerHTML = ai_str.charAt(0);
}
requestAnimationFrame(animate);
}, delay_init);
}
},
{ threshold: 0 }
);
function clearSTO() {
if (sto.length) {
sto.forEach(item => {
if (item) {
clearTimeout(item);
}
});
}
// 当前随机到的ai摘要到index
let lastAiRandomIndex = -1;
let animationRunning = true; // 标志变量,控制动画函数的运行
// 当前gpt模式
let mode = modeName
// 刷新点击次数
let refreshNum = 0
// 记录上一次传递给aiAbstract的参数
let prevParam;
const aiTitleRefreshIcon = document.querySelector(".ai-title .anzhiyufont.anzhiyu-icon-arrow-rotate-right")
const explanation = document.querySelector(".ai-explanation");
const post_ai = document.querySelector(".post-ai");
let ai_str = "";
let ai_str_length = "";
let delay_init = 600;
let i = 0;
let j = 0;
let sto = [];
let elapsed = 0;
const animate = timestamp => {
if (!animationRunning) {
return; // 动画函数停止运行
}
function startAI(str, df = true) {
i = 0; //重置计数器
j = 1;
clearSTO();
animationRunning = false;
elapsed = 0;
observer.disconnect(); // 暂停上一次监听
explanation.innerHTML = df ? "生成中. . ." : "请等待. . .";
ai_str = str;
ai_str_length = ai_str.length;
observer.observe(post_ai); //启动新监听
}
async function aiAbstract(num = basicWordCount) {
i = 0; //重置计数器
j = 1;
clearSTO();
animationRunning = false;
elapsed = 0;
observer.disconnect(); // 暂停上一次监听
if (mode === "tianli") {
num = Math.max(10, Math.min(2000, num));
const options = {
key: keys,
Referer: Referers
};
const truncateDescription = getTitleAndContent(num);
const queryParams = `key=${options.key}&content=${truncateDescription}`;
const requestOptions = {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: options.Referer
},
};
try {
let animationInterval = null
if (animationInterval) clearInterval(animationInterval);
animationInterval = setInterval(() => {
const animationText = "生成中" + ".".repeat(j);
explanation.innerHTML = animationText;
j = (j % 3) + 1; // 在 1、2、3 之间循环
}, 500);
const response = await fetch(`https://summary.tianli0.top/?${queryParams}`, requestOptions);
let result;
if (response.status === 403) {
result = {
summary: "403 refer与key不匹配本地无法显示。"
}
} else if (response.status === 500) {
result = {
summary: "500 系统内部错误"
}
} else {
result = await response.json();
}
const summary = result.summary.trim();
setTimeout(() => {
aiTitleRefreshIcon.style.opacity = "1";
}, 300)
startAI(summary);
clearInterval(animationInterval)
} catch (error) {
console.error(error);
if (!animate.start) animate.start = timestamp;
elapsed = timestamp - animate.start;
if (elapsed >= 20) {
animate.start = timestamp;
if (i < ai_str_length - 1) {
let char = ai_str.charAt(i + 1);
let delay = /[,.,。!?]/.test(char) ? 150 : 20;
if (explanation.firstElementChild) {
explanation.removeChild(explanation.firstElementChild);
}
} else {
const strArr = ai.split(",").map(item => item.trim()); // 将字符串转换为数组,去除每个字符串前后的空格
if (strArr.length !== 1) {
let randomIndex = Math.floor(Math.random() * strArr.length); // 随机生成一个索引
while (randomIndex === lastAiRandomIndex) { // 如果随机到了上次的索引
randomIndex = Math.floor(Math.random() * strArr.length); // 再次随机
explanation.innerHTML += char;
let div = document.createElement("div");
div.className = "ai-cursor";
explanation.appendChild(div);
i++;
if (delay === 150) {
document.querySelector(".ai-explanation .ai-cursor").style.opacity = "0";
}
if (i === ai_str_length - 1) {
observer.disconnect(); // 暂停监听
explanation.removeChild(explanation.firstElementChild);
}
sto[0] = setTimeout(() => {
requestAnimationFrame(animate);
}, delay);
}
} else {
requestAnimationFrame(animate);
}
};
const observer = new IntersectionObserver(
entries => {
let isVisible = entries[0].isIntersecting;
animationRunning = isVisible; // 标志变量更新
if (animationRunning) {
delay_init = i === 0 ? 200 : 20;
sto[1] = setTimeout(() => {
if (j) {
i = 0;
j = 0;
}
if (i === 0) {
explanation.innerHTML = ai_str.charAt(0);
}
requestAnimationFrame(animate);
}, delay_init);
}
},
{ threshold: 0 }
);
function clearSTO() {
if (sto.length) {
sto.forEach(item => {
if (item) {
clearTimeout(item);
}
});
}
}
function startAI(str, df = true) {
i = 0; //重置计数器
j = 1;
clearSTO();
animationRunning = false;
elapsed = 0;
observer.disconnect(); // 暂停上一次监听
explanation.innerHTML = df ? "生成中. . ." : "请等待. . .";
ai_str = str;
ai_str_length = ai_str.length;
observer.observe(post_ai); //启动新监听
}
async function aiAbstract(num = basicWordCount) {
i = 0; //重置计数器
j = 1;
clearSTO();
animationRunning = false;
elapsed = 0;
observer.disconnect(); // 暂停上一次监听
if (mode === "tianli") {
num = Math.max(10, Math.min(2000, num));
const options = {
key: keys,
Referer: Referers
};
const truncateDescription = getTitleAndContent(num);
const queryParams = `key=${options.key}&content=${truncateDescription}`;
const requestOptions = {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: options.Referer
},
};
try {
let animationInterval = null
if (animationInterval) clearInterval(animationInterval);
animationInterval = setInterval(() => {
const animationText = "生成中" + ".".repeat(j);
explanation.innerHTML = animationText;
j = (j % 3) + 1; // 在 1、2、3 之间循环
}, 500);
const response = await fetch(`https://summary.tianli0.top/?${queryParams}`, requestOptions);
let result;
if (response.status === 403) {
result = {
summary: "403 refer与key不匹配本地无法显示。"
}
} else if (response.status === 500) {
result = {
summary: "500 系统内部错误"
}
lastAiRandomIndex = randomIndex; // 更新上次随机到的索引
startAI(strArr[randomIndex]);
} else {
startAI(strArr[0])
result = await response.json();
}
const summary = result.summary.trim();
setTimeout(() => {
aiTitleRefreshIcon.style.opacity = "1";
}, 600)
}, 300)
startAI(summary);
clearInterval(animationInterval)
} catch (error) {
console.error(error);
}
}
function aiRecommend() {
i = 0; //重置计数器
j = 1;
clearSTO();
animationRunning = false;
elapsed = 0;
explanation.innerHTML = "生成中. . .";
ai_str = "";
ai_str_length = "";
observer.disconnect(); // 暂停上一次监听
sto[2] = setTimeout(() => {
explanation.innerHTML = recommendList();
}, 600);
}
function aiGoHome() {
startAI("正在前往博客主页...", false);
sto[2] = setTimeout(() => {
pjax.loadUrl("/");
}, 1000);
}
const ai_btn_item = document.querySelectorAll(".ai-btn-item");
function Introduce() {
if (mode == "tianli") {
startAI("我是文章辅助AI: TianliGPT点击下方的按钮让我生成本文简介、推荐相关文章等。")
} else {
startAI("我是文章辅助AI: " + gptName + " GPT点击下方的按钮让我生成本文简介、推荐相关文章等。")
}
}
function aiTitleRefreshIconClick() {
aiTitleRefreshIcon.click()
}
const aiFunctions = [Introduce, aiTitleRefreshIconClick, aiRecommend, aiGoHome];
ai_btn_item.forEach((item, index) => {
item.addEventListener("click", () => {
aiFunctions[index]();
});
});
function recommendList() {
let thumbnail = document.querySelectorAll('.relatedPosts-list a');
if (!thumbnail.length) {
const cardRecentPost = document.querySelector('.card-widget.card-recent-post');
if (!cardRecentPost) return '';
thumbnail = cardRecentPost.querySelectorAll('.aside-list-item a');
let list = '';
for (let i = 0; i < thumbnail.length; i++) {
const item = thumbnail[i];
list += `<div class="ai-recommend-item"><span class="index">${i + 1}</span><a href="javascript:;" onclick="pjax.loadUrl('${item.href}')" title="${item.title}" data-pjax-state="">${item.title}</a></div>`;
} else {
const strArr = ai.split(",").map(item => item.trim()); // 将字符串转换为数组,去除每个字符串前后的空格
if (strArr.length !== 1) {
let randomIndex = Math.floor(Math.random() * strArr.length); // 随机生成一个索引
while (randomIndex === lastAiRandomIndex) { // 如果随机到了上次的索引
randomIndex = Math.floor(Math.random() * strArr.length); // 再次随机
}
return `很抱歉,无法找到类似的文章,你也可以看看本站最新发布的文章:<br /><div class="ai-recommend">${list}</div>`;
lastAiRandomIndex = randomIndex; // 更新上次随机到的索引
startAI(strArr[randomIndex]);
} else {
startAI(strArr[0])
}
setTimeout(() => {
aiTitleRefreshIcon.style.opacity = "1";
}, 600)
}
}
function aiRecommend() {
i = 0; //重置计数器
j = 1;
clearSTO();
animationRunning = false;
elapsed = 0;
explanation.innerHTML = "生成中. . .";
ai_str = "";
ai_str_length = "";
observer.disconnect(); // 暂停上一次监听
sto[2] = setTimeout(() => {
explanation.innerHTML = recommendList();
}, 600);
}
function aiGoHome() {
startAI("正在前往博客主页...", false);
sto[2] = setTimeout(() => {
pjax.loadUrl("/");
}, 1000);
}
const ai_btn_item = document.querySelectorAll(".ai-btn-item");
function Introduce() {
if (mode == "tianli") {
startAI("我是文章辅助AI: TianliGPT点击下方的按钮让我生成本文简介、推荐相关文章等。")
} else {
startAI("我是文章辅助AI: " + gptName + " GPT点击下方的按钮让我生成本文简介、推荐相关文章等。")
}
}
function aiTitleRefreshIconClick() {
aiTitleRefreshIcon.click()
}
const aiFunctions = [Introduce, aiTitleRefreshIconClick, aiRecommend, aiGoHome];
ai_btn_item.forEach((item, index) => {
item.addEventListener("click", () => {
aiFunctions[index]();
});
});
function recommendList() {
let thumbnail = document.querySelectorAll('.relatedPosts-list a');
if (!thumbnail.length) {
const cardRecentPost = document.querySelector('.card-widget.card-recent-post');
if (!cardRecentPost) return '';
thumbnail = cardRecentPost.querySelectorAll('.aside-list-item a');
let list = '';
for (let i = 0; i < thumbnail.length; i++) {
const item = thumbnail[i];
list += `<div class="ai-recommend-item"><span>推荐${i + 1}</span><a href="javascript:;" onclick="pjax.loadUrl('${item.href}')" title="${item.title}" data-pjax-state="">${item.title}</a></div>`;
list += `<div class="ai-recommend-item"><span class="index">${i + 1}</span><a href="javascript:;" onclick="pjax.loadUrl('${item.href}')" title="${item.title}" data-pjax-state="">${item.title}</a></div>`;
}
return `推荐文章:<br /><div class="ai-recommend">${list}</div>`;
return `很抱歉,无法找到类似的文章,你也可以看看本站最新发布的文章:<br /><div class="ai-recommend">${list}</div>`;
}
function changeShowMode() {
if (mode === "tianli") {
mode = "local";
document.getElementById("ai-tag").innerHTML = gptName + " GPT";
aiAbstract(basicWordCount);
} else {
mode = "tianli";
document.getElementById("ai-tag").innerHTML = "Tianli GPT";
const truncateDescription = getTitleAndContent(basicWordCount);
let value = Math.floor(Math.random() * randomNum) + basicWordCount;
while (value === prevParam || truncateDescription.length - value === prevParam) {
value = Math.floor(Math.random() * randomNum) + basicWordCount;
}
aiTitleRefreshIcon.style.opacity = "0.2";
aiTitleRefreshIcon.style.transitionDuration = "0.3s";
aiTitleRefreshIcon.style.transform = "rotate(" + 360 * refreshNum + "deg)";
if (truncateDescription.length <= 1000) {
let param = truncateDescription.length - Math.floor(Math.random() * randomNum);
while (param === prevParam) {
param = truncateDescription.length - Math.floor(Math.random() * randomNum);
}
aiAbstract(param);
prevParam = param;
} else {
aiAbstract(value);
prevParam = value;
}
refreshNum++;
}
let list = '';
for (let i = 0; i < thumbnail.length; i++) {
const item = thumbnail[i];
list += `<div class="ai-recommend-item"><span>推荐${i + 1}</span><a href="javascript:;" onclick="pjax.loadUrl('${item.href}')" title="${item.title}" data-pjax-state="">${item.title}</a></div>`;
}
//- 监听tag点击事件
document.getElementById("ai-tag").addEventListener("click", () => {
if (mode === "tianli") {
document.querySelectorAll(".ai-btn-item").forEach(item => item.style.display = "none");
document.getElementById("go-tianli-blog").style.display = "block";
startAI("你好我是Tianli开发的摘要生成助理TianliGPT是一个基于GPT-4的生成式AI。我在这里只负责摘要的预生成和显示你无法与我直接沟通如果你也需要一个这样的AI摘要接口可以在下方购买。暂未开放购买敬请期待")
} else {
document.getElementById("go-tianli-blog").style.display = "none";
startAI("你好,我是本站摘要生成助理" + gptName + " GPT是一个基于GPT-4的生成式AI。我在这里只负责摘要的预生成和显示你无法与我直接沟通。")
}
return `推荐文章:<br /><div class="ai-recommend">${list}</div>`;
}
});
aiTitleRefreshIcon.addEventListener("click", () => {
function changeShowMode() {
if (mode === "tianli") {
mode = "local";
document.getElementById("ai-tag").innerHTML = gptName + " GPT";
aiAbstract(basicWordCount);
} else {
mode = "tianli";
document.getElementById("ai-tag").innerHTML = "Tianli GPT";
const truncateDescription = getTitleAndContent(basicWordCount);
let value = Math.floor(Math.random() * randomNum) + basicWordCount;
while (value === prevParam || truncateDescription.length - value === prevParam) {
@ -315,34 +278,71 @@
aiAbstract(value);
prevParam = value;
}
showAiBtn();
refreshNum++;
});
}
}
document.getElementById("go-tianli-blog").addEventListener("click", () => {
window.open(btnLink, "_blank");
});
if (switchBtn) {
document.getElementById("ai-Toggle").addEventListener("click", () => {
changeShowMode()
});
//- 监听tag点击事件
document.getElementById("ai-tag").addEventListener("click", () => {
if (mode === "tianli") {
document.querySelectorAll(".ai-btn-item").forEach(item => item.style.display = "none");
document.getElementById("go-tianli-blog").style.display = "block";
startAI("你好我是Tianli开发的摘要生成助理TianliGPT是一个基于GPT-4的生成式AI。我在这里只负责摘要的预生成和显示你无法与我直接沟通如果你也需要一个这样的AI摘要接口可以在下方购买。暂未开放购买敬请期待")
} else {
document.getElementById("go-tianli-blog").style.display = "none";
startAI("你好,我是本站摘要生成助理" + gptName + " GPT是一个基于GPT-4的生成式AI。我在这里只负责摘要的预生成和显示你无法与我直接沟通。")
}
function showAiBtn() {
document.querySelectorAll(".ai-btn-item").forEach(item => {
if (item.id !== "go-tianli-blog") {
item.style.display = "block";
}
if (item.id === "go-tianli-blog") {
item.style.display = "none";
}
});
}
});
//读取文章中的所有文本
function getTitleAndContent(basicWordCount) {
try {
aiTitleRefreshIcon.addEventListener("click", () => {
const truncateDescription = getTitleAndContent(basicWordCount);
let value = Math.floor(Math.random() * randomNum) + basicWordCount;
while (value === prevParam || truncateDescription.length - value === prevParam) {
value = Math.floor(Math.random() * randomNum) + basicWordCount;
}
aiTitleRefreshIcon.style.opacity = "0.2";
aiTitleRefreshIcon.style.transitionDuration = "0.3s";
aiTitleRefreshIcon.style.transform = "rotate(" + 360 * refreshNum + "deg)";
if (truncateDescription.length <= 1000) {
let param = truncateDescription.length - Math.floor(Math.random() * randomNum);
while (param === prevParam) {
param = truncateDescription.length - Math.floor(Math.random() * randomNum);
}
aiAbstract(param);
prevParam = param;
} else {
aiAbstract(value);
prevParam = value;
}
showAiBtn();
refreshNum++;
});
document.getElementById("go-tianli-blog").addEventListener("click", () => {
window.open(btnLink, "_blank");
});
if (switchBtn) {
document.getElementById("ai-Toggle").addEventListener("click", () => {
changeShowMode()
});
}
function showAiBtn() {
document.querySelectorAll(".ai-btn-item").forEach(item => {
if (item.id !== "go-tianli-blog") {
item.style.display = "block";
}
if (item.id === "go-tianli-blog") {
item.style.display = "none";
}
});
}
//读取文章中的所有文本
function getTitleAndContent(basicWordCount) {
try {
const title = document.title;
const container = document.querySelector('#post #article-container');
if (!container) {
@ -350,20 +350,20 @@
return '';
}
const paragraphs = container.getElementsByTagName('p');
const headings = container.querySelectorAll('h1, h2, h3, h4, h5');
let content = '';
for (let h of headings) {
content += h.innerText + ' ';
}
for (let p of paragraphs) {
// 移除包含'http'的链接
const filteredText = p.innerText.replace(/https?:\/\/[^\s]+/g, '');
content += filteredText;
}
const combinedText = title + ' ' + content;
let wordLimit = 1000;
if (basicWordCount !== "undefined") {
@ -371,18 +371,18 @@
}
const truncatedText = combinedText.slice(0, wordLimit);
return truncatedText;
} catch (e) {
} catch (e) {
console.error('TianliGPT错误可能由于一个或多个错误导致没有正常运行原因出在获取文章容器中的内容失败或者可能是在文章转换过程中失败。', e);
return '';
}
}
}
aiAbstract();
showAiBtn()
})()
aiAbstract();
showAiBtn()
})()
</script>
</script>
</html>

View File

@ -99,14 +99,14 @@
<!-- 文章ai摘要 -->
<div class="post-ai" th:if="${theme.config.aiDescription.enable}">
<div class="post-ai" th:if="${theme.config.post.aiDescription.aiDescriptionEnable}">
<div class="ai-title"><i class="anzhiyufont anzhiyu-icon-bilibili"></i>
<div class="ai-title-text">AI-摘要</div>
<div th:if="${theme.config.aiDescription.switchBtn}" id="ai-Toggle">切换</div>
<div th:if="${theme.config.post.aiDescription.switchBtn}" id="ai-Toggle">切换</div>
<i class="anzhiyufont anzhiyu-icon-arrow-rotate-right"></i>
<div th:if="${#strings.equals(theme.config.aiDescription.mode, 'local')}" class="ai-tag" id="ai-tag">[[${theme.config.aiDescription.gptName}]] GPT</div>
<div th:if="${#strings.equals(theme.config.aiDescription.mode, 'tianli')}" class="ai-tag" id="ai-tag">Tianli GPT</div>
<div th:if="${#strings.equals(theme.config.post.aiDescription.mode, 'local')}" class="ai-tag" id="ai-tag">[[${theme.config.post.aiDescription.gptName}]] GPT</div>
<div th:if="${#strings.equals(theme.config.post.aiDescription.mode, 'tianli')}" class="ai-tag" id="ai-tag">Tianli GPT</div>
</div>
<div class="ai-explanation" style="display: block;">AI初始化中...</div>
<div class="ai-btn-box">