-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
42 lines (36 loc) · 1.09 KB
/
content.js
File metadata and controls
42 lines (36 loc) · 1.09 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function () {
const THEME_ID = 'gitstyles-theme';
function applyTheme(themeName) {
const existingLink = document.getElementById(THEME_ID);
if (themeName && themeName !== 'default') {
const themeFile = `styles/${themeName}.css`;
if (existingLink) {
// If the theme file is different, update it
if (!existingLink.href.includes(themeFile)) {
existingLink.href = chrome.runtime.getURL(themeFile);
}
} else {
const link = document.createElement('link');
link.href = chrome.runtime.getURL(themeFile);
link.type = 'text/css';
link.rel = 'stylesheet';
link.id = THEME_ID;
document.head.appendChild(link);
}
} else {
if (existingLink) {
existingLink.remove();
}
}
}
// Initial load
chrome.storage.local.get(['theme'], (result) => {
applyTheme(result.theme);
});
// Listen for changes
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'local' && changes.theme) {
applyTheme(changes.theme.newValue);
}
});
})();