I don’t know wether somebody has already started on this kind of project. I’m tickled so I tried to give a shot. I read some stuff about KJS, read its methods and found that we can actually execute a(ny) js script with it. I was 100% sure that KHTML (later found as KHTMLPart) will definitely has KJS in it, so this suerscript for Konqueror must be possible to achieve. Fire up KDevelop and test the khtmlpart plugin. I had to remove the original factory part and replace it with the (apparently) new factory code:
typedef KGenericFactory
static const KAboutData aboutdata("konqtest", I18N_NOOP("Konqueror KHTMLPart plugin test") , "0.1" );
K_EXPORT_COMPONENT_FACTORY( libkonqtestplugin, KonqTestFactory( &aboutdata ) )
Testing simple alert(document.getElementsByTagName(“link”).length) was sucessful. Thanks to akregator plugin for the example idea. Later, added a feature to autoload and execute any file under ~/.kde/share/apps/konqueror/userscripts. It wasn’t really easy for me who don’t have much knowledge about Qt and KDE. Simple task such as iterating over a list, reading lines from file had become a terrible torture
. Thank God it’s all over now. Or that waht I thought. next barrier was the UString stuff. After a careful read, I understand what the dev meant with “Happy implementing QString support” which is attched in KJS::UString::UString(QString &) doc. WTF!! Hahahah. Lucky me, we have lxr.kde.org. With some sweat I finally managed to get it working.
So far, the only feature available is autoexecuting every file under ~/.kde/share/apps/konqueror/userscripts as js, within current document context. TODO, of course, a lil bit compatibility with GreaseMonkey. Include, exclude url definitely will be mandatory needed feature. So far, you got to filtered it yourself within your JS
. I’m sure somebody will post a handy js script for this. Also, needed feature would be: enable disable userscript of course.
Okay, I no nothing about security. This code may not be secure at all
. That’s your homework. And if somebody has already start the same kind of thing then you can freely throw this code to your nearest recycle bin. I’m pretty happy already with my experience stroling new stuves :p.
For an example on how this thing work, save this code below to your userscripts folder. Don’t just copy paste! There are nasty quotes! (I should fix GeSHi plugin immediately :p)
var elms = document.getElementsByTagName("a");
//alert(elms.length);
for(var i=0;i
elms[i].style.border="1px solid";
}
The code above should make all links goes red and contained in red box.
Uploaded to kde-apps.org
Pingback: Lust::Geek Building The Bridge Part 2 » QRegExp greedy non greedy