Google docs bookmaklet to format code

Something has been annoying me for some time as I write this book in Google Docs: I want to be able to format text as code (Courier New) only using the keyboard. So I came up with this bookmarklet. It's one of those "works for me" so if it doesn't work for you feel free to modify and post here your version.

Code

Basically I attach an event (FF way, so won't work in IE) that listens to the keyboard combination ALT+x and then calls the appropriate editor command:

javascript:(
function(){
  window.frames[1].document.addEventListener(
    'keypress',
    function(e){
      if (e.altKey && e.charCode === 120){
        EditorCommand('fontname', 'Courier New');
        return false;
      }
    },
    false);
}
)()

Download

Right-click, bookmark:

Alt+X


Post this entry to: » del.icio.us  » Digg  » Furl  » Newsvine  » reddit  » Y!

Somewhat related posts

One Response to “Google docs bookmaklet to format code”

  1. phpied.com » Blog Archive » replace selected text (Firefox) Says:

    […] Luckily I'm so close (and yet so far) to finishing this book, otherwise I won't be able to help myself but create a whole toolbar of bookmarklets for "power" Google doc users… Post this entry to: » del.icio.us  » Digg  » Furl  » Newsvine  » reddit  » Y! […]

Leave a Reply