2024-03-03 18:18:34 +08:00
|
|
|
export function initRepositorySearch() {
|
2024-12-11 16:29:04 +08:00
|
|
|
const repositorySearchForm = document.querySelector<HTMLFormElement>('#repo-search-form');
|
2024-03-03 18:18:34 +08:00
|
|
|
if (!repositorySearchForm) return;
|
|
|
|
|
2024-12-11 16:29:04 +08:00
|
|
|
repositorySearchForm.addEventListener('change', (e: Event & {target: HTMLFormElement}) => {
|
2024-03-03 18:18:34 +08:00
|
|
|
e.preventDefault();
|
|
|
|
|
2024-12-16 05:02:32 +08:00
|
|
|
const params = new URLSearchParams();
|
|
|
|
for (const [key, value] of new FormData(repositorySearchForm).entries()) {
|
|
|
|
params.set(key, value.toString());
|
|
|
|
}
|
2024-03-03 18:18:34 +08:00
|
|
|
if (e.target.name === 'clear-filter') {
|
|
|
|
params.delete('archived');
|
|
|
|
params.delete('fork');
|
|
|
|
params.delete('mirror');
|
|
|
|
params.delete('template');
|
|
|
|
params.delete('private');
|
|
|
|
}
|
|
|
|
|
|
|
|
params.delete('clear-filter');
|
|
|
|
window.location.search = params.toString();
|
|
|
|
});
|
|
|
|
}
|