Google docs bookmaklet to format code

January 27th, 2008. Tagged: bookmarklets, writing

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

Comments? Find me on BlueSky, Mastodon, LinkedIn, Threads, Twitter