For the record, this is what Copilot recommended.
document.addEventListener('DOMContentLoaded', () => {
const normalizePath = (path) => {
if (!path) return '';
const q = path.indexOf('?');
const h = path.indexOf('#');
const end = Math.min(q === -1 ? path.length : q, h === -1 ? path.length : h);
let p = path.slice(0, end).toLowerCase();