K-Meleon
Use this page to experiment with the wiki. (Just don't delete this text; otherwise people won't know the purpose of the page.)
See also:
A line starting with # is a comment and is ignored.
Variables are not declared explicitly, but must have a name starting with a dollar sign. A variable can either be global, accessible from any macro, or local to a specific macro. Before a variable can be used in an expression, it must be assigned a value. Integer and string values are available.
Macro declarations consist of a macro name followed by a compound of statements enclosed in curly braces to execute for that macro. An optional assignment of a string value to 'menu' can be used to set the text shown when the macro is used in menus.
The following operators are available:
Operator | Meaning | Sample Statement | Integer Result |
= | assignement | $x = 7; | $x = 7 |
. | string concatenation | $x = 7 . 3; | $x = 73 |
+ | integer addition | $x = 7 + 3; | $x = 10 |
- | integer subtraction | $x = 7 - 3; | $x = 4 |
* | integer multiplication | $x = 7 * 3; | $x = 21 |
/ | integer division | $x = 7 / 3; | $x = 2 |
% | integer remainder | $x = 7 % 3; | $x = 1 |
== | equality | $x = 7 == 3; | $x = 0 |
!= | unequality | $x = 7 != 3; | $x = 1 |
<, <=, >, >= | string comparison | $x = 10 < 2 | $x = 1 |
<, <=, >, >= | integer comparison | $x = +10 > +2 | $x = 1 |
? : | conditional expression | $x = $y==1 ? 2:3; | $x = 2 if y equals 1, $x = 3 otherwise |
Parentheses can be used to alter the evaluation order. By default, addition and subtraction have higher precedence than multiplication, division and remainder operations.
When needed, a variable is automatically converted from a string to an integer, or vice versa.
$x = 1 + "2"; $x = 3 $y = "The value of x is " . x; $y = "The value of x is 3"
Strings should be enclosed in double quotes although not required unless the string contains operators. A backslash is used to escape special characters:
\\ | backslash (\) |
\n | newline character |
\t | tabulator |
\" | quotation mark (") |
The string values "true" and "false" are recognized as boolean values and can be used in place of a conditional expression.
$z = "false"; $z ? $x = 1 : $x = 0; $x = 0 $z = "true"; $z ? $x = 1 : $x = 0; $x = 1
There is a number of predefined global variables to let K-Meleon macros access some global state information.
$ARG | Argument given from caller plugin (not from caller macro). |
$CHARSET | Character encoding used for the current page. Since 1.0. |
$FrameURL | URL for the current frame. |
$ImageURL | URL for the current image. |
$LinkURL | URL for the current link. |
$SelectedText | Selected text in the current page. Since 1.0. |
$TextZoom | Text zoom factor for the current page. Since 1.0. |
$TITLE | Title for the current page. |
$URL | URL for the current page. |
$URLBAR | Contents of the URL bar. Since 1.0. |
OnActivateWindow OnCloseGroup OnCloseWindow OnInit OnLoad OnOpenWindow OnQuit OnSetup OnStartup OnWMAppExit
Statements should be finished by a semicolon. Statements may not span several lines!
# THIS IS INVALID $error = 1 + 1;
Several statements can be lined up on the same line with a semicolon in between.
$x = 0; $y = "A text string";
The conditional expression operator (? :) can be used to execute a single statement depending on a certain condition.
A complete "If ... Then ... Else ..." statement would look like this:
CONDITION ? STATEMENT_CONDITION_TRUE : STATEMENT_CONDITION_FALSE;
A simple "If ... Then ..." statement would look like this:
CONDITION ? STATEMENT_CONDITION_TRUE : 0;
In the example above, nothing (0 = zero) is executed when the condition is false.
To execute multiple statements depending on a certain condition, these have to be encapsulated in helper macros:
CONDITION ? &ConditionTrue : &ConditionFalse; ConditionTrue { ... } ConditionFalse { ... }