[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH] Support for bookmarklets
From: Aurélien_Gâteau <aurelien.gateau () free ! fr>
Date: 2009-02-04 9:07:08
Message-ID: 49895ABC.6040301 () free ! fr
[Download RAW message or body]
David Faure wrote:
> On Thursday 29 January 2009, Aurélien Gâteau wrote:
>> Attached is a patch which adds support for bookmarklets to Konqueror.
>>
>> In case you don't know about them, bookmarklets are one-line javascript
>> bookmarks which can be triggered by the user to do nifty things with the
>> current web page, for example enforcing a sane combination of background
>> and foreground colors. One of the most common bookmarklets is the one
>> provided by Del.icio.us to bookmark pages to their service. You can find
>> it here:
>>
>> http://delicious.com/help/bookmarklets
>>
>> The patch is quite simple, but requires linking libkdeinit_konqueror
>> with khtml.
>
> Maybe the additional linking isn't needed if you just let konqueror ask
> khtml to open the javascript url (using KParts::ReadOnlyPart::openUrl)?
> Just wondering; otherwise no strong objection against linking khtml.
Good idea! I gave it a try this morning and came up with a much simpler
patch. This approach has the additional benefits of obeying javascript
enabled/disabled state and making it possible for another html part
(*cough* webkit *cough*) to implement bookmarklet support as well.
Aurélien
["konqueror-bookmarklet-2-khtml.diff" (text/x-diff)]
diff --git a/khtml/khtml_part.cpp b/khtml/khtml_part.cpp
index 4069ac7..12cf883 100644
--- a/khtml/khtml_part.cpp
+++ b/khtml/khtml_part.cpp
@@ -666,6 +666,13 @@ bool KHTMLPart::openUrl( const KUrl &url )
d->m_redirectionTimer.stop();
+ // Bookmarklet support
+ if ( url.protocol() == "javascript" && d->m_bJScriptEnabled ) {
+ const QString script = url.prettyUrl().section(':', 1);
+ executeScript(script);
+ return true;
+ }
+
// check to see if this is an "error://" URL. This is caused when an error
// occurs before this part was loaded (e.g. KonqRun), and is passed to
// khtmlpart so that it can display the error.
["konqueror-bookmarklet-2-konqueror.diff" (text/x-diff)]
Index: konqueror/src/konqmainwindow.cpp
===================================================================
--- konqueror/src/konqmainwindow.cpp (révision 917241)
+++ konqueror/src/konqmainwindow.cpp (copie de travail)
@@ -518,6 +518,12 @@
{
mimeType = "text/html";
}
+ else if ( url.protocol() == "javascript" )
+ {
+ // Bookmarklet support
+ // Fake html content so that the bookmarklet url is passed to the html part.
+ mimeType = "text/html";
+ }
else if ( !url.isValid() )
{
KMessageBox::error(0, i18n("Malformed URL\n%1", url.url()));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic