Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import trackingParams from "https://esm.town/v/nbbaier/trackingParams";
function removeTrackingParams(url: URL, customParams: string[] = []): URL {
const paramsToRemove = [...new Set([...customParams, ...trackingParams])];
const params = new URLSearchParams(url.search.replace(/amp;/g, "&"));
params.forEach((_, key) => {
for (const paramToRemove of paramsToRemove) {
const regex = new RegExp(paramToRemove);
if (regex.test(key)) {
console.log(`${key} is deletable`);
url.searchParams.delete(key);
}
}
});
return url;
}
export default removeTrackingParams;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 8, 2024