Skip to content

Instantly share code, notes, and snippets.

@kofigumbs
Created December 17, 2020 03:58
Show Gist options
  • Save kofigumbs/b5f393f4e05160d7764336a851dd8a6d to your computer and use it in GitHub Desktop.
Save kofigumbs/b5f393f4e05160d7764336a851dd8a6d to your computer and use it in GitHub Desktop.
Multi URL bar, Cmd-K
document.addEventListener("keydown", event => {
if (event.metaKey && event.key === "k") {
event.preventDefault();
const input = document.createElement("input");
input.required = true;
input.type = "url";
input.placeholder = "URL";
input.style.position = "absolute";
input.style.top = "0";
input.style.left = "0";
input.style.right = "0";
input.style.zIndex = "2147483647"; // https://stackoverflow.com/a/856569
input.style.padding = "1rem";
input.style.textAlign = "center";
input.style.fontSize = "16px";
input.style.fontFamily = "monospace";
const form = document.createElement("form");
form.appendChild(input);
form.addEventListener("submit", e => {
e.preventDefault();
window.location.href = input.value
});
document.body.appendChild(form);
input.focus();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment