Repository navigation
Expand file tree
/
Copy pathcontent.js
More file actions
142 lines (127 loc) · 4.15 KB
/
Copy pathcontent.js
File metadata and controls
142 lines (127 loc) · 4.15 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const isDev = false; // set true for development
// toggles console logs
if (!isDev) {
console.log = function () {};
}
(() => {
// Handles styling requests for the webpage
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "changeFont") {
changeFont(message.value);
} else if (message.type === "changeFontSize") {
changeFontSize(message.value);
} else if (message.type === "getFontStyles") {
getFontStyles(sendResponse);
} else if (message.type === "changeLetterSpacing") {
changeLetterSpace(message.value);
} else if (message.type === "changeColorMode") {
changeColorMode(message.value);
} else if (message.type === "reset") {
resetAll();
}
});
// Method to change color mode
const changeColorMode = (value) => {
const existing = document.getElementById("universal-dark-mode");
if (existing) {
existing.remove();
} else {
const style = document.createElement("style");
style.id = "universal-dark-mode";
style.textContent = `
html, body, div, span, p, a, h1, h2, h3, h4, h5, h6,
section, article, header, footer, main, nav, aside,
li, ul, ol, table, tr, td, th, form, label, input, textarea, select, button {
background-color: #121212 !important;
color: #e0e0e0 !important;
border-color: #333 !important;
}
a {
color: #80cbc4 !important;
}
img, svg, path, [class*="icon"], use {
filter: none !important;
color: unset !important;
fill: unset !important;
stroke: unset !important;
background-color: transparent !important;
}
}
`;
document.head.appendChild(style);
}
};
// Method to reset webpage back to original style
const resetAll = () => {
const idsToRemove = [
"font-override-style",
"size-override-style",
"space-override-style",
];
idsToRemove.forEach((id) => {
const style = document.getElementById(id);
if (style) style.remove();
});
};
// Method for changing font
const changeFont = (value) => {
if (value === "None") {
const style = document.getElementById("font-override-style");
if (style) style.remove();
return;
}
const styleId = "font-override-style";
const existingStyle = document.getElementById(styleId);
if (existingStyle) existingStyle.remove();
const style = document.createElement("style");
style.id = styleId;
style.textContent = `
* {
font-family: "${value}" !important;
}
yt-formatted-string, ytd-video-primary-info-renderer {
font-family: "${value}" !important;
}
`;
document.head.appendChild(style);
};
// Method for changing font size
const changeFontSize = (value) => {
const styleId = "size-override-style";
const existingStyle = document.getElementById(styleId);
if (existingStyle) existingStyle.remove();
const style = document.createElement("style");
style.id = styleId;
style.textContent = `html { font-size: ${value} !important; }`;
document.head.appendChild(style);
};
// Method for changing letter spacing
const changeLetterSpace = (value) => {
const styleId = "space-override-style";
const existingStyle = document.getElementById(styleId);
if (existingStyle) existingStyle.remove();
const style = document.createElement("style");
style.id = styleId;
style.textContent = `html { letter-spacing: ${value} !important; }`;
document.head.appendChild(style);
};
const getFontStyles = (sendResponse) => {
const style = window.getComputedStyle(document.documentElement);
const fontStyles = {
fontFamily: style.fontFamily,
fontSize: style.fontSize,
fontWeight: style.fontWeight,
fontStyle: style.fontStyle,
fontVariant: style.fontVariant,
lineHeight: style.lineHeight,
letterSpacing: style.letterSpacing,
wordSpacing: style.wordSpacing,
textTransform: style.textTransform,
textIndent: style.textIndent,
textDecoration: style.textDecoration,
};
console.log("Font styles: ", fontStyles);
// Sent back to popup.js
sendResponse(fontStyles);
};
})();