mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-09 12:37:48 +03:00
chore: refactor
This commit is contained in:
@@ -1,20 +1,36 @@
|
||||
// Handle tab updates to inject content script
|
||||
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab): void => {
|
||||
if (changeInfo.status === 'complete' && tab.url && /^https?:/.test(tab.url)) {
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId },
|
||||
files: ['dist/main.js']
|
||||
}).catch((err: unknown) => {
|
||||
console.warn('Injection failed:', err);
|
||||
import { StorageService } from './services/StorageService.js';
|
||||
|
||||
class BackgroundService {
|
||||
constructor() {
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
private initialize(): void {
|
||||
this.setupTabUpdateListener();
|
||||
this.setupInstallListener();
|
||||
}
|
||||
|
||||
private setupTabUpdateListener(): void {
|
||||
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab): void => {
|
||||
if (changeInfo.status === 'complete' && tab.url && /^https?:/.test(tab.url)) {
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId },
|
||||
files: ['dist/content-standalone.js']
|
||||
}).catch((err: unknown) => {
|
||||
console.warn('Injection failed:', err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize storage on extension install
|
||||
chrome.runtime.onInstalled.addListener((): void => {
|
||||
chrome.storage.local.get(['exceptionsList'], (result: any) => {
|
||||
if (!result.exceptionsList) {
|
||||
chrome.storage.local.set({ exceptionsList: [] });
|
||||
}
|
||||
});
|
||||
});
|
||||
private setupInstallListener(): void {
|
||||
chrome.runtime.onInstalled.addListener(async (): Promise<void> => {
|
||||
const data = await StorageService.get(['exceptionsList']);
|
||||
if (!data.exceptionsList) {
|
||||
await StorageService.update('exceptionsList', []);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
new BackgroundService();
|
||||
Reference in New Issue
Block a user