-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
73 lines (64 loc) · 1.88 KB
/
content.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Inject the @font-face rule to load the bundled vintage font
const fontFaceStyle = document.createElement('style');
fontFaceStyle.textContent = `
@font-face {
font-family: 'Caslon Antique';
src: url(${chrome.runtime.getURL('caslon-antique.woff2')}) format('woff2');
font-weight: normal;
font-style: normal;
}
`;
document.head.appendChild(fontFaceStyle);
// Get the current hostname
const currentHost = window.location.hostname.toLowerCase();
// Retrieve user settings from storage
chrome.storage.sync.get(
['sepiaImages', 'textGlow', 'glowIntensity', 'pageTheme', 'whitelist'],
(result) => {
// Set default values
const defaults = {
sepiaImages: true,
textGlow: true,
glowIntensity: 1, // Changed default to 1
pageTheme: true,
whitelist: []
};
const settings = { ...defaults, ...result };
// Check whitelist: if current domain is in the whitelist, do nothing.
const whitelist = settings.whitelist;
if (whitelist.some(domain => currentHost.includes(domain.toLowerCase()))) {
return;
}
let cssRules = '';
if (settings.sepiaImages) {
cssRules += `
img {
filter: sepia(100%) !important;
}
`;
}
if (settings.textGlow) {
const intensity = settings.glowIntensity;
cssRules += `
body, p, span, h1, h2, h3, h4, h5, h6, a {
color: #704214 !important;
text-shadow: 0 0 ${intensity}px rgba(255, 228, 196, 0.8);
font-family: 'Caslon Antique', serif !important;
}
`;
}
if (settings.pageTheme) {
cssRules += `
body {
background: #f5f3ed !important;
}
`;
}
if (cssRules) {
const styleTag = document.createElement('style');
styleTag.id = 'nostalgia-sepia-style';
styleTag.textContent = cssRules;
document.head.appendChild(styleTag);
}
}
);