-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
80 lines (74 loc) · 2.38 KB
/
index.html
File metadata and controls
80 lines (74 loc) · 2.38 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tlink</title>
<meta name="manifest.type" content="browser_action" />
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
html,
body,
#root {
height: 100%;
}
</style>
</head>
<body>
<div id="root">
<iframe
id="tlink-iframe"
class="relative size-full"
style="height: 100%; width: 100%; border: none"
allow="clipboard-write"
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals"></iframe>
</div>
<script>
;(function () {
const iframe = document.getElementById("tlink-iframe")
async function handleMessage(event) {
// We only proxy messages that originate from the child iframe or parent window
// This prevents postMessage listeners of other tlink iframes on the same page causing duplicate requests to the background service
if (
event.source !== iframe.contentWindow &&
event.source !== window.parent.window
) {
return
}
if (event.data.type === "TLINK_API_REQUEST") {
// forward ts viewer API request out
window.parent.postMessage(
{ source: "TLINK_API_REQUEST", data: event.data.data },
"*"
)
} else if (event.data.source === "TLINK_API_RESPONSE") {
// forward ts viewer API response in
iframe?.contentWindow?.postMessage(event.data, "*")
} else if (event.data.source === "tlink-rpc-resp") {
// forward response to ts viewer
iframe?.contentWindow?.postMessage(event.data.data, "*")
} else {
// forward ts viewer message out
window.parent.postMessage(
{ source: "tlink", data: event.data },
"*"
)
}
}
function init() {
const url = new URL(window.location.href)
const dAppUrl = url.searchParams.get("url")
if (dAppUrl) {
iframe.src = dAppUrl
}
window.addEventListener("message", handleMessage)
}
init()
})()
</script>
</body>
</html>