Skip to content

Commit

Permalink
feat: Inline param stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
brian6932 committed Aug 8, 2024
1 parent fb06f18 commit 862736e
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions linkfix.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,44 @@

let i = -1
const
strippableParams = [
"ei",
"fbs",
"sa",
"sca_esv",
"sca_upv",
"source",
"sxsrf",
"ved",
],
links = document.links,
fixLinks = () => {
while (++i < links.length) {
if (links[i].pathname !== "/url" || links[i].search === "")
if (links[i].search === "" && links[i].host !== `www.google.com`)
continue
// Extract the search without the leading '?'.
const q = new URLSearchParams(links[i].search.slice(1)).get("q")
// note to self: must change href attribute, not the entire
// thing. Doh. Read the docs, sort of.
if (q !== null)
links[i].href = decodeURIComponent(q)

switch (links[i].pathname) {
case "/url":
// Extract the search without the leading '?'.
const q = new URLSearchParams(links[i].search.slice(1)).get("q")
// note to self: must change href attribute, not the entire
// thing. Doh. Read the docs, sort of.
if (q !== null)
links[i].href = decodeURIComponent(q)
case "/":
case "/maps":
case "/preferences":
case "/search":
case "/setprefs":
case "/travel":
case "/webhp":
const link = new URL(links[i].href)

for (const param of strippableParams)
link.searchParams.delete(param)

links[i].href = link.toString()
}
}
}

Expand Down

0 comments on commit 862736e

Please sign in to comment.