38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
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();
|
||
// 首次加载自动收集并存储
|
||
const pins = collector.collect();
|
||
if (pins.length > 0) {
|
||
collector.saveToStorage();
|
||
}
|
||
// 允许 popup 主动触发重新收集
|
||
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||
if (msg.type === 'COLLECT_PINS') {
|
||
const updatedPins = collector.collect();
|
||
sendResponse({ success: true, count: updatedPins.length });
|
||
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,
|
||
});
|
||
}
|