Development :  K-Meleon Forum
K-Meleon development related discussions. 
macrolanguage - love it grinning smiley
Posted by: siria
Date: August 14, 2011 03:37AM

Hey, I'm delighted to realize that "and" and "or" actually work inside if-conditions, never knew that! Thought had tried it in the past, and it didn't work then, but perhaps I had some other mistake in the code. Or perhaps I only tried in caps (AND / OR)??
Anyway, there were always workarounds for "and", by boxing conditions, but workarounds for "or" seemed so difficult. Meanwhile I don't understand at all anymore why I had been so blind *blush*
Little example:

test_or{
$_x=prompt("","number?","1");
if($_x<3 or $_x>6) alert("","x<3 or x>6: YES"); else alert("","x<3 or x>6: NO");
}

Perhaps this thread can be used by macro coders to exchange little tips or updates ;-)

Just recently, while I remember it yet:
"setmenu" works also in-session, not just at browser start, as was written somewhere smiling smiley
The rebuildmenu-command is still a mystery to me, but doesn't seem to be needed anyway, since simply setmenu can be used?

Probably a bug, but can come in handy anyway: cool smiley
Inserting a new popup or inline menu but without giving a name (""), makes that the top entry of the parent menu is deleted! Used by jsnj for his search+ macro smiling smiley

And JamesD figured out that comparing variables takes the type (STRING or INT) from the left side of the "=" ! (defines whether e.g. 10 is smaller or greater than e.g. 3) And a prompt seems to return always a STRING. This can be converted to INT by e.g. adding zero: $_x=$_x+0;

Ah yes, had almost forgotten already:
the new RETURN function for injectJS crops a string after 127 characters sad smiley

Yet another:
Input via prompt is cropped after 254 characters sad smiley Although a pref line can hold far longer strings, well over 1000 at least, probably much more. Funnily, when creating a new pref directly on the page about:config, then the input field accepts longer entries. But of course I have no idea how to call that version.
PS: Does anyone know the name of the context menu on about:config??? Would long since like to add an entry to open some help sites. Works fine via mouse gestures, but guess most other people would prefer a menu ;-)



Edited 8 time(s). Last edit at 08/14/2011 04:23AM by siria.

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: JamesD
Date: August 14, 2011 08:37AM

Really good find about the 'or' and 'and' words working with the if statement. They do not work with the older conditional statement.
They seem to work for the while statement. If I get time tomorrow, I guess I had better do some update to MacroLanguage2. I need to put all of your points in the wiki page so user will not need to search so much for them.

I also need to remember how to change the KM language file for Notepad++. The 'or' and 'and' do not show in keyword color.

_Snippet_RunCode {
$_y = 0 ;
$_x=prompt("","number?","1");
if($_x<3 or $_x>6) alert("","x<3 or x>6: YES"); else alert("","x<3 or x>6: NO");

# Does not work with older conditional statement
#$_x<3 or $_x>6 ? alert("","x<3 or x>6: YES") : alert("","x<3 or x>6: NO");  

if ($_x <= 6 and $_x < 3) alert("Both"); else alert("One or neither") ;

while ($_y < 3 and $_x > 2) {
	alert($_y ."  and  ". $_x, "The values are") ;
	$_y = $_y +1;  $_x = $_x -1;
	}
}

As for rebuildmenu, Groups2 and QuickStore both use it. It is when the macro uses code/data to change the menu. see: http://dl.dropbox.com/u/1522294/QuickStore.7z

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: JamesD
Date: August 14, 2011 11:43PM

I have made some changes to prompt() and injectJS() in MacroLanguage2. http://kmeleon.sourceforge.net/wiki/MacroLanguage2

I have started some changes for the Expressions section of MacroLanguage2.
Those changes are in the sandbox. http://kmeleon.sourceforge.net/wiki/SandBox

I really would like some input on the expressions changes. I did not like the old comparison stuff as integer. It really is Boolean. I put an item about the left side controlling at the bottom.

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: JamesD
Date: August 18, 2011 03:44AM

Changes to expressions, while(), and if() have been completed for MacroLanguage2

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: JamesD
Date: August 18, 2011 03:55AM

Quote
siria
Just recently, while I remember it yet:
"setmenu" works also in-session, not just at browser start, as was written somewhere smiling smiley
The rebuildmenu-command is still a mystery to me, but doesn't seem to be needed anyway, since simply setmenu can be used?

I do not know about KM 1.5.4 but in 1.6.0 rebuildmenu is not required. I commented out the rebuildmenu line in Page Load Sound http://kmeleon.sourceforge.net/wiki/KmmPgLdSound and it still worked and changed the menu as designed.

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: adodupan
Date: August 23, 2011 11:48PM

Maybe you can look here and try some of the functions, i assume that MacroLanguage2 should be another update.

Regards.

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: siria
Date: August 24, 2011 01:47AM

Yep smiling smiley Actually I checked it out just recently, when I stumbled in a neighbor file about "reserved words" (or such) "and" and "or" grinning smiley Have no clue about real programming, being only a little KM user dabbling with macrolanguage, so can only pick up little hints here and there from those cvs files, but sometimes they contain interesting descriptions - like in this case. But it seems those functions are pretty much all described in the wiki already or on kko's website.

Don't know how macrolanguage2 page started out, perhaps it was meant as an update, or perhaps meant to be an independent version, that was before my time. But it's always been the "current" version for me, have put the link in all my own macros.

James, I worked with in-session setmenu functions long before 1.6 came about, it worked just the same in KM1.5x already smiling smiley

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: JamesD
Date: August 26, 2011 02:36AM

Quote
siria
Don't know how macrolanguage2 page started out, perhaps it was meant as an update, or perhaps meant to be an independent version, that was before my time. But it's always been the "current" version for me, have put the link in all my own macros.

I began the MacroLanguage2 page. Some new items were being added to the macro language and the organization of the original page was such that I could not decide where in the page to add them. I just tried to lay out a better 'Contents' block and move all the items to fit the new contents block.

I don't know where the first small contents block comes from. It is not part of my work.

I have tried to keep the page updated. I hope that I have been successful. I hope users will always keep me informed if new items become available or any documentation is incorrect. They can, if they wish, update the page themselves. I only ask they follow the existing format where possible.

Quote
siria
James, I worked with in-session setmenu functions long before 1.6 came about, it worked just the same in KM1.5x already smiling smiley

Should I put some information about 'rebuildmenu' being depreciated in modern versions of KM?



Edited 1 time(s). Last edit at 08/26/2011 02:39AM by JamesD.

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley (Link Text)
Posted by: siria
Date: March 04, 2014 11:19PM

Don't know where to put it, but *finally* figured out a way to get the Link Text in a variable.
Handy e.g. for favorites macros, as title for adding link targets. Perhaps for other stuff too.
It's now mainly pieced together from default macros in main.kmm, with some little modifications.
(Wishlist: Would be much easier to have $LinkText as another default variable some day smiling smiley)

If anyone has use, the snippet goes like this:
Quote

$JS_doit="for(var j=0,a=getElementsByTagName('a');j<a.length;j++)with(a[j])if(urlencode(href)=='".urlencode($LinkURL)."'){var linktext=text;} return linktext;";
$_LinkText=injectJS("(function(){".$_JS_urlencode."with(document){".$JS_doit."}})()",frame);
$JS_doit="";

The catch is, injectJS is buggy yet in KM1.7, and because a JS variable needs to be returned the open-workaround doesn't help.
But works fine in KM1.6, and hopefully injectJS gets fixed some day in newer versions.

Perhaps a javascript expert can have a look, am not quite sure about the syntax around "return". Only know it works and error console doesn't complain.



Edited 1 time(s). Last edit at 03/04/2014 11:22PM by siria.

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley (Link Text)
Posted by: rodocop
Date: March 05, 2014 03:06AM

siria,
injectJS bug was fixed (or cured ;-) in 1.7 by Realgy


Try K-Meleon-1.6db+NS by dugbug // KM-16-S2014 by Fred // 1.6beta2.6 by JamesD

K-Meleon Twin+ Download for modern browsers =//= Download for old ones =//= Discuss it!!!

New KM74.0 for test and feedback! Get it there!


Options: ReplyQuote
Re: macrolanguage - love it grinning smiley (Link Text)
Posted by: siria
Date: March 05, 2014 04:29AM

Yes I've seen that a while ago. He has replaced "injectJS" with the "open" workaround, but only now -thanks to you- I've taken a closer look again and am slightly shocked: His fix toggles Javascript and other settings permanently "ON" when reloading images, all secretly without warning the user!

Anyway, the workaround works for most things, but alas not for the one thing that so far only the real injectJS can do: Transfer a javascript-variable to a macro-variable. That's the prob here...

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley (Link Text)
Posted by: siria
Date: March 23, 2014 09:37PM

Just had the prob to get a &-sign into a prompt box.
It was always shown as an underlined blank, and \& didn't help either.
Finally the solution was to type && :-)

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley (Link Text)
Posted by: siria
Date: March 25, 2014 05:32AM

A little bug, just to note it somewhere:
$ARG must not contain commas, or it gets cropped there.
A workaround is to first replace it with a hopefully rather rare sign like ` and later replace it back. (KM1.6)

Options: ReplyQuote
Re: macrolanguage - love it grinning smiley
Posted by: siria
Date: September 19, 2014 04:56PM

Question about macro bug in KM1.6/1.7:
Since 1.6 it's not possible anymore to execute a js-code and in next line toggle off again one of the js-prefs (e.g. capability). Because JS is already off again before the script execution has even started, the toggle-line is executed BEFORE its previous line with the code-injecting! So far I don't know any other workaround but to insert an annoying alert-box before the togglepref just to get a break.

Is there any way to toggle a pref with pure JS in a macro? So that it could be appended to the actual js code and hopefully only toggled AFTER that code is finished?



Edited 1 time(s). Last edit at 09/19/2014 04:56PM by siria.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.