koishi-plugin-ll-mc 3.1.8 → 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.
Files changed (2) hide show
  1. package/lib/index.js +45 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2601,8 +2601,6 @@ ${targetUserRecord[0].username}
2601
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
- /* 名字/数字加白色描边光晕,保证在深浅/花哨背景上都看得清 */
2605
- .row-name, .row-count { text-shadow: -1px -1px 0 rgba(255,255,255,0.9), 1px -1px 0 rgba(255,255,255,0.9), -1px 1px 0 rgba(255,255,255,0.9), 1px 1px 0 rgba(255,255,255,0.9), 0 1px 2px rgba(0,0,0,0.12); }
2606
2604
  </style>
2607
2605
  ${backgroundCss ? `<style>${backgroundCss}</style>` : ""}
2608
2606
  </head>
@@ -2649,6 +2647,51 @@ ${rows}
2649
2647
  // 确保 emoji 字体就绪再截图
2650
2648
  await page.evaluate(() => document.fonts.ready).catch(() => {});
2651
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
+ }
2652
2695
  // 背景(自定义 CSS/API 背景)是加在 html 上的,必须截整页才能把卡片外的背景一起截进来;
2653
2696
  // body 高度由内容撑开(无 min-height),所以 fullPage 不会产生多余空白。
2654
2697
  const buf = await page.screenshot({ type: "png", fullPage: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-mc",
3
3
  "description": "消息数量统计插件(基于 koishi-plugin-message-counter 重做,官方QQ机器人兼容)",
4
- "version": "3.1.8",
4
+ "version": "3.1.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [