Changed darkreader CDN to local copy.
This commit is contained in:
parent
1c465dc73e
commit
c6fe04df72
4 changed files with 43 additions and 15 deletions
|
@ -1,5 +1,9 @@
|
|||
const DARK = "dark";
|
||||
const LIGHT = "light";
|
||||
const SYSTEM = "system";
|
||||
|
||||
function enableDarkTheme() {
|
||||
localStorage.setItem('color-scheme', "dark");
|
||||
localStorage.setItem('color-theme', DARK);
|
||||
DarkReader.enable({
|
||||
brightness: 100,
|
||||
contrast: 100,
|
||||
|
@ -8,12 +12,12 @@ function enableDarkTheme() {
|
|||
}
|
||||
|
||||
function enableLightTheme() {
|
||||
localStorage.setItem('color-scheme', "light");
|
||||
localStorage.setItem('color-theme', LIGHT);
|
||||
DarkReader.disable();
|
||||
}
|
||||
|
||||
function useSystemTheme() {
|
||||
localStorage.setItem('color-scheme', "system");
|
||||
localStorage.setItem('color-theme', SYSTEM);
|
||||
DarkReader.auto({
|
||||
brightness: 100,
|
||||
contrast: 100,
|
||||
|
@ -22,20 +26,22 @@ function useSystemTheme() {
|
|||
}
|
||||
|
||||
function initializeColorScheme() {
|
||||
// We're using the themeInitialization attributes as a 'hack' for setting up the
|
||||
// default color scheme becauase we don't want to complicate this further by
|
||||
// creating custom javascript output in Hugo.
|
||||
themeInitialization = document.getElementById("themeInitialization");
|
||||
defaultColorScheme = themeInitialization.getAttribute('default-theme');
|
||||
// We're using the themeInitialization attributes as a 'hack' for setting up
|
||||
// the default color scheme because we don't want to complicate this further
|
||||
// by creating custom javascript output in Hugo.
|
||||
let themeInitialization = document.getElementById("themeInitialization");
|
||||
let defaultColorScheme = themeInitialization.getAttribute('default-theme');
|
||||
// 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.
|
||||
if (!localStorage.getItem('color-scheme'))
|
||||
localStorage.setItem('color-scheme', defaultColorScheme);
|
||||
storedColorScheme = localStorage.getItem('color-scheme');
|
||||
if (storedColorScheme == "dark") {
|
||||
let colorTheme = localStorage.getItem('color-theme');
|
||||
if (colorTheme == null || colorTheme.length == 0) {
|
||||
colorTheme = defaultColorScheme;
|
||||
}
|
||||
// Enable the color theme
|
||||
if (colorTheme == DARK) {
|
||||
enableDarkTheme();
|
||||
} else if (storedColorScheme == "system") {
|
||||
} else if (colorTheme == SYSTEM) {
|
||||
useSystemTheme();
|
||||
} else {
|
||||
// We use light theme for the two conditions below.
|
||||
|
|
22
static/js/darkreader.js
Normal file
22
static/js/darkreader.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue