-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
118 lines (102 loc) · 3.21 KB
/
background.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
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
// Function to modify theme
function gotMessage(message) {
function persist(key, value) {
chrome.storage.local.set({ [key]: value }, function () {});
}
function changeLogoColor() {
const selector =
"#logo-icon > yt-icon-shape > icon-shape > div > svg > svg > g:nth-child(1) > path:nth-child(1)";
const svgPath = document.querySelector(selector);
if (svgPath) {
svgPath.style.fill = message.setLogoColor;
persist("setLogoColor", message.setLogoColor);
} else {
console.log("SVG path not found using the given selector:", selector);
}
}
function changeTimeLineColor() {
const selector = ".ytp-swatch-background-color";
const timeLine = document.querySelectorAll(selector);
if (timeLine) {
timeLine.forEach((el) => {
el.style.backgroundColor = message.setTimelineColor;
persist("setTimelineColor", message.setTimelineColor);
});
} else {
console.log("SVG path not found using the given selector:", selector);
}
}
function changePlayerIconsColor() {
let selector = ".ytp-svg-fill";
let icons = document.querySelectorAll(selector);
if (icons) {
icons.forEach((el) => {
el.style.fill = message.setPlayerIconsColor;
persist("setPlayerIconsColor", message.setPlayerIconsColor);
});
} else {
console.log("SVG path not found using the given selector:", selector);
}
selector = ".ytp-button > svg";
icons = document.querySelectorAll(selector);
if (icons) {
icons.forEach((el) => {
el.style.fill = message.setPlayerIconsColor;
});
} else {
console.log("SVG path not found using the given selector:", selector);
}
}
function changeIconsColor() {
const selector = ".guide-icon.ytd-guide-entry-renderer";
const icon = document.querySelectorAll(selector);
if (icon) {
icon.forEach((el) => {
el.style.color = message.setIconsColor;
persist("setIconsColor", message.setIconsColor);
});
} else {
console.log("SVG path not found using the given selector:", selector);
}
}
changeLogoColor();
changeTimeLineColor();
changeIconsColor();
changePlayerIconsColor();
}
// Listen for messages
function handleGotMessage(message) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
func: gotMessage,
args: [message],
});
});
}
const theme = {
setLogoColor: "setLogoColor",
setTimelineColor: "setTimelineColor",
// setAllFontsColors: getInputValue("setFontsColor"),
setIconsColor: "setIconsColor",
setPlayerIconsColor: "setPlayerIconsColor",
};
chrome.runtime.onMessage.addListener(handleGotMessage);
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.greeting === "get-theme-data") {
let fetchedTheme = {};
const keys = Object.keys(theme);
let counter = 0;
keys.forEach((key) => {
chrome.storage.local.get(key, function (value) {
fetchedTheme[key] = value[key];
counter++;
if (counter === keys.length) {
sendResponse(fetchedTheme);
}
});
});
return true;
}
return true;
});