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"; @import "markdown.css";
:root {
--max-width: 900px;
}
main {
max-width: var(--max-width);
}
/* Filetree */ /* Filetree */
aside { aside {
float: left; float: left;

View file

@ -182,6 +182,7 @@ pre:has(code.language-mermaid) {
/* Tables */ /* Tables */
table { table {
border-collapse: collapse; border-collapse: collapse;
margin-inline: auto;
} }
th, 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")) { for (const item of document.getElementsByTagName("img")) {
if (!item.src.startsWith("data:image/svg+xml;base64,")) { if (!item.src.startsWith("data:image/svg+xml;base64,")) {
// Exclude image who aren't SVG and base64 encoded // Exclude image who aren't SVG and base64 encoded
break; continue;
} }
/** Convert to grayscale */ /** Convert to grayscale */
@ -129,9 +134,19 @@ const svgDarkTheme = () => {
const totalGrayscale = grayscaleValues.reduce((acc, val) => acc + val, 0); const totalGrayscale = grayscaleValues.reduce((acc, val) => acc + val, 0);
const averageGrayscale = totalGrayscale / grayscaleValues.length; const averageGrayscale = totalGrayscale / grayscaleValues.length;
if (averageGrayscale < 128) { const treshold = 128;
if (averageGrayscale < treshold && mode === Mode.Dark) {
item.style = "filter: invert(1);"; 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); uncollapse(last_openeded);
} }
// Fix SVG images in dark mode // Fix SVG images
if (window.matchMedia("(prefers-color-scheme: dark)").matches) { svgChangeTheme(
svgDarkTheme(); window.matchMedia("(prefers-color-scheme: dark)").matches
} ? Mode.Dark
: Mode.Light
);
}); });
// Is this working?
window window
.matchMedia("(prefers-color-scheme: dark)") .matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", svgDarkTheme); .addEventListener("change", (event) =>
svgChangeTheme(event.matches ? Mode.Dark : Mode.Light)
);