Friday, November 30, 2007

Latest news from Konqueror Userscripts

Hi everyone. (anyone? :P)

(Read on to see a video of the Konqueror Userscript Plugin in action...)

I spent some time today to fix a few issues to the khtml_userscript plugin for Konqueror (think of it as GreaseMonkey for KDE) and it now works to a point where I think its usable.

The installer now works. It can be used with:
  • The builtin binary "khtml_userscript_installer"
  • Clicking the Tools => User Scripts => Install Script button in Konqueror
  • Double-clicking a *.user.js file in dolphin / konqueror
Also there is a very dumb greasemonkey compatibility script that gets installed. Right now it does *nothing* but provides the few functions GreaseMonkey provide. At least scripts that use the GM_log() function do not throw any errors anymore... (All other functions are likely to fail)

Internally, we don't use KJS anymore. KHTMLPart now provides a very handy executeScript() function. Basically the Konqueror Userscript plugin is simply an UI on top of this method...

Lots of issues remaining though: the status bar icon is not deleted so after browsing for a while you'll see 20 instances of the icon. Also the "Manage User Script" is still read-only (it shows the good information but no editing works).

For those of you who wonder what exactly is khtml_userscript, I made a small screencast that shows a few features. You can see it below, some explainations will follow...

First I install a user script from the konqueror "Tools => Konqueror UserScripts" menu. I install a script that was used in the previous example by neofreko. It highlights all link with a red border.

// ==UserScript==
// @name KHTML Userscript (kuskus) Test
// @version 0.1.1
// @namespace
// @author Akhmad Fathonih
// @description Change links in red, only for testing
// @include **
// @exclude **
// ==/UserScript==

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

for(var i=0;i<elms.length;i++) {
elms[i].style.border="1px solid";

Then I install another userscript that acts on In this one, all the image of class "hackergotchi" are replaced with another image and I add a h1 element at top of the page that says "Planet Thumbs Up!"

// ==UserScript==
// @name KHTML Userscript Test in PlanetKDE
// @version 0.1.1
// @namespace
// @author Mathieu Ducharme
// @description
// @include **
// ==/UserScript==

var imgs = document.getElementsByTagName("img");

for(var i=0;i<imgs.length;i++) {
if(imgs[i].className == 'hackergotchi') {
imgs[i].src = '';

var h2 = document.getElementsByTagName('h2')[4];
var txt = document.createElement('h1');
txt.innerHTML = 'Planet Thumbs Up';

h2.parentNode.insertBefore(txt, h2);


EnsGabe said...

Just going to chime in and say thanks for the work!

Michael said...

I also want to say thanks for working on this. Greasemonkey is really useful, and I'll be very happy to have this feature in Konqueror. Keep up the good work!

JackieBrown said...

This seems to be working beyond just a proof of concept as the read me says in trunk.

Give yourself more credit.

Anonymous said...

Can't wait until this is packaged for Debian.

If you still need to emulate some of the GM API functions, you might find some useful code here:

Anonymous said...

Can anyone recommend the top Script Deployment program for a small IT service company like mine? Does anyone use or How do they compare to these guys I found recently: N-able N-central software monitoring
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Anonymous said...

I truly believe that we have reached the point where technology has become one with our world, and I am fairly certain that we have passed the point of no return in our relationship with technology.

I don't mean this in a bad way, of course! Ethical concerns aside... I just hope that as technology further advances, the possibility of uploading our memories onto a digital medium becomes a true reality. It's one of the things I really wish I could see in my lifetime.

(Posted on Nintendo DS running [url=]R4i SDHC[/url] DS BB)

Anonymous said...

It's so easy to choose high quality [url=]replica watches[/url] online: [url=]Rolex replica[/url], [url=]Breitling replica[/url], Chanel replica or any other watch from the widest variety of models and brands.

Anonymous said...

Takings Our Unimportant Prices at, The Singular [b][url=]Online Dispensary [/url][/b] To [url=]Buy Viagra[/url] Online ! You Can also Dupe Away dippy Deals When You [url=]Buy Cialis[/url] and When You You [url=]Buy Levitra[/url] Online. We Also Companions a Unequalled Generic [url=]Phentermine[/url] As a prolongation to Your Regimen ! We Our times away Interchange splotch [url=]Viagra[/url] and Also [url=]Generic Viagra[/url] !