Development :  K-Meleon Web Browser Forum
K-Meleon development related discussions. 
How to keep strings in a macro ?
Posted by: JujuLand
Date: May 18, 2012 01:07PM

Hi,

As under Linux, mailto: doesn't work, I want to fabricate some variables usable by the macro.

Exemple:

Mail_SendLinkURL{
macroinfo=_("Send the current link by mail");
$JS_doitLink="j=a.length;location='mailtomoody smileybody='+encodeURIComponent(href)"; &JS_hndlLink;
}

here is what I want yo do:

Mail_SendLinkURL{
macroinfo=_("Send the current link by mail");
$_body= result of JS treatment of encodeURIComponent(href)"
exec($_mail." -compose body=".$_body);
}

Is-it possible, and how ?

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 1 time(s). Last edit at 05/18/2012 01:08PM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JamesD
Date: May 18, 2012 06:47PM

Do you have any injectJS running correctly in KM 1.7? I was not able to make that happen. See here http://kmeleonbrowser.org/forum/read.php?2,118158,122297#msg-122297

Hanlon’s razor is an eponymous adage named after Robert J. Hanlon that states: “Never attribute to malice that which is adequately explained by stupidity.”

JamesD

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 19, 2012 07:44AM

I have tried this:

$_title = injectJS( "var title=encodeURIComponent(title); function returnVar(title){return title;} returnVar(title);");
alert($_title,"$_title");

and it returns : undefined

Am-I wrong in my code, or is-it the problem that is already encountered ?

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc



Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: deadlock
Date: May 19, 2012 05:21PM

@JujuLand

Not sure what you're trying to do,
but created working macro lines for 'KM 1.6/1.7 CVS'
with encodeURIComponent, title and location:

injectJS( 'var a=window,b=document,c=encodeURIComponent,d='&title='+c(b.title),e=alert(c(d),d) ;');
injectJS( 'var a=window,b=document,c=encodeURIComponent,d='&title='+c(b.title),e=c(b.location),f=alert(c(e),d) ;');

Open a web page first!



Edited 1 time(s). Last edit at 05/19/2012 05:55PM by deadlock.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 19, 2012 06:43PM

@ deadlock,

As mailto protocol doesn't work with wine, I'm trying to keep the needed values in macro variables, and exec() the command to create a mail with the needed parameters (subject and body)

The samples you gave me doesn't return values to the macro, but just display a box.

I want to use the last syntax find on MacorLanguage3 page:

$value = injectJS( JS [, location ]);

except, I don't use location, It's not to operate the page, but to send a mail.

The sample I use was not very good, as $TITLE already contains the page title.

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 1 time(s). Last edit at 05/19/2012 06:45PM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 19, 2012 08:23PM

Hum ... if fact your two lines don't work, and I have errors in 'Error console' just launching K-Meleon

KMM => Invalid expression 'var a=window,b=document,
KMM => ) expected but found ;.
KMM => Invalid statement

To have no error, I must transform the lines like that:

injectJS( "var a=window,b=document,c=encodeURIComponent,d="+"$title="+"c(b.title),e=c(b.location),f=alert(c(e),d) ;");
instead of
injectJS( 'var a=window,b=document,c=encodeURIComponent,d='&title='+c(b.title),e=c(b.location),f=alert(c(e),d) ;');

but it done nothing.
changing it with $test=injectJS( "var ...
seems to do nothing too, but $test=0

It looks like the returned value is the error flag ???

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 3 time(s). Last edit at 05/19/2012 08:26PM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JamesD
Date: May 20, 2012 12:28AM

@ JujuLand

Are you using KM 1.7 code in your testing? I have not gotten any injectJS() to work with KM 1.7 code. You must first test to see if you can get any injectJS() to work. The following all seem to work for me in KM 1.6.2.4 beta. They don't work when I move them to 1.7 code.
$_Snippet_Value = injectJS( "Date()"); 
alert( $_Snippet_Value, "datestring", INFO);

$_Snippet_Date = injectJS( "var d = new Date(); function returnVar(d){return d;} returnVar(d);");
alert( $_Snippet_Date, "Date()", INFO);

$_Snippet_Year = injectJS( "var d = new Date(); dm = d.getFullYear();  function returnVar(dm){return dm;} returnVar(dm);");
alert( $_Snippet_Year, "d.getFullYear()", INFO);
 
$_Snippet_Month = injectJS( "var d = new Date(); dm = d.getMonth();  function returnVar(dm){return dm;} returnVar(dm);");
alert( $_Snippet_Month + 1, "d.getMonth() +1", INFO);

$_Snippet_Day = injectJS( "var d = new Date(); dm = d.getDate();  function returnVar(dm){return dm;} returnVar(dm);");
alert( $_Snippet_Day, "d.getDate()", INFO);

$_Snippet_WeekDay = injectJS( "var d = new Date(); dm = d.getDay();  function returnVar(dm){return dm;} returnVar(dm);");
alert( $_Snippet_Day, "d.getDay()", INFO);

$_Snippet_DateString = injectJS( "var d = new Date(); dm = d.toDateString();  function returnVar(dm){return dm;} returnVar(dm);");
alert( $_Snippet_DateString, "d.toDateString()", INFO);

If you can't get a date item with one of these then injectJS() is not functioning for your install.

Hanlon’s razor is an eponymous adage named after Robert J. Hanlon that states: “Never attribute to malice that which is adequately explained by stupidity.”

JamesD

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 20, 2012 09:29AM

@JamesD,

I was using 1.6.0b2 under Ubuntu/wine, obviously. smiling smiley

Your code works perfectly. the code I use is probably wrong. I confirm it doesn't work under Ubuntu/wine too with 1.7

Can you try, instead of date, to return a DOM info, like image link title ?

Do you know an online doc which talks about JavaScript and DOM ?

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 2 time(s). Last edit at 05/20/2012 09:33AM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 20, 2012 10:00AM

I have just modified the test like this:

$_Snippet_Date = injectJS( "var d = new Date(); function returnVar(d){return d;} alert(d);returnVar(d);");

With 1.6.0b2, JavaScript opens alert box
With 1.7.0, JavaScript doesn't open alert box

It seems that :

1) JavaScript isn't correctly called, and doesn't execute the code
or
2) Syntax isn't correct and JavaScript doesn't execute the code.

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 1 time(s). Last edit at 05/20/2012 10:02AM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 20, 2012 10:11AM

Weel after some searches, I have found a nice uttorials website:

w3schools

this test code for 1.6.0 works:

$_Snippet_Date = injectJS( "var d = document.title; function returnVar(d){return d;} alert(d);returnVar(d);");
alert( $_Snippet_Date, "document.title", INFO);

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 1 time(s). Last edit at 05/20/2012 10:11AM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JamesD
Date: May 20, 2012 11:19AM

I was confused because your signature includes "K-Meleon/1.7.0 ."

This site has some information on the DOM.
http://www.brainjar.com/dhtml/intro/

Hanlon’s razor is an eponymous adage named after Robert J. Hanlon that states: “Never attribute to malice that which is adequately explained by stupidity.”

JamesD

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: deadlock
Date: May 20, 2012 02:27PM

@JujuLand
>With 1.7.0, JavaScript doesn't open alert box

I've fixed that last spring to enable
view->Links/View->Linked Images/View->Images.

Disabled InjectJS in 1.7 alpha.

The macros above work with all 1.6 and
new 1.7 using BrowserWindow.cpp v1.2+.

@JamesD
Did you optimize any default macros
with new InjectJS commands?

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: deadlock
Date: May 20, 2012 03:22PM

@JujuLand
KMM => Invalid expression 'var a=window,b=document,
KMM => ) expected but found ;.
KMM => Invalid statement


Quotation marks only on the outside.
There was no error in my sample. smiling smiley

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JujuLand
Date: May 20, 2012 04:24PM

I first must say that reading again the Km doc helps me, and I have no more to run injectJS to make mail macros to work under Linux, except for mail subject, where I can't retreive what I want. For example, link text, or alt image text. For now I just use page title, even it's not exactly what I want to use.

Quote
JamesD
I was confused because your signature includes "K-Meleon/1.7.0 ."
I use the two versions.
If you know a way to change the signature, depending the version you use smiling smiley

Quote
JamesD
This site has some information on the DOM.
http://www.brainjar.com/dhtml/intro/
Thanks for the link

Quote
deadlock
>With 1.7.0, JavaScript doesn't open alert box

I've fixed that last spring to enable
view->Links/View->Linked Images/View->Images.

Disabled InjectJS in 1.7 alpha.

The macros above work with all 1.6 and
new 1.7 using BrowserWindow.cpp v1.2+.
Where can I find a 1.7 version using v1.2+ ?
I can't compile it ...

Quote
deadlock
@JujuLand
KMM => Invalid expression 'var a=window,b=document,
KMM => ) expected but found ;.
KMM => Invalid statement

Quotation marks only on the outside.
There was no error in my sample.
Hum, I don't understand, just copying your code in a macro and executing, and error console has these errors.

I have make it work after replacing external ' with "

I dont understand the utility of encodeURIComponent()
I have the result I want with this:

injectJS( "var a=window,b=document.title,e=alert(b) ;");
injectJS( "var a=window,b=document,c=b.location,f=alert(c) ;");

A+



Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:38.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/76.0


Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr



Ubuntu 12.04 - Gramps 3.4.9 - Harbour 3.2.0 - Hwgui 2.20-3 - K-Meleon 76.0 rc





Edited 1 time(s). Last edit at 05/20/2012 05:14PM by JujuLand.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JamesD
Date: May 20, 2012 06:00PM

Quote
deadlock
@JamesD
Did you optimize any default macros
with new InjectJS commands?

No, I did not. I played around with obtaining system date, but I have not put that code in any default macro. I think most, if not all, the default macros work for me so I have not changed anything.

Hanlon’s razor is an eponymous adage named after Robert J. Hanlon that states: “Never attribute to malice that which is adequately explained by stupidity.”

JamesD

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: deadlock
Date: May 20, 2012 07:14PM

@JujuLand

Where can I find a 1.7 version using v1.2+ ?
I can't compile it ...

The project owner updated CVS and has a compiled version.

Hum, I don't understand, just copying your code in a
macro and executing, and error console has these errors.

Forum replaces my double quotation marks
with single quotation marks.

I dont understand the utility of encodeURIComponent()
Found some details at w3schools.com.



Edited 1 time(s). Last edit at 05/20/2012 08:12PM by deadlock.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: deadlock
Date: May 20, 2012 07:43PM

@JamesD
I played around with obtaining system date
... using javascript date().
Your other solutions are great too.

default macros work for me
I'll try to clean up the defaults to prevent
conflicts with personal configurations.

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: JamesD
Date: May 20, 2012 08:44PM

Quote
deadlock
I'll try to clean up the defaults to prevent
conflicts with personal configurations.

I did do some work to prevent a problem for users that might be using policy manager. I put a few lines of code in main.kmm to allow injectJS() to work even when Javascript is off in policy manager. The first instance can be found at line 596 in the main.kmm distributed with my beta 2.4 version.

Hanlon’s razor is an eponymous adage named after Robert J. Hanlon that states: “Never attribute to malice that which is adequately explained by stupidity.”

JamesD

Options: ReplyQuote
Re: How to keep strings in a macro ?
Posted by: deadlock
Date: May 20, 2012 10:24PM

@JamesD
a few lines of code in main.kmm to allow injectJS()

Yes, I know and red the threads,
but it is very special.
That's why it is not part of greprefs.
It should be added to Chrome 'Preferences
/Privacy & Security' (not set/true)
or as optional download from kmext.sourceforge.net.

I'd prefer to continue looking for old preferences,
that don't exist in Gecko 1.9++.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.