Added SVG inversion.

This commit is contained in:
donfiguerres 2022-06-10 14:10:04 +08:00
parent f3f928018f
commit 169bcfde94
5 changed files with 17 additions and 18 deletions

View file

@ -4,17 +4,17 @@
default-theme="{{ site.Params.darkMode.default }}"></div>
<a class="nav-link dropdown-toggle" href="#" id="themeSelector" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src="{{ "/images/moon-svgrepo-com.svg" }}" width=20>
<img src="{{ "/icons/moon-svgrepo-com.svg" }}" width=20>
</a>
<div class="dropdown-menu" aria-labelledby="themeSelector">
<a class="dropdown-item nav-link" href="#" onclick="enableLightTheme()">
<img src="{{ "/images/sun-svgrepo-com.svg" }}" width=20>
<img src="{{ "/icons/sun-svgrepo-com.svg" }}" width=20>
</a>
<a class="dropdown-item nav-link" href="#" onclick="enableDarkTheme()">
<img src="{{ "/images/moon-svgrepo-com.svg" }}" width=20>
<img src="{{ "/icons/moon-svgrepo-com.svg" }}" width=20>
</a>
<a class="dropdown-item nav-link" href="#" onclick="useSystemTheme()">
<img src="{{ "/images/computer-svgrepo-com.svg" }}" width=20>
<img src="{{ "/icons/computer-svgrepo-com.svg" }}" width=20>
</a>
</div>
</li>

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before After
Before After

View file

@ -1,28 +1,27 @@
const DARK = "dark";
const LIGHT = "light";
const SYSTEM = "system";
const COLOR_THEME = "color-theme";
const DARK_OPTIONS = {
brightness: 100,
contrast: 100,
sepia: 0
};
const SVG_INVERT = {invert: ['img[src$=".svg"]']};
function enableDarkTheme() {
localStorage.setItem('color-theme', DARK);
DarkReader.enable({
brightness: 100,
contrast: 100,
sepia: 0
});
localStorage.setItem(COLOR_THEME, DARK);
DarkReader.enable(DARK_OPTIONS, SVG_INVERT);
}
function enableLightTheme() {
localStorage.setItem('color-theme', LIGHT);
localStorage.setItem(COLOR_THEME, LIGHT);
DarkReader.disable();
}
function useSystemTheme() {
localStorage.setItem('color-theme', SYSTEM);
DarkReader.auto({
brightness: 100,
contrast: 100,
sepia: 0
});
localStorage.setItem(COLOR_THEME, SYSTEM);
DarkReader.auto(DARK_OPTIONS, SVG_INVERT);
}
function initializeColorTheme() {
@ -34,7 +33,7 @@ function initializeColorTheme() {
// If the user has already selected a preferred theme then use that instead
// of the default theme. Also, the default theme gets loaded to localStorage
// on the first visit.
let colorTheme = localStorage.getItem('color-theme');
let colorTheme = localStorage.getItem(COLOR_THEME);
if (colorTheme == null || colorTheme.length == 0) {
colorTheme = defaultColorScheme;
}