Last active
June 9, 2017 18:02
-
-
Save mbarkhau/41d7594db0b4981a08007a596b85641c to your computer and use it in GitHub Desktop.
harvest_shortcuts_userscript.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Harvest Keyboard Shortcuts | |
| // @namespace https://gist.github.com/mbarkhau/41d7594db0b4981a08007a596b85641c | |
| // @version 0.1 | |
| // @description enter something useful | |
| // @author Manuel Barkhau | |
| // @match https://*.harvestapp.com/time/day/* | |
| // @grant none | |
| // ==/UserScript== | |
| // supported shortcuts: | |
| // | |
| // - space : start/stop most recent timer | |
| // - arrow left/right, page up/down: previous/next day | |
| // - home/pos1 : jump to today | |
| // - 1,2,3,4,5,6 : start/stop list entry 1,2,3,4,5,6 | |
| (function(){ | |
| 'use strict'; | |
| var $ = document.querySelector.bind(document); | |
| var lastStoppedButtonIndex = -1; | |
| document.addEventListener('keydown', function(e) { | |
| var activeModal = $(".modal-overlay.is-active"); | |
| if (!!activeModal) { | |
| return; | |
| } | |
| if (e.ctrlKey || e.altKey || e.shiftKey) { | |
| return; | |
| } | |
| if (e.keyCode == 36) { | |
| $('.js-harvest-current-view button.jump-to-today').click(); | |
| lastStoppedButtonIndex = -1; | |
| return; | |
| } | |
| if (e.keyCode == 37 || e.keyCode == 34) { | |
| $('.js-harvest-current-view button.js-jump-one-day-back').click(); | |
| lastStoppedButtonIndex = -1; | |
| return; | |
| } | |
| if (e.keyCode == 39 || e.keyCode == 33) { | |
| $('.js-harvest-current-view button.js-jump-one-day-forward').click(); | |
| lastStoppedButtonIndex = -1; | |
| return; | |
| } | |
| var entryList = $(".day-view-entry-list"); | |
| if (49 <= e.keyCode && e.keyCode <= 55) { | |
| var buttonIndex = e.keyCode - 49; | |
| var timerButton = entryList.children[buttonIndex].querySelector('button'); | |
| if (timerButton) { | |
| timerButton.click(); | |
| } | |
| return; | |
| } | |
| if (e.keyCode == 32) { | |
| var startedTimerListItem = entryList.querySelector('li.is-running'); | |
| if (!!startedTimerListItem) { | |
| var startedTimerButton = startedTimerListItem.querySelector('button'); | |
| startedTimerButton.click(); | |
| lastStoppedButtonIndex = Array.prototype.indexOf.call( | |
| entryList.children, startedTimerListItem | |
| ); | |
| return; | |
| } | |
| if (lastStoppedButtonIndex < 0) { | |
| lastStoppedButtonIndex = entryList.children.length - 1; | |
| } | |
| if (lastStoppedButtonIndex >= 0) { | |
| entryList.children[lastStoppedButtonIndex].querySelector('button').click(); | |
| lastStoppedButtonIndex = -1; | |
| return; | |
| } | |
| } | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment