Greasy Fork 还支持 简体中文。

Greasy Fork - Scripts Links

Add more scripts' links on scripts listing.

目前為 2014-03-08 提交的版本,檢視 最新版本

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