Tuesday, October 13, 2009

Readability+Opera+StumpWM

Last time I wrote about using Readability bookmarklet in Opera running under StumpWM without mouse. The straightforward solution had a lot of deficiencies. One of the worst ones was that it didn't work in full-screen mode. Here's a much better way. Opera has a number of command-line switches (listed here). One of them, openURL, allows us to open a URL in the current window. So, if we put the bookmarklet code into the URL field, it will do the trick:

(defcommand readability () ()
   (run-shell-command "opera -remote \"openURL(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);
})();)\""))

Now, this Stump command will work even in full screen mode. It will even work when the Opera window does not have the input focus.

Of course, the code for any bookmarklet may be supplied instead of Readability.

NB: Just like before, the lines containing the bookmarklet code should be merged in one line before cutting and pasting the above snippet!

1 comment:

  1. See also this:

    http://www.ustunozgur.com/2010/02/opera-and-readability-bookmarklet.html

    ReplyDelete