OpenWithVSCode

快速将GitHub项目下载到本地,并支持选择VSCode或VSCodeInsiders

  1. // ==UserScript==
  2. // @name OpenWithVSCode
  3. // @name:en OpenWithVSCode
  4. // @version 1.1.4
  5. // @description 快速将GitHub项目下载到本地,并支持选择VSCode或VSCodeInsiders
  6. // @description:en Quickly download GitHub project to local and choose VSCode or VSCodeInsiders
  7. // @author hoorn
  8. // @icon https://code.visualstudio.com/favicon.ico
  9. // @license MIT
  10. // @compatible chrome Latest
  11. // @compatible firefox Latest
  12. // @compatible edge Latest
  13. // @noframes
  14. // @grant window.onurlchange
  15. // @match https://github.com/*
  16. // @namespace https://greasyfork.org/users/1276388
  17. // ==/UserScript==
  18.  
  19. (() => {
  20. "use strict";
  21.  
  22. const actions = document.querySelector('.pagehead-actions');
  23. if (!actions || document.getElementById('openwithvscode-button')) return;
  24.  
  25. actions.insertAdjacentHTML('afterBegin', `
  26. <li>
  27. <div class="BtnGroup">
  28. <a id="openwithvscode-button" class="btn btn-sm BtnGroup-item">OpenVSCode</a>
  29. <a id="openwithvscodeinsiders-button" class="btn btn-sm BtnGroup-item">OpenInsiders</a>
  30. </div>
  31. </li>`);
  32.  
  33. const projectUrl = window.location.href + ".git";
  34.  
  35. document.getElementById('openwithvscode-button').addEventListener('click', e => {
  36. e.preventDefault();
  37. window.location.href = `vscode://vscode.git/clone?url=${projectUrl}`;
  38. });
  39.  
  40. document.getElementById('openwithvscodeinsiders-button').addEventListener('click', e => {
  41. e.preventDefault();
  42. window.location.href = `vscode-insiders://vscode.git/clone?url=${projectUrl}`;
  43. });
  44.  
  45. })();