google search unredirect android firefox

remove redirect link in google search result page

  1. // ==UserScript==
  2. // @name google search unredirect android firefox
  3. // @namespace http://gholk.github.io
  4. // @description remove redirect link in google search result page
  5. // @version 0.1
  6. // @match https://www.google.com/search?*
  7. // @grant none
  8. // @license GPLv3
  9. // ==/UserScript==
  10.  
  11. function unRedirect(a) {
  12. const attr = a.getAttribute('href')
  13. if (attr.slice(0, 5) != '/url?') return
  14. const u = new URL(a.href)
  15. const o = u.searchParams.get('q')
  16. a.href = o
  17. }
  18.  
  19. void function tryUnRedirect () {
  20. const allAnchor = document.querySelectorAll('a[href^= "/url?"')
  21. if (allAnchor.length > 0) {
  22. allAnchor.forEach(a => unRedirect(a))
  23. }
  24. else setTimeout(tryUnRedirect, 500)
  25. }()