blob: cd57f8db88d66c8b9bf4c9d8c96d081543f575f8 (
plain) (
blame)
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
|
<script lang="text/javascript">
let host = "{{ .Host }}";
let jsonObj = "{{ .JSON }}";
let data = JSON.parse(jsonObj);
let tool = "curl";
let commandBox, widgetBox, compositePath, commandStr;
let path
let ipQuery, portQuery
let ipCheckBox, portCheckBox, portInput
let ip = ''
window.onload = (event) => {
commandBox = document.getElementById('command');
widgetBox = document.getElementById('output');
ipCheckBox = document.getElementById('ipCheckBox')
portCheckBox = document.getElementById('portCheckBox')
portInput = document.getElementById('portInput')
reset()
setcommdStr()
changeInput("ip")
}
function reset() {
path = '';
ipQuery = '';
portQuery = '';
}
function setcommdStr() {
compositePath = `${path}${portQuery}${ipQuery}`;
commandStr = `${tool} ${host}/${compositePath}`;
commandBox.innerText = commandStr;
}
function changeInput(input, button) {
path = input
portQuery = ""
portInput.classList.add("hidden");
switch(path) {
case "json":
output.innerText = jsonObj
break
case "country-iso":
output.innerText = data["country_iso"]
break
case "port":
portInput.classList.remove("hidden");
path = "port";
output.innerText = "{}";
let currentPort = document.querySelector("#portInput").value;
updatePort(currentPort);
break
case "ip":
output.innerText = data["ip"]
path = ""
break
default:
output.innerText = data[path]
}
setcommdStr();
// set button selected
if (button) {
allButtons = document.querySelectorAll(('button.selected'));
allButtons.forEach((btn) => {btn.classList.remove("selected")})
button.classList.add("selected");
}
}
function navigate(event) {
console.log("navigate", compositePath)
window.location = compositePath
}
function updatePort(value) {
port = value
portQuery = `/${port}`
setcommdStr()
}
function updateIP(value) {
ip = value
ipQuery = `?ip=${ip}`;
setcommdStr()
changeInput("ip", null)
}
</script>
|