{
  "format": "tdplugin/1",
  "manifest": {
    "id": "tangodown.adsbdb-aircraft",
    "name": "Luftfahrzeug & Flugroute (adsbdb)",
    "name_en": "Aircraft & flight route (adsbdb)",
    "version": "1.0",
    "description": "Kennzeichen (z.B. D-AIMA) oder Mode-S-Code eines Luftfahrzeugs → Hersteller, Typ, Halter/Betreiber, Registerland und Foto-Link; der Halter wird als verknüpfte Firma angelegt. Ein Flug-Rufzeichen (z.B. DLH400) ergibt Fluggesellschaft sowie Start- und Zielflughafen (mit Kartenposition). Ohne Schlüssel; gesendet wird nur Kennzeichen, Code bzw. Rufzeichen an api.adsbdb.com.",
    "description_en": "Registration (e.g. D-AIMA) or Mode-S code of an aircraft → manufacturer, type, owner/operator, country of registration and photo link; the owner is created as a linked company. A flight callsign (e.g. DLH400) gives the airline plus departure and arrival airport (with map position). No key needed; only the registration, code or callsign is sent to api.adsbdb.com.",
    "author": "TangoDown",
    "inputs": [
      "vehicle"
    ],
    "kind": "js",
    "main": "main.js",
    "timeout": 60,
    "icon": "✈",
    "icon_svg": "icon.svg",
    "permissions": {
      "net": [
        "api.adsbdb.com"
      ]
    }
  },
  "files": {
    "LICENSE.txt": "MIT License\n\nCopyright (c) 2026 Lars Stahl (TangoDown)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
    "README.md": "# Luftfahrzeug & Flugroute (adsbdb)\n\n*English below.*\n\nRechtsklick auf ein **Fahrzeug** → **Plugins & Konnektoren** → **Luftfahrzeug & Flugroute (adsbdb)**.\n\nDas Plugin fragt **adsbdb**, eine offene Datenbank zu Luftfahrzeugen und Flugrouten (gespeist aus öffentlich verfügbaren Luftfahrt-Daten).\n\n## Was es tut\n\n- **Kennzeichen** (z.B. `D-AIMA`, auch ohne Bindestrich) oder **Mode-S-Code** (ICAO-24-Bit-Adresse, z.B. `3C65A1`, wie ihn ADS-B-Empfänger und Flugverfolgungsseiten zeigen):\n  - **trägt in das Fahrzeug ein** (nur leere Felder): Kennzeichen, Registerland, Hersteller (Marke), Typ (Modell), Mode-S, ICAO-Typcode, Halter und einen Foto-Link,\n  - **legt den Halter/Betreiber als verknüpfte Firma an**.\n- **Flug-Rufzeichen** (z.B. `DLH400`): **Fluggesellschaft** (Firma) sowie **Start- und Zielflughafen** als Orte mit Kartenposition, verknüpft mit dem Element. Das ist die **übliche Route** zu diesem Rufzeichen – keine Live-Position.\n- **Notiz** mit allen Angaben, Quelle und Abrufdatum.\n\nGesucht wird in dieser Reihenfolge: Felder „kennzeichen“, „mode-s“, „rufzeichen“ am Element, dann die Bezeichnung. Ist als **Fahrzeugart** ein Straßenfahrzeug eingetragen (Pkw, Lkw, Motorrad …), fragt das Plugin **nichts** ab – so gehen keine Auto-Kennzeichen an adsbdb.\n\nMeldung, Notiz und Verknüpfungen folgen der Oberflächensprache von TangoDown (Deutsch oder Englisch).\n\n## Rechte und Datenschutz\n\n- **Netz:** nur `api.adsbdb.com` (HTTPS, über das in TangoDown eingestellte Routing). Gesendet wird nur **Kennzeichen, Mode-S-Code bzw. Rufzeichen** – keine anderen Falldaten.\n- **Keine Schlüssel, keine Dateien.** Je Lauf 1–3 Abfragen.\n- Die Angaben können veraltet sein (Halterwechsel, neue Lackierung, geänderte Routen). **Amtlich** ist nur das Luftfahrzeugregister des jeweiligen Landes. Eine Route zum Rufzeichen belegt nicht, dass ein bestimmtes Flugzeug sie an einem bestimmten Tag geflogen ist.\n- Dieses Plugin ist kein Angebot von adsbdb und wird von adsbdb weder unterstützt noch autorisiert.\n\n## Ausprobieren\n\nIn TangoDown unter **Plugins** → „▶ Ausprobieren“ z.B. `D-AIMA`, `3C65A1` oder `DLH400` eingeben.\n\n## Lizenz\n\nMIT – siehe `LICENSE.txt`. Verbesserungen sind willkommen.\n\n---\n\n# Aircraft & flight route (adsbdb)\n\nRight-click a **vehicle** → **Plugins & connectors** → **Aircraft & flight route (adsbdb)**.\n\nThe plugin queries **adsbdb**, an open database of aircraft and flight routes (fed from publicly available aviation data).\n\n## What it does\n\n- **Registration** (e.g. `D-AIMA`, also without hyphen) or **Mode-S code** (ICAO 24-bit address, e.g. `3C65A1`, as shown by ADS-B receivers and flight-tracking sites):\n  - **fills in the vehicle** (empty fields only): registration, country of registration, manufacturer (make), type (model), Mode-S, ICAO type code, owner and a photo link,\n  - **creates the owner/operator as a linked company**.\n- **Flight callsign** (e.g. `DLH400`): the **airline** (company) plus **departure and arrival airport** as places with map position, linked to the element. This is the **usual route** for this callsign – not a live position.\n- **Note** with all details, source and retrieval date.\n\nSearch order: fields \"kennzeichen\", \"mode-s\", \"rufzeichen\" on the element, then the label. If a road vehicle is set as **vehicle type** (car, truck, motorcycle …), the plugin queries **nothing** – so no car number plates are sent to adsbdb.\n\nMessages, notes and link labels follow TangoDown's interface language (German or English).\n\n## Permissions and privacy\n\n- **Network:** only `api.adsbdb.com` (HTTPS, through the routing set in TangoDown). Only the **registration, Mode-S code or callsign** is sent – no other case data.\n- **No keys, no files.** 1–3 requests per run.\n- The data may be outdated (change of owner, new livery, changed routes). Only the aircraft register of the respective country is **official**. A route for a callsign does not prove that a particular aircraft flew it on a particular day.\n- This plugin is not an adsbdb service and is not endorsed or authorised by adsbdb.\n\n## License\n\nMIT – see `LICENSE.txt`. Improvements are welcome.\n",
    "icon.svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">\n  <rect x=\"0.5\" y=\"0.5\" width=\"23\" height=\"23\" rx=\"5\" fill=\"#0b2545\"/>\n  <path d=\"M4 18.5c4-1.2 11-1.2 16 0\" fill=\"none\" stroke=\"#38bdf8\" stroke-width=\"1.2\" stroke-dasharray=\"1.6 1.6\" stroke-linecap=\"round\"/>\n  <path d=\"M20 9.6 13.2 8l-3.4-4.3H8.4l1.5 4.1-4 .1-1.6-1.8H3.2l.9 3 .1.2-.9 3h1.1l1.6-1.8 4 .1-1.5 4.1h1.4l3.4-4.3 6.8-1.6a.8.8 0 0 0 0-1.5z\" fill=\"#a3e635\"/>\n</svg>\n",
    "main.js": "// Luftfahrzeug & Flugroute (adsbdb) – Plugin für TangoDown. Lizenz: MIT (siehe LICENSE.txt).\n// Fragt ausschließlich die öffentliche adsbdb-API (api.adsbdb.com, ohne Schlüssel). Läuft in der TangoDown-Sandbox:\n// Netz nur über td.fetch, kein Dateizugriff, keine anderen Falldaten. Gesendet wird nur Kennzeichen, Mode-S-Code bzw. Rufzeichen.\n\nconst API = 'https://api.adsbdb.com/v0/'\n\nlet EN = false\nconst T = (de, en) => (EN ? en : de)\n\n/** Eingabe einordnen: Mode-S (ICAO 24 Bit, 6 Hex-Zeichen), Rufzeichen (3 Buchstaben + Nummer) oder Kennzeichen */\nfunction classify(raw) {\n  const v = String(raw || '').trim().toUpperCase().replace(/\\s+/g, '')\n  if (!v) return null\n  if (/^[0-9A-F]{6}$/.test(v) && /\\d/.test(v)) return { kind: 'modes', v }\n  if (/^[A-Z]{3}\\d{1,4}[A-Z]{0,2}$/.test(v)) return { kind: 'callsign', v }\n  // Kennzeichen: Länderpräfix + Kennung, z.B. D-AIMA, N123AB, G-EZAA, HB-JNA, 9H-ABC\n  if (/^[A-Z0-9]{1,2}-?[A-Z0-9]{1,5}$/.test(v) && /[A-Z]/.test(v)) return { kind: 'reg', v }\n  return null\n}\n\nasync function get(path) {\n  const r = await td.fetch(API + path, { headers: { Accept: 'application/json' } })\n  if (r.status === 404) return null\n  if (r.status === 429) throw new Error(T('adsbdb: zu viele Abfragen – bitte kurz warten', 'adsbdb: too many requests – please wait a moment'))\n  if (!r.ok) throw new Error(T('adsbdb antwortet HTTP ', 'adsbdb responds HTTP ') + r.status)\n  const j = r.json()\n  return j && typeof j.response === 'object' ? j.response : null\n}\n\nconst COUNTRY_DE = { Germany: 'Deutschland', Austria: 'Österreich', Switzerland: 'Schweiz', 'United States': 'USA', 'United Kingdom': 'Vereinigtes Königreich', France: 'Frankreich', Netherlands: 'Niederlande', Italy: 'Italien', Spain: 'Spanien', Poland: 'Polen', Ireland: 'Irland', Belgium: 'Belgien', Denmark: 'Dänemark', Sweden: 'Schweden', Norway: 'Norwegen', Turkey: 'Türkei', Russia: 'Russland', Luxembourg: 'Luxemburg', Malta: 'Malta', 'United Arab Emirates': 'Vereinigte Arabische Emirate', Qatar: 'Katar', Canada: 'Kanada', China: 'China', Japan: 'Japan' }\nconst land = (n) => (EN ? n : COUNTRY_DE[n] || n) || ''\n\nfunction aircraftResult(a, input, via) {\n  const props = input.props || {}\n  const reg = a.registration || ''\n  const self = {\n    kennzeichen: reg, land: land(a.registered_owner_country_name), marke: a.manufacturer || '', modell: a.type || '',\n    'mode-s': a.mode_s || '', 'icao-typ': a.icao_type || '', halter: a.registered_owner || '', fotoseite: a.url_photo || ''\n  }\n  for (const k of Object.keys(self)) if (!self[k] || String(props[k] || '') === self[k]) delete self[k]\n  // Das angeklickte Element ist das Luftfahrzeug – nur Felder ergänzen, kein zweites Element anlegen\n  const label = String(input.label || '').trim()\n  const entities = [{ type: 'vehicle', label: label || reg, props: self }]\n  if (a.registered_owner) entities.push({ type: 'company', label: a.registered_owner, props: { ...(a.registered_owner_operator_flag_code ? { 'icao-code': a.registered_owner_operator_flag_code } : {}) }, link: T('Halter / Betreiber laut adsbdb', 'owner / operator according to adsbdb') })\n  const note = [\n    `${T('Luftfahrzeug (adsbdb)', 'Aircraft (adsbdb)')}: ${reg || '?'} · Mode-S ${a.mode_s || '?'}${via ? ' · ' + T('gefunden über', 'found via') + ' ' + via : ''}`,\n    `${T('Typ', 'Type')}: ${[a.manufacturer, a.type].filter(Boolean).join(' ')}${a.icao_type ? ' (ICAO ' + a.icao_type + ')' : ''}`,\n    a.registered_owner ? `${T('Halter / Betreiber', 'Owner / operator')}: ${a.registered_owner}${a.registered_owner_operator_flag_code ? ' (' + a.registered_owner_operator_flag_code + ')' : ''}` : '',\n    a.registered_owner_country_name ? `${T('Registerland', 'Country of registration')}: ${land(a.registered_owner_country_name)}` : '',\n    a.url_photo ? `${T('Foto', 'Photo')}: ${a.url_photo}` : ''\n  ]\n  return { entities, note, head: `${reg || a.mode_s}: ${[a.manufacturer, a.type].filter(Boolean).join(' ')}${a.registered_owner ? ' · ' + a.registered_owner : ''}` }\n}\n\nfunction airportLabel(p) { return `${p.name}${p.iata_code ? ' (' + p.iata_code + ')' : p.icao_code ? ' (' + p.icao_code + ')' : ''}` }\nfunction airport(p, link) {\n  const geo = Number.isFinite(Number(p.latitude)) && Number.isFinite(Number(p.longitude)) ? [Number(p.latitude), Number(p.longitude)] : undefined\n  return { type: 'location', label: airportLabel(p), props: { anschrift: [p.municipality, land(p.country_name)].filter(Boolean).join(', '), art: 'Sonstiges', ...(p.icao_code ? { icao: p.icao_code } : {}), ...(p.iata_code ? { iata: p.iata_code } : {}) }, ...(geo ? { geo } : {}), link }\n}\n\nfunction routeResult(f, input) {\n  const entities = []\n  const label = String(input.label || '').trim()\n  if (f.airline && f.airline.name) entities.push({ type: 'company', label: f.airline.name, props: { ...(f.airline.icao ? { 'icao-code': f.airline.icao } : {}), ...(f.airline.iata ? { 'iata-code': f.airline.iata } : {}), ...(f.airline.callsign ? { funkrufname: f.airline.callsign } : {}) }, link: T('Fluggesellschaft (Rufzeichen)', 'airline (callsign)') })\n  if (f.origin) entities.push(airport(f.origin, T('Startflughafen (übliche Route)', 'departure airport (usual route)')))\n  if (f.destination) entities.push(airport(f.destination, T('Zielflughafen (übliche Route)', 'arrival airport (usual route)')))\n  const route = `${f.origin ? airportLabel(f.origin) : '?'} → ${f.destination ? airportLabel(f.destination) : '?'}`\n  const note = [\n    `${T('Flugroute zum Rufzeichen', 'Flight route for callsign')} ${f.callsign}${f.callsign_iata ? ' / ' + f.callsign_iata : ''} (adsbdb)`,\n    f.airline && f.airline.name ? `${T('Fluggesellschaft', 'Airline')}: ${f.airline.name}${f.airline.icao ? ' (' + f.airline.icao + ')' : ''}${f.airline.country ? ' · ' + land(f.airline.country) : ''}` : '',\n    `${T('Route', 'Route')}: ${route}`,\n    T('Hinweis: Das ist die übliche (geplante) Route zu diesem Rufzeichen – keine Live-Position und kein Beleg, dass ein bestimmtes Flugzeug sie an einem bestimmten Tag geflogen ist.', 'Note: this is the usual (scheduled) route for this callsign – not a live position and no proof that a particular aircraft flew it on a particular day.')\n  ]\n  // Rufzeichen-Element selbst: nur die Route eintragen, nicht als Fahrzeug umdeuten\n  const self = { route }\n  if (label) entities.unshift({ type: input.type || 'vehicle', label, props: self })\n  return { entities, note, head: `${f.callsign}: ${route}` }\n}\n\nasync function transform(input) {\n  EN = input.lang === 'en'\n  const props = input.props || {}\n  const label = String(input.label || '').trim()\n  const value = String(input.value || '').trim()\n  // Ausdrücklich als Straßen- oder Wasserfahrzeug eingetragen: nichts senden (kein Auto-Kennzeichen an adsbdb)\n  const art = String(props.art || '').trim()\n  if (art && /^(pkw|kleintransporter|lkw|bus|motorrad|wohnmobil|anhänger|car|van|truck|motorcycle|trailer)$/i.test(art)) return { entities: [], message: T(`Fahrzeugart „${art}“ – kein Luftfahrzeug, nichts abgefragt`, `Vehicle type \"${art}\" – not an aircraft, nothing queried`) }\n  // Feld am Element zuerst (Kennzeichen, Mode-S, Rufzeichen), sonst Bezeichnung bzw. Wert\n  const cands = [props.kennzeichen, props['mode-s'], props.modes, props.icao24, props.rufzeichen, props.callsign, label, value].map(classify).filter(Boolean)\n  const c = cands[0]\n  if (!c) return { entities: [], message: T('Kein Luftfahrzeug-Kennzeichen, Mode-S-Code oder Rufzeichen erkannt (z.B. D-AIMA, 3C65A1, DLH400)', 'No aircraft registration, Mode-S code or callsign recognised (e.g. D-AIMA, 3C65A1, DLH400)') }\n\n  let out = null\n  if (c.kind === 'callsign') {\n    const r = await get('callsign/' + encodeURIComponent(c.v))\n    if (r && r.flightroute) out = routeResult(r.flightroute, input)\n  }\n  if (!out) {\n    // Kennzeichen mit Bindestrich wie im Register (D-AIMA); ohne Bindestrich erst so, dann mit Bindestrich nach 1 bzw. 2 Zeichen\n    const tries = c.kind === 'reg' && !c.v.includes('-') ? [c.v, c.v.slice(0, 1) + '-' + c.v.slice(1), c.v.slice(0, 2) + '-' + c.v.slice(2)] : [c.v]\n    for (const t of tries) {\n      const r = await get('aircraft/' + encodeURIComponent(t))\n      if (r && r.aircraft) { out = aircraftResult(r.aircraft, input, c.kind === 'modes' ? 'Mode-S ' + c.v : ''); break }\n    }\n  }\n  // „CFE123“ ist sowohl gültiger Mode-S-Code als auch Rufzeichen – ohne Flugzeug-Treffer noch als Rufzeichen versuchen\n  if (!out && c.kind === 'modes' && /^[A-Z]{3}\\d{1,4}$/.test(c.v)) {\n    const r = await get('callsign/' + encodeURIComponent(c.v))\n    if (r && r.flightroute) out = routeResult(r.flightroute, input)\n  }\n  if (!out) return { entities: [], message: T(`adsbdb kennt „${c.v}“ nicht – weder als Luftfahrzeug noch als Rufzeichen`, `adsbdb does not know \"${c.v}\" – neither as an aircraft nor as a callsign`) }\n\n  const note = [\n    ...out.note,\n    `${T('Quelle', 'Source')}: https://www.adsbdb.com (${T('Abruf', 'retrieved')} ${new Date().toISOString().slice(0, 10)})`,\n    T('Hinweis: adsbdb führt öffentlich verfügbare Luftfahrt-Daten zusammen; Angaben (z.B. Halter, Betreiber, Route) können veraltet sein – amtlich ist nur das Luftfahrzeugregister des jeweiligen Landes. Dieses Plugin ist kein Angebot von adsbdb.', 'Note: adsbdb combines publicly available aviation data; details (e.g. owner, operator, route) may be outdated – only the aircraft register of the respective country is official. This plugin is not a service of adsbdb.')\n  ].filter(Boolean).join('\\n')\n  return { entities: out.entities, note, message: out.head }\n}\n",
    "pruefung.json": "{\n  \"format\": \"tangodown-pruefung/1\",\n  \"checkVersion\": 1,\n  \"id\": \"tangodown.adsbdb-aircraft\",\n  \"version\": \"1.0\",\n  \"at\": \"2026-11-25T11:57:09.111Z\",\n  \"rights\": {\n    \"kind\": \"js\",\n    \"net\": [\n      \"api.adsbdb.com\"\n    ],\n    \"secrets\": [],\n    \"files\": false\n  },\n  \"counts\": {\n    \"warn\": 0,\n    \"info\": 0\n  },\n  \"findings\": []\n}"
  }
}