Greasy Fork - More Install button

Add install button on script Code, Versions and Feedback page.

  1. /* This program is free software. It comes without any warranty, to
  2. * the extent permitted by applicable law. You can redistribute it
  3. * and/or modify it under the terms of the Do What The Fuck You Want
  4. * To Public License, Version 2, as published by Sam Hocevar. See
  5. * http://www.wtfpl.net/ for more details. */
  6.  
  7. // ==UserScript==
  8. // @id greasy-fork-more-install-button@loucypher
  9. // @name Greasy Fork - More Install button
  10. // @namespace https://github.com/LouCypher/userscripts
  11. // @description Add install button on script Code, Versions and Feedback page.
  12. // @version 2.0
  13. // @author LouCypher
  14. // @license WTFPL
  15. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+More+Install+button
  16. // @homepageURL https://greasyfork.org/scripts/173
  17. // @supportURL https://greasyfork.org/scripts/173/feedback
  18. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/greasyfork/install-button/CHANGELOG.txt
  19. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/WTFPL/LICENSE.txt
  20. // @include https://greasyfork.org/scripts/*/code
  21. // @include https://greasyfork.org/scripts/*/versions
  22. // @include https://greasyfork.org/scripts/*/feedback
  23. // @grant none
  24. // ==/UserScript==
  25.  
  26. var blocked = /\/scripts\/(94|115|116|117|119|120|121|122|123|172)\//;
  27. var header, title;
  28. header = document.querySelector("#script-info header")
  29. if (header)
  30. title = header.querySelector("h2");
  31.  
  32. if (title) {
  33. /* Get CSRF authenticity token */
  34. var csrfToken = document.head.children["csrf-token"];
  35. var authToken = csrfToken ? "?authenticity_token=" +
  36. encodeURIComponent(csrfToken.content)
  37. : null;
  38.  
  39. /* Add Install button */
  40. var scriptId = location.href.match(/\d+/);
  41. var span = header.insertBefore(document.createElement("span"), title);
  42. var link = span.appendChild(document.createElement("a"));
  43. link.href = "/scripts/" + scriptId + "/code.user.js";
  44. link.dataset.pingUrl = "/scripts/" + scriptId + "/install-ping"
  45. + (authToken ? authToken : "");
  46. link.textContent = "Install";
  47. link.className = "install-link";
  48. link.style.cssFloat = "right";
  49.  
  50. if (blocked.test(location.href)) {
  51. link.href = "/scripts/under-assessment";
  52. link.style.backgroundColor = "maroon";
  53. link.addEventListener("click", function(aEvent) {
  54. aEvent.preventDefault();
  55. alert("This script is currently under review");
  56. });
  57. }
  58. }
  59.  
  60. else
  61. throw new Error("Sam Ting Wen Wong!"); // Terminate