fixed: 现在能显示作者名称
This commit is contained in:
@@ -2,6 +2,7 @@ import { showPageMarker } from "@/components/page-marker";
|
||||
import { PinCollector } from "#imports";
|
||||
import { AutoLoader } from '@/components/autoLoader';
|
||||
import type { PinData } from '#imports';
|
||||
import { extractPinFromApi } from "@/components/pin-collector";
|
||||
|
||||
let loader: AutoLoader | null = null;
|
||||
|
||||
@@ -57,12 +58,12 @@ export default defineContentScript({
|
||||
}).catch(() => { });
|
||||
},
|
||||
onData: async (items) => {
|
||||
const newPins: PinData[] = items.map((pin: any) => extractPinData(pin));
|
||||
const newPins: PinData[] = items.map((pin: any) => extractPinFromApi(pin));
|
||||
// 读取已有数据,按 pin_id 去重合并
|
||||
const stored = await browser.storage.local.get('collectedPins') as { collectedPins?: PinData[] };
|
||||
const existing: PinData[] = stored.collectedPins || [];
|
||||
const existingIds = new Set(existing.map((p) => p.pinId));
|
||||
const merged = [...existing, ...newPins.filter((p) => !existingIds.has(p.pinId))];
|
||||
const existingUrls = new Set(existing.map((p) => p.url));
|
||||
const merged = [...existing, ...newPins.filter((p) => !existingUrls.has(p.url))];
|
||||
await browser.storage.local.set({ collectedPins: merged });
|
||||
console.log(`[content] 已写入 storage,累计 ${merged.length} 条`);
|
||||
},
|
||||
@@ -91,17 +92,4 @@ function sayHello() {
|
||||
closable: true, // 用户可点击 × 关闭
|
||||
autoRemoveSeconds: 10,
|
||||
});
|
||||
}
|
||||
|
||||
function extractPinData(pin: any): PinData {
|
||||
return {
|
||||
pinId: pin.pin_id ?? '',
|
||||
imgSmallSrc: pin.file?.url ?? '',
|
||||
imgSrc: (pin.file?.url ?? '').replace(/_fw\d+webp|_png/, ''),
|
||||
alt: pin.raw_text ?? '',
|
||||
author: pin.user?.username ?? '',
|
||||
time: pin.created_at ?? '',
|
||||
tags: pin.tags?.map((t: any) => t.tag ?? t) ?? [],
|
||||
url: `/pins/${pin.pin_id}/`,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user