Skip to content

Commit 89609ee

Browse files
committed
fix: faulty locationChange emitter fixed
locationChange was being emitted even when only the query params changed
1 parent b43c15e commit 89609ee

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.changeset/pink-pandas-ring.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gregmat-buddy": patch
3+
---
4+
5+
fixed multiple jumps from one keypress on vocab mountain

src/entrypoints/content/emitters.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { VIMEO_SELECTOR } from "@/constants";
22
import { waitForElement, waitForNoElement } from "@/utils";
33

4+
function sanitizedUrl(url: string) {
5+
const queryIndex = url.indexOf("?");
6+
7+
if (queryIndex == -1) return url;
8+
9+
return url.substring(0, queryIndex);
10+
}
11+
412
export function registerLocationChange() {
5-
let currentUrl = location.href;
13+
let currentUrl = sanitizedUrl(location.href);
614

715
setInterval(() => {
8-
if (location.href !== currentUrl) {
9-
currentUrl = location.href;
16+
const url = sanitizedUrl(location.href);
17+
if (url !== currentUrl) {
18+
currentUrl = url;
1019
window.dispatchEvent(new Event("locationChange"));
1120
}
1221
}, 500);

0 commit comments

Comments
 (0)