awilliams

Custom Keyboard Shortcuts: User Script

Blog Post created by awilliams Administrator on Apr 4, 2017

I was tabbing around in Canvas and decided to try and tab my way back to global navigation; Lots of tabbing...

I realized I could get there faster if I used ctrl+L in Chrome to get to the omnibar (address bar): 3 tabs to Account

I thought for a moment how nice it would be to have a keyboard shortcut to go straight there...

... Rabbit Hole Entered ...

 

I'll spare you the journey and just take you to the end of this trip. A user script that provides a framework for creating custom keyboard shortcuts. 

 

Credit(s):

Disclaimer(s):

  • I really have no idea what I'm doing with JS and user scripts. You probably shouldn't use anything I make unless you know more than I do.
  • This could be a bad idea for reasons I haven't discovered yet. I'm sharing as a means of documenting, not to encourage you to follow in my madness.

 

// ==UserScript==
// @name         Canvas Custom Keyboard Shortcuts
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Uses https://craig.is/killing/mice library
// @author       Adam Williams
// @match       https://*.instructure.com/*
// @require     http://cdn.craig.is/js/mousetrap/mousetrap.min.js?9d308

// ==/UserScript==
// Working Examples
/*
Mousetrap.bind('1', function() {console.log('1 worked');});    // Basic Example
Mousetrap.bind('2', function() {alert('2 worked');});  // Alert Example
*/


// Global Nav Shortcuts
Mousetrap.bind('0', function() {alert('Keyboard Shortcuts:');}); // Show an alert
Mousetrap.bind('1', function() {document.getElementById("global_nav_profile_link").click();}); // Toggle Account Drawer
Mousetrap.bind('2', function() {document.getElementById("global_nav_accounts_link").click();}); // Toggle Admin Drawer

// For later
/*
3 : global_nav_dashboard_link
4 : global_nav_courses_link
5 :
*/

Outcomes