-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
64 lines (55 loc) · 1.62 KB
/
index.html
File metadata and controls
64 lines (55 loc) · 1.62 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scriptable Reflector</title>
</head>
<body>
<a href="" id="link" target="_blank" rel="noopener noreferrer">
<!-- https://www.freecodecamp.org/news/how-to-use-html-to-open-link-in-new-tab/ -->
<h1 id="text">No callback URI provided</h1>
</a>
</body>
<script>
let linkElement = document.getElementById("link");
if (location.hash.startsWith("#")) {
processURIFragment(location.hash);
}
function processURIFragment(fragment) {
let params = fragment.substring(1); // Take everything after '#'
let urlParams = new URLSearchParams(params);
for (let i of urlParams) {
console.log(i);
}
let uri = parseURIFromURLParams(urlParams);
if (urlParams.has("text")) setText(urlParams.get("text"));
else setText("Click here: " + uri);
}
function parseURIFromURLParams(urlParams) {
let uri;
if (urlParams.has("uri")) uri = urlParams.get("uri");
else if (urlParams.has("url")) uri = urlParams.get("url");
setLink(uri);
return uri;
}
function setLink(link) {
linkElement.setAttribute("href", link);
linkElement.addEventListener("click", () => {
// window.location = link;
// window.location.reload();
// event.preventDefault();
// window.open(link);
setTimeout(window.close, 10);
document.body.innerHTML = "<h1>You may now close this window</h1>"
}, {
passive: true
});
}
function setText(text) {
let textElement = document.getElementById("text");
textElement.innerHTML = text;
}
</script>
</html>