Skip to content

A live bird collage card for your Home Assistant dashboard.

16.2 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>your birds</title>
<meta name="description" content="A live bird collage from your window.">
<link rel="icon" type="image/png" href="./favicon.png">
<link rel="apple-touch-icon" href="./favicon.png">
<!-- Follow the OS color scheme before first paint so dark mode doesn't
     flash light on load. (The HA card follows Home Assistant's theme instead.) -->
<script>try{if(matchMedia('(prefers-color-scheme: dark)').matches)document.documentElement.setAttribute('data-theme','dark');}catch(e){}</script>
<link rel="stylesheet" href="./styles.css">
<!-- Home Assistant build: BirdNET-Pi's admin surfaces (menu drawer,
     lock screen, admin overlay) have no backend here - BirdNET-Go owns
     its own settings UI. The elements stay in the DOM because apt.js
     wires listeners to them unconditionally; CSS just hides them. -->
<style>
  #menuBtn, #menu-dd, #returnToAtlas, #adminScreen { display: none !important; }
</style>
</head>
<body class="av-local">
<!-- Pill in the top-left slot, only visible on admin overlays
     (body.admin-on); CSS in styles.css hides it everywhere else.
     href="/" returns to the collage view via a full reload, which is
     fine for an off-hot-path control. -->
<a class="return-to-atlas" id="returnToAtlas" href="/" aria-label="back to collage">
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
    <path d="M10 3 L4 8 L10 13"/>
  </svg>
  collage
</a>
<header class="top">
  <div class="window-pick" id="winPick" role="tablist">
    <i class="seg-pill" aria-hidden="true"></i>
    <button data-h="1"   type="button" data-i18n="winpick.1h">1H</button>
    <button data-h="12"  type="button" data-i18n="winpick.12h">12H</button>
    <button data-h="today" type="button" data-i18n="winpick.today">TODAY</button>
    <button data-h="24"  type="button" aria-current="true" data-i18n="winpick.24h">24H</button>
    <button data-h="168" type="button" data-i18n="winpick.7d">7D</button>
    <button data-h="1000000" type="button" data-i18n="winpick.all">ALL</button>
  </div>
  <button class="menu-btn" id="menuBtn">menu</button>
</header>

<aside id="menu-dd" aria-hidden="true">
  <div id="dd-locked">
    <form class="lock-row" id="unlockForm">
      <input id="lockPass" type="password" placeholder="password" autocomplete="current-password">
      <button type="submit" aria-label="unlock">→</button>
    </form>
    <p class="lock-hint" id="lockHint">enter password to unlock tools.</p>
  </div>
  <nav class="menu-items" id="dd-items"></nav>
  <p class="built-by">built by <a href="https://theodore.net" target="_blank" rel="noopener">teddy</a> · <a href="https://github.com/Twarner491/AvianVisitors" target="_blank" rel="noopener">github</a></p>
</aside>

<main class="stage">
  <header class="static-head">
    <button type="button" class="pre" id="aboutLink" data-i18n="head.about">your birds</button>
    <h1 id="staticTitle">Heard Recently</h1>
  </header>
  <div class="views" id="views">

    <!-- ========== View 1 - Collage ========== -->
    <section class="view" id="v0" aria-label="Bird collage" data-i18n-aria="aria.collage">
      <div class="gcollage" id="collage"></div>
      <!-- Wall-display widgets (clock / weather), hidden unless enabled in
           config.js (wall: {...}) or via ?wall. Lives in a corner of the
           collage view itself; renderCollage() stamps its box into the
           packing grid so birds nest around the numerals like they do
           around each other. Sibling of #collage (not inside it) because
           renderCollage clears the collage's innerHTML on every pass. -->
      <div class="wall-widgets" id="wallWidgets" data-corner="bottom-right" hidden>
        <div class="ww-block" id="wwClock" hidden>
          <span class="ww-big" id="wwTime">--:--</span>
          <span class="ww-cap" id="wwDate"></span>
        </div>
        <i class="ww-rule" id="wwRule" hidden aria-hidden="true"></i>
        <div class="ww-block" id="wwWeather" hidden>
          <span class="ww-big" id="wwTemp"></span>
          <span class="ww-cap" id="wwCond"></span>
          <span class="ww-cap" id="wwSun"></span>
        </div>
      </div>
      <!-- Optional species-name strip (issue #69): every species in the
           current window as a line of names along the bottom of the
           collage, so a bird you don't recognise can be looked up by
           name - including any species the library has no artwork for
           yet (those are otherwise invisible in the collage). Hidden
           unless enabled in config (names: 'common' | 'scientific' |
           'both') or via ?names on the URL. renderCollage fills it and
           stamps its box into the packing grid, like the clock. -->
      <div class="name-strip" id="nameStrip" aria-label="Species heard" data-i18n-aria="names.aria" hidden></div>
    </section>

    <!-- ========== View 2 - Stats ========== -->
    <section class="view" id="v1" aria-label="Stats" data-i18n-aria="aria.stats">
      <div class="stats-grid">
        <div class="stats-timeline" id="statsTimeline">
          <!-- Activity heatmap. One row per species from the current
               time window (most-heard first), one cell per hour of day;
               a cell's tint deepens with its detection count and the
               number prints inside. Hard-rendered by renderActivity(). -->
        </div>
        <aside class="stats-side">
          <div class="grp">
            <h3 data-i18n="stats.byPeriod">By Period</h3>
            <small data-i18n="stats.byPeriodSub">detections, grouped by recency</small>
            <ol id="statsByPeriod"></ol>
            <!-- Only shown while >=1 auto-discovered HA microphone sensor
                 reads 'unavailable'/'unknown' - see renderMicOfflineNote(). -->
            <small id="statsMicNote" class="mic-note" hidden></small>
          </div>
          <div class="grp">
            <h3 data-i18n="stats.topSpecies">Top Species</h3>
            <small id="statsTopSpecCap">most-heard, current window</small>
            <ol id="statsTopSpec"></ol>
          </div>
          <div class="grp">
            <h3 data-i18n="stats.firstDetections">First Detections</h3>
            <small data-i18n="stats.firstDetectionsSub">newest additions to the life list</small>
            <ol id="statsFirstSeen"></ol>
          </div>
        </aside>
      </div>
    </section>

    <!-- ========== View 3 - Atlas ========== -->
    <section class="view" id="v2" aria-label="Atlas" data-i18n-aria="aria.atlas">
      <div class="atlas-controls">
        <div class="atlas-sort" id="atlasSort" role="tablist" aria-label="sort atlas" data-i18n-aria="atlas.sort">
          <i class="seg-pill" aria-hidden="true"></i>
          <button data-sort="count"  type="button" aria-current="true" aria-label="most heard" data-i18n-aria="atlas.mostHeard">
            <svg viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round">
              <path d="M2 12 V8"/><path d="M6 12 V5"/><path d="M10 12 V3"/>
            </svg>
            <span class="tip" data-i18n="atlas.mostHeard">most heard</span>
          </button>
          <button data-sort="recent" type="button" aria-label="most recent" data-i18n-aria="atlas.mostRecent">
            <svg viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
              <circle cx="7" cy="7" r="5.2"/><path d="M7 4 V7 L9.2 8.3"/>
            </svg>
            <span class="tip" data-i18n="atlas.mostRecent">most recent</span>
          </button>
          <button data-sort="alpha"  type="button" aria-label="alphabetical" data-i18n-aria="atlas.alphabetical">
            <svg viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round">
              <path d="M2.4 11.5 L4 4.5 L5.6 11.5"/><path d="M2.9 9.2 H5.1"/>
              <path d="M8.2 11.5 V4.5 H10.4 a1.3 1.3 0 0 1 0 2.6 H8.2"/><path d="M8.2 7.1 H10.6 a1.5 1.5 0 0 1 0 3 H8.2"/>
            </svg>
            <span class="tip" data-i18n="atlas.atoz">a → z</span>
          </button>
        </div>
      </div>
      <div class="atlas-grid" id="atlasGrid"></div>
    </section>

  </div>
</main>

<div id="detail-modal" aria-hidden="true" role="dialog" aria-labelledby="modalCommon">
  <div class="modal-backdrop" data-close="1"></div>
  <article class="modal-card">
    <button class="modal-close" type="button" aria-label="Close" data-i18n-aria="modal.close" data-close="1">×</button>
    <button class="modal-link" id="modalLink" type="button" aria-label="Copy link to this bird" data-i18n-aria="modal.copyLink">
      <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <path d="M6.6 9.4 L 9.4 6.6"/>
        <path d="M7.4 4.6 L 8.6 3.4 a 2.6 2.6 0 0 1 3.7 3.7 L 11.1 8.3"/>
        <path d="M8.6 11.4 L 7.4 12.6 a 2.6 2.6 0 0 1 -3.7 -3.7 L 4.9 7.7"/>
      </svg>
    </button>
    <a class="modal-wiki" id="modalWiki" target="_blank" rel="noopener" aria-label="Read more on Wikipedia" data-i18n-aria="modal.wikipedia">
      <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <circle cx="8" cy="8" r="5.6"/>
        <path d="M8 7.4 L 8 11"/>
        <circle cx="8" cy="5" r=".55" fill="currentColor" stroke="none"/>
      </svg>
    </a>
    <div class="modal-grid">
      <div class="modal-img">
        <img id="modalImg" src="" alt="" loading="eager">
        <div class="pose-toggle" id="modalPoseToggle" role="tablist" aria-label="Pose" data-i18n-aria="modal.pose">
          <i class="seg-pill" aria-hidden="true"></i>
          <button type="button" data-pose="1" aria-label="perched" data-i18n-aria="modal.perched">
            <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
              <path d="M3.5 6.5 C 4 4, 6 3, 8 4 C 10 3.6, 11.6 4.6, 12 6.5 L 11.5 8 C 11 9.6, 9.4 10.4, 8 10.4 C 6.4 10.4, 4.8 9.6, 4.2 8 Z"/>
              <circle cx="10.6" cy="5.7" r=".4" fill="currentColor"/>
              <path d="M12 6.2 L 13.6 5.8"/>
              <path d="M7.5 10.4 L 7.2 12.2"/>
              <path d="M8.6 10.4 L 8.9 12.2"/>
              <path d="M2 12.6 H 13"/>
            </svg>
            <span class="tip" data-i18n="modal.perched">perched</span>
          </button>
          <button type="button" data-pose="2" aria-label="in flight" data-i18n-aria="modal.inFlight">
            <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
              <path d="M1.5 8 Q 4.5 4, 7.5 7.5 Q 11 4, 14.5 8"/>
              <path d="M7.5 7.5 L 8 9.5"/>
              <circle cx="8.5" cy="7.2" r=".4" fill="currentColor"/>
              <path d="M8.6 7 L 10 6.6"/>
            </svg>
            <span class="tip" data-i18n="modal.inFlight">in flight</span>
          </button>
        </div>
      </div>
      <div class="modal-info">
        <h2 id="modalCommon">-</h2>
        <p class="sci" id="modalSci"></p>
        <div class="modal-meta">
          <span class="meta-item"><span class="k" data-i18n="modal.genus">genus</span><span class="v" id="modalGenus">-</span></span>
          <span class="meta-item"><span class="k" data-i18n="modal.rarity">rarity</span><span class="v" id="modalRarity">-</span></span>
        </div>
        <div class="modal-stats">
          <div><span class="n" id="modalAllTime">-</span><span class="lbl" data-i18n="modal.allTime">all time</span></div>
          <div id="modalWindowStat"><span class="n" id="modalWindow">-</span><span class="lbl" id="modalWindowLbl">window</span></div>
          <!-- Feeder-camera sightings; only shown when a visits stream is
               configured (visitsSensors / visits_sensors). -->
          <div id="modalVisitsStat" style="display:none"><span class="n" id="modalVisits">-</span><span class="lbl" id="modalVisitsLbl" data-i18n="modal.visits">visits</span></div>
          <div><span class="n" id="modalFirstSeen">-</span><span class="lbl" data-i18n="modal.firstHeard">first heard</span></div>
        </div>
        <p class="desc placeholder" id="modalDesc" data-i18n="modal.loadingDesc">Loading description...</p>
      </div>
    </div>
    <div class="modal-recordings">
      <div class="rec-head">
        <h3 data-i18n="modal.recordings">Recordings</h3>
        <button type="button" class="ref-call-btn" id="modalRefCall" hidden aria-label="play reference call" data-i18n-aria="modal.playRefCall">
          <svg viewBox="0 0 12 12" fill="currentColor"><path d="M3 2 L10 6 L3 10 Z"/></svg><span data-i18n="modal.refCall">reference call</span>
        </button>
        <span class="rec-count" id="modalRecCount"></span>
      </div>
      <p class="ref-credit" id="modalRefCredit" hidden></p>
      <ol id="modalRecordings">
        <li class="rec-empty" data-i18n="modal.loadingRecordings">Loading recordings...</li>
      </ol>
    </div>
  </article>
</div>

<div id="about-modal" aria-hidden="true" role="dialog" aria-labelledby="aboutTitle">
  <div class="modal-backdrop" data-close="1"></div>
  <div class="about-card" role="document">
    <button type="button" class="modal-close" data-close="1" aria-label="close" data-i18n-aria="modal.close">×</button>
    <p class="about-eyebrow" data-i18n="head.about">your birds</p>
    <h2 id="aboutTitle" data-i18n="about.title">The birds outside your window</h2>
    <p class="about-body" data-i18n-html="about.body">A tiny microphone identifies every passing bird with <a href="https://github.com/tphakala/birdnet-go" target="_blank" rel="noopener">BirdNET-Go</a>, built on Cornell's <a href="https://birdnet.cornell.edu/" target="_blank" rel="noopener">BirdNET</a>. Each species shows up as an illustration in the collage, sized by how often it's been heard. Confident detections perch; uncertain ones fly past.</p>
    <button type="button" class="about-explore" data-close="1" data-i18n="about.explore">explore the birds →</button>
    </div>
</div>

<nav class="slider" id="slider" aria-label="View" data-i18n-aria="view.aria">
  <i class="seg-pill" aria-hidden="true"></i>
  <button type="button" data-i="0" aria-current="true" data-i18n="view.collage">collage</button>
  <button type="button" data-i="1" data-i18n="view.stats">stats</button>
  <button type="button" data-i="2" data-i18n="view.atlas">atlas</button>
</nav>


<!-- AvianVisitors: empty admin-screen stub. The live JS expects this
     element to exist (openAdmin/closeAdmin call setAttribute on it).
     Menu items navigate to BirdNET-Pi's stock pages instead of opening
     in-app admin views, so this stays empty. -->
<section class="admin-screen" id="adminScreen" aria-hidden="true">
  <div class="admin-frame">
    <header class="admin-title"><h1 id="adminTitle"></h1></header>
    <div class="admin-body" id="adminBody"></div>
  </div>
</section>

<script src="./config.js"></script>
<script src="./masks.js"></script>
<!-- i18n bootstrap: load the English reference table plus the detected
     language (config override, else navigator.language), THEN the app.
     Dynamically injected <script src> runs even from file://; a missing
     language 404s harmlessly (onerror) and English still loads. Adding a
     new language needs a new i18n/<code>.js file and no edit here. -->
<script>
(function () {
  // Same normalization as the app's resolveLocale: lowercase, and try the
  // base subtag alongside any regional one ('pt-BR' -> pt-br.js + pt.js).
  var want = String((window.AV_CONFIG && AV_CONFIG.language)
    || navigator.language || 'en').toLowerCase();
  var base = want.split('-')[0];
  var files = ['en'];
  if (base && base !== 'en') files.push(base);
  if (want !== base && want !== 'en') files.push(want);
  var left = files.length;
  files.forEach(function (code) {
    var s = document.createElement('script');
    s.src = './i18n/' + code + '.js';
    s.onload = s.onerror = function () { if (--left === 0) loadApp(); };
    document.head.appendChild(s);
  });
  function loadApp() {
    var a = document.createElement('script'); a.src = './apt.js'; document.head.appendChild(a);
  }
})();
</script>
</body>
</html>