koishi-plugin-ll-mc 3.1.0 → 3.1.1
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 +17 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2567,7 +2567,7 @@ ${targetUserRecord[0].username}
|
|
|
2567
2567
|
</div>`;
|
|
2568
2568
|
}
|
|
2569
2569
|
__name(buildLeaderboardRow, "buildLeaderboardRow");
|
|
2570
|
-
function buildLeaderboardHtml(title, date, items) {
|
|
2570
|
+
function buildLeaderboardHtml(title, date, items, backgroundCss) {
|
|
2571
2571
|
const rows = items.map(buildLeaderboardRow).join("\n");
|
|
2572
2572
|
return `<!DOCTYPE html>
|
|
2573
2573
|
<html lang="zh-CN">
|
|
@@ -2578,11 +2578,15 @@ ${targetUserRecord[0].username}
|
|
|
2578
2578
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
2579
2579
|
html, body {
|
|
2580
2580
|
width: 900px;
|
|
2581
|
+
}
|
|
2582
|
+
html {
|
|
2581
2583
|
background-color: #F5F7FA;
|
|
2584
|
+
}
|
|
2585
|
+
body {
|
|
2586
|
+
padding: 16px;
|
|
2582
2587
|
font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
2583
2588
|
-webkit-font-smoothing: antialiased;
|
|
2584
2589
|
}
|
|
2585
|
-
body { padding: 16px; }
|
|
2586
2590
|
.card {
|
|
2587
2591
|
width: 100%;
|
|
2588
2592
|
max-width: 868px;
|
|
@@ -2609,6 +2613,7 @@ ${targetUserRecord[0].username}
|
|
|
2609
2613
|
.row-star { width: 16px; height: 16px; color: #FCD34D; flex-shrink: 0; }
|
|
2610
2614
|
.row-count { font-size: 18px; font-weight: 700; }
|
|
2611
2615
|
</style>
|
|
2616
|
+
${backgroundCss ? `<style>${backgroundCss}</style>` : ""}
|
|
2612
2617
|
</head>
|
|
2613
2618
|
<body>
|
|
2614
2619
|
<div class="card">
|
|
@@ -2624,11 +2629,11 @@ ${rows}
|
|
|
2624
2629
|
</html>`;
|
|
2625
2630
|
}
|
|
2626
2631
|
__name(buildLeaderboardHtml, "buildLeaderboardHtml");
|
|
2627
|
-
async function renderLeaderboardTemplate(ctx, title, date, items) {
|
|
2632
|
+
async function renderLeaderboardTemplate(ctx, title, date, items, backgroundCss) {
|
|
2628
2633
|
if (typeof ctx.puppeteer?.page !== "function") return null;
|
|
2629
2634
|
let page;
|
|
2630
2635
|
try {
|
|
2631
|
-
const html = buildLeaderboardHtml(title, date, items);
|
|
2636
|
+
const html = buildLeaderboardHtml(title, date, items, backgroundCss);
|
|
2632
2637
|
page = await ctx.puppeteer.page();
|
|
2633
2638
|
await page.setViewport({ width: 900, height: 400, deviceScaleFactor: 2 });
|
|
2634
2639
|
try {
|
|
@@ -2665,11 +2670,18 @@ ${rows}
|
|
|
2665
2670
|
rank: index + 1,
|
|
2666
2671
|
name: item.name.replace(/^★/, "")
|
|
2667
2672
|
}));
|
|
2673
|
+
let templateBackgroundCss = "";
|
|
2674
|
+
if (config.backgroundType === "css" && config.backgroundValue) {
|
|
2675
|
+
templateBackgroundCss = config.backgroundValue;
|
|
2676
|
+
} else if (config.backgroundType === "api" && config.apiBackgroundConfig?.apiUrl) {
|
|
2677
|
+
templateBackgroundCss = await _prepareBackgroundStyle(config);
|
|
2678
|
+
}
|
|
2668
2679
|
const dataUri = await renderLeaderboardTemplate(
|
|
2669
2680
|
ctx,
|
|
2670
2681
|
rankTitle,
|
|
2671
2682
|
rankTimeTitle,
|
|
2672
|
-
templateItems
|
|
2683
|
+
templateItems,
|
|
2684
|
+
templateBackgroundCss
|
|
2673
2685
|
);
|
|
2674
2686
|
if (dataUri) {
|
|
2675
2687
|
return import_koishi.h.image(dataUri);
|