-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewNTSB.html
More file actions
51 lines (46 loc) · 1.69 KB
/
Copy pathviewNTSB.html
File metadata and controls
51 lines (46 loc) · 1.69 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>NTSB PDF Viewer</title>
<style>
html, body { margin: 0; height: 100%; }
iframe { width: 100%; height: 100%; border: none; }
</style>
</head>
<body>
<script>
async function getPDFBlobFromURL(url) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error("Fetch failed with status " + response.status);
const arrayBuffer = await response.arrayBuffer();
const bytes = new Uint8Array(arrayBuffer);
// Check first few bytes for %PDF
const signature = String.fromCharCode(...bytes.slice(0, 4));
if (signature !== "%PDF") throw new Error("File does not appear to be a valid PDF");
const blob = new Blob([arrayBuffer], { type: "application/pdf" });
const blobURL = URL.createObjectURL(blob);
const iframe = document.createElement("iframe");
iframe.src = blobURL;
document.body.appendChild(iframe);
} catch (error) {
document.body.innerHTML = "<h2>Error loading NTSB PDF:</h2><pre>" + error + "</pre>";
}
}
const params = new URLSearchParams(window.location.search);
const ntsbNum = params.get("num");
if (ntsbNum) {
const rawURL = `https://data.ntsb.gov/carol-repgen/api/Aviation/ReportMain/GenerateNewestReport/${ntsbNum}/pdf`;
const proxiedURL = `https://corsproxy.io/?${rawURL}`;
getPDFBlobFromURL(proxiedURL);
} else {
document.body.innerHTML = `
<h2>Usage:</h2>
<p>Add <code>?num=200482</code> to the URL to load an NTSB report.</p>
<p>Example: <code>viewNTSB.html?num=200482</code></p>
`;
}
</script>
</body>
</html>