Greasy Fork - More Install button

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

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

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