Script Support
Quicktext scrips are written using the Javascript language, and what ever you return is going to be inserted instead of the tag. So if you don't know Javascript please take some time to learn the basics before trying to make scripts for Quicktext. It is only Quicktext Pro that has script support. This document is under development so if you have any suggestions or questions please ask.
The basic
The simplest script would be something like:
return "mystring";
which just replaces the tag with "mystring". But that is not very useful. To make it a little more useful you can do stuff like:
var date = new Date();
if (date.getHours() < 12)
  return "Good morning";
else
  return "Good afternoon";
One thing you want to use is variables. So if you call your script with [[SCRIPT=test|myvar]] you want to be able to get the myvar-value in the script. And this is how you do it:
var variable = this.mVariables[0];
return variable;
You can use as many variables as you want. To go through all variables you can do this:
var vars = [];
for (var i = 0; i < this.mVariables.length; i++)
  vars.push(this.mVariables[i]);
return vars.length;
You can also use tags recursivley which means that you can do this: [[SCRIPT=test|[[TO=firstname]]]]
The advanced
But you can also in the script get all the values that you would get from other tags. There are two types of functions that you can use: this.mQuicktext.get_{tagname}(); and this.mQuicktext.process_{tagname}(); (with the tagname in lowercase). The get-function is what Quicktext uses to process the tags so the tag needs the same variables as the tag do. It takes an array of variables. So if you would use a tag like [[TO=firstname|,]] you would in a script do:
var firstname = this.mQuicktext.get_to(["firstname",","]);
and [[ATT=full]] would be the same as doing:
var att = this.mQuicktext.get_att(["full"]);
The process-function you get more data from. It's what the get-function uses. One thing you can do is:
var str = [];
var to = this.mQuicktext.process_to();
for (var i in to)
  str.push(i +": "+ to[i]);

return str.join("\n");
Most process-functions don't need any variables but some do. For example the process_input(). That is because it is impossible for process_input() to return anything if it doesn't get any variables. That means that it is the same to use get_input() and process_input(). There are some functions that work like this, and to know which you can either:
- Try, if it don't work without variables it needs them
- Or think about whether process_{tagname}() would be able to return anything without any variables. If you don't think that process_{tagname}() would return anything without getting variables it takes the same argument as the get_{tagname}() function does.
The warning
The script support is very powerful because you can do anything that an extension could do. This also means that you should not just trust scripts if you get them from someone. Script could do bad stuff. But because all scripts are written in Javascript it is very easy to see if a script could do any harm.
Related texts