optimized js

This commit is contained in:
speyll
2025-04-25 01:50:29 +01:00
parent 105dc40b11
commit daee992cfb
6 changed files with 228 additions and 2 deletions

BIN
public/click.ogg Normal file

Binary file not shown.

125
public/css/style.css Normal file
View File

@@ -0,0 +1,125 @@
:root {
--icon-size: 1.3rem;
--icon-color: var(--text);
}
#nav-bar {
padding: 0.625rem 0 0;
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
justify-content: flex-end;
align-items: center;
}
#footer-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.accent-data {
color: var(--accent);
}
.theme-transition {
transition: color 0.3s ease, background-color 0.3s ease;
}
.tags-data {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-end;
align-items: flex-start;
align-content: flex-end
}
.title-list li {
margin-bottom: .375rem;
}
/* icons settings */
.icon {
width: var(--icon-size);
height: var(--icon-size);
display: inline-block;
vertical-align: middle;
color: var(--icon-color);
fill: currentColor;
transition: color 0.3s ease;
cursor: pointer;
}
.icon:hover {
--icon-color: var(--accent);
}
/* Theme toggle specific styles */
.theme-toggle {
cursor: pointer;
padding: 0;
margin: 0;
background: none;
border: none;
display: inline-flex;
}
.theme-toggle:hover .icon {
--icon-color: var(--accent);
}
.theme-toggle:active {
transform: scale(0.95);
}
/* footnotes */
.footnote-definition {
margin: 0 0 0 .125rem;
}
.footnote-definition-label {
color: var(--accent);
}
.footnote-definition p {
display: inline;
margin: .625rem 0 0 .625rem;
}
/* general classes */
/* Cleaned no-style class */
.no-style {
all: unset;
background: none !important;
border: none !important;
}
.no-style:hover {
background: transparent;
color: inherit;
}
/* Modern float replacement */
.float-right {
margin-inline-start: auto;
}
.float-left {
margin-inline-end: auto;
}
.center {
text-align: center;
}
.center img {
display: block;
margin: 1rem auto;
}
/* shortcodes css */
.webring {
margin: .375rem;
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

21
public/icons.svg Normal file
View File

@@ -0,0 +1,21 @@
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="rss" viewBox="0 0 24 24"><rect x="0" y="0" fill="none" stroke="none" />
<path fill="currentColor" d="M6.18 15.64a2.18 2.18 0 0 1 2.18 2.18C8.36 19 7.38 20 6.18 20C5 20 4 19 4 17.82a2.18 2.18 0 0 1 2.18-2.18M4 4.44A15.56 15.56 0 0 1 19.56 20h-2.83A12.73 12.73 0 0 0 4 7.27V4.44m0 5.66a9.9 9.9 0 0 1 9.9 9.9h-2.83A7.07 7.07 0 0 0 4 12.93V10.1Z"/>
</symbol>
<symbol id="darkMode" viewBox="0 0 24 24"><rect x="0" y="0" fill="none" stroke="none" />
<path fill="currentColor" d="M12 21q-3.775 0-6.388-2.613T3 12q0-3.45 2.25-5.988T11 3.05q.625-.075.975.45t-.025 1.1q-.425.65-.638 1.375T11.1 7.5q0 2.25 1.575 3.825T16.5 12.9q.775 0 1.538-.225t1.362-.625q.525-.35 1.075-.037t.475.987q-.35 3.45-2.937 5.725T12 21Zm0-2q2.2 0 3.95-1.213t2.55-3.162q-.5.125-1 .2t-1 .075q-3.075 0-5.238-2.163T9.1 7.5q0-.5.075-1t.2-1q-1.95.8-3.163 2.55T5 12q0 2.9 2.05 4.95T12 19Zm-.25-6.75Z"/>
</symbol>
<symbol id="lightMode" viewBox="0 0 24 24"><rect x="0" y="0" fill="none" stroke="none" />
<path fill="currentColor" d="M12 15q1.25 0 2.125-.875T15 12q0-1.25-.875-2.125T12 9q-1.25 0-2.125.875T9 12q0 1.25.875 2.125T12 15Zm0 2q-2.075 0-3.538-1.463T7 12q0-2.075 1.463-3.538T12 7q2.075 0 3.538 1.463T17 12q0 2.075-1.463 3.538T12 17ZM2 13q-.425 0-.713-.288T1 12q0-.425.288-.713T2 11h2q.425 0 .713.288T5 12q0 .425-.288.713T4 13H2Zm18 0q-.425 0-.713-.288T19 12q0-.425.288-.713T20 11h2q.425 0 .713.288T23 12q0 .425-.288.713T22 13h-2Zm-8-8q-.425 0-.713-.288T11 4V2q0-.425.288-.713T12 1q.425 0 .713.288T13 2v2q0 .425-.288.713T12 5Zm0 18q-.425 0-.713-.288T11 22v-2q0-.425.288-.713T12 19q.425 0 .713.288T13 20v2q0 .425-.288.713T12 23ZM5.65 7.05L4.575 6q-.3-.275-.288-.7t.288-.725q.3-.3.725-.3t.7.3L7.05 5.65q.275.3.275.7t-.275.7q-.275.3-.687.288T5.65 7.05ZM18 19.425l-1.05-1.075q-.275-.3-.275-.713t.275-.687q.275-.3.688-.287t.712.287L19.425 18q.3.275.288.7t-.288.725q-.3.3-.725.3t-.7-.3ZM16.95 7.05q-.3-.275-.288-.687t.288-.713L18 4.575q.275-.3.7-.288t.725.288q.3.3.3.725t-.3.7L18.35 7.05q-.3.275-.7.275t-.7-.275ZM4.575 19.425q-.3-.3-.3-.725t.3-.7l1.075-1.05q.3-.275.712-.275t.688.275q.3.275.288.688t-.288.712L6 19.425q-.275.3-.7.288t-.725-.288ZM12 12Z"/>
</symbol>
<symbol id="chevronLeft" viewBox="0 0 24 24"><rect x="0" y="0" fill="none" stroke="none" />
<path fill="currentColor" d="M15.41 16.58L10.83 12l4.58-4.59L14 6l-6 6l6 6l1.41-1.42Z"/>
</symbol>
<symbol id="chevronRight" viewBox="0 0 24 24"><rect x="0" y="0" fill="none" stroke="none" />
<path fill="currentColor" d="M8.59 16.58L13.17 12L8.59 7.41L10 6l6 6l-6 6l-1.41-1.42Z"/>
</symbol>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

72
public/js/script.js Normal file
View File

@@ -0,0 +1,72 @@
class ThemeManager {
constructor() {
this.toggle = document.getElementById('theme-toggle');
if (!this.toggle) return;
this.icon = document.getElementById('theme-icon');
const { iconBase, iconDark, iconLight, soundSrc } = this.toggle.dataset;
this.iconBase = iconBase;
this.iconDark = iconDark;
this.iconLight = iconLight;
// Create audio element lazily only when needed
this.sound = null;
this.soundSrc = soundSrc;
this.init();
}
init() {
this.setInitialTheme();
this.toggle.addEventListener('click', () => this.toggleTheme());
}
setInitialTheme() {
const savedTheme = localStorage.getItem('theme');
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const initialTheme = savedTheme || (systemDark ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', initialTheme);
this.updateIcon(initialTheme === 'dark');
}
toggleTheme() {
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
const newTheme = isDark ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', newTheme);
this.updateIcon(!isDark);
localStorage.setItem('theme', newTheme);
// Lazy load sound only when needed
if (!this.sound && this.soundSrc) {
this.sound = new Audio(this.soundSrc);
}
if (this.sound) {
this.sound.play().catch(() => {});
}
// Use requestAnimationFrame for better performance on transition
requestAnimationFrame(() => {
setTimeout(() => {
document.body.classList.remove('theme-transition');
}, 300);
});
}
updateIcon(isDark) {
if (this.icon) {
this.icon.setAttribute('href',
`${this.iconBase}${isDark ? this.iconDark : this.iconLight}`);
}
}
}
// Initialize when content is loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => new ThemeManager());
} else {
new ThemeManager();
}