GitHub Clone URL Username Adder

Adds username to clone URL and a button to clone using TortoiseGit

  1. // ==UserScript==
  2. // @name GitHub Clone URL Username Adder
  3. // @id github-clone-url-username-adder
  4. // @namespace github-username-adder
  5.  
  6. // @description Adds username to clone URL and a button to clone using TortoiseGit
  7. // @version 0.1.2
  8. // @screenshot https://raw.githubusercontent.com/KOLANICH/github-clone-url-username-adder-userscript/master/images/github_repo.png https://raw.githubusercontent.com/KOLANICH/github-clone-url-username-adder-userscript/master/images/gist_repo.PNG
  9.  
  10. // @author KOLANICH
  11. // @copyright KOLANICH, 2015
  12. // @license Unlicensed
  13. // @contributionURL https://github.com/KOLANICH/github-clone-url-username-adder-userscript
  14. // @contributionAmount feel free to fork and contribute
  15.  
  16. // @include /https?://(?:gist\.)?github.com/[\w_ -]+/.+/?/
  17. // @grant none
  18. // @noframes 1
  19. // @run-at document-idle
  20. // @optimize 1
  21. // ==/UserScript==
  22. /*This is free and unencumbered software released into the public domain.
  23.  
  24. Anyone is free to copy, modify, publish, use, compile, sell, or
  25. distribute this software, either in source code form or as a compiled
  26. binary, for any purpose, commercial or non-commercial, and by any
  27. means.
  28.  
  29. In jurisdictions that recognize copyright laws, the author or authors
  30. of this software dedicate any and all copyright interest in the
  31. software to the public domain. We make this dedication for the benefit
  32. of the public at large and to the detriment of our heirs and
  33. successors. We intend this dedication to be an overt act of
  34. relinquishment in perpetuity of all present and future rights to this
  35. software under copyright law.
  36.  
  37. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  38. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  39. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  40. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  41. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  42. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  43. OTHER DEALINGS IN THE SOFTWARE.
  44.  
  45. For more information, please refer to <http://unlicense.org/>*/
  46.  
  47. "use strict";
  48. const githubForWindowsPrefix="github-windows://openRepo/";
  49. const tortoiseGitPrefix="tgit://clone/";
  50. try{
  51. let authorName=document.getElementsByName("octolytics-actor-login")[0].content;
  52. let cloneURLBox=document.querySelector('[data-protocol-type="http"]').getElementsByTagName("INPUT")[0];
  53. let link=document.createElement("A");
  54. link.href=cloneURLBox.value;
  55. link.username=authorName;
  56. cloneURLBox.value=link.href;
  57. link.href=tortoiseGitPrefix+link.href;
  58. link.innerHTML="<span class=\"octicon octicon-device-desktop\"></span> Clone to TortoiseGit";
  59. let cloneGHBtn;
  60. {//dealing with bug in gist.github.com : doubling clone-options
  61. let cloneOptions=document.getElementsByClassName("clone-options");
  62. cloneGHBtn=cloneOptions[cloneOptions.length-1].nextElementSibling;
  63. }
  64. cloneGHBtn.href=cloneGHBtn.href.substring(githubForWindowsPrefix.length);
  65. cloneGHBtn.username=authorName;
  66. cloneGHBtn.href=githubForWindowsPrefix+cloneGHBtn.href;
  67. link.className=cloneGHBtn.className;
  68. cloneGHBtn.parentNode.insertBefore(link,cloneGHBtn.nextElementSibling);
  69. }catch(err){
  70. console.error(err);
  71. }