PTH Search requests on failed search

Add a link to the 'Your search did not match anything' page to search for a request with the same search

  1. // ==UserScript==
  2. // @name PTH Search requests on failed search
  3. // @version 0.3
  4. // @description Add a link to the 'Your search did not match anything' page to search for a request with the same search
  5. // @author Chameleon
  6. // @include http*://redacted.ch/torrents.php*
  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 a=document.createElement('a');
  17. a.innerHTML = 'Search Requests';
  18. var b=document.getElementsByClassName('box pad')[0];
  19. b.appendChild(document.createElement('br'));
  20. b.appendChild(a);
  21.  
  22. var search="search="+encodeURIComponent(document.getElementById('search_terms').getElementsByTagName('input')[0].value);
  23. var tags=document.getElementById('tagfilter').getElementsByTagName('input')[0].value;
  24. if(tags.length > 0)
  25. search+="&tags="+encodeURIComponent();
  26. var tags_type0 = document.getElementById('tags_type0').checked;
  27. var tags_type1 = document.getElementById('tags_type1').checked;
  28. if(tags_type0 || tags_type1)
  29. search+="&tags_type="+(tags_type0 ? '0':'1');
  30.  
  31. var anyType=false;
  32.  
  33. for(var i=1; i<8; i++)
  34. {
  35. if(document.getElementById('cat_'+i).checked)
  36. {
  37. anyType=true;
  38. }
  39. }
  40. if(anyType)
  41. {
  42. for(var i=1; i<8; i++)
  43. {
  44.  
  45. if(document.getElementById('cat_'+i).checked)
  46. {
  47. search+="&"+encodeURIComponent("filter_cat["+i+"]=1");
  48. }
  49. }
  50. }
  51.  
  52. a.href="/requests.php?"+search;
  53.  
  54. //a.href='javascript:void(0);';
  55. //a.addEventListener('click', searchRequests, false);
  56. }
  57. })();
  58.  
  59. function searchRequests()
  60. {
  61. var form=document.createElement('form');
  62. form.setAttribute('action', '/requests.php');
  63. form.setAttribute('action_method', 'get');
  64.  
  65. var search=document.getElementById('search_terms').getElementsByTagName('input')[0];
  66. search.setAttribute('name', 'search');
  67. form.appendChild(search);
  68.  
  69. var tags=document.getElementById('tagfilter').getElementsByTagName('input')[0];
  70. tags.setAttribute('name', 'tags');
  71. form.appendChild(tags);
  72.  
  73. form.appendChild(document.getElementById('tags_type0'));
  74. form.appendChild(document.getElementById('tags_type1'));
  75.  
  76. for(var i=1; i<8; i++)
  77. {
  78. form.appendChild(document.getElementById('cat_'+i));
  79. }
  80.  
  81. form.submit();
  82. }