Greasy Fork is available in English.

Copy SSH URL Button for github.com

Adds a button to copy SSH clone URL on GitHub repositories when logged out.

Fra 05.06.2024. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name Copy SSH URL Button for github.com
  3. // @namespace Violentmonkey Scripts
  4. // @match https://github.com/*/*
  5. // @grant none
  6. // @version 1.1
  7. // @author Matthew Hugley
  8. // @description Adds a button to copy SSH clone URL on GitHub repositories when logged out.
  9. // @license BSD 3-Clause
  10. // ==/UserScript==
  11.  
  12. function addCopySSHButton() {
  13. const button = document.createElement("button");
  14. button.textContent = "Copy SSH URL";
  15. button.style.cssText = `
  16. position: absolute;
  17. left: 50%;
  18. top: 2%;
  19. transform: translateX(-50%);
  20. z-index: 1000;
  21. padding: 10px 20px;
  22. border: none;
  23. border-radius: 5px;
  24. background-color: #007bff;
  25. color: white;
  26. cursor: pointer;
  27. box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  28. transition: filter 0.15s;
  29. `;
  30.  
  31. button.onmouseover = function () {
  32. button.style.transform = "translateX(-50%) scale(0.97)";
  33. };
  34.  
  35. button.onmouseout = function () {
  36. button.style.transform = "translateX(-50%)";
  37. };
  38.  
  39. button.onclick = function () {
  40. const repoUrl = window.location.href;
  41. const sshUrl = repoUrl.replace("https://github.com/", "git@github.com:").replace(/\/$/, "") + ".git";
  42. navigator.clipboard.writeText(sshUrl).then(
  43. function () {
  44. alert("SSH URL copied to clipboard:\n" + sshUrl);
  45. },
  46. function (err) {
  47. console.error("Could not copy SSH URL:", err);
  48. }
  49. );
  50. };
  51.  
  52. document.body.appendChild(button);
  53. }
  54.  
  55. addCopySSHButton();