Files
custom-plugin/entrypoints/content.ts
2026-05-01 21:54:20 +08:00

35 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { showPageMarker } from "@/components/page-marker";
import { PinCollector } from "#imports";
export default defineContentScript({
matches: ['*://*.huaban.com/*'],
runAt: 'document_idle',
main() {
sayHello();
const collector = new PinCollector();
// 首次加载自动收集并存储
// 允许 popup 主动触发重新收集
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.type === 'COLLECT_PINS') {
const pins = collector.collect();
sendResponse({ success: true, count: pins.length, pins });
return true; // 异步响应
}
});
},
});
function sayHello() {
console.log('检测到花瓣网!', window.location.href);
console.log('这个插件是一个用于自动收集图片的插件。');
showPageMarker({
text: '检测到花瓣网!插件已启动',
position: 'top-right',
backgroundColor: 'rgba(34, 139, 34, 0.9)',
closable: true, // 用户可点击 × 关闭
autoRemoveSeconds: 10,
});
}