Monday, October 5, 2009

Readability bookmarklet, browsers and StumpWM

Recently, I was looking for a way to get rid of the web-design while surfing the Net. Some most obvious ways, like banning custom fonts in Firefox work nice, while banning custom colors makes reading Gmail and Google Reader extremely unpleasant.

In Firefox I use TidyRead extension regularly. In the rare cases when TidyRead fails to do its job in the way I expect it to do, I use Readability bookmarklet. Readability, though, has a huge deficiency of being a bookmarklet. I mean, to use it you have to grab the mouse and click it. Of course, one could use keyboard to select Bookmarks menu and press twenty four arrows to get to the bookmarklet, but, of course, this is not what I would like to see. Especially because I love StumpWM window manager which is known for the disregard of mouse-like pointers. I needed a way to call the bookmark from the keyboard.

Here's what I came up with. Below is a piece of my .stumpwmrc file:

(defcommand readability () ()
  (send-meta-key (current-screen) (kbd "C-l"))
  (window-send-string "javascript:(function(){readStyle='style-novel';readSize='size-medium';
readMargin='margin-medium';
_readability_script=document.createElement('SCRIPT');
_readability_script.type='text/javascript';
_readability_script.src='http://lab.arc90.com/experiments/readability/js/readability.js?x='+(Math.random());
document.getElementsByTagName('head')[0].appendChild(_readability_script);
_readability_css=document.createElement('LINK');
_readability_css.rel='stylesheet';
_readability_css.href='http://lab.arc90.com/experiments/readability/css/readability.css';
_readability_css.type='text/css';
_readability_css.media='screen';
document.getElementsByTagName('head')[0].appendChild(_readability_css);
_readability_print_css=document.createElement('LINK');
_readability_print_css.rel='stylesheet';
_readability_print_css.href='http://lab.arc90.com/experiments/readability/css/readability-print.css';
_readability_print_css.media='print';
_readability_print_css.type='text/css';
document.getElementsByTagName('head')[0].appendChild(_readability_print_css);
})();
")
  (send-meta-key (current-screen) (kbd "RET")))
  (define-key *top-map* (kbd "s-p") "readability")

NB! I had to split the long line into a number of shorter ones. Merge them together to make the command work!

The first lines defines a new command which behaves just like you would: "presses" C-l to move the pointer to the address bar of the browser, pastes the full text of the bookmarklet and presses Return. That's it! And the last line maps the new command to a keyboard shortcut super-p.

No comments:

Post a Comment