run
Syntax
run: {= (javascript) =} [every (time)] [after (time)][, (javascript)...];
A safer alternative to eval.
Example:
body:init {
run: {=
alert('Hi! I'm a popup!');
=};
}
Under the hood it does something like this:
Function(..., '"use strict"; ...' + yourFunction)(...);
Use this instead of eval.
This works with the "vars" syntax, so if you declare your Active CSS variables with "vars" in your JavaScript, then you can get access to the variables that are applicable to the scope the run command is running in.
runButton:click {
$myVariable: "awesome";
run: {=
/* This is just regular JavaScript with the addition of the Active CSS special "vars" command. */
vars $myVariable;
alert('$myVariable is: ' + $myVariable);
=};
}
References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
Don't forget to put the semi-colon at the end of your command after the final "=}" or it won't run.
Alternatives
These other alternatives are safer than using eval:
Simply using ACSS syntax. You can do a lot more with it now than you could a while back.
@command or create-command - creates your own Active CSS action command, like all the other Active CSS commands, which is scoped to the "ActiveCSS" global variable and not the window scope.
func - calls an external function that you have already pre-written in a JavaScript file.
Note: The run command isn't allowed in browser extension JavaScript files due to browser security policies, but it works fine on websites.
Here is an example of run in action: