lldata / Any.do keyboard shortcuts

// ==UserScript==
// @name            Any.do keyboard shortcuts
// @description     Adds much needed keyboard navigation for the any.do web version
// @copyright       2019, lldata (https://openuserjs.org/users/lldata)
// @license         MIT
// @author          lldata
// @version         2
// @grant           none
// @icon            https://desktop.any.do/favicon.ico
// @include         https://desktop.any.do/*
// @require         https://code.jquery.com/jquery-3.2.1.min.js
// ==/UserScript==

function addTask() {
  var addTaskButton = document.querySelector('button.AppHeaderNewTaskButton');
  //console.log(addTaskButton);
  if (addTaskButton) addTaskButton.click();
}

function editTask() {
  var editTextbox = document.querySelector('textarea.DynamicTextArea__visibleTextArea');
  if (editTextbox) editTextbox.click();
}

function search() {
  var searchButton = document.querySelector('button.AppHeaderSearch__button');
  if (searchButton) searchButton.click();
}

function cancel() {
  var closeModal = document.querySelector('div.BackdropTooltip');
  if (closeModal) closeModal.click();
  else {
    // click some random header
    document.querySelector('h1').click();
  }
} 

function changeToList(key) {
  // baseline key to array index
  var index = (key - 49) + 1;
  var listLinks = document.querySelectorAll('a.AppSidebarLink');
  var link = listLinks[index];
  if (link) link.click();
}


$(document).on('keydown', function (e) {
  // key "esc" for close modals
  if (e.which == 27) { cancel(); }

  if( e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA" ) return;
  if( e.target.isContentEditable ) return;

  // Adding key "c" for add task
  if (e.which == 67) { addTask(); }
  // Adding key "e" for edit task
  if (e.which == 69) { editTask(); }
  // Adding key "s" or "/" for searching
  else if (e.which == 191 || e.which == 83) { search(); }
  // 1 to 9 to change between lists
  else if (e.which > 48 && e.which <= 59) {
    changeToList(e.which);
  } else {
      // console.log('unhandled key ' + e.which);
  }
});