diff options
Diffstat (limited to 'src/lib/Tools/tool.ts')
| -rw-r--r-- | src/lib/Tools/tool.ts | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/lib/Tools/tool.ts b/src/lib/Tools/tool.ts index fc50a715..cf24eb8c 100644 --- a/src/lib/Tools/tool.ts +++ b/src/lib/Tools/tool.ts @@ -1,16 +1,21 @@ import { browser } from '$app/environment'; import { page } from '$app/stores'; +import { get } from 'svelte/store'; export const clearAllParameters = (saved: string[] = []) => { - if (browser) - page.subscribe((value) => { - value.url.searchParams.forEach((_, key) => { - if (!saved.includes(key) && key !== 'tool') { - value.url.searchParams.delete(key); - } - }); - history.replaceState(null, '', `?${value.url.searchParams.toString()}`); + if (browser) { + const parameters = new URLSearchParams(); + + if (get(page).url.searchParams.has('tool')) + parameters.set('tool', get(page).url.searchParams.get('tool') || ''); + + saved.forEach((key) => { + if (get(page).url.searchParams.has(key)) { + parameters.set(key, get(page).url.searchParams.get(key) || ''); + } }); + history.replaceState(null, '', `${get(page).url.pathname}?${parameters}`); + } }; export const parseOrDefault = <T = string | number>( |