Open with VSCode

Support Open Remote Repo in GitHub Code menu!

当前为 2021-07-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Open with VSCode
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.0
  5. // @description Support Open Remote Repo in GitHub Code menu!
  6. // @author Sanonz <sanonz@126.com>
  7. // @match https://github.com/*/*
  8. // @icon https://github.githubassets.com/pinned-octocat.svg
  9. // @homepage https://sanonz.github.io
  10. // @supportURL https://github.com/sanonz
  11. // @grant none
  12. // @run-at document-idle
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. function render() {
  19. var ul = document.querySelector('[data-target="get-repo.modal"] > ul');
  20.  
  21. var li = document.createElement('li');
  22. li.className = 'Box-row Box-row--hover-gray p-0 rounded-0';
  23.  
  24. var a = document.createElement('a');
  25. a.className = 'd-flex flex-items-center color-text-primary text-bold no-underline p-3';
  26. a.rel = 'nofollow';
  27. a.href = `vscode://github.remotehub/open?url=${encodeURIComponent(location.href)}`;
  28.  
  29. var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  30. svg.setAttribute('width', 16);
  31. svg.setAttribute('height', 15);
  32. svg.setAttribute('viewBox', '0 0 1024 1024');
  33. svg.setAttribute('version', '1.1');
  34. svg.setAttribute('class', 'octicon mr-3');
  35. svg.setAttribute('aria-hidden', 'true');
  36.  
  37. var path = document.createElementNS(svg.namespaceURI, 'path');
  38. path.setAttribute('d', 'M746.222933 102.239573l-359.799466 330.820267L185.347413 281.4976 102.2464 329.864533l198.20544 182.132054-198.20544 182.132053 83.101013 48.510293 201.076054-151.558826 359.799466 330.676906 175.527254-85.251413V187.4944z m0 217.57952v384.341334l-255.040853-192.177494z');
  39.  
  40. var text = document.createTextNode('Open with VSCode');
  41.  
  42. svg.appendChild(path);
  43. a.appendChild(svg);
  44. a.appendChild(text);
  45. li.appendChild(a);
  46. ul.insertBefore(li, ul.children[0]);
  47. }
  48.  
  49. window.addEventListener('pjax:complete', function(evt) {
  50. const pathnames = location.pathname.substr(1).split('/');
  51. if (pathnames.length === 2) {
  52. render();
  53. }
  54. });
  55.  
  56. render();
  57. })();