-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
106 lines (87 loc) · 3.34 KB
/
app.js
File metadata and controls
106 lines (87 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Squawk - Airline Ops Message Translator
// Modular Orchestrator
import { parseInputToBlocks } from './scanner.js';
import { parseSingleFlight } from './parser.js';
import { renderFlights } from './renderer.js';
import { copyToClipboard, copyImageToClipboard, saveAsPNG } from './exporter.js';
// ============================================================================
// DOM ELEMENTS
// ============================================================================
const inputText = document.getElementById('input-text');
const translateBtn = document.getElementById('translate-btn');
const tryExampleLink = document.getElementById('try-example');
const clearBtn = document.getElementById('clear-btn');
const copyBtn = document.getElementById('copy-btn');
const copyImageBtn = document.getElementById('copy-image-btn');
const saveBtn = document.getElementById('save-btn');
const outputSection = document.getElementById('output-section');
const cardBody = document.getElementById('card-body');
const outputCard = document.getElementById('output-card');
// State
let lastParsedFlights = [];
// ============================================================================
// EVENT LISTENERS
// ============================================================================
translateBtn.addEventListener('click', translate);
// Keyboard Shortcut: Ctrl+Enter or Cmd+Enter to translate
inputText.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
translate();
}
});
tryExampleLink.addEventListener('click', (e) => {
e.preventDefault();
inputText.value = `🛫 ICE602 🇮🇸
Date: 25Feb
A/C REG: TF-ICU (738)
Route: BIKF-CYYZ
STA 1745
ETA 1800
Pax: 150 (C12 Y138)
WCHR: 2R+1C
CARGO:
TOTAL: 450kgs
30pcs LIVE LOBSTERS
Remarks:
WAITING FOR PAX FROM 🛫 FI601.
PLEASE PRIORITIZE BGS.`;
translate();
});
clearBtn.addEventListener('click', (e) => {
e.preventDefault();
inputText.value = '';
outputSection.style.display = 'none';
lastParsedFlights = [];
copyBtn.disabled = true;
copyImageBtn.disabled = true;
saveBtn.disabled = true;
inputText.focus();
});
copyBtn.addEventListener('click', () => copyToClipboard(lastParsedFlights, copyBtn));
copyImageBtn.addEventListener('click', () => copyImageToClipboard(outputCard, copyImageBtn));
saveBtn.addEventListener('click', () => saveAsPNG(outputCard, lastParsedFlights, saveBtn));
// ============================================================================
// CORE WORKFLOW
// ============================================================================
function translate() {
const input = inputText.value.trim();
if (!input) return;
// 1. Scanner: Split raw text into flight blocks
const blocks = parseInputToBlocks(input);
if (blocks.length === 0) return;
// 2. Parser: Extract data from each block
const flights = blocks
.map(block => parseSingleFlight(block))
.filter(f => f && f.number);
if (flights.length === 0) return;
lastParsedFlights = flights;
// 3. Renderer: Display the results
renderFlights(flights, cardBody);
// UI Updates
outputSection.style.display = 'block';
copyBtn.disabled = false;
copyImageBtn.disabled = false;
saveBtn.disabled = false;
outputSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}