-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
24 lines (23 loc) · 1.01 KB
/
background.js
File metadata and controls
24 lines (23 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Background script placeholder for Escape Hatch
// Currently not strictly required but kept for simple storage tasks or future messaging.
chrome.runtime.onInstalled.addListener(() => {
// Ensure default settings exist
chrome.storage.sync.get(['enabled', 'customPhrases'], (res) => {
if (typeof res.enabled === 'undefined') {
// Default to disabled; users must enable the extension explicitly
chrome.storage.sync.set({ enabled: false });
}
// If user has no custom phrases saved, populate them with defaults.json so defaults are active by default
if (!Array.isArray(res.customPhrases) || !res.customPhrases.length) {
const url = chrome.runtime.getURL('defaults.json');
fetch(url).then(r => r.json()).then(defs => {
if (Array.isArray(defs) && defs.length) {
chrome.storage.sync.set({ customPhrases: defs });
}
}).catch(() => {
// On error, ensure at least an empty array
chrome.storage.sync.set({ customPhrases: [] });
});
}
});
});