62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
export interface ExtensionSettings {
|
|
showDangerWarning: boolean
|
|
copyOnTranslate: boolean
|
|
preferredShell: 'bash' | 'zsh' | 'fish' | 'powershell'
|
|
theme: 'light' | 'dark' | 'auto'
|
|
contextMenuEnabled: boolean
|
|
inlinePanelEnabled: boolean
|
|
}
|
|
|
|
const DEFAULT_SETTINGS: ExtensionSettings = {
|
|
showDangerWarning: true,
|
|
copyOnTranslate: true,
|
|
preferredShell: 'bash',
|
|
theme: 'auto',
|
|
contextMenuEnabled: true,
|
|
inlinePanelEnabled: true,
|
|
}
|
|
|
|
export async function getSettings(): Promise<ExtensionSettings> {
|
|
try {
|
|
const result = await chrome.storage.sync.get('screwdriver_settings')
|
|
return { ...DEFAULT_SETTINGS, ...(result.screwdriver_settings ?? {}) }
|
|
} catch {
|
|
return DEFAULT_SETTINGS
|
|
}
|
|
}
|
|
|
|
export async function setSettings(settings: Partial<ExtensionSettings>): Promise<void> {
|
|
const current = await getSettings()
|
|
await chrome.storage.sync.set({
|
|
screwdriver_settings: { ...current, ...settings },
|
|
})
|
|
}
|
|
|
|
export interface ClipboardItem {
|
|
id: string
|
|
text: string
|
|
timestamp: number
|
|
type: 'command' | 'transform' | 'conflict' | 'regex'
|
|
}
|
|
|
|
export async function addClipboardItem(item: Omit<ClipboardItem, 'id' | 'timestamp'>): Promise<void> {
|
|
const result = await chrome.storage.local.get('screwdriver_history')
|
|
const history: ClipboardItem[] = result.screwdriver_history ?? []
|
|
const newItem: ClipboardItem = {
|
|
...item,
|
|
id: `${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
timestamp: Date.now(),
|
|
}
|
|
const updated = [newItem, ...history].slice(0, 50)
|
|
await chrome.storage.local.set({ screwdriver_history: updated })
|
|
}
|
|
|
|
export async function getClipboardHistory(): Promise<ClipboardItem[]> {
|
|
const result = await chrome.storage.local.get('screwdriver_history')
|
|
return result.screwdriver_history ?? []
|
|
}
|
|
|
|
export async function clearClipboardHistory(): Promise<void> {
|
|
await chrome.storage.local.remove('screwdriver_history')
|
|
}
|