This repository was archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
174 lines (153 loc) · 6.06 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vocabulary Search</title>
<style>
/* Basic Reset and Font */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; background: #f2f7ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 20px; }
/* Trans Flag Banner */
.banner {
display: flex;
width: 100%;
max-width: 600px;
height: 20px;
margin-bottom: 30px;
border-radius: 5px;
overflow: hidden;
}
.banner div {
flex: 1;
}
.banner .blue { background: #55CDFC; }
.banner .pink { background: #F7A8B8; }
.banner .white { background: #ffffff; }
/* Main Container */
.container {
background: white;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
padding: 30px;
max-width: 600px;
width: 100%;
text-align: center;
}
/* Title */
h1 {
font-size: 1.8rem;
color: #333;
margin-bottom: 20px;
}
/* Input and Button */
input[type="text"] {
width: 80%;
padding: 10px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 1rem;
margin-bottom: 15px;
outline: none;
transition: border-color 0.3s;
}
input[type="text"]:focus { border-color: #55CDFC; }
button {
padding: 10px 20px;
font-size: 1rem;
color: white;
background: #55CDFC;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background 0.3s;
}
button:hover { background: #4bb9e3; }
/* Results Area */
#results { margin-top: 20px; text-align: left; }
.file-match { margin-bottom: 15px; padding: 15px; background: #f9f9f9; border-radius: 5px; border-left: 4px solid #55CDFC; }
.file-match h3 { font-size: 1.2rem; margin-bottom: 10px; color: #333; }
.file-match p { margin-left: 10px; color: #555; }
/* Messages */
.no-results, .error-message {
color: #F7A8B8;
font-weight: bold;
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<!-- Trans Flag Banner -->
<div class="banner">
<div class="blue"></div>
<div class="pink"></div>
<div class="white"></div>
<div class="pink"></div>
<div class="blue"></div>
</div>
<!-- Search Container -->
<div class="container">
<h1>Vocabulary Search</h1>
<input type="text" id="searchInput" placeholder="Enter search term">
<button onclick="searchVocabulary()">Search</button>
<!-- Results Area -->
<div id="results"></div>
</div>
<script>
async function searchVocabulary() {
const searchInput = document.getElementById("searchInput").value.trim();
const resultsDiv = document.getElementById("results");
resultsDiv.innerHTML = ""; // Clear previous results
if (!searchInput) {
resultsDiv.innerHTML = "<p class='no-results'>Please enter a search term.</p>";
return;
}
const repoOwner = "Transconlang";
const repoName = "translang";
const directoryPath = "Vocabulary";
try {
// Step 1: Fetch the list of files in the Vocabulary directory
const fileList = await fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/contents/${directoryPath}`);
const files = await fileList.json();
// Check if we received a valid response
if (fileList.status !== 200 || !Array.isArray(files)) {
throw new Error("Failed to load file list.");
}
let foundMatches = false;
for (const file of files) {
if (file.type === "file") {
// Step 2: Fetch each file content
const fileContentResponse = await fetch(file.download_url);
const fileContent = await fileContentResponse.text();
// Step 3: Search for the term in file content, ignoring unwanted lines
const lines = fileContent.split("\n");
const matches = lines.filter(line =>
line.includes(searchInput) && line !== "| Spelling | Definition |"
);
if (matches.length > 0) {
foundMatches = true;
// Step 4: Display results
const fileMatchDiv = document.createElement("div");
fileMatchDiv.className = "file-match";
fileMatchDiv.innerHTML = `<h3>Matches in ${file.name}</h3>`;
matches.forEach(match => {
const lineDiv = document.createElement("p");
lineDiv.textContent = match;
fileMatchDiv.appendChild(lineDiv);
});
resultsDiv.appendChild(fileMatchDiv);
}
}
}
if (!foundMatches) {
resultsDiv.innerHTML = "<p class='no-results'>No matches found.</p>";
}
} catch (error) {
console.error("Error fetching files or content:", error);
resultsDiv.innerHTML = "<p class='error-message'>There was an error fetching the files. Please try again later.</p>";
}
}
</script>
</body>
</html>