Created
August 9, 2012 15:53
-
-
Save amacdougall/3305354 to your computer and use it in GitHub Desktop.
Use Tampermonkey or something to install this user script in Chrome.
This file contains 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 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); |
TODO: Ignore new key commands when date chooser, label editor, etc are open.
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
Version 0.1.1
Ignore the new key commands when typing a checklist item.