Initial build: SimpleScan Solo v0.1.0 - Freelancer receipt capture Chrome extension
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { DEFAULT_SETTINGS } from '../types.js';
|
||||
const RECEIPTS_KEY = 'simplescan_receipts';
|
||||
const SETTINGS_KEY = 'simplescan_settings';
|
||||
export async function getReceipts() {
|
||||
const result = await chrome.storage.local.get(RECEIPTS_KEY);
|
||||
return result[RECEIPTS_KEY] || [];
|
||||
}
|
||||
export async function saveReceipt(receipt) {
|
||||
const receipts = await getReceipts();
|
||||
const existingIndex = receipts.findIndex((r) => r.id === receipt.id);
|
||||
if (existingIndex >= 0) {
|
||||
receipts[existingIndex] = receipt;
|
||||
}
|
||||
else {
|
||||
receipts.unshift(receipt);
|
||||
}
|
||||
await chrome.storage.local.set({ [RECEIPTS_KEY]: receipts });
|
||||
}
|
||||
export async function deleteReceipt(id) {
|
||||
const receipts = await getReceipts();
|
||||
const filtered = receipts.filter((r) => r.id !== id);
|
||||
await chrome.storage.local.set({ [RECEIPTS_KEY]: filtered });
|
||||
}
|
||||
export async function getSettings() {
|
||||
const result = await chrome.storage.local.get(SETTINGS_KEY);
|
||||
return result[SETTINGS_KEY] || { ...DEFAULT_SETTINGS };
|
||||
}
|
||||
export async function saveSettings(settings) {
|
||||
await chrome.storage.local.set({ [SETTINGS_KEY]: settings });
|
||||
}
|
||||
export async function clearAllReceipts() {
|
||||
await chrome.storage.local.remove(RECEIPTS_KEY);
|
||||
}
|
||||
Reference in New Issue
Block a user