├── .gitignore ├── manifest.json ├── package.json ├── LICENSE.txt ├── contentscript.js ├── README.md └── static └── vscode.svg /.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | node_modules 3 | web-ext-artifacts -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Open in Visual Studio Code", 3 | "description": "Adds open in Visual Studio Code to GitHub repos", 4 | "version": "1.0.2", 5 | "manifest_version": 2, 6 | "web_accessible_resources": ["static/vscode.svg"], 7 | "content_scripts": [ 8 | { 9 | "matches": ["*://github.com/*"], 10 | "js": ["contentscript.js"] 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openincode", 3 | "version": "1.0.0", 4 | "description": "A browser extension that adds an \"Open in Visual Studio Code\" option to GitHub repos.", 5 | "main": "contentscript.js", 6 | "scripts": { 7 | "run": "web-ext run --verbose", 8 | "build": "web-ext build --overwrite-dest" 9 | }, 10 | "keywords": [], 11 | "author": "Joseph Diragi", 12 | "license": "MIT", 13 | "devDependencies": { 14 | "web-ext": "^7.2.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Joseph Diragi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /contentscript.js: -------------------------------------------------------------------------------- 1 | (() => { 2 | mutationObserver = window.MutationObserver || window.WebKitMutationObserver; 3 | var observer = new MutationObserver(function(mutations, observer) { 4 | let ghCodeDropdown = getDropUL(); 5 | if (ghCodeDropdown != undefined) { 6 | ghCodeDropdown.appendChild(openInCodeElement(`${document.URL}.git`)); 7 | } 8 | }) 9 | 10 | observer.observe(document, { 11 | subtree: true, 12 | attributes: true 13 | }); 14 | 15 | function openInCodeElement(repo) { 16 | // If the LI is already here, return 17 | if (document.getElementById("openincode") != null) return; 18 | // List item 19 | const openInCodeLI = document.createElement("li"); 20 | openInCodeLI.id = "openincode"; 21 | openInCodeLI.classList.add(...["Box-row", "Box-row--hover-gray", "p-3", "mt-0"]); 22 | // List child element / link 23 | const openInCodeA = document.createElement("a"); 24 | openInCodeA.classList.add(...["d-flex", "flex-items-center", "color-fg-default", "text-bold", "no-underline"]); 25 | openInCodeA.rel = "nofollow"; 26 | // TODO: Add option to clone with SSH 27 | openInCodeA.href = `vscode://vscode.git/clone?url=${encodeURI(repo)}`; 28 | // Add logo 29 | const logo = document.createElement("img"); 30 | logo.src = browser.runtime.getURL("static/vscode.svg"); 31 | logo.setAttribute("viewBox", "0 0 16 16"); 32 | logo.setAttribute("class", "mr-2"); 33 | logo.width = 16; 34 | logo.height = 16; 35 | openInCodeA.appendChild(logo); 36 | // Add label 37 | openInCodeA.appendChild(document.createTextNode("Open in Visual Studio Code")); 38 | // Add openInCodeA to LI 39 | openInCodeLI.appendChild(openInCodeA); 40 | return openInCodeLI; 41 | } 42 | 43 | function getDropUL() { 44 | // Find get-repo modal 45 | const dropDownDiv = document.querySelectorAll('[data-target="get-repo.modal"]'); 46 | // There will only be one code dropdown 47 | if (dropDownDiv.length != 1) return; 48 | let getRepoModal = dropDownDiv[0]; 49 | // Find the
2 |
3 |