Github - Open with VSCode

Fixes "Open with Visual Studio" button to open with VSCode instead

当前为 2023-10-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Github - Open with VSCode
  3. // @namespace V@no
  4. // @description Fixes "Open with Visual Studio" button to open with VSCode instead
  5. // @match https://github.com/*
  6. // @version 23.10.21-011323
  7. // @license MIT
  8. // @run-at document-end
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (() =>
  13. {
  14. "use strict";
  15. /**
  16. * This function fixes the link to open a GitHub repository in Visual Studio Code.
  17. * It replaces the data-open-app attribute value from "visual-studio" to "vscode",
  18. * adds " Code" to the link text, and updates the href attribute to launch VS Code
  19. * with the clone URL of the repository.
  20. * @returns {boolean} Returns true if the link element is not found.
  21. */
  22. const fixLink = () =>
  23. {
  24. const elLink = document.querySelector('[data-open-app="visual-studio"]');
  25. if (!elLink)
  26. return true;
  27.  
  28. // display "Launching Visual Studio Code..." message
  29. elLink.dataset.openApp = "vscode";
  30. elLink.innerHTML += " Code";
  31. const cloneURL = (document.querySelector(".input-group > .form-control") || {}).value;
  32. if (cloneURL)
  33. elLink.href = "vscode://vscode.git/clone?url=" + encodeURI(cloneURL);
  34. else
  35. elLink.href = elLink.href.replace("git-client://", "vscode://vscode.git/");
  36.  
  37. //we don't need keep observing DOM changes anymore
  38. observer.disconnect();
  39. };
  40.  
  41. const observer = new MutationObserver(fixLink);
  42. if (fixLink())
  43. observer.observe(document, {childList: true, subtree: true});
  44. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址