startpage.com pseudo bangs

06/04/2025, 7:23:21 pm

  1. // ==UserScript==
  2. // @name startpage.com pseudo bangs
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.startpage.com/do/dsearch*
  5. // @match https://www.startpage.com/do/search*
  6. // @match https://www.startpage.com/sp/search*
  7. // @grant none
  8. // @version 1.0
  9. // @license MIT
  10. // @author -
  11. // @description 06/04/2025, 7:23:21 pm
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. const usp = new URLSearchParams(window.location.search)
  16.  
  17. const hasBang = (b, q) => q.startsWith(`!${b} `) || q.endsWith(` !${b}`) || q.includes(` !${b} `)
  18.  
  19. const gotoUrl = (u, b, q) => window.location.href = `${u}${q.replace(`!${b}`, "")}`
  20.  
  21. let query = false
  22.  
  23. if(usp.has("query")){
  24. query = usp.get("query").trim()
  25. }
  26. else if (usp.has("q")){
  27. query = usp.get("q").trim()
  28. }
  29.  
  30.  
  31. if(query){
  32. if(hasBang("", query)){
  33. // Running at document-start so some dom not ready yet.
  34. // Run at document-start to make other code run quicker as it only needs url info and not dom.
  35. const interval = setInterval(() => {
  36. const firstResult = document.querySelector('.result-link')
  37. if(firstResult){
  38. window.location.href = firstResult.href
  39. clearInterval(interval)
  40. }
  41. }, 0) // this is fine as dont need anything on the initial page.
  42.  
  43. }
  44. if(hasBang("g", query)){
  45. gotoUrl(`https://www.google.com/search?q=`, "g", query)
  46. }
  47. if(hasBang("gm", query)){
  48. gotoUrl(`https://www.google.com/maps?search&q=`, "gm", query)
  49. }
  50. }