-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.py
262 lines (250 loc) · 9.66 KB
/
export.py
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
"""
This module generates the Electric Dark themes for both Firefox and Chrome.
It loads common manifest data from a JSON file, generates a specific manifest
for each browser, and updates color placeholders using a predefined color scheme.
"""
import os
import zipfile
import json
import copy
manifest_data = {
"manifest_version": 3,
"version": "5.8.4",
"name": "Electric [color] Dark",
"author": "Vito Ferri",
"developer": {"name": "Vito Ferri", "url": "https://github.com/VitoFe"},
"browser_specific_settings": {"gecko": {"id": "[id]"}},
}
addon_ids = {
"Purple": "{5d266402-4868-4f0c-b650-fd2d17c3a752}",
"Orange": "{5d266402-4868-4f0c-b650-fd2d17c3a753}",
"Green": "{5d266402-4868-4f0c-b650-fd2d17c3a754}",
"Azure": "{5d266402-4868-4f0c-b650-fd2d17c3a765}",
"Pink": "{5d266402-4868-4f0c-b650-fd2d17c3a756}",
"Red": "{5d266402-4868-4f0c-b650-fd2d17c3a757}",
"Yellow": "{5d266402-4868-4f0c-b650-fd2d17c3a758}",
"Twitch": "{5d266402-4868-4f0c-b650-fd2d17c3a759}",
"Discord": "{5d266402-4868-4f0c-b650-fd2d17c3a760}",
"Cyberpunk": "{5d266402-4868-4f0c-b650-fd2d17c3a761}",
"Cerbero": "{5d266402-4868-4f0c-b650-fd2d17c3a762}",
"Vaporwave": "{5d266402-4868-4f0c-b650-fd2d17c3a763}",
}
colors = {
"Purple": {
"accent_color": "#BD00FF",
"accent_color_trans": "#BD00FF20",
"accent_color_semitrans": "#BD00FF30",
"accent_color_chrome": "#C72EFF",
"frame_color": "#0C0E14EE",
"text_color": "#FFFFFF",
"text_color_popup": "#FFFFFF",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#121521",
},
"Orange": {
"accent_color": "#ff3503",
"accent_color_trans": "#ff350320",
"accent_color_semitrans": "#ff350330",
"accent_color_chrome": "#ff3503",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#0C0E14",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#150e0d",
},
"Green": {
"accent_color": "#00FF00",
"accent_color_trans": "#00FF0020",
"accent_color_semitrans": "#00FF0030",
"accent_color_chrome": "#00FF00",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#0C0E14",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#0D150E",
},
"Azure": {
"accent_color": "#00BFFF",
"accent_color_trans": "#00BFFF20",
"accent_color_semitrans": "#00BFFF30",
"accent_color_chrome": "#00BFFF",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#FFFFFF",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#0D1315",
},
"Red": {
"accent_color": "#FF0000",
"accent_color_trans": "#FF000020",
"accent_color_semitrans": "#FF000030",
"accent_color_chrome": "#FF0000",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#FFFFFF",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#150D0D",
},
"Yellow": {
"accent_color": "#FFFF00",
"accent_color_trans": "#FFFF0020",
"accent_color_semitrans": "#FFFF0030",
"accent_color_chrome": "#FFFF00",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#0C0E14",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#15150D",
},
"Pink": {
"accent_color": "#FF00FF",
"accent_color_trans": "#FF00FF20",
"accent_color_semitrans": "#FF00FF30",
"accent_color_chrome": "#FF00FF",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#FFFFFF",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#150D15",
},
"Twitch": {
"accent_color": "#9146FF",
"accent_color_trans": "#9146FF20",
"accent_color_semitrans": "#9146FF30",
"accent_color_chrome": "#AA60FF",
"frame_color": "#0C0E14",
"text_color": "#FFFFFF",
"text_color_popup": "#FFFFFF",
"text_muted_color": "#CCCCCC",
"toolbar_color": "#1A0F2B",
"theme_frame": "images/twitch-[browser].png",
},
"Discord": {
"accent_color": "#7289DA",
"accent_color_trans": "#7289DA20",
"accent_color_semitrans": "#7289DA30",
"accent_color_chrome": "#7289DA",
"frame_color": "#23272A",
"text_color": "#FFFFFF",
"text_color_popup": "#FFFFFF",
"text_muted_color": "#99AAB5",
"toolbar_color": "#2C2F33",
"theme_frame": "images/discord-[browser].png",
},
"Cyberpunk": {
"accent_color": "#BD00FF",
"accent_color_trans": "#BD00FF20",
"accent_color_semitrans": "#BD00FF30",
"accent_color_chrome": "#C72EFF",
"frame_color": "#0C0E14DD",
"text_color": "#f2e900",
"text_color_popup": "#002b32",
"text_muted_color": "#02d7f2",
"toolbar_color": "#0D131560",
"theme_frame": "images/cyberpunk.png"
},
"Cerbero": {
"accent_color": "#fffe94",
"accent_color_trans": "#fffe9420",
"accent_color_semitrans": "#fffe9430",
"accent_color_chrome": "#fffe94",
"frame_color": "#0d0d00DD",
"text_color": "#fffe94",
"text_color_popup": "#0C0E14",
"text_muted_color": "#cccb76",
"toolbar_color": "#0d0d0060",
"theme_ntp_bg": "images/cerbero-ntpb.png",
"theme_frame": "images/cerbero.png"
},
"Vaporwave": {
"accent_color": "#f62e97",
"accent_color_trans": "#f62e9720",
"accent_color_semitrans": "#f62e9730",
"accent_color_chrome": "#f62e97",
"frame_color": "#1A0F2BDD",
"text_color": "#f9d653",
"text_color_popup": "#0C0E14",
"text_muted_color": "#f9ba53",
"toolbar_color": "#1A0F2B50",
"theme_frame": "images/vaporwave.png"
},
}
def invert_hex(hex_color):
hex_color = hex_color.lstrip('#')
r, g, b = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
r = 255 - r
g = 255 - g
b = 255 - b
inverted_hex = '#{:02x}{:02x}{:02x}'.format(r, g, b)
return inverted_hex
def extract_number(filename):
name = filename.split(".")[0]
for i in range(len(name)):
if name[i].isdigit():
number = name[i:]
return int(number)
return None
# Convert color theme from dark-mode to light-mode
def convert_theme(theme):
new_theme = {}
for key, value in theme.items():
if value.startswith('#'):
new_value = invert_hex(value)
else:
new_value = value
new_theme[key] = new_value
return new_theme
# Load common manifest data
with open(os.path.join("templates", "common.json"), "r", encoding="utf-8") as f:
manifest_data.update(json.load(f))
# Generate extension package for each browser
for browser in ["firefox", "chrome"]:
with open(os.path.join("templates", f"{browser}.json"), "r", encoding="utf-8") as f:
manifest_spec = json.load(f)
# Parse color placeholders
for accent, colormap in colors.items():
manifest = copy.deepcopy(manifest_data)
manifest["theme"]["colors"].update(manifest_spec["colors"])
manifest["name"] = manifest_data["name"].replace("[color]", accent)
manifest.update(
{"browser_specific_settings": {"gecko": {"id": addon_ids[accent]}}}
)
if "theme_frame" in colormap.keys():
theme_frame = colormap["theme_frame"].replace("[browser]", browser)
if theme_frame.endswith(".svg") and browser != "firefox":
theme_frame = theme_frame.replace(".svg", ".png")
manifest["theme"]["images"]["theme_frame"] = theme_frame
if "theme_ntp_bg" in colormap.keys():
manifest["theme"]["images"]["theme_ntp_background"] = colormap["theme_ntp_bg"]
context = colormap.copy()
manifest["theme"]["colors"] = {
key: context[value] if value in context else value
for key, value in manifest["theme"]["colors"].items()
}
if browser == "chrome": # RGB array instead of HEX
manifest["theme"]["colors"] = {
element[0]: [int(element[1][i : i + 2], 16) for i in (1, 3, 5)]
if element[1].startswith("#")
else element[1]
for element in manifest["theme"]["colors"].items()
}
# Create extension package
EXT = ".xpi" if browser == "firefox" else ".zip"
theme_file = f"{manifest['name'].replace(' ', '')}_{browser}_{manifest['version']}{EXT}"
if not os.path.exists("out"):
os.makedirs("out")
with zipfile.ZipFile(os.path.join("out", theme_file), "w", zipfile.ZIP_DEFLATED) as package:
for include_dir in [ "icons", "images"]:
for root, dirs, files in os.walk(include_dir):
for file in files:
if include_dir == "icons":
if file.startswith(accent.lower()):
resolution = str(extract_number(file))
manifest["icons"][resolution] = f"{include_dir}/{file}"
package.write(os.path.join(root, file))
elif file.startswith("icon"):
package.write(os.path.join(root, file))
else:
package.write(os.path.join(root, file))
package.write("LICENSE")
package.writestr("manifest.json", json.dumps(manifest))