增加对爱发电插件的支持

detailed:
1.增加了对爱发电插件的支持。
2.移除了爱发电apiToekn和userID的配置项。
3.修改了关于页面中访问统计内的“文章隧道”按钮在移动端下的样式。
This commit is contained in:
UPToZ 2024-05-21 11:25:37 +08:00
parent eca30a503b
commit 15f3614aac
5 changed files with 37 additions and 101 deletions

View File

@ -750,9 +750,7 @@ spec:
label: 爱发电赞助 label: 爱发电赞助
value: value:
powerLink: / powerLink: /
url: https://afdian.net/api/open/query-sponsor url: /apis/api.plugin.halo.run/v1alpha1/plugins/plugin-afdian/afdian/getSponsorList
userId:
apiToken:
showNum: 3 showNum: 3
children: children:
- $formkit: url - $formkit: url
@ -761,12 +759,7 @@ spec:
- $formkit: text - $formkit: text
name: url name: url
label: 接口地址 label: 接口地址
- $formkit: text help: 需要安装爱发电插件
name: userId
label: 用户ID
- $formkit: text
name: apiToken
label: API-Token
- $formkit: number - $formkit: number
name: showNum name: showNum
label: 最大展示条数 label: 最大展示条数

View File

@ -374,54 +374,23 @@ let halo = {
}, },
getTopSponsors() { getTopSponsors() {
var user_id = GLOBAL_CONFIG.source.power.userId;
var show_num = GLOBAL_CONFIG.source.power.showNum; var show_num = GLOBAL_CONFIG.source.power.showNum;
var api_token = GLOBAL_CONFIG.source.power.apiToken;
var url = GLOBAL_CONFIG.source.power.url; var url = GLOBAL_CONFIG.source.power.url;
//计算sign function getPower() {
function calculateSign(token, params, ts, userId) { const url = GLOBAL_CONFIG.source.power.url;
// 按照签名规则拼接字符串 fetch(url)
const signString = `${token}params${params}ts${ts}user_id${userId}`; .then(res => res.json())
// 使用MD5库计算签名 .then(data => {
const sign = CryptoJS.MD5(signString).toString(); console.log(data)
return sign; if (200 === data["ec"]) {
const values = data["data"]["list"];
saveToLocal.set('power-data', JSON.stringify(values), 10 / (60 * 24))
renderer(values);
} }
})
//查询赞助者 .catch(error => {
async function callQuerySponsorApi() { let powerStar = document.getElementById("power-star")
//查询参数
const params = {
page: 1,
per_page: 10
}
// 获取秒级时间戳
const ts = Math.floor(Date.now() / 1000);
// 计算签名
const sign = calculateSign(api_token, JSON.stringify(params), ts, user_id);
// 构建请求体
const request = {
user_id: user_id,
params: JSON.stringify(params),
ts: ts,
sign: sign
};
// 发送请求
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
});
// 处理响应
if (response.ok) {
const data = await response.json();
console.log('API Response:', data);
} else {
let powerStar = document.getElementById("power-star");
powerStar.href = GLOBAL_CONFIG.source.power.powerLink powerStar.href = GLOBAL_CONFIG.source.power.powerLink
powerStar.innerHTML = ` powerStar.innerHTML = `
<div id="power-star-image" style="background-image: url('/themes/theme-hao/assets/images/afadian/afadian.webp')"> <div id="power-star-image" style="background-image: url('/themes/theme-hao/assets/images/afadian/afadian.webp')">
@ -430,25 +399,7 @@ let halo = {
<div id="power-star-title">还没有人赞助</div> <div id="power-star-title">还没有人赞助</div>
<div id="power-star-desc">为爱发电点击赞助</div> <div id="power-star-desc">为爱发电点击赞助</div>
</div>`; </div>`;
console.error('API Error:', response.status, response.statusText); console.error(error);
}
}
function getPower() {
const url = GLOBAL_CONFIG.source.power.url;
const ts = Math.floor(Date.now() / 1000);
const sign =
// + user_id
fetch(url)
.then(res => res.json())
.then(data => {
if (200 === data["ec"]) {
var values = data["data"]["list"]
saveToLocal.set('power-data', JSON.stringify(values), 10 / (60 * 24))
renderer(values);
}
}) })
} }
@ -466,12 +417,12 @@ let halo = {
</div>`; </div>`;
} else { } else {
if (powerStar) { if (powerStar) {
powerStar.href = "https://afdian.net/u/" + data[0].user_id powerStar.href = "https://afdian.net/u/" + data[0]["user"].user_id
powerStar.innerHTML = ` powerStar.innerHTML = `
<div id="power-star-image" style="background-image: url(${data[0].avatar})"> <div id="power-star-image" style="background-image: url(${data[0]["user"].avatar})">
</div> </div>
<div class="power-star-body"> <div class="power-star-body">
<div id="power-star-title">${data[0].name}</div> <div id="power-star-title">${data[0]["user"].name}</div>
<div id="power-star-desc">更多支持为爱发电</div> <div id="power-star-desc">更多支持为爱发电</div>
</div>`; </div>`;
} }
@ -484,7 +435,7 @@ let halo = {
break; break;
} }
htmlText += htmlText +=
` <a href="${"https://afdian.net/u/" + value["user_id"]}" rel="external nofollow" target="_blank" th:title="${value["name"]}">${value["name"]}</a>`; ` <a href="${"https://afdian.net/u/" + value["user"]["user_id"]}" rel="external nofollow" target="_blank" th:title="${value["user"]["name"]}">${value["user"]["name"]}</a>`;
i = i + 1; i = i + 1;
} }
if (document.getElementById("power-item-link")) { if (document.getElementById("power-item-link")) {
@ -499,8 +450,7 @@ let halo = {
if (data) { if (data) {
renderer(JSON.parse(data)) renderer(JSON.parse(data))
} else { } else {
callQuerySponsorApi(); getPower();
// getPower();
} }
} }

View File

@ -2860,11 +2860,11 @@ blockquote footer cite::before {
display: inline; display: inline;
} }
#nav .menus_items .menus_item { /* #nav .menus_items .menus_item {
position: relative; position: relative;
display: inline-block; display: inline-block;
padding: 0px 0.4rem 0px 0px; padding: 0px 0.4rem 0px 0px;
} } */
#nav .menus_items .recursion_menus_item:hover>.menus_item_child, #nav .menus_items .recursion_menus_item:hover>.menus_item_child,
#nav .menus_items .menus_item:hover>.menus_item_child { #nav .menus_items .menus_item:hover>.menus_item_child {
@ -12432,11 +12432,6 @@ a.reward-main-btn:hover {
} }
/* 评论 */ /* 评论 */
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
div#post-comment { div#post-comment {
margin-top: 2rem; margin-top: 2rem;
} }
@ -16867,7 +16862,7 @@ span.hexo-douban-pagenum {
} }
.author-content-item .card-content .banner-button-group .banner-button { .author-content-item .card-content .banner-button-group .banner-button {
background: none; background: none !important;
color: var(--heo-white); color: var(--heo-white);
padding: 0; padding: 0;
width: fit-content; width: fit-content;

View File

@ -58,9 +58,7 @@
power: { power: {
powerLink: [[${theme.config.sidebar.power.powerLink}]], powerLink: [[${theme.config.sidebar.power.powerLink}]],
url: [[${theme.config.sidebar.power.url}]], url: [[${theme.config.sidebar.power.url}]],
userId: [[${theme.config.sidebar.power.userId}]], showNum: [[${theme.config.sidebar.power.showNum}]]
showNum: [[${theme.config.sidebar.power.showNum}]],
apiToken:[[${theme.config.sidebar.power.apiToken}]]
}, },
links: { links: {
linksUrl: [[${ theme.config.link.linksUrl }]], linksUrl: [[${ theme.config.link.linksUrl }]],

View File

@ -5,7 +5,7 @@
<a class="power-charge" th:href="${theme.config.sidebar.power.powerLink}" target="_blank" title="赞助博主">赞助 <a class="power-charge" th:href="${theme.config.sidebar.power.powerLink}" target="_blank" title="赞助博主">赞助
</a> </a>
</div> </div>
<a id="power-star" rel="external nofollow" target="_blank" title="推荐博主"> <a id="power-star" rel="external nofollow" target="_blank" title="感谢赞助博主">
</a> </a>
<div class="power-list"> <div class="power-list">