feat: add config option for night mode
This commit is contained in:
parent
a10b6a50ce
commit
c8e4149792
2 changed files with 25 additions and 8 deletions
|
@ -78,6 +78,10 @@ yat:
|
|||
# Custom color as below:
|
||||
# theme_color: "#882250"
|
||||
|
||||
# Night mode, default is "auto", "auto" is for auto nightshift (19:00 - 07:00),
|
||||
# "mannual" is for mannual toggle, and "on/off" is for always on/off.
|
||||
# night_mode: "auto"
|
||||
|
||||
# If you want to link only specific pages in your header, uncomment
|
||||
# this and add the path to the pages in order as they should show up
|
||||
# header_pages:
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
</label>
|
||||
</div>
|
||||
|
||||
{%- assign name = 'night_mode' -%}
|
||||
{%- include functions.html func='get_value' default='auto' -%}
|
||||
{%- assign night_mode = return -%}
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var sw = document.getElementById('theme-switch');
|
||||
|
@ -24,7 +28,7 @@
|
|||
try {
|
||||
data = JSON.parse(data ? data : '');
|
||||
} catch(e) {
|
||||
data = { nightShift: null, autoToggleAt: 0 };
|
||||
data = { nightShift: false, autoToggleAt: 0 };
|
||||
saveThemeData(data);
|
||||
}
|
||||
return data;
|
||||
|
@ -72,19 +76,28 @@
|
|||
};
|
||||
}
|
||||
|
||||
var data = autoThemeToggle();
|
||||
|
||||
// Listen the theme toggle event
|
||||
sw.addEventListener('change', function(event) {
|
||||
handleThemeToggle(event.target.checked);
|
||||
});
|
||||
|
||||
// Toggle theme by local setting
|
||||
if (data.toggleAt > themeData.autoToggleAt) {
|
||||
themeData.autoToggleAt = data.toggleAt;
|
||||
handleThemeToggle(data.nightShift);
|
||||
} else {
|
||||
var nightModeOption = '{{ night_mode }}';
|
||||
nightModeOption = nightModeOption.toLowerCase();
|
||||
|
||||
if (nightModeOption == 'auto') {
|
||||
var data = autoThemeToggle();
|
||||
|
||||
// Toggle theme by local setting
|
||||
if (data.toggleAt > themeData.autoToggleAt) {
|
||||
themeData.autoToggleAt = data.toggleAt;
|
||||
handleThemeToggle(data.nightShift);
|
||||
} else {
|
||||
handleThemeToggle(themeData.nightShift);
|
||||
}
|
||||
} else if (nightModeOption == 'mannual') {
|
||||
handleThemeToggle(themeData.nightShift);
|
||||
} else {
|
||||
handleThemeToggle(nightModeOption == 'on');
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue