-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchResult.html
156 lines (143 loc) · 6.25 KB
/
searchResult.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="author" content="Hugonez" />
<meta name="description" content="Venha ver as ultimas novidades e já que está aqui, aproveita e da uma verificada no seu personagem">
<meta name="theme-color" content="#000000">
<title>Pesquisa de Personagem
</title>
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Font Awesome icons (free version)-->
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
<!-- Google fonts-->
<link href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
</head>
<meta charset="UTF-8">
<style>
/* Add your custom styles here */
.masthead {
background-image: url('assets/img/search-bg.webp');
background-size: cover;
background-position: center;
color: white;
text-align: center;
padding: 100px 0;
}
.masthead h1 {
font-size: 2rem;
margin-bottom: 20px;
}
.character-image {
max-width: 100%;
height: auto;
}
</style>
<title>Pesquisa na API do xivapi.com</title>
<!-- Navigation-->
<nav class="navbar navbar-expand-lg navbar-light" id="mainNav">
<div class="container px-4 px-lg-5">
<a class="navbar-brand" href="index.html">Lodestone</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto py-4 py-lg-0">
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="index.html">Início</a></li>
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="about-me.html">Sobre Mim</a></li>
</ul>
</div>
</div>
</nav>
<header class="masthead" style="background-image: url('assets/img/search-bg.webp')">
</header>
<style>
#searchForm {
margin: 20px auto;
}
#searchForm button {
background-color: #007BFF;
color: #fff;
padding: 10px 20px;
border: none;
cursor: pointer;
}
#searchResults {
margin-top: 20px;
text-align: center; /* Centralize o texto dos botões */
}
#searchResults button {
background-color: #f0f0f0;
border: 1px solid #ccc;
padding: 10px 20px;
margin: 5px;
cursor: pointer;
width: calc(30% - 10px);
}
@media (max-width: 767px) {
#searchResults button {
display: block;
width: 100%;
white-space: normal;
}
}
</style>
<body>
<div class="container position-relative px-4 px-lg-5">
<h1>Pesquise seu Personagem</h1>
<form id="searchForm">
<label for="characterName">Nome do Personagem:</label>
<input type="text" id="characterName" required>
<button type="submit">Pesquisar</button>
</form>
<div id="searchResults">
<!-- Os resultados da pesquisa serão exibidos aqui -->
</div>
<script>
document.getElementById('searchForm').addEventListener('submit', function (event) {
event.preventDefault();
const characterName = document.getElementById('characterName').value;
searchCharacter(characterName);
});
function searchCharacter(characterName) {
// URL da API do xivapi.com para pesquisar personagens pelo nome
const apiUrl = `https://xivapi.com/character/search?name=${encodeURIComponent(characterName)}`;
// Faça a solicitação GET à API usando a função fetch
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// Manipule os resultados da pesquisa aqui
displaySearchResults(data.Results);
})
.catch(error => {
console.error('Erro ao realizar a pesquisa:', error);
});
}
function displaySearchResults(results) {
const searchResultsDiv = document.getElementById('searchResults');
if (results.length === 0) {
searchResultsDiv.innerHTML = 'Nenhum resultado encontrado.';
return;
}
let html = '';
results.forEach(result => {
html += `<button onclick="showCharacterDetails(${result.ID})">${result.Name}<br>Home World: ${result.Server}</button>`;
});
searchResultsDiv.innerHTML = html;
}
function showCharacterDetails(characterID) {
// Redirecione para a página de detalhes do personagem com o ID como parâmetro de consulta
window.location.href = `characterDetails.html?id=${characterID}`;
}
</script>
<!-- Bootstrap core JS-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS-->
<script src="js/scripts.js"></script>
</body>
</html>