gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit31b758aa31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre31b758aa/login.js

2.7 KB

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

Branches

Latest commits

  • 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre
  • 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
  • 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre
  • 3251488atracker#7: /my/shows (followed shows, newest follow first, poster, title, last watched SxxEyy); gate can take screenshots (TRACKER_GATE_SHOTS)mre
  • 44b7d9f9tracker#6: /schedule — upcoming episodes of followed shows, soonest firstmre
  • 91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre
  • a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
  • 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre
  • 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
  • 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
  • 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
  • 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre