Greasy Fork镜像 - Scripts Links

Add more scripts' links on scripts listing.

目前为 2014-03-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @id greasy-fork-scripts-links@loucypher
  3. // @name Greasy Fork镜像 - Scripts Links
  4. // @namespace https://userscripts.org/users/12
  5. // @description Add more scripts' links on scripts listing.
  6. // @version 3.3
  7. // @author LouCypher
  8. // @license MIT License
  9. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+Scripts+Links
  10. // @homepageURL https://gf.qytechs.cn/scripts/174
  11. // @supportURL https://gf.qytechs.cn/scripts/174/feedback
  12. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/greasyfork/scripts-links/LICENSE.txt
  13. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/greasyfork/scripts-links/CHANGELOG.txt
  14. // @include https://gf.qytechs.cn/scripts*
  15. // @include https://gf.qytechs.cn/users/*
  16. // @run-at document-end
  17. // @grant GM_addStyle
  18. // @grant GM_log
  19. // ==/UserScript==
  20.  
  21. function $(aSelector, aNode) {
  22. return (aNode || document).querySelector(aSelector);
  23. }
  24.  
  25. function $$(aSelector, aNode) {
  26. return (aNode || document).querySelectorAll(aSelector);
  27. }
  28.  
  29. function createElement(aNodeName) {
  30. return document.createElement(aNodeName);
  31. }
  32.  
  33. function addLink(aURL, aText, aTitle, aPingURL) {
  34. var link = createElement("a");
  35. link.className = "script-link";
  36. link.href = aURL;
  37. link.textContent = aText;
  38. if (aTitle)
  39. link.title = aTitle;
  40. if (aPingURL)
  41. link.dataset.pingUrl = aPingURL;
  42. return link;
  43. }
  44.  
  45. function addSeparator(aNode, aSpaces) {
  46. return aNode.appendChild(document.createTextNode(aSpaces ? " | " : "|"));
  47. }
  48.  
  49. function underReview(aEvent) {
  50. aEvent.preventDefault();
  51. var scriptTitle = aEvent.target.dataset.scriptTitle;
  52. alert(scriptTitle + " is currently under review");
  53. }
  54.  
  55. // Opera UserJS doesn't recognize GM API so we rewrite the functions
  56. if (typeof GM_addStyle !== "function" && GM_log !== "function") {
  57. function GM_addStyle(aCSS) {
  58. var style = createElement("style");
  59. style.type = "text/css";
  60. style.textContent = aCSS;
  61. $("head").appendChild(style);
  62. }
  63.  
  64. function GM_log(aText) {
  65. console.log(aText);
  66. }
  67. }
  68.  
  69. var blocked = /\/(115|116|117|119|120|121|122|123|172)$/;
  70. var user = $(".user-profile-link a"); // Check if you're logged in
  71.  
  72. /* Get CSRF authenticity token */
  73. var csrfToken = $("head").children["csrf-token"];
  74. var authToken = csrfToken ? "?authenticity_token=" +
  75. encodeURIComponent(csrfToken.content)
  76. : null;
  77.  
  78. var scriptBoxes = $$(".script-list article");
  79. //GM_log(scriptBoxes.length);
  80. if (scriptBoxes.length) {
  81. GM_addStyle(".script-links .script-link{padding:0 .25em}");
  82.  
  83. var box, node, name, href, install;
  84. for (var i = 0; i < scriptBoxes.length; i++) {
  85. box = scriptBoxes[i];
  86. name = $("h2 a", box).textContent; // Script title
  87. href = $("h2 a", box).getAttribute("href"); // Script page URL
  88. node = box.insertBefore(createElement("p"), $("footer", box));
  89. node.className = "script-links";
  90.  
  91. install = node.appendChild(addLink(href + "/code.user.js", "install", "",
  92. href + "/install-ping"
  93. + (authToken ? authToken : "")));
  94. if (blocked.test(href)) {
  95. install.href = "/scripts/under-assessment";
  96. install.removeAttribute("data-ping-url");
  97. install.dataset.scriptTitle = name;
  98. install.addEventListener("click", underReview);
  99. }
  100.  
  101. addSeparator(node);
  102. node.appendChild(addLink(href + "/code", "code"));
  103.  
  104. addSeparator(node);
  105. node.appendChild(addLink(href + "/versions", "versions"));
  106.  
  107. addSeparator(node);
  108. node.appendChild(addLink(href + "/feedback", "feedback"));
  109.  
  110. // Add 'update' and 'sync' links if you're logged in and it's your own script
  111. if (user && $(".script-list-author a", box).href === user.href) {
  112. addSeparator(node);
  113. node.appendChild(addLink(href + "/versions/new", "update"));
  114. addSeparator(node);
  115. node.appendChild(addLink(href + "/sync", "sync"));
  116. }
  117. }
  118. }
  119.  
  120. /* Sonny's Greasy Fork镜像 user script */
  121. document.addEventListener("DOMContentLoaded", function() {
  122. var scriptTable = $("#script-table");
  123. if (scriptTable) {
  124. GM_addStyle("#script-table tr > td:nth-child(2) a.script-link" +
  125. "{display:inline}");
  126.  
  127. var cells = $$("td:nth-child(2)", scriptTable);
  128. //GM_log(cells.length);
  129. if (cells.length) {
  130. var cell, node, link, name, href, install, userId, authorColumn, mine;
  131. for (var i = 0; i < cells.length; i++) {
  132. cell = cells[i];
  133. name = $("a", cell).textContent; // Script title
  134. link = $("a", cell); // Script page link
  135. href = link.getAttribute("href"); // Script page URL
  136.  
  137. node = cell.appendChild(createElement("span"));
  138. node.className = "script-links";
  139.  
  140. install = node.appendChild(addLink(href + "/code.user.js", "I",
  141. "Install " + link.textContent,
  142. href + "/install-ping"
  143. + (authToken ? authToken : "")));
  144. if (blocked.test(href)) {
  145. install.href = "/scripts/under-assessment";
  146. install.removeAttribute("data-ping-url");
  147. install.dataset.scriptTitle = name;
  148. install.addEventListener("click", underReview);
  149. }
  150.  
  151. addSeparator(node);
  152. node.appendChild(addLink(href + "/code", "C", "Code"));
  153.  
  154. addSeparator(node);
  155. node.appendChild(addLink(href + "/versions", "V", "Version"));
  156.  
  157. addSeparator(node);
  158. node.appendChild(addLink(href + "/feedback", "F", "Feedback"));
  159.  
  160. if (user) { // If logged in
  161. userId = parseInt(user.href.match(/\d+/));
  162.  
  163. // Check if it's own your script
  164. authorColumn = $("td:nth-child(4) a", cell.parentNode);
  165. if (authorColumn)
  166. mine = authorColumn.href === user.href;
  167. else
  168. mine = parseInt(location.href.match(/\d+/)) === userId;
  169.  
  170. // Add 'update' and 'sync' links if you're logged in and it's your own script
  171. if (mine) {
  172. addSeparator(node);
  173. node.appendChild(addLink(href + "/versions/new", "U", "Update"));
  174.  
  175. addSeparator(node);
  176. node.appendChild(addLink(href + "/sync", "S", "Sync"));
  177. }
  178. }
  179. }
  180. }
  181. }
  182. });

QingJ © 2025

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