Expand the template catalog and restore fwnet dark mode

This commit is contained in:
2026-11-28 20:07:27 +08:00
parent 11aa155f6b
commit a24b034426
27 changed files with 259 additions and 3 deletions
+36
View File
@@ -1,6 +1,42 @@
'use strict';
jQuery(function ($) {
const fwnetPage = document.querySelector('#main-content.theme-fwnet');
const fwnetLinks = fwnetPage?.querySelector('.fwnet-nav > div');
if (fwnetLinks) {
const systemTheme = matchMedia('(prefers-color-scheme: dark)');
const preferenceKey = 'laysite-fwnet-appearance';
let preference;
try {
const stored = localStorage.getItem(preferenceKey);
if (stored === 'dark' || stored === 'light') preference = stored;
} catch {
// The switch still works when the browser disables storage.
}
const $icon = $('<span>', {'aria-hidden': 'true'});
const $toggle = $('<button>', {type: 'button', class: 'fwnet-theme-toggle', 'aria-label': '深色模式'}).append($icon);
$(fwnetLinks).append($toggle);
function reflectAppearance() {
const dark = preference ? preference === 'dark' : systemTheme.matches;
if (preference) fwnetPage.dataset.fwnetAppearance = preference;
$toggle.attr('aria-pressed', String(dark));
$icon.text(dark ? '☾' : '☀');
}
reflectAppearance();
systemTheme.addEventListener('change', reflectAppearance);
$toggle.on('click', () => {
preference = $toggle.attr('aria-pressed') === 'true' ? 'light' : 'dark';
reflectAppearance();
try {
localStorage.setItem(preferenceKey, preference);
} catch {
// A storage error must not undo the visible change.
}
});
}
$('.menu-toggle[aria-controls]').each(function () {
const $toggle = $(this);
const $nav = $(document.getElementById(this.getAttribute('aria-controls')));