gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0516b4cc0516b4ccmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre0516b4cc/login.js

2.6 KB

  1. // login.js — the small bridge between ident's <ident-selector> and the notes shell (components/main.hl; the same
  2. // as gitoria's login.js). Plain JS because hl:web cannot listen to a custom DOM event: `ident-login`
  3. // (event.detail.code, the one-time code) goes into the hidden input #identcode, whose `change` the shell handles
  4. // (→ face notesLogin, server-side exchange). The shell keeps the selector element's class at `in` / `out`; it is
  5. // mirrored here into the selector's `loggedIn` (false = back to "choose ident").
  6. // BACK TO THE PAGE: the "Log in with ident" click gets `?next=<this page>` in its return URL (project.hl safePath).
  7. // RUNS ONCE PER DOCUMENT: hl:web re-creates the header and its <script>s when the login state flips, the
  8. // selector element is then a NEW one; listeners sit on `document`, the CURRENT #selector is looked up each
  9. // time, and a one-time code is handed to the shell at most once.
  10. (() => {
  11. if (window.__notesLogin) { window.__notesLogin.sync(); return; }
  12. const sync = () => {
  13. const sel = document.getElementById('selector');
  14. // not upgraded yet: a property set now would shadow the element's own accessor
  15. if (!sel || !window.customElements || !customElements.get('ident-selector')) return;
  16. const want = sel.classList.contains('in');
  17. if (sel.loggedIn !== want) sel.loggedIn = want;
  18. };
  19. new MutationObserver(sync).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['class'] });
  20. if (window.customElements) customElements.whenDefined('ident-selector').then(sync);
  21. const handed = new Set();
  22. document.addEventListener('ident-login', (e) => {
  23. const code = e.detail && e.detail.code;
  24. const input = document.getElementById('identcode');
  25. if (!input || !code || handed.has(code)) return; // a one-time code is exchanged once
  26. handed.add(code);
  27. input.value = code;
  28. input.dispatchEvent(new Event('change', { bubbles: true }));
  29. });
  30. const withNext = (a) => {
  31. try {
  32. const u = new URL(a.href);
  33. const ret = new URL(u.searchParams.get('return'));
  34. const here = location.pathname + location.search;
  35. ret.search = '';
  36. if (here !== '/' && here.length <= 500) ret.searchParams.set('next', here);
  37. u.searchParams.set('return', ret.href);
  38. a.href = u.href;
  39. } catch (err) { /* keep the server's href: the login still works, it returns to / */ }
  40. };
  41. const onButton = (e) => {
  42. const a = e.target && e.target.closest && e.target.closest('#loginbutton');
  43. if (a) withNext(a);
  44. };
  45. for (const t of ['click', 'auxclick', 'contextmenu']) document.addEventListener(t, onButton, true);
  46. window.__notesLogin = { sync };
  47. })();

Branches

Latest commits

  • 0516b4ccmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
  • 38cc11ecmd-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
  • 3e7e79f5reports/H1-hydrate.mdmre
  • d98775e8tests/browser.mjs: wait for hydration before the clicks after a goto('/') (tables new note, phone sidebar)mre
  • 1f3198b6tests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
  • 39cf9fdfre-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • db07aa84tests: short-id-switch ports from env (NOTES_SWITCH_IDENT_PORT/_PORT), defaults unchangedmre
  • ef9f9feere-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 5485467cdocker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 86ea4a85deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • edeab20fnotes mission 015: mission, report, LOG, STATUSmre
  • 542a0383notes mission 015: e2e-chrome E2E_HOST (own cookie jar in the shared Chrome)mre
  • 8b30f510notes mission 015: main-menu from layouts 0bcc629, current = true kept (route marks only /), server-HTML marker checksmre
  • 84b574c4notes mission 015: re-vendor plugins from hybriel f9614007 (incl. web, #117)mre
  • 447da53dnotes mission 014: report — remaining gates and lisbeth E2E proofmre
  • fd9f92c3notes mission 014: report (partial), LOG, STATUSmre
  • b2501360notes mission 014: open() sets asking=false before flush(0) (hybriel#196)mre
  • 9414ce59notes mission 014: merge theme 76f99f6, components 3794c59, strict single-press openAsk (fails on old open())mre
  • c08c655anotes 013: theme re-copied from layouts 76f99f6 (menu marks the current page), current = true on the menu item, e2e marker checks, reportmre
  • 21c8f65dnotes mission 012: STATUSmre