Github - Open with VSCode

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

Verze ze dne 21. 10. 2023. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Github - Open with VSCode
// @namespace    V@no
// @description  Fixes "Open with Visual Studio" button to open with VSCode instead
// @match        https://github.com/*
// @version      23.10.21-011323
// @license      MIT
// @run-at       document-end
// @grant        none
// ==/UserScript==

(() =>
{
	"use strict";
	/**
	 * This function fixes the link to open a GitHub repository in Visual Studio Code.
	 * It replaces the data-open-app attribute value from "visual-studio" to "vscode",
	 * adds " Code" to the link text, and updates the href attribute to launch VS Code
	 * with the clone URL of the repository.
	 * @returns {boolean} Returns true if the link element is not found.
	 */
	const fixLink = () =>
	{
		const elLink = document.querySelector('[data-open-app="visual-studio"]');
		if (!elLink)
			return true;

		// display "Launching Visual Studio Code..." message
		elLink.dataset.openApp = "vscode";
		elLink.innerHTML += " Code";
		const cloneURL = (document.querySelector(".input-group > .form-control") || {}).value;
		if (cloneURL)
			elLink.href = "vscode://vscode.git/clone?url=" + encodeURI(cloneURL);
		else
			elLink.href = elLink.href.replace("git-client://", "vscode://vscode.git/");

		//we don't need keep observing DOM changes anymore
		observer.disconnect();
	};

	const observer = new MutationObserver(fixLink);
	if (fixLink())
		observer.observe(document, {childList: true, subtree: true});
})();