Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions public/_locales/da/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@
"GO_TO_OPTIONS": {
"message": "Gå til indstillinger"
},
"DATABASE_SETTINGS": {
"message": "Wiki database indstillinger"
},
"PAGES_DATABASE_UPDATE": {
"message": "Opdater manuelt"
},
"UPDATE_NOW": {
"message": "Opdater nu"
},
"AUTO_UPDATE_PAGESDB": {
"message": "Automatisk opdatering"
},
"PAGES_DATABASE_UPDATE_INTERVAL": {
"message": "Opdatere hver $days$ dag",
"placeholders": {
"days": {
"content": "$1"
}
}
},
"SHOW_MORE_OPTION": {
"message": "Vis mere option"
},
Expand Down Expand Up @@ -103,5 +123,17 @@
},
"IN_PAGE_SETTINGS": {
"message": "Side besked instillinger"
},
"SHOW_COMPANY": {
"message": "Vis firma resultater"
},
"SHOW_INCIDENT": {
"message": "Vis hændelse resultater"
},
"SHOW_PRODUCT": {
"message": "Vis produkt resultater"
},
"SHOW_PRODUCTLINE": {
"message": "Vis produktlinje resultater"
}
}
32 changes: 32 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@
"GO_TO_OPTIONS": {
"message": "Go to Options"
},
"DATABASE_SETTINGS": {
"message": "Wiki database options"
},
"PAGES_DATABASE_UPDATE": {
"message": "Manually update"
},
"UPDATE_NOW": {
"message": "Update now"
},
"AUTO_UPDATE_PAGESDB": {
"message": "Automatic update"
},
"PAGES_DATABASE_UPDATE_INTERVAL": {
"message": "Updating every $days$ days",
"placeholders": {
"days": {
"content": "$1"
}
}
},
"SHOW_MORE_OPTION": {
"message": "Show more option"
},
Expand Down Expand Up @@ -103,5 +123,17 @@
},
"IN_PAGE_SETTINGS": {
"message": "In page message settings"
},
"SHOW_COMPANY": {
"message": "Show company results"
},
"SHOW_INCIDENT": {
"message": "Show incedent results"
},
"SHOW_PRODUCT": {
"message": "Show product results"
},
"SHOW_PRODUCTLINE": {
"message": "Show productline results"
}
}
4 changes: 4 additions & 0 deletions src/common/helpers/dom-messenger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ describe('DOMMessenger', () => {
showMore: true,
showMute: true,
showHide: true,
showCompany: true,
showIncident: true,
showProduct: true,
showProductLine: true,
autoHideTime: 5000,
};

Expand Down
10 changes: 9 additions & 1 deletion src/common/messages/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,24 @@ const pageInfoHandler: MessageHandler<'pageInfo'> = (payload, context) => {

const notifyUpdateHandler: MessageHandler<'notifyUpdate'> = (payload, context) => {
return new Promise(() => {
console.log('Notify update Received, triggering page load handler:', payload);
console.log('Notify update Received, triggering notify update handler:', payload);
context.main.onNotifyUpdate(payload.pageId, payload.action);
});
};

const optionsActionHandler: MessageHandler<'optionsAction'> = (payload, context) => {
return new Promise(() => {
console.log('Notify update Received, triggering options action handler:', payload);
context.main.onOptions(payload.action);
});
};

const handlers = {
log: logHandler,
notify: notifyHandler,
pageInfo: pageInfoHandler,
notifyUpdate: notifyUpdateHandler,
optionsAction: optionsActionHandler,
} satisfies { [K in keyof MessageMap]: MessageHandler<K> };

function messageHandler(
Expand Down
1 change: 1 addition & 0 deletions src/common/messages/messages.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface MessageMap {
notify: [{ title: string; message: string }];
pageInfo: [{ domain: string; url: string }];
notifyUpdate: [{ pageId: number; action: string }];
optionsAction: [{ action: string }];
}
export interface MessageHandlerContext {
main: Main;
Expand Down
103 changes: 99 additions & 4 deletions src/common/services/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@ class Preferences {
static readonly PAGE_NOTIFICATIONS_SHOWMORE_KEY = 'page_notifications_show_more';
static readonly PAGE_NOTIFICATIONS_SHOWMUTE_KEY = 'page_notifications_show_mute';
static readonly PAGE_NOTIFICATIONS_SHOWHIDE_KEY = 'page_notifications_show_hide';
static readonly PAGE_NOTIFICATIONS_SHOW_COMPANY_KEY = 'page_notifications_show_company';
static readonly PAGE_NOTIFICATIONS_SHOW_INCIDENT_KEY = 'page_notifications_show_incident';
static readonly PAGE_NOTIFICATIONS_SHOW_PRODUCT_KEY = 'page_notifications_show_product';
static readonly PAGE_NOTIFICATIONS_SHOW_PRODUCTLINE_KEY = 'page_notifications_show_productline';

static readonly AUTO_UPDATE_PAGESDB_KEY = 'auto_update_pagesdb';
static readonly AUTO_UPDATE_PAGESDB_INTERVAL_KEY = 'auto_update_interval_pagesdb';

static isEnabled = new ObservableValue<boolean>(true);
static domainExclusions = new ObservableSet<string>();
static browserNotificationsEnabled = new ObservableValue<boolean>(true);
static pageNotificationsEnabled = new ObservableValue<boolean>(true);

//in page options
static pageNotificationsEnabled = new ObservableValue<boolean>(true);
static pageNotificationsAutoHideTime = new ObservableValue<number>(5);
static pageNotificationsDismissTime = new ObservableValue<number>(1);
static pageNotificationsShowMore = new ObservableValue<boolean>(true);
static pageNotificationsShowMute = new ObservableValue<boolean>(true);
static pageNotificationsShowHide = new ObservableValue<boolean>(true);
static pageNotificationsShowCompany = new ObservableValue<boolean>(true);
static pageNotificationsShowIncident = new ObservableValue<boolean>(true);
static pageNotificationsShowProduct = new ObservableValue<boolean>(true);
static pageNotificationsShowProductLine = new ObservableValue<boolean>(true);

static autoUpdateDB = new ObservableValue<boolean>(true);
static autoUpdateIntervalDB = new ObservableValue<number>(1);

// Injected storage backends (TODO: do we need both?)
// Sync is used to share data across browsers if logged in, e.g. plugin settings
Expand Down Expand Up @@ -61,9 +74,14 @@ class Preferences {
this.pageNotificationsShowMore.removeAllListeners();
this.pageNotificationsShowMute.removeAllListeners();
this.pageNotificationsShowHide.removeAllListeners();
this.pageNotificationsShowCompany.removeAllListeners();
this.pageNotificationsShowIncident.removeAllListeners();
this.pageNotificationsShowProduct.removeAllListeners();
this.pageNotificationsShowProductLine.removeAllListeners();
this.autoUpdateDB.removeAllListeners();
this.autoUpdateIntervalDB.removeAllListeners();

// Set up default callbacks

this.isEnabled.addListener(this.IS_ENABLED_KEY, (result: boolean) => {
this.setPreference(Preferences.IS_ENABLED_KEY, result);
});
Expand Down Expand Up @@ -100,6 +118,33 @@ class Preferences {
this.setPreference(Preferences.PAGE_NOTIFICATIONS_SHOWHIDE_KEY, result);
});

this.pageNotificationsShowCompany.addListener(this.PAGE_NOTIFICATIONS_SHOW_COMPANY_KEY, (result: boolean) => {
this.setPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_COMPANY_KEY, result);
});

this.pageNotificationsShowIncident.addListener(this.PAGE_NOTIFICATIONS_SHOW_INCIDENT_KEY, (result: boolean) => {
this.setPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_INCIDENT_KEY, result);
});

this.pageNotificationsShowProduct.addListener(this.PAGE_NOTIFICATIONS_SHOW_PRODUCT_KEY, (result: boolean) => {
this.setPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_PRODUCT_KEY, result);
});

this.pageNotificationsShowProductLine.addListener(
this.PAGE_NOTIFICATIONS_SHOW_PRODUCTLINE_KEY,
(result: boolean) => {
this.setPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_PRODUCTLINE_KEY, result);
}
);

this.autoUpdateDB.addListener(this.AUTO_UPDATE_PAGESDB_KEY, (result: boolean) => {
void this.setPreference(Preferences.AUTO_UPDATE_PAGESDB_KEY, result);
});

this.autoUpdateIntervalDB.addListener(this.AUTO_UPDATE_PAGESDB_INTERVAL_KEY, (result: number) => {
void this.setPreference(Preferences.AUTO_UPDATE_PAGESDB_INTERVAL_KEY, result);
});

// Attempt preference retrieval
const rawIsEnabled = await this.getPreference(this.IS_ENABLED_KEY);
if (typeof rawIsEnabled === 'boolean') {
Expand Down Expand Up @@ -164,6 +209,50 @@ class Preferences {
} else {
this.pageNotificationsShowHide.value = true;
}

const rawpageNotificationsShowCompany = await this.getPreference(this.PAGE_NOTIFICATIONS_SHOW_COMPANY_KEY);
if (typeof rawpageNotificationsShowCompany === 'boolean') {
this.pageNotificationsShowCompany.value = rawpageNotificationsShowCompany;
} else {
this.pageNotificationsShowCompany.value = true;
}

const rawpageNotificationsShowIncident = await this.getPreference(this.PAGE_NOTIFICATIONS_SHOW_INCIDENT_KEY);
if (typeof rawpageNotificationsShowIncident === 'boolean') {
this.pageNotificationsShowIncident.value = rawpageNotificationsShowIncident;
} else {
this.pageNotificationsShowIncident.value = true;
}

const rawpageNotificationsShowProduct = await this.getPreference(this.PAGE_NOTIFICATIONS_SHOW_PRODUCT_KEY);
if (typeof rawpageNotificationsShowProduct === 'boolean') {
this.pageNotificationsShowProduct.value = rawpageNotificationsShowProduct;
} else {
this.pageNotificationsShowProduct.value = true;
}

const rawpageNotificationsShowProductLine = await this.getPreference(
this.PAGE_NOTIFICATIONS_SHOW_PRODUCTLINE_KEY
);
if (typeof rawpageNotificationsShowProductLine === 'boolean') {
this.pageNotificationsShowProductLine.value = rawpageNotificationsShowProductLine;
} else {
this.pageNotificationsShowProductLine.value = true;
}

const rawAutoUpdatePagesDB = await this.getPreference(this.AUTO_UPDATE_PAGESDB_KEY);
if (typeof rawAutoUpdatePagesDB === 'boolean') {
this.autoUpdateDB.value = rawAutoUpdatePagesDB;
} else {
this.autoUpdateDB.value = true;
}

const rawAutoUpdateIntervalDB = await this.getPreference(this.AUTO_UPDATE_PAGESDB_KEY);
if (typeof rawAutoUpdateIntervalDB === 'number') {
this.autoUpdateIntervalDB.value = rawAutoUpdateIntervalDB;
} else {
this.autoUpdateIntervalDB.value = 1;
}
}

public static dump(): void {
Expand All @@ -176,7 +265,13 @@ class Preferences {
`PageNotificationsDismissTime = ${Preferences.pageNotificationsDismissTime.toString()}, ` +
`pageNotificationsShowMore = ${Preferences.pageNotificationsShowMore.toString()}, ` +
`pageNotificationsShowMute = ${Preferences.pageNotificationsShowMute.toString()}, ` +
`pageNotificationsShowHide = ${Preferences.pageNotificationsShowHide.toString()}`;
`pageNotificationsShowHide = ${Preferences.pageNotificationsShowHide.toString()}, ` +
`pageNotificationsShowCompany = ${Preferences.pageNotificationsShowCompany.toString()}, ` +
`pageNotificationsShowIncident = ${Preferences.pageNotificationsShowIncident.toString()}, ` +
`pageNotificationsShowProduct = ${Preferences.pageNotificationsShowProduct.toString()}, ` +
`pageNotificationsShowProductLine = ${Preferences.pageNotificationsShowProductLine.toString()}, ` +
`autoUpdateDB = ${Preferences.autoUpdateDB.toString()}, ` +
`autoUpdateIntervalDB = ${Preferences.autoUpdateIntervalDB.toString()}`;
console.log(msg);
}

Expand Down
25 changes: 25 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class Main {
/**
* Display how many pages were found by updating the badge text
*/

indicateCATPages(pages: CATWikiPageSearchResults, domMessenger: IDOMMessengerInterface): void {
Promise.all([
Preferences.getPreference(Preferences.IS_ENABLED_KEY),
Expand All @@ -55,6 +56,10 @@ export class Main {
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_SHOWHIDE_KEY),
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_AUTOHIDETIME_KEY),
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_DISMISSTIME_KEY),
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_COMPANY_KEY),
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_INCIDENT_KEY),
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_PRODUCT_KEY),
Preferences.getPreference(Preferences.PAGE_NOTIFICATIONS_SHOW_PRODUCTLINE_KEY),
NotificationsFilter.get(),
])
.then(
Expand All @@ -67,13 +72,21 @@ export class Main {
pageNotificationsShowHide,
pageNotificationsAutoHideTime,
pageNotificationsDismissTime,
pageNotificationsShowCompany,
pageNotificationsShowIncident,
pageNotificationsShowProduct,
pageNotificationsShowProductLine,
filters,
]) => {
if (isEnabled) {
const options: IInPageNotificationOptions = {
showMore: pageNotificationsShowMore as boolean,
showMute: pageNotificationsShowMute as boolean,
showHide: pageNotificationsShowHide as boolean,
showCompany: pageNotificationsShowCompany as boolean,
showIncident: pageNotificationsShowIncident as boolean,
showProduct: pageNotificationsShowProduct as boolean,
showProductLine: pageNotificationsShowProductLine as boolean,
autoHideTime: (pageNotificationsAutoHideTime as number) * 1000,
};

Expand Down Expand Up @@ -238,6 +251,18 @@ export class Main {
NotificationsFilter.update(page);
}

/**
* Called when a page (tab) has finished loading.
* Scans the domain and in-page contents, merges results,
* and indicates how many CAT pages were found.
*/
onOptions(action: string) {
if (action == 'pageDB.update') {
this.storageCache.updatePagesDB(true);
}
return;
}

/**
* Called when the extension is installed.
* Initializes default settings and indicates current status.
Expand Down
Loading