-
Notifications
You must be signed in to change notification settings - Fork 1
/
all_plugins_search.js
41 lines (33 loc) · 1.68 KB
/
all_plugins_search.js
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
document.addEventListener('DOMContentLoaded', function() {
loadPlugins();
async function loadPlugins() {
const response = await fetch('plugins_list.html');
const html = await response.text();
document.getElementById('pluginContainer').innerHTML = html;
updatePluginCount();
}
function updatePluginCount() {
const count = document.getElementById('pluginContainer').querySelectorAll('a').length; // Assuming each plugin is wrapped in a <a>
document.getElementById('pluginCount').textContent = count;
}
document.getElementById('searchBox').addEventListener('input', function() {
searchFunction(this.value); // Pass the current value of the search box to the search function
});
async function searchFunction(searchText) {
// Load the entire list again (or you could optimize by caching it)
const response = await fetch('plugins_list.html');
const html = await response.text();
document.getElementById('pluginContainer').innerHTML = html;
if (!searchText) {
updatePluginCount();
return; // If the search box is empty, display all plugins
}
const plugins = Array.from(document.getElementById('pluginContainer').children);
const filteredPlugins = plugins.filter(plugin => plugin.textContent.toLowerCase().includes(searchText.toLowerCase()));
document.getElementById('pluginContainer').innerHTML = ''; // Clear the container
filteredPlugins.forEach(plugin => {
document.getElementById('pluginContainer').appendChild(plugin);
});
updatePluginCount(); // Update the count based on search
}
});