Google Search URL Fixup Fork

Sets the links in the JavaScript-free Google Basic Variant (gbv=1) search results to their original domains, which circumvents click routing through Google's query parameters, fixes browser history mismatch, and strips tracking query parameters.

  1. // ==UserScript==
  2. // @name Google Search URL Fixup Fork
  3. // @namespace https://gf.qytechs.cn/users/581142
  4. // @namespace https://github.com/brian6932/gsearch-urlfix
  5. // @license MPL-2.0
  6. // @include /^https?:\/{2}w{3}\.google\.(?:a[delmstz]|b[aefgijsty]|c(?:o(?:m(?:\.(?:a[fgru]|b[dhnorz]|c[ouy]|do|e[cgt]|fj|g[hit]|hk|jm|k[hw]|l[by]|m[mtxy]|n[agip]|om|p[aeghkry]|qa|s[abglv]|t[jrw]|u[ay]|v[cn]))?|\.(?:ao|bw|c[kr]|i[dln]|jp|k[er]|ls|m[az]|nz|t[hz]|u[gkz]|v[ei]|z[amw]))|[adfghilmnvz])|d[ejkmz]|e[es]|f[imr]|g[aeglmry]|h[nrtu]|i[emqst]|j[eo]|k[giz]|l[aiktuv]|m[degklnuvw]|n[eloru]|p[lnst]|r[osuw]|s[cehikmnort]|t[dglmnot]|vu|ws)\/search\?/
  7. // @icon https://raw.githubusercontent.com/brian6932/gsearch-urlfix/master/icon.svg
  8. // @grant none
  9. // @version 0.8.10
  10. // @author brian6932
  11. // @description Sets the links in the JavaScript-free Google Basic Variant (gbv=1) search results to their original domains, which circumvents click routing through Google's query parameters, fixes browser history mismatch, and strips tracking query parameters.
  12. // ==/UserScript==
  13. // jshint esversion: 11
  14.  
  15. let i = -1
  16. const
  17. pathToParam = {
  18. __proto__: null,
  19. "/url": "q",
  20. "/imgres": "imgurl"
  21. },
  22. strippableParams = [
  23. "ei",
  24. "fbs",
  25. "sa",
  26. "sca_esv",
  27. "sca_upv",
  28. "source",
  29. "sxsrf",
  30. "ved",
  31. ],
  32. { links } = globalThis.document,
  33. fixLinks = () => {
  34. while (++i < links.length) {
  35. if (links[i].search === "" && links[i].host !== "www.google.com")
  36. continue
  37.  
  38. const mappedParam = pathToParam[links[i].pathname]
  39. if (mappedParam !== undefined) {
  40. const encodedLink = new globalThis.URLSearchParams(links[i].search).get(mappedParam)
  41. if (encodedLink === null)
  42. continue
  43.  
  44. if (!(links[i].href = globalThis.decodeURIComponent(encodedLink)).startsWith("https://www.google.com/"))
  45. continue
  46. }
  47.  
  48. /*
  49. * Should hit the following paths:
  50. /
  51. /maps
  52. /preferences
  53. /search
  54. /setprefs
  55. /travel
  56. /webhp
  57. */
  58. const link = new globalThis.URL(links[i].href)
  59.  
  60. for (const param of strippableParams)
  61. link.searchParams.delete(param)
  62.  
  63. links[i].href = link.toString()
  64. }
  65. }
  66.  
  67. // Invoke on load.
  68. fixLinks()
  69.  
  70. // Reinvoke on body change.
  71. new globalThis.MutationObserver(mutations => {
  72. for (const mutation of mutations)
  73. if (mutation.type === "childList")
  74. return fixLinks()
  75. }).observe(globalThis.document.body, { __proto__: null, childList: true, subtree: true })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址