Greasy Fork - Search scripts on other sites (Added more sites)

Add search option to search on Userscripts.org, OpenUserJS.org, MonkeyGuts.com (Code Remodified), Google.com(Beta;Work in progress;still functional) and Google Custom Search(Search all userscript websites with one click). Plus especially Userscripts-mirror.org(As Userscripts.org has shut down).

  1. // ==UserScript==
  2. // @id greasyfork-search-other-sites@hackscomicon
  3. // @name Greasy Fork - Search scripts on other sites (Added more sites)
  4. // @namespace https://github.com/LouCypher/userscripts
  5. // @description Add search option to search on Userscripts.org, OpenUserJS.org, MonkeyGuts.com (Code Remodified), Google.com(Beta;Work in progress;still functional) and Google Custom Search(Search all userscript websites with one click). Plus especially Userscripts-mirror.org(As Userscripts.org has shut down).
  6. // @icon http://www.mediafire.com/convkey/6b10/64gmr1m4qul6xalzg.jpg?size_id=2
  7. // @version 5.1
  8. // @author HACKSCOMICON Credits:LouCypher
  9. // @license MIT License
  10. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+Search+other+sites
  11. // @homepageURL https://greasyfork.org/en/scripts/9630
  12. // @supportURL https://greasyfork.org/en/scripts/9630/feedback
  13. // @resource LICENSE https://raw.githubusercontent.com/HACKSCOMICON/greasyforksearch/master/LICENSE
  14. // @include https://greasyfork.org/*
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. function $(aSelector, aNode) {
  19. return (aNode || document).querySelector(aSelector);
  20. }
  21.  
  22. function createElement(aTagName) {
  23. return document.createElement(aTagName);
  24. }
  25.  
  26. function createText(aText) {
  27. return document.createTextNode(aText);
  28. }
  29.  
  30. function createLink(aURL, aText, aName) {
  31. var link = createElement("a");
  32. aURL && (link.href = aURL);
  33. aText && (link.textContent = aText);
  34. aName && (link.name = aName);
  35. return link;
  36. }
  37.  
  38. function addStyle(aCSS) {
  39. var style = createElement("style");
  40. style.type = "text/css";
  41. style.textContent = aCSS;
  42. if (document.head)
  43. document.head.appendChild(style);
  44. else
  45. document.documentElement.appendChild(style);
  46. return style;
  47. }
  48.  
  49. var sites = [
  50. { name: "Userscripts.org", url: "http://userscripts.org/scripts/search?q=" },
  51. { name: "OpenUserJS", url: "https://openuserjs.org/?q=" },
  52. { name: "MonkeyGuts", url: "https://monkeyguts.com/index.php?search=" },
  53. { name: "Userscripts-mirror.org", url: "http://www.google.ro/cse?cx=006416817443944833046:kp4ssgm5w-8&ie=UTF-8&q=" },
  54. { name: "Google-Beta", url: "https://www.google.ro/webhp#q=userscript%20" },
  55. { name: "Google-Custom Search", url: "http://www.google.ro/cse?cx=006416817443944833046:icpbeh10o5k&ie=UTF-8&q=" }
  56. ];
  57.  
  58. function onsubmit(aEvent) {
  59. var searchURL;
  60. var query = aEvent.target.q.value;
  61. var site = $("#search-other-sites");
  62. switch (parseInt(site.value)) {
  63. case 6: searchURL = sites[6].url; break;
  64. case 5: searchURL = sites[4].url; break;
  65. case 4: searchURL = sites[3].url; break;
  66. case 3: searchURL = sites[2].url; break;
  67. case 2: searchURL = sites[1].url; break;
  68. case 1: searchURL = sites[0].url; break;
  69. default: searchURL = null;
  70. }
  71. if (searchURL) {
  72. aEvent.preventDefault();
  73. location.assign(searchURL + encodeURIComponent(query));
  74. }
  75. }
  76.  
  77. function onchange(aEvent) {
  78. var input = $("#script-search").q;
  79. switch (parseInt(aEvent.target.value)) {
  80. case 6: input.placeholder = "Search " + sites[5].name; break;
  81. case 5: input.placeholder = "Search " + sites[4].name; break;
  82. case 4: input.placeholder = "Search " + sites[3].name; break;
  83. case 3: input.placeholder = "Search " + sites[2].name; break;
  84. case 2: input.placeholder = "Search " + sites[1].name; break;
  85. case 1: input.placeholder = "Search " + sites[0].name; break;
  86. default: input.placeholder = "Search";
  87. }
  88. $("#script-search input[type='submit']").title = input.placeholder;
  89. }
  90.  
  91. var form = $("#script-search");
  92. if (form) {
  93. addStyle("#search-other-sites{width:19px;direction:rtl}" +
  94. "#link-other-sites li{line-height:1.5em}");
  95.  
  96. var select = form.insertBefore(createElement("select"), form.lastChild);
  97. select.id = "search-other-sites";
  98. select.title = "Search other sites";
  99. select.innerHTML = '<option value="0">Greasy Fork</option>'
  100. + '<option value="1">' + sites[0].name + '</option>'
  101. + '<option value="2">' + sites[1].name + '</option>'
  102. + '<option value="3">' + sites[2].name + '</option>'
  103. + '<option value="4">' + sites[3].name + '</option>'
  104. + '<option value="5">' + sites[4].name + '</option>'
  105. + '<option value="6">' + sites[5].name + '</option>';
  106.  
  107. select.addEventListener("change", onchange);
  108. form.addEventListener("submit", onsubmit);
  109. }
  110.  
  111. if (location.pathname === "/scripts/search") {
  112. var xpath = "//p[@id='script-list-sort']/following-sibling::p[text()='No scripts found.']";
  113. var p = document.evaluate(xpath, document, null, 9, null).singleNodeValue;
  114. if (p) {
  115. var query = $("#script-search").q.value;
  116. p.appendChild(createElement("br"));
  117. p.appendChild(createText("Search '" + query + "' on other sites:"));
  118. var ul = document.body.insertBefore(createElement("ul"), p.nextSibling);
  119. ul.id = "link-other-sites";
  120. var li;
  121. sites.forEach(function(site) {
  122. li = ul.appendChild(createElement("li"));
  123. li.appendChild(createLink(site.url + encodeURIComponent(query), site.name));
  124. });
  125. }
  126. }