Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active June 14, 2023 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JustinGrote/0148f9accc7355f650cd0a0f6b404fa5 to your computer and use it in GitHub Desktop.
Save JustinGrote/0148f9accc7355f650cd0a0f6b404fa5 to your computer and use it in GitHub Desktop.
Tampermonkey script to add a "Open in Remote Repositories" button as well as open it in vscode when you press the comma key
// ==UserScript==
// @name GitHub in VSCode Remote Repository
// @version 0.0.1
// @description A userscript that adds a button to open a repo in VSCode using github1s
// @license MIT
// @author Justin Grote (Heavily borrowed from Rob Garrison)
// @namespace https://github.com/JustinGrote
// @include https://github.com/*
// @run-at document-end
// @grant none
// @connect github.com
// @connect githubusercontent.com
// @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=895926
// @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=882023
// @icon https://github.githubassets.com/pinned-octocat.svg
// @supportURL https://github.com/JustinGrote
// ==/UserScript==
/* global $ on make */
(() => {
"use strict";
// Icon modified from https://commons.wikimedia.org/wiki/File:Visual_Studio_Code_1.35_icon.svg
const vsCodeIcon = `
<svg width="1em" height="1em" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask id="mask0" mask-type="alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="256" height="256">
<path d="M176.049 250.669C180.838 255.459 188.13 256.7 194.234 253.764L246.94 228.419C252.478 225.755 256 220.154 256 214.008V42.1479C256 36.0025 252.478 30.4008 246.94 27.7374L194.234 2.39089C188.13 -0.544416 180.838 0.696607 176.049 5.48572C181.95 -0.41506 192.039 3.76413 192.039 12.1091V244.046C192.039 252.391 181.95 256.57 176.049 250.669Z" fill="white"/>
<path d="M181.379 180.646L114.33 128.633L181.379 75.5114V17.794C181.379 10.8477 173.128 7.20673 167.996 11.8862L74.6514 97.8518L31.1994 64.1438C27.1081 61.039 21.3851 61.294 17.5853 64.7476L3.48974 77.5627C-1.15847 81.7893 -1.16367 89.0948 3.47672 93.3292L167.98 244.185C173.107 248.887 181.379 245.249 181.379 238.292V180.646Z" fill="white"/>
<path d="M36.6937 134.195L3.47672 162.828C-1.16367 167.062 -1.15847 174.37 3.48974 178.594L17.5853 191.409C21.3851 194.863 27.1081 195.118 31.1994 192.013L69.4472 164.057L36.6937 134.195Z" fill="white"/>
</mask>
<g mask="url(#mask0)">
<path d="M167.996 11.8857C173.128 7.20627 181.379 10.8473 181.379 17.7936V75.5109L104.938 136.073L65.5742 106.211L167.996 11.8857Z" fill="#009A7C"/>
<path d="M36.6937 134.194L3.47672 162.827C-1.16367 167.062 -1.15847 174.37 3.48974 178.594L17.5853 191.409C21.3851 194.863 27.1081 195.118 31.1994 192.013L69.4472 164.056L36.6937 134.194Z" fill="#009A7C"/>
<g filter="url(#filter0_d)">
<path d="M181.379 180.645L31.1994 64.1427C27.1081 61.0379 21.3851 61.2929 17.5853 64.7465L3.48974 77.5616C-1.15847 81.7882 -1.16367 89.0937 3.47672 93.3281L167.972 244.176C173.102 248.881 181.379 245.241 181.379 238.28V180.645Z" fill="#00B294"/>
</g>
<g filter="url(#filter1_d)">
<path d="M194.233 253.766C188.13 256.701 180.837 255.46 176.048 250.671C181.949 256.571 192.039 252.392 192.039 244.047V12.1103C192.039 3.76535 181.949 -0.413839 176.048 5.48694C180.837 0.697824 188.129 -0.543191 194.233 2.3921L246.939 27.7386C252.478 30.402 256 36.0037 256 42.1491V214.009C256 220.155 252.478 225.757 246.939 228.42L194.233 253.766Z" fill="#24BFA5"/>
</g>
</g>
<defs>
<filter id="filter0_d" x="-21.3333" y="40.6413" width="224.045" height="226.988" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
<feOffset/>
<feGaussianBlur stdDeviation="10.6667"/>
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.15 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
</filter>
<filter id="filter1_d" x="154.715" y="-20.5169" width="122.618" height="297.191" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
<feOffset/>
<feGaussianBlur stdDeviation="10.6667"/>
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>
<feBlend mode="overlay" in2="BackgroundImageFix" result="effect1_dropShadow"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
</filter>
</defs>
</svg>
`;
const contentWrap = document.createElement("div");
contentWrap.className = "ghiv-content";
function init() {
const goToFileButton = document.querySelector("span.d-none.d-md-flex.ml-2");
if (!goToFileButton || $(".ghiv-link")) {
return;
}
const margin = goToFileButton.classList.contains("mr-2") ? "mr-2" : "ml-2";
const encodedUri = encodeURI(window.location.href);
const link = make({
el: "a",
className: `ghiv-link btn ${margin} tooltipped tooltipped-n`,
attrs: {
href: `vscode-insiders://github.remotehub/open?url=${encodedUri}`,
"aria-label":
"Open this repo in VS Code Insiders as a Remote Repository",
target: "_blank",
rel: "noopener noreferrer",
},
html: vsCodeIcon,
});
goToFileButton.before(link);
}
function openRemoteRepoOnCommaPress(evt) {
if (evt.code == "Comma" && evt.target.tagName == "BODY") {
const encodedUri = encodeURI(window.location.href);
window.location.href = `vscode-insiders://github.remotehub/open?url=${encodedUri}`;
}
}
document.addEventListener("keydown", openRemoteRepoOnCommaPress, true);
on(document, "ghmo:container pjax:end", init);
init();
})();
@aetonsi
Copy link

aetonsi commented May 8, 2023

It doesn't seem to work anymore, neither with vscode nor vscode-insiders..

@JustinGrote
Copy link
Author

@aetonsi yeah I've noticed, I think they don't register the same URI anymore. I'll look into it.

@aetonsi
Copy link

aetonsi commented Jun 12, 2023

https://gist.github.com/aetonsi/26d4257e439a94dfacb5b230fb4b438a

Script updated.
I added a "clone" button. The "open" button doesn't, since i don't know which vscode:// URL to open in order to emulated VSCode's Open Remote Repository/Open Repository from Github functionality. I tried with vscode-vfs:// URLs, no luck..

@JustinGrote
Copy link
Author

@aetonsi thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment