-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportUserCSS.py
49 lines (37 loc) · 1.52 KB
/
exportUserCSS.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
#!/usr/bin/env python3
from settings import getSettings
from os.path import dirname
def main():
# Get current directory
cd = dirname(__file__)
# Get settings
settings = getSettings()
# Get base and header
with open(cd + '/../style/base.css') as f:
base = f.read()
with open(cd + '/../style/header.txt') as f:
header = f.read()
# Write userCSS header
userCSS = "/* ==UserStyle==\n" + header + "\n"
userCSSSettings = ""
for settingId, settingVal in settings.items():
match settingVal['type']:
case ('dropdown' | 'image'):
userCSSSettings += f"@advanced dropdown {settingId} \"{settingVal['title']}\" {{\n"
for optionId, optionVal in settingVal['options'].items():
userCSSSettings += f"\t{settingId}--{optionId} \"{optionVal['title']}{'*' if settingVal['default'] == optionId else ''}\" <<<EOT {optionVal['content']} EOT;\n"
userCSSSettings += "}\n"
case 'color':
userCSSSettings += f"@advanced color {settingId} \"{settingVal['title']}\" {settingVal['default']}\n"
case _:
print(f"Error: Setting '{settingId}' has unknown type '{settingVal['type']}'")
exit()
userCSS += userCSSSettings.replace('*/', '*\\/')
userCSS += "\n==/UserStyle== */\n\n"
# Append base
userCSS += base
# Save
with open(cd + '/../dist/style.user.css', 'w+') as f:
f.write(userCSS)
if __name__ == "__main__":
main()