增加对爱发电插件的支持

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

View File

@ -374,54 +374,23 @@ let halo = {
},
getTopSponsors() {
var user_id = GLOBAL_CONFIG.source.power.userId;
var show_num = GLOBAL_CONFIG.source.power.showNum;
var api_token = GLOBAL_CONFIG.source.power.apiToken;
var url = GLOBAL_CONFIG.source.power.url;
//计算sign
function calculateSign(token, params, ts, userId) {
// 按照签名规则拼接字符串
const signString = `${token}params${params}ts${ts}user_id${userId}`;
// 使用MD5库计算签名
const sign = CryptoJS.MD5(signString).toString();
return sign;
function getPower() {
const url = GLOBAL_CONFIG.source.power.url;
fetch(url)
.then(res => res.json())
.then(data => {
console.log(data)
if (200 === data["ec"]) {
const values = data["data"]["list"];
saveToLocal.set('power-data', JSON.stringify(values), 10 / (60 * 24))
renderer(values);
}
//查询赞助者
async function callQuerySponsorApi() {
//查询参数
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");
})
.catch(error => {
let powerStar = document.getElementById("power-star")
powerStar.href = GLOBAL_CONFIG.source.power.powerLink
powerStar.innerHTML = `
<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-desc">为爱发电点击赞助</div>
</div>`;
console.error('API Error:', response.status, response.statusText);
}
}
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);
}
console.error(error);
})
}
@ -466,12 +417,12 @@ let halo = {
</div>`;
} else {
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 = `
<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 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>`;
}
@ -484,7 +435,7 @@ let halo = {
break;
}
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;
}
if (document.getElementById("power-item-link")) {
@ -499,8 +450,7 @@ let halo = {
if (data) {
renderer(JSON.parse(data))
} else {
callQuerySponsorApi();
// getPower();
getPower();
}
}

View File

@ -2860,11 +2860,11 @@ blockquote footer cite::before {
display: inline;
}
#nav .menus_items .menus_item {
/* #nav .menus_items .menus_item {
position: relative;
display: inline-block;
padding: 0px 0.4rem 0px 0px;
}
} */
#nav .menus_items .recursion_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 {
margin-top: 2rem;
}
@ -16867,7 +16862,7 @@ span.hexo-douban-pagenum {
}
.author-content-item .card-content .banner-button-group .banner-button {
background: none;
background: none !important;
color: var(--heo-white);
padding: 0;
width: fit-content;

View File

@ -58,9 +58,7 @@
power: {
powerLink: [[${theme.config.sidebar.power.powerLink}]],
url: [[${theme.config.sidebar.power.url}]],
userId: [[${theme.config.sidebar.power.userId}]],
showNum: [[${theme.config.sidebar.power.showNum}]],
apiToken:[[${theme.config.sidebar.power.apiToken}]]
showNum: [[${theme.config.sidebar.power.showNum}]]
},
links: {
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>
</div>
<a id="power-star" rel="external nofollow" target="_blank" title="推荐博主">
<a id="power-star" rel="external nofollow" target="_blank" title="感谢赞助博主">
</a>
<div class="power-list">