-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.html
35 lines (34 loc) · 1.27 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<script>
(() => {
const code = location.pathname.split("/").filter(i => i !== "").reverse()[0];
const base = "appZpbJa44TkE9Bew";
const read_only_api_key = "patOE5mEe6epcRHR5.e24fde5f62999bcd71306bebd6e2fe4533d7cfe36b15ce37718f84b6320fffd1"
let request = new XMLHttpRequest();
request.open("GET", `https://api.airtable.com/v0/${base}/Links?maxRecords=1&view=Grid%20view&filterByFormula=%7BCode%7D%3D'${code}'`, true);
request.setRequestHeader("Authorization", `Bearer ${read_only_api_key}`);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
const data = JSON.parse(this.response);
const url = data.records[0].fields.URL_Formatted;
if (url.substr(0,5) === "data:") {
// This is a data URL, to get around browser security restrictions,
// just make a link to it in the doc body to be clicked.
const clickable_url = decodeURIComponent(url.substr(15,url.length));
document.body.innerHTML = clickable_url;
}
else {
location.replace(url);
}
}
}
request.send();
})();
</script>
</head>
<body>
<p>...</p>
</body>
</html>