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.

当前为 2024-08-18 提交的版本,查看 最新版本

  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. // @grant none
  8. // @version 0.88
  9. // @author brian6932
  10. // @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.
  11. // ==/UserScript==
  12. // jshint esversion: 11
  13.  
  14. let i = -1
  15. const
  16. pathToParam = {
  17. __proto__: null,
  18. "/url": "q",
  19. "/imgres": "imgurl"
  20. },
  21. strippableParams = [
  22. "ei",
  23. "fbs",
  24. "sa",
  25. "sca_esv",
  26. "sca_upv",
  27. "source",
  28. "sxsrf",
  29. "ved",
  30. ],
  31. links = document.links,
  32. fixLinks = () => {
  33. while (++i < links.length) {
  34. if (links[i].search === "" && links[i].host !== "www.google.com")
  35. continue
  36.  
  37. const mappedParam = pathToParam[links[i].pathname]
  38. if (mappedParam !== undefined) {
  39. const encodedLink = new URLSearchParams(links[i].search).get(mappedParam)
  40. // note to self: must change href attribute, not the entire
  41. // thing. Doh. Read the docs, sort of.
  42. if (encodedLink === null)
  43. continue
  44.  
  45. if (!(links[i].href = decodeURIComponent(encodedLink)).startsWith("https://www.google.com/"))
  46. continue
  47. }
  48.  
  49. /*
  50. * Should hit the following paths
  51. /
  52. /maps
  53. /preferences
  54. /search
  55. /setprefs
  56. /travel
  57. /webhp
  58. */
  59. const link = new URL(links[i].href)
  60.  
  61. for (const param of strippableParams)
  62. link.searchParams.delete(param)
  63.  
  64. links[i].href = link.toString()
  65. }
  66. }
  67.  
  68. // Invoke on load.
  69. fixLinks()
  70.  
  71. // Reinvoke on body change.
  72. new MutationObserver(mutations => {
  73. for (const mutation of mutations)
  74. if (mutation.type === "childList")
  75. return fixLinks()
  76. }).observe(document.body, { __proto__: null, childList: true, subtree: true })

QingJ © 2025

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