Thanks for the feedback mouser & czechboy & ecaradec!

Here is a new version with these improvements:
- the user chooses the input and output currency (stored in options.xml ). If the input/output phrase works in google, it should work in this plugin.
- the plugin uses google only once after each FARR restart, thereafter it uses the cached exchange rate which means lightning fast results. (I'll look into writing the exchange rate to a file later, but I suspect the current in memory cache is enough for most usage)
code for fscript.js :
// plugin script :
displayname="Currency Converter Mini";
versionstring="1.02.01";
releasedatestring="11.3.2008";
author="nod5";
updateurl="";
homepageurl="";
shortdescription="Convert from one currency to another via google.";
longdescription="To run the plugin, type \"ex 50 \" but replace 50 with the amount you want converted.\nSet input/output currency in advanced plugin options. (examples: $ £ GBP SEK canadian money )\nTest your input/output first by googling \"1 __ in __\", where _ is your input/output.\nAfter a FARR restart the first conversion uses google. Later conversions use the cached exchange rate.\nThe alias \"ex\" stands for exchange rate. The plugin converts one way, between two fixed currencies.\nFor other conversion needs just use google.";
advconfigstring="Currency Converter Mini";
readmestring="Currency Converter Mini";
iconfilename="favicon.ico";
aliasstr="ex";
regexstr="^ex ((?:\d|\.|\,)*?) $";
scriptregex=/^ex ((?:\d|\.|\,)*?) $/;
regexfilterstr="";
keywordstr="";
scorestr="300";
// type
UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
// Postprocessing
IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
// search state
STOPPED=0; SEARCHING=1;
var pre_string = "{\\rtf1\\ansi\\ansicpg1250\\deff0\\deftab709{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}{\\colortbl ;\\red255\\green0\\blue0;}{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs18 ";
var post_string = "\\par\n}";
var history = "";
var exrate = "";
function doQuery(querykey,querynokeyword){
querynokeyword = querynokeyword.replace(/,/g,'.');
if(exrate == ""){
var url = "http://www.google.com/search?hl=en&q=1"+myinputcurrency+"+in+"+myoutputcurrency;
var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4) {
var string = xmlhttp.responseText;
string = string.match(/<b>1 .* = (?:\d|\.|\,)*? /g);
var splitstring = string[0].split("=");
var exrate = splitstring[1].slice(1,-1);
string = exrate * querynokeyword;
string = Math.round(string);
string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
FARR.setStrValue("statusbar","Currency Converter Mini");
FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else {
var string = exrate * querynokeyword;
string = Math.round(string);
string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
FARR.setStrValue("statusbar","Currency Convert Mini");
FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
}
}
myinputcurrency="";
myoutputcurrency="";
function onOptionsChanged() {
var options=new ActiveXObject("MSXML2.DOMDocument");
options.load(currentDirectory+"\\options.xml")
myinputcurrency=options.selectSingleNode("options/myinputcurrency").getAttribute("value");
myoutputcurrency=options.selectSingleNode("options/myoutputcurrency").getAttribute("value");
}
function onInit(c) {
currentDirectory=c;
var options=new ActiveXObject("MSXML2.DOMDocument");
if(!options.load(currentDirectory+"\\options.xml") ||
options.selectSingleNode("options/myinputcurrency").getAttribute("value")=='' ||
options.selectSingleNode("options/myoutputcurrency").getAttribute("value")=='') {
options.loadXML("<options>\n"+
"<myinputcurrency label='exchange from :' value=''/>\n"+
"<myoutputcurrency label='exchange to :' value=''/>\n"+
"</options>");
options.save(currentDirectory+"\\options.xml");
options=null;
FARR.showOptions();
} else {
onOptionsChanged();
}
}
function onSearchBegin(querykey, explicit, queryraw, querynokeyword) {
if(!explicit) {
if(aliasstr.indexOf(querynokeyword)!=-1) {
FARR.setState(querykey,1);
FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
FARR.setState(querykey,0);
}
return;
}
FARR.setStrValue("statusbar","Currency Converter Mini");
display = pre_string+"Type amount and hit \\b space\\b0"+post_string;
FARR.setStrValue("window.richeditmode",display);
}
function onRegexSearchMatch(querykey,querynokeyword) {
var match_reg = querynokeyword.match(scriptregex);
doQuery(querykey,match_reg[1]);
}
edit:
- Can I add a title or description to the settings popup? (the one that stores the input/output in options.xml)
- I tried using escaping $ to \$ but still couldn't get it to work as an alias. Are you sure that it is possible in FARR?