Skip to content

Instantly share code, notes, and snippets.

@jlewi
Created December 28, 2024 22:57
Show Gist options
  • Save jlewi/2de0556f23489a53cf687ec8d2d716a0 to your computer and use it in GitHub Desktop.
Save jlewi/2de0556f23489a53cf687ec8d2d716a0 to your computer and use it in GitHub Desktop.
vscodeuri
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VSCode URI Generator</title>
<script>
document.addEventListener("DOMContentLoaded", () => {
// Retrieve the BasePath variable from local storage
const basePath = localStorage.getItem("BasePath");
// Check if BasePath exists in storage
if (!basePath) {
document.getElementById("output").innerHTML = `
<p style="color: red;">BasePath is not set in local storage!</p>
`;
return;
}
// Construct the vscode URI
const vscodeUri = `vscode://file/${basePath}`;
// Display the link in the output
const linkElement = document.createElement("a");
linkElement.href = vscodeUri;
linkElement.textContent = vscodeUri;
linkElement.style.color = "blue";
linkElement.style.textDecoration = "underline";
document.getElementById("output").appendChild(linkElement);
});
// Helper function to set BasePath in local storage for testing
function setBasePath() {
const inputPath = document.getElementById("basePathInput").value;
localStorage.setItem("BasePath", inputPath);
alert("BasePath set successfully!");
}
</script>
</head>
<body>
<h1>VSCode URI Generator</h1>
<p>
This page reads the <strong>BasePath</strong> variable from your browser's local storage and constructs a VSCode URI.
</p>
<div>
<label for="basePathInput">Set BasePath:</label>
<input type="text" id="basePathInput" placeholder="/path/to/folder">
<button onclick="setBasePath()">Set BasePath</button>
</div>
<h2>Generated Link:</h2>
<div id="output"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment