PTH non-ascii search workaround

Redirect on searches that fail due to 16-bit non-ascii characters

  1. // ==UserScript==
  2. // @name PTH non-ascii search workaround
  3. // @version 0.2
  4. // @description Redirect on searches that fail due to 16-bit non-ascii characters
  5. // @author Chameleon
  6. // @include http*://redacted.ch/torrents.php?searchstr=*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/87476
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. if(document.body.innerHTML.indexOf('Your search did not match anything.') != -1)
  15. {
  16. var match=window.location.search.match(/%..%../g);
  17. if(match)
  18. {
  19. var newSearch=window.location.search;
  20. for(var i=0; i<match.length; i++)
  21. {
  22. var m=match[i];
  23. newSearch=newSearch.replace(m, "%"+m.split('%')[1]);
  24. }
  25. window.location = '/torrents.php'+newSearch;
  26. }
  27. }
  28. })();