Friday, January 19, 2007

Userscript for KDE4

I love KDE. I use it every day, at home, at work, on the laptop, everywhere I can. The desktop feels right, Kate, Quanta, Amarok and others are just the best of their categories, and it's suuuper fast.

However I must admit Firefox is still my web browser of choice. I actually do prefer *using* Konqueror (faster, better UI imho), but when it comes to HTML/CSS rendering and JavaScript parsing, sometimes I just need to use Firefox. 3 reasons, really
  • Better rendering of websites. I'm not saying Konqueror sucks, I'm just saying that web designers do not target or test for Konq.
  • Better JavaScript parsing. While rendering feels much faster in Konqueror, JS code execution feels waaaayy faster in FF. Also, many scripts just work better. FCKEditor, amongst others
  • Extensions. I actually don't care that Firefox has a million extensions, but three of them are now essential:
    • AdBlock
    • FireBug
    • GreaseMonkey
Since 3.5, there is now an ad blocker plugin for Konqueror. Works great so far, hopefully the KDE4 version will support FilterSet.G -- Not a reason to use FF anymore

As a web developer, FireBug is a god-send. It turns Firefox in a very nice Javascript/CSS debugging environment. The next version will be absolutely amazing. Nothing close exists for Konqueror. Seriously, this is the best plugin ever. -- Until there is a similar tool, I will need to use Firefox at work.

Coincidentally, GreaseMonkey is also the best plugin ever. All it does is allow to run custom scripts on a given website. Why is that great? All those annoying behaviors on certain websites can be fixed with custom javascript, and their features can be extended. A gigantic amount of cool scripts already exists on http://www.userscripts.org

So I was *very* happy when I saw a small plugin appears on kde-apps.org that runs custom user scripts. Neofreko did a very cool job laying out the concept, for KDE3. Basically, a khtml plugin scans for js file in a given directory, parses their metadata and attaches the javascript to the page. Quite different from the actual GreaseMonkey plugin (which is written in XUL/JavaScript) but works none the less.

In all honesty, I couldn't compile it because of my broken Kubuntu installation so I thought, hey, why don't I just port this to KDE4/Qt4/CMake? Since the script was only a few lines it was quite easy and fast, and now there is hope for user script support in KDE4.

Here's a first screenshot of Konqueror (KDE4) running neofreko's sample script



Sample script:

var elms = document.getElementsByTagName("a");

for(var i=0;i
elms[i].style.color="red";
elms[i].style.border="1px solid";
}

This is still in "Proof Of Concept" stage; right now it simply executes any script matching the domain, it does not offer any of the GreaseMonkey functions (mostly, the cross-site XMLHttpRequest object) and is not optimized or secured in any form. But I believe both neofreko and I are committed to delivering this plugin and adjusting it to meet KDE's quality.

Our goal for now is full compatibility with existing GM scripts. It remains to be seen if it can be achieved.

It should appeared in KDE svn soon (watch for it in trunk/playground/base). Stay tuned!

No comments: