Greasy Fork - Scripts Links

Add more scripts' links on scripts listing.

As of 2014-03-07. See the latest version.

  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 2.0
  7. // @author LouCypher
  8. // @license MIT License
  9. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+Scripts+Links
  10. // @homepageURL https://greatest.deepsurf.us/scripts/174
  11. // @supportURL https://greatest.deepsurf.us/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://greatest.deepsurf.us/scripts*
  15. // @include https://greatest.deepsurf.us/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. var user = $(".user-profile-link a"); // Check if you're logged in
  51.  
  52. /* Get CSRF authenticity token */
  53. var csrfToken = $("head").children["csrf-token"];
  54. var authToken = csrfToken ? "?authenticity_token=" +
  55. encodeURIComponent(csrfToken.content)
  56. : null;
  57.  
  58. var scriptBoxes = $$(".script-list article");
  59. //GM_log(scriptBoxes.length);
  60. if (scriptBoxes.length) {
  61. GM_addStyle(".script-list li{height:200px!important}");
  62.  
  63. var box, node, href;
  64. for (var i = 0; i < scriptBoxes.length; i++) {
  65. box = scriptBoxes[i];
  66. node = box.insertBefore(createElement("p"), $("footer", box));
  67. href = $("h2 a", box).getAttribute("href"); // Script page URL
  68.  
  69. node.appendChild(addLink(href + "/code.user.js", "install", "",
  70. href + "/install-ping"
  71. + (authToken ? authToken : "")));
  72.  
  73. separate(node, true);
  74. node.appendChild(addLink(href + "/code", "code"));
  75.  
  76. separate(node, true);
  77. node.appendChild(addLink(href + "/versions", "versions"));
  78.  
  79. separate(node, true);
  80. node.appendChild(addLink(href + "/feedback", "feedback"));
  81.  
  82. // Add 'update' link if you're logged in and it's your own script
  83. if (user && $(".script-list-author a", box).href === user.href) {
  84. separate(node, true);
  85. node.appendChild(addLink(href + "/versions/new", "update"));
  86. }
  87. }
  88. }
  89.  
  90. /* Sonny's Greasy Fork user script */
  91. document.addEventListener("DOMContentLoaded", function() {
  92. var scriptTable = $("#script-table");
  93. if (scriptTable) {
  94. GM_addStyle("#script-table tr > td:nth-child(2) span{float:right}" +
  95. "#script-table tr > td:nth-child(2) a.script-link" +
  96. "{display:inline;padding:0 .5em}");
  97.  
  98. var cells = $$("td:nth-child(2)", scriptTable);
  99. //GM_log(cells.length);
  100. if (cells.length) {
  101. var cell, node, link, href, authorColumn, mine;
  102. for (var i = 0; i < cells.length; i++) {
  103. cell = cells[i];
  104. link = $("a", cell); // Script page link
  105. href = link.getAttribute("href"); // Script page URL
  106.  
  107. node = cell.appendChild(createElement("span"));
  108.  
  109. node.appendChild(addLink(href + "/code.user.js", "I",
  110. "Install " + link.textContent,
  111. href + "/install-ping"
  112. + (authToken ? authToken : "")));
  113.  
  114. separate(node);
  115. node.appendChild(addLink(href + "/code", "C", "Code"));
  116.  
  117. separate(node);
  118. node.appendChild(addLink(href + "/versions", "V", "Version"));
  119.  
  120. separate(node);
  121. node.appendChild(addLink(href + "/feedback", "F", "Feedback"));
  122.  
  123. // Check if you're logged in and it's own your script
  124. authorColumn = $("td:nth-child(4) a", cell.parentNode);
  125. if (authorColumn)
  126. mine = authorColumn.href === user.href;
  127. else
  128. mine = location.href.indexOf(user.href) === 0;
  129. // Add 'update' link if you're logged in and it's your own script
  130. if (user && mine) {
  131. separate(node);
  132. node.appendChild(addLink(href + "/versions/new", "U",
  133. "Update " + link.textContent));
  134. }
  135. }
  136. }
  137. }
  138. });