Google URL Cleaner

Remove url parameters not listed

  1. // ==UserScript==
  2. // @id Google URL Cleaner
  3. // @name Google URL Cleaner
  4. // @namespace vzjrz1@gmail.com
  5. // @description Remove url parameters not listed
  6. // @include http://www.google.tld/search?*
  7. // @include https://www.google.tld/search?*
  8. // @version 1.3
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. // Parameters to keep and in what order to reinsert
  14. var okParams = [
  15. 'q', // search parameter
  16. 'start', // current page parameter
  17. 'tbm', // search filter used eg: images, books, news
  18. 'tbs' // extra search parameters eg: show resolution on images, encoded image uploads
  19. ];
  20. var newParams = [];
  21.  
  22. okParams.forEach(function (item, index, array) {
  23. console.log(item, index);
  24. if (m = window.location.search.match(RegExp('[?&]' + item + '=([^?&]+)'))) {
  25. // newParams.push(item + '=' + m[1]); // Don't replace +'s with spaces
  26. newParams.push(item + '=' + m[1].replace(/\+/g, '%20'));
  27. }
  28. });
  29.  
  30. history.replaceState(null, 'Google URL Cleaner', 'search?' + newParams.join('&').replace(/&$/g, ''));