DonationCoder.com Software > FARR Plugins and Aliases
CurrencyConverterMini (plugin) [renamed thread]
TucknDar:
thanks, works now! very useful, but a request would be to be able to write 'ex 10 gbp usd' to change which currencies to use.
about the crash, I'll look into it a little more. It's been a while since I actually opened the plugins dialog, so maybe there's another culprit. I'll reply about it later
Nod5:
I'm glad it works!
On custom currencies, see this and the post after.
I earlier considered adding modifiers for other currencies. But in the end I just aimed for the slimmest and quickest possible conversion from one specific currency to another. Adding modifiers could conflict with that somewhat. I could parse the string after "ex" for space separated substrings ("111 aaa bbb ") an if so treat the latter as modifiers. But then a users that wants "111 aaa bbb " would see results for "ex 111 " and "ex 111 aaa " on the way, which is ugly. (Using format "111aaa bbb" might work though). I'll think about it but at the moment I think complex conversions is well handled by the igo method ("igo 200 $ in €") or czechboys Google Calculator plugin (see link above).
lanux128:
thanks again Nod5 & czechboy but it is possible to use another source such as RatesFx? i have an off-site page of the website's currency calculator and currently view it through 'igo'. if this can be somewhat piped through Farr like the 'gcal', then it would be a great time-saver.
P.S. remove the 'txt' extension before viewing it. i put it there since the forum wouldn't allow me to attach 'html' files.
Nod5:
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.
Enzomaticus:
Did this ever get put into a proper plugin package? Or am I just to dumb to find it?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version