Skip to content

Instantly share code, notes, and snippets.

@codycodes
Last active January 15, 2020 20:03
Show Gist options
  • Save codycodes/e050edf24ace15ba10fedac8434c9856 to your computer and use it in GitHub Desktop.
Save codycodes/e050edf24ace15ba10fedac8434c9856 to your computer and use it in GitHub Desktop.
Allows you to use the keyboard shorcuts in the comments to manipulate hiding/showing the calendar and going to its today view as well as starting/stopping pomodone if you use it
// ==UserScript==
// @name Some Trello Keyboard Shortcuts
// @namespace https://cody.codes
// @version 0.1
// @description Allows you to use the keyboard shorcuts in the comments to manipulate hiding/showing the calendar and going to its today view as well as starting/stopping pomodone if you use it
// @author You
// @match https://trello.com/b/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var lastCalendarView = 'week';
function F_handleKeyDown(event)
{
let calendarDisplaying = document.getElementsByClassName('calendar-header-toolbar').length > 0;
let cardDisplaying = document.getElementsByClassName('js-close-window').length > 0;
let composeCardDisplaying = document.getElementsByClassName('js-add-card').length > 0;
let isEditing = document.getElementsByClassName('editing').length > 0 || document.getElementsByClassName('is-focused').length > 0 || document.getElementsByClassName('is-editing').length > 0;
let inputActive = false;
let inputElements = document.getElementsByTagName('input');
// check if the active element is an input
for (let i = 0; i < inputElements.length; i++ ) {
if (inputElements[i] === document.activeElement) {
inputActive = true;
}
}
if (!inputActive && !isEditing) {
switch(event.keyCode) {
case 192: // ` -> open calendar and cycle through month or week
if (!composeCardDisplaying && calendarDisplaying) {
if (lastCalendarView == 'week') {
lastCalendarView = 'month'
} else {
lastCalendarView = 'week';
}
document.getElementsByClassName(`${lastCalendarView}-button`)[0].click();
} else if (!cardDisplaying && !composeCardDisplaying){
document.getElementsByClassName('icon-calendar')[0].click();
}
break;
case 84: // t -> switch to today on calendar
if (!cardDisplaying && !composeCardDisplaying && calendarDisplaying) {
document.getElementsByClassName('js-today')[0].click();
}
break;
case 27: // esc -> close calendar
if (!composeCardDisplaying && calendarDisplaying) {
// calendar view
document.getElementsByClassName('js-close-calendar')[0].click();
}
break;
case 80: // p -> start pomodone
if (cardDisplaying) {
document.getElementsByClassName('pd_timer_button__body_title')[0].click();
}
break;
case 186: // ; -> toggle due date complete
if (cardDisplaying) {
document.getElementsByClassName('js-details-toggle-due-date-complete')[0].click();
}
break;
default:
break;
}
}
}
window.addEventListener( 'keydown', F_handleKeyDown, false );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment