Skip to content

Instantly share code, notes, and snippets.

@amacdougall
Created August 9, 2012 15:53
Show Gist options
  • Save amacdougall/3305354 to your computer and use it in GitHub Desktop.
Save amacdougall/3305354 to your computer and use it in GitHub Desktop.
Use Tampermonkey or something to install this user script in Chrome.
// ==UserScript==
// @name Extra Trello Edit Keys
// @namespace http://www.paperlesspost.com/
// @version 0.1.1
// @description From the card edit window, hit H to edit the description and Y to add a new comment.
// @match https://trello.com/*
// @copyright 2012+, Alan MacDougall
// ==/UserScript==
function main() {
$(document).ready(function() {
console.log("Installing extra Trello keyboard shortcuts!");
function textFieldActive() {
var visibleFields = $("textarea:visible")
.add("input[type='text'].field:visible")
.add("input[type='text'].new-task-text:visible");
if (visibleFields.length == 1 &&
visibleFields.first().hasClass("new-comment-input") &&
$("div.new-comment div.add-controls:visible").length === 0) {
// only visible input field is the new comment placeholder, and comment
// save/cancel buttons are not visible: thus no text fields are active,
// but we ARE on a card page. Otherwise the new-comment-input field
// would not be visible at all.
return false;
} else {
return true;
}
}
$(document).on("keydown", function(event) {
if (event.which == 72) {
// handle "h" key by editing the card description
if (!textFieldActive()) {
event.preventDefault(); // don't input text
$("a.js-edit-desc").trigger("click");
}
} else if (event.which == 89) {
// handle "y" key by adding a comment
if (!textFieldActive()) {
event.preventDefault(); // don't input text
$("textarea.new-comment-input").trigger("focus");
}
}
});
});
}
// Inject our main script
var script = document.createElement('script');
script.type = "text/javascript";
script.textContent = '(' + main.toString() + ')();';
document.body.appendChild(script);
@amacdougall
Copy link
Author

Version 0.1.1

Ignore the new key commands when typing a checklist item.

@amacdougall
Copy link
Author

TODO: Ignore new key commands when date chooser, label editor, etc are open.

@amacdougall
Copy link
Author

Micro-fix: Treat checklist item edit and checklist item add the same. Weird that they're two different classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment