SelaoO / Meckano Ultra Fast

// ==UserScript==
// @name         Meckano Ultra Fast
// @namespace    https://app.meckano.co.il
// @version      0.2
// @description  Meckano script to improve UX and support mouseless use
// @author       Sela Oren
// @match        https://app.meckano.co.il/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
  "use strict";
  const ENTER = "13";
  const isHourValidFromElement = element => {
    const splittedHour = element.val().split(":");
    return !isNaN(+splittedHour[0]) && !isNaN(+splittedHour[1]);
  };

  $(document).keypress(event => {
    const keycode = event.keyCode || event.which;
    if (keycode == ENTER) {
      if ($(".inline-confirm").length === 1) {
        $(".inline-confirm").click();

        // move to the next screen
        $("#tab-tasks-reports").click();
        $("#li-project-report").click();
      }
    }
  });

  $(document).on("click", ".insert-row", () => {
    $(".checkin-str").keypress(event => {
      const jTargetElement = $(event.target);
      if (isHourValidFromElement(jTargetElement)) {
        $(".checkout-str").select();
      }
    });
  });

  // tasks report
  $(document).on("click", ".report-entry.checkin", () => {
    $(".report-entry.checkin").keypress(event => {
      const jTargetElement = $(event.target);
      if (isHourValidFromElement(jTargetElement)) {
        $(jTargetElement)
          .parent()
          .parent()
          .find(".report-entry.checkout")
          .select();
      }
    });

    $(".report-entry.checkout").keypress(event => {
      const keycode = event.keyCode || event.which;
      if (keycode == ENTER) {
        $(event.target)
          .parent()
          .parent()
          .find(".inline-confirm")
          .click();
      }
    });
  });
})();