-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
148 lines (140 loc) · 5.57 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PoliPicker</title>
<link href="main.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="navbar.css">
<link rel="stylesheet" href="carousel.css">
<style>
/* Additional styles for the Google search section */
.google-search-container {
margin: 20px;
text-align: center;
}
/*.google-search-bar {
margin-bottom: 10px;
}*/
/* Style for the results container */
.results-box {
margin-top: 20px;
padding: 15px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
max-width: 800px; /* Set max width */
margin-left: auto;
margin-right: auto;
text-align: left;
}
.result-item {
margin-bottom: 15px;
}
.result-item a {
font-weight: bold;
color: #1a0dab;
text-decoration: none;
}
.result-item p {
margin: 5px 0;
color: #545454;
}
/* Title style */
.results-title {
font-size: 1.5em;
margin-bottom: 10px;
text-align: center;
color: #333; /* Darker color for visibility */
}
</style>
</head>
<body>
<nav class="navbar">
<div class="navbar-left">
<a href="index.html">
<img class="navbar-img" src="logo.png" alt="Polipicker">
</a>
</div>
<div class="navbar-center">
<form id="searchForm" class="search-bar">
<input id="searchInput" type="text" placeholder="Search politicians...">
<button type="submit">
<i class="fa fa-search"></i>
</button>
</form>
<div id="dropdownMenu"></div>
</div>
<div class="navbar-right">
<a href="profile.html">
<img id="pfp" class="navbar-img" src="profilePicDefault.png" alt="Account">
</a>
</div>
</nav>
<div class="alignment-container">
<div class="carousel-container">
<span class="arrow left-arrow" id="prev">❮</span>
<div class="carousel-content">
<div class="carousel-slide" id="carousel-slide">
<div class="carousel-item">
<img src="2024election.jpg" alt="2024 Presidential Election">
<div class="headline">2024 Presidential Election</div>
</div>
<div class="carousel-item">
<img src="texasSenateRace.jpg" alt="Texas Senate Race">
<div class="headline">Texas Senate Rate</div>
</div>
<div class="carousel-item">
<img src="ohioSenateRace.jpg" alt="Ohio Senate Race">
<div class="headline">Ohio Senate Race</div>
</div>
</div>
</div>
<span class="arrow right-arrow" id="next">❯</span>
</div>
</div>
<!-- Google Search Section -->
<div class="google-search-container">
<!-- Results box with title -->
<div class="results-box" id="searchResults">
<div class="results-title">Elections Near You</div>
<!-- Search results will be dynamically added here -->
</div>
</div>
<script src="carousel.js"></script>
<script src="search.js"></script>
<script>
const API_KEY = 'AIzaSyCEPDDQcYA0CQne4DY7tiH6snKOz-pTWtc'; // Replace with your API key
const SEARCH_ENGINE_ID = 'a0f1d23ff7fbd4989'; // Replace with your Search Engine ID
const MAX_RESULTS = 5; // Limit the number of results
async function searchGoogle() {
const query = 'Elections in Pittsburgh'; // Define the search query here
const searchResultsDiv = document.getElementById('searchResults');
searchResultsDiv.innerHTML = '<div class="results-title">Elections Near You</div>'; // Reset with title
try {
const response = await fetch(`https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${SEARCH_ENGINE_ID}&q=${encodeURIComponent(query)}&num=${MAX_RESULTS}`);
const data = await response.json();
if (data.items) {
data.items.forEach(item => {
const resultItem = document.createElement('div');
resultItem.className = 'result-item';
resultItem.innerHTML = `
<a href="${item.link}" target="_blank">${item.title}</a>
<p>${item.snippet}</p>
`;
searchResultsDiv.appendChild(resultItem);
});
} else {
searchResultsDiv.innerHTML += '<p>No results found.</p>';
}
} catch (error) {
console.error('Error fetching search results:', error);
searchResultsDiv.innerHTML += '<p>Error fetching search results. Please try again.</p>';
}
}
// Call the search function when the page loads
window.onload = searchGoogle;
</script>
</body>
</html>