Merge pull request #154 from 0dayCTF/0dayCTF-patch-12

Fixed Search Bug
This commit is contained in:
Ryan Montgomery 2023-12-01 13:11:46 -05:00 committed by GitHub
commit 288974464c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -537,31 +537,67 @@ $(function () {
// TODO: add a random fifo for netcat mkfifo // TODO: add a random fifo for netcat mkfifo
//let randomId = Math.random().toString(36).substring(2, 4); //let randomId = Math.random().toString(36).substring(2, 4);
// Search functionality // Global variable to keep track of the last search term
document.getElementById('searchBox').addEventListener('keyup', function() { // This variable will hold the last search term
var searchTerm = this.value.toLowerCase(); // This function will apply the search filter to the list
// Utility function to save the search term
function saveSearchTerm(term) {
localStorage.setItem('searchTerm', term);
}
// Utility function to get the saved search term
function getSavedSearchTerm() {
return localStorage.getItem('searchTerm');
}
// Function to apply the search filter
function applySearchFilter(term) {
var listItems = document.querySelectorAll('#reverse-shell-selection .list-group-item'); var listItems = document.querySelectorAll('#reverse-shell-selection .list-group-item');
var count = 0; var count = 0;
listItems.forEach(function(item) { listItems.forEach(function(item) {
var text = item.textContent.toLowerCase(); var text = item.textContent.toLowerCase();
var match = text.indexOf(searchTerm) !== -1; var match = text.indexOf(term) !== -1;
if (match) { item.style.display = match ? '' : 'none';
item.style.display = ''; if (match) count++;
count++;
} else {
item.style.display = 'none';
}
}); });
document.getElementById('noResults').style.display = count === 0 ? '' : 'none'; // Show or hide the 'no results' message
}); var noResultsEl = document.getElementById('noResults');
if (noResultsEl) {
noResultsEl.style.display = count === 0 ? 'block' : 'none';
}
// Event listener for search results // Reattach event listeners to the filtered items
document.querySelectorAll('#reverse-shell-selection .list-group-item').forEach(function(item) { attachClickListenersToItems();
item.addEventListener('click', function(event) { }
event.preventDefault();
console.log(item.textContent); // Attach click event listeners to search result items
document.getElementById('searchBox').dispatchEvent(new Event('keyup')); function attachClickListenersToItems() {
document.querySelectorAll('#reverse-shell-selection .list-group-item').forEach(function(item) {
item.addEventListener('click', function(event) {
event.preventDefault();
event.stopPropagation();
var searchTerm = getSavedSearchTerm();
if (searchTerm) {
applySearchFilter(searchTerm);
}
});
}); });
}
// Set up the initial event listener for the search box
document.addEventListener('DOMContentLoaded', function() {
var searchBox = document.getElementById('searchBox');
if (searchBox) {
searchBox.value = getSavedSearchTerm() || '';
applySearchFilter(searchBox.value.toLowerCase());
searchBox.addEventListener('keyup', function() {
var searchTerm = this.value.toLowerCase();
saveSearchTerm(searchTerm);
applySearchFilter(searchTerm);
});
}
}); });