koishi-plugin-fimtale-api 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +19 -14
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -173,7 +173,7 @@ function apply(ctx, config) {
|
|
|
173
173
|
if (actionDiv) {
|
|
174
174
|
actionDiv.querySelectorAll("span[title]").forEach((s) => {
|
|
175
175
|
const t = s.getAttribute("title") || "";
|
|
176
|
-
const v = s.textContent?.trim().replace(
|
|
176
|
+
const v = s.textContent?.trim().replace(/[^0-9]/g, "") || "0";
|
|
177
177
|
if (t.includes("字")) stats.words = v;
|
|
178
178
|
if (t.includes("阅读")) stats.views = v;
|
|
179
179
|
if (t.includes("评论")) stats.comments = v;
|
|
@@ -202,7 +202,13 @@ function apply(ctx, config) {
|
|
|
202
202
|
const renderCard = /* @__PURE__ */ __name(async (info, parent) => {
|
|
203
203
|
const isChapter = info.IsChapter || !!parent && parent.ID !== info.ID;
|
|
204
204
|
const displayTitle = isChapter && parent ? parent.Title : info.Title;
|
|
205
|
-
|
|
205
|
+
let displayCover = null;
|
|
206
|
+
if (isChapter) {
|
|
207
|
+
displayCover = extractImage(info.Content);
|
|
208
|
+
}
|
|
209
|
+
if (!displayCover) {
|
|
210
|
+
displayCover = isChapter && parent ? parent.Background || extractImage(parent.Content) : info.Background || extractImage(info.Content);
|
|
211
|
+
}
|
|
206
212
|
const displayTagsObj = isChapter && parent ? parent.Tags : info.Tags;
|
|
207
213
|
const subTitle = isChapter ? info.Title : null;
|
|
208
214
|
const views = info.Views || 0;
|
|
@@ -212,7 +218,7 @@ function apply(ctx, config) {
|
|
|
212
218
|
const bgStyle = displayCover ? `background-image: url('${displayCover}');` : `background: ${generateGradient(displayTitle)};`;
|
|
213
219
|
let summary = stripHtml(info.Content);
|
|
214
220
|
if (summary.length < 10 && parent && isChapter) summary = stripHtml(parent.Content);
|
|
215
|
-
if (summary.length >
|
|
221
|
+
if (summary.length > 110) summary = summary.substring(0, 110) + "...";
|
|
216
222
|
if (!summary) summary = "暂无简介";
|
|
217
223
|
const tagsArr = [];
|
|
218
224
|
if (displayTagsObj?.Type) tagsArr.push(displayTagsObj.Type);
|
|
@@ -227,10 +233,10 @@ function apply(ctx, config) {
|
|
|
227
233
|
<head>
|
|
228
234
|
<style>
|
|
229
235
|
body { margin: 0; padding: 0; font-family: ${fontStack}; background: transparent; }
|
|
230
|
-
.card { width:
|
|
236
|
+
.card { width: 620px; height: 340px; background: #fff; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); display: flex; overflow: hidden; }
|
|
231
237
|
.cover { width: 220px; height: 100%; ${bgStyle} background-size: cover; background-position: center; position: relative; flex-shrink: 0; }
|
|
232
238
|
.id-tag { position: absolute; top: 12px; left: 12px; background: rgba(0,0,0,0.6); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: bold; backdrop-filter: blur(4px); font-family: monospace; }
|
|
233
|
-
.info { flex: 1; padding:
|
|
239
|
+
.info { flex: 1; padding: 22px 26px; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
|
|
234
240
|
|
|
235
241
|
.title {
|
|
236
242
|
font-size: 22px; font-weight: 700; color: #333; line-height: 1.35;
|
|
@@ -242,9 +248,9 @@ function apply(ctx, config) {
|
|
|
242
248
|
padding-left: 10px; border-left: 3px solid #e91e63;
|
|
243
249
|
}
|
|
244
250
|
|
|
245
|
-
.author { font-size: 13px; color: #888; margin-top:
|
|
251
|
+
.author { font-size: 13px; color: #888; margin-top: 6px; font-weight: 400; }
|
|
246
252
|
|
|
247
|
-
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin:
|
|
253
|
+
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; max-height: 56px; overflow: hidden; align-content: flex-start; }
|
|
248
254
|
.tag { background: #eff2f5; color: #5c6b7f; padding: 3px 9px; border-radius: 4px; font-size: 11px; font-weight: 500; }
|
|
249
255
|
.tag-imp { background: #e3f2fd; color: #1565c0; }
|
|
250
256
|
|
|
@@ -253,7 +259,7 @@ function apply(ctx, config) {
|
|
|
253
259
|
display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
|
|
254
260
|
margin-top: auto;
|
|
255
261
|
}
|
|
256
|
-
.footer { border-top: 1px solid #eee; padding-top: 14px; display: flex; justify-content: space-between; font-size: 12px; color: #888; margin-top:
|
|
262
|
+
.footer { border-top: 1px solid #eee; padding-top: 14px; display: flex; justify-content: space-between; font-size: 12px; color: #888; margin-top: 12px; }
|
|
257
263
|
.stat b { color: #555; font-weight: bold; margin-right: 2px;}
|
|
258
264
|
</style>
|
|
259
265
|
</head>
|
|
@@ -280,7 +286,7 @@ function apply(ctx, config) {
|
|
|
280
286
|
const page = await ctx.puppeteer.page();
|
|
281
287
|
await injectCookies(page);
|
|
282
288
|
await page.setContent(html);
|
|
283
|
-
await page.setViewport({ width:
|
|
289
|
+
await page.setViewport({ width: 660, height: 460, deviceScaleFactor: 2 });
|
|
284
290
|
const el = await page.$(".card");
|
|
285
291
|
const img = await el.screenshot({ type: "png" });
|
|
286
292
|
await page.close();
|
|
@@ -343,7 +349,7 @@ function apply(ctx, config) {
|
|
|
343
349
|
return img;
|
|
344
350
|
}, "renderSearchResults");
|
|
345
351
|
const renderReadPages = /* @__PURE__ */ __name(async (info) => {
|
|
346
|
-
const
|
|
352
|
+
const content = cleanContent(info.Content);
|
|
347
353
|
const html = `
|
|
348
354
|
<!DOCTYPE html>
|
|
349
355
|
<html>
|
|
@@ -367,14 +373,13 @@ function apply(ctx, config) {
|
|
|
367
373
|
font-size: 12px; color: #aaa; font-family: sans-serif;
|
|
368
374
|
}
|
|
369
375
|
.page-content { flex: 1; overflow: hidden; font-size: ${config.fontSize}px; line-height: 1.7; text-align: justify; }
|
|
370
|
-
/* 段落样式优化 */
|
|
371
376
|
p { margin: 0 0 0.6em 0; text-indent: 2em; }
|
|
372
377
|
img { max-width: 100%; height: auto; display: block; margin: 10px auto; border-radius: 6px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
|
|
373
378
|
h1, h2, h3 { font-size: 1.1em; margin: 0.5em 0; color: #5d4037; text-indent: 0; font-weight: bold; }
|
|
374
379
|
</style>
|
|
375
380
|
</head>
|
|
376
381
|
<body>
|
|
377
|
-
<div id="source-container"><div class="meta-info" data-title="${info.Title}" data-author="${info.UserName}"></div>${
|
|
382
|
+
<div id="source-container"><div class="meta-info" data-title="${info.Title}" data-author="${info.UserName}"></div>${content}</div>
|
|
378
383
|
<div id="output"></div>
|
|
379
384
|
<script>
|
|
380
385
|
function paginate() {
|
|
@@ -468,7 +473,7 @@ function apply(ctx, config) {
|
|
|
468
473
|
if (!res.valid) return `[错误] ID:${id} 读取失败`;
|
|
469
474
|
const img = await renderCard(res.data, res.parent);
|
|
470
475
|
await session.send(import_koishi.h.image(img, "image/png"));
|
|
471
|
-
return
|
|
476
|
+
return `Tip: 发送 /ft.read ${res.data.ID} 阅读全文`;
|
|
472
477
|
});
|
|
473
478
|
ctx.command("ft.search <keyword:text>", "搜索作品").action(async ({ session }, keyword) => {
|
|
474
479
|
if (!keyword) return "请输入关键词";
|
|
@@ -477,7 +482,7 @@ function apply(ctx, config) {
|
|
|
477
482
|
if (!results.length) return "未找到结果。";
|
|
478
483
|
const img = await renderSearchResults(keyword, results);
|
|
479
484
|
await session.send(import_koishi.h.image(img, "image/png"));
|
|
480
|
-
return "
|
|
485
|
+
return "Tip: 发送 /ft.read <ID> 阅读";
|
|
481
486
|
});
|
|
482
487
|
ctx.command("ft.sub <threadId:string>", "订阅").action(async ({ session }, threadId) => {
|
|
483
488
|
if (!/^\d+$/.test(threadId)) return "ID错误";
|