Skip to content

Commit 6163dbd

Browse files
committed
feat: support multi themes
1 parent 465931a commit 6163dbd

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

gitstats/gitstats.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ body {
66
background-color: #ffffff;
77
}
88

9+
#theme {
10+
position: absolute;
11+
top: 10px;
12+
right: 10px;
13+
}
14+
915
dt {
1016
font-weight: bold;
1117
float: left;

gitstats/report_creator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def create(self, data, path):
4040
basedir = os.path.dirname(os.path.abspath(__file__))
4141
for file in (
4242
conf["style"],
43+
"script.js",
4344
"sortable.js",
4445
"arrow-up.gif",
4546
"arrow-down.gif",
@@ -930,6 +931,12 @@ def print_header(self, file) -> None:
930931
<script type="text/javascript" src="sortable.js"></script>
931932
</head>
932933
<body>
934+
935+
<select id="theme">
936+
<option value="default">White</option>
937+
<option value="green">Green</option>
938+
</select>
939+
<script type="text/javascript" src="script.js"></script>
933940
"""
934941
% (self.title, conf["style"], get_version)
935942
)

gitstats/script.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const themeSelect = document.getElementById('theme');
2+
3+
// Get the current theme from local storage
4+
const currentTheme = localStorage.getItem('theme');
5+
6+
// If a theme is stored in local storage, apply it to the page
7+
if (currentTheme) {
8+
document.body.style.color = getThemeColor(currentTheme);
9+
document.body.style.backgroundColor = getThemeBackgroundColor(currentTheme);
10+
}
11+
12+
// Add an event listener to the theme select element
13+
themeSelect.addEventListener('change', () => {
14+
const theme = themeSelect.value;
15+
// Store the selected theme in local storage
16+
localStorage.setItem('theme', theme);
17+
// Apply the selected theme to the page
18+
document.body.style.color = getThemeColor(theme);
19+
document.body.style.backgroundColor = getThemeBackgroundColor(theme);
20+
});
21+
22+
// Helper functions to get the theme color and background color
23+
function getThemeColor(theme) {
24+
switch (theme) {
25+
case 'default':
26+
return 'black';
27+
case 'green':
28+
return 'black';
29+
default:
30+
return 'black';
31+
}
32+
}
33+
34+
function getThemeBackgroundColor(theme) {
35+
switch (theme) {
36+
case 'default':
37+
return '#ffffff';
38+
case 'green':
39+
return '#dfd';
40+
default:
41+
return '#ffffff';
42+
}
43+
}

0 commit comments

Comments
 (0)