forked from GameChaos/gckzstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
120 lines (107 loc) · 2.53 KB
/
search.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<head>
<title>GCKZStats - Search</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="js/helpers.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<form action="./search.html" method="get">
<input name="search" type="text" id="search-input" placeholder="Map or player name">
<input type="submit" value="Search">
</form>
<h1>Search</h1>
<div id="search-results">
<h2>Results</h2>
<div style="padding:0px 1% 0px 1%; float: left">
<h3>Players</h3>
<table id="search-results-players" style="width:75%;float: left;">
<tr>
<th>Name</th>
<th>Steam ID</th>
</tr>
</table>
</div>
<div style="padding:0px 1% 0px 1%; float: left">
<h3>Maps</h3>
<table id="search-results-maps" style="width:75%;float: left;">
<tr>
<th>Maps</th>
</tr>
</table>
</div>
</div>
</body>
<script>
let g_SearchString = ""
OnPageOpened()
function OnPageOpened()
{
let params = GetParams(window.location.href)
if ("search" in params)
{
g_SearchString = params["search"]
}
if (g_SearchString === "")
{
RemoveAllChildrenFromNode(document.getElementById("search-results"))
}
else
{
UpdateSearchResults(g_SearchString)
}
}
function UpdateSearchResults(searchString)
{
//https://kztimerglobal.com/api/v1.0/players?name=gamechaos
RemoveAllChildrenFromNode(document.getElementById("search-results-players"))
$('#search-results-players').append('\
<tr>\
<th>Name</th>\
<th>Steam ID</th>\
</tr>'
)
$.getJSON("https://kztimerglobal.com/api/v1.0/players?name=" + searchString, function (data)
{
if (data.length == 0)
{
return
}
$.each(data, function (index, value)
{
$('#search-results-players').append('\
<tr>\
<td>' + CreatePlayerProfileLink(data[index].steam_id, data[index].name) + '</td>\
<td>' + data[index].steam_id + '</td>\
</tr>')
})
})
// maps
//https://kztimerglobal.com/api/v2.0/maps?is_validated=true
RemoveAllChildrenFromNode(document.getElementById("search-results-maps"))
$('#search-results-maps').append('\
<tr>\
<th>Maps</th>\
</tr>'
)
$.getJSON("https://kztimerglobal.com/api/v2.0/maps?is_validated=true", function (data)
{
if (data.length == 0)
{
return
}
$.each(data, function (index, value)
{
if (data[index].name.indexOf(searchString) !== -1)
{
$('#search-results-maps').append('\
<tr>\
<td>' + data[index].name + '</td>\
</tr>')
}
})
})
}
</script>
</html>