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 http://www.kde.org
// @author Akhmad Fathonih
// @description Change links in red, only for testing
// @include *.kde.org*
// @exclude *.google.com*
// ==/UserScript==

var elms = document.getElementsByTagName("a");
//alert(elms.length);

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


Then I install another userscript that acts on planetkde.org. 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 http://www.kde.org
// @author Mathieu Ducharme
// @description
// @include *.planetkde.org*
// ==/UserScript==

var imgs = document.getElementsByTagName("img");
//alert(elms.length);

for(var i=0;i<imgs.length;i++) {
if(imgs[i].className == 'hackergotchi') {
imgs[i].src = 'http://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Thumbs_up.jpg/420px-Thumbs_up.jpg';
}
}

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

h2.parentNode.insertBefore(txt, h2);

6 comments:

Anonymous said...

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

Unknown 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!

Anonymous 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:

http://hwi.ath.cx/code/java/web/SuperProxy/javascript/

Anonymous said...

Can anyone recommend the top Script Deployment program for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? 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=http://kwstar88.zoomshare.com/2.shtml]R4i SDHC[/url] DS BB)