-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
20 lines (17 loc) · 825 Bytes
/
background.js
File metadata and controls
20 lines (17 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const DEFAULT_SETTINGS = { bold: false, spacing: 0, lineHeight: 1.5, fontSize: 16 };
async function applyToTab(tabId) {
const store = await chrome.storage.local.get(['global-enabled', 'global-settings']);
if (!store['global-enabled']) return;
const settings = store['global-settings'] ?? DEFAULT_SETTINGS;
try {
await chrome.tabs.sendMessage(tabId, { type: 'APPLY_ALL', settings });
} catch {
// Tab doesn't have content script (e.g. chrome:// pages)
}
}
// Apply settings when switching to an existing tab
chrome.tabs.onActivated.addListener(({ tabId }) => applyToTab(tabId));
// Apply settings when a tab finishes loading (handles navigation within a tab)
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (changeInfo.status === 'complete') applyToTab(tabId);
});