Created
June 24, 2026 23:27
-
-
Save LeaVerou/d991f76a9a45dd90a3fcf5261e13006c to your computer and use it in GitHub Desktop.
Bookmarklet to open GitHub URL locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(() => { | |
| const BASE = '/Users/lea/code'; | |
| const g = new URLPattern( | |
| 'https://github.com/:owner/:repo{/:kind(blob|tree|edit)}?{/:ref}?{/:file(.*)}?' | |
| ).exec(location)?.pathname.groups; | |
| if (!g) return alert('Not a GitHub repo URL'); | |
| const line = location.hash.match(/^#L(\d+)/)?.[1] ?? ''; | |
| location.href = | |
| `vscode://file${BASE}/${g.repo}${g.file ? `/${g.file}` : ''}${line && `:${line}`}`; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment