Initialized repo
This commit is contained in:
15
assets/js/auto-style-switch.js
Normal file
15
assets/js/auto-style-switch.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Detects system/browser color scheme and sets the "style_variant" cookie accordingly.
|
||||
* Reloads the page if the variant changes.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
const cookie = document.cookie.split('; ').find(r => r.startsWith('style_variant='));
|
||||
const current = cookie ? cookie.split('=')[1] : '';
|
||||
const desired = prefersDark ? '01-evening' : 'default'; // Customize variant names as needed
|
||||
if (current !== desired) {
|
||||
document.cookie = "style_variant=" + desired + "; path=/; max-age=31536000";
|
||||
location.reload();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user