Keyboard shortcut to edit profile or now page

Hey everyone! I’m not sure I can say this is my idea because I think I got it from someone mentioning it on Adam’s livestream or maybe on IRC…

Anyways… if you see yourself, like me, constantly going back and forth between your profile page and the editor here’s some yummy spaghetti code that would be cool to add to your “Additional <head> content” (be sure to replace YOUR-ADDRESS):

<script>
document.addEventListener('keydown',  event => {
  if (event.key === ".") {
    if (window.location.href.slice(-4) === "/now" || window.location.href.slice(-5) === "/now/"){
      window.location.assign("https://home.omg.lol/address/YOUR-ADDRESS/now");
    } else {
      window.location.assign("https://home.omg.lol/address/YOUR-ADDRESS/web"); 
    }
  }
});
</script>

This code redirects you to your profile/now page dashboard when someone presses the . key on the keyboard, à là GitHub.

This snippet assumes that:

  • You also want it to work for your now page.
  • Your now page is at the same URL as your profile address but with /now or /now/ at the end (change the if guard if your case is different).
  • You want the . key to do the job (change line 3 otherwise).

Marked this as feature-request because it would be cool if @adam implemented this behaviour in the backend :prami_happy: .

Last note: if the visitor has Javascript off, the page would work fine but the shortcut won’t work.

Edit 2023-04-26:
Changed window.location.replace to window.location.assign which keeps the previous page in the browser’s history. I’m definitely not the best at Javascript :sweat_smile:.

2 Likes

This is so cool! Reminds me of how Squarespace lets people hit Esc to drop into the edit mode for the site. Will definitely get this integrated; thanks for the awesome suggestion!

2 Likes

Oh, I think you mentioned that on a livestream, then! Awesome, I bet you’ll find a less hacky solution than what I did checking if the webpage ends with “/now” :sweat_smile:

1 Like