// The navbar when signed in: "admin" and "log out" in place of "log in". Loaded right after the // nav, before the rest of the page, so the signed-out links never show first. Pages are the same // for everyone; the readable kepr_editor cookie, set beside the session, carries the form token // that log out posts back, so this needs no request. { const token = /(?:^|;\s*)kepr_editor=([0-9a-f]{64})(?:;|$)/.exec(document.cookie)?.[1]; const link = document.querySelector('.nav-links a[href^="/sign-in"]'); if (token && link) { const admin = document.createElement("a"); admin.href = "/admin"; admin.textContent = "admin"; const form = document.createElement("form"); form.className = "nav-logout"; form.method = "post"; form.action = "/admin/sign-out"; const field = document.createElement("input"); field.type = "hidden"; field.name = "form"; field.value = token; const button = document.createElement("button"); button.type = "submit"; button.textContent = "log out"; form.append(field, button); link.replaceWith(admin, form); } }