Skip to content

Commit

Permalink
fix darkmode images #88
Browse files Browse the repository at this point in the history
Signed-off-by: weru <[email protected]>
  • Loading branch information
onweru committed Jan 24, 2023
1 parent 542c99f commit 9adbfd9
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,13 @@ function loadActions() {
}
})();

function pickModePicture(user, system, context) {
const pictures = elems('picture');
if(pictures) {
pictures.forEach(function(picture){
let source = picture.firstElementChild;
if(user == system) {
context ? source.media = prefersColor(dark) : false;
} else {
if(system == light) {
source.media = (user === dark) ? prefersColor(light) : prefersColor(dark) ;
} else {
source.media = (user === dark) ? prefersColor(dark) : prefersColor(light) ;
}
}
});
}
function pickModePicture(mode) {
elems('picture').forEach(function(picture){
let source = picture.firstElementChild;
const picture_data = picture.dataset;
const images = [picture_data.lit, picture_data.dark];
source.src = mode == 'dark' ? images[1] : images[0];
});
}

function setUserColorMode(mode = false) {
Expand All @@ -326,7 +317,7 @@ function loadActions() {
}
const user_mode = doc.dataset.mode;
doc.dataset.systemmode = sys_mode;
user_mode ? pickModePicture(user_mode,sys_mode,mode) : false;
user_mode ? pickModePicture(user_mode) : false;
}

setUserColorMode();
Expand Down

0 comments on commit 9adbfd9

Please sign in to comment.