Compare commits

..

3 commits

Author SHA1 Message Date
a3161d822d
svg theme changer 2024-11-06 18:17:29 +01:00
0f6f2f1fc4
increase cours page width 2024-11-06 17:54:02 +01:00
2a4ae9f273
centered 2024-11-06 17:41:27 +01:00
3 changed files with 36 additions and 9 deletions

View file

@ -1,5 +1,13 @@
@import "markdown.css";
:root {
--max-width: 900px;
}
main {
max-width: var(--max-width);
}
/* Filetree */
aside {
float: left;

View file

@ -182,6 +182,7 @@ pre:has(code.language-mermaid) {
/* Tables */
table {
border-collapse: collapse;
margin-inline: auto;
}
th,

View file

@ -80,11 +80,16 @@ const deepestNodeOpened = (path, options) => {
}
};
const svgDarkTheme = () => {
const Mode = {
Light: 1,
Dark: 2,
};
const svgChangeTheme = (mode) => {
for (const item of document.getElementsByTagName("img")) {
if (!item.src.startsWith("data:image/svg+xml;base64,")) {
// Exclude image who aren't SVG and base64 encoded
break;
continue;
}
/** Convert to grayscale */
@ -129,9 +134,19 @@ const svgDarkTheme = () => {
const totalGrayscale = grayscaleValues.reduce((acc, val) => acc + val, 0);
const averageGrayscale = totalGrayscale / grayscaleValues.length;
if (averageGrayscale < 128) {
const treshold = 128;
if (averageGrayscale < treshold && mode === Mode.Dark) {
item.style = "filter: invert(1);";
continue;
}
if (averageGrayscale > treshold && mode === Mode.Light) {
item.style = "filter: invert(1);";
continue;
}
item.style = "";
}
};
@ -160,13 +175,16 @@ window.addEventListener("load", () => {
uncollapse(last_openeded);
}
// Fix SVG images in dark mode
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
svgDarkTheme();
}
// Fix SVG images
svgChangeTheme(
window.matchMedia("(prefers-color-scheme: dark)").matches
? Mode.Dark
: Mode.Light
);
});
// Is this working?
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", svgDarkTheme);
.addEventListener("change", (event) =>
svgChangeTheme(event.matches ? Mode.Dark : Mode.Light)
);