koishi-plugin-ll-mc 3.1.0 → 3.1.2
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 +39 -32
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2519,39 +2519,33 @@ ${targetUserRecord[0].username}
|
|
|
2519
2519
|
}[ch]));
|
|
2520
2520
|
}
|
|
2521
2521
|
__name(escapeHtml, "escapeHtml");
|
|
2522
|
-
const
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
{ bar: "#B2DFDB", fill: "#80CBC4", text: "#374151" },
|
|
2535
|
-
{ bar: "#BBDEFB", fill: "#90CAF9", text: "#374151" },
|
|
2536
|
-
{ bar: "#E1BEE7", fill: "#CE93D8", text: "#374151" },
|
|
2537
|
-
{ bar: "#FFCCBC", fill: "#FFAB91", text: "#374151" },
|
|
2538
|
-
{ bar: "#F0F4C3", fill: "#E6EE9C", text: "#374151" },
|
|
2539
|
-
{ bar: "#BCAAA4", fill: "#A1887F", text: "#374151" },
|
|
2540
|
-
{ bar: "#EEEEEE", fill: "#BDBDBD", text: "#374151" },
|
|
2541
|
-
{ bar: "#CFD8DC", fill: "#90A4AE", text: "#374151" }
|
|
2522
|
+
const BAR_LIGHT_TRACK = "#F3F4F6";
|
|
2523
|
+
const BAR_FILL_COLORS = [
|
|
2524
|
+
"#F472B6", // pink
|
|
2525
|
+
"#A78BFA", // violet
|
|
2526
|
+
"#60A5FA", // blue
|
|
2527
|
+
"#34D399", // emerald
|
|
2528
|
+
"#FBBF24", // amber
|
|
2529
|
+
"#F87171", // red
|
|
2530
|
+
"#22D3EE", // cyan
|
|
2531
|
+
"#A3E635", // lime
|
|
2532
|
+
"#FB923C", // orange
|
|
2533
|
+
"#818CF8" // indigo
|
|
2542
2534
|
];
|
|
2543
|
-
function buildLeaderboardRow(item, index) {
|
|
2544
|
-
const pal = LEADERBOARD_ROW_PALETTES[index % LEADERBOARD_ROW_PALETTES.length];
|
|
2535
|
+
function buildLeaderboardRow(item, index, maxCount) {
|
|
2545
2536
|
const isHero = index === 0;
|
|
2546
|
-
const
|
|
2537
|
+
const fillColor = BAR_FILL_COLORS[((index - 1) % BAR_FILL_COLORS.length + BAR_FILL_COLORS.length) % BAR_FILL_COLORS.length];
|
|
2538
|
+
// 发言(数据)部分相对第一名缩放,确保柱子占比直观;0 发言使用极细条
|
|
2539
|
+
const width = item.count > 0 ? Math.max((item.count / maxCount) * 100, 2) : 1;
|
|
2547
2540
|
const avatar = escapeHtml(item.avatar || "");
|
|
2548
2541
|
const name = escapeHtml(item.name || "");
|
|
2549
2542
|
const count = item.count;
|
|
2550
|
-
|
|
2543
|
+
// 柱子总背景固定为浅色,发言部分单独用颜色区分,这样更显眼
|
|
2544
|
+
const barBg = BAR_LIGHT_TRACK;
|
|
2551
2545
|
const fill = isHero
|
|
2552
2546
|
? 'linear-gradient(to right, #6366F1, #A855F7, #EC4899)'
|
|
2553
|
-
:
|
|
2554
|
-
const textColor = isHero ? "#FFFFFF" :
|
|
2547
|
+
: fillColor;
|
|
2548
|
+
const textColor = isHero ? "#FFFFFF" : "#1F2937";
|
|
2555
2549
|
const star = isHero
|
|
2556
2550
|
? `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="row-star"><path fill-rule="evenodd" d="M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.007 5.404.433c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.433 2.082-5.006z" clip-rule="evenodd"/></svg>`
|
|
2557
2551
|
: "";
|
|
@@ -2567,8 +2561,9 @@ ${targetUserRecord[0].username}
|
|
|
2567
2561
|
</div>`;
|
|
2568
2562
|
}
|
|
2569
2563
|
__name(buildLeaderboardRow, "buildLeaderboardRow");
|
|
2570
|
-
function buildLeaderboardHtml(title, date, items) {
|
|
2571
|
-
const
|
|
2564
|
+
function buildLeaderboardHtml(title, date, items, backgroundCss) {
|
|
2565
|
+
const maxCount = Math.max(1, ...items.map((item) => item.count || 0));
|
|
2566
|
+
const rows = items.map((item, index) => buildLeaderboardRow(item, index, maxCount)).join("\n");
|
|
2572
2567
|
return `<!DOCTYPE html>
|
|
2573
2568
|
<html lang="zh-CN">
|
|
2574
2569
|
<head>
|
|
@@ -2578,11 +2573,15 @@ ${targetUserRecord[0].username}
|
|
|
2578
2573
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
2579
2574
|
html, body {
|
|
2580
2575
|
width: 900px;
|
|
2576
|
+
}
|
|
2577
|
+
html {
|
|
2581
2578
|
background-color: #F5F7FA;
|
|
2579
|
+
}
|
|
2580
|
+
body {
|
|
2581
|
+
padding: 16px;
|
|
2582
2582
|
font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
2583
2583
|
-webkit-font-smoothing: antialiased;
|
|
2584
2584
|
}
|
|
2585
|
-
body { padding: 16px; }
|
|
2586
2585
|
.card {
|
|
2587
2586
|
width: 100%;
|
|
2588
2587
|
max-width: 868px;
|
|
@@ -2609,6 +2608,7 @@ ${targetUserRecord[0].username}
|
|
|
2609
2608
|
.row-star { width: 16px; height: 16px; color: #FCD34D; flex-shrink: 0; }
|
|
2610
2609
|
.row-count { font-size: 18px; font-weight: 700; }
|
|
2611
2610
|
</style>
|
|
2611
|
+
${backgroundCss ? `<style>${backgroundCss}</style>` : ""}
|
|
2612
2612
|
</head>
|
|
2613
2613
|
<body>
|
|
2614
2614
|
<div class="card">
|
|
@@ -2624,11 +2624,11 @@ ${rows}
|
|
|
2624
2624
|
</html>`;
|
|
2625
2625
|
}
|
|
2626
2626
|
__name(buildLeaderboardHtml, "buildLeaderboardHtml");
|
|
2627
|
-
async function renderLeaderboardTemplate(ctx, title, date, items) {
|
|
2627
|
+
async function renderLeaderboardTemplate(ctx, title, date, items, backgroundCss) {
|
|
2628
2628
|
if (typeof ctx.puppeteer?.page !== "function") return null;
|
|
2629
2629
|
let page;
|
|
2630
2630
|
try {
|
|
2631
|
-
const html = buildLeaderboardHtml(title, date, items);
|
|
2631
|
+
const html = buildLeaderboardHtml(title, date, items, backgroundCss);
|
|
2632
2632
|
page = await ctx.puppeteer.page();
|
|
2633
2633
|
await page.setViewport({ width: 900, height: 400, deviceScaleFactor: 2 });
|
|
2634
2634
|
try {
|
|
@@ -2665,11 +2665,18 @@ ${rows}
|
|
|
2665
2665
|
rank: index + 1,
|
|
2666
2666
|
name: item.name.replace(/^★/, "")
|
|
2667
2667
|
}));
|
|
2668
|
+
let templateBackgroundCss = "";
|
|
2669
|
+
if (config.backgroundType === "css" && config.backgroundValue) {
|
|
2670
|
+
templateBackgroundCss = config.backgroundValue;
|
|
2671
|
+
} else if (config.backgroundType === "api" && config.apiBackgroundConfig?.apiUrl) {
|
|
2672
|
+
templateBackgroundCss = await _prepareBackgroundStyle(config);
|
|
2673
|
+
}
|
|
2668
2674
|
const dataUri = await renderLeaderboardTemplate(
|
|
2669
2675
|
ctx,
|
|
2670
2676
|
rankTitle,
|
|
2671
2677
|
rankTimeTitle,
|
|
2672
|
-
templateItems
|
|
2678
|
+
templateItems,
|
|
2679
|
+
templateBackgroundCss
|
|
2673
2680
|
);
|
|
2674
2681
|
if (dataUri) {
|
|
2675
2682
|
return import_koishi.h.image(dataUri);
|