Custom Search Engine Redirect (Enhanced)

Redirects searches from popular search engines to your preferred engine and adds a sleek, auto-hiding search bar for instant custom searches.

  1. // ==UserScript==
  2. // @name Custom Search Engine Redirect (Enhanced)
  3. // @description Redirects searches from popular search engines to your preferred engine and adds a sleek, auto-hiding search bar for instant custom searches.
  4. // @author SijosxStudio
  5. // @version 1.0
  6. // @license MIT
  7. // @match *://*/*
  8. // @grant none
  9. // @inject-into auto
  10. // @run-at document-start
  11. // @namespace https://greasyfork.org/users/1375139
  12.  
  13. // ==/UserScript==
  14. (function () {
  15. 'use strict';
  16.  
  17. // CONFIGURATION: Replace with your preferred search engine URL.
  18. const searchEngineURL = 'https://startpage.com/search?q=';
  19.  
  20. const defaultEngines = [
  21. 'duckduckgo.com',
  22. 'google.com',
  23. 'bing.com',
  24. 'yahoo.com',
  25. 'search.yahoo.com'
  26. ];
  27.  
  28. // REDIRECTION LOGIC
  29. const currentURL = window.location.href;
  30.  
  31. if (defaultEngines.some(engine => currentURL.includes(engine))) {
  32. const queryParam = new URLSearchParams(window.location.search);
  33. const query = queryParam.get('q') || queryParam.get('query') || queryParam.get('p');
  34. if (query) {
  35. window.location.href = searchEngineURL + encodeURIComponent(query);
  36. }
  37. }
  38.  
  39. // FLOATING SEARCH BAR (WITH AUTO-HIDE)
  40. window.addEventListener('DOMContentLoaded', function () {
  41. const searchBar = document.createElement('div');
  42. searchBar.id = 'floating-search-bar';
  43. searchBar.style.position = 'fixed';
  44. searchBar.style.top = '10px';
  45. searchBar.style.right = '-220px'; // Start hidden
  46. searchBar.style.zIndex = '9999';
  47. searchBar.style.background = 'rgba(0, 0, 0, 0.8)';
  48. searchBar.style.border = '2px solid #00bfff';
  49. searchBar.style.borderRadius = '8px';
  50. searchBar.style.padding = '5px';
  51. searchBar.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.5)';
  52. searchBar.style.display = 'flex';
  53. searchBar.style.alignItems = 'center';
  54. searchBar.style.transition = 'right 0.3s ease-in-out';
  55.  
  56. const inputField = document.createElement('input');
  57. inputField.type = 'text';
  58. inputField.placeholder = 'Custom Search...';
  59. inputField.style.border = 'none';
  60. inputField.style.outline = 'none';
  61. inputField.style.padding = '5px';
  62. inputField.style.flexGrow = '1';
  63. inputField.style.width = '150px';
  64. inputField.style.background = 'transparent';
  65. inputField.style.color = '#fff';
  66.  
  67. const searchButton = document.createElement('button');
  68. searchButton.textContent = 'Go';
  69. searchButton.style.background = '#00bfff';
  70. searchButton.style.color = '#fff';
  71. searchButton.style.border = 'none';
  72. searchButton.style.padding = '5px 10px';
  73. searchButton.style.cursor = 'pointer';
  74. searchButton.style.borderRadius = '4px';
  75.  
  76. searchButton.onclick = function () {
  77. const query = inputField.value.trim();
  78. if (query) {
  79. window.location.href = searchEngineURL + encodeURIComponent(query);
  80. }
  81. };
  82.  
  83. inputField.addEventListener('keypress', function (e) {
  84. if (e.key === 'Enter') {
  85. searchButton.click();
  86. }
  87. });
  88.  
  89. // Auto-hide logic
  90. const toggleArea = document.createElement('div');
  91. toggleArea.style.position = 'fixed';
  92. toggleArea.style.top = '10px';
  93. toggleArea.style.right = '0';
  94. toggleArea.style.width = '30px';
  95. toggleArea.style.height = '30px';
  96. toggleArea.style.zIndex = '9998';
  97.  
  98. toggleArea.addEventListener('mouseenter', () => {
  99. searchBar.style.right = '10px'; // Show search bar on hover
  100. });
  101.  
  102. searchBar.addEventListener('mouseleave', () => {
  103. searchBar.style.right = '-220px'; // Auto-hide on mouse leave
  104. });
  105.  
  106. searchBar.appendChild(inputField);
  107. searchBar.appendChild(searchButton);
  108. document.body.appendChild(searchBar);
  109. document.body.appendChild(toggleArea);
  110. });
  111. })();