I added the more complex google syntax after all. Please testdrive it for bugs TucknDar and others
Currency Converter Mini now has two modes: default and advanced.
To use default, enter your default input/output currency to options once and after that just type "ex 100 "
To use advanced, type in a way that google currency converter understands: "ex 100$ in € " ("ex 100 $ in €" also works but does an extra search at "ex 100 ")
I also noticed that the plugin uses google for every default search now so the cache is not working. I'll try to fix that too.
// plugin script :
displayname="Currency Converter Mini";
versionstring="1.03.01";
releasedatestring="23.6.2008";
author="nod5";
updateurl="";
homepageurl="";
shortdescription="Convert from one currency to another via google.";
longdescription="Set default input/output currency in options (examples: $ £ GBP SEK canadian money or anything google accepts).\nDefault mode: \"ex 50 \". Advanced mode: \"ex 50$ in € \" where $ and € are currency names. \"ex\" means exchange rate.";
advconfigstring="Currency Converter Mini";
readmestring="Currency Converter Mini";
iconfilename="favicon.ico";
aliasstr="ex";
regexstr="^ex ((?:\d|\.|\,|\w|€|£|\$| )*) $";
scriptregex=/^ex (\d(?:\d|\.|\,|\w|€|£|\$| )*) $/;
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 exrate = "";
function doQuery(querykey,querynokeyword){
querynokeyword = querynokeyword.replace(/,/g,'.');
// if non-digit, then assume custom currency input
// so google entire string if structured "111aaa in bbb "
// else do nothing
var xtest = querynokeyword.search(/\D/g);
if (xtest != -1) {
var xtest = querynokeyword.search(/\d[^ ]*? (?:|[^ 0-9]*? )(?:|[^ 0-9]*? )in [^ 0-9]*?(?: [^ 0-9]*?|)/g);
// finds matches for:
// "ex 10$ in € "
// "ex 10 $ in € "
// "ex 10 swedish money in american money "
if (xtest == -1) {
FARR.setStrValue("window.richeditmode",display);
return;
}
var url = "http://www.google.com/search?hl=en&q="+querynokeyword;
var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4) {
var string = xmlhttp.responseText;
string = string.match(/><b>\d.*?[^<(?:f|b)]*? = \d.*?<\/b>/g);
string = string[0].replace(/<[^>]*?>/g,"");
string = string.replace(/>/g,"");
string = string.replace(/×/g,"x");
FARR.setStrValue("statusbar","Currency Converter Mini");
FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
return;
}
//-----------------------------------
FARR.setStrValue("window.richeditmode","");
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;
var xtest = queryraw.search(/(?:\d\D| \D)/g)
if (xtest != -1)
display = pre_string+"use google syntax: ex 100$ in € "+post_string;
FARR.setStrValue("window.richeditmode",display);
}
function onRegexSearchMatch(querykey,querynokeyword) {
var match_reg = querynokeyword.match(scriptregex);
doQuery(querykey,match_reg[1]);
}
lanux128, I don't really have time to add the RatesFx at the moment. Hopefully someone else does.