🗡️ Strip Query Params

Open strip-query-params in Script Kit

🗡️ Strip Query Params

  • ⌨️ Prompts the user for a URL
  • 🗡️ Cuts off all query params
  • 🛡️ Maintains essential query params (e.g., youtube.com/watch?v=[videoId])
  • 📋 Automatically copies the updated URL to the clipboard.

Useful for removing tracking / other information from URLs before sharing with others.

Examples

|Site|Input|Output| |-|-|-| |Facebook Video|https://www.facebook.com/watch/?v=1233056997105202&extid=NS-UNK-CHE-UNK-IOS_WXYZ-ABCD&mibextid=cfeeni&ref=sharing|https://www.facebook.com/watch/?v=1233056997105202| |Facebook|https://www.facebook.com/groups/funnycatsworld/permalink/5619404908185458/?mibextid=cfeeni|https://www.facebook.com/groups/funnycatsworld/permalink/5619404908185458/| |Instagram|https://www.instagram.com/reel/CnxZnkRprAD/?igshid=YmNmMTdmZDM=|https://www.instagram.com/reel/CnxZnkRprAD/| |YouTube|https://www.youtube.com/watch?v=MWRPYBoCEaY&ab_channel=NoBoilerplate|https://www.youtube.com/watch?v=MWRPYBoCEaY|

// Name: 🗡️ Strip Query Params
// Description: Strips query params from a URL.
// Author: Ryan Baer
import "@johnlindquist/kit";
// TODO: let's leverage the awesome `db` feature and allow users to add their own
// rules.
const requiredParams: Record<string, string[]> = {
// youtube.com/watch?v=[videoId] requires the 'v' param to locate the video
"youtube.com": ["v"],
// facebook.com/watch/?v=[videoId] requires the 'v' param to locate the video
"facebook.com": ["v"],
};
function stripQueryParams(input: string) {
const url = new URL(input);
function getBaseDomain(hostname: string) {
const [tld, base] = hostname.split(".").reverse();
return `${base}.${tld}`;
}
// Clone so we're not deleting from the list as we're iterating it.
const searchParams = new URLSearchParams(url.searchParams);
searchParams.forEach((_value, key) => {
const baseDomain = getBaseDomain(url.hostname);
const skip = requiredParams[baseDomain];
if (skip?.includes(key)) {
return;
}
url.searchParams.delete(key);
});
return url.href;
}
const input = await arg("Enter a URL");
const result = stripQueryParams(input);
await copy(result);
await div(
md(`# 🔬 Result (automatically copied to clipboard)
\`\`\`
${result}
\`\`\`
`)
);