GitHubSourceTree

Adds a "Clone in SourceTree" button to github pages

当前为 2015-09-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHubSourceTree
  3. // @namespace http://really-serious.biz/
  4. // @version 1.1.2
  5. // @description Adds a "Clone in SourceTree" button to github pages
  6. // @respository https://github.com/jamesgarfield/GitHubSourceTree
  7. // @match https://github.com/*
  8. // @match https://*.github.com/*
  9. // @grant none
  10. // @licence MIT(3)
  11. // @copyright 2014+, James Garfield
  12. // ==/UserScript==
  13.  
  14. //Firefox/GreaseMonkey apppears to not like IIFEs, so use of a named function is required
  15. ghst_init();
  16. function ghst_init(){
  17. const $ = document.querySelectorAll.bind(document);
  18.  
  19. //GitHub's "Clone in Desktop" Button
  20. const gitHubNode = $(".clone-options + a")[0]
  21. const parentNode = gitHubNode.parentNode;
  22.  
  23. //Insert our button between the GitHub Clone button and whatever is after it.
  24. const insertBeforeNode = gitHubNode.nextSibling;
  25. //Find the clone url for this repo
  26. const gitURL = $(".js-url-field")[0].value
  27.  
  28. var sourceTreeNode = gitHubNode.cloneNode();
  29. sourceTreeNode.href = 'sourcetree://cloneRepo/' + gitURL;
  30. sourceTreeNode.innerHTML = '<span class="octicon octicon-device-desktop"></span>&nbsp;Clone in SourceTree';
  31. parentNode.insertBefore(sourceTreeNode, insertBeforeNode);
  32. }