koishi-plugin-ll-mc 3.1.7 → 3.1.9
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 +46 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2598,7 +2598,7 @@ ${targetUserRecord[0].username}
|
|
|
2598
2598
|
.fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 8px 0 0 8px; z-index: 0; }
|
|
2599
2599
|
.bar-content { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; width: 100%; }
|
|
2600
2600
|
.row-name { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 5px; max-width: 78%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2601
|
-
.row-name.is-hero { color: #FFFFFF;
|
|
2601
|
+
.row-name.is-hero { color: #FFFFFF; }
|
|
2602
2602
|
.row-star { width: 16px; height: 16px; color: #FCD34D; flex-shrink: 0; }
|
|
2603
2603
|
.row-count { font-size: 18px; font-weight: 700; }
|
|
2604
2604
|
</style>
|
|
@@ -2647,6 +2647,51 @@ ${rows}
|
|
|
2647
2647
|
// 确保 emoji 字体就绪再截图
|
|
2648
2648
|
await page.evaluate(() => document.fonts.ready).catch(() => {});
|
|
2649
2649
|
await page.waitForSelector(".card").catch(() => {});
|
|
2650
|
+
// 官机补丁:背景图右侧可能是深色人物,导致排在右下角的发言数字看不清。
|
|
2651
|
+
// 这里对每个数字的位置采样一次背景亮度,凡是背景偏暗的数字改成白色(去掉全局描边)。
|
|
2652
|
+
try {
|
|
2653
|
+
const dpr = 2;
|
|
2654
|
+
// 先隐藏所有文字以采样"纯背景"像素
|
|
2655
|
+
await page.evaluate(() => {
|
|
2656
|
+
document.querySelectorAll(".bar-content").forEach((el) => { el.style.visibility = "hidden"; });
|
|
2657
|
+
});
|
|
2658
|
+
const bgShot = await page.screenshot({ type: "png", fullPage: true });
|
|
2659
|
+
await page.evaluate(() => {
|
|
2660
|
+
document.querySelectorAll(".bar-content").forEach((el) => { el.style.visibility = ""; });
|
|
2661
|
+
});
|
|
2662
|
+
const bgDataUrl = `data:image/png;base64,${bgShot.toString("base64")}`;
|
|
2663
|
+
const luminances = await page.evaluate(async (dataUrl) => {
|
|
2664
|
+
const img = new Image();
|
|
2665
|
+
img.src = dataUrl;
|
|
2666
|
+
await img.decode();
|
|
2667
|
+
const canvas = document.createElement("canvas");
|
|
2668
|
+
canvas.width = img.naturalWidth;
|
|
2669
|
+
canvas.height = img.naturalHeight;
|
|
2670
|
+
const ctx = canvas.getContext("2d");
|
|
2671
|
+
ctx.drawImage(img, 0, 0);
|
|
2672
|
+
const scale = window.devicePixelRatio || 1;
|
|
2673
|
+
const out = [];
|
|
2674
|
+
document.querySelectorAll(".row-count").forEach((el) => {
|
|
2675
|
+
const r = el.getBoundingClientRect();
|
|
2676
|
+
const x = Math.max(0, Math.min(Math.round((r.left + r.width / 2) * scale), canvas.width - 1));
|
|
2677
|
+
const y = Math.max(0, Math.min(Math.round((r.top + r.height / 2) * scale), canvas.height - 1));
|
|
2678
|
+
const d = ctx.getImageData(x, y, 1, 1).data;
|
|
2679
|
+
out.push(0.2126 * d[0] + 0.7152 * d[1] + 0.0722 * d[2]);
|
|
2680
|
+
});
|
|
2681
|
+
return out;
|
|
2682
|
+
}, bgDataUrl);
|
|
2683
|
+
await page.evaluate((lums) => {
|
|
2684
|
+
const nodes = document.querySelectorAll(".row-count");
|
|
2685
|
+
nodes.forEach((el, i) => {
|
|
2686
|
+
const lum = lums[i];
|
|
2687
|
+
if (lum !== undefined && lum < 120) {
|
|
2688
|
+
el.style.color = "#FFFFFF";
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
}, luminances);
|
|
2692
|
+
} catch (sampleError) {
|
|
2693
|
+
logger.warn("背景亮度采样失败,使用默认数字颜色:", sampleError?.message);
|
|
2694
|
+
}
|
|
2650
2695
|
// 背景(自定义 CSS/API 背景)是加在 html 上的,必须截整页才能把卡片外的背景一起截进来;
|
|
2651
2696
|
// body 高度由内容撑开(无 min-height),所以 fullPage 不会产生多余空白。
|
|
2652
2697
|
const buf = await page.screenshot({ type: "png", fullPage: true });
|