Google Search Better Privacy

Delete unnecessary params and add useful params on Google Search.

  1. // ==UserScript==
  2. // @name Google Search Better Privacy
  3. // @description Delete unnecessary params and add useful params on Google Search.
  4. // @version 0.0.4
  5. // @include http://*.google.*/search*
  6. // @include http://*.google.*/imgres*
  7. // @include https://*.google.*/search*
  8. // @include https://*.google.*/imgres*
  9. // @exclude http://play.google.com/*
  10. // @exclude http://mail.google.com/*
  11. // @exclude https://play.google.com/*
  12. // @exclude https://mail.google.com/*
  13. // @author nodaguti
  14. // @license MIT License
  15. // @run-at document-start
  16. // @namespace https://greatest.deepsurf.us/users/1453
  17. // ==/UserScript==
  18.  
  19. (function(){
  20.  
  21. //--- Config ---
  22. //For more information about parameters, please see
  23. //http://www.blueglass.com/blog/google-search-url-parameters-query-string-anatomy/ or
  24. //http://www.seomoz.org/ugc/the-ultimate-guide-to-the-google-search-parameters
  25. var addParams = [
  26. 'safe=off', //Disable safe search
  27. 'newwindow=1', //Open links in new tab
  28. 'pws=0', //Disable personalized search
  29. 'complete=0', //Disable instant search
  30. // 'as_qdr=y15', //Display when sites released
  31. // 'adtest=on', //Turn off AdWords database connection
  32. //See https://developers.google.com/custom-search-ads/docs/reference#adtest for detail
  33. ];
  34.  
  35. var deleteParams = [
  36. //--- Tracking Params ---
  37. //Thx: http://www.blueglass.com/blog/google-search-url-parameters-query-string-anatomy/
  38.  
  39. 'client', //Browser Name
  40. 'sclient', //Browser Name
  41. 'sourceid', //Source of the query
  42. 'source', //Source of the query
  43. 'oq', //What you typed before you made a selection
  44. //from the suggestions
  45. 'aq', //Google Suggest Tracking (Shows which suggestion you choose)
  46. 'pq', //Previous Query
  47. 'sa', //Google SERPs navigation behavior tracking
  48. 'swrnum', //The number of results the initial query returned
  49. 'as_q', //When searching within results, the query is added as_q
  50. 'oi', //Universal search: Group name
  51. 'resnum', //Universal search: Number of a result within the group
  52.  
  53. //--- Maybe Tracking Params, but details unknown ---
  54. 'gs_l', //Location?
  55. 'bav',
  56. 'bvm',
  57. 'bpcl',
  58. 'biw', //Client display width?
  59. 'bih', //Client display height?
  60. 'w',
  61. 'h',
  62. 'tbnh',
  63. 'tbnw',
  64. 'fp',
  65. 'ei',
  66. 'usg',
  67. 'sig2',
  68. 'tbs',
  69. 'ved',
  70.  
  71. //--- Appearance Setting Params (default: Disabled) ---
  72. // If you want to delete these params, please reveal the comment out.
  73. // 'tbo', //tbo=1: Display search toolbar
  74. // 'prmdo', //prmdo=1: Expand 'services' in toolbar
  75. // 'sout', //sout=1: Change UI of Google Image Search to old version
  76. // 'esrch', //esrch=instantpreviews: Enable instant preview
  77. // 'filter', //filter=1: Filter similar pages
  78. // 'hl', //Interface language
  79. // 'lr', //Search target language
  80. // 'ie', //Query encoding
  81. // 'oe', //Search result encoding
  82. // 'noj', //noj=1: No JavaScript
  83.  
  84. //--- Unknown Params ---
  85. 'pdx',
  86. 'ech',
  87. 'psi',
  88. 'emsg',
  89. 'facrc',
  90. 'imgdii',
  91. 'iact',
  92. 'ndsp',
  93. 'tx',
  94. 'ty',
  95. ];
  96. // --- /Config ---
  97.  
  98.  
  99. var delParamReg = new RegExp('&(?:' + deleteParams.join('=[^&#]*|') + '=[^&#]*)', 'g');
  100. var overwriteParamReg = new RegExp('&(?:' + addParams.map(function(i){return i.split('=')[0];}).join('=[^&#]*|') + '=[^&#]*)', 'g');
  101.  
  102.  
  103. //Delete and add params
  104. function urlFix(url){
  105. var _url = url;
  106.  
  107. //delete params
  108. _url = url.replace(delParamReg, '');
  109.  
  110. //overwrite and add params
  111. _url = _url.replace(overwriteParamReg, '').replace(/&$/, '');
  112. _url += '&' + addParams.join('&') + '&urlfixed=1';
  113.  
  114. return _url;
  115. }
  116.  
  117. //Reload page when hash is changed (when search from textbox on result page)
  118. function hashChange(){
  119. //Exclude Image Search
  120. if(location.search.indexOf('tbm=isch') !== -1) return;
  121.  
  122. var newURL = ('https://' +
  123. location.host + '/search' +
  124. location.search + '&' +
  125. location.hash.substr(1));
  126.  
  127. newURL = urlFix(newURL);
  128.  
  129. location.replace(newURL);
  130. }
  131.  
  132.  
  133. if(location.href.indexOf('urlfixed=1') === -1){
  134. location.replace(urlFix(location.href));
  135. }
  136.  
  137. window.addEventListener('hashchange', hashChange, false);
  138.  
  139. })();