Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
taylormonacelli committed Aug 7, 2024
1 parent a6c0b78 commit 6b10b04
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
64 changes: 32 additions & 32 deletions core/links/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ var excludeParams = []string{
"tbm",
}

var ParamsToRemove = []string{
"bih",
"biw",
"client",
"dpr",
"ei",
"fbs",
"gs_lcp",
"gs_lcrp",
"gs_lp",
"gs_ssp",
"hl",
"ictx",
"ie",
"oq",
"prmd",
"sa",
"sca_esv",
"sca_upv",
"sclient",
"source",
"sourceid",
"spell",
"sqi",
"sxsrf",
"uact",
// "udm", // keep image search links in tact
"uds",
"ved",
}

func RemoveParamsFromGoogleURLs(r io.Reader, w io.Writer) error {
buf, err := io.ReadAll(r)
if err != nil {
Expand Down Expand Up @@ -76,41 +107,10 @@ func cleanGoogleURL(urlStr string) (string, []string, error) {

q := u.Query()

paramsToRemove := []string{
"bih",
"biw",
"client",
"dpr",
"ei",
"fbs",
"gs_lcp",
"gs_lcrp",
"gs_lp",
"gs_ssp",
"hl",
"ictx",
"ie",
"oq",
"prmd",
"sa",
"sca_esv",
"sca_upv",
"sclient",
"source",
"sourceid",
"spell",
"sqi",
"sxsrf",
"uact",
// "udm", // keep image search links in tact
"uds",
"ved",
}

var remainingParams []string

for param := range q {
if contains(excludeParams, param) || !contains(paramsToRemove, param) {
if contains(excludeParams, param) || !contains(ParamsToRemove, param) {
remainingParams = append(remainingParams, param)
continue
}
Expand Down
5 changes: 5 additions & 0 deletions core/links/google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func TestRemoveParamsFromGoogleLinks(t *testing.T) {
input: "https://www.google.com/search?q=test&bih=722&biw=1536&hl=en&sxsrf=ABC123",
expected: "https://www.google.com/search?q=test",
},
{
name: "Google image search",
input: "https://www.google.com/search?udm=2&q=skiing",
expected: "https://www.google.com/search?q=skiing&udm=2",
},
{
name: "Google link without parameters",
input: "https://www.google.com",
Expand Down

0 comments on commit 6b10b04

Please sign in to comment.