Greasy Fork镜像 支持简体中文。

Greasy Fork镜像 - Search other sites

Add search option to search on Userscripts.org and *cough* OpenUserJS.org.

  1. // ==UserScript==
  2. // @id greasyfork-search-other-sites@loucypher
  3. // @name Greasy Fork镜像 - Search other sites
  4. // @namespace https://github.com/LouCypher/userscripts
  5. // @description Add search option to search on Userscripts.org and *cough* OpenUserJS.org.
  6. // @version 1.1
  7. // @author LouCypher
  8. // @license MIT License
  9. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+Search+other+sites
  10. // @homepageURL https://gf.qytechs.cn/scripts/259
  11. // @supportURL https://gf.qytechs.cn/scripts/259/feedback
  12. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/greasyfork/search-other-sites/LICENSE.txt
  13. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/greasyfork/search-other-sites/CHANGELOG.txt
  14. // @include https://gf.qytechs.cn/*
  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/search/" }
  52. ];
  53.  
  54. function onsubmit(aEvent) {
  55. var searchURL;
  56. var query = aEvent.target.q.value;
  57. var site = $("#search-other-sites");
  58. switch (parseInt(site.value)) {
  59. case 2: searchURL = sites[1].url; break;
  60. case 1: searchURL = sites[0].url; break;
  61. default: searchURL = null;
  62. }
  63. if (searchURL) {
  64. aEvent.preventDefault();
  65. location.assign(searchURL + encodeURIComponent(query));
  66. }
  67. }
  68.  
  69. function onchange(aEvent) {
  70. var input = $("#script-search").q;
  71. switch (parseInt(aEvent.target.value)) {
  72. case 2: input.placeholder = "Search " + sites[1].name; break;
  73. case 1: input.placeholder = "Search " + sites[0].name; break;
  74. default: input.placeholder = "Search";
  75. }
  76. $("#script-search input[type='submit']").title = input.placeholder;
  77. }
  78.  
  79. var form = $("#script-search");
  80. if (form) {
  81. addStyle("#search-other-sites{width:19px;direction:rtl}" +
  82. "#link-other-sites li{line-height:1.5em}");
  83.  
  84. var select = form.insertBefore(createElement("select"), form.lastChild);
  85. select.id = "search-other-sites";
  86. select.title = "Search other sites";
  87. select.innerHTML = '<option value="0">Greasy Fork镜像</option>'
  88. + '<option value="1">' + sites[0].name + '</option>'
  89. + '<option value="2">' + sites[1].name + '</option>';
  90.  
  91. select.addEventListener("change", onchange);
  92. form.addEventListener("submit", onsubmit);
  93. }
  94.  
  95. if (location.pathname === "/scripts/search") {
  96. var xpath = "//p[@id='script-list-sort']/following-sibling::p[text()='No scripts found.']";
  97. var p = document.evaluate(xpath, document, null, 9, null).singleNodeValue;
  98. if (p) {
  99. var query = $("#script-search").q.value;
  100. p.appendChild(createElement("br"));
  101. p.appendChild(createText("Search '" + query + "' on other sites:"));
  102. var ul = document.body.insertBefore(createElement("ul"), p.nextSibling);
  103. ul.id = "link-other-sites";
  104. var li;
  105. sites.forEach(function(site) {
  106. li = ul.appendChild(createElement("li"));
  107. li.appendChild(createLink(site.url + encodeURIComponent(query), site.name));
  108. });
  109. }
  110. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址